{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "query-plan.v1.json",
  "title": "Plato's Kallipolis Query Plan Request",
  "type": "object",
  "required": ["intent"],
  "properties": {
    "intent": { "type": "string", "minLength": 3, "maxLength": 2000 },
    "sources": {
      "type": "array",
      "minItems": 1,
      "maxItems": 16,
      "items": {
        "type": "object",
        "required": ["id", "kind"],
        "properties": {
          "id": { "type": "string", "pattern": "^[A-Za-z0-9][A-Za-z0-9._-]{2,127}$" },
          "kind": { "enum": ["resource", "agent"] },
          "endpoint": { "type": "string", "pattern": "^/" }
        },
        "additionalProperties": false
      }
    },
    "freshness": {
      "type": "object",
      "properties": {
        "maxAgeSeconds": { "type": "integer", "minimum": 0, "maximum": 31536000 },
        "asOf": { "type": "string", "format": "date-time" }
      },
      "additionalProperties": false
    },
    "evidence": {
      "type": "object",
      "properties": {
        "minimumSources": { "type": "integer", "minimum": 1, "maximum": 8 },
        "independentSources": { "type": "integer", "minimum": 1, "maximum": 8 },
        "citationsRequired": { "type": "boolean" }
      },
      "additionalProperties": false
    },
    "limits": {
      "type": "object",
      "properties": {
        "maxResults": { "type": "integer", "minimum": 1, "maximum": 100 },
        "maxLatencyMs": { "type": "integer", "minimum": 100, "maximum": 60000 },
        "maxCostUnits": { "type": "integer", "minimum": 0, "maximum": 100000 }
      },
      "additionalProperties": false
    },
    "output": {
      "type": "object",
      "properties": {
        "format": { "const": "json" },
        "schema": { "type": "string", "maxLength": 500 },
        "citations": { "type": "boolean" }
      },
      "additionalProperties": false
    },
    "policy": {
      "type": "object",
      "properties": {
        "dataClassification": { "const": "public" },
        "allowSensitiveData": { "const": false },
        "allowExternalProviders": { "const": false }
      },
      "additionalProperties": false
    }
  },
  "additionalProperties": false
}
