{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://zaai.com/astro-aeo/schema/rag-report-v1.schema.json",
  "title": "Astro-AEO rag-report-v1",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "version",
    "type",
    "warnings",
    "source",
    "buildDigest",
    "inventoryComplete",
    "buildTimeIncomplete",
    "records"
  ],
  "properties": {
    "version": {
      "const": 1
    },
    "type": {
      "const": "rag"
    },
    "warnings": {
      "type": "array",
      "maxItems": 100000,
      "items": {
        "type": "string"
      }
    },
    "source": {
      "enum": [
        "private",
        "companions"
      ]
    },
    "buildDigest": {
      "type": [
        "string",
        "null"
      ],
      "pattern": "^sha256:[a-f0-9]{64}$"
    },
    "inventoryComplete": {
      "type": "boolean"
    },
    "buildTimeIncomplete": {
      "type": "boolean"
    },
    "records": {
      "type": "array",
      "maxItems": 100000,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "version",
          "kind",
          "id",
          "pageId",
          "chunkIndex",
          "text",
          "tokenCount",
          "tokenizer",
          "hash",
          "pageHash",
          "headings",
          "oversized",
          "metadata"
        ],
        "properties": {
          "version": {
            "const": 1
          },
          "kind": {
            "enum": [
              "page",
              "chunk"
            ]
          },
          "id": {
            "type": "string",
            "pattern": "^page:[a-f0-9]{64}(?::chunk:[0-9]{4,})?$"
          },
          "pageId": {
            "type": "string",
            "pattern": "^page:[a-f0-9]{64}$"
          },
          "chunkIndex": {
            "type": [
              "integer",
              "null"
            ],
            "minimum": 1
          },
          "text": {
            "type": "string"
          },
          "tokenCount": {
            "type": "integer",
            "minimum": 0
          },
          "tokenizer": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "name",
              "version",
              "approximate"
            ],
            "properties": {
              "name": {
                "type": "string",
                "minLength": 1
              },
              "version": {
                "type": "string",
                "minLength": 1
              },
              "approximate": {
                "type": "boolean"
              }
            }
          },
          "tokenizerFallback": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "reason"
            ],
            "properties": {
              "reason": {
                "enum": [
                  "preflight",
                  "count"
                ]
              }
            }
          },
          "hash": {
            "type": "string",
            "pattern": "^sha256:[a-f0-9]{64}$"
          },
          "pageHash": {
            "type": "string",
            "pattern": "^sha256:[a-f0-9]{64}$"
          },
          "headings": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "oversized": {
            "type": "boolean"
          },
          "metadata": {
            "type": "object",
            "required": [
              "url",
              "pathname",
              "title",
              "locale",
              "language",
              "contentVersion",
              "versionGroup",
              "section"
            ],
            "propertyNames": {
              "pattern": "^[A-Za-z][A-Za-z0-9_]{0,63}$"
            },
            "additionalProperties": {
              "type": [
                "string",
                "number",
                "boolean",
                "null"
              ]
            },
            "properties": {
              "url": {
                "type": "string",
                "format": "uri",
                "pattern": "^[Hh][Tt][Tt][Pp][Ss]?://[^/?#@\\s]+(?:/[^?#\\s]*)?$"
              },
              "pathname": {
                "type": "string",
                "maxLength": 2048,
                "pattern": "^(?!//)(?![\\s\\S]*/\\.{1,2}(?:/|$))/[^?#\\\\\\u0000-\\u001f\\u007f]*$"
              },
              "title": {
                "type": "string"
              },
              "locale": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "language": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "contentVersion": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "versionGroup": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "section": {
                "type": [
                  "string",
                  "null"
                ]
              }
            }
          }
        },
        "allOf": [
          {
            "if": {
              "properties": {
                "kind": {
                  "const": "page"
                }
              }
            },
            "then": {
              "properties": {
                "chunkIndex": {
                  "type": "null"
                },
                "id": {
                  "pattern": "^page:[a-f0-9]{64}$"
                }
              }
            },
            "else": {
              "properties": {
                "chunkIndex": {
                  "type": "integer",
                  "minimum": 1
                },
                "id": {
                  "pattern": "^page:[a-f0-9]{64}:chunk:[0-9]{4,}$"
                }
              }
            }
          }
        ]
      }
    }
  }
}
