{
  "openapi": "3.1.0",
  "info": {
    "title": "Agentic API",
    "version": "0.1.0",
    "description": "The API of the product. Every request that changes something carries an Idempotency-Key header. Sign in with a session cookie or an API token."
  },
  "servers": [
    {
      "url": "https://app.agentic.figentra.com"
    }
  ],
  "paths": {
    "/api/health": {
      "get": {
        "operationId": "getHealth",
        "summary": "Health of the platform Worker.",
        "parameters": [],
        "security": [],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$schema": "https://json-schema.org/draft/2020-12/schema",
                  "type": "object",
                  "properties": {
                    "ok": {
                      "type": "boolean"
                    },
                    "service": {
                      "type": "string",
                      "minLength": 1
                    },
                    "version": {
                      "type": "string",
                      "minLength": 1
                    },
                    "time": {
                      "type": "string",
                      "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))$"
                    }
                  },
                  "required": [
                    "ok",
                    "service",
                    "version",
                    "time"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "default": {
            "description": "Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            }
          }
        }
      }
    },
    "/api/openapi.json": {
      "get": {
        "operationId": "getOpenApi",
        "summary": "This API's OpenAPI document.",
        "parameters": [],
        "security": [],
        "responses": {
          "200": {
            "description": "Not JSON (a socket upgrade or this document)"
          },
          "default": {
            "description": "Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            }
          }
        }
      }
    },
    "/api/me": {
      "get": {
        "operationId": "getMe",
        "summary": "The signed-in user, their organisations and roles.",
        "parameters": [],
        "security": [
          {
            "session": []
          },
          {
            "token": []
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$schema": "https://json-schema.org/draft/2020-12/schema",
                  "type": "object",
                  "properties": {
                    "user": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "type": "string",
                          "pattern": "^usr_[0-9A-Za-z]{8,64}$"
                        },
                        "name": {
                          "type": "string"
                        },
                        "email": {
                          "type": "string",
                          "format": "email",
                          "pattern": "^(?:[A-Za-z0-9_'+\\-]+\\.)*[A-Za-z0-9_'+\\-]*[A-Za-z0-9_+-]@(?:[A-Za-z0-9][A-Za-z0-9\\-]*\\.)+[A-Za-z]{2,}$"
                        },
                        "emailVerified": {
                          "type": "boolean"
                        },
                        "image": {
                          "anyOf": [
                            {
                              "type": "string",
                              "format": "uri"
                            },
                            {
                              "type": "null"
                            }
                          ]
                        },
                        "createdAt": {
                          "type": "string",
                          "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))$"
                        }
                      },
                      "required": [
                        "id",
                        "name",
                        "email",
                        "emailVerified",
                        "image",
                        "createdAt"
                      ],
                      "additionalProperties": false
                    },
                    "memberships": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "memberId": {
                            "type": "string",
                            "pattern": "^mem_[0-9A-Za-z]{8,64}$"
                          },
                          "organisation": {
                            "type": "object",
                            "properties": {
                              "id": {
                                "type": "string",
                                "pattern": "^org_[0-9A-Za-z]{8,64}$"
                              },
                              "name": {
                                "type": "string",
                                "minLength": 1,
                                "maxLength": 120
                              },
                              "slug": {
                                "type": "string",
                                "maxLength": 64,
                                "pattern": "^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$"
                              },
                              "plan": {
                                "type": "string",
                                "enum": [
                                  "free",
                                  "pro",
                                  "team"
                                ]
                              },
                              "createdAt": {
                                "type": "string",
                                "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))$"
                              }
                            },
                            "required": [
                              "id",
                              "name",
                              "slug",
                              "plan",
                              "createdAt"
                            ],
                            "additionalProperties": false
                          },
                          "role": {
                            "type": "string",
                            "enum": [
                              "owner",
                              "admin",
                              "member",
                              "viewer"
                            ]
                          }
                        },
                        "required": [
                          "memberId",
                          "organisation",
                          "role"
                        ],
                        "additionalProperties": false
                      }
                    },
                    "currentOrganisationId": {
                      "anyOf": [
                        {
                          "type": "string",
                          "pattern": "^org_[0-9A-Za-z]{8,64}$"
                        },
                        {
                          "type": "null"
                        }
                      ]
                    }
                  },
                  "required": [
                    "user",
                    "memberships",
                    "currentOrganisationId"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "default": {
            "description": "Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            }
          }
        }
      }
    },
    "/api/permissions": {
      "get": {
        "operationId": "getPermissions",
        "summary": "The caller's permissions in the current organisation.",
        "parameters": [],
        "security": [
          {
            "session": []
          },
          {
            "token": []
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$schema": "https://json-schema.org/draft/2020-12/schema",
                  "type": "object",
                  "properties": {
                    "organisationId": {
                      "type": "string",
                      "pattern": "^org_[0-9A-Za-z]{8,64}$"
                    },
                    "role": {
                      "type": "string",
                      "enum": [
                        "owner",
                        "admin",
                        "member",
                        "viewer"
                      ]
                    },
                    "permissions": {
                      "type": "array",
                      "items": {
                        "type": "string",
                        "enum": [
                          "project.read",
                          "project.create",
                          "project.update",
                          "project.archive",
                          "run.read",
                          "run.start",
                          "run.interrupt",
                          "version.restore",
                          "files.read",
                          "publish.start",
                          "publish.approve",
                          "deployment.rollback",
                          "approval.decide",
                          "usage.read",
                          "personas.read",
                          "members.read",
                          "members.manage",
                          "settings.read",
                          "settings.manage",
                          "connectors.manage",
                          "tokens.manage",
                          "audit.read",
                          "billing.read",
                          "billing.manage",
                          "stop-switch.use"
                        ]
                      }
                    }
                  },
                  "required": [
                    "organisationId",
                    "role",
                    "permissions"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "default": {
            "description": "Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            }
          }
        }
      }
    },
    "/api/projects": {
      "get": {
        "operationId": "listProjects",
        "summary": "List projects.",
        "parameters": [
          {
            "name": "cursor",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "minLength": 1
            }
          },
          {
            "name": "limit",
            "in": "query",
            "required": true,
            "schema": {
              "default": 50,
              "type": "integer",
              "minimum": 1,
              "maximum": 100
            }
          },
          {
            "name": "status",
            "in": "query",
            "required": true,
            "schema": {
              "default": "active",
              "type": "string",
              "enum": [
                "active",
                "archived"
              ]
            }
          }
        ],
        "security": [
          {
            "session": []
          },
          {
            "token": []
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$schema": "https://json-schema.org/draft/2020-12/schema",
                  "type": "object",
                  "properties": {
                    "projects": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string",
                            "pattern": "^prj_[0-9A-Za-z]{8,64}$"
                          },
                          "organisationId": {
                            "type": "string",
                            "pattern": "^org_[0-9A-Za-z]{8,64}$"
                          },
                          "name": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 120
                          },
                          "description": {
                            "anyOf": [
                              {
                                "type": "string",
                                "maxLength": 2000
                              },
                              {
                                "type": "null"
                              }
                            ]
                          },
                          "appSlug": {
                            "type": "string",
                            "maxLength": 64,
                            "pattern": "^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$"
                          },
                          "status": {
                            "type": "string",
                            "enum": [
                              "active",
                              "archived"
                            ]
                          },
                          "settings": {
                            "type": "object",
                            "properties": {
                              "sandboxSize": {
                                "type": "string",
                                "enum": [
                                  "standard-2",
                                  "standard-4"
                                ]
                              },
                              "runBudgetCents": {
                                "anyOf": [
                                  {
                                    "type": "integer",
                                    "minimum": 0,
                                    "maximum": 9007199254740991
                                  },
                                  {
                                    "type": "null"
                                  }
                                ]
                              },
                              "monthlyBudgetCents": {
                                "anyOf": [
                                  {
                                    "type": "integer",
                                    "minimum": 0,
                                    "maximum": 9007199254740991
                                  },
                                  {
                                    "type": "null"
                                  }
                                ]
                              },
                              "connectors": {
                                "type": "array",
                                "items": {
                                  "type": "string",
                                  "maxLength": 64,
                                  "pattern": "^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$"
                                }
                              }
                            },
                            "required": [
                              "sandboxSize",
                              "runBudgetCents",
                              "monthlyBudgetCents",
                              "connectors"
                            ],
                            "additionalProperties": false
                          },
                          "appUrl": {
                            "anyOf": [
                              {
                                "type": "string",
                                "format": "uri"
                              },
                              {
                                "type": "null"
                              }
                            ]
                          },
                          "createdBy": {
                            "type": "string",
                            "pattern": "^usr_[0-9A-Za-z]{8,64}$"
                          },
                          "createdAt": {
                            "type": "string",
                            "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))$"
                          },
                          "updatedAt": {
                            "type": "string",
                            "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))$"
                          },
                          "lastRunAt": {
                            "anyOf": [
                              {
                                "type": "string",
                                "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": "null"
                              }
                            ]
                          },
                          "archivedAt": {
                            "anyOf": [
                              {
                                "type": "string",
                                "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": "null"
                              }
                            ]
                          }
                        },
                        "required": [
                          "id",
                          "organisationId",
                          "name",
                          "description",
                          "appSlug",
                          "status",
                          "settings",
                          "appUrl",
                          "createdBy",
                          "createdAt",
                          "updatedAt",
                          "lastRunAt",
                          "archivedAt"
                        ],
                        "additionalProperties": false
                      }
                    },
                    "nextCursor": {
                      "type": [
                        "string",
                        "null"
                      ]
                    }
                  },
                  "required": [
                    "projects",
                    "nextCursor"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "default": {
            "description": "Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            }
          }
        },
        "x-permission": "project.read"
      },
      "post": {
        "operationId": "createProject",
        "summary": "Create a project.",
        "parameters": [],
        "security": [
          {
            "session": []
          },
          {
            "token": []
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$schema": "https://json-schema.org/draft/2020-12/schema",
                  "type": "object",
                  "properties": {
                    "project": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "type": "string",
                          "pattern": "^prj_[0-9A-Za-z]{8,64}$"
                        },
                        "organisationId": {
                          "type": "string",
                          "pattern": "^org_[0-9A-Za-z]{8,64}$"
                        },
                        "name": {
                          "type": "string",
                          "minLength": 1,
                          "maxLength": 120
                        },
                        "description": {
                          "anyOf": [
                            {
                              "type": "string",
                              "maxLength": 2000
                            },
                            {
                              "type": "null"
                            }
                          ]
                        },
                        "appSlug": {
                          "type": "string",
                          "maxLength": 64,
                          "pattern": "^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$"
                        },
                        "status": {
                          "type": "string",
                          "enum": [
                            "active",
                            "archived"
                          ]
                        },
                        "settings": {
                          "type": "object",
                          "properties": {
                            "sandboxSize": {
                              "type": "string",
                              "enum": [
                                "standard-2",
                                "standard-4"
                              ]
                            },
                            "runBudgetCents": {
                              "anyOf": [
                                {
                                  "type": "integer",
                                  "minimum": 0,
                                  "maximum": 9007199254740991
                                },
                                {
                                  "type": "null"
                                }
                              ]
                            },
                            "monthlyBudgetCents": {
                              "anyOf": [
                                {
                                  "type": "integer",
                                  "minimum": 0,
                                  "maximum": 9007199254740991
                                },
                                {
                                  "type": "null"
                                }
                              ]
                            },
                            "connectors": {
                              "type": "array",
                              "items": {
                                "type": "string",
                                "maxLength": 64,
                                "pattern": "^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$"
                              }
                            }
                          },
                          "required": [
                            "sandboxSize",
                            "runBudgetCents",
                            "monthlyBudgetCents",
                            "connectors"
                          ],
                          "additionalProperties": false
                        },
                        "appUrl": {
                          "anyOf": [
                            {
                              "type": "string",
                              "format": "uri"
                            },
                            {
                              "type": "null"
                            }
                          ]
                        },
                        "createdBy": {
                          "type": "string",
                          "pattern": "^usr_[0-9A-Za-z]{8,64}$"
                        },
                        "createdAt": {
                          "type": "string",
                          "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))$"
                        },
                        "updatedAt": {
                          "type": "string",
                          "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))$"
                        },
                        "lastRunAt": {
                          "anyOf": [
                            {
                              "type": "string",
                              "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": "null"
                            }
                          ]
                        },
                        "archivedAt": {
                          "anyOf": [
                            {
                              "type": "string",
                              "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": "null"
                            }
                          ]
                        }
                      },
                      "required": [
                        "id",
                        "organisationId",
                        "name",
                        "description",
                        "appSlug",
                        "status",
                        "settings",
                        "appUrl",
                        "createdBy",
                        "createdAt",
                        "updatedAt",
                        "lastRunAt",
                        "archivedAt"
                      ],
                      "additionalProperties": false
                    }
                  },
                  "required": [
                    "project"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "default": {
            "description": "Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            }
          }
        },
        "x-permission": "project.create",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$schema": "https://json-schema.org/draft/2020-12/schema",
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 120
                  },
                  "description": {
                    "type": "string",
                    "maxLength": 2000
                  },
                  "appSlug": {
                    "type": "string",
                    "maxLength": 64,
                    "pattern": "^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$"
                  },
                  "sandboxSize": {
                    "type": "string",
                    "enum": [
                      "standard-2",
                      "standard-4"
                    ]
                  },
                  "prompt": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 20000
                  }
                },
                "required": [
                  "name"
                ]
              }
            }
          }
        }
      }
    },
    "/api/projects/{id}": {
      "get": {
        "operationId": "getProject",
        "summary": "Read a project.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^prj_[0-9A-Za-z]{8,64}$"
            }
          }
        ],
        "security": [
          {
            "session": []
          },
          {
            "token": []
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$schema": "https://json-schema.org/draft/2020-12/schema",
                  "type": "object",
                  "properties": {
                    "project": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "type": "string",
                          "pattern": "^prj_[0-9A-Za-z]{8,64}$"
                        },
                        "organisationId": {
                          "type": "string",
                          "pattern": "^org_[0-9A-Za-z]{8,64}$"
                        },
                        "name": {
                          "type": "string",
                          "minLength": 1,
                          "maxLength": 120
                        },
                        "description": {
                          "anyOf": [
                            {
                              "type": "string",
                              "maxLength": 2000
                            },
                            {
                              "type": "null"
                            }
                          ]
                        },
                        "appSlug": {
                          "type": "string",
                          "maxLength": 64,
                          "pattern": "^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$"
                        },
                        "status": {
                          "type": "string",
                          "enum": [
                            "active",
                            "archived"
                          ]
                        },
                        "settings": {
                          "type": "object",
                          "properties": {
                            "sandboxSize": {
                              "type": "string",
                              "enum": [
                                "standard-2",
                                "standard-4"
                              ]
                            },
                            "runBudgetCents": {
                              "anyOf": [
                                {
                                  "type": "integer",
                                  "minimum": 0,
                                  "maximum": 9007199254740991
                                },
                                {
                                  "type": "null"
                                }
                              ]
                            },
                            "monthlyBudgetCents": {
                              "anyOf": [
                                {
                                  "type": "integer",
                                  "minimum": 0,
                                  "maximum": 9007199254740991
                                },
                                {
                                  "type": "null"
                                }
                              ]
                            },
                            "connectors": {
                              "type": "array",
                              "items": {
                                "type": "string",
                                "maxLength": 64,
                                "pattern": "^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$"
                              }
                            }
                          },
                          "required": [
                            "sandboxSize",
                            "runBudgetCents",
                            "monthlyBudgetCents",
                            "connectors"
                          ],
                          "additionalProperties": false
                        },
                        "appUrl": {
                          "anyOf": [
                            {
                              "type": "string",
                              "format": "uri"
                            },
                            {
                              "type": "null"
                            }
                          ]
                        },
                        "createdBy": {
                          "type": "string",
                          "pattern": "^usr_[0-9A-Za-z]{8,64}$"
                        },
                        "createdAt": {
                          "type": "string",
                          "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))$"
                        },
                        "updatedAt": {
                          "type": "string",
                          "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))$"
                        },
                        "lastRunAt": {
                          "anyOf": [
                            {
                              "type": "string",
                              "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": "null"
                            }
                          ]
                        },
                        "archivedAt": {
                          "anyOf": [
                            {
                              "type": "string",
                              "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": "null"
                            }
                          ]
                        }
                      },
                      "required": [
                        "id",
                        "organisationId",
                        "name",
                        "description",
                        "appSlug",
                        "status",
                        "settings",
                        "appUrl",
                        "createdBy",
                        "createdAt",
                        "updatedAt",
                        "lastRunAt",
                        "archivedAt"
                      ],
                      "additionalProperties": false
                    }
                  },
                  "required": [
                    "project"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "default": {
            "description": "Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            }
          }
        },
        "x-permission": "project.read"
      },
      "patch": {
        "operationId": "updateProject",
        "summary": "Change a project's settings.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^prj_[0-9A-Za-z]{8,64}$"
            }
          }
        ],
        "security": [
          {
            "session": []
          },
          {
            "token": []
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$schema": "https://json-schema.org/draft/2020-12/schema",
                  "type": "object",
                  "properties": {
                    "project": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "type": "string",
                          "pattern": "^prj_[0-9A-Za-z]{8,64}$"
                        },
                        "organisationId": {
                          "type": "string",
                          "pattern": "^org_[0-9A-Za-z]{8,64}$"
                        },
                        "name": {
                          "type": "string",
                          "minLength": 1,
                          "maxLength": 120
                        },
                        "description": {
                          "anyOf": [
                            {
                              "type": "string",
                              "maxLength": 2000
                            },
                            {
                              "type": "null"
                            }
                          ]
                        },
                        "appSlug": {
                          "type": "string",
                          "maxLength": 64,
                          "pattern": "^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$"
                        },
                        "status": {
                          "type": "string",
                          "enum": [
                            "active",
                            "archived"
                          ]
                        },
                        "settings": {
                          "type": "object",
                          "properties": {
                            "sandboxSize": {
                              "type": "string",
                              "enum": [
                                "standard-2",
                                "standard-4"
                              ]
                            },
                            "runBudgetCents": {
                              "anyOf": [
                                {
                                  "type": "integer",
                                  "minimum": 0,
                                  "maximum": 9007199254740991
                                },
                                {
                                  "type": "null"
                                }
                              ]
                            },
                            "monthlyBudgetCents": {
                              "anyOf": [
                                {
                                  "type": "integer",
                                  "minimum": 0,
                                  "maximum": 9007199254740991
                                },
                                {
                                  "type": "null"
                                }
                              ]
                            },
                            "connectors": {
                              "type": "array",
                              "items": {
                                "type": "string",
                                "maxLength": 64,
                                "pattern": "^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$"
                              }
                            }
                          },
                          "required": [
                            "sandboxSize",
                            "runBudgetCents",
                            "monthlyBudgetCents",
                            "connectors"
                          ],
                          "additionalProperties": false
                        },
                        "appUrl": {
                          "anyOf": [
                            {
                              "type": "string",
                              "format": "uri"
                            },
                            {
                              "type": "null"
                            }
                          ]
                        },
                        "createdBy": {
                          "type": "string",
                          "pattern": "^usr_[0-9A-Za-z]{8,64}$"
                        },
                        "createdAt": {
                          "type": "string",
                          "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))$"
                        },
                        "updatedAt": {
                          "type": "string",
                          "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))$"
                        },
                        "lastRunAt": {
                          "anyOf": [
                            {
                              "type": "string",
                              "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": "null"
                            }
                          ]
                        },
                        "archivedAt": {
                          "anyOf": [
                            {
                              "type": "string",
                              "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": "null"
                            }
                          ]
                        }
                      },
                      "required": [
                        "id",
                        "organisationId",
                        "name",
                        "description",
                        "appSlug",
                        "status",
                        "settings",
                        "appUrl",
                        "createdBy",
                        "createdAt",
                        "updatedAt",
                        "lastRunAt",
                        "archivedAt"
                      ],
                      "additionalProperties": false
                    }
                  },
                  "required": [
                    "project"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "default": {
            "description": "Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            }
          }
        },
        "x-permission": "project.update",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$schema": "https://json-schema.org/draft/2020-12/schema",
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 120
                  },
                  "description": {
                    "anyOf": [
                      {
                        "type": "string",
                        "maxLength": 2000
                      },
                      {
                        "type": "null"
                      }
                    ]
                  },
                  "settings": {
                    "type": "object",
                    "properties": {
                      "sandboxSize": {
                        "type": "string",
                        "enum": [
                          "standard-2",
                          "standard-4"
                        ]
                      },
                      "runBudgetCents": {
                        "anyOf": [
                          {
                            "type": "integer",
                            "minimum": 0,
                            "maximum": 9007199254740991
                          },
                          {
                            "type": "null"
                          }
                        ]
                      },
                      "monthlyBudgetCents": {
                        "anyOf": [
                          {
                            "type": "integer",
                            "minimum": 0,
                            "maximum": 9007199254740991
                          },
                          {
                            "type": "null"
                          }
                        ]
                      },
                      "connectors": {
                        "type": "array",
                        "items": {
                          "type": "string",
                          "maxLength": 64,
                          "pattern": "^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$"
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      },
      "delete": {
        "operationId": "archiveProject",
        "summary": "Archive a project.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^prj_[0-9A-Za-z]{8,64}$"
            }
          }
        ],
        "security": [
          {
            "session": []
          },
          {
            "token": []
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$schema": "https://json-schema.org/draft/2020-12/schema",
                  "type": "object",
                  "properties": {
                    "project": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "type": "string",
                          "pattern": "^prj_[0-9A-Za-z]{8,64}$"
                        },
                        "organisationId": {
                          "type": "string",
                          "pattern": "^org_[0-9A-Za-z]{8,64}$"
                        },
                        "name": {
                          "type": "string",
                          "minLength": 1,
                          "maxLength": 120
                        },
                        "description": {
                          "anyOf": [
                            {
                              "type": "string",
                              "maxLength": 2000
                            },
                            {
                              "type": "null"
                            }
                          ]
                        },
                        "appSlug": {
                          "type": "string",
                          "maxLength": 64,
                          "pattern": "^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$"
                        },
                        "status": {
                          "type": "string",
                          "enum": [
                            "active",
                            "archived"
                          ]
                        },
                        "settings": {
                          "type": "object",
                          "properties": {
                            "sandboxSize": {
                              "type": "string",
                              "enum": [
                                "standard-2",
                                "standard-4"
                              ]
                            },
                            "runBudgetCents": {
                              "anyOf": [
                                {
                                  "type": "integer",
                                  "minimum": 0,
                                  "maximum": 9007199254740991
                                },
                                {
                                  "type": "null"
                                }
                              ]
                            },
                            "monthlyBudgetCents": {
                              "anyOf": [
                                {
                                  "type": "integer",
                                  "minimum": 0,
                                  "maximum": 9007199254740991
                                },
                                {
                                  "type": "null"
                                }
                              ]
                            },
                            "connectors": {
                              "type": "array",
                              "items": {
                                "type": "string",
                                "maxLength": 64,
                                "pattern": "^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$"
                              }
                            }
                          },
                          "required": [
                            "sandboxSize",
                            "runBudgetCents",
                            "monthlyBudgetCents",
                            "connectors"
                          ],
                          "additionalProperties": false
                        },
                        "appUrl": {
                          "anyOf": [
                            {
                              "type": "string",
                              "format": "uri"
                            },
                            {
                              "type": "null"
                            }
                          ]
                        },
                        "createdBy": {
                          "type": "string",
                          "pattern": "^usr_[0-9A-Za-z]{8,64}$"
                        },
                        "createdAt": {
                          "type": "string",
                          "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))$"
                        },
                        "updatedAt": {
                          "type": "string",
                          "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))$"
                        },
                        "lastRunAt": {
                          "anyOf": [
                            {
                              "type": "string",
                              "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": "null"
                            }
                          ]
                        },
                        "archivedAt": {
                          "anyOf": [
                            {
                              "type": "string",
                              "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": "null"
                            }
                          ]
                        }
                      },
                      "required": [
                        "id",
                        "organisationId",
                        "name",
                        "description",
                        "appSlug",
                        "status",
                        "settings",
                        "appUrl",
                        "createdBy",
                        "createdAt",
                        "updatedAt",
                        "lastRunAt",
                        "archivedAt"
                      ],
                      "additionalProperties": false
                    }
                  },
                  "required": [
                    "project"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "default": {
            "description": "Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            }
          }
        },
        "x-permission": "project.archive"
      }
    },
    "/api/projects/{id}/socket": {
      "get": {
        "operationId": "openProjectSocket",
        "summary": "Upgrade to the project's session socket.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^prj_[0-9A-Za-z]{8,64}$"
            }
          },
          {
            "name": "after",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "minimum": 0,
              "maximum": 9007199254740991
            }
          }
        ],
        "security": [
          {
            "session": []
          },
          {
            "token": []
          }
        ],
        "responses": {
          "200": {
            "description": "Not JSON (a socket upgrade or this document)"
          },
          "default": {
            "description": "Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            }
          }
        },
        "x-permission": "project.read"
      }
    },
    "/api/projects/{id}/runs": {
      "get": {
        "operationId": "listRuns",
        "summary": "A project's run history.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^prj_[0-9A-Za-z]{8,64}$"
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "minLength": 1
            }
          },
          {
            "name": "limit",
            "in": "query",
            "required": true,
            "schema": {
              "default": 50,
              "type": "integer",
              "minimum": 1,
              "maximum": 100
            }
          },
          {
            "name": "status",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "queued",
                "running",
                "needs_you",
                "finished",
                "failed",
                "interrupted"
              ]
            }
          }
        ],
        "security": [
          {
            "session": []
          },
          {
            "token": []
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$schema": "https://json-schema.org/draft/2020-12/schema",
                  "type": "object",
                  "properties": {
                    "runs": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string",
                            "pattern": "^run_[0-9A-Za-z]{8,64}$"
                          },
                          "projectId": {
                            "type": "string",
                            "pattern": "^prj_[0-9A-Za-z]{8,64}$"
                          },
                          "organisationId": {
                            "type": "string",
                            "pattern": "^org_[0-9A-Za-z]{8,64}$"
                          },
                          "status": {
                            "type": "string",
                            "enum": [
                              "queued",
                              "running",
                              "needs_you",
                              "finished",
                              "failed",
                              "interrupted"
                            ]
                          },
                          "phase": {
                            "type": "string",
                            "enum": [
                              "admit",
                              "plan",
                              "build",
                              "check",
                              "fix",
                              "record",
                              "finish"
                            ]
                          },
                          "mode": {
                            "type": "string",
                            "enum": [
                              "build",
                              "plan"
                            ]
                          },
                          "prompt": {
                            "type": "string",
                            "minLength": 1
                          },
                          "personaId": {
                            "type": "string",
                            "maxLength": 64,
                            "pattern": "^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$"
                          },
                          "modelTier": {
                            "type": "string",
                            "enum": [
                              "plan",
                              "review",
                              "build",
                              "small"
                            ]
                          },
                          "startedBy": {
                            "type": "string",
                            "pattern": "^usr_[0-9A-Za-z]{8,64}$"
                          },
                          "limits": {
                            "type": "object",
                            "properties": {
                              "costCents": {
                                "type": "integer",
                                "minimum": 0,
                                "maximum": 9007199254740991
                              },
                              "wallSeconds": {
                                "type": "integer",
                                "exclusiveMinimum": 0,
                                "maximum": 9007199254740991
                              },
                              "steps": {
                                "type": "integer",
                                "exclusiveMinimum": 0,
                                "maximum": 9007199254740991
                              }
                            },
                            "required": [
                              "costCents",
                              "wallSeconds",
                              "steps"
                            ],
                            "additionalProperties": false
                          },
                          "totals": {
                            "type": "object",
                            "properties": {
                              "tokensIn": {
                                "type": "integer",
                                "minimum": 0,
                                "maximum": 9007199254740991
                              },
                              "tokensOut": {
                                "type": "integer",
                                "minimum": 0,
                                "maximum": 9007199254740991
                              },
                              "costCents": {
                                "type": "integer",
                                "minimum": 0,
                                "maximum": 9007199254740991
                              },
                              "steps": {
                                "type": "integer",
                                "minimum": 0,
                                "maximum": 9007199254740991
                              },
                              "wallSeconds": {
                                "type": "integer",
                                "minimum": 0,
                                "maximum": 9007199254740991
                              },
                              "fixRounds": {
                                "type": "integer",
                                "minimum": 0,
                                "maximum": 9007199254740991
                              }
                            },
                            "required": [
                              "tokensIn",
                              "tokensOut",
                              "costCents",
                              "steps",
                              "wallSeconds",
                              "fixRounds"
                            ],
                            "additionalProperties": false
                          },
                          "pins": {
                            "anyOf": [
                              {
                                "type": "object",
                                "properties": {
                                  "engine": {
                                    "type": "string",
                                    "enum": [
                                      "opencode",
                                      "claude-code"
                                    ]
                                  },
                                  "engineVersion": {
                                    "type": "string",
                                    "minLength": 1
                                  },
                                  "packVersion": {
                                    "type": "string",
                                    "minLength": 1
                                  },
                                  "packHash": {
                                    "type": "string",
                                    "minLength": 1
                                  },
                                  "image": {
                                    "type": "string",
                                    "minLength": 1
                                  },
                                  "templateVersion": {
                                    "type": "string",
                                    "minLength": 1
                                  },
                                  "runnerVersion": {
                                    "type": "string",
                                    "minLength": 1
                                  },
                                  "models": {
                                    "type": "object",
                                    "propertyNames": {
                                      "type": "string",
                                      "enum": [
                                        "plan",
                                        "review",
                                        "build",
                                        "small"
                                      ]
                                    },
                                    "additionalProperties": {
                                      "type": "string",
                                      "minLength": 1
                                    },
                                    "required": [
                                      "plan",
                                      "review",
                                      "build",
                                      "small"
                                    ]
                                  }
                                },
                                "required": [
                                  "engine",
                                  "engineVersion",
                                  "packVersion",
                                  "packHash",
                                  "image",
                                  "templateVersion",
                                  "runnerVersion",
                                  "models"
                                ],
                                "additionalProperties": false
                              },
                              {
                                "type": "null"
                              }
                            ]
                          },
                          "summary": {
                            "type": [
                              "string",
                              "null"
                            ]
                          },
                          "failure": {
                            "anyOf": [
                              {
                                "type": "object",
                                "properties": {
                                  "reason": {
                                    "type": "string",
                                    "enum": [
                                      "checks_failed",
                                      "cost_limit",
                                      "wall_limit",
                                      "step_limit",
                                      "interrupted",
                                      "engine_error",
                                      "pack_mismatch",
                                      "sandbox_lost",
                                      "refused",
                                      "internal"
                                    ]
                                  },
                                  "message": {
                                    "type": "string",
                                    "minLength": 1
                                  }
                                },
                                "required": [
                                  "reason",
                                  "message"
                                ],
                                "additionalProperties": false
                              },
                              {
                                "type": "null"
                              }
                            ]
                          },
                          "commit": {
                            "anyOf": [
                              {
                                "type": "string",
                                "pattern": "^(?:[0-9a-f]{40}|[0-9a-f]{64})$"
                              },
                              {
                                "type": "null"
                              }
                            ]
                          },
                          "versionId": {
                            "anyOf": [
                              {
                                "type": "string",
                                "pattern": "^ver_[0-9A-Za-z]{8,64}$"
                              },
                              {
                                "type": "null"
                              }
                            ]
                          },
                          "lastSeq": {
                            "type": "integer",
                            "minimum": 0,
                            "maximum": 9007199254740991
                          },
                          "createdAt": {
                            "type": "string",
                            "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))$"
                          },
                          "startedAt": {
                            "anyOf": [
                              {
                                "type": "string",
                                "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": "null"
                              }
                            ]
                          },
                          "finishedAt": {
                            "anyOf": [
                              {
                                "type": "string",
                                "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": "null"
                              }
                            ]
                          }
                        },
                        "required": [
                          "id",
                          "projectId",
                          "organisationId",
                          "status",
                          "phase",
                          "mode",
                          "prompt",
                          "personaId",
                          "modelTier",
                          "startedBy",
                          "limits",
                          "totals",
                          "pins",
                          "summary",
                          "failure",
                          "commit",
                          "versionId",
                          "lastSeq",
                          "createdAt",
                          "startedAt",
                          "finishedAt"
                        ],
                        "additionalProperties": false
                      }
                    },
                    "nextCursor": {
                      "type": [
                        "string",
                        "null"
                      ]
                    }
                  },
                  "required": [
                    "runs",
                    "nextCursor"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "default": {
            "description": "Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            }
          }
        },
        "x-permission": "run.read"
      }
    },
    "/api/runs/{id}": {
      "get": {
        "operationId": "getRun",
        "summary": "One run.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^run_[0-9A-Za-z]{8,64}$"
            }
          }
        ],
        "security": [
          {
            "session": []
          },
          {
            "token": []
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$schema": "https://json-schema.org/draft/2020-12/schema",
                  "type": "object",
                  "properties": {
                    "run": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "type": "string",
                          "pattern": "^run_[0-9A-Za-z]{8,64}$"
                        },
                        "projectId": {
                          "type": "string",
                          "pattern": "^prj_[0-9A-Za-z]{8,64}$"
                        },
                        "organisationId": {
                          "type": "string",
                          "pattern": "^org_[0-9A-Za-z]{8,64}$"
                        },
                        "status": {
                          "type": "string",
                          "enum": [
                            "queued",
                            "running",
                            "needs_you",
                            "finished",
                            "failed",
                            "interrupted"
                          ]
                        },
                        "phase": {
                          "type": "string",
                          "enum": [
                            "admit",
                            "plan",
                            "build",
                            "check",
                            "fix",
                            "record",
                            "finish"
                          ]
                        },
                        "mode": {
                          "type": "string",
                          "enum": [
                            "build",
                            "plan"
                          ]
                        },
                        "prompt": {
                          "type": "string",
                          "minLength": 1
                        },
                        "personaId": {
                          "type": "string",
                          "maxLength": 64,
                          "pattern": "^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$"
                        },
                        "modelTier": {
                          "type": "string",
                          "enum": [
                            "plan",
                            "review",
                            "build",
                            "small"
                          ]
                        },
                        "startedBy": {
                          "type": "string",
                          "pattern": "^usr_[0-9A-Za-z]{8,64}$"
                        },
                        "limits": {
                          "type": "object",
                          "properties": {
                            "costCents": {
                              "type": "integer",
                              "minimum": 0,
                              "maximum": 9007199254740991
                            },
                            "wallSeconds": {
                              "type": "integer",
                              "exclusiveMinimum": 0,
                              "maximum": 9007199254740991
                            },
                            "steps": {
                              "type": "integer",
                              "exclusiveMinimum": 0,
                              "maximum": 9007199254740991
                            }
                          },
                          "required": [
                            "costCents",
                            "wallSeconds",
                            "steps"
                          ],
                          "additionalProperties": false
                        },
                        "totals": {
                          "type": "object",
                          "properties": {
                            "tokensIn": {
                              "type": "integer",
                              "minimum": 0,
                              "maximum": 9007199254740991
                            },
                            "tokensOut": {
                              "type": "integer",
                              "minimum": 0,
                              "maximum": 9007199254740991
                            },
                            "costCents": {
                              "type": "integer",
                              "minimum": 0,
                              "maximum": 9007199254740991
                            },
                            "steps": {
                              "type": "integer",
                              "minimum": 0,
                              "maximum": 9007199254740991
                            },
                            "wallSeconds": {
                              "type": "integer",
                              "minimum": 0,
                              "maximum": 9007199254740991
                            },
                            "fixRounds": {
                              "type": "integer",
                              "minimum": 0,
                              "maximum": 9007199254740991
                            }
                          },
                          "required": [
                            "tokensIn",
                            "tokensOut",
                            "costCents",
                            "steps",
                            "wallSeconds",
                            "fixRounds"
                          ],
                          "additionalProperties": false
                        },
                        "pins": {
                          "anyOf": [
                            {
                              "type": "object",
                              "properties": {
                                "engine": {
                                  "type": "string",
                                  "enum": [
                                    "opencode",
                                    "claude-code"
                                  ]
                                },
                                "engineVersion": {
                                  "type": "string",
                                  "minLength": 1
                                },
                                "packVersion": {
                                  "type": "string",
                                  "minLength": 1
                                },
                                "packHash": {
                                  "type": "string",
                                  "minLength": 1
                                },
                                "image": {
                                  "type": "string",
                                  "minLength": 1
                                },
                                "templateVersion": {
                                  "type": "string",
                                  "minLength": 1
                                },
                                "runnerVersion": {
                                  "type": "string",
                                  "minLength": 1
                                },
                                "models": {
                                  "type": "object",
                                  "propertyNames": {
                                    "type": "string",
                                    "enum": [
                                      "plan",
                                      "review",
                                      "build",
                                      "small"
                                    ]
                                  },
                                  "additionalProperties": {
                                    "type": "string",
                                    "minLength": 1
                                  },
                                  "required": [
                                    "plan",
                                    "review",
                                    "build",
                                    "small"
                                  ]
                                }
                              },
                              "required": [
                                "engine",
                                "engineVersion",
                                "packVersion",
                                "packHash",
                                "image",
                                "templateVersion",
                                "runnerVersion",
                                "models"
                              ],
                              "additionalProperties": false
                            },
                            {
                              "type": "null"
                            }
                          ]
                        },
                        "summary": {
                          "type": [
                            "string",
                            "null"
                          ]
                        },
                        "failure": {
                          "anyOf": [
                            {
                              "type": "object",
                              "properties": {
                                "reason": {
                                  "type": "string",
                                  "enum": [
                                    "checks_failed",
                                    "cost_limit",
                                    "wall_limit",
                                    "step_limit",
                                    "interrupted",
                                    "engine_error",
                                    "pack_mismatch",
                                    "sandbox_lost",
                                    "refused",
                                    "internal"
                                  ]
                                },
                                "message": {
                                  "type": "string",
                                  "minLength": 1
                                }
                              },
                              "required": [
                                "reason",
                                "message"
                              ],
                              "additionalProperties": false
                            },
                            {
                              "type": "null"
                            }
                          ]
                        },
                        "commit": {
                          "anyOf": [
                            {
                              "type": "string",
                              "pattern": "^(?:[0-9a-f]{40}|[0-9a-f]{64})$"
                            },
                            {
                              "type": "null"
                            }
                          ]
                        },
                        "versionId": {
                          "anyOf": [
                            {
                              "type": "string",
                              "pattern": "^ver_[0-9A-Za-z]{8,64}$"
                            },
                            {
                              "type": "null"
                            }
                          ]
                        },
                        "lastSeq": {
                          "type": "integer",
                          "minimum": 0,
                          "maximum": 9007199254740991
                        },
                        "createdAt": {
                          "type": "string",
                          "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))$"
                        },
                        "startedAt": {
                          "anyOf": [
                            {
                              "type": "string",
                              "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": "null"
                            }
                          ]
                        },
                        "finishedAt": {
                          "anyOf": [
                            {
                              "type": "string",
                              "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": "null"
                            }
                          ]
                        }
                      },
                      "required": [
                        "id",
                        "projectId",
                        "organisationId",
                        "status",
                        "phase",
                        "mode",
                        "prompt",
                        "personaId",
                        "modelTier",
                        "startedBy",
                        "limits",
                        "totals",
                        "pins",
                        "summary",
                        "failure",
                        "commit",
                        "versionId",
                        "lastSeq",
                        "createdAt",
                        "startedAt",
                        "finishedAt"
                      ],
                      "additionalProperties": false
                    }
                  },
                  "required": [
                    "run"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "default": {
            "description": "Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            }
          }
        },
        "x-permission": "run.read"
      }
    },
    "/api/runs/{id}/events": {
      "get": {
        "operationId": "listRunEvents",
        "summary": "A run's stored events.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^run_[0-9A-Za-z]{8,64}$"
            }
          },
          {
            "name": "after",
            "in": "query",
            "required": true,
            "schema": {
              "default": 0,
              "type": "integer",
              "minimum": 0,
              "maximum": 9007199254740991
            }
          },
          {
            "name": "limit",
            "in": "query",
            "required": true,
            "schema": {
              "default": 500,
              "type": "integer",
              "minimum": 1,
              "maximum": 1000
            }
          }
        ],
        "security": [
          {
            "session": []
          },
          {
            "token": []
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$schema": "https://json-schema.org/draft/2020-12/schema",
                  "type": "object",
                  "properties": {
                    "events": {
                      "type": "array",
                      "items": {
                        "oneOf": [
                          {
                            "type": "object",
                            "properties": {
                              "seq": {
                                "type": "integer",
                                "exclusiveMinimum": 0,
                                "maximum": 9007199254740991
                              },
                              "ts": {
                                "type": "string",
                                "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))$"
                              },
                              "runId": {
                                "type": "string",
                                "pattern": "^run_[0-9A-Za-z]{8,64}$"
                              },
                              "persona": {
                                "type": "string",
                                "maxLength": 64,
                                "pattern": "^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$"
                              },
                              "type": {
                                "type": "string",
                                "const": "run.started"
                              },
                              "data": {
                                "type": "object",
                                "properties": {
                                  "mode": {
                                    "type": "string",
                                    "enum": [
                                      "build",
                                      "plan"
                                    ]
                                  },
                                  "prompt": {
                                    "type": "string"
                                  },
                                  "personaId": {
                                    "type": "string",
                                    "maxLength": 64,
                                    "pattern": "^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$"
                                  },
                                  "modelTier": {
                                    "type": "string",
                                    "enum": [
                                      "plan",
                                      "review",
                                      "build",
                                      "small"
                                    ]
                                  },
                                  "limits": {
                                    "type": "object",
                                    "properties": {
                                      "costCents": {
                                        "type": "integer",
                                        "minimum": 0,
                                        "maximum": 9007199254740991
                                      },
                                      "wallSeconds": {
                                        "type": "integer",
                                        "exclusiveMinimum": 0,
                                        "maximum": 9007199254740991
                                      },
                                      "steps": {
                                        "type": "integer",
                                        "exclusiveMinimum": 0,
                                        "maximum": 9007199254740991
                                      }
                                    },
                                    "required": [
                                      "costCents",
                                      "wallSeconds",
                                      "steps"
                                    ],
                                    "additionalProperties": false
                                  },
                                  "pins": {
                                    "type": "object",
                                    "properties": {
                                      "engine": {
                                        "type": "string",
                                        "enum": [
                                          "opencode",
                                          "claude-code"
                                        ]
                                      },
                                      "engineVersion": {
                                        "type": "string",
                                        "minLength": 1
                                      },
                                      "packVersion": {
                                        "type": "string",
                                        "minLength": 1
                                      },
                                      "packHash": {
                                        "type": "string",
                                        "minLength": 1
                                      },
                                      "image": {
                                        "type": "string",
                                        "minLength": 1
                                      },
                                      "templateVersion": {
                                        "type": "string",
                                        "minLength": 1
                                      },
                                      "runnerVersion": {
                                        "type": "string",
                                        "minLength": 1
                                      },
                                      "models": {
                                        "type": "object",
                                        "propertyNames": {
                                          "type": "string",
                                          "enum": [
                                            "plan",
                                            "review",
                                            "build",
                                            "small"
                                          ]
                                        },
                                        "additionalProperties": {
                                          "type": "string",
                                          "minLength": 1
                                        },
                                        "required": [
                                          "plan",
                                          "review",
                                          "build",
                                          "small"
                                        ]
                                      }
                                    },
                                    "required": [
                                      "engine",
                                      "engineVersion",
                                      "packVersion",
                                      "packHash",
                                      "image",
                                      "templateVersion",
                                      "runnerVersion",
                                      "models"
                                    ],
                                    "additionalProperties": false
                                  }
                                },
                                "required": [
                                  "mode",
                                  "prompt",
                                  "personaId",
                                  "modelTier",
                                  "limits",
                                  "pins"
                                ],
                                "additionalProperties": false
                              }
                            },
                            "required": [
                              "seq",
                              "ts",
                              "runId",
                              "type",
                              "data"
                            ],
                            "additionalProperties": false
                          },
                          {
                            "type": "object",
                            "properties": {
                              "seq": {
                                "type": "integer",
                                "exclusiveMinimum": 0,
                                "maximum": 9007199254740991
                              },
                              "ts": {
                                "type": "string",
                                "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))$"
                              },
                              "runId": {
                                "type": "string",
                                "pattern": "^run_[0-9A-Za-z]{8,64}$"
                              },
                              "persona": {
                                "type": "string",
                                "maxLength": 64,
                                "pattern": "^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$"
                              },
                              "type": {
                                "type": "string",
                                "const": "plan.proposed"
                              },
                              "data": {
                                "type": "object",
                                "properties": {
                                  "plan": {
                                    "type": "string",
                                    "minLength": 1
                                  },
                                  "steps": {
                                    "type": "array",
                                    "items": {
                                      "type": "string",
                                      "minLength": 1
                                    }
                                  }
                                },
                                "required": [
                                  "plan",
                                  "steps"
                                ],
                                "additionalProperties": false
                              }
                            },
                            "required": [
                              "seq",
                              "ts",
                              "runId",
                              "type",
                              "data"
                            ],
                            "additionalProperties": false
                          },
                          {
                            "type": "object",
                            "properties": {
                              "seq": {
                                "type": "integer",
                                "exclusiveMinimum": 0,
                                "maximum": 9007199254740991
                              },
                              "ts": {
                                "type": "string",
                                "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))$"
                              },
                              "runId": {
                                "type": "string",
                                "pattern": "^run_[0-9A-Za-z]{8,64}$"
                              },
                              "persona": {
                                "type": "string",
                                "maxLength": 64,
                                "pattern": "^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$"
                              },
                              "type": {
                                "type": "string",
                                "const": "step.started"
                              },
                              "data": {
                                "type": "object",
                                "properties": {
                                  "step": {
                                    "type": "integer",
                                    "exclusiveMinimum": 0,
                                    "maximum": 9007199254740991
                                  },
                                  "title": {
                                    "type": "string"
                                  }
                                },
                                "required": [
                                  "step",
                                  "title"
                                ],
                                "additionalProperties": false
                              }
                            },
                            "required": [
                              "seq",
                              "ts",
                              "runId",
                              "type",
                              "data"
                            ],
                            "additionalProperties": false
                          },
                          {
                            "type": "object",
                            "properties": {
                              "seq": {
                                "type": "integer",
                                "exclusiveMinimum": 0,
                                "maximum": 9007199254740991
                              },
                              "ts": {
                                "type": "string",
                                "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))$"
                              },
                              "runId": {
                                "type": "string",
                                "pattern": "^run_[0-9A-Za-z]{8,64}$"
                              },
                              "persona": {
                                "type": "string",
                                "maxLength": 64,
                                "pattern": "^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$"
                              },
                              "type": {
                                "type": "string",
                                "const": "text.delta"
                              },
                              "data": {
                                "type": "object",
                                "properties": {
                                  "messageId": {
                                    "type": "string",
                                    "pattern": "^msg_[0-9A-Za-z]{8,64}$"
                                  },
                                  "text": {
                                    "type": "string"
                                  }
                                },
                                "required": [
                                  "messageId",
                                  "text"
                                ],
                                "additionalProperties": false
                              }
                            },
                            "required": [
                              "seq",
                              "ts",
                              "runId",
                              "type",
                              "data"
                            ],
                            "additionalProperties": false
                          },
                          {
                            "type": "object",
                            "properties": {
                              "seq": {
                                "type": "integer",
                                "exclusiveMinimum": 0,
                                "maximum": 9007199254740991
                              },
                              "ts": {
                                "type": "string",
                                "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))$"
                              },
                              "runId": {
                                "type": "string",
                                "pattern": "^run_[0-9A-Za-z]{8,64}$"
                              },
                              "persona": {
                                "type": "string",
                                "maxLength": 64,
                                "pattern": "^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$"
                              },
                              "type": {
                                "type": "string",
                                "const": "text.done"
                              },
                              "data": {
                                "type": "object",
                                "properties": {
                                  "messageId": {
                                    "type": "string",
                                    "pattern": "^msg_[0-9A-Za-z]{8,64}$"
                                  },
                                  "text": {
                                    "type": "string"
                                  }
                                },
                                "required": [
                                  "messageId",
                                  "text"
                                ],
                                "additionalProperties": false
                              }
                            },
                            "required": [
                              "seq",
                              "ts",
                              "runId",
                              "type",
                              "data"
                            ],
                            "additionalProperties": false
                          },
                          {
                            "type": "object",
                            "properties": {
                              "seq": {
                                "type": "integer",
                                "exclusiveMinimum": 0,
                                "maximum": 9007199254740991
                              },
                              "ts": {
                                "type": "string",
                                "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))$"
                              },
                              "runId": {
                                "type": "string",
                                "pattern": "^run_[0-9A-Za-z]{8,64}$"
                              },
                              "persona": {
                                "type": "string",
                                "maxLength": 64,
                                "pattern": "^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$"
                              },
                              "type": {
                                "type": "string",
                                "const": "tool.called"
                              },
                              "data": {
                                "type": "object",
                                "properties": {
                                  "callId": {
                                    "type": "string",
                                    "minLength": 1
                                  },
                                  "tool": {
                                    "type": "string",
                                    "minLength": 1
                                  },
                                  "summary": {
                                    "type": "string"
                                  }
                                },
                                "required": [
                                  "callId",
                                  "tool",
                                  "summary"
                                ],
                                "additionalProperties": false
                              }
                            },
                            "required": [
                              "seq",
                              "ts",
                              "runId",
                              "type",
                              "data"
                            ],
                            "additionalProperties": false
                          },
                          {
                            "type": "object",
                            "properties": {
                              "seq": {
                                "type": "integer",
                                "exclusiveMinimum": 0,
                                "maximum": 9007199254740991
                              },
                              "ts": {
                                "type": "string",
                                "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))$"
                              },
                              "runId": {
                                "type": "string",
                                "pattern": "^run_[0-9A-Za-z]{8,64}$"
                              },
                              "persona": {
                                "type": "string",
                                "maxLength": 64,
                                "pattern": "^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$"
                              },
                              "type": {
                                "type": "string",
                                "const": "tool.result"
                              },
                              "data": {
                                "type": "object",
                                "properties": {
                                  "callId": {
                                    "type": "string",
                                    "minLength": 1
                                  },
                                  "tool": {
                                    "type": "string",
                                    "minLength": 1
                                  },
                                  "status": {
                                    "type": "string",
                                    "enum": [
                                      "completed",
                                      "error"
                                    ]
                                  },
                                  "summary": {
                                    "type": "string"
                                  }
                                },
                                "required": [
                                  "callId",
                                  "tool",
                                  "status",
                                  "summary"
                                ],
                                "additionalProperties": false
                              }
                            },
                            "required": [
                              "seq",
                              "ts",
                              "runId",
                              "type",
                              "data"
                            ],
                            "additionalProperties": false
                          },
                          {
                            "type": "object",
                            "properties": {
                              "seq": {
                                "type": "integer",
                                "exclusiveMinimum": 0,
                                "maximum": 9007199254740991
                              },
                              "ts": {
                                "type": "string",
                                "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))$"
                              },
                              "runId": {
                                "type": "string",
                                "pattern": "^run_[0-9A-Za-z]{8,64}$"
                              },
                              "persona": {
                                "type": "string",
                                "maxLength": 64,
                                "pattern": "^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$"
                              },
                              "type": {
                                "type": "string",
                                "const": "file.changed"
                              },
                              "data": {
                                "type": "object",
                                "properties": {
                                  "path": {
                                    "type": "string",
                                    "minLength": 1
                                  },
                                  "change": {
                                    "type": "string",
                                    "enum": [
                                      "added",
                                      "modified",
                                      "deleted",
                                      "renamed"
                                    ]
                                  },
                                  "oldPath": {
                                    "type": [
                                      "string",
                                      "null"
                                    ]
                                  }
                                },
                                "required": [
                                  "path",
                                  "change",
                                  "oldPath"
                                ],
                                "additionalProperties": false
                              }
                            },
                            "required": [
                              "seq",
                              "ts",
                              "runId",
                              "type",
                              "data"
                            ],
                            "additionalProperties": false
                          },
                          {
                            "type": "object",
                            "properties": {
                              "seq": {
                                "type": "integer",
                                "exclusiveMinimum": 0,
                                "maximum": 9007199254740991
                              },
                              "ts": {
                                "type": "string",
                                "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))$"
                              },
                              "runId": {
                                "type": "string",
                                "pattern": "^run_[0-9A-Za-z]{8,64}$"
                              },
                              "persona": {
                                "type": "string",
                                "maxLength": 64,
                                "pattern": "^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$"
                              },
                              "type": {
                                "type": "string",
                                "const": "subagent.started"
                              },
                              "data": {
                                "type": "object",
                                "properties": {
                                  "subagentId": {
                                    "type": "string",
                                    "minLength": 1
                                  },
                                  "personaId": {
                                    "type": "string",
                                    "maxLength": 64,
                                    "pattern": "^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$"
                                  },
                                  "task": {
                                    "type": "string"
                                  }
                                },
                                "required": [
                                  "subagentId",
                                  "personaId",
                                  "task"
                                ],
                                "additionalProperties": false
                              }
                            },
                            "required": [
                              "seq",
                              "ts",
                              "runId",
                              "type",
                              "data"
                            ],
                            "additionalProperties": false
                          },
                          {
                            "type": "object",
                            "properties": {
                              "seq": {
                                "type": "integer",
                                "exclusiveMinimum": 0,
                                "maximum": 9007199254740991
                              },
                              "ts": {
                                "type": "string",
                                "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))$"
                              },
                              "runId": {
                                "type": "string",
                                "pattern": "^run_[0-9A-Za-z]{8,64}$"
                              },
                              "persona": {
                                "type": "string",
                                "maxLength": 64,
                                "pattern": "^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$"
                              },
                              "type": {
                                "type": "string",
                                "const": "subagent.finished"
                              },
                              "data": {
                                "type": "object",
                                "properties": {
                                  "subagentId": {
                                    "type": "string",
                                    "minLength": 1
                                  },
                                  "personaId": {
                                    "type": "string",
                                    "maxLength": 64,
                                    "pattern": "^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$"
                                  },
                                  "status": {
                                    "type": "string",
                                    "enum": [
                                      "completed",
                                      "failed",
                                      "interrupted"
                                    ]
                                  },
                                  "summary": {
                                    "type": "string"
                                  }
                                },
                                "required": [
                                  "subagentId",
                                  "personaId",
                                  "status",
                                  "summary"
                                ],
                                "additionalProperties": false
                              }
                            },
                            "required": [
                              "seq",
                              "ts",
                              "runId",
                              "type",
                              "data"
                            ],
                            "additionalProperties": false
                          },
                          {
                            "type": "object",
                            "properties": {
                              "seq": {
                                "type": "integer",
                                "exclusiveMinimum": 0,
                                "maximum": 9007199254740991
                              },
                              "ts": {
                                "type": "string",
                                "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))$"
                              },
                              "runId": {
                                "type": "string",
                                "pattern": "^run_[0-9A-Za-z]{8,64}$"
                              },
                              "persona": {
                                "type": "string",
                                "maxLength": 64,
                                "pattern": "^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$"
                              },
                              "type": {
                                "type": "string",
                                "const": "permission.denied"
                              },
                              "data": {
                                "type": "object",
                                "properties": {
                                  "tool": {
                                    "type": "string",
                                    "minLength": 1
                                  },
                                  "summary": {
                                    "type": "string"
                                  },
                                  "reason": {
                                    "type": "string",
                                    "minLength": 1
                                  },
                                  "ruleId": {
                                    "type": [
                                      "string",
                                      "null"
                                    ]
                                  }
                                },
                                "required": [
                                  "tool",
                                  "summary",
                                  "reason",
                                  "ruleId"
                                ],
                                "additionalProperties": false
                              }
                            },
                            "required": [
                              "seq",
                              "ts",
                              "runId",
                              "type",
                              "data"
                            ],
                            "additionalProperties": false
                          },
                          {
                            "type": "object",
                            "properties": {
                              "seq": {
                                "type": "integer",
                                "exclusiveMinimum": 0,
                                "maximum": 9007199254740991
                              },
                              "ts": {
                                "type": "string",
                                "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))$"
                              },
                              "runId": {
                                "type": "string",
                                "pattern": "^run_[0-9A-Za-z]{8,64}$"
                              },
                              "persona": {
                                "type": "string",
                                "maxLength": 64,
                                "pattern": "^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$"
                              },
                              "type": {
                                "type": "string",
                                "const": "usage"
                              },
                              "data": {
                                "type": "object",
                                "properties": {
                                  "tokensIn": {
                                    "type": "integer",
                                    "minimum": 0,
                                    "maximum": 9007199254740991
                                  },
                                  "tokensOut": {
                                    "type": "integer",
                                    "minimum": 0,
                                    "maximum": 9007199254740991
                                  },
                                  "costCents": {
                                    "type": "integer",
                                    "minimum": 0,
                                    "maximum": 9007199254740991
                                  },
                                  "model": {
                                    "type": "string",
                                    "minLength": 1
                                  },
                                  "fixRound": {
                                    "type": "boolean"
                                  }
                                },
                                "required": [
                                  "tokensIn",
                                  "tokensOut",
                                  "costCents",
                                  "model",
                                  "fixRound"
                                ],
                                "additionalProperties": false
                              }
                            },
                            "required": [
                              "seq",
                              "ts",
                              "runId",
                              "type",
                              "data"
                            ],
                            "additionalProperties": false
                          },
                          {
                            "type": "object",
                            "properties": {
                              "seq": {
                                "type": "integer",
                                "exclusiveMinimum": 0,
                                "maximum": 9007199254740991
                              },
                              "ts": {
                                "type": "string",
                                "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))$"
                              },
                              "runId": {
                                "type": "string",
                                "pattern": "^run_[0-9A-Za-z]{8,64}$"
                              },
                              "persona": {
                                "type": "string",
                                "maxLength": 64,
                                "pattern": "^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$"
                              },
                              "type": {
                                "type": "string",
                                "const": "check.started"
                              },
                              "data": {
                                "type": "object",
                                "properties": {
                                  "checkId": {
                                    "type": "string",
                                    "pattern": "^chk_[0-9A-Za-z]{8,64}$"
                                  },
                                  "kind": {
                                    "type": "string",
                                    "enum": [
                                      "format",
                                      "lint",
                                      "typecheck",
                                      "build",
                                      "browser",
                                      "secret_scan",
                                      "migration"
                                    ]
                                  }
                                },
                                "required": [
                                  "checkId",
                                  "kind"
                                ],
                                "additionalProperties": false
                              }
                            },
                            "required": [
                              "seq",
                              "ts",
                              "runId",
                              "type",
                              "data"
                            ],
                            "additionalProperties": false
                          },
                          {
                            "type": "object",
                            "properties": {
                              "seq": {
                                "type": "integer",
                                "exclusiveMinimum": 0,
                                "maximum": 9007199254740991
                              },
                              "ts": {
                                "type": "string",
                                "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))$"
                              },
                              "runId": {
                                "type": "string",
                                "pattern": "^run_[0-9A-Za-z]{8,64}$"
                              },
                              "persona": {
                                "type": "string",
                                "maxLength": 64,
                                "pattern": "^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$"
                              },
                              "type": {
                                "type": "string",
                                "const": "check.finished"
                              },
                              "data": {
                                "type": "object",
                                "properties": {
                                  "result": {
                                    "type": "object",
                                    "properties": {
                                      "id": {
                                        "type": "string",
                                        "pattern": "^chk_[0-9A-Za-z]{8,64}$"
                                      },
                                      "kind": {
                                        "type": "string",
                                        "enum": [
                                          "format",
                                          "lint",
                                          "typecheck",
                                          "build",
                                          "browser",
                                          "secret_scan",
                                          "migration"
                                        ]
                                      },
                                      "status": {
                                        "type": "string",
                                        "enum": [
                                          "passed",
                                          "failed",
                                          "skipped",
                                          "error"
                                        ]
                                      },
                                      "summary": {
                                        "type": "string"
                                      },
                                      "durationMs": {
                                        "type": "integer",
                                        "minimum": 0,
                                        "maximum": 9007199254740991
                                      },
                                      "issues": {
                                        "type": "array",
                                        "items": {
                                          "type": "object",
                                          "properties": {
                                            "severity": {
                                              "type": "string",
                                              "enum": [
                                                "error",
                                                "warning"
                                              ]
                                            },
                                            "message": {
                                              "type": "string",
                                              "minLength": 1
                                            },
                                            "file": {
                                              "type": [
                                                "string",
                                                "null"
                                              ]
                                            },
                                            "line": {
                                              "anyOf": [
                                                {
                                                  "type": "integer",
                                                  "exclusiveMinimum": 0,
                                                  "maximum": 9007199254740991
                                                },
                                                {
                                                  "type": "null"
                                                }
                                              ]
                                            },
                                            "column": {
                                              "anyOf": [
                                                {
                                                  "type": "integer",
                                                  "exclusiveMinimum": 0,
                                                  "maximum": 9007199254740991
                                                },
                                                {
                                                  "type": "null"
                                                }
                                              ]
                                            },
                                            "code": {
                                              "type": [
                                                "string",
                                                "null"
                                              ]
                                            }
                                          },
                                          "required": [
                                            "severity",
                                            "message",
                                            "file",
                                            "line",
                                            "column",
                                            "code"
                                          ],
                                          "additionalProperties": false
                                        }
                                      },
                                      "screenshotPath": {
                                        "type": [
                                          "string",
                                          "null"
                                        ]
                                      },
                                      "autoFixed": {
                                        "type": "boolean"
                                      }
                                    },
                                    "required": [
                                      "id",
                                      "kind",
                                      "status",
                                      "summary",
                                      "durationMs",
                                      "issues",
                                      "screenshotPath",
                                      "autoFixed"
                                    ],
                                    "additionalProperties": false
                                  }
                                },
                                "required": [
                                  "result"
                                ],
                                "additionalProperties": false
                              }
                            },
                            "required": [
                              "seq",
                              "ts",
                              "runId",
                              "type",
                              "data"
                            ],
                            "additionalProperties": false
                          },
                          {
                            "type": "object",
                            "properties": {
                              "seq": {
                                "type": "integer",
                                "exclusiveMinimum": 0,
                                "maximum": 9007199254740991
                              },
                              "ts": {
                                "type": "string",
                                "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))$"
                              },
                              "runId": {
                                "type": "string",
                                "pattern": "^run_[0-9A-Za-z]{8,64}$"
                              },
                              "persona": {
                                "type": "string",
                                "maxLength": 64,
                                "pattern": "^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$"
                              },
                              "type": {
                                "type": "string",
                                "const": "restore-point.created"
                              },
                              "data": {
                                "type": "object",
                                "properties": {
                                  "commit": {
                                    "type": "string",
                                    "pattern": "^(?:[0-9a-f]{40}|[0-9a-f]{64})$"
                                  },
                                  "message": {
                                    "type": "string"
                                  },
                                  "versionId": {
                                    "anyOf": [
                                      {
                                        "type": "string",
                                        "pattern": "^ver_[0-9A-Za-z]{8,64}$"
                                      },
                                      {
                                        "type": "null"
                                      }
                                    ]
                                  }
                                },
                                "required": [
                                  "commit",
                                  "message",
                                  "versionId"
                                ],
                                "additionalProperties": false
                              }
                            },
                            "required": [
                              "seq",
                              "ts",
                              "runId",
                              "type",
                              "data"
                            ],
                            "additionalProperties": false
                          },
                          {
                            "type": "object",
                            "properties": {
                              "seq": {
                                "type": "integer",
                                "exclusiveMinimum": 0,
                                "maximum": 9007199254740991
                              },
                              "ts": {
                                "type": "string",
                                "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))$"
                              },
                              "runId": {
                                "type": "string",
                                "pattern": "^run_[0-9A-Za-z]{8,64}$"
                              },
                              "persona": {
                                "type": "string",
                                "maxLength": 64,
                                "pattern": "^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$"
                              },
                              "type": {
                                "type": "string",
                                "const": "run.finished"
                              },
                              "data": {
                                "type": "object",
                                "properties": {
                                  "summary": {
                                    "type": "string"
                                  },
                                  "commit": {
                                    "anyOf": [
                                      {
                                        "type": "string",
                                        "pattern": "^(?:[0-9a-f]{40}|[0-9a-f]{64})$"
                                      },
                                      {
                                        "type": "null"
                                      }
                                    ]
                                  },
                                  "totals": {
                                    "type": "object",
                                    "properties": {
                                      "tokensIn": {
                                        "type": "integer",
                                        "minimum": 0,
                                        "maximum": 9007199254740991
                                      },
                                      "tokensOut": {
                                        "type": "integer",
                                        "minimum": 0,
                                        "maximum": 9007199254740991
                                      },
                                      "costCents": {
                                        "type": "integer",
                                        "minimum": 0,
                                        "maximum": 9007199254740991
                                      },
                                      "steps": {
                                        "type": "integer",
                                        "minimum": 0,
                                        "maximum": 9007199254740991
                                      },
                                      "wallSeconds": {
                                        "type": "integer",
                                        "minimum": 0,
                                        "maximum": 9007199254740991
                                      },
                                      "fixRounds": {
                                        "type": "integer",
                                        "minimum": 0,
                                        "maximum": 9007199254740991
                                      }
                                    },
                                    "required": [
                                      "tokensIn",
                                      "tokensOut",
                                      "costCents",
                                      "steps",
                                      "wallSeconds",
                                      "fixRounds"
                                    ],
                                    "additionalProperties": false
                                  }
                                },
                                "required": [
                                  "summary",
                                  "commit",
                                  "totals"
                                ],
                                "additionalProperties": false
                              }
                            },
                            "required": [
                              "seq",
                              "ts",
                              "runId",
                              "type",
                              "data"
                            ],
                            "additionalProperties": false
                          },
                          {
                            "type": "object",
                            "properties": {
                              "seq": {
                                "type": "integer",
                                "exclusiveMinimum": 0,
                                "maximum": 9007199254740991
                              },
                              "ts": {
                                "type": "string",
                                "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))$"
                              },
                              "runId": {
                                "type": "string",
                                "pattern": "^run_[0-9A-Za-z]{8,64}$"
                              },
                              "persona": {
                                "type": "string",
                                "maxLength": 64,
                                "pattern": "^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$"
                              },
                              "type": {
                                "type": "string",
                                "const": "run.failed"
                              },
                              "data": {
                                "type": "object",
                                "properties": {
                                  "reason": {
                                    "type": "string",
                                    "enum": [
                                      "checks_failed",
                                      "cost_limit",
                                      "wall_limit",
                                      "step_limit",
                                      "interrupted",
                                      "engine_error",
                                      "pack_mismatch",
                                      "sandbox_lost",
                                      "refused",
                                      "internal"
                                    ]
                                  },
                                  "message": {
                                    "type": "string",
                                    "minLength": 1
                                  },
                                  "lastGoodCommit": {
                                    "anyOf": [
                                      {
                                        "type": "string",
                                        "pattern": "^(?:[0-9a-f]{40}|[0-9a-f]{64})$"
                                      },
                                      {
                                        "type": "null"
                                      }
                                    ]
                                  },
                                  "totals": {
                                    "type": "object",
                                    "properties": {
                                      "tokensIn": {
                                        "type": "integer",
                                        "minimum": 0,
                                        "maximum": 9007199254740991
                                      },
                                      "tokensOut": {
                                        "type": "integer",
                                        "minimum": 0,
                                        "maximum": 9007199254740991
                                      },
                                      "costCents": {
                                        "type": "integer",
                                        "minimum": 0,
                                        "maximum": 9007199254740991
                                      },
                                      "steps": {
                                        "type": "integer",
                                        "minimum": 0,
                                        "maximum": 9007199254740991
                                      },
                                      "wallSeconds": {
                                        "type": "integer",
                                        "minimum": 0,
                                        "maximum": 9007199254740991
                                      },
                                      "fixRounds": {
                                        "type": "integer",
                                        "minimum": 0,
                                        "maximum": 9007199254740991
                                      }
                                    },
                                    "required": [
                                      "tokensIn",
                                      "tokensOut",
                                      "costCents",
                                      "steps",
                                      "wallSeconds",
                                      "fixRounds"
                                    ],
                                    "additionalProperties": false
                                  }
                                },
                                "required": [
                                  "reason",
                                  "message",
                                  "lastGoodCommit",
                                  "totals"
                                ],
                                "additionalProperties": false
                              }
                            },
                            "required": [
                              "seq",
                              "ts",
                              "runId",
                              "type",
                              "data"
                            ],
                            "additionalProperties": false
                          }
                        ]
                      }
                    },
                    "nextAfter": {
                      "anyOf": [
                        {
                          "type": "integer",
                          "minimum": 0,
                          "maximum": 9007199254740991
                        },
                        {
                          "type": "null"
                        }
                      ]
                    }
                  },
                  "required": [
                    "events",
                    "nextAfter"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "default": {
            "description": "Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            }
          }
        },
        "x-permission": "run.read"
      }
    },
    "/api/projects/{id}/versions": {
      "get": {
        "operationId": "listVersions",
        "summary": "A project's restore points.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^prj_[0-9A-Za-z]{8,64}$"
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "minLength": 1
            }
          },
          {
            "name": "limit",
            "in": "query",
            "required": true,
            "schema": {
              "default": 50,
              "type": "integer",
              "minimum": 1,
              "maximum": 100
            }
          }
        ],
        "security": [
          {
            "session": []
          },
          {
            "token": []
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$schema": "https://json-schema.org/draft/2020-12/schema",
                  "type": "object",
                  "properties": {
                    "versions": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string",
                            "pattern": "^ver_[0-9A-Za-z]{8,64}$"
                          },
                          "projectId": {
                            "type": "string",
                            "pattern": "^prj_[0-9A-Za-z]{8,64}$"
                          },
                          "runId": {
                            "anyOf": [
                              {
                                "type": "string",
                                "pattern": "^run_[0-9A-Za-z]{8,64}$"
                              },
                              {
                                "type": "null"
                              }
                            ]
                          },
                          "commit": {
                            "type": "string",
                            "pattern": "^(?:[0-9a-f]{40}|[0-9a-f]{64})$"
                          },
                          "label": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 200
                          },
                          "restoredFrom": {
                            "anyOf": [
                              {
                                "type": "string",
                                "pattern": "^ver_[0-9A-Za-z]{8,64}$"
                              },
                              {
                                "type": "null"
                              }
                            ]
                          },
                          "createdBy": {
                            "anyOf": [
                              {
                                "type": "string",
                                "pattern": "^usr_[0-9A-Za-z]{8,64}$"
                              },
                              {
                                "type": "null"
                              }
                            ]
                          },
                          "createdAt": {
                            "type": "string",
                            "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))$"
                          }
                        },
                        "required": [
                          "id",
                          "projectId",
                          "runId",
                          "commit",
                          "label",
                          "restoredFrom",
                          "createdBy",
                          "createdAt"
                        ],
                        "additionalProperties": false
                      }
                    },
                    "nextCursor": {
                      "type": [
                        "string",
                        "null"
                      ]
                    }
                  },
                  "required": [
                    "versions",
                    "nextCursor"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "default": {
            "description": "Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            }
          }
        },
        "x-permission": "project.read"
      }
    },
    "/api/projects/{id}/restore": {
      "post": {
        "operationId": "restoreProject",
        "summary": "Restore a version as a new commit.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^prj_[0-9A-Za-z]{8,64}$"
            }
          }
        ],
        "security": [
          {
            "session": []
          },
          {
            "token": []
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$schema": "https://json-schema.org/draft/2020-12/schema",
                  "type": "object",
                  "properties": {
                    "version": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "type": "string",
                          "pattern": "^ver_[0-9A-Za-z]{8,64}$"
                        },
                        "projectId": {
                          "type": "string",
                          "pattern": "^prj_[0-9A-Za-z]{8,64}$"
                        },
                        "runId": {
                          "anyOf": [
                            {
                              "type": "string",
                              "pattern": "^run_[0-9A-Za-z]{8,64}$"
                            },
                            {
                              "type": "null"
                            }
                          ]
                        },
                        "commit": {
                          "type": "string",
                          "pattern": "^(?:[0-9a-f]{40}|[0-9a-f]{64})$"
                        },
                        "label": {
                          "type": "string",
                          "minLength": 1,
                          "maxLength": 200
                        },
                        "restoredFrom": {
                          "anyOf": [
                            {
                              "type": "string",
                              "pattern": "^ver_[0-9A-Za-z]{8,64}$"
                            },
                            {
                              "type": "null"
                            }
                          ]
                        },
                        "createdBy": {
                          "anyOf": [
                            {
                              "type": "string",
                              "pattern": "^usr_[0-9A-Za-z]{8,64}$"
                            },
                            {
                              "type": "null"
                            }
                          ]
                        },
                        "createdAt": {
                          "type": "string",
                          "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))$"
                        }
                      },
                      "required": [
                        "id",
                        "projectId",
                        "runId",
                        "commit",
                        "label",
                        "restoredFrom",
                        "createdBy",
                        "createdAt"
                      ],
                      "additionalProperties": false
                    }
                  },
                  "required": [
                    "version"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "default": {
            "description": "Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            }
          }
        },
        "x-permission": "version.restore",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$schema": "https://json-schema.org/draft/2020-12/schema",
                "type": "object",
                "properties": {
                  "versionId": {
                    "type": "string",
                    "pattern": "^ver_[0-9A-Za-z]{8,64}$"
                  }
                },
                "required": [
                  "versionId"
                ]
              }
            }
          }
        }
      }
    },
    "/api/projects/{id}/publish": {
      "post": {
        "operationId": "publishProject",
        "summary": "Ask to publish a version.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^prj_[0-9A-Za-z]{8,64}$"
            }
          }
        ],
        "security": [
          {
            "session": []
          },
          {
            "token": []
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$schema": "https://json-schema.org/draft/2020-12/schema",
                  "type": "object",
                  "properties": {
                    "approval": {
                      "anyOf": [
                        {
                          "type": "object",
                          "properties": {
                            "id": {
                              "type": "string",
                              "pattern": "^apr_[0-9A-Za-z]{8,64}$"
                            },
                            "organisationId": {
                              "type": "string",
                              "pattern": "^org_[0-9A-Za-z]{8,64}$"
                            },
                            "projectId": {
                              "type": "string",
                              "pattern": "^prj_[0-9A-Za-z]{8,64}$"
                            },
                            "runId": {
                              "anyOf": [
                                {
                                  "type": "string",
                                  "pattern": "^run_[0-9A-Za-z]{8,64}$"
                                },
                                {
                                  "type": "null"
                                }
                              ]
                            },
                            "kind": {
                              "type": "string",
                              "enum": [
                                "publish",
                                "destructive_migration",
                                "budget_overrun",
                                "connector_enable",
                                "plan"
                              ]
                            },
                            "status": {
                              "type": "string",
                              "enum": [
                                "pending",
                                "approved",
                                "rejected",
                                "expired"
                              ]
                            },
                            "reason": {
                              "type": "string",
                              "minLength": 1
                            },
                            "subject": {
                              "oneOf": [
                                {
                                  "type": "object",
                                  "properties": {
                                    "kind": {
                                      "type": "string",
                                      "const": "publish"
                                    },
                                    "versionId": {
                                      "type": "string",
                                      "pattern": "^ver_[0-9A-Za-z]{8,64}$"
                                    }
                                  },
                                  "required": [
                                    "kind",
                                    "versionId"
                                  ],
                                  "additionalProperties": false
                                },
                                {
                                  "type": "object",
                                  "properties": {
                                    "kind": {
                                      "type": "string",
                                      "const": "destructive_migration"
                                    },
                                    "versionId": {
                                      "type": "string",
                                      "pattern": "^ver_[0-9A-Za-z]{8,64}$"
                                    },
                                    "statements": {
                                      "minItems": 1,
                                      "type": "array",
                                      "items": {
                                        "type": "string",
                                        "minLength": 1
                                      }
                                    }
                                  },
                                  "required": [
                                    "kind",
                                    "versionId",
                                    "statements"
                                  ],
                                  "additionalProperties": false
                                },
                                {
                                  "type": "object",
                                  "properties": {
                                    "kind": {
                                      "type": "string",
                                      "const": "budget_overrun"
                                    },
                                    "runId": {
                                      "type": "string",
                                      "pattern": "^run_[0-9A-Za-z]{8,64}$"
                                    },
                                    "spentCents": {
                                      "type": "integer",
                                      "minimum": 0,
                                      "maximum": 9007199254740991
                                    },
                                    "limitCents": {
                                      "type": "integer",
                                      "minimum": 0,
                                      "maximum": 9007199254740991
                                    }
                                  },
                                  "required": [
                                    "kind",
                                    "runId",
                                    "spentCents",
                                    "limitCents"
                                  ],
                                  "additionalProperties": false
                                },
                                {
                                  "type": "object",
                                  "properties": {
                                    "kind": {
                                      "type": "string",
                                      "const": "connector_enable"
                                    },
                                    "connectorId": {
                                      "type": "string",
                                      "maxLength": 64,
                                      "pattern": "^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$"
                                    }
                                  },
                                  "required": [
                                    "kind",
                                    "connectorId"
                                  ],
                                  "additionalProperties": false
                                },
                                {
                                  "type": "object",
                                  "properties": {
                                    "kind": {
                                      "type": "string",
                                      "const": "plan"
                                    },
                                    "runId": {
                                      "type": "string",
                                      "pattern": "^run_[0-9A-Za-z]{8,64}$"
                                    },
                                    "plan": {
                                      "type": "string",
                                      "minLength": 1
                                    }
                                  },
                                  "required": [
                                    "kind",
                                    "runId",
                                    "plan"
                                  ],
                                  "additionalProperties": false
                                }
                              ]
                            },
                            "requestedAt": {
                              "type": "string",
                              "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))$"
                            },
                            "expiresAt": {
                              "anyOf": [
                                {
                                  "type": "string",
                                  "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": "null"
                                }
                              ]
                            },
                            "decidedBy": {
                              "anyOf": [
                                {
                                  "type": "string",
                                  "pattern": "^usr_[0-9A-Za-z]{8,64}$"
                                },
                                {
                                  "type": "null"
                                }
                              ]
                            },
                            "decidedAt": {
                              "anyOf": [
                                {
                                  "type": "string",
                                  "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": "null"
                                }
                              ]
                            },
                            "note": {
                              "type": [
                                "string",
                                "null"
                              ]
                            }
                          },
                          "required": [
                            "id",
                            "organisationId",
                            "projectId",
                            "runId",
                            "kind",
                            "status",
                            "reason",
                            "subject",
                            "requestedAt",
                            "expiresAt",
                            "decidedBy",
                            "decidedAt",
                            "note"
                          ],
                          "additionalProperties": false
                        },
                        {
                          "type": "null"
                        }
                      ]
                    },
                    "deployment": {
                      "anyOf": [
                        {
                          "type": "object",
                          "properties": {
                            "id": {
                              "type": "string",
                              "pattern": "^dep_[0-9A-Za-z]{8,64}$"
                            },
                            "projectId": {
                              "type": "string",
                              "pattern": "^prj_[0-9A-Za-z]{8,64}$"
                            },
                            "versionId": {
                              "type": "string",
                              "pattern": "^ver_[0-9A-Za-z]{8,64}$"
                            },
                            "status": {
                              "type": "string",
                              "enum": [
                                "pending",
                                "building",
                                "live",
                                "failed",
                                "superseded",
                                "rolled_back"
                              ]
                            },
                            "scriptName": {
                              "type": "string",
                              "minLength": 1
                            },
                            "url": {
                              "anyOf": [
                                {
                                  "type": "string",
                                  "format": "uri"
                                },
                                {
                                  "type": "null"
                                }
                              ]
                            },
                            "buildKey": {
                              "type": [
                                "string",
                                "null"
                              ]
                            },
                            "rollbackOf": {
                              "anyOf": [
                                {
                                  "type": "string",
                                  "pattern": "^dep_[0-9A-Za-z]{8,64}$"
                                },
                                {
                                  "type": "null"
                                }
                              ]
                            },
                            "error": {
                              "type": [
                                "string",
                                "null"
                              ]
                            },
                            "createdBy": {
                              "type": "string",
                              "pattern": "^usr_[0-9A-Za-z]{8,64}$"
                            },
                            "createdAt": {
                              "type": "string",
                              "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))$"
                            },
                            "finishedAt": {
                              "anyOf": [
                                {
                                  "type": "string",
                                  "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": "null"
                                }
                              ]
                            }
                          },
                          "required": [
                            "id",
                            "projectId",
                            "versionId",
                            "status",
                            "scriptName",
                            "url",
                            "buildKey",
                            "rollbackOf",
                            "error",
                            "createdBy",
                            "createdAt",
                            "finishedAt"
                          ],
                          "additionalProperties": false
                        },
                        {
                          "type": "null"
                        }
                      ]
                    }
                  },
                  "required": [
                    "approval",
                    "deployment"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "default": {
            "description": "Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            }
          }
        },
        "x-permission": "publish.start",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$schema": "https://json-schema.org/draft/2020-12/schema",
                "type": "object",
                "properties": {
                  "versionId": {
                    "type": "string",
                    "pattern": "^ver_[0-9A-Za-z]{8,64}$"
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/projects/{id}/deployments": {
      "get": {
        "operationId": "listDeployments",
        "summary": "A project's deployments.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^prj_[0-9A-Za-z]{8,64}$"
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "minLength": 1
            }
          },
          {
            "name": "limit",
            "in": "query",
            "required": true,
            "schema": {
              "default": 50,
              "type": "integer",
              "minimum": 1,
              "maximum": 100
            }
          }
        ],
        "security": [
          {
            "session": []
          },
          {
            "token": []
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$schema": "https://json-schema.org/draft/2020-12/schema",
                  "type": "object",
                  "properties": {
                    "deployments": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string",
                            "pattern": "^dep_[0-9A-Za-z]{8,64}$"
                          },
                          "projectId": {
                            "type": "string",
                            "pattern": "^prj_[0-9A-Za-z]{8,64}$"
                          },
                          "versionId": {
                            "type": "string",
                            "pattern": "^ver_[0-9A-Za-z]{8,64}$"
                          },
                          "status": {
                            "type": "string",
                            "enum": [
                              "pending",
                              "building",
                              "live",
                              "failed",
                              "superseded",
                              "rolled_back"
                            ]
                          },
                          "scriptName": {
                            "type": "string",
                            "minLength": 1
                          },
                          "url": {
                            "anyOf": [
                              {
                                "type": "string",
                                "format": "uri"
                              },
                              {
                                "type": "null"
                              }
                            ]
                          },
                          "buildKey": {
                            "type": [
                              "string",
                              "null"
                            ]
                          },
                          "rollbackOf": {
                            "anyOf": [
                              {
                                "type": "string",
                                "pattern": "^dep_[0-9A-Za-z]{8,64}$"
                              },
                              {
                                "type": "null"
                              }
                            ]
                          },
                          "error": {
                            "type": [
                              "string",
                              "null"
                            ]
                          },
                          "createdBy": {
                            "type": "string",
                            "pattern": "^usr_[0-9A-Za-z]{8,64}$"
                          },
                          "createdAt": {
                            "type": "string",
                            "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))$"
                          },
                          "finishedAt": {
                            "anyOf": [
                              {
                                "type": "string",
                                "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": "null"
                              }
                            ]
                          }
                        },
                        "required": [
                          "id",
                          "projectId",
                          "versionId",
                          "status",
                          "scriptName",
                          "url",
                          "buildKey",
                          "rollbackOf",
                          "error",
                          "createdBy",
                          "createdAt",
                          "finishedAt"
                        ],
                        "additionalProperties": false
                      }
                    },
                    "nextCursor": {
                      "type": [
                        "string",
                        "null"
                      ]
                    }
                  },
                  "required": [
                    "deployments",
                    "nextCursor"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "default": {
            "description": "Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            }
          }
        },
        "x-permission": "project.read"
      }
    },
    "/api/deployments/{id}/rollback": {
      "post": {
        "operationId": "rollbackDeployment",
        "summary": "Upload an earlier deployment's build again.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^dep_[0-9A-Za-z]{8,64}$"
            }
          }
        ],
        "security": [
          {
            "session": []
          },
          {
            "token": []
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$schema": "https://json-schema.org/draft/2020-12/schema",
                  "type": "object",
                  "properties": {
                    "deployment": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "type": "string",
                          "pattern": "^dep_[0-9A-Za-z]{8,64}$"
                        },
                        "projectId": {
                          "type": "string",
                          "pattern": "^prj_[0-9A-Za-z]{8,64}$"
                        },
                        "versionId": {
                          "type": "string",
                          "pattern": "^ver_[0-9A-Za-z]{8,64}$"
                        },
                        "status": {
                          "type": "string",
                          "enum": [
                            "pending",
                            "building",
                            "live",
                            "failed",
                            "superseded",
                            "rolled_back"
                          ]
                        },
                        "scriptName": {
                          "type": "string",
                          "minLength": 1
                        },
                        "url": {
                          "anyOf": [
                            {
                              "type": "string",
                              "format": "uri"
                            },
                            {
                              "type": "null"
                            }
                          ]
                        },
                        "buildKey": {
                          "type": [
                            "string",
                            "null"
                          ]
                        },
                        "rollbackOf": {
                          "anyOf": [
                            {
                              "type": "string",
                              "pattern": "^dep_[0-9A-Za-z]{8,64}$"
                            },
                            {
                              "type": "null"
                            }
                          ]
                        },
                        "error": {
                          "type": [
                            "string",
                            "null"
                          ]
                        },
                        "createdBy": {
                          "type": "string",
                          "pattern": "^usr_[0-9A-Za-z]{8,64}$"
                        },
                        "createdAt": {
                          "type": "string",
                          "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))$"
                        },
                        "finishedAt": {
                          "anyOf": [
                            {
                              "type": "string",
                              "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": "null"
                            }
                          ]
                        }
                      },
                      "required": [
                        "id",
                        "projectId",
                        "versionId",
                        "status",
                        "scriptName",
                        "url",
                        "buildKey",
                        "rollbackOf",
                        "error",
                        "createdBy",
                        "createdAt",
                        "finishedAt"
                      ],
                      "additionalProperties": false
                    }
                  },
                  "required": [
                    "deployment"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "default": {
            "description": "Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            }
          }
        },
        "x-permission": "deployment.rollback",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$schema": "https://json-schema.org/draft/2020-12/schema",
                "type": "object",
                "properties": {
                  "reason": {
                    "type": "string",
                    "maxLength": 500
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/projects/{id}/files": {
      "get": {
        "operationId": "listFiles",
        "summary": "A project's file tree.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^prj_[0-9A-Za-z]{8,64}$"
            }
          },
          {
            "name": "path",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "versionId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^ver_[0-9A-Za-z]{8,64}$"
            }
          }
        ],
        "security": [
          {
            "session": []
          },
          {
            "token": []
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$schema": "https://json-schema.org/draft/2020-12/schema",
                  "type": "object",
                  "properties": {
                    "entries": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "path": {
                            "type": "string",
                            "minLength": 1
                          },
                          "kind": {
                            "type": "string",
                            "enum": [
                              "file",
                              "dir"
                            ]
                          },
                          "size": {
                            "anyOf": [
                              {
                                "type": "integer",
                                "minimum": 0,
                                "maximum": 9007199254740991
                              },
                              {
                                "type": "null"
                              }
                            ]
                          }
                        },
                        "required": [
                          "path",
                          "kind",
                          "size"
                        ],
                        "additionalProperties": false
                      }
                    }
                  },
                  "required": [
                    "entries"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "default": {
            "description": "Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            }
          }
        },
        "x-permission": "files.read"
      }
    },
    "/api/projects/{id}/files/{path}": {
      "get": {
        "operationId": "getFile",
        "summary": "One file of a project.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^prj_[0-9A-Za-z]{8,64}$"
            }
          },
          {
            "name": "path",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 1
            }
          },
          {
            "name": "versionId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^ver_[0-9A-Za-z]{8,64}$"
            }
          }
        ],
        "security": [
          {
            "session": []
          },
          {
            "token": []
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$schema": "https://json-schema.org/draft/2020-12/schema",
                  "type": "object",
                  "properties": {
                    "path": {
                      "type": "string",
                      "minLength": 1
                    },
                    "encoding": {
                      "type": "string",
                      "enum": [
                        "utf8",
                        "base64"
                      ]
                    },
                    "content": {
                      "type": "string"
                    },
                    "size": {
                      "type": "integer",
                      "minimum": 0,
                      "maximum": 9007199254740991
                    }
                  },
                  "required": [
                    "path",
                    "encoding",
                    "content",
                    "size"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "default": {
            "description": "Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            }
          }
        },
        "x-permission": "files.read"
      }
    },
    "/api/projects/{id}/diff": {
      "get": {
        "operationId": "getDiff",
        "summary": "The diff of a run or between versions.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^prj_[0-9A-Za-z]{8,64}$"
            }
          },
          {
            "name": "runId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^run_[0-9A-Za-z]{8,64}$"
            }
          },
          {
            "name": "from",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^ver_[0-9A-Za-z]{8,64}$"
            }
          },
          {
            "name": "to",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^ver_[0-9A-Za-z]{8,64}$"
            }
          }
        ],
        "security": [
          {
            "session": []
          },
          {
            "token": []
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$schema": "https://json-schema.org/draft/2020-12/schema",
                  "type": "object",
                  "properties": {
                    "files": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "path": {
                            "type": "string",
                            "minLength": 1
                          },
                          "oldPath": {
                            "type": [
                              "string",
                              "null"
                            ]
                          },
                          "change": {
                            "type": "string",
                            "enum": [
                              "added",
                              "modified",
                              "deleted",
                              "renamed"
                            ]
                          },
                          "additions": {
                            "type": "integer",
                            "minimum": 0,
                            "maximum": 9007199254740991
                          },
                          "deletions": {
                            "type": "integer",
                            "minimum": 0,
                            "maximum": 9007199254740991
                          },
                          "patch": {
                            "type": [
                              "string",
                              "null"
                            ]
                          }
                        },
                        "required": [
                          "path",
                          "oldPath",
                          "change",
                          "additions",
                          "deletions",
                          "patch"
                        ],
                        "additionalProperties": false
                      }
                    }
                  },
                  "required": [
                    "files"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "default": {
            "description": "Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            }
          }
        },
        "x-permission": "files.read"
      }
    },
    "/api/approvals": {
      "get": {
        "operationId": "listApprovals",
        "summary": "The \"needs you\" list.",
        "parameters": [
          {
            "name": "cursor",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "minLength": 1
            }
          },
          {
            "name": "limit",
            "in": "query",
            "required": true,
            "schema": {
              "default": 50,
              "type": "integer",
              "minimum": 1,
              "maximum": 100
            }
          },
          {
            "name": "status",
            "in": "query",
            "required": true,
            "schema": {
              "default": "pending",
              "type": "string",
              "enum": [
                "pending",
                "approved",
                "rejected",
                "expired"
              ]
            }
          },
          {
            "name": "projectId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^prj_[0-9A-Za-z]{8,64}$"
            }
          }
        ],
        "security": [
          {
            "session": []
          },
          {
            "token": []
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$schema": "https://json-schema.org/draft/2020-12/schema",
                  "type": "object",
                  "properties": {
                    "approvals": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string",
                            "pattern": "^apr_[0-9A-Za-z]{8,64}$"
                          },
                          "organisationId": {
                            "type": "string",
                            "pattern": "^org_[0-9A-Za-z]{8,64}$"
                          },
                          "projectId": {
                            "type": "string",
                            "pattern": "^prj_[0-9A-Za-z]{8,64}$"
                          },
                          "runId": {
                            "anyOf": [
                              {
                                "type": "string",
                                "pattern": "^run_[0-9A-Za-z]{8,64}$"
                              },
                              {
                                "type": "null"
                              }
                            ]
                          },
                          "kind": {
                            "type": "string",
                            "enum": [
                              "publish",
                              "destructive_migration",
                              "budget_overrun",
                              "connector_enable",
                              "plan"
                            ]
                          },
                          "status": {
                            "type": "string",
                            "enum": [
                              "pending",
                              "approved",
                              "rejected",
                              "expired"
                            ]
                          },
                          "reason": {
                            "type": "string",
                            "minLength": 1
                          },
                          "subject": {
                            "oneOf": [
                              {
                                "type": "object",
                                "properties": {
                                  "kind": {
                                    "type": "string",
                                    "const": "publish"
                                  },
                                  "versionId": {
                                    "type": "string",
                                    "pattern": "^ver_[0-9A-Za-z]{8,64}$"
                                  }
                                },
                                "required": [
                                  "kind",
                                  "versionId"
                                ],
                                "additionalProperties": false
                              },
                              {
                                "type": "object",
                                "properties": {
                                  "kind": {
                                    "type": "string",
                                    "const": "destructive_migration"
                                  },
                                  "versionId": {
                                    "type": "string",
                                    "pattern": "^ver_[0-9A-Za-z]{8,64}$"
                                  },
                                  "statements": {
                                    "minItems": 1,
                                    "type": "array",
                                    "items": {
                                      "type": "string",
                                      "minLength": 1
                                    }
                                  }
                                },
                                "required": [
                                  "kind",
                                  "versionId",
                                  "statements"
                                ],
                                "additionalProperties": false
                              },
                              {
                                "type": "object",
                                "properties": {
                                  "kind": {
                                    "type": "string",
                                    "const": "budget_overrun"
                                  },
                                  "runId": {
                                    "type": "string",
                                    "pattern": "^run_[0-9A-Za-z]{8,64}$"
                                  },
                                  "spentCents": {
                                    "type": "integer",
                                    "minimum": 0,
                                    "maximum": 9007199254740991
                                  },
                                  "limitCents": {
                                    "type": "integer",
                                    "minimum": 0,
                                    "maximum": 9007199254740991
                                  }
                                },
                                "required": [
                                  "kind",
                                  "runId",
                                  "spentCents",
                                  "limitCents"
                                ],
                                "additionalProperties": false
                              },
                              {
                                "type": "object",
                                "properties": {
                                  "kind": {
                                    "type": "string",
                                    "const": "connector_enable"
                                  },
                                  "connectorId": {
                                    "type": "string",
                                    "maxLength": 64,
                                    "pattern": "^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$"
                                  }
                                },
                                "required": [
                                  "kind",
                                  "connectorId"
                                ],
                                "additionalProperties": false
                              },
                              {
                                "type": "object",
                                "properties": {
                                  "kind": {
                                    "type": "string",
                                    "const": "plan"
                                  },
                                  "runId": {
                                    "type": "string",
                                    "pattern": "^run_[0-9A-Za-z]{8,64}$"
                                  },
                                  "plan": {
                                    "type": "string",
                                    "minLength": 1
                                  }
                                },
                                "required": [
                                  "kind",
                                  "runId",
                                  "plan"
                                ],
                                "additionalProperties": false
                              }
                            ]
                          },
                          "requestedAt": {
                            "type": "string",
                            "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))$"
                          },
                          "expiresAt": {
                            "anyOf": [
                              {
                                "type": "string",
                                "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": "null"
                              }
                            ]
                          },
                          "decidedBy": {
                            "anyOf": [
                              {
                                "type": "string",
                                "pattern": "^usr_[0-9A-Za-z]{8,64}$"
                              },
                              {
                                "type": "null"
                              }
                            ]
                          },
                          "decidedAt": {
                            "anyOf": [
                              {
                                "type": "string",
                                "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": "null"
                              }
                            ]
                          },
                          "note": {
                            "type": [
                              "string",
                              "null"
                            ]
                          }
                        },
                        "required": [
                          "id",
                          "organisationId",
                          "projectId",
                          "runId",
                          "kind",
                          "status",
                          "reason",
                          "subject",
                          "requestedAt",
                          "expiresAt",
                          "decidedBy",
                          "decidedAt",
                          "note"
                        ],
                        "additionalProperties": false
                      }
                    },
                    "nextCursor": {
                      "type": [
                        "string",
                        "null"
                      ]
                    }
                  },
                  "required": [
                    "approvals",
                    "nextCursor"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "default": {
            "description": "Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            }
          }
        },
        "x-permission": "project.read"
      }
    },
    "/api/approvals/{id}": {
      "post": {
        "operationId": "decideApproval",
        "summary": "Decide an approval (publish approvals also need publish.approve).",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^apr_[0-9A-Za-z]{8,64}$"
            }
          }
        ],
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$schema": "https://json-schema.org/draft/2020-12/schema",
                  "type": "object",
                  "properties": {
                    "approval": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "type": "string",
                          "pattern": "^apr_[0-9A-Za-z]{8,64}$"
                        },
                        "organisationId": {
                          "type": "string",
                          "pattern": "^org_[0-9A-Za-z]{8,64}$"
                        },
                        "projectId": {
                          "type": "string",
                          "pattern": "^prj_[0-9A-Za-z]{8,64}$"
                        },
                        "runId": {
                          "anyOf": [
                            {
                              "type": "string",
                              "pattern": "^run_[0-9A-Za-z]{8,64}$"
                            },
                            {
                              "type": "null"
                            }
                          ]
                        },
                        "kind": {
                          "type": "string",
                          "enum": [
                            "publish",
                            "destructive_migration",
                            "budget_overrun",
                            "connector_enable",
                            "plan"
                          ]
                        },
                        "status": {
                          "type": "string",
                          "enum": [
                            "pending",
                            "approved",
                            "rejected",
                            "expired"
                          ]
                        },
                        "reason": {
                          "type": "string",
                          "minLength": 1
                        },
                        "subject": {
                          "oneOf": [
                            {
                              "type": "object",
                              "properties": {
                                "kind": {
                                  "type": "string",
                                  "const": "publish"
                                },
                                "versionId": {
                                  "type": "string",
                                  "pattern": "^ver_[0-9A-Za-z]{8,64}$"
                                }
                              },
                              "required": [
                                "kind",
                                "versionId"
                              ],
                              "additionalProperties": false
                            },
                            {
                              "type": "object",
                              "properties": {
                                "kind": {
                                  "type": "string",
                                  "const": "destructive_migration"
                                },
                                "versionId": {
                                  "type": "string",
                                  "pattern": "^ver_[0-9A-Za-z]{8,64}$"
                                },
                                "statements": {
                                  "minItems": 1,
                                  "type": "array",
                                  "items": {
                                    "type": "string",
                                    "minLength": 1
                                  }
                                }
                              },
                              "required": [
                                "kind",
                                "versionId",
                                "statements"
                              ],
                              "additionalProperties": false
                            },
                            {
                              "type": "object",
                              "properties": {
                                "kind": {
                                  "type": "string",
                                  "const": "budget_overrun"
                                },
                                "runId": {
                                  "type": "string",
                                  "pattern": "^run_[0-9A-Za-z]{8,64}$"
                                },
                                "spentCents": {
                                  "type": "integer",
                                  "minimum": 0,
                                  "maximum": 9007199254740991
                                },
                                "limitCents": {
                                  "type": "integer",
                                  "minimum": 0,
                                  "maximum": 9007199254740991
                                }
                              },
                              "required": [
                                "kind",
                                "runId",
                                "spentCents",
                                "limitCents"
                              ],
                              "additionalProperties": false
                            },
                            {
                              "type": "object",
                              "properties": {
                                "kind": {
                                  "type": "string",
                                  "const": "connector_enable"
                                },
                                "connectorId": {
                                  "type": "string",
                                  "maxLength": 64,
                                  "pattern": "^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$"
                                }
                              },
                              "required": [
                                "kind",
                                "connectorId"
                              ],
                              "additionalProperties": false
                            },
                            {
                              "type": "object",
                              "properties": {
                                "kind": {
                                  "type": "string",
                                  "const": "plan"
                                },
                                "runId": {
                                  "type": "string",
                                  "pattern": "^run_[0-9A-Za-z]{8,64}$"
                                },
                                "plan": {
                                  "type": "string",
                                  "minLength": 1
                                }
                              },
                              "required": [
                                "kind",
                                "runId",
                                "plan"
                              ],
                              "additionalProperties": false
                            }
                          ]
                        },
                        "requestedAt": {
                          "type": "string",
                          "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))$"
                        },
                        "expiresAt": {
                          "anyOf": [
                            {
                              "type": "string",
                              "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": "null"
                            }
                          ]
                        },
                        "decidedBy": {
                          "anyOf": [
                            {
                              "type": "string",
                              "pattern": "^usr_[0-9A-Za-z]{8,64}$"
                            },
                            {
                              "type": "null"
                            }
                          ]
                        },
                        "decidedAt": {
                          "anyOf": [
                            {
                              "type": "string",
                              "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": "null"
                            }
                          ]
                        },
                        "note": {
                          "type": [
                            "string",
                            "null"
                          ]
                        }
                      },
                      "required": [
                        "id",
                        "organisationId",
                        "projectId",
                        "runId",
                        "kind",
                        "status",
                        "reason",
                        "subject",
                        "requestedAt",
                        "expiresAt",
                        "decidedBy",
                        "decidedAt",
                        "note"
                      ],
                      "additionalProperties": false
                    }
                  },
                  "required": [
                    "approval"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "default": {
            "description": "Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            }
          }
        },
        "x-permission": "approval.decide",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$schema": "https://json-schema.org/draft/2020-12/schema",
                "type": "object",
                "properties": {
                  "decision": {
                    "type": "string",
                    "enum": [
                      "approve",
                      "reject"
                    ]
                  },
                  "note": {
                    "type": "string",
                    "maxLength": 2000
                  }
                },
                "required": [
                  "decision"
                ]
              }
            }
          }
        }
      }
    },
    "/api/usage": {
      "get": {
        "operationId": "getUsage",
        "summary": "Spend by project and by day.",
        "parameters": [
          {
            "name": "from",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "format": "date",
              "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])))$"
            }
          },
          {
            "name": "to",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "format": "date",
              "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])))$"
            }
          }
        ],
        "security": [
          {
            "session": []
          },
          {
            "token": []
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$schema": "https://json-schema.org/draft/2020-12/schema",
                  "type": "object",
                  "properties": {
                    "from": {
                      "type": "string",
                      "format": "date",
                      "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])))$"
                    },
                    "to": {
                      "type": "string",
                      "format": "date",
                      "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])))$"
                    },
                    "totalCents": {
                      "type": "integer",
                      "minimum": 0,
                      "maximum": 9007199254740991
                    },
                    "byDay": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "day": {
                            "type": "string",
                            "format": "date",
                            "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])))$"
                          },
                          "costCents": {
                            "type": "integer",
                            "minimum": 0,
                            "maximum": 9007199254740991
                          }
                        },
                        "required": [
                          "day",
                          "costCents"
                        ],
                        "additionalProperties": false
                      }
                    },
                    "byProject": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "projectId": {
                            "type": "string",
                            "pattern": "^prj_[0-9A-Za-z]{8,64}$"
                          },
                          "projectName": {
                            "type": "string"
                          },
                          "costCents": {
                            "type": "integer",
                            "minimum": 0,
                            "maximum": 9007199254740991
                          }
                        },
                        "required": [
                          "projectId",
                          "projectName",
                          "costCents"
                        ],
                        "additionalProperties": false
                      }
                    },
                    "monthSpentCents": {
                      "type": "integer",
                      "minimum": 0,
                      "maximum": 9007199254740991
                    },
                    "monthLimitCents": {
                      "anyOf": [
                        {
                          "type": "integer",
                          "minimum": 0,
                          "maximum": 9007199254740991
                        },
                        {
                          "type": "null"
                        }
                      ]
                    }
                  },
                  "required": [
                    "from",
                    "to",
                    "totalCents",
                    "byDay",
                    "byProject",
                    "monthSpentCents",
                    "monthLimitCents"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "default": {
            "description": "Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            }
          }
        },
        "x-permission": "usage.read"
      }
    },
    "/api/usage/projects/{id}": {
      "get": {
        "operationId": "getProjectUsage",
        "summary": "One project's spend.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^prj_[0-9A-Za-z]{8,64}$"
            }
          },
          {
            "name": "from",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "format": "date",
              "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])))$"
            }
          },
          {
            "name": "to",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "format": "date",
              "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])))$"
            }
          }
        ],
        "security": [
          {
            "session": []
          },
          {
            "token": []
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$schema": "https://json-schema.org/draft/2020-12/schema",
                  "type": "object",
                  "properties": {
                    "projectId": {
                      "type": "string",
                      "pattern": "^prj_[0-9A-Za-z]{8,64}$"
                    },
                    "from": {
                      "type": "string",
                      "format": "date",
                      "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])))$"
                    },
                    "to": {
                      "type": "string",
                      "format": "date",
                      "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])))$"
                    },
                    "totalCents": {
                      "type": "integer",
                      "minimum": 0,
                      "maximum": 9007199254740991
                    },
                    "byDay": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "day": {
                            "type": "string",
                            "format": "date",
                            "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])))$"
                          },
                          "costCents": {
                            "type": "integer",
                            "minimum": 0,
                            "maximum": 9007199254740991
                          }
                        },
                        "required": [
                          "day",
                          "costCents"
                        ],
                        "additionalProperties": false
                      }
                    },
                    "byRun": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "runId": {
                            "type": "string",
                            "pattern": "^run_[0-9A-Za-z]{8,64}$"
                          },
                          "costCents": {
                            "type": "integer",
                            "minimum": 0,
                            "maximum": 9007199254740991
                          },
                          "createdAt": {
                            "type": "string",
                            "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))$"
                          }
                        },
                        "required": [
                          "runId",
                          "costCents",
                          "createdAt"
                        ],
                        "additionalProperties": false
                      }
                    },
                    "monthSpentCents": {
                      "type": "integer",
                      "minimum": 0,
                      "maximum": 9007199254740991
                    },
                    "monthLimitCents": {
                      "anyOf": [
                        {
                          "type": "integer",
                          "minimum": 0,
                          "maximum": 9007199254740991
                        },
                        {
                          "type": "null"
                        }
                      ]
                    }
                  },
                  "required": [
                    "projectId",
                    "from",
                    "to",
                    "totalCents",
                    "byDay",
                    "byRun",
                    "monthSpentCents",
                    "monthLimitCents"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "default": {
            "description": "Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            }
          }
        },
        "x-permission": "usage.read"
      }
    },
    "/api/personas": {
      "get": {
        "operationId": "listPersonas",
        "summary": "The persona registry.",
        "parameters": [
          {
            "name": "group",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "maxLength": 64,
              "pattern": "^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$"
            }
          }
        ],
        "security": [
          {
            "session": []
          },
          {
            "token": []
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$schema": "https://json-schema.org/draft/2020-12/schema",
                  "type": "object",
                  "properties": {
                    "personas": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string",
                            "maxLength": 64,
                            "pattern": "^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$"
                          },
                          "title": {
                            "type": "string",
                            "minLength": 1
                          },
                          "group": {
                            "type": "string",
                            "maxLength": 64,
                            "pattern": "^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$"
                          },
                          "tier": {
                            "type": "string",
                            "enum": [
                              "steward",
                              "executor",
                              "reviewer",
                              "guardian",
                              "lead"
                            ]
                          },
                          "purpose": {
                            "type": "string",
                            "minLength": 1
                          },
                          "model": {
                            "type": "string",
                            "enum": [
                              "plan",
                              "review",
                              "build",
                              "small"
                            ]
                          }
                        },
                        "required": [
                          "id",
                          "title",
                          "group",
                          "tier",
                          "purpose",
                          "model"
                        ],
                        "additionalProperties": false
                      }
                    },
                    "characters": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string",
                            "maxLength": 64,
                            "pattern": "^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$"
                          },
                          "name": {
                            "type": "string",
                            "minLength": 1
                          },
                          "persona": {
                            "type": "string",
                            "maxLength": 64,
                            "pattern": "^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$"
                          },
                          "portrait": {
                            "type": "string",
                            "minLength": 1
                          },
                          "tagline": {
                            "type": "string",
                            "maxLength": 140
                          }
                        },
                        "required": [
                          "id",
                          "name",
                          "persona",
                          "portrait"
                        ],
                        "additionalProperties": false
                      }
                    }
                  },
                  "required": [
                    "personas",
                    "characters"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "default": {
            "description": "Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            }
          }
        },
        "x-permission": "personas.read"
      }
    },
    "/api/personas/{id}": {
      "get": {
        "operationId": "getPersona",
        "summary": "One persona's bundle.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "maxLength": 64,
              "pattern": "^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$"
            }
          }
        ],
        "security": [
          {
            "session": []
          },
          {
            "token": []
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$schema": "https://json-schema.org/draft/2020-12/schema",
                  "type": "object",
                  "properties": {
                    "persona": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "type": "string",
                          "maxLength": 64,
                          "pattern": "^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$"
                        },
                        "title": {
                          "type": "string",
                          "minLength": 1
                        },
                        "group": {
                          "type": "string",
                          "maxLength": 64,
                          "pattern": "^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$"
                        },
                        "tier": {
                          "type": "string",
                          "enum": [
                            "steward",
                            "executor",
                            "reviewer",
                            "guardian",
                            "lead"
                          ]
                        },
                        "purpose": {
                          "type": "string",
                          "minLength": 1,
                          "maxLength": 200
                        },
                        "skills": {
                          "type": "array",
                          "items": {
                            "type": "string",
                            "maxLength": 64,
                            "pattern": "^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$"
                          }
                        },
                        "tools": {
                          "type": "array",
                          "items": {
                            "type": "string",
                            "enum": [
                              "read",
                              "search",
                              "edit",
                              "shell",
                              "fetch",
                              "subagent",
                              "skill",
                              "todo"
                            ]
                          }
                        },
                        "connectors": {
                          "type": "array",
                          "items": {
                            "type": "string",
                            "maxLength": 64,
                            "pattern": "^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$"
                          }
                        },
                        "may_change": {
                          "type": "array",
                          "items": {
                            "type": "string",
                            "minLength": 1
                          }
                        },
                        "never": {
                          "type": "array",
                          "items": {
                            "type": "string",
                            "enum": [
                              "merge",
                              "deploy",
                              "publish",
                              "push",
                              "read-secrets",
                              "approve-own-work",
                              "edit",
                              "write-product-code"
                            ]
                          }
                        },
                        "model": {
                          "type": "string",
                          "enum": [
                            "plan",
                            "review",
                            "build",
                            "small"
                          ]
                        },
                        "reviewed_by": {
                          "type": "array",
                          "items": {
                            "type": "string",
                            "maxLength": 64,
                            "pattern": "^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$"
                          }
                        },
                        "blocks": {
                          "type": "array",
                          "items": {
                            "type": "string",
                            "maxLength": 64,
                            "pattern": "^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$"
                          }
                        },
                        "steps": {
                          "type": "integer",
                          "exclusiveMinimum": 0,
                          "maximum": 9007199254740991
                        },
                        "instructions": {
                          "type": "string",
                          "minLength": 1
                        }
                      },
                      "required": [
                        "id",
                        "title",
                        "group",
                        "tier",
                        "purpose",
                        "skills",
                        "tools",
                        "connectors",
                        "may_change",
                        "never",
                        "model",
                        "reviewed_by",
                        "instructions"
                      ],
                      "additionalProperties": false
                    },
                    "instructions": {
                      "type": "string"
                    },
                    "characters": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string",
                            "maxLength": 64,
                            "pattern": "^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$"
                          },
                          "name": {
                            "type": "string",
                            "minLength": 1
                          },
                          "persona": {
                            "type": "string",
                            "maxLength": 64,
                            "pattern": "^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$"
                          },
                          "portrait": {
                            "type": "string",
                            "minLength": 1
                          },
                          "tagline": {
                            "type": "string",
                            "maxLength": 140
                          }
                        },
                        "required": [
                          "id",
                          "name",
                          "persona",
                          "portrait"
                        ],
                        "additionalProperties": false
                      }
                    },
                    "hash": {
                      "type": "string",
                      "minLength": 1
                    }
                  },
                  "required": [
                    "persona",
                    "instructions",
                    "characters",
                    "hash"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "default": {
            "description": "Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            }
          }
        },
        "x-permission": "personas.read"
      }
    },
    "/api/audit": {
      "get": {
        "operationId": "listAuditEntries",
        "summary": "The audit log.",
        "parameters": [
          {
            "name": "cursor",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "minLength": 1
            }
          },
          {
            "name": "limit",
            "in": "query",
            "required": true,
            "schema": {
              "default": 50,
              "type": "integer",
              "minimum": 1,
              "maximum": 100
            }
          },
          {
            "name": "action",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "signed_in",
                "signed_out",
                "session_ended",
                "member_invited",
                "member_joined",
                "member_removed",
                "role_changed",
                "token_created",
                "token_revoked",
                "token_used",
                "project_created",
                "project_updated",
                "project_archived",
                "run_started",
                "run_interrupted",
                "approval_decided",
                "version_restored",
                "published",
                "rolled_back",
                "settings_changed",
                "stop_switch_used",
                "connector_enabled",
                "subscription_changed",
                "checkout_started",
                "egress_refused"
              ]
            }
          },
          {
            "name": "userId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^usr_[0-9A-Za-z]{8,64}$"
            }
          },
          {
            "name": "from",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "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))$"
            }
          },
          {
            "name": "to",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "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))$"
            }
          }
        ],
        "security": [
          {
            "session": []
          },
          {
            "token": []
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$schema": "https://json-schema.org/draft/2020-12/schema",
                  "type": "object",
                  "properties": {
                    "entries": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string",
                            "pattern": "^aud_[0-9A-Za-z]{8,64}$"
                          },
                          "organisationId": {
                            "type": "string",
                            "pattern": "^org_[0-9A-Za-z]{8,64}$"
                          },
                          "actor": {
                            "type": "object",
                            "properties": {
                              "kind": {
                                "type": "string",
                                "enum": [
                                  "member",
                                  "token",
                                  "system"
                                ]
                              },
                              "userId": {
                                "anyOf": [
                                  {
                                    "type": "string",
                                    "pattern": "^usr_[0-9A-Za-z]{8,64}$"
                                  },
                                  {
                                    "type": "null"
                                  }
                                ]
                              },
                              "tokenId": {
                                "anyOf": [
                                  {
                                    "type": "string",
                                    "pattern": "^tok_[0-9A-Za-z]{8,64}$"
                                  },
                                  {
                                    "type": "null"
                                  }
                                ]
                              }
                            },
                            "required": [
                              "kind",
                              "userId",
                              "tokenId"
                            ],
                            "additionalProperties": false
                          },
                          "action": {
                            "type": "string",
                            "enum": [
                              "signed_in",
                              "signed_out",
                              "session_ended",
                              "member_invited",
                              "member_joined",
                              "member_removed",
                              "role_changed",
                              "token_created",
                              "token_revoked",
                              "token_used",
                              "project_created",
                              "project_updated",
                              "project_archived",
                              "run_started",
                              "run_interrupted",
                              "approval_decided",
                              "version_restored",
                              "published",
                              "rolled_back",
                              "settings_changed",
                              "stop_switch_used",
                              "connector_enabled",
                              "subscription_changed",
                              "checkout_started",
                              "egress_refused"
                            ]
                          },
                          "target": {
                            "type": "object",
                            "properties": {
                              "type": {
                                "type": "string",
                                "minLength": 1
                              },
                              "id": {
                                "type": [
                                  "string",
                                  "null"
                                ]
                              }
                            },
                            "required": [
                              "type",
                              "id"
                            ],
                            "additionalProperties": false
                          },
                          "details": {
                            "type": "object",
                            "propertyNames": {
                              "type": "string"
                            },
                            "additionalProperties": {
                              "type": [
                                "string",
                                "number",
                                "boolean",
                                "null"
                              ]
                            }
                          },
                          "createdAt": {
                            "type": "string",
                            "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))$"
                          }
                        },
                        "required": [
                          "id",
                          "organisationId",
                          "actor",
                          "action",
                          "target",
                          "details",
                          "createdAt"
                        ],
                        "additionalProperties": false
                      }
                    },
                    "nextCursor": {
                      "type": [
                        "string",
                        "null"
                      ]
                    }
                  },
                  "required": [
                    "entries",
                    "nextCursor"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "default": {
            "description": "Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            }
          }
        },
        "x-permission": "audit.read"
      }
    },
    "/api/settings": {
      "get": {
        "operationId": "getSettings",
        "summary": "Organisation settings.",
        "parameters": [],
        "security": [
          {
            "session": []
          },
          {
            "token": []
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$schema": "https://json-schema.org/draft/2020-12/schema",
                  "type": "object",
                  "properties": {
                    "settings": {
                      "type": "object",
                      "properties": {
                        "organisationId": {
                          "type": "string",
                          "pattern": "^org_[0-9A-Za-z]{8,64}$"
                        },
                        "models": {
                          "type": "object",
                          "propertyNames": {
                            "type": "string",
                            "enum": [
                              "plan",
                              "review",
                              "build",
                              "small"
                            ]
                          },
                          "additionalProperties": {
                            "type": "string",
                            "minLength": 1
                          }
                        },
                        "limits": {
                          "type": "object",
                          "properties": {
                            "runCents": {
                              "type": "integer",
                              "minimum": 0,
                              "maximum": 9007199254740991
                            },
                            "projectMonthlyCents": {
                              "anyOf": [
                                {
                                  "type": "integer",
                                  "minimum": 0,
                                  "maximum": 9007199254740991
                                },
                                {
                                  "type": "null"
                                }
                              ]
                            },
                            "organisationMonthlyCents": {
                              "anyOf": [
                                {
                                  "type": "integer",
                                  "minimum": 0,
                                  "maximum": 9007199254740991
                                },
                                {
                                  "type": "null"
                                }
                              ]
                            },
                            "checkInCents": {
                              "anyOf": [
                                {
                                  "type": "integer",
                                  "minimum": 0,
                                  "maximum": 9007199254740991
                                },
                                {
                                  "type": "null"
                                }
                              ]
                            }
                          },
                          "required": [
                            "runCents",
                            "projectMonthlyCents",
                            "organisationMonthlyCents",
                            "checkInCents"
                          ],
                          "additionalProperties": false
                        },
                        "stopSwitch": {
                          "type": "object",
                          "properties": {
                            "on": {
                              "type": "boolean"
                            },
                            "changedBy": {
                              "anyOf": [
                                {
                                  "type": "string",
                                  "pattern": "^usr_[0-9A-Za-z]{8,64}$"
                                },
                                {
                                  "type": "null"
                                }
                              ]
                            },
                            "changedAt": {
                              "anyOf": [
                                {
                                  "type": "string",
                                  "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": "null"
                                }
                              ]
                            }
                          },
                          "required": [
                            "on",
                            "changedBy",
                            "changedAt"
                          ],
                          "additionalProperties": false
                        },
                        "connectors": {
                          "type": "array",
                          "items": {
                            "type": "string",
                            "maxLength": 64,
                            "pattern": "^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$"
                          }
                        },
                        "updatedAt": {
                          "type": "string",
                          "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))$"
                        }
                      },
                      "required": [
                        "organisationId",
                        "models",
                        "limits",
                        "stopSwitch",
                        "connectors",
                        "updatedAt"
                      ],
                      "additionalProperties": false
                    }
                  },
                  "required": [
                    "settings"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "default": {
            "description": "Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            }
          }
        },
        "x-permission": "settings.read"
      },
      "patch": {
        "operationId": "updateSettings",
        "summary": "Change organisation settings (the stop switch also needs stop-switch.use).",
        "parameters": [],
        "security": [
          {
            "session": []
          },
          {
            "token": []
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$schema": "https://json-schema.org/draft/2020-12/schema",
                  "type": "object",
                  "properties": {
                    "settings": {
                      "type": "object",
                      "properties": {
                        "organisationId": {
                          "type": "string",
                          "pattern": "^org_[0-9A-Za-z]{8,64}$"
                        },
                        "models": {
                          "type": "object",
                          "propertyNames": {
                            "type": "string",
                            "enum": [
                              "plan",
                              "review",
                              "build",
                              "small"
                            ]
                          },
                          "additionalProperties": {
                            "type": "string",
                            "minLength": 1
                          }
                        },
                        "limits": {
                          "type": "object",
                          "properties": {
                            "runCents": {
                              "type": "integer",
                              "minimum": 0,
                              "maximum": 9007199254740991
                            },
                            "projectMonthlyCents": {
                              "anyOf": [
                                {
                                  "type": "integer",
                                  "minimum": 0,
                                  "maximum": 9007199254740991
                                },
                                {
                                  "type": "null"
                                }
                              ]
                            },
                            "organisationMonthlyCents": {
                              "anyOf": [
                                {
                                  "type": "integer",
                                  "minimum": 0,
                                  "maximum": 9007199254740991
                                },
                                {
                                  "type": "null"
                                }
                              ]
                            },
                            "checkInCents": {
                              "anyOf": [
                                {
                                  "type": "integer",
                                  "minimum": 0,
                                  "maximum": 9007199254740991
                                },
                                {
                                  "type": "null"
                                }
                              ]
                            }
                          },
                          "required": [
                            "runCents",
                            "projectMonthlyCents",
                            "organisationMonthlyCents",
                            "checkInCents"
                          ],
                          "additionalProperties": false
                        },
                        "stopSwitch": {
                          "type": "object",
                          "properties": {
                            "on": {
                              "type": "boolean"
                            },
                            "changedBy": {
                              "anyOf": [
                                {
                                  "type": "string",
                                  "pattern": "^usr_[0-9A-Za-z]{8,64}$"
                                },
                                {
                                  "type": "null"
                                }
                              ]
                            },
                            "changedAt": {
                              "anyOf": [
                                {
                                  "type": "string",
                                  "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": "null"
                                }
                              ]
                            }
                          },
                          "required": [
                            "on",
                            "changedBy",
                            "changedAt"
                          ],
                          "additionalProperties": false
                        },
                        "connectors": {
                          "type": "array",
                          "items": {
                            "type": "string",
                            "maxLength": 64,
                            "pattern": "^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$"
                          }
                        },
                        "updatedAt": {
                          "type": "string",
                          "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))$"
                        }
                      },
                      "required": [
                        "organisationId",
                        "models",
                        "limits",
                        "stopSwitch",
                        "connectors",
                        "updatedAt"
                      ],
                      "additionalProperties": false
                    }
                  },
                  "required": [
                    "settings"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "default": {
            "description": "Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            }
          }
        },
        "x-permission": "settings.manage",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$schema": "https://json-schema.org/draft/2020-12/schema",
                "type": "object",
                "properties": {
                  "models": {
                    "type": "object",
                    "propertyNames": {
                      "type": "string",
                      "enum": [
                        "plan",
                        "review",
                        "build",
                        "small"
                      ]
                    },
                    "additionalProperties": {
                      "anyOf": [
                        {
                          "type": "string",
                          "minLength": 1
                        },
                        {
                          "type": "null"
                        }
                      ]
                    }
                  },
                  "limits": {
                    "type": "object",
                    "properties": {
                      "runCents": {
                        "type": "integer",
                        "minimum": 0,
                        "maximum": 9007199254740991
                      },
                      "projectMonthlyCents": {
                        "anyOf": [
                          {
                            "type": "integer",
                            "minimum": 0,
                            "maximum": 9007199254740991
                          },
                          {
                            "type": "null"
                          }
                        ]
                      },
                      "organisationMonthlyCents": {
                        "anyOf": [
                          {
                            "type": "integer",
                            "minimum": 0,
                            "maximum": 9007199254740991
                          },
                          {
                            "type": "null"
                          }
                        ]
                      },
                      "checkInCents": {
                        "anyOf": [
                          {
                            "type": "integer",
                            "minimum": 0,
                            "maximum": 9007199254740991
                          },
                          {
                            "type": "null"
                          }
                        ]
                      }
                    }
                  },
                  "stopSwitch": {
                    "type": "boolean"
                  },
                  "connectors": {
                    "type": "array",
                    "items": {
                      "type": "string",
                      "maxLength": 64,
                      "pattern": "^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/members": {
      "get": {
        "operationId": "listMembers",
        "summary": "Members and pending invitations.",
        "parameters": [],
        "security": [
          {
            "session": []
          },
          {
            "token": []
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$schema": "https://json-schema.org/draft/2020-12/schema",
                  "type": "object",
                  "properties": {
                    "members": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string",
                            "pattern": "^mem_[0-9A-Za-z]{8,64}$"
                          },
                          "organisationId": {
                            "type": "string",
                            "pattern": "^org_[0-9A-Za-z]{8,64}$"
                          },
                          "userId": {
                            "type": "string",
                            "pattern": "^usr_[0-9A-Za-z]{8,64}$"
                          },
                          "name": {
                            "type": "string"
                          },
                          "email": {
                            "type": "string",
                            "format": "email",
                            "pattern": "^(?:[A-Za-z0-9_'+\\-]+\\.)*[A-Za-z0-9_'+\\-]*[A-Za-z0-9_+-]@(?:[A-Za-z0-9][A-Za-z0-9\\-]*\\.)+[A-Za-z]{2,}$"
                          },
                          "image": {
                            "anyOf": [
                              {
                                "type": "string",
                                "format": "uri"
                              },
                              {
                                "type": "null"
                              }
                            ]
                          },
                          "role": {
                            "type": "string",
                            "enum": [
                              "owner",
                              "admin",
                              "member",
                              "viewer"
                            ]
                          },
                          "joinedAt": {
                            "type": "string",
                            "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))$"
                          }
                        },
                        "required": [
                          "id",
                          "organisationId",
                          "userId",
                          "name",
                          "email",
                          "image",
                          "role",
                          "joinedAt"
                        ],
                        "additionalProperties": false
                      }
                    },
                    "invitations": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string",
                            "pattern": "^inv_[0-9A-Za-z]{8,64}$"
                          },
                          "organisationId": {
                            "type": "string",
                            "pattern": "^org_[0-9A-Za-z]{8,64}$"
                          },
                          "email": {
                            "type": "string",
                            "format": "email",
                            "pattern": "^(?:[A-Za-z0-9_'+\\-]+\\.)*[A-Za-z0-9_'+\\-]*[A-Za-z0-9_+-]@(?:[A-Za-z0-9][A-Za-z0-9\\-]*\\.)+[A-Za-z]{2,}$"
                          },
                          "role": {
                            "type": "string",
                            "enum": [
                              "owner",
                              "admin",
                              "member",
                              "viewer"
                            ]
                          },
                          "status": {
                            "type": "string",
                            "enum": [
                              "pending",
                              "accepted",
                              "revoked",
                              "expired"
                            ]
                          },
                          "invitedBy": {
                            "type": "string",
                            "pattern": "^usr_[0-9A-Za-z]{8,64}$"
                          },
                          "createdAt": {
                            "type": "string",
                            "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))$"
                          },
                          "expiresAt": {
                            "type": "string",
                            "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))$"
                          }
                        },
                        "required": [
                          "id",
                          "organisationId",
                          "email",
                          "role",
                          "status",
                          "invitedBy",
                          "createdAt",
                          "expiresAt"
                        ],
                        "additionalProperties": false
                      }
                    }
                  },
                  "required": [
                    "members",
                    "invitations"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "default": {
            "description": "Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            }
          }
        },
        "x-permission": "members.read"
      }
    },
    "/api/members/invite": {
      "post": {
        "operationId": "inviteMember",
        "summary": "Invite a member.",
        "parameters": [],
        "security": [
          {
            "session": []
          },
          {
            "token": []
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$schema": "https://json-schema.org/draft/2020-12/schema",
                  "type": "object",
                  "properties": {
                    "invitation": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "type": "string",
                          "pattern": "^inv_[0-9A-Za-z]{8,64}$"
                        },
                        "organisationId": {
                          "type": "string",
                          "pattern": "^org_[0-9A-Za-z]{8,64}$"
                        },
                        "email": {
                          "type": "string",
                          "format": "email",
                          "pattern": "^(?:[A-Za-z0-9_'+\\-]+\\.)*[A-Za-z0-9_'+\\-]*[A-Za-z0-9_+-]@(?:[A-Za-z0-9][A-Za-z0-9\\-]*\\.)+[A-Za-z]{2,}$"
                        },
                        "role": {
                          "type": "string",
                          "enum": [
                            "owner",
                            "admin",
                            "member",
                            "viewer"
                          ]
                        },
                        "status": {
                          "type": "string",
                          "enum": [
                            "pending",
                            "accepted",
                            "revoked",
                            "expired"
                          ]
                        },
                        "invitedBy": {
                          "type": "string",
                          "pattern": "^usr_[0-9A-Za-z]{8,64}$"
                        },
                        "createdAt": {
                          "type": "string",
                          "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))$"
                        },
                        "expiresAt": {
                          "type": "string",
                          "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))$"
                        }
                      },
                      "required": [
                        "id",
                        "organisationId",
                        "email",
                        "role",
                        "status",
                        "invitedBy",
                        "createdAt",
                        "expiresAt"
                      ],
                      "additionalProperties": false
                    }
                  },
                  "required": [
                    "invitation"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "default": {
            "description": "Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            }
          }
        },
        "x-permission": "members.manage",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$schema": "https://json-schema.org/draft/2020-12/schema",
                "type": "object",
                "properties": {
                  "email": {
                    "type": "string",
                    "format": "email",
                    "pattern": "^(?:[A-Za-z0-9_'+\\-]+\\.)*[A-Za-z0-9_'+\\-]*[A-Za-z0-9_+-]@(?:[A-Za-z0-9][A-Za-z0-9\\-]*\\.)+[A-Za-z]{2,}$"
                  },
                  "role": {
                    "type": "string",
                    "enum": [
                      "owner",
                      "admin",
                      "member",
                      "viewer"
                    ]
                  }
                },
                "required": [
                  "email",
                  "role"
                ]
              }
            }
          }
        }
      }
    },
    "/api/members/{id}": {
      "patch": {
        "operationId": "updateMember",
        "summary": "Change a member's role.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^mem_[0-9A-Za-z]{8,64}$"
            }
          }
        ],
        "security": [
          {
            "session": []
          },
          {
            "token": []
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$schema": "https://json-schema.org/draft/2020-12/schema",
                  "type": "object",
                  "properties": {
                    "member": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "type": "string",
                          "pattern": "^mem_[0-9A-Za-z]{8,64}$"
                        },
                        "organisationId": {
                          "type": "string",
                          "pattern": "^org_[0-9A-Za-z]{8,64}$"
                        },
                        "userId": {
                          "type": "string",
                          "pattern": "^usr_[0-9A-Za-z]{8,64}$"
                        },
                        "name": {
                          "type": "string"
                        },
                        "email": {
                          "type": "string",
                          "format": "email",
                          "pattern": "^(?:[A-Za-z0-9_'+\\-]+\\.)*[A-Za-z0-9_'+\\-]*[A-Za-z0-9_+-]@(?:[A-Za-z0-9][A-Za-z0-9\\-]*\\.)+[A-Za-z]{2,}$"
                        },
                        "image": {
                          "anyOf": [
                            {
                              "type": "string",
                              "format": "uri"
                            },
                            {
                              "type": "null"
                            }
                          ]
                        },
                        "role": {
                          "type": "string",
                          "enum": [
                            "owner",
                            "admin",
                            "member",
                            "viewer"
                          ]
                        },
                        "joinedAt": {
                          "type": "string",
                          "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))$"
                        }
                      },
                      "required": [
                        "id",
                        "organisationId",
                        "userId",
                        "name",
                        "email",
                        "image",
                        "role",
                        "joinedAt"
                      ],
                      "additionalProperties": false
                    }
                  },
                  "required": [
                    "member"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "default": {
            "description": "Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            }
          }
        },
        "x-permission": "members.manage",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$schema": "https://json-schema.org/draft/2020-12/schema",
                "type": "object",
                "properties": {
                  "role": {
                    "type": "string",
                    "enum": [
                      "owner",
                      "admin",
                      "member",
                      "viewer"
                    ]
                  }
                },
                "required": [
                  "role"
                ]
              }
            }
          }
        }
      },
      "delete": {
        "operationId": "removeMember",
        "summary": "Remove a member.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^mem_[0-9A-Za-z]{8,64}$"
            }
          }
        ],
        "security": [
          {
            "session": []
          },
          {
            "token": []
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$schema": "https://json-schema.org/draft/2020-12/schema",
                  "type": "object",
                  "properties": {
                    "memberId": {
                      "type": "string",
                      "pattern": "^mem_[0-9A-Za-z]{8,64}$"
                    }
                  },
                  "required": [
                    "memberId"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "default": {
            "description": "Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            }
          }
        },
        "x-permission": "members.manage"
      }
    },
    "/api/tokens": {
      "get": {
        "operationId": "listApiTokens",
        "summary": "API tokens.",
        "parameters": [],
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$schema": "https://json-schema.org/draft/2020-12/schema",
                  "type": "object",
                  "properties": {
                    "tokens": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string",
                            "pattern": "^tok_[0-9A-Za-z]{8,64}$"
                          },
                          "organisationId": {
                            "type": "string",
                            "pattern": "^org_[0-9A-Za-z]{8,64}$"
                          },
                          "name": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 80
                          },
                          "permissions": {
                            "type": "array",
                            "items": {
                              "type": "string",
                              "enum": [
                                "project.read",
                                "project.create",
                                "project.update",
                                "project.archive",
                                "run.read",
                                "run.start",
                                "run.interrupt",
                                "version.restore",
                                "files.read",
                                "publish.start",
                                "publish.approve",
                                "deployment.rollback",
                                "approval.decide",
                                "usage.read",
                                "personas.read",
                                "members.read",
                                "members.manage",
                                "settings.read",
                                "settings.manage",
                                "connectors.manage",
                                "tokens.manage",
                                "audit.read",
                                "billing.read",
                                "billing.manage",
                                "stop-switch.use"
                              ]
                            }
                          },
                          "prefix": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 16
                          },
                          "createdBy": {
                            "type": "string",
                            "pattern": "^usr_[0-9A-Za-z]{8,64}$"
                          },
                          "createdAt": {
                            "type": "string",
                            "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))$"
                          },
                          "expiresAt": {
                            "anyOf": [
                              {
                                "type": "string",
                                "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": "null"
                              }
                            ]
                          },
                          "lastUsedAt": {
                            "anyOf": [
                              {
                                "type": "string",
                                "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": "null"
                              }
                            ]
                          },
                          "revokedAt": {
                            "anyOf": [
                              {
                                "type": "string",
                                "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": "null"
                              }
                            ]
                          }
                        },
                        "required": [
                          "id",
                          "organisationId",
                          "name",
                          "permissions",
                          "prefix",
                          "createdBy",
                          "createdAt",
                          "expiresAt",
                          "lastUsedAt",
                          "revokedAt"
                        ],
                        "additionalProperties": false
                      }
                    }
                  },
                  "required": [
                    "tokens"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "default": {
            "description": "Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            }
          }
        },
        "x-permission": "tokens.manage"
      },
      "post": {
        "operationId": "createApiToken",
        "summary": "Create an API token (the secret is shown once).",
        "parameters": [],
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$schema": "https://json-schema.org/draft/2020-12/schema",
                  "type": "object",
                  "properties": {
                    "token": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "type": "string",
                          "pattern": "^tok_[0-9A-Za-z]{8,64}$"
                        },
                        "organisationId": {
                          "type": "string",
                          "pattern": "^org_[0-9A-Za-z]{8,64}$"
                        },
                        "name": {
                          "type": "string",
                          "minLength": 1,
                          "maxLength": 80
                        },
                        "permissions": {
                          "type": "array",
                          "items": {
                            "type": "string",
                            "enum": [
                              "project.read",
                              "project.create",
                              "project.update",
                              "project.archive",
                              "run.read",
                              "run.start",
                              "run.interrupt",
                              "version.restore",
                              "files.read",
                              "publish.start",
                              "publish.approve",
                              "deployment.rollback",
                              "approval.decide",
                              "usage.read",
                              "personas.read",
                              "members.read",
                              "members.manage",
                              "settings.read",
                              "settings.manage",
                              "connectors.manage",
                              "tokens.manage",
                              "audit.read",
                              "billing.read",
                              "billing.manage",
                              "stop-switch.use"
                            ]
                          }
                        },
                        "prefix": {
                          "type": "string",
                          "minLength": 1,
                          "maxLength": 16
                        },
                        "createdBy": {
                          "type": "string",
                          "pattern": "^usr_[0-9A-Za-z]{8,64}$"
                        },
                        "createdAt": {
                          "type": "string",
                          "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))$"
                        },
                        "expiresAt": {
                          "anyOf": [
                            {
                              "type": "string",
                              "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": "null"
                            }
                          ]
                        },
                        "lastUsedAt": {
                          "anyOf": [
                            {
                              "type": "string",
                              "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": "null"
                            }
                          ]
                        },
                        "revokedAt": {
                          "anyOf": [
                            {
                              "type": "string",
                              "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": "null"
                            }
                          ]
                        }
                      },
                      "required": [
                        "id",
                        "organisationId",
                        "name",
                        "permissions",
                        "prefix",
                        "createdBy",
                        "createdAt",
                        "expiresAt",
                        "lastUsedAt",
                        "revokedAt"
                      ],
                      "additionalProperties": false
                    },
                    "secret": {
                      "type": "string",
                      "minLength": 1
                    }
                  },
                  "required": [
                    "token",
                    "secret"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "default": {
            "description": "Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            }
          }
        },
        "x-permission": "tokens.manage",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$schema": "https://json-schema.org/draft/2020-12/schema",
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 80
                  },
                  "permissions": {
                    "minItems": 1,
                    "type": "array",
                    "items": {
                      "type": "string",
                      "enum": [
                        "project.read",
                        "project.create",
                        "project.update",
                        "project.archive",
                        "run.read",
                        "run.start",
                        "run.interrupt",
                        "version.restore",
                        "files.read",
                        "publish.start",
                        "publish.approve",
                        "deployment.rollback",
                        "approval.decide",
                        "usage.read",
                        "personas.read",
                        "members.read",
                        "members.manage",
                        "settings.read",
                        "settings.manage",
                        "connectors.manage",
                        "tokens.manage",
                        "audit.read",
                        "billing.read",
                        "billing.manage",
                        "stop-switch.use"
                      ]
                    }
                  },
                  "expiresAt": {
                    "type": "string",
                    "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))$"
                  }
                },
                "required": [
                  "name",
                  "permissions"
                ]
              }
            }
          }
        }
      }
    },
    "/api/tokens/{id}": {
      "delete": {
        "operationId": "revokeApiToken",
        "summary": "Revoke an API token.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^tok_[0-9A-Za-z]{8,64}$"
            }
          }
        ],
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$schema": "https://json-schema.org/draft/2020-12/schema",
                  "type": "object",
                  "properties": {
                    "token": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "type": "string",
                          "pattern": "^tok_[0-9A-Za-z]{8,64}$"
                        },
                        "organisationId": {
                          "type": "string",
                          "pattern": "^org_[0-9A-Za-z]{8,64}$"
                        },
                        "name": {
                          "type": "string",
                          "minLength": 1,
                          "maxLength": 80
                        },
                        "permissions": {
                          "type": "array",
                          "items": {
                            "type": "string",
                            "enum": [
                              "project.read",
                              "project.create",
                              "project.update",
                              "project.archive",
                              "run.read",
                              "run.start",
                              "run.interrupt",
                              "version.restore",
                              "files.read",
                              "publish.start",
                              "publish.approve",
                              "deployment.rollback",
                              "approval.decide",
                              "usage.read",
                              "personas.read",
                              "members.read",
                              "members.manage",
                              "settings.read",
                              "settings.manage",
                              "connectors.manage",
                              "tokens.manage",
                              "audit.read",
                              "billing.read",
                              "billing.manage",
                              "stop-switch.use"
                            ]
                          }
                        },
                        "prefix": {
                          "type": "string",
                          "minLength": 1,
                          "maxLength": 16
                        },
                        "createdBy": {
                          "type": "string",
                          "pattern": "^usr_[0-9A-Za-z]{8,64}$"
                        },
                        "createdAt": {
                          "type": "string",
                          "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))$"
                        },
                        "expiresAt": {
                          "anyOf": [
                            {
                              "type": "string",
                              "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": "null"
                            }
                          ]
                        },
                        "lastUsedAt": {
                          "anyOf": [
                            {
                              "type": "string",
                              "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": "null"
                            }
                          ]
                        },
                        "revokedAt": {
                          "anyOf": [
                            {
                              "type": "string",
                              "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": "null"
                            }
                          ]
                        }
                      },
                      "required": [
                        "id",
                        "organisationId",
                        "name",
                        "permissions",
                        "prefix",
                        "createdBy",
                        "createdAt",
                        "expiresAt",
                        "lastUsedAt",
                        "revokedAt"
                      ],
                      "additionalProperties": false
                    }
                  },
                  "required": [
                    "token"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "default": {
            "description": "Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            }
          }
        },
        "x-permission": "tokens.manage"
      }
    },
    "/api/billing/plans": {
      "get": {
        "operationId": "listPlans",
        "summary": "The plans and credit packs on sale.",
        "parameters": [],
        "security": [],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$schema": "https://json-schema.org/draft/2020-12/schema",
                  "type": "object",
                  "properties": {
                    "plans": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "key": {
                            "type": "string",
                            "enum": [
                              "free",
                              "pro",
                              "team"
                            ]
                          },
                          "name": {
                            "type": "string",
                            "minLength": 1
                          },
                          "description": {
                            "type": "string"
                          },
                          "stripeLookupKey": {
                            "anyOf": [
                              {
                                "type": "string",
                                "minLength": 1
                              },
                              {
                                "type": "null"
                              }
                            ]
                          },
                          "displayPriceCents": {
                            "type": "integer",
                            "minimum": 0,
                            "maximum": 9007199254740991
                          },
                          "currency": {
                            "type": "string",
                            "pattern": "^[a-z]{3}$"
                          },
                          "interval": {
                            "type": "string",
                            "const": "month"
                          },
                          "priceConfirmed": {
                            "type": "boolean"
                          },
                          "entitlements": {
                            "type": "object",
                            "properties": {
                              "projects": {
                                "anyOf": [
                                  {
                                    "type": "integer",
                                    "minimum": 0,
                                    "maximum": 9007199254740991
                                  },
                                  {
                                    "type": "null"
                                  }
                                ]
                              },
                              "members": {
                                "anyOf": [
                                  {
                                    "type": "integer",
                                    "exclusiveMinimum": 0,
                                    "maximum": 9007199254740991
                                  },
                                  {
                                    "type": "null"
                                  }
                                ]
                              },
                              "sandboxSize": {
                                "type": "string",
                                "enum": [
                                  "standard-2",
                                  "standard-4"
                                ]
                              },
                              "creditsPerMonth": {
                                "type": "integer",
                                "minimum": 0,
                                "maximum": 9007199254740991
                              },
                              "publishedApps": {
                                "anyOf": [
                                  {
                                    "type": "integer",
                                    "minimum": 0,
                                    "maximum": 9007199254740991
                                  },
                                  {
                                    "type": "null"
                                  }
                                ]
                              },
                              "topUpAllowed": {
                                "type": "boolean"
                              }
                            },
                            "required": [
                              "projects",
                              "members",
                              "sandboxSize",
                              "creditsPerMonth",
                              "publishedApps",
                              "topUpAllowed"
                            ],
                            "additionalProperties": false
                          }
                        },
                        "required": [
                          "key",
                          "name",
                          "description",
                          "stripeLookupKey",
                          "displayPriceCents",
                          "currency",
                          "interval",
                          "priceConfirmed",
                          "entitlements"
                        ],
                        "additionalProperties": false
                      }
                    },
                    "creditPacks": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "key": {
                            "type": "string",
                            "maxLength": 64,
                            "pattern": "^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$"
                          },
                          "name": {
                            "type": "string",
                            "minLength": 1
                          },
                          "credits": {
                            "type": "integer",
                            "exclusiveMinimum": 0,
                            "maximum": 9007199254740991
                          },
                          "stripeLookupKey": {
                            "type": "string",
                            "minLength": 1
                          },
                          "displayPriceCents": {
                            "type": "integer",
                            "minimum": 0,
                            "maximum": 9007199254740991
                          },
                          "currency": {
                            "type": "string",
                            "pattern": "^[a-z]{3}$"
                          },
                          "priceConfirmed": {
                            "type": "boolean"
                          }
                        },
                        "required": [
                          "key",
                          "name",
                          "credits",
                          "stripeLookupKey",
                          "displayPriceCents",
                          "currency",
                          "priceConfirmed"
                        ],
                        "additionalProperties": false
                      }
                    }
                  },
                  "required": [
                    "plans",
                    "creditPacks"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "default": {
            "description": "Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            }
          }
        }
      }
    },
    "/api/billing/subscription": {
      "get": {
        "operationId": "getSubscription",
        "summary": "The subscription and entitlements.",
        "parameters": [],
        "security": [
          {
            "session": []
          },
          {
            "token": []
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$schema": "https://json-schema.org/draft/2020-12/schema",
                  "type": "object",
                  "properties": {
                    "subscription": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "type": "string",
                          "pattern": "^sbs_[0-9A-Za-z]{8,64}$"
                        },
                        "organisationId": {
                          "type": "string",
                          "pattern": "^org_[0-9A-Za-z]{8,64}$"
                        },
                        "plan": {
                          "type": "string",
                          "enum": [
                            "free",
                            "pro",
                            "team"
                          ]
                        },
                        "status": {
                          "type": "string",
                          "enum": [
                            "trialing",
                            "active",
                            "past_due",
                            "canceled"
                          ]
                        },
                        "stripeCustomerId": {
                          "type": [
                            "string",
                            "null"
                          ]
                        },
                        "stripeSubscriptionId": {
                          "type": [
                            "string",
                            "null"
                          ]
                        },
                        "currentPeriodStart": {
                          "anyOf": [
                            {
                              "type": "string",
                              "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": "null"
                            }
                          ]
                        },
                        "currentPeriodEnd": {
                          "anyOf": [
                            {
                              "type": "string",
                              "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": "null"
                            }
                          ]
                        },
                        "cancelAtPeriodEnd": {
                          "type": "boolean"
                        },
                        "graceUntil": {
                          "anyOf": [
                            {
                              "type": "string",
                              "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": "null"
                            }
                          ]
                        },
                        "updatedAt": {
                          "type": "string",
                          "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))$"
                        }
                      },
                      "required": [
                        "id",
                        "organisationId",
                        "plan",
                        "status",
                        "stripeCustomerId",
                        "stripeSubscriptionId",
                        "currentPeriodStart",
                        "currentPeriodEnd",
                        "cancelAtPeriodEnd",
                        "graceUntil",
                        "updatedAt"
                      ],
                      "additionalProperties": false
                    },
                    "plan": {
                      "type": "object",
                      "properties": {
                        "key": {
                          "type": "string",
                          "enum": [
                            "free",
                            "pro",
                            "team"
                          ]
                        },
                        "name": {
                          "type": "string",
                          "minLength": 1
                        },
                        "description": {
                          "type": "string"
                        },
                        "stripeLookupKey": {
                          "anyOf": [
                            {
                              "type": "string",
                              "minLength": 1
                            },
                            {
                              "type": "null"
                            }
                          ]
                        },
                        "displayPriceCents": {
                          "type": "integer",
                          "minimum": 0,
                          "maximum": 9007199254740991
                        },
                        "currency": {
                          "type": "string",
                          "pattern": "^[a-z]{3}$"
                        },
                        "interval": {
                          "type": "string",
                          "const": "month"
                        },
                        "priceConfirmed": {
                          "type": "boolean"
                        },
                        "entitlements": {
                          "type": "object",
                          "properties": {
                            "projects": {
                              "anyOf": [
                                {
                                  "type": "integer",
                                  "minimum": 0,
                                  "maximum": 9007199254740991
                                },
                                {
                                  "type": "null"
                                }
                              ]
                            },
                            "members": {
                              "anyOf": [
                                {
                                  "type": "integer",
                                  "exclusiveMinimum": 0,
                                  "maximum": 9007199254740991
                                },
                                {
                                  "type": "null"
                                }
                              ]
                            },
                            "sandboxSize": {
                              "type": "string",
                              "enum": [
                                "standard-2",
                                "standard-4"
                              ]
                            },
                            "creditsPerMonth": {
                              "type": "integer",
                              "minimum": 0,
                              "maximum": 9007199254740991
                            },
                            "publishedApps": {
                              "anyOf": [
                                {
                                  "type": "integer",
                                  "minimum": 0,
                                  "maximum": 9007199254740991
                                },
                                {
                                  "type": "null"
                                }
                              ]
                            },
                            "topUpAllowed": {
                              "type": "boolean"
                            }
                          },
                          "required": [
                            "projects",
                            "members",
                            "sandboxSize",
                            "creditsPerMonth",
                            "publishedApps",
                            "topUpAllowed"
                          ],
                          "additionalProperties": false
                        }
                      },
                      "required": [
                        "key",
                        "name",
                        "description",
                        "stripeLookupKey",
                        "displayPriceCents",
                        "currency",
                        "interval",
                        "priceConfirmed",
                        "entitlements"
                      ],
                      "additionalProperties": false
                    },
                    "entitlements": {
                      "type": "object",
                      "properties": {
                        "projects": {
                          "anyOf": [
                            {
                              "type": "integer",
                              "minimum": 0,
                              "maximum": 9007199254740991
                            },
                            {
                              "type": "null"
                            }
                          ]
                        },
                        "members": {
                          "anyOf": [
                            {
                              "type": "integer",
                              "exclusiveMinimum": 0,
                              "maximum": 9007199254740991
                            },
                            {
                              "type": "null"
                            }
                          ]
                        },
                        "sandboxSize": {
                          "type": "string",
                          "enum": [
                            "standard-2",
                            "standard-4"
                          ]
                        },
                        "creditsPerMonth": {
                          "type": "integer",
                          "minimum": 0,
                          "maximum": 9007199254740991
                        },
                        "publishedApps": {
                          "anyOf": [
                            {
                              "type": "integer",
                              "minimum": 0,
                              "maximum": 9007199254740991
                            },
                            {
                              "type": "null"
                            }
                          ]
                        },
                        "topUpAllowed": {
                          "type": "boolean"
                        }
                      },
                      "required": [
                        "projects",
                        "members",
                        "sandboxSize",
                        "creditsPerMonth",
                        "publishedApps",
                        "topUpAllowed"
                      ],
                      "additionalProperties": false
                    }
                  },
                  "required": [
                    "subscription",
                    "plan",
                    "entitlements"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "default": {
            "description": "Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            }
          }
        },
        "x-permission": "billing.read"
      }
    },
    "/api/billing/checkout": {
      "post": {
        "operationId": "checkout",
        "summary": "Start a Stripe checkout for a plan or a credit pack.",
        "parameters": [],
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$schema": "https://json-schema.org/draft/2020-12/schema",
                  "type": "object",
                  "properties": {
                    "url": {
                      "type": "string",
                      "format": "uri"
                    }
                  },
                  "required": [
                    "url"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "default": {
            "description": "Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            }
          }
        },
        "x-permission": "billing.manage",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$schema": "https://json-schema.org/draft/2020-12/schema",
                "oneOf": [
                  {
                    "type": "object",
                    "properties": {
                      "kind": {
                        "type": "string",
                        "const": "plan"
                      },
                      "plan": {
                        "type": "string",
                        "enum": [
                          "free",
                          "pro",
                          "team"
                        ]
                      }
                    },
                    "required": [
                      "kind",
                      "plan"
                    ]
                  },
                  {
                    "type": "object",
                    "properties": {
                      "kind": {
                        "type": "string",
                        "const": "credit_pack"
                      },
                      "pack": {
                        "type": "string",
                        "maxLength": 64,
                        "pattern": "^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$"
                      }
                    },
                    "required": [
                      "kind",
                      "pack"
                    ]
                  }
                ]
              }
            }
          }
        }
      }
    },
    "/api/billing/portal": {
      "post": {
        "operationId": "portal",
        "summary": "Open the Stripe customer portal.",
        "parameters": [],
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$schema": "https://json-schema.org/draft/2020-12/schema",
                  "type": "object",
                  "properties": {
                    "url": {
                      "type": "string",
                      "format": "uri"
                    }
                  },
                  "required": [
                    "url"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "default": {
            "description": "Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            }
          }
        },
        "x-permission": "billing.manage",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$schema": "https://json-schema.org/draft/2020-12/schema",
                "type": "object",
                "properties": {
                  "returnPath": {
                    "type": "string",
                    "format": "starts_with",
                    "pattern": "^\\/.*"
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/billing/invoices": {
      "get": {
        "operationId": "listInvoices",
        "summary": "Invoices.",
        "parameters": [],
        "security": [
          {
            "session": []
          },
          {
            "token": []
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$schema": "https://json-schema.org/draft/2020-12/schema",
                  "type": "object",
                  "properties": {
                    "invoices": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string",
                            "minLength": 1
                          },
                          "number": {
                            "type": [
                              "string",
                              "null"
                            ]
                          },
                          "status": {
                            "type": "string",
                            "enum": [
                              "draft",
                              "open",
                              "paid",
                              "void",
                              "uncollectible"
                            ]
                          },
                          "totalCents": {
                            "type": "integer",
                            "minimum": 0,
                            "maximum": 9007199254740991
                          },
                          "currency": {
                            "type": "string",
                            "pattern": "^[a-z]{3}$"
                          },
                          "createdAt": {
                            "type": "string",
                            "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))$"
                          },
                          "periodStart": {
                            "anyOf": [
                              {
                                "type": "string",
                                "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": "null"
                              }
                            ]
                          },
                          "periodEnd": {
                            "anyOf": [
                              {
                                "type": "string",
                                "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": "null"
                              }
                            ]
                          },
                          "hostedUrl": {
                            "anyOf": [
                              {
                                "type": "string",
                                "format": "uri"
                              },
                              {
                                "type": "null"
                              }
                            ]
                          },
                          "pdfUrl": {
                            "anyOf": [
                              {
                                "type": "string",
                                "format": "uri"
                              },
                              {
                                "type": "null"
                              }
                            ]
                          }
                        },
                        "required": [
                          "id",
                          "number",
                          "status",
                          "totalCents",
                          "currency",
                          "createdAt",
                          "periodStart",
                          "periodEnd",
                          "hostedUrl",
                          "pdfUrl"
                        ],
                        "additionalProperties": false
                      }
                    }
                  },
                  "required": [
                    "invoices"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "default": {
            "description": "Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            }
          }
        },
        "x-permission": "billing.read"
      }
    },
    "/api/billing/credits": {
      "get": {
        "operationId": "getCredits",
        "summary": "The credit balance and its transactions.",
        "parameters": [
          {
            "name": "cursor",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "minLength": 1
            }
          },
          {
            "name": "limit",
            "in": "query",
            "required": true,
            "schema": {
              "default": 50,
              "type": "integer",
              "minimum": 1,
              "maximum": 100
            }
          }
        ],
        "security": [
          {
            "session": []
          },
          {
            "token": []
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$schema": "https://json-schema.org/draft/2020-12/schema",
                  "type": "object",
                  "properties": {
                    "balance": {
                      "type": "integer",
                      "minimum": -9007199254740991,
                      "maximum": 9007199254740991
                    },
                    "monthlyGrant": {
                      "type": "integer",
                      "minimum": 0,
                      "maximum": 9007199254740991
                    },
                    "nextGrantAt": {
                      "anyOf": [
                        {
                          "type": "string",
                          "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": "null"
                        }
                      ]
                    },
                    "transactions": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string",
                            "pattern": "^crt_[0-9A-Za-z]{8,64}$"
                          },
                          "organisationId": {
                            "type": "string",
                            "pattern": "^org_[0-9A-Za-z]{8,64}$"
                          },
                          "kind": {
                            "type": "string",
                            "enum": [
                              "monthly_grant",
                              "top_up",
                              "usage",
                              "refund",
                              "expiry"
                            ]
                          },
                          "amount": {
                            "type": "integer",
                            "minimum": -9007199254740991,
                            "maximum": 9007199254740991
                          },
                          "balanceAfter": {
                            "type": "integer",
                            "minimum": -9007199254740991,
                            "maximum": 9007199254740991
                          },
                          "usageEventId": {
                            "anyOf": [
                              {
                                "type": "string",
                                "pattern": "^use_[0-9A-Za-z]{8,64}$"
                              },
                              {
                                "type": "null"
                              }
                            ]
                          },
                          "stripeRef": {
                            "type": [
                              "string",
                              "null"
                            ]
                          },
                          "note": {
                            "type": [
                              "string",
                              "null"
                            ]
                          },
                          "expiresAt": {
                            "anyOf": [
                              {
                                "type": "string",
                                "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": "null"
                              }
                            ]
                          },
                          "createdAt": {
                            "type": "string",
                            "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))$"
                          }
                        },
                        "required": [
                          "id",
                          "organisationId",
                          "kind",
                          "amount",
                          "balanceAfter",
                          "usageEventId",
                          "stripeRef",
                          "note",
                          "expiresAt",
                          "createdAt"
                        ],
                        "additionalProperties": false
                      }
                    },
                    "nextCursor": {
                      "type": [
                        "string",
                        "null"
                      ]
                    }
                  },
                  "required": [
                    "balance",
                    "monthlyGrant",
                    "nextGrantAt",
                    "transactions",
                    "nextCursor"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "default": {
            "description": "Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            }
          }
        },
        "x-permission": "billing.read"
      }
    },
    "/api/webhooks/stripe": {
      "post": {
        "operationId": "handleStripeWebhook",
        "summary": "Stripe events, signature checked, each handled once.",
        "parameters": [],
        "security": [],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$schema": "https://json-schema.org/draft/2020-12/schema",
                  "type": "object",
                  "properties": {
                    "received": {
                      "type": "boolean",
                      "const": true
                    }
                  },
                  "required": [
                    "received"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "default": {
            "description": "Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "ErrorEnvelope": {
        "$schema": "https://json-schema.org/draft/2020-12/schema",
        "type": "object",
        "properties": {
          "error": {
            "type": "object",
            "properties": {
              "code": {
                "type": "string",
                "pattern": "^[a-z][a-z0-9_]*$"
              },
              "message": {
                "type": "string",
                "minLength": 1
              },
              "details": {
                "type": "object",
                "propertyNames": {
                  "type": "string"
                },
                "additionalProperties": {}
              }
            },
            "required": [
              "code",
              "message"
            ],
            "additionalProperties": false
          }
        },
        "required": [
          "error"
        ],
        "additionalProperties": false
      }
    },
    "securitySchemes": {
      "session": {
        "type": "apiKey",
        "in": "cookie",
        "name": "session"
      },
      "token": {
        "type": "http",
        "scheme": "bearer"
      }
    }
  }
}
