{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://agentdirective.org/schemas/ai-agent-flow-map-v1.schema.json",
  "title": "AgentDirective AI Agent Design Flow Map v1",
  "type": "object",
  "additionalProperties": false,
  "required": ["$schema", "artifact_type", "artifact_version", "created_at", "scope", "privacy", "title", "description", "source", "pack_ids", "nodes", "edges", "warning_states", "warnings", "limitations"],
  "properties": {
    "$schema": { "const": "https://agentdirective.org/schemas/ai-agent-flow-map-v1.schema.json" },
    "artifact_type": { "const": "agentdirective_design_flow_map" },
    "artifact_version": { "$ref": "#/$defs/semver" },
    "created_at": { "type": "string", "format": "date-time" },
    "scope": { "const": "intended_design_not_runtime_telemetry" },
    "privacy": {
      "type": "object", "additionalProperties": false,
      "required": ["processing", "uploaded_by_feature", "retained_by_feature"],
      "properties": {
        "processing": { "const": "browser_local" },
        "uploaded_by_feature": { "const": false },
        "retained_by_feature": { "const": false }
      }
    },
    "title": { "type": "string", "minLength": 1, "maxLength": 120 },
    "description": { "type": "string", "maxLength": 500 },
    "source": { "type": "string", "minLength": 1, "maxLength": 120 },
    "pack_ids": { "type": "array", "uniqueItems": true, "items": { "$ref": "#/$defs/packId" } },
    "nodes": { "type": "array", "maxItems": 80, "items": { "$ref": "#/$defs/node" } },
    "edges": { "type": "array", "maxItems": 120, "items": { "$ref": "#/$defs/edge" } },
    "warning_states": { "type": "object", "additionalProperties": { "enum": ["open", "addressed", "dismissed"] } },
    "warnings": { "type": "array", "items": { "$ref": "#/$defs/warning" } },
    "limitations": { "type": "array", "minItems": 1, "items": { "type": "string", "minLength": 1, "maxLength": 500 } }
  },
  "$defs": {
    "semver": { "type": "string", "pattern": "^(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)(?:-[0-9A-Za-z.-]+)?(?:\\+[0-9A-Za-z.-]+)?$" },
    "id": { "type": "string", "pattern": "^[a-z][a-z0-9_-]{0,79}$" },
    "packId": { "type": "string", "pattern": "^[A-Z]{2,4}-[0-9]{3}$" },
    "node": {
      "type": "object", "additionalProperties": false,
      "required": ["id", "type", "label", "x", "y", "zone", "description"],
      "properties": {
        "id": { "$ref": "#/$defs/id" },
        "type": { "enum": ["user", "agent", "model", "memory", "tool", "database", "external", "human", "logging"] },
        "label": { "type": "string", "minLength": 1, "maxLength": 80 },
        "x": { "type": "number", "minimum": 0, "maximum": 1000 },
        "y": { "type": "number", "minimum": 0, "maximum": 620 },
        "zone": { "type": "string", "maxLength": 80 },
        "description": { "type": "string", "maxLength": 400 }
      }
    },
    "edge": {
      "type": "object", "additionalProperties": false,
      "required": ["id", "from", "to", "label", "data", "sensitive", "consequential", "approved", "logged", "failureHandled"],
      "properties": {
        "id": { "$ref": "#/$defs/id" }, "from": { "$ref": "#/$defs/id" }, "to": { "$ref": "#/$defs/id" },
        "label": { "type": "string", "minLength": 1, "maxLength": 100 }, "data": { "type": "string", "maxLength": 400 },
        "sensitive": { "type": "boolean" }, "consequential": { "type": "boolean" }, "approved": { "type": "boolean" }, "logged": { "type": "boolean" }, "failureHandled": { "type": "boolean" }
      }
    },
    "warning": {
      "type": "object", "additionalProperties": false,
      "required": ["id", "label", "severity", "pack_ids", "target_kind", "target_id", "status", "failure", "why"],
      "properties": {
        "id": { "type": "string", "minLength": 1, "maxLength": 180 }, "label": { "type": "string", "minLength": 1, "maxLength": 120 },
        "severity": { "enum": ["critical", "high", "medium"] }, "pack_ids": { "type": "array", "minItems": 1, "uniqueItems": true, "items": { "$ref": "#/$defs/packId" } },
        "target_kind": { "enum": ["node", "edge"] }, "target_id": { "$ref": "#/$defs/id" }, "status": { "enum": ["open", "addressed", "dismissed"] },
        "failure": { "type": "string", "minLength": 1, "maxLength": 500 }, "why": { "type": "string", "minLength": 1, "maxLength": 500 }
      }
    }
  }
}
