{
  "$id": "https://sessionpipe.org/schema/v1/control-command.json",
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "v": {
      "type": "number",
      "const": 1
    },
    "t": {
      "type": "string",
      "const": "sessionpipe.control"
    },
    "machine": {
      "type": "string",
      "pattern": "^m_[A-Za-z0-9_-]{16,40}$"
    },
    "kind": {
      "type": "string",
      "enum": [
        "prompt",
        "permission.answer",
        "cancel",
        "start",
        "key.add",
        "pool"
      ]
    },
    "session": {
      "type": "string",
      "pattern": "^[a-z][a-z0-9-]{0,39}:[A-Za-z0-9._:-]{1,128}$"
    },
    "text": {
      "type": "string",
      "minLength": 1,
      "maxLength": 20000
    },
    "for": {
      "type": "string",
      "minLength": 1,
      "maxLength": 128
    },
    "decision": {
      "type": "string",
      "enum": [
        "allow",
        "deny"
      ]
    },
    "note": {
      "type": "string",
      "maxLength": 2000
    },
    "cwd": {
      "type": "string",
      "maxLength": 1024
    },
    "key": {
      "oneOf": [
        {
          "type": "object",
          "properties": {
            "id": {
              "type": "string",
              "minLength": 16,
              "maxLength": 1400,
              "pattern": "^[A-Za-z0-9_-]*$"
            },
            "alg": {
              "anyOf": [
                {
                  "type": "number",
                  "const": -7
                },
                {
                  "type": "number",
                  "const": -257
                }
              ]
            },
            "spki": {
              "type": "string",
              "minLength": 1,
              "pattern": "^[A-Za-z0-9_-]*$"
            }
          },
          "required": [
            "id",
            "alg",
            "spki"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "id": {
              "type": "string",
              "pattern": "^[A-Za-z0-9_-]{43}$"
            },
            "alg": {
              "type": "number",
              "const": -7
            },
            "spki": {
              "type": "string",
              "minLength": 1,
              "pattern": "^[A-Za-z0-9_-]*$"
            },
            "type": {
              "type": "string",
              "const": "device"
            },
            "store": {
              "type": "string",
              "const": "hardware"
            },
            "uv": {
              "type": "string",
              "const": "each-use"
            }
          },
          "required": [
            "id",
            "alg",
            "spki",
            "type",
            "store",
            "uv"
          ],
          "additionalProperties": false
        }
      ]
    },
    "name": {
      "type": "string",
      "minLength": 1,
      "maxLength": 80
    },
    "files": {
      "minItems": 1,
      "maxItems": 10,
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string",
            "minLength": 1,
            "maxLength": 200,
            "pattern": "^[^./\\\\\\x00-\\x1f\\x7f][^/\\\\\\x00-\\x1f\\x7f]*$"
          },
          "type": {
            "type": "string",
            "minLength": 1,
            "maxLength": 100,
            "pattern": "^[A-Za-z0-9][A-Za-z0-9!#$&^_.+-]*\\/[A-Za-z0-9][A-Za-z0-9!#$&^_.+-]*$"
          },
          "size": {
            "type": "integer",
            "minimum": 1,
            "maximum": 26214400
          },
          "sha256": {
            "type": "string",
            "pattern": "^[A-Za-z0-9_-]{43}$"
          }
        },
        "required": [
          "name",
          "type",
          "size",
          "sha256"
        ]
      }
    },
    "permission": {
      "type": "string",
      "enum": [
        "read",
        "safe",
        "edits",
        "auto"
      ]
    },
    "model": {
      "type": "string",
      "minLength": 1,
      "maxLength": 100,
      "pattern": "^[A-Za-z0-9][A-Za-z0-9._:/@[\\]-]*$"
    },
    "pool_action": {
      "type": "string",
      "enum": [
        "on",
        "off",
        "enable",
        "disable",
        "remove",
        "order",
        "refresh",
        "login.begin",
        "login.complete"
      ]
    },
    "pool_account": {
      "type": "string",
      "pattern": "^[A-Za-z0-9._:-]{1,128}$"
    },
    "pool_order": {
      "minItems": 1,
      "maxItems": 20,
      "type": "array",
      "items": {
        "type": "string",
        "pattern": "^[A-Za-z0-9._:-]{1,128}$"
      },
      "uniqueItems": true
    },
    "pool_code": {
      "type": "string",
      "minLength": 1,
      "maxLength": 512,
      "pattern": "^[^\\r\\n]+$"
    },
    "reply_to": {
      "type": "string",
      "pattern": "^[a-z][a-z0-9-]{0,39}:[A-Za-z0-9._:-]{1,128}$"
    },
    "nonce": {
      "type": "string",
      "pattern": "^[A-Za-z0-9_-]{22,64}$"
    },
    "iat": {
      "type": "integer",
      "minimum": 1,
      "maximum": 9007199254740991
    }
  },
  "required": [
    "v",
    "t",
    "machine",
    "kind",
    "session",
    "nonce",
    "iat"
  ]
}
