{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/run402-com/json-schema/run402-com-agent-escalation-list-schema.json",
  "title": "AgentEscalationList",
  "x-generated": "2026-11-10",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/run402-com-escalations-api-openapi.yml#/components/schemas/AgentEscalationList",
  "type": "object",
  "properties": {
    "escalations": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/AgentEscalation"
      }
    },
    "scope": {
      "type": "string",
      "enum": [
        "organization",
        "own"
      ],
      "description": "'own' when the caller is a grant key or grant-only principal — it sees only what it raised."
    },
    "has_more": {
      "type": "boolean"
    },
    "next_cursor": {
      "type": [
        "string",
        "null"
      ],
      "description": "Keyset continuation over (raised_at DESC, id). Null on the last page."
    }
  },
  "$defs": {
    "AgentEscalation": {
      "type": "object",
      "description": "An agent's page to a human, and its whole life story.",
      "properties": {
        "escalation_id": {
          "type": "string",
          "format": "uuid"
        },
        "org_id": {
          "type": "string",
          "format": "uuid"
        },
        "project_id": {
          "type": [
            "string",
            "null"
          ],
          "description": "Soft reference — the escalation outlives the project's deletion."
        },
        "raised_by": {
          "type": "object",
          "properties": {
            "kind": {
              "type": "string",
              "enum": [
                "principal",
                "rule"
              ],
              "description": "event-attention-rules: `rule` when a routing rule with channel escalation raised it — then principal_id is null and rule_id / rule_owner_email name the rule and who set it (rule_id is null once that rule is deleted)."
            },
            "principal_id": {
              "type": [
                "string",
                "null"
              ],
              "format": "uuid"
            },
            "rule_id": {
              "type": [
                "string",
                "null"
              ],
              "format": "uuid"
            },
            "rule_owner_email": {
              "type": [
                "string",
                "null"
              ]
            },
            "grant_key_id": {
              "type": [
                "string",
                "null"
              ],
              "format": "uuid"
            },
            "presence_name": {
              "type": [
                "string",
                "null"
              ]
            }
          }
        },
        "severity": {
          "type": "string",
          "enum": [
            "normal",
            "high"
          ]
        },
        "reason": {
          "type": "string",
          "description": "The agent's argument, verbatim. Rendered as DATA everywhere it is shown. For a rule raise, the platform's composed account of the event or window: what happened, where, the bounded facts, and who set the rule."
        },
        "attached_count": {
          "type": "integer",
          "description": "event-attention-rules: further matches of the raising rule that joined this escalation while it was open or acknowledged, instead of paging again. Always 0 for an agent raise."
        },
        "last_attached_at": {
          "type": [
            "string",
            "null"
          ],
          "format": "date-time"
        },
        "details": {
          "type": "object",
          "description": "Structured sidecar. Readable here; never rendered into a page."
        },
        "status": {
          "type": "string",
          "enum": [
            "open",
            "acknowledged",
            "resolved"
          ]
        },
        "level": {
          "type": "integer",
          "description": "Which contact level is currently paged."
        },
        "raised_at": {
          "type": "string",
          "format": "date-time"
        },
        "deadline_at": {
          "type": "string",
          "format": "date-time",
          "description": "When an unacknowledged escalation climbs to the next level."
        },
        "acknowledged": {
          "type": [
            "object",
            "null"
          ],
          "properties": {
            "at": {
              "type": "string",
              "format": "date-time"
            },
            "by_email": {
              "type": [
                "string",
                "null"
              ]
            },
            "channel": {
              "type": "string",
              "enum": [
                "token",
                "authenticated"
              ]
            }
          }
        },
        "resolved": {
          "type": [
            "object",
            "null"
          ],
          "properties": {
            "at": {
              "type": "string",
              "format": "date-time"
            },
            "by_email": {
              "type": [
                "string",
                "null"
              ]
            },
            "note": {
              "type": [
                "string",
                "null"
              ]
            }
          }
        },
        "climbs": {
          "type": "array",
          "description": "Append-only deadman history.",
          "items": {
            "type": "object",
            "properties": {
              "from_level": {
                "type": "integer"
              },
              "to_level": {
                "type": "integer"
              },
              "at": {
                "type": "string",
                "format": "date-time"
              },
              "reason": {
                "type": "string",
                "enum": [
                  "deadline_lapsed"
                ]
              }
            }
          }
        },
        "repage_count": {
          "type": "integer",
          "description": "Top-level re-pages so far. At the bound the row rests OPEN — never auto-resolved."
        },
        "delivery_attempts": {
          "type": "array",
          "description": "Only when include=delivery. What ACTUALLY happened on the wire, read from the audit log rather than assumed.",
          "items": {
            "type": "object",
            "properties": {
              "email": {
                "type": "string"
              },
              "channel": {
                "type": "string"
              },
              "status": {
                "type": "string"
              },
              "error": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "at": {
                "type": "string",
                "format": "date-time"
              }
            }
          }
        }
      }
    }
  }
}