{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "properties": {
    "capabilities": {
      "items": {
        "oneOf": [
          {
            "properties": {
              "actions": {
                "items": {
                  "enum": [
                    "generate"
                  ],
                  "type": "string"
                },
                "minItems": 1,
                "type": "array"
              },
              "credential_owner": {
                "const": "workspace",
                "type": "string"
              },
              "id": {
                "const": "ai.generate",
                "type": "string"
              },
              "provider": {
                "properties": {
                  "allow": {
                    "items": {
                      "type": "string"
                    },
                    "type": "array"
                  },
                  "fallback": {
                    "enum": [
                      "none",
                      "listed"
                    ],
                    "type": "string"
                  },
                  "prefer": {
                    "type": "string"
                  }
                },
                "required": [
                  "allow",
                  "fallback"
                ],
                "type": "object"
              },
              "required": {
                "type": "boolean"
              },
              "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",
              "required",
              "actions",
              "scope",
              "credential_owner",
              "provider"
            ],
            "type": "object"
          },
          {
            "properties": {
              "actions": {
                "items": {
                  "enum": [
                    "read",
                    "write",
                    "delete",
                    "list"
                  ],
                  "type": "string"
                },
                "minItems": 1,
                "type": "array"
              },
              "credential_owner": {
                "const": "workspace",
                "type": "string"
              },
              "id": {
                "const": "storage.object",
                "type": "string"
              },
              "provider": {
                "properties": {
                  "allow": {
                    "items": {
                      "type": "string"
                    },
                    "type": "array"
                  },
                  "fallback": {
                    "enum": [
                      "none",
                      "listed"
                    ],
                    "type": "string"
                  },
                  "prefer": {
                    "type": "string"
                  }
                },
                "required": [
                  "allow",
                  "fallback"
                ],
                "type": "object"
              },
              "required": {
                "type": "boolean"
              },
              "scope": {
                "properties": {
                  "max_object_bytes": {
                    "exclusiveMinimum": 0,
                    "maximum": 9007199254740991,
                    "type": "integer"
                  },
                  "prefix": {
                    "pattern": "^\\/(?!.*\\.\\.).*$",
                    "type": "string"
                  }
                },
                "required": [
                  "prefix",
                  "max_object_bytes"
                ],
                "type": "object"
              }
            },
            "required": [
              "id",
              "required",
              "actions",
              "scope",
              "credential_owner",
              "provider"
            ],
            "type": "object"
          },
          {
            "properties": {
              "actions": {
                "items": {
                  "enum": [
                    "get",
                    "set",
                    "delete",
                    "list",
                    "increment"
                  ],
                  "type": "string"
                },
                "minItems": 1,
                "type": "array"
              },
              "credential_owner": {
                "const": "platform",
                "type": "string"
              },
              "id": {
                "const": "data.kv",
                "type": "string"
              },
              "provider": {
                "properties": {
                  "allow": {
                    "items": {
                      "const": "platform",
                      "type": "string"
                    },
                    "maxItems": 1,
                    "minItems": 1,
                    "type": "array"
                  },
                  "fallback": {
                    "const": "none",
                    "type": "string"
                  },
                  "prefer": {
                    "const": "platform",
                    "type": "string"
                  }
                },
                "required": [
                  "allow",
                  "fallback"
                ],
                "type": "object"
              },
              "required": {
                "type": "boolean"
              },
              "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",
              "required",
              "actions",
              "scope",
              "credential_owner",
              "provider"
            ],
            "type": "object"
          },
          {
            "properties": {
              "actions": {
                "items": {
                  "enum": [
                    "send"
                  ],
                  "type": "string"
                },
                "minItems": 1,
                "type": "array"
              },
              "credential_owner": {
                "const": "workspace",
                "type": "string"
              },
              "id": {
                "const": "email.send",
                "type": "string"
              },
              "provider": {
                "properties": {
                  "allow": {
                    "items": {
                      "type": "string"
                    },
                    "type": "array"
                  },
                  "fallback": {
                    "enum": [
                      "none",
                      "listed"
                    ],
                    "type": "string"
                  },
                  "prefer": {
                    "type": "string"
                  }
                },
                "required": [
                  "allow",
                  "fallback"
                ],
                "type": "object"
              },
              "required": {
                "type": "boolean"
              },
              "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",
              "required",
              "actions",
              "scope",
              "credential_owner",
              "provider"
            ],
            "type": "object"
          }
        ]
      },
      "type": "array"
    },
    "confirmed_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"
    },
    "contract_hash": {
      "pattern": "^[0-9a-f]{64}$",
      "type": "string"
    },
    "product_id": {
      "pattern": "^prod_[0-7][0123456789abcdefghjkmnpqrstvwxyz]{25}$",
      "type": "string"
    },
    "revision_id": {
      "pattern": "^rev_[0-7][0123456789abcdefghjkmnpqrstvwxyz]{25}$",
      "type": "string"
    },
    "workspace_id": {
      "pattern": "^ws_[0-7][0123456789abcdefghjkmnpqrstvwxyz]{25}$",
      "type": "string"
    }
  },
  "required": [
    "product_id",
    "revision_id",
    "workspace_id",
    "capabilities",
    "contract_hash",
    "confirmed_at"
  ],
  "type": "object"
}
