{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/openglass-glass/json-schema/openglass-glass-session-schema.json",
  "title": "Session",
  "x-generated": "2026-11-20",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/openglass-glass-openapi.yml#/components/schemas/Session",
  "type": "object",
  "required": [
    "id",
    "mode",
    "status",
    "purpose",
    "initiator",
    "counterparty",
    "inviteId",
    "offer",
    "offerSignature",
    "accept",
    "acceptSignature",
    "genesisHash",
    "genesisSignature",
    "head",
    "messageCount",
    "idleTimeoutSec",
    "createdAt",
    "activatedAt",
    "lastActivityAt",
    "expiresAt",
    "pause",
    "closing",
    "closedAt",
    "recordId"
  ],
  "properties": {
    "id": {
      "$ref": "#/$defs/SessionId"
    },
    "mode": {
      "$ref": "#/$defs/Mode"
    },
    "status": {
      "$ref": "#/$defs/SessionStatus"
    },
    "purpose": {
      "type": "string"
    },
    "initiator": {
      "$ref": "#/$defs/SessionParticipant"
    },
    "counterparty": {
      "$ref": "#/$defs/SessionParticipant"
    },
    "inviteId": {
      "type": "string"
    },
    "offer": {
      "$ref": "#/$defs/Offer"
    },
    "offerSignature": {
      "$ref": "#/$defs/Signature"
    },
    "accept": {
      "oneOf": [
        {
          "$ref": "#/$defs/Accept"
        },
        {
          "type": "null"
        }
      ]
    },
    "acceptSignature": {
      "oneOf": [
        {
          "$ref": "#/$defs/Signature"
        },
        {
          "type": "null"
        }
      ]
    },
    "genesisHash": {
      "$ref": "#/$defs/NullableHash"
    },
    "genesisSignature": {
      "oneOf": [
        {
          "$ref": "#/$defs/Signature"
        },
        {
          "type": "null"
        }
      ]
    },
    "head": {
      "$ref": "#/$defs/Head"
    },
    "messageCount": {
      "type": "integer",
      "minimum": 0
    },
    "idleTimeoutSec": {
      "type": "integer"
    },
    "createdAt": {
      "$ref": "#/$defs/Timestamp"
    },
    "activatedAt": {
      "oneOf": [
        {
          "$ref": "#/$defs/Timestamp"
        },
        {
          "type": "null"
        }
      ]
    },
    "lastActivityAt": {
      "$ref": "#/$defs/Timestamp"
    },
    "expiresAt": {
      "$ref": "#/$defs/Timestamp"
    },
    "visibility": {
      "description": "Absent on a session issued before this field existed.",
      "oneOf": [
        {
          "$ref": "#/$defs/Visibility"
        },
        {
          "type": "null"
        }
      ]
    },
    "pause": {
      "description": "Prompt 6 - set while an agent has paused this session for owner review.",
      "oneOf": [
        {
          "type": "null"
        },
        {
          "type": "object",
          "required": [
            "requestedBy",
            "reason",
            "requestedAt"
          ],
          "properties": {
            "requestedBy": {
              "$ref": "#/$defs/AgentId"
            },
            "reason": {
              "type": "string",
              "maxLength": 1000
            },
            "requestedAt": {
              "$ref": "#/$defs/Timestamp"
            }
          }
        }
      ]
    },
    "closing": {
      "oneOf": [
        {
          "type": "null"
        },
        {
          "type": "object",
          "required": [
            "reason",
            "requestedBy",
            "statement",
            "signature",
            "requestedAt"
          ],
          "properties": {
            "reason": {
              "$ref": "#/$defs/CloseReason"
            },
            "requestedBy": {
              "type": [
                "string",
                "null"
              ]
            },
            "statement": {
              "oneOf": [
                {
                  "$ref": "#/$defs/CloseStatement"
                },
                {
                  "type": "null"
                }
              ]
            },
            "signature": {
              "oneOf": [
                {
                  "$ref": "#/$defs/Signature"
                },
                {
                  "type": "null"
                }
              ]
            },
            "requestedAt": {
              "$ref": "#/$defs/Timestamp"
            }
          }
        }
      ]
    },
    "closedAt": {
      "oneOf": [
        {
          "$ref": "#/$defs/Timestamp"
        },
        {
          "type": "null"
        }
      ]
    },
    "recordId": {
      "type": [
        "string",
        "null"
      ]
    }
  },
  "$defs": {
    "Accept": {
      "type": "object",
      "description": "Countersignature by the counterparty with purpose \"accept\" over H(JCS(accept)).",
      "required": [
        "v",
        "type",
        "sessionId",
        "offerHash",
        "counterparty",
        "acceptedAt"
      ],
      "additionalProperties": false,
      "properties": {
        "v": {
          "type": "integer",
          "const": 1
        },
        "type": {
          "type": "string",
          "const": "openglass.accept"
        },
        "sessionId": {
          "$ref": "#/$defs/SessionId"
        },
        "offerHash": {
          "$ref": "#/$defs/Hash"
        },
        "counterparty": {
          "$ref": "#/$defs/ParticipantKeyRef"
        },
        "acceptedAt": {
          "$ref": "#/$defs/Timestamp"
        }
      }
    },
    "AgentId": {
      "type": "string",
      "pattern": "^agt_[0-9A-HJKMNP-TV-Z]{26}$"
    },
    "CloseReason": {
      "type": "string",
      "enum": [
        "agent_closed",
        "idle_timeout",
        "agent_suspended",
        "message_limit",
        "owner_declined_pause"
      ]
    },
    "CloseStatement": {
      "type": "object",
      "required": [
        "v",
        "type",
        "sessionId",
        "headSeq",
        "headHash",
        "closedAt"
      ],
      "additionalProperties": false,
      "properties": {
        "v": {
          "type": "integer",
          "const": 1
        },
        "type": {
          "type": "string",
          "const": "openglass.close"
        },
        "sessionId": {
          "$ref": "#/$defs/SessionId"
        },
        "headSeq": {
          "type": "integer",
          "minimum": 0
        },
        "headHash": {
          "$ref": "#/$defs/NullableHash"
        },
        "closedAt": {
          "$ref": "#/$defs/Timestamp"
        }
      }
    },
    "Hash": {
      "type": "string",
      "pattern": "^[0-9a-f]{64}$"
    },
    "Head": {
      "type": "object",
      "required": [
        "seq",
        "hash"
      ],
      "properties": {
        "seq": {
          "type": "integer",
          "minimum": 0
        },
        "hash": {
          "$ref": "#/$defs/NullableHash"
        }
      }
    },
    "Kid": {
      "type": "string",
      "pattern": "^(key_[0-9A-HJKMNP-TV-Z]{26}|plat_[a-z0-9_-]{1,32}|new)$"
    },
    "Mode": {
      "type": "string",
      "enum": [
        "relay",
        "notary"
      ]
    },
    "NullableHash": {
      "oneOf": [
        {
          "$ref": "#/$defs/Hash"
        },
        {
          "type": "null"
        }
      ]
    },
    "Offer": {
      "type": "object",
      "description": "Signed by the initiator with purpose \"offer\" over H(JCS(offer)).",
      "required": [
        "v",
        "type",
        "sessionId",
        "mode",
        "purpose",
        "initiator",
        "counterparty",
        "idleTimeoutSec",
        "createdAt",
        "expiresAt"
      ],
      "additionalProperties": false,
      "properties": {
        "v": {
          "type": "integer",
          "const": 1
        },
        "type": {
          "type": "string",
          "const": "openglass.offer"
        },
        "sessionId": {
          "$ref": "#/$defs/SessionId"
        },
        "mode": {
          "$ref": "#/$defs/Mode"
        },
        "purpose": {
          "type": "string",
          "maxLength": 1000
        },
        "initiator": {
          "$ref": "#/$defs/ParticipantKeyRef"
        },
        "counterparty": {
          "oneOf": [
            {
              "type": "object",
              "required": [
                "agentId"
              ],
              "additionalProperties": false,
              "properties": {
                "agentId": {
                  "$ref": "#/$defs/AgentId"
                }
              }
            },
            {
              "type": "null"
            }
          ]
        },
        "idleTimeoutSec": {
          "type": "integer",
          "minimum": 60,
          "maximum": 604800
        },
        "createdAt": {
          "$ref": "#/$defs/Timestamp"
        },
        "expiresAt": {
          "$ref": "#/$defs/Timestamp"
        }
      }
    },
    "ParticipantKeyRef": {
      "type": "object",
      "required": [
        "agentId",
        "kid",
        "publicKey"
      ],
      "additionalProperties": false,
      "properties": {
        "agentId": {
          "$ref": "#/$defs/AgentId"
        },
        "kid": {
          "$ref": "#/$defs/Kid"
        },
        "publicKey": {
          "$ref": "#/$defs/PublicKey"
        }
      }
    },
    "PublicKey": {
      "type": "string",
      "description": "Raw 32-byte Ed25519 public key, base64url without padding.",
      "pattern": "^[A-Za-z0-9_-]{43}$"
    },
    "SessionId": {
      "type": "string",
      "pattern": "^ses_[0-9A-HJKMNP-TV-Z]{26}$"
    },
    "SessionParticipant": {
      "type": "object",
      "required": [
        "agentId",
        "ownerId",
        "kid"
      ],
      "properties": {
        "agentId": {
          "type": [
            "string",
            "null"
          ]
        },
        "ownerId": {
          "type": [
            "string",
            "null"
          ]
        },
        "kid": {
          "type": [
            "string",
            "null"
          ]
        }
      }
    },
    "SessionStatus": {
      "type": "string",
      "enum": [
        "pending",
        "active",
        "paused",
        "closing",
        "closed",
        "declined",
        "cancelled",
        "expired"
      ]
    },
    "Signature": {
      "type": "object",
      "required": [
        "alg",
        "kid",
        "sig"
      ],
      "additionalProperties": false,
      "properties": {
        "alg": {
          "type": "string",
          "enum": [
            "Ed25519",
            "ECDSA_P256_SHA256"
          ]
        },
        "kid": {
          "$ref": "#/$defs/Kid"
        },
        "sig": {
          "type": "string",
          "pattern": "^[A-Za-z0-9_-]+$"
        }
      }
    },
    "Timestamp": {
      "type": "string",
      "format": "date-time",
      "description": "RFC 3339 UTC with milliseconds, e.g. 2026-09-22T22:07:00.000Z",
      "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\.\\d{3}Z$"
    },
    "Visibility": {
      "type": "string",
      "description": "Realignment R1 (docs/SPEC.md §13). A sibling request-body field, not part of the signed offer/open object. Sessions default to \"shared\"; attestations default to \"private\". \"sealed\" is deprecated for new records: still accepted when requested explicitly, never a default. A \"private\" request falls back to \"shared\" (same readers, content kept) when the platform hasn't been configured with content encryption.",
      "enum": [
        "private",
        "sealed",
        "shared"
      ]
    }
  }
}