{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "properties": {
    "actions": {
      "items": {
        "type": "string"
      },
      "minItems": 1,
      "type": "array"
    },
    "binding_id": {
      "pattern": "^bind_[0-7][0123456789abcdefghjkmnpqrstvwxyz]{25}$",
      "type": "string"
    },
    "capability": {
      "type": "string"
    },
    "capability_scope": {
      "oneOf": [
        {
          "properties": {
            "id": {
              "const": "ai.generate",
              "type": "string"
            },
            "provider_models": {
              "properties": {
                "embedding": {
                  "minLength": 1,
                  "type": "string"
                },
                "text": {
                  "minLength": 1,
                  "type": "string"
                }
              },
              "type": "object"
            },
            "scope": {
              "properties": {
                "max_tokens_per_call": {
                  "exclusiveMinimum": 0,
                  "maximum": 9007199254740991,
                  "type": "integer"
                },
                "models": {
                  "items": {
                    "enum": [
                      "text",
                      "embedding"
                    ],
                    "type": "string"
                  },
                  "minItems": 1,
                  "type": "array"
                }
              },
              "required": [
                "models",
                "max_tokens_per_call"
              ],
              "type": "object"
            }
          },
          "required": [
            "id",
            "scope",
            "provider_models"
          ],
          "type": "object"
        },
        {
          "properties": {
            "id": {
              "const": "storage.object",
              "type": "string"
            },
            "scope": {
              "properties": {
                "max_object_bytes": {
                  "exclusiveMinimum": 0,
                  "maximum": 9007199254740991,
                  "type": "integer"
                },
                "prefix": {
                  "pattern": "^\\/(?!.*\\.\\.).*$",
                  "type": "string"
                }
              },
              "required": [
                "prefix",
                "max_object_bytes"
              ],
              "type": "object"
            }
          },
          "required": [
            "id",
            "scope"
          ],
          "type": "object"
        },
        {
          "properties": {
            "id": {
              "const": "data.kv",
              "type": "string"
            },
            "scope": {
              "properties": {
                "max_keys": {
                  "exclusiveMinimum": 0,
                  "maximum": 100000,
                  "type": "integer"
                },
                "max_value_bytes": {
                  "exclusiveMinimum": 0,
                  "maximum": 65536,
                  "type": "integer"
                },
                "prefix": {
                  "pattern": "^\\/(?!.*\\.\\.).*$",
                  "type": "string"
                }
              },
              "required": [
                "prefix",
                "max_value_bytes",
                "max_keys"
              ],
              "type": "object"
            }
          },
          "required": [
            "id",
            "scope"
          ],
          "type": "object"
        },
        {
          "properties": {
            "id": {
              "const": "email.send",
              "type": "string"
            },
            "scope": {
              "properties": {
                "from_addresses": {
                  "items": {
                    "maxLength": 254,
                    "pattern": "^(?!.*[A-Z])(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|\"(?:[ !#-[\\]-~]|\\\\[ -~])*\")@(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\\.)*[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$",
                    "type": "string"
                  },
                  "maxItems": 32,
                  "minItems": 1,
                  "type": "array"
                },
                "max_message_bytes": {
                  "exclusiveMinimum": 0,
                  "maximum": 1048576,
                  "type": "integer"
                },
                "max_recipients": {
                  "maximum": 50,
                  "minimum": 1,
                  "type": "integer"
                },
                "recipient_domains": {
                  "items": {
                    "maxLength": 253,
                    "pattern": "^(?:\\*|(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\\.)*[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)$",
                    "type": "string"
                  },
                  "maxItems": 32,
                  "minItems": 1,
                  "type": "array"
                }
              },
              "required": [
                "from_addresses",
                "recipient_domains",
                "max_recipients",
                "max_message_bytes"
              ],
              "type": "object"
            }
          },
          "required": [
            "id",
            "scope"
          ],
          "type": "object"
        }
      ]
    },
    "expires_at": {
      "format": "date-time",
      "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(?:\\.\\d+)?(?:Z))$",
      "type": "string"
    },
    "outcome": {
      "enum": [
        "ready",
        "failed",
        "revoked"
      ],
      "type": "string"
    },
    "owner_kind": {
      "enum": [
        "workspace",
        "publisher",
        "consumer",
        "platform"
      ],
      "type": "string"
    },
    "provider": {
      "type": "string"
    },
    "reason": {
      "type": [
        "string",
        "null"
      ]
    },
    "scope": {
      "items": {
        "type": "string"
      },
      "type": "array"
    },
    "workspace_id": {
      "anyOf": [
        {
          "pattern": "^ws_[0-7][0123456789abcdefghjkmnpqrstvwxyz]{25}$",
          "type": "string"
        },
        {
          "const": "ws_platform",
          "type": "string"
        }
      ]
    }
  },
  "required": [
    "binding_id",
    "workspace_id",
    "owner_kind",
    "provider",
    "capability",
    "actions",
    "scope",
    "outcome",
    "reason",
    "expires_at"
  ],
  "type": "object"
}
