{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://docs.kapiworks.com/schemas/bundle-1.json",
  "title": "Kapi Works bundle",
  "description": "A whole package's data as one JSON block, for an AI that writes text rather than files. Long output can come in parts, which Kapi joins in order. Kapi then reads the files as a package, under the same rules as an upload.",
  "type": "object",
  "required": [
    "schema",
    "files"
  ],
  "properties": {
    "$schema": {
      "description": "This file's schema, https://docs.kapiworks.com/schemas/bundle-1.json, so editors check the file as you type. Kapi ignores it."
    },
    "schema": {
      "const": "kapi.works.bundle/1",
      "description": "The format, kapi.works.bundle/1."
    },
    "part": {
      "type": "integer",
      "minimum": 1,
      "maximum": 20,
      "description": "This part's number, when the bundle comes in parts. Left out: 1."
    },
    "of": {
      "type": "integer",
      "minimum": 1,
      "maximum": 20,
      "description": "How many parts the bundle comes in, up to 20. Left out: 1. Every part gives the same number."
    },
    "files": {
      "description": "The package's files by path. Media come separately: Kapi asks for them by their IDs.",
      "type": "object",
      "propertyNames": {
        "not": {
          "pattern": "^(?:view|media)/"
        }
      },
      "properties": {
        "kapi-works.json": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "$ref": "https://docs.kapiworks.com/schemas/package-2.json"
            }
          ],
          "description": "The manifest, as JSON or as its text."
        },
        "content.json": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "$ref": "https://docs.kapiworks.com/schemas/content-2.json"
            }
          ],
          "description": "The lessons, pages and blocks, as JSON or as text."
        },
        "questions.json": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "$ref": "https://docs.kapiworks.com/schemas/questions-2.json"
            }
          ],
          "description": "The questions, as JSON or as text."
        },
        "support.json": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "$ref": "https://docs.kapiworks.com/schemas/support-1.json"
            }
          ],
          "description": "Where answers and facts come from, as JSON or as text."
        },
        "look/theme.json": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "$ref": "https://docs.kapiworks.com/schemas/theme-1.json"
            }
          ],
          "description": "The look, as JSON or as text."
        }
      },
      "patternProperties": {
        "^words/(?:[a-z]{2,3}(?:-[A-Z][a-z]{3})?(?:-(?:[A-Z]{2}|\\d{3}))?)\\.json$": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "$ref": "https://docs.kapiworks.com/schemas/words-1.json"
            }
          ],
          "description": "A words file, as JSON or as text."
        },
        "^(?![\\s\\S]*\\.json$)": {
          "type": "string",
          "description": "A file that isn't JSON, such as AGENTS.md, as its text."
        }
      },
      "additionalProperties": {
        "description": "Any other JSON file, as JSON or as text."
      }
    }
  },
  "allOf": [
    {
      "if": {
        "not": {
          "required": [
            "of"
          ]
        }
      },
      "then": {
        "properties": {
          "part": {
            "type": "integer",
            "maximum": 1
          }
        }
      }
    },
    {
      "if": {
        "required": [
          "of"
        ],
        "properties": {
          "of": {
            "const": 1
          }
        }
      },
      "then": {
        "properties": {
          "part": {
            "type": "integer",
            "maximum": 1
          }
        }
      }
    },
    {
      "if": {
        "required": [
          "of"
        ],
        "properties": {
          "of": {
            "const": 2
          }
        }
      },
      "then": {
        "properties": {
          "part": {
            "type": "integer",
            "maximum": 2
          }
        }
      }
    },
    {
      "if": {
        "required": [
          "of"
        ],
        "properties": {
          "of": {
            "const": 3
          }
        }
      },
      "then": {
        "properties": {
          "part": {
            "type": "integer",
            "maximum": 3
          }
        }
      }
    },
    {
      "if": {
        "required": [
          "of"
        ],
        "properties": {
          "of": {
            "const": 4
          }
        }
      },
      "then": {
        "properties": {
          "part": {
            "type": "integer",
            "maximum": 4
          }
        }
      }
    },
    {
      "if": {
        "required": [
          "of"
        ],
        "properties": {
          "of": {
            "const": 5
          }
        }
      },
      "then": {
        "properties": {
          "part": {
            "type": "integer",
            "maximum": 5
          }
        }
      }
    },
    {
      "if": {
        "required": [
          "of"
        ],
        "properties": {
          "of": {
            "const": 6
          }
        }
      },
      "then": {
        "properties": {
          "part": {
            "type": "integer",
            "maximum": 6
          }
        }
      }
    },
    {
      "if": {
        "required": [
          "of"
        ],
        "properties": {
          "of": {
            "const": 7
          }
        }
      },
      "then": {
        "properties": {
          "part": {
            "type": "integer",
            "maximum": 7
          }
        }
      }
    },
    {
      "if": {
        "required": [
          "of"
        ],
        "properties": {
          "of": {
            "const": 8
          }
        }
      },
      "then": {
        "properties": {
          "part": {
            "type": "integer",
            "maximum": 8
          }
        }
      }
    },
    {
      "if": {
        "required": [
          "of"
        ],
        "properties": {
          "of": {
            "const": 9
          }
        }
      },
      "then": {
        "properties": {
          "part": {
            "type": "integer",
            "maximum": 9
          }
        }
      }
    },
    {
      "if": {
        "required": [
          "of"
        ],
        "properties": {
          "of": {
            "const": 10
          }
        }
      },
      "then": {
        "properties": {
          "part": {
            "type": "integer",
            "maximum": 10
          }
        }
      }
    },
    {
      "if": {
        "required": [
          "of"
        ],
        "properties": {
          "of": {
            "const": 11
          }
        }
      },
      "then": {
        "properties": {
          "part": {
            "type": "integer",
            "maximum": 11
          }
        }
      }
    },
    {
      "if": {
        "required": [
          "of"
        ],
        "properties": {
          "of": {
            "const": 12
          }
        }
      },
      "then": {
        "properties": {
          "part": {
            "type": "integer",
            "maximum": 12
          }
        }
      }
    },
    {
      "if": {
        "required": [
          "of"
        ],
        "properties": {
          "of": {
            "const": 13
          }
        }
      },
      "then": {
        "properties": {
          "part": {
            "type": "integer",
            "maximum": 13
          }
        }
      }
    },
    {
      "if": {
        "required": [
          "of"
        ],
        "properties": {
          "of": {
            "const": 14
          }
        }
      },
      "then": {
        "properties": {
          "part": {
            "type": "integer",
            "maximum": 14
          }
        }
      }
    },
    {
      "if": {
        "required": [
          "of"
        ],
        "properties": {
          "of": {
            "const": 15
          }
        }
      },
      "then": {
        "properties": {
          "part": {
            "type": "integer",
            "maximum": 15
          }
        }
      }
    },
    {
      "if": {
        "required": [
          "of"
        ],
        "properties": {
          "of": {
            "const": 16
          }
        }
      },
      "then": {
        "properties": {
          "part": {
            "type": "integer",
            "maximum": 16
          }
        }
      }
    },
    {
      "if": {
        "required": [
          "of"
        ],
        "properties": {
          "of": {
            "const": 17
          }
        }
      },
      "then": {
        "properties": {
          "part": {
            "type": "integer",
            "maximum": 17
          }
        }
      }
    },
    {
      "if": {
        "required": [
          "of"
        ],
        "properties": {
          "of": {
            "const": 18
          }
        }
      },
      "then": {
        "properties": {
          "part": {
            "type": "integer",
            "maximum": 18
          }
        }
      }
    },
    {
      "if": {
        "required": [
          "of"
        ],
        "properties": {
          "of": {
            "const": 19
          }
        }
      },
      "then": {
        "properties": {
          "part": {
            "type": "integer",
            "maximum": 19
          }
        }
      }
    },
    {
      "if": {
        "required": [
          "of"
        ],
        "properties": {
          "of": {
            "const": 20
          }
        }
      },
      "then": {
        "properties": {
          "part": {
            "type": "integer",
            "maximum": 20
          }
        }
      }
    }
  ]
}
