{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/run402-com/json-schema/run402-com-agent-message-page-schema.json",
  "title": "AgentMessagePage",
  "x-generated": "2026-11-10",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/run402-com-agentmessaging-api-openapi.yml#/components/schemas/AgentMessagePage",
  "type": "object",
  "properties": {
    "messages": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/AgentMessage"
      }
    },
    "cursor": {
      "type": "string",
      "description": "High-water mark — pass as ?cursor= next time."
    },
    "has_more": {
      "type": "boolean"
    },
    "reset": {
      "type": "boolean",
      "description": "Present (true) when the supplied cursor was unusable; resume from earliest_cursor."
    },
    "earliest_cursor": {
      "type": "string"
    },
    "before_cursor": {
      "type": "string",
      "description": "desc mode: bound for the next OLDER page, present while older rows remain."
    },
    "waited_ms": {
      "type": [
        "integer",
        "null"
      ],
      "description": "kygit-invite (design D6/D7). Present only when the request carried `wait=<seconds>` — how long the gateway held before answering. A page returned WITHOUT this field means the gateway did not hold (an older gateway, or `wait` omitted); a client's own `waitForMessages` treats its absence as the degrade-to-polling signal."
    },
    "live_presences": {
      "type": "array",
      "description": "kygit-invite (design D6/D7). Present only alongside `waited_ms` — the room's live presences at the moment the held read answered, the caller's own resolved presence excluded when resolvable. Rides even a timed-out (silent) page, so \"is the other agent still here\" is answered with no second call.",
      "items": {
        "type": "object",
        "additionalProperties": true
      }
    }
  },
  "required": [
    "messages",
    "cursor",
    "has_more"
  ],
  "$defs": {
    "AgentMessage": {
      "type": "object",
      "description": "A room-visible agent message. Lists carry body_snippet only; the get-one read includes the full body.",
      "properties": {
        "message_id": {
          "type": "string",
          "description": "Opaque id, msg_ prefixed."
        },
        "cursor": {
          "type": "string",
          "description": "This row's opaque feed cursor (mcr_ prefixed) — a valid ?cursor= value."
        },
        "room_key": {
          "type": "string"
        },
        "sender": {
          "type": "string",
          "description": "Sender presence name."
        },
        "body_snippet": {
          "type": "string"
        },
        "body_truncated": {
          "type": "boolean"
        },
        "body": {
          "type": "string",
          "description": "Full markdown body (get-one only)."
        },
        "thread_id": {
          "type": [
            "string",
            "null"
          ]
        },
        "importance": {
          "type": "string",
          "enum": [
            "normal",
            "high"
          ]
        },
        "ack_required": {
          "type": "boolean"
        },
        "recipients": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/AgentMessageRecipient"
          }
        },
        "created_at": {
          "type": "string",
          "format": "date-time"
        }
      },
      "required": [
        "message_id",
        "cursor",
        "room_key",
        "sender",
        "body_snippet",
        "body_truncated",
        "importance",
        "recipients",
        "created_at"
      ]
    },
    "AgentMessageRecipient": {
      "type": "object",
      "properties": {
        "name": {
          "type": "string"
        },
        "kind": {
          "type": "string",
          "enum": [
            "to",
            "cc"
          ]
        },
        "ack_required": {
          "type": "boolean"
        },
        "acked_at": {
          "type": [
            "string",
            "null"
          ],
          "format": "date-time"
        }
      },
      "required": [
        "name",
        "kind",
        "ack_required"
      ]
    }
  }
}