{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/cotal-ai/json-schema/cotal-ai-exchange-request-schema.json",
  "title": "ExchangeRequest",
  "description": "Provide idpToken for a human OR owner plus actorToken for a managed agent, never both. Agent view may only be manager-caller. managerInstanceId requires manager-caller; sessionGrant accompanies session-caller; transferWriter accompanies transfer-writer. Native SessionGrant is verified against the redeemed session ledger; the nested schema documents its transport shape only.",
  "x-generated": "2026-11-04",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/cotal-ai-auth-openapi.yml#/components/schemas/ExchangeRequest",
  "type": "object",
  "properties": {
    "idpToken": {
      "type": "string",
      "minLength": 1
    },
    "owner": {
      "type": "string",
      "minLength": 1
    },
    "actor": {
      "type": "string",
      "minLength": 1
    },
    "actorToken": {
      "type": "string",
      "minLength": 1
    },
    "ttlSec": {
      "type": "number"
    },
    "view": {
      "type": "string",
      "enum": [
        "channel-writer",
        "channel-purger",
        "manager-caller",
        "session-caller",
        "transfer-writer"
      ]
    },
    "managerInstanceId": {
      "type": "string"
    },
    "sessionGrant": {
      "type": "object",
      "properties": {
        "sessionId": {
          "type": "string",
          "minLength": 1
        },
        "endpoint": {
          "type": "string",
          "minLength": 1
        },
        "serving": {
          "type": "object",
          "properties": {
            "instanceId": {
              "type": "string",
              "minLength": 1
            },
            "epoch": {
              "type": "integer",
              "minimum": 0
            }
          },
          "required": [
            "instanceId",
            "epoch"
          ]
        },
        "sig": {
          "type": "string",
          "minLength": 1
        },
        "v": {
          "const": 1
        },
        "space": {
          "type": "string",
          "minLength": 1
        },
        "subjects": {
          "type": "object",
          "required": [
            "in",
            "out"
          ],
          "properties": {
            "in": {
              "type": "string",
              "minLength": 1
            },
            "out": {
              "type": "string",
              "minLength": 1
            }
          }
        },
        "holder": {
          "type": "object",
          "required": [
            "id",
            "lifecycleUid",
            "processEpoch"
          ],
          "properties": {
            "id": {
              "type": "string",
              "minLength": 1
            },
            "lifecycleUid": {
              "type": "string",
              "minLength": 1
            },
            "processEpoch": {
              "type": "integer",
              "minimum": 0
            }
          }
        },
        "window": {
          "type": "integer",
          "minimum": 0
        },
        "iat": {
          "type": "integer",
          "minimum": 0
        },
        "nbf": {
          "type": "integer",
          "minimum": 0
        },
        "exp": {
          "type": "integer",
          "minimum": 0
        },
        "nonce": {
          "type": "string",
          "minLength": 1
        },
        "issuer": {
          "type": "object",
          "required": [
            "keyId"
          ],
          "properties": {
            "keyId": {
              "type": "string",
              "minLength": 1
            }
          }
        }
      },
      "required": [],
      "description": "Transport envelope only. Nested native fields and operation-specific constraints are defined by SessionGrant in the linked source; this schema is not a complete native command contract.",
      "x-native-contract": {
        "name": "SessionGrant",
        "url": "https://github.com/Cotal-AI/Cotal/blob/main/packages/core/src/endpoint-session.ts"
      }
    },
    "transferWriter": {
      "type": "object",
      "properties": {
        "instanceId": {
          "type": "string",
          "minLength": 1
        },
        "hex": {
          "type": "string",
          "minLength": 1
        }
      },
      "required": [
        "instanceId",
        "hex"
      ]
    }
  },
  "required": [
    "actor"
  ],
  "oneOf": [
    {
      "required": [
        "idpToken"
      ],
      "not": {
        "required": [
          "actorToken"
        ]
      },
      "title": "Human identity"
    },
    {
      "required": [
        "owner",
        "actorToken"
      ],
      "not": {
        "required": [
          "idpToken"
        ]
      },
      "title": "Managed agent"
    }
  ]
}