{
  "openapi": "3.1.0",
  "info": {
    "title": "Aferliffe.ArtGallery API",
    "version": "2026-11-12",
    "summary": "API công khai, chỉ đọc, cho nội dung gallery.",
    "description": "Dữ liệu tác phẩm, khu trưng bày và hệ sinh thái của Aferliffe.ArtGallery. Không cần xác thực. Các endpoint .json là tệp tĩnh; /api/search, /api/chat và /mcp chạy trên Netlify Edge Functions. Chính sách sử dụng: https://aferliffe-artgallery.org/ai.txt",
    "license": {
      "name": "Chính sách dữ liệu AI của Aferliffe.ArtGallery",
      "url": "https://aferliffe-artgallery.org/ai.txt"
    }
  },
  "servers": [
    {
      "url": "https://aferliffe-artgallery.org"
    }
  ],
  "externalDocs": {
    "description": "llms.txt",
    "url": "https://aferliffe-artgallery.org/llms.txt"
  },
  "security": [],
  "tags": [
    {
      "name": "Dữ liệu",
      "description": "Tệp JSON tĩnh, luôn sẵn sàng"
    },
    {
      "name": "Tìm kiếm",
      "description": "Tìm kiếm toàn văn (Edge Function)"
    },
    {
      "name": "AI",
      "description": "Trợ lý AI trả lời dạng streaming (Edge Function)"
    }
  ],
  "paths": {
    "/api/gallery.json": {
      "get": {
        "operationId": "getGallery",
        "tags": [
          "Dữ liệu"
        ],
        "summary": "Toàn bộ dữ liệu gallery trong một lần gọi",
        "responses": {
          "200": {
            "description": "Tổ chức, năm chương, bốn khu, tác phẩm và hệ sinh thái",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Gallery"
                }
              }
            }
          }
        }
      }
    },
    "/api/artworks.json": {
      "get": {
        "operationId": "listArtworks",
        "tags": [
          "Dữ liệu"
        ],
        "summary": "Danh sách tác phẩm (bản tóm tắt)",
        "responses": {
          "200": {
            "description": "Danh sách tác phẩm",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "count": {
                      "type": "integer"
                    },
                    "updated": {
                      "type": "string",
                      "format": "date"
                    },
                    "artworks": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/ArtworkSummary"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/artworks/{slug}.json": {
      "get": {
        "operationId": "getArtwork",
        "tags": [
          "Dữ liệu"
        ],
        "summary": "Chi tiết một tác phẩm",
        "parameters": [
          {
            "name": "slug",
            "in": "path",
            "required": true,
            "description": "Mã tác phẩm viết thường, không dấu cách, ví dụ aff148",
            "schema": {
              "type": "string",
              "enum": [
                "aff136",
                "aff125",
                "aff124",
                "aff137",
                "aff141",
                "aff144",
                "aff145",
                "aff148",
                "aff151",
                "aff121",
                "aff130",
                "aff153",
                "aff154",
                "aff155",
                "aff156",
                "aff157",
                "aff158",
                "aff159",
                "aff160",
                "aff161",
                "aff162",
                "aff163",
                "aff164",
                "aff165"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Tác phẩm",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Artwork"
                }
              }
            }
          },
          "404": {
            "description": "Không có tác phẩm với mã này"
          }
        }
      }
    },
    "/api/ecosystem.json": {
      "get": {
        "operationId": "getEcosystem",
        "tags": [
          "Dữ liệu"
        ],
        "summary": "Bốn trụ cột của hệ sinh thái doanh nghiệp",
        "responses": {
          "200": {
            "description": "Hệ sinh thái",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "count": {
                      "type": "integer"
                    },
                    "ecosystem": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/EcosystemPillar"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/search": {
      "get": {
        "operationId": "searchGallery",
        "tags": [
          "Tìm kiếm"
        ],
        "summary": "Tìm kiếm toàn văn trong nội dung gallery",
        "description": "Hỗ trợ tiếng Việt có dấu hoặc không dấu và tiếng Anh.",
        "parameters": [
          {
            "name": "q",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            },
            "example": "Nhật Bản mùa đông"
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 20,
              "default": 5
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Kết quả xếp theo độ phù hợp",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "query": {
                      "type": "string"
                    },
                    "results": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/SearchResult"
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Lỗi",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/chat": {
      "post": {
        "operationId": "chat",
        "tags": [
          "AI"
        ],
        "summary": "Hỏi trợ lý AI của gallery (streaming)",
        "description": "Trả lời dựa trên nội dung của site. Mặc định trả về luồng Server-Sent Events; mỗi sự kiện là một dòng `data: {json}` với type là start, text-delta, sources hoặc finish, kết thúc bằng `data: [DONE]`. Gửi \"stream\": false để nhận một JSON duy nhất. Giới hạn khoảng 12 yêu cầu mỗi phút cho mỗi địa chỉ IP.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ChatRequest"
              },
              "example": {
                "messages": [
                  {
                    "role": "user",
                    "content": "Kể về tác phẩm Apulia"
                  }
                ],
                "lang": "vi"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Câu trả lời",
            "content": {
              "text/event-stream": {
                "schema": {
                  "type": "string",
                  "description": "Luồng SSE"
                }
              },
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ChatResponse"
                }
              }
            }
          },
          "400": {
            "description": "Lỗi",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Lỗi",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "Artwork": {
        "type": "object",
        "required": [
          "code",
          "slug",
          "title",
          "intro",
          "paragraphs",
          "image",
          "url"
        ],
        "properties": {
          "code": {
            "type": "string",
            "examples": [
              "AFf148"
            ]
          },
          "slug": {
            "type": "string",
            "examples": [
              "aff148"
            ]
          },
          "title": {
            "type": "string",
            "description": "Tên tiếng Việt"
          },
          "title_en": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "place": {
            "type": "string"
          },
          "place_en": {
            "type": "string"
          },
          "sign": {
            "type": "string"
          },
          "zone": {
            "type": "string",
            "enum": [
              "A",
              "B"
            ]
          },
          "zone_code": {
            "type": "string"
          },
          "zone_name": {
            "type": "string"
          },
          "collection": {
            "type": "string"
          },
          "intro": {
            "type": "string"
          },
          "paragraphs": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "alt": {
            "type": "string"
          },
          "image": {
            "type": "string",
            "format": "uri"
          },
          "thumbnail": {
            "type": "string",
            "format": "uri"
          },
          "url": {
            "type": "string",
            "format": "uri"
          },
          "markdown_url": {
            "type": "string",
            "format": "uri"
          },
          "api_url": {
            "type": "string",
            "format": "uri"
          },
          "language": {
            "type": "string"
          },
          "publisher": {
            "type": "string"
          },
          "updated": {
            "type": "string",
            "format": "date"
          }
        }
      },
      "ArtworkSummary": {
        "type": "object",
        "properties": {
          "code": {
            "type": "string",
            "examples": [
              "AFf148"
            ]
          },
          "slug": {
            "type": "string",
            "examples": [
              "aff148"
            ]
          },
          "title": {
            "type": "string",
            "description": "Tên tiếng Việt"
          },
          "title_en": {
            "type": "string"
          },
          "place": {
            "type": "string"
          },
          "place_en": {
            "type": "string"
          },
          "zone": {
            "type": "string",
            "enum": [
              "A",
              "B"
            ]
          },
          "zone_code": {
            "type": "string"
          },
          "intro": {
            "type": "string"
          },
          "image": {
            "type": "string",
            "format": "uri"
          },
          "thumbnail": {
            "type": "string",
            "format": "uri"
          },
          "url": {
            "type": "string",
            "format": "uri"
          },
          "markdown_url": {
            "type": "string",
            "format": "uri"
          },
          "api_url": {
            "type": "string",
            "format": "uri"
          }
        }
      },
      "EcosystemPillar": {
        "type": "object",
        "properties": {
          "code": {
            "type": "string"
          },
          "slug": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "name_vi": {
            "type": "string"
          },
          "representatives": {
            "type": "string"
          },
          "goal": {
            "type": "string"
          },
          "open_for_registration": {
            "type": "boolean"
          },
          "text": {
            "type": "string",
            "description": "Nội dung dạng Markdown"
          },
          "body": {
            "type": "array",
            "items": {}
          },
          "url": {
            "type": "string",
            "format": "uri"
          }
        }
      },
      "Gallery": {
        "type": "object",
        "properties": {
          "site": {
            "type": "object"
          },
          "updated": {
            "type": "string",
            "format": "date"
          },
          "chapters": {
            "type": "array",
            "items": {
              "type": "object"
            }
          },
          "zones": {
            "type": "array",
            "items": {
              "type": "object"
            }
          },
          "artworks": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Artwork"
            }
          },
          "ecosystem": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/EcosystemPillar"
            }
          }
        }
      },
      "SearchResult": {
        "type": "object",
        "properties": {
          "type": {
            "type": "string",
            "enum": [
              "about",
              "zone",
              "artwork",
              "ecosystem"
            ]
          },
          "id": {
            "type": "string"
          },
          "code": {
            "type": "string"
          },
          "title": {
            "type": "string"
          },
          "url": {
            "type": "string",
            "format": "uri"
          },
          "markdown_url": {
            "type": "string",
            "format": "uri"
          },
          "image": {
            "type": "string",
            "format": "uri"
          },
          "snippet": {
            "type": "string"
          },
          "score": {
            "type": "number"
          }
        }
      },
      "ChatRequest": {
        "type": "object",
        "required": [
          "messages"
        ],
        "properties": {
          "messages": {
            "type": "array",
            "minItems": 1,
            "items": {
              "type": "object",
              "required": [
                "role",
                "content"
              ],
              "properties": {
                "role": {
                  "type": "string",
                  "enum": [
                    "user",
                    "assistant"
                  ]
                },
                "content": {
                  "type": "string",
                  "maxLength": 1500
                }
              }
            }
          },
          "lang": {
            "type": "string",
            "enum": [
              "vi",
              "en",
              "ja"
            ],
            "default": "vi"
          },
          "stream": {
            "type": "boolean",
            "default": true
          }
        }
      },
      "ChatResponse": {
        "type": "object",
        "properties": {
          "answer": {
            "type": "string"
          },
          "mode": {
            "type": "string",
            "enum": [
              "ai",
              "retrieval"
            ],
            "description": "ai: mô hình ngôn ngữ trả lời; retrieval: chỉ tra cứu vì AI chưa được bật"
          },
          "sources": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "title": {
                  "type": "string"
                },
                "url": {
                  "type": "string",
                  "format": "uri"
                },
                "type": {
                  "type": "string"
                }
              }
            }
          }
        }
      },
      "Error": {
        "type": "object",
        "properties": {
          "error": {
            "type": "string"
          }
        }
      }
    }
  },
  "x-mcp": {
    "endpoint": "https://aferliffe-artgallery.org/mcp",
    "transport": "streamable-http",
    "manifest": "https://aferliffe-artgallery.org/.well-known/mcp.json"
  }
}
