{
  "openapi": "3.1.0",
  "info": {
    "title": "ReplyBrain API",
    "version": "1.0.0",
    "summary": "Cases, needs, runs, actions, commitments and the event stream of your ReplyBrain organization, and the signed events a connected product posts.",
    "description": "Every request but one is authenticated with an organization-owned secret key: `Authorization: Bearer rb_sk_live_…`. Each key carries scopes named after resource families (`cases.read`, `cases.write`, …); reads need `<family>.read`, writes `<family>.write`.\n\nEvery write needs an `Idempotency-Key` header. ReplyBrain keeps each (organization, key) record for the life of the organization: a retry with the same key and body answers the recorded resource (`Idempotent-Replayed: true`), the same key with another body is `409 idempotency_conflict`.\n\n`202 Accepted` means recorded, never sent or done: poll the `Location`.\n\nLists return `data` and an opaque `next_cursor` (stable order, bound to the key and the route, valid one hour). The event stream's cursor lasts seven days.\n\n`POST /v1/connections/{id}/events` is the exception: a connected product signs it with its connection secret (`ReplyBrain-Signature`), with no Bearer key.\n\nEach key may send 600 requests a minute; above that, `429 rate_limited` with `Retry-After`."
  },
  "servers": [
    {
      "url": "https://replybrain.com",
      "description": "Production"
    }
  ],
  "security": [
    {
      "secretKey": []
    }
  ],
  "tags": [
    {
      "name": "context-queries",
      "description": "Ask for scoped evidence about a customer, without opening a case."
    },
    {
      "name": "cases",
      "description": "Cases and their messages. A managed case lives on ReplyBrain's own desk; a connected case lives in your product."
    },
    {
      "name": "needs",
      "description": "What a customer wants, with the message it came from."
    },
    {
      "name": "connections",
      "description": "A connected product: the events it posts and its status."
    },
    {
      "name": "runs",
      "description": "Bounded work on one need, planned by ReplyBrain or by your own agent."
    },
    {
      "name": "capabilities",
      "description": "The things ReplyBrain may ask your product to do, as registered."
    },
    {
      "name": "actions",
      "description": "One planned step: read it, approve it, dispatch it, cancel it, reconcile it."
    },
    {
      "name": "commitments",
      "description": "Promises made to a customer, tracked until they are kept."
    },
    {
      "name": "events",
      "description": "The organization's event stream, with cursor replay."
    },
    {
      "name": "waits",
      "description": "What waits for a person in your organization."
    }
  ],
  "paths": {
    "/v1/context-queries": {
      "post": {
        "tags": [
          "context-queries"
        ],
        "operationId": "createContextQuery",
        "summary": "Ask for scoped evidence (no case needed)",
        "description": "Scope `context.read`. Records the query and answers `202`; ReplyBrain reads your connected products' facts afterwards. Nothing is sent, opened or changed. Poll the `Location`.",
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ContextQueryRequest"
              }
            }
          }
        },
        "responses": {
          "202": {
            "$ref": "#/components/responses/ContextQueryAccepted"
          },
          "400": {
            "$ref": "#/components/responses/InvalidRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "$ref": "#/components/responses/PolicyDenied"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/v1/context-queries/{id}": {
      "get": {
        "tags": [
          "context-queries"
        ],
        "operationId": "getContextQuery",
        "summary": "Poll a context query",
        "description": "Scope `context.read`. Once `completed`, `result` holds the evidence, what was missing and why.",
        "parameters": [
          {
            "$ref": "#/components/parameters/Id"
          }
        ],
        "responses": {
          "200": {
            "description": "The query and, once completed, its evidence, missing and unsupported sources.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ContextQuery"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/v1/cases": {
      "get": {
        "tags": [
          "cases"
        ],
        "operationId": "listCases",
        "summary": "List cases",
        "description": "Scope `cases.read`. Oldest first. A key bounded to products, connections, accounts or cases sees only those.",
        "parameters": [
          {
            "$ref": "#/components/parameters/Cursor"
          },
          {
            "$ref": "#/components/parameters/Limit"
          }
        ],
        "responses": {
          "200": {
            "description": "A page of cases.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CasePage"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "$ref": "#/components/responses/PolicyDenied"
          },
          "410": {
            "$ref": "#/components/responses/CursorExpired"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      },
      "post": {
        "tags": [
          "cases"
        ],
        "operationId": "createCase",
        "summary": "Open a managed case",
        "description": "Scope `cases.write`. Opens a case on your organization's managed desk with the customer's first message. `201` when a case was opened, `200` when the message was added to the requester's open case. The email names the requester; it proves nothing about who they are.",
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CaseCreateRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Added to the requester's open case.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Case"
                }
              }
            }
          },
          "201": {
            "description": "Opened.",
            "headers": {
              "Location": {
                "$ref": "#/components/headers/Location"
              },
              "ETag": {
                "$ref": "#/components/headers/ETag"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Case"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/InvalidRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/v1/cases/{id}": {
      "get": {
        "tags": [
          "cases"
        ],
        "operationId": "getCase",
        "summary": "Read a case",
        "description": "Scope `cases.read`. The `ETag` is what `PATCH` needs as `If-Match`.",
        "parameters": [
          {
            "$ref": "#/components/parameters/Id"
          }
        ],
        "responses": {
          "200": {
            "description": "The case.",
            "headers": {
              "ETag": {
                "$ref": "#/components/headers/ETag"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Case"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      },
      "patch": {
        "tags": [
          "cases"
        ],
        "operationId": "updateCase",
        "summary": "Rename a managed case",
        "description": "Scope `cases.write`. Only `title` changes. A connected case changes in your product, never here (`409 capability_unavailable`).",
        "parameters": [
          {
            "$ref": "#/components/parameters/Id"
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          },
          {
            "$ref": "#/components/parameters/IfMatch"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "case"
                ],
                "properties": {
                  "case": {
                    "type": "object",
                    "properties": {
                      "title": {
                        "type": "string"
                      }
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Updated.",
            "headers": {
              "ETag": {
                "$ref": "#/components/headers/ETag"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Case"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "412": {
            "$ref": "#/components/responses/StaleRevision"
          },
          "428": {
            "$ref": "#/components/responses/PreconditionRequired"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/v1/cases/{id}/messages": {
      "get": {
        "tags": [
          "cases"
        ],
        "operationId": "listCaseMessages",
        "summary": "Read a case's transcript",
        "description": "Scope `cases.read`. Chronological, bodies included. A connected message whose source access was revoked comes back without its body (`body_revoked: true`).",
        "parameters": [
          {
            "$ref": "#/components/parameters/Id"
          },
          {
            "$ref": "#/components/parameters/Cursor"
          },
          {
            "$ref": "#/components/parameters/Limit"
          }
        ],
        "responses": {
          "200": {
            "description": "A page of messages.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/MessagePage"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "410": {
            "$ref": "#/components/responses/CursorExpired"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      },
      "post": {
        "tags": [
          "cases"
        ],
        "operationId": "createCaseMessage",
        "summary": "Add the customer's next message to a managed case",
        "description": "Scope `cases.write`. Inbound customer messages only: `direction` other than `inbound` or `visibility` other than `customer` is `409 capability_unavailable`. Replies are drafted by ReplyBrain and approved by a person; a connected case's messages arrive through its connection's events (`409`).",
        "parameters": [
          {
            "$ref": "#/components/parameters/Id"
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "message"
                ],
                "properties": {
                  "message": {
                    "type": "object",
                    "required": [
                      "body_text"
                    ],
                    "properties": {
                      "body_text": {
                        "type": "string"
                      },
                      "direction": {
                        "type": "string",
                        "enum": [
                          "inbound"
                        ]
                      },
                      "visibility": {
                        "type": "string",
                        "enum": [
                          "customer"
                        ]
                      }
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Recorded in the desk's transcript.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Message"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/v1/cases/{case_id}/needs": {
      "post": {
        "tags": [
          "needs"
        ],
        "operationId": "createNeed",
        "summary": "Record a need",
        "description": "Scope `needs.write`. `message_ref_id` must be a message of the same case.",
        "parameters": [
          {
            "name": "case_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "message_ref_id",
                  "need"
                ],
                "properties": {
                  "message_ref_id": {
                    "type": "string"
                  },
                  "need": {
                    "type": "object",
                    "required": [
                      "desired_outcome"
                    ],
                    "properties": {
                      "desired_outcome": {
                        "type": "string"
                      }
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Recorded.",
            "headers": {
              "Location": {
                "$ref": "#/components/headers/Location"
              },
              "ETag": {
                "$ref": "#/components/headers/ETag"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Need"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/InvalidRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/v1/needs/{id}": {
      "get": {
        "tags": [
          "needs"
        ],
        "operationId": "getNeed",
        "summary": "Read a need",
        "description": "Scope `needs.read`.",
        "parameters": [
          {
            "$ref": "#/components/parameters/Id"
          }
        ],
        "responses": {
          "200": {
            "description": "The need.",
            "headers": {
              "ETag": {
                "$ref": "#/components/headers/ETag"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Need"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      },
      "patch": {
        "tags": [
          "needs"
        ],
        "operationId": "updateNeed",
        "summary": "Reword or decide a need",
        "description": "Scope `needs.write`. `desired_outcome` changes only while the need is `identified` (`409 invalid_state`). `state` (`satisfied`, `declined`, `unknown`) is a human decision, recorded as the decision of the member who created the key.",
        "parameters": [
          {
            "$ref": "#/components/parameters/Id"
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          },
          {
            "$ref": "#/components/parameters/IfMatch"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "need"
                ],
                "properties": {
                  "need": {
                    "type": "object",
                    "properties": {
                      "desired_outcome": {
                        "type": "string"
                      },
                      "state": {
                        "type": "string",
                        "enum": [
                          "satisfied",
                          "declined",
                          "unknown"
                        ]
                      }
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Updated.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Need"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/InvalidRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "$ref": "#/components/responses/PolicyDenied"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "412": {
            "$ref": "#/components/responses/StaleRevision"
          },
          "428": {
            "$ref": "#/components/responses/PreconditionRequired"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/v1/connections/{id}/events": {
      "post": {
        "tags": [
          "connections"
        ],
        "operationId": "postConnectionEvent",
        "summary": "Post a signed event from your product",
        "description": "Signed with the connection's secret, no Bearer key: `ReplyBrain-Signature` and `ReplyBrain-Key-Id` over the raw body, within five minutes (see the security scheme). Recorded once per `source_event_id`: posting the same id again answers `state: duplicate` and changes nothing. `202` means recorded; the message is read and drafted afterwards. Bodies over 256 KB are refused with `413`.",
        "security": [
          {
            "replybrainSignature": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/Id"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/SourceEventRequest"
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "Recorded (or a duplicate of an event already recorded).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SourceEvent"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/InvalidRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "413": {
            "$ref": "#/components/responses/PayloadTooLarge"
          }
        }
      }
    },
    "/v1/connections/{id}/status": {
      "get": {
        "tags": [
          "connections"
        ],
        "operationId": "getConnectionStatus",
        "summary": "Read a connection's status",
        "description": "Scope `connections.read`. Sync health, credential state and what the connection declared it can do. Never a credential.",
        "parameters": [
          {
            "$ref": "#/components/parameters/Id"
          }
        ],
        "responses": {
          "200": {
            "description": "The status.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ConnectionStatus"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/v1/runs": {
      "post": {
        "tags": [
          "runs"
        ],
        "operationId": "createRun",
        "summary": "Start a run for one need",
        "description": "Scope `runs.write`. `planner: replybrain` (default) has ReplyBrain plan after the `202`; `planner: caller` waits for your own plan (`POST /v1/runs/{id}/plans`). `budget` is a ceiling; it never raises what your organization allows.",
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "need_id"
                ],
                "properties": {
                  "need_id": {
                    "type": "string"
                  },
                  "case_id": {
                    "type": "string"
                  },
                  "objective": {
                    "type": "string"
                  },
                  "planner": {
                    "type": "string",
                    "enum": [
                      "replybrain",
                      "caller"
                    ]
                  },
                  "budget": {
                    "type": "object",
                    "additionalProperties": false,
                    "properties": {
                      "max_cost_minor": {
                        "type": "integer",
                        "minimum": 0
                      },
                      "max_tool_calls": {
                        "type": "integer",
                        "minimum": 0
                      },
                      "currency": {
                        "type": "string",
                        "pattern": "^[A-Z]{3}$"
                      },
                      "deadline_at": {
                        "type": "string",
                        "format": "date-time"
                      }
                    }
                  },
                  "deadline_at": {
                    "type": "string",
                    "format": "date-time"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "Recorded, queued.",
            "headers": {
              "Location": {
                "$ref": "#/components/headers/Location"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Run"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/InvalidRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/v1/runs/{id}": {
      "get": {
        "tags": [
          "runs"
        ],
        "operationId": "getRun",
        "summary": "Poll a run",
        "description": "Scope `runs.read`. `completed` means the run ended, not that the need is satisfied.",
        "parameters": [
          {
            "$ref": "#/components/parameters/Id"
          }
        ],
        "responses": {
          "200": {
            "description": "The run.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Run"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/v1/runs/{id}/cancel": {
      "post": {
        "tags": [
          "runs"
        ],
        "operationId": "cancelRun",
        "summary": "Cancel a run",
        "description": "Scope `runs.write`. Actions not yet dispatched are cancelled. Dispatched work is listed under `work.running` until it is reconciled. A run that already ended is `409 invalid_state`.",
        "parameters": [
          {
            "$ref": "#/components/parameters/Id"
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "responses": {
          "202": {
            "description": "Cancelled; what is still running and what already committed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Run"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/v1/runs/{id}/plans": {
      "post": {
        "tags": [
          "runs"
        ],
        "operationId": "createPlan",
        "summary": "Submit a plan for a run",
        "description": "Scope `runs.write`. A run takes one plan; once planned, cancelled, failed or past its deadline it takes no other (`409 invalid_state`). Each step is checked like ReplyBrain's own: a registered capability, arguments matching its schema, known dependencies. Rejected steps come back with reasons. `base_revision` is the revision you read (0 for none).",
        "parameters": [
          {
            "$ref": "#/components/parameters/Id"
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PlanRequest"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "The new revision.",
            "headers": {
              "Location": {
                "$ref": "#/components/headers/Location"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Plan"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/InvalidRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "$ref": "#/components/responses/PolicyDenied"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "412": {
            "$ref": "#/components/responses/StaleRevision"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/v1/runs/{id}/plans/{revision}": {
      "get": {
        "tags": [
          "runs"
        ],
        "operationId": "getPlan",
        "summary": "Read a plan revision",
        "description": "Scope `runs.read`.",
        "parameters": [
          {
            "$ref": "#/components/parameters/Id"
          },
          {
            "name": "revision",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer",
              "minimum": 1
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The revision.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Plan"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/v1/capabilities": {
      "get": {
        "tags": [
          "capabilities"
        ],
        "operationId": "listCapabilities",
        "summary": "List registered capabilities",
        "description": "Scope `capabilities.read`. Reading a schema is not permission to run it.",
        "parameters": [
          {
            "$ref": "#/components/parameters/Cursor"
          },
          {
            "$ref": "#/components/parameters/Limit"
          }
        ],
        "responses": {
          "200": {
            "description": "A page of capabilities.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CapabilityPage"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "410": {
            "$ref": "#/components/responses/CursorExpired"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/v1/capabilities/{name}/versions/{version}": {
      "get": {
        "tags": [
          "capabilities"
        ],
        "operationId": "getCapabilityVersion",
        "summary": "Read one capability version",
        "description": "Scope `capabilities.read`.",
        "parameters": [
          {
            "name": "name",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "example": "order.refund"
          },
          {
            "name": "version",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer",
              "minimum": 1
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The capability.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Capability"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/v1/actions/{id}": {
      "get": {
        "tags": [
          "actions"
        ],
        "operationId": "getAction",
        "summary": "Read an action",
        "description": "Scope `actions.read`. Reading never runs anything.",
        "parameters": [
          {
            "$ref": "#/components/parameters/Id"
          }
        ],
        "responses": {
          "200": {
            "description": "The action.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Action"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/v1/actions/{id}/dispatch": {
      "post": {
        "tags": [
          "actions"
        ],
        "operationId": "dispatchAction",
        "summary": "Dispatch an action",
        "description": "Scope `actions.write`, plus `actions.<effect class>` for a `financial`, `identity`, `deployment` or `work` effect. Policy and approval are checked now and again before the call. An action that needs an approval it does not have is `409 approval_required`. `202`: the dispatch is recorded (`dispatch.state: pending`); poll the action.",
        "parameters": [
          {
            "$ref": "#/components/parameters/Id"
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "responses": {
          "202": {
            "description": "Recorded.",
            "headers": {
              "Location": {
                "$ref": "#/components/headers/Location"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Action"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "$ref": "#/components/responses/PolicyDenied"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/v1/actions/{id}/cancel": {
      "post": {
        "tags": [
          "actions"
        ],
        "operationId": "cancelAction",
        "summary": "Cancel an action that was not dispatched",
        "description": "Scope `actions.write`. Only `proposed`, `awaiting_approval` or `ready` actions; dispatched work may have acted, so it is reconciled, not cancelled (`409 invalid_state`).",
        "parameters": [
          {
            "$ref": "#/components/parameters/Id"
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "responses": {
          "200": {
            "description": "Cancelled.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Action"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/v1/actions/{id}/reconcile": {
      "post": {
        "tags": [
          "actions"
        ],
        "operationId": "reconcileAction",
        "summary": "Find out what happened to an action",
        "description": "Scope `actions.write`. Only for an `outcome_unknown` action (`409 invalid_state` otherwise). Asks your product whether the effect happened; never repeats it. `202`, then poll.",
        "parameters": [
          {
            "$ref": "#/components/parameters/Id"
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "responses": {
          "202": {
            "description": "Recorded.",
            "headers": {
              "Location": {
                "$ref": "#/components/headers/Location"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Action"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/v1/actions/{id}/approvals": {
      "post": {
        "tags": [
          "actions"
        ],
        "operationId": "decideAction",
        "summary": "Approve or reject an action",
        "description": "Scope `approvals.write`, plus `actions.<effect class>` for a structural effect. The decision is recorded as the key creator's, a member who may approve actions. A key cannot decide a plan it proposed (`403`). The approval is bound to `action_revision` and `arguments_digest`: if the action changed, `412 stale_revision`.",
        "parameters": [
          {
            "$ref": "#/components/parameters/Id"
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "decision",
                  "action_revision"
                ],
                "properties": {
                  "decision": {
                    "type": "string",
                    "enum": [
                      "approve",
                      "reject"
                    ]
                  },
                  "action_revision": {
                    "type": "integer"
                  },
                  "arguments_digest": {
                    "type": "string",
                    "description": "The digest you read. If the action's arguments changed since, 412."
                  },
                  "policy_revision": {
                    "type": "integer",
                    "description": "Must be the policy revision in force (409 authority_mismatch otherwise)."
                  },
                  "expires_at": {
                    "type": "string",
                    "format": "date-time",
                    "description": "May only shorten the capability's default expiry (400 otherwise)."
                  },
                  "precondition_snapshot_id": {
                    "type": "string",
                    "description": "Not supported: refused with 400.",
                    "which issues no precondition snapshots.": null
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Rejected; the action is cancelled.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Action"
                }
              }
            }
          },
          "201": {
            "description": "Approved.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Approval"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "$ref": "#/components/responses/PolicyDenied"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "412": {
            "$ref": "#/components/responses/StaleRevision"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/v1/commitments": {
      "post": {
        "tags": [
          "commitments"
        ],
        "operationId": "createCommitment",
        "summary": "Record a proposed commitment",
        "description": "Scope `commitments.write`. A caller proposes; reserving, communicating and fulfilling happen in ReplyBrain. `due_at` is refused (`400`): send `review_at`.",
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "case_id",
                  "commitment"
                ],
                "properties": {
                  "case_id": {
                    "type": "string"
                  },
                  "commitment": {
                    "type": "object",
                    "required": [
                      "kind",
                      "wording"
                    ],
                    "properties": {
                      "kind": {
                        "type": "string"
                      },
                      "wording": {
                        "type": "string"
                      },
                      "owner_action_id": {
                        "type": "string"
                      },
                      "review_at": {
                        "type": "string",
                        "format": "date-time"
                      },
                      "conditions": {
                        "type": "array",
                        "items": {
                          "type": "object",
                          "properties": {
                            "predicate": {
                              "type": "string"
                            },
                            "follow_up": {
                              "type": "string"
                            }
                          }
                        }
                      },
                      "due_at": {
                        "type": "string",
                        "format": "date-time",
                        "description": "Refused (400): a caller sets `review_at`, never a due date."
                      }
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Proposed.",
            "headers": {
              "Location": {
                "$ref": "#/components/headers/Location"
              },
              "ETag": {
                "$ref": "#/components/headers/ETag"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Commitment"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/InvalidRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/v1/commitments/{id}": {
      "get": {
        "tags": [
          "commitments"
        ],
        "operationId": "getCommitment",
        "summary": "Read a commitment",
        "description": "Scope `commitments.read`.",
        "parameters": [
          {
            "$ref": "#/components/parameters/Id"
          }
        ],
        "responses": {
          "200": {
            "description": "The commitment.",
            "headers": {
              "ETag": {
                "$ref": "#/components/headers/ETag"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Commitment"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      },
      "patch": {
        "tags": [
          "commitments"
        ],
        "operationId": "updateCommitment",
        "summary": "Reword, reschedule or withdraw a commitment",
        "description": "Scope `commitments.write`. `wording` and `review_at` change only while the commitment is `proposed` (`409 invalid_state`). `state` takes only `withdrawn`. A `work` commitment is withdrawn with a `reason` (the customer is told when it had been communicated) by a key a member created: `422 reason_required` or `422 unattributed` otherwise, `409 send_in_progress` while a reply about it is being sent.",
        "parameters": [
          {
            "$ref": "#/components/parameters/Id"
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          },
          {
            "$ref": "#/components/parameters/IfMatch"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "commitment"
                ],
                "properties": {
                  "commitment": {
                    "type": "object",
                    "properties": {
                      "wording": {
                        "type": "string"
                      },
                      "review_at": {
                        "type": "string",
                        "format": "date-time"
                      },
                      "state": {
                        "type": "string",
                        "enum": [
                          "withdrawn"
                        ]
                      },
                      "reason": {
                        "type": "string",
                        "description": "Why a `work` commitment is withdrawn. Required for one; the customer is told when it had been communicated."
                      }
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Updated.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Commitment"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/InvalidRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "412": {
            "$ref": "#/components/responses/StaleRevision"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          },
          "428": {
            "$ref": "#/components/responses/PreconditionRequired"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/v1/events": {
      "get": {
        "tags": [
          "events"
        ],
        "operationId": "listEvents",
        "summary": "Read the event stream",
        "description": "Scope `events.read`. A bounded key sees only events about records it may read. `next_cursor` is always present: the stream does not end, so stop at an empty page and resume from the cursor later. Deduplicate by event `id`. An expired cursor is `410 cursor_expired` with `details.snapshot_cursor`: read current state, then resume from it.",
        "parameters": [
          {
            "name": "after",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "A next_cursor from an earlier page."
          },
          {
            "name": "from",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "now"
              ]
            },
            "description": "Start at the current horizon; request it before reading a snapshot."
          },
          {
            "name": "run_id",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Only the run",
            "its plans and their actions.": null
          },
          {
            "$ref": "#/components/parameters/Limit"
          }
        ],
        "responses": {
          "200": {
            "description": "A page of events.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/EventPage"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "410": {
            "$ref": "#/components/responses/CursorExpired"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/v1/waits": {
      "get": {
        "tags": [
          "waits"
        ],
        "operationId": "listWaits",
        "summary": "List what waits for a person",
        "description": "Scope `waits.read`. `provider_confirmation`: your product could not tell whether an effect happened; confirm with the provider. `registration_invalid`: a capability's registration fails today's rules and is disabled; register it again. `late_cost`: a model call's cost arrived after its run was settled; no money moved. Without `kind`, all three.",
        "parameters": [
          {
            "name": "kind",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "provider_confirmation",
                "registration_invalid",
                "late_cost"
              ]
            }
          },
          {
            "name": "state",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "open",
                "resolved"
              ]
            }
          },
          {
            "$ref": "#/components/parameters/Cursor"
          },
          {
            "$ref": "#/components/parameters/Limit"
          }
        ],
        "responses": {
          "200": {
            "description": "A page of waits.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/WaitPage"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/InvalidRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "410": {
            "$ref": "#/components/responses/CursorExpired"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/v1/waits/{id}": {
      "get": {
        "tags": [
          "waits"
        ],
        "operationId": "getWait",
        "summary": "Read one wait",
        "description": "Scope `waits.read`.",
        "parameters": [
          {
            "$ref": "#/components/parameters/Id"
          }
        ],
        "responses": {
          "200": {
            "description": "The wait.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Wait"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    }
  },
  "webhooks": {
    "messagePublish": {
      "post": {
        "operationId": "hostMessagePublish",
        "summary": "A reply for your product's conversation (`capabilities/message.publish`)",
        "description": "`Idempotency-Key` is the `effect_key`. `mode: draft` asks you to hold it as a draft your people send. `mode: publish` is used only for a connection that declares conditional publishing; the assistant's words are sent only to one that also declares the disclosure contract, which renders `disclosure_mode` or refuses with `disclosure_unsupported`. `valid_until` comes only to a connection that declared it enforces it.",
        "security": [
          {
            "replybrainSignature": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/HostMessagePublish"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "`{ status: accepted, source_refs: { message_id } }`, `{ status: drafted, ref }` or `{ status: refused, reason }`."
          }
        }
      }
    },
    "messageWithdraw": {
      "post": {
        "operationId": "hostMessageWithdraw",
        "summary": "Take back a draft (`capabilities/message.withdraw`)",
        "description": "Until your product serves and registers this, it is sent no assistant draft at all. Same `effect_key` on every retry. Reject the draft under the same lock a person's send takes; a withdrawal that arrives before the draft prevents it.",
        "security": [
          {
            "replybrainSignature": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "capability": {
                    "const": "message.withdraw"
                  },
                  "version": {
                    "type": "integer"
                  },
                  "effect_key": {
                    "type": "string"
                  },
                  "arguments": {
                    "type": "object",
                    "properties": {
                      "publication_id": {
                        "type": "string"
                      },
                      "draft_id": {
                        "type": "string"
                      },
                      "reason": {
                        "type": "string",
                        "pattern": "^[a-z0-9_.:-]{1,64}$"
                      }
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "`{ status: succeeded, provider_refs: { outcome: withdrawn | prevented | not_pending | already_sent, message_id? } }` or `{ status: failed, failure_reason }`."
          }
        }
      }
    },
    "supportOpenTickets": {
      "post": {
        "operationId": "hostOpenTickets",
        "summary": "List open conversations (`capabilities/support.open_tickets`)",
        "description": "Read-only. Open conversations only, oldest first. `conversation_ref` is exactly `<source_object.type>:<source_object.id>` of your events.",
        "security": [
          {
            "replybrainSignature": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "capability": {
                    "const": "support.open_tickets"
                  },
                  "version": {
                    "type": "integer"
                  },
                  "arguments": {
                    "type": "object"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "`{ status: succeeded, provider_refs: { tickets: [ { conversation_ref, latest_message_id, opened_at, awaiting, requester } ], truncated } }`."
          }
        }
      }
    },
    "identityLookup": {
      "post": {
        "operationId": "hostIdentityLookup",
        "summary": "Who wrote from this address (`capabilities/identity.lookup`)",
        "description": "Read-only. Asked for an inbound mail's sender. The answer is a candidate a person confirms, never proof.",
        "security": [
          {
            "replybrainSignature": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "capability": {
                    "const": "identity.lookup"
                  },
                  "version": {
                    "type": "integer"
                  },
                  "arguments": {
                    "type": "object",
                    "required": [
                      "email"
                    ],
                    "properties": {
                      "email": {
                        "type": "string"
                      },
                      "phones": {
                        "type": "array",
                        "items": {
                          "type": "string"
                        }
                      },
                      "name": {
                        "type": "string"
                      }
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "`{ status: succeeded, provider_refs: { ref, account_scope, name?, email?, phone?, matched_by? } }` (both null: nobody), or `{ status: failed, failure_reason: invalid_email }`."
          }
        }
      }
    },
    "conversationClose": {
      "post": {
        "operationId": "hostConversationClose",
        "summary": "Close a conversation (`capabilities/conversation.close`)",
        "description": "A compare-and-close: close only if the last message is still `expected_last_message_id`. Without this capability, ReplyBrain never wraps up a case of your product.",
        "security": [
          {
            "replybrainSignature": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "capability": {
                    "const": "conversation.close"
                  },
                  "version": {
                    "type": "integer"
                  },
                  "effect_key": {
                    "type": "string"
                  },
                  "arguments": {
                    "type": "object",
                    "properties": {
                      "conversation_ref": {
                        "type": "string"
                      },
                      "expected_last_message_id": {
                        "type": "string"
                      },
                      "closing_publication_id": {
                        "type": "string"
                      },
                      "silent": {
                        "type": "string",
                        "enum": [
                          "true",
                          "false"
                        ]
                      }
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "`{ status: succeeded, provider_refs: { outcome: closed } }`, or `{ status: failed, failure_reason }`."
          }
        }
      }
    },
    "facts": {
      "post": {
        "operationId": "hostFacts",
        "summary": "Facts about one record (`facts/<topic>`)",
        "description": "Answer only for a record that `account_scope` owns. A record of another account answers exactly like a missing one.",
        "security": [
          {
            "replybrainSignature": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "ref": {
                    "type": "object",
                    "properties": {
                      "type": {
                        "type": "string"
                      },
                      "id": {
                        "type": "string"
                      },
                      "account_scope": {
                        "type": "string"
                      }
                    }
                  },
                  "purpose": {
                    "type": "string"
                  },
                  "query": {
                    "type": "object"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "`{ facts: { … }, revision, observed_at, ref }`. 404 `not_found`: no such record (for this account). 404 `unsupported`: you serve no such topic."
          }
        }
      }
    },
    "manifest": {
      "post": {
        "operationId": "hostManifest",
        "summary": "What your product offers (`manifest`)",
        "description": "Read when your connection is set up and whenever your capabilities change.",
        "security": [
          {
            "replybrainSignature": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "`{ capabilities: [ … ], facts: { account_topic, record_topics }, client_version }`."
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "secretKey": {
        "type": "http",
        "scheme": "bearer",
        "description": "An organization-owned secret key (`rb_sk_live_…`). Browser sessions and other key types are refused."
      },
      "replybrainSignature": {
        "type": "apiKey",
        "in": "header",
        "name": "ReplyBrain-Signature",
        "description": "`ReplyBrain-Signature: t=<unix seconds>,v2=<hex HMAC-SHA256(secret, \"v2\\n<t>\\nPOST\\n<path>\\n<connection id>\\n<raw body>\")>` and `ReplyBrain-Key-Id: <key id>`. `<path>` is the request path as sent, with `?query` if any. Accepted within five minutes, with the connection's current or previous key. `v1` signatures are refused."
      }
    },
    "parameters": {
      "Id": {
        "name": "id",
        "in": "path",
        "required": true,
        "schema": {
          "type": "string"
        }
      },
      "IdempotencyKey": {
        "name": "Idempotency-Key",
        "in": "header",
        "required": true,
        "schema": {
          "type": "string",
          "minLength": 1,
          "maxLength": 255
        },
        "description": "Unique per logical write; the same on every retry of it. Kept for the life of the organization."
      },
      "IfMatch": {
        "name": "If-Match",
        "in": "header",
        "required": true,
        "schema": {
          "type": "string"
        },
        "description": "The ETag you read. Missing is 428; changed is 412."
      },
      "Cursor": {
        "name": "cursor",
        "in": "query",
        "schema": {
          "type": "string"
        }
      },
      "Limit": {
        "name": "limit",
        "in": "query",
        "schema": {
          "type": "integer",
          "minimum": 1,
          "maximum": 100
        }
      }
    },
    "headers": {
      "Location": {
        "schema": {
          "type": "string"
        },
        "description": "The status resource to poll."
      },
      "ETag": {
        "schema": {
          "type": "string"
        }
      }
    },
    "responses": {
      "ContextQueryAccepted": {
        "description": "Recorded; poll the Location.",
        "headers": {
          "Location": {
            "$ref": "#/components/headers/Location"
          }
        },
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ContextQuery"
            }
          }
        }
      },
      "InvalidRequest": {
        "description": "invalid_request",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "Unauthenticated": {
        "description": "unauthenticated",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "PolicyDenied": {
        "description": "policy_denied: a missing scope, a key that is not an organization secret key, or a refused authority",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "NotFound": {
        "description": "not_found, also for anything of another organization or outside the key's bounds",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "Conflict": {
        "description": "approval_required, capability_unavailable, authority_mismatch, idempotency_conflict, invalid_state or send_in_progress",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "CursorExpired": {
        "description": "cursor_expired. For a list, start again without a cursor. For the event stream, read current state, then resume from `details.snapshot_cursor`, deduplicating by event id.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "StaleRevision": {
        "description": "stale_revision",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "PreconditionRequired": {
        "description": "precondition_required",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "RateLimited": {
        "description": "rate_limited, with Retry-After",
        "headers": {
          "Retry-After": {
            "schema": {
              "type": "integer"
            }
          }
        },
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "Unprocessable": {
        "description": "reason_required or unattributed",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "PayloadTooLarge": {
        "description": "invalid_request: the body is over 256 KB",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      }
    },
    "schemas": {
      "HostMessagePublish": {
        "type": "object",
        "required": [
          "capability",
          "version",
          "publication_id",
          "effect_key",
          "mode",
          "arguments"
        ],
        "properties": {
          "capability": {
            "const": "message.publish"
          },
          "version": {
            "type": "integer"
          },
          "publication_id": {
            "type": "string"
          },
          "effect_key": {
            "type": "string"
          },
          "mode": {
            "type": "string",
            "enum": [
              "publish",
              "draft"
            ],
            "description": "`draft`: hold it for your people to send. `publish`: send it now, only if `expected_source_revision` still holds."
          },
          "arguments": {
            "type": "object",
            "required": [
              "body",
              "channel",
              "origin",
              "disclosure_mode"
            ],
            "properties": {
              "body": {
                "type": "string"
              },
              "recipients": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              },
              "channel": {
                "type": "string"
              },
              "conversation_ref": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "expected_source_revision": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "origin": {
                "type": "string",
                "enum": [
                  "assistant",
                  "member"
                ],
                "description": "Who publishes: the assistant (no person sends these words) or a member, as themselves."
              },
              "disclosure_mode": {
                "type": [
                  "string",
                  "null"
                ],
                "enum": [
                  "signature_and_notice",
                  "signature",
                  "notice",
                  "none",
                  null
                ],
                "description": "How the assistant's words say an AI wrote them. `signature`: each message signed as an AI assistant. `notice`: a line saying an AI assistant is answering, before her first message in the conversation. `signature_and_notice`: both. On email, always the signature and the header `X-ReplyBrain-AI-Generated: yes`. `none` only ever comes with `mode: draft`. `null`: a teammate's own words."
              },
              "approval_id": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "policy_id": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "valid_until": {
                "type": "string",
                "format": "date-time",
                "description": "Sent only to a connection that declared it enforces it: do not send this draft after this time."
              }
            }
          }
        }
      },
      "Error": {
        "type": "object",
        "required": [
          "error"
        ],
        "properties": {
          "error": {
            "type": "object",
            "required": [
              "code",
              "message",
              "request_id",
              "retryable",
              "details"
            ],
            "properties": {
              "code": {
                "type": "string",
                "enum": [
                  "invalid_request",
                  "unauthenticated",
                  "policy_denied",
                  "not_found",
                  "approval_required",
                  "capability_unavailable",
                  "authority_mismatch",
                  "idempotency_conflict",
                  "invalid_state",
                  "cursor_expired",
                  "stale_revision",
                  "precondition_required",
                  "rate_limited",
                  "send_in_progress",
                  "reason_required",
                  "unattributed"
                ]
              },
              "message": {
                "type": "string"
              },
              "request_id": {
                "type": "string"
              },
              "retryable": {
                "type": "boolean"
              },
              "details": {
                "type": "object",
                "additionalProperties": true
              }
            }
          }
        },
        "example": {
          "error": {
            "code": "stale_revision",
            "message": "The resource changed. Read it again before retrying.",
            "request_id": "req_01HEXAMPLE",
            "retryable": false,
            "details": {
              "current_etag": "\"3f1c…\""
            }
          }
        }
      },
      "Links": {
        "type": "object",
        "required": [
          "self"
        ],
        "properties": {
          "self": {
            "type": [
              "string",
              "null"
            ]
          }
        },
        "additionalProperties": {
          "type": "string"
        }
      },
      "ResourceRef": {
        "type": "object",
        "required": [
          "connection_id",
          "type",
          "id"
        ],
        "properties": {
          "connection_id": {
            "type": "string"
          },
          "type": {
            "type": "string"
          },
          "id": {
            "type": "string"
          },
          "account_scope": {
            "type": "string"
          }
        }
      },
      "ContextQueryRequest": {
        "type": "object",
        "required": [
          "query"
        ],
        "properties": {
          "query": {
            "type": "string"
          },
          "purpose": {
            "type": "string"
          },
          "product_id": {
            "type": "string"
          },
          "principal_ref": {
            "type": "string"
          },
          "account_id": {
            "type": "string",
            "description": "A ReplyBrain account id this key may read, whose customer has a live verified proof. Your product is asked about it as its own `account_scope`. Required for a key bounded to accounts or cases. `account_ref`, and `account_scope` inside a resource ref, are refused (400)."
          },
          "case_id": {
            "type": "string",
            "description": "A case this key may read (404 otherwise). A case bound to an account is read only with that `account_id` (400 otherwise)."
          },
          "resource_refs": {
            "type": "array",
            "maxItems": 20,
            "items": {
              "type": "object",
              "required": [
                "connection_id",
                "type",
                "id"
              ],
              "properties": {
                "connection_id": {
                  "type": "string"
                },
                "type": {
                  "type": "string"
                },
                "id": {
                  "type": "string"
                }
              }
            },
            "description": "At most 20. `type` is a simple name such as `order`."
          },
          "source_filters": {
            "type": "array",
            "items": {
              "type": "string"
            }
          }
        },
        "example": {
          "query": "Why hasn't order 4521 shipped?",
          "purpose": "support",
          "account_id": "6f1c2d3e-0000-4000-8000-000000000001",
          "resource_refs": [
            {
              "connection_id": "9a8b7c6d-0000-4000-8000-000000000002",
              "type": "order",
              "id": "4521"
            }
          ]
        }
      },
      "ContextQuery": {
        "type": "object",
        "required": [
          "object",
          "id",
          "state",
          "links"
        ],
        "properties": {
          "object": {
            "const": "context_query"
          },
          "id": {
            "type": "string"
          },
          "kind": {
            "const": "context_query"
          },
          "state": {
            "type": "string",
            "enum": [
              "queued",
              "running",
              "completed",
              "failed"
            ]
          },
          "query": {
            "type": "object",
            "additionalProperties": true
          },
          "result": {
            "type": "object",
            "properties": {
              "evidence": {
                "type": "array",
                "items": {
                  "type": "object",
                  "properties": {
                    "evidence_id": {
                      "type": "string"
                    },
                    "source": {
                      "type": "string"
                    },
                    "connection_id": {
                      "type": "string"
                    },
                    "resource": {
                      "type": "object",
                      "additionalProperties": true
                    },
                    "facts": {
                      "type": "object",
                      "additionalProperties": true
                    },
                    "revision": {
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "observed_at": {
                      "type": "string",
                      "format": "date-time"
                    },
                    "basis": {
                      "type": "string"
                    }
                  }
                }
              },
              "missing": {
                "type": "array",
                "description": "Sources not read, with why: `not_found` (the host serves the topic, not the record),\n`unsupported_by_host` (the host does not serve the topic), `connection_not_found`,\n`not_a_host_connection`, `account_scope_mismatch`, `unreadable_answer`, `http_<status>`\nor a network reason.\n",
                "items": {
                  "type": "object",
                  "properties": {
                    "resource_ref": {
                      "type": "object"
                    },
                    "reason": {
                      "type": "string"
                    }
                  }
                }
              },
              "unsupported": {
                "type": "array",
                "items": {
                  "type": "object",
                  "additionalProperties": true
                }
              },
              "complete": {
                "type": "boolean"
              },
              "uncertainty": {
                "type": [
                  "string",
                  "null"
                ]
              }
            }
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "completed_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "links": {
            "$ref": "#/components/schemas/Links"
          }
        }
      },
      "CaseCreateRequest": {
        "type": "object",
        "required": [
          "requester",
          "message"
        ],
        "properties": {
          "requester": {
            "type": "object",
            "required": [
              "email"
            ],
            "properties": {
              "email": {
                "type": "string",
                "format": "email"
              }
            }
          },
          "message": {
            "type": "object",
            "required": [
              "body_text"
            ],
            "properties": {
              "body_text": {
                "type": "string"
              }
            }
          },
          "case": {
            "type": "object",
            "properties": {
              "title": {
                "type": "string"
              }
            }
          }
        },
        "example": {
          "requester": {
            "email": "ada@example.com"
          },
          "message": {
            "body_text": "I was charged twice for my Acme plan."
          },
          "case": {
            "title": "Double charge"
          }
        }
      },
      "Case": {
        "type": "object",
        "required": [
          "object",
          "id",
          "links"
        ],
        "properties": {
          "object": {
            "const": "case"
          },
          "id": {
            "type": "string"
          },
          "title": {
            "type": [
              "string",
              "null"
            ]
          },
          "product_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "account_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "held_by_human": {
            "type": "boolean"
          },
          "conversations": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "id": {
                  "type": "string"
                },
                "authority": {
                  "type": "string",
                  "enum": [
                    "managed",
                    "connected"
                  ]
                },
                "channel": {
                  "type": "string"
                },
                "connection_id": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "revision": {
                  "type": "integer"
                }
              }
            }
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time"
          },
          "links": {
            "$ref": "#/components/schemas/Links"
          }
        }
      },
      "CasePage": {
        "$ref": "#/components/schemas/PageOfCases"
      },
      "PageOfCases": {
        "type": "object",
        "required": [
          "data",
          "next_cursor"
        ],
        "properties": {
          "data": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Case"
            }
          },
          "next_cursor": {
            "type": [
              "string",
              "null"
            ]
          }
        }
      },
      "Message": {
        "type": "object",
        "required": [
          "object",
          "id",
          "direction",
          "visibility"
        ],
        "properties": {
          "object": {
            "const": "message"
          },
          "id": {
            "type": "string"
          },
          "conversation_id": {
            "type": "string"
          },
          "direction": {
            "type": "string",
            "enum": [
              "inbound",
              "outbound"
            ]
          },
          "visibility": {
            "type": "string",
            "enum": [
              "customer",
              "internal"
            ]
          },
          "author_principal_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "body_text": {
            "type": [
              "string",
              "null"
            ]
          },
          "body_revoked": {
            "type": "boolean"
          },
          "occurred_at": {
            "type": "string",
            "format": "date-time"
          },
          "revision": {
            "type": "integer"
          },
          "links": {
            "$ref": "#/components/schemas/Links"
          }
        }
      },
      "MessagePage": {
        "type": "object",
        "required": [
          "data",
          "next_cursor"
        ],
        "properties": {
          "data": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Message"
            }
          },
          "next_cursor": {
            "type": [
              "string",
              "null"
            ]
          }
        }
      },
      "Need": {
        "type": "object",
        "required": [
          "object",
          "id",
          "case_id",
          "desired_outcome",
          "state"
        ],
        "properties": {
          "object": {
            "const": "need"
          },
          "id": {
            "type": "string"
          },
          "case_id": {
            "type": "string"
          },
          "message_ref_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "desired_outcome": {
            "type": "string"
          },
          "state": {
            "type": "string",
            "enum": [
              "identified",
              "planned",
              "in_work",
              "satisfied",
              "declined",
              "unknown"
            ]
          },
          "affected_resources": {
            "type": "array"
          },
          "decided_by_principal_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time"
          },
          "links": {
            "$ref": "#/components/schemas/Links"
          }
        }
      },
      "SourceEventRequest": {
        "type": "object",
        "required": [
          "source_object",
          "occurred_at",
          "kind"
        ],
        "description": "An event about one conversation in your product. Identity is `source_event_id` (or, without one, `source_object` + `source_revision` + `kind`); a body with neither is refused (400).",
        "properties": {
          "source_event_id": {
            "type": "string",
            "description": "Unique per event. Deduplication key: the same id again changes nothing."
          },
          "source_object": {
            "type": "object",
            "required": [
              "type",
              "id"
            ],
            "description": "The conversation, e.g. `{ type: ticket, id: SUP-1 }`. One conversation per (type, id).",
            "properties": {
              "type": {
                "type": "string"
              },
              "id": {
                "type": "string"
              }
            }
          },
          "source_revision": {
            "type": "string"
          },
          "occurred_at": {
            "type": "string",
            "format": "date-time",
            "description": "When it happened in your product (ISO 8601)."
          },
          "kind": {
            "type": "string",
            "description": "`conversation.message_added`, `conversation.opened`, `conversation.reopened`, `conversation.closed`, `conversation.assigned`, or your own.",
            "examples": [
              "conversation.message_added"
            ]
          },
          "message": {
            "type": "object",
            "description": "The message, when the event carries one. Only `visibility: customer` messages are read; without `visibility` the message counts as internal.",
            "properties": {
              "id": {
                "type": "string",
                "description": "Your id for the message. Without one, the event's `source_event_id` is used."
              },
              "visibility": {
                "type": "string",
                "enum": [
                  "customer",
                  "internal"
                ]
              },
              "direction": {
                "type": "string",
                "enum": [
                  "inbound",
                  "outbound"
                ],
                "description": "`inbound` from the customer (default), `outbound` from your team."
              },
              "body_text": {
                "type": "string"
              },
              "channel": {
                "type": "string",
                "enum": [
                  "email",
                  "in_app",
                  "whatsapp",
                  "sms",
                  "phone",
                  "api"
                ],
                "description": "Where the customer wrote. Set when the conversation is first seen; without it (or with another value) the conversation is filed under `api`."
              },
              "author": {
                "type": "string",
                "enum": [
                  "requester",
                  "agent"
                ],
                "description": "Who wrote it."
              },
              "author_name": {
                "type": "string",
                "maxLength": 60,
                "description": "For `author: agent` on an outbound message: the teammate's name as the customer reads it."
              },
              "author_email": {
                "type": "string",
                "format": "email",
                "description": "For `author: agent` on an outbound message: the address that teammate signs in with. When it is a member of your ReplyBrain team's, the reply is shown as that member's."
              }
            }
          },
          "requester": {
            "type": "object",
            "description": "The customer the conversation is with. A signed event proves where it came from, not who the customer is: everything here is your product's word.",
            "properties": {
              "ref": {
                "type": "string",
                "description": "Your stable id for the customer. Required for anything below to be used."
              },
              "account_scope": {
                "type": "string",
                "description": "Your id for their account: what ReplyBrain sends back when it asks for their facts."
              },
              "name": {
                "type": "string"
              },
              "email": {
                "type": "string",
                "description": "Kept as an unverified address; never one ReplyBrain writes to."
              },
              "phone": {
                "type": "string",
                "description": "E.164, e.g. +34600000000."
              },
              "avatar_url": {
                "type": "string",
                "format": "uri",
                "maxLength": 2048,
                "description": "Where you keep their picture: an https address the console draws beside their name. Stored as an address, never fetched; an event without it removes the picture."
              },
              "session": {
                "type": "object",
                "description": "Only when your server verified the customer's signed-in session as they posted this inbound message.",
                "properties": {
                  "verified": {
                    "const": true
                  },
                  "method": {
                    "type": "string"
                  },
                  "provenance": {
                    "type": "string"
                  },
                  "verified_at": {
                    "type": "string",
                    "format": "date-time"
                  },
                  "expires_at": {
                    "type": "string",
                    "format": "date-time"
                  }
                }
              }
            }
          },
          "assignee": {
            "type": "object",
            "description": "Who on your team holds the conversation now: `{ name, email }`, or `{}` when nobody does. Leave the key out to say nothing.",
            "properties": {
              "name": {
                "type": "string"
              },
              "email": {
                "type": "string"
              }
            }
          },
          "caused_by_action_id": {
            "type": [
              "string",
              "null"
            ],
            "description": "When this event echoes ReplyBrain's own work: the action id or the `publication_id` it sent you."
          }
        },
        "example": {
          "source_event_id": "evt_7f3a",
          "source_object": {
            "type": "ticket",
            "id": "SUP-1042"
          },
          "occurred_at": "2026-11-12T09:30:00Z",
          "kind": "conversation.message_added",
          "message": {
            "id": "msg_88",
            "visibility": "customer",
            "direction": "inbound",
            "channel": "in_app",
            "author": "requester",
            "body_text": "My export has been stuck since this morning."
          },
          "requester": {
            "ref": "user_42",
            "account_scope": "acct_7",
            "name": "Ada",
            "email": "ada@example.com"
          },
          "assignee": {}
        }
      },
      "SourceEvent": {
        "type": "object",
        "properties": {
          "object": {
            "const": "source_event"
          },
          "id": {
            "type": "string"
          },
          "connection_id": {
            "type": "string"
          },
          "source_event_id": {
            "type": "string"
          },
          "state": {
            "type": "string",
            "enum": [
              "recorded",
              "duplicate"
            ]
          },
          "links": {
            "type": "object",
            "additionalProperties": {
              "type": "string"
            }
          }
        }
      },
      "ConnectionStatus": {
        "type": "object",
        "properties": {
          "object": {
            "const": "connection_status"
          },
          "id": {
            "type": "string"
          },
          "kind": {
            "type": "string"
          },
          "system": {
            "type": "string"
          },
          "product_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "sync": {
            "type": "string",
            "enum": [
              "fresh",
              "stale",
              "broken"
            ]
          },
          "since": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "reason": {
            "type": [
              "string",
              "null"
            ]
          },
          "grants": {
            "type": "string",
            "enum": [
              "valid",
              "expiring",
              "revoked"
            ]
          },
          "credential_expires_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "write": {
            "type": "string",
            "enum": [
              "available",
              "drafts_only",
              "unavailable"
            ]
          },
          "operations": {
            "type": "object",
            "additionalProperties": true
          },
          "links": {
            "type": "object",
            "additionalProperties": {
              "type": "string"
            }
          }
        }
      },
      "Run": {
        "type": "object",
        "required": [
          "object",
          "id",
          "state"
        ],
        "properties": {
          "object": {
            "const": "run"
          },
          "id": {
            "type": "string"
          },
          "state": {
            "type": "string",
            "enum": [
              "queued",
              "running",
              "waiting",
              "completed",
              "failed",
              "cancelled"
            ]
          },
          "case_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "need_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "objective": {
            "type": [
              "string",
              "null"
            ]
          },
          "planner": {
            "type": [
              "string",
              "null"
            ],
            "enum": [
              "replybrain",
              "caller",
              null
            ]
          },
          "budget": {
            "type": "object",
            "additionalProperties": true
          },
          "deadline_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "checkpoints": {
            "type": "array",
            "items": {
              "type": "object",
              "additionalProperties": true
            }
          },
          "plans": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "id": {
                  "type": "string"
                },
                "revision": {
                  "type": "integer"
                },
                "links": {
                  "$ref": "#/components/schemas/Links"
                }
              }
            }
          },
          "work": {
            "type": "object",
            "properties": {
              "running": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              },
              "committed": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              },
              "cancelled": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              }
            }
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time"
          },
          "links": {
            "$ref": "#/components/schemas/Links"
          }
        }
      },
      "PlanRequest": {
        "type": "object",
        "required": [
          "base_revision",
          "steps"
        ],
        "properties": {
          "base_revision": {
            "type": "integer",
            "minimum": 0
          },
          "rationale": {
            "type": "string"
          },
          "desired_outcome": {
            "type": "string"
          },
          "steps": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "key",
                "capability",
                "version",
                "arguments"
              ],
              "properties": {
                "key": {
                  "type": "string"
                },
                "capability": {
                  "type": "string"
                },
                "version": {
                  "type": "integer",
                  "minimum": 1
                },
                "arguments": {
                  "type": "object",
                  "additionalProperties": true
                },
                "scope": {
                  "type": "object",
                  "additionalProperties": true
                },
                "depends_on": {
                  "type": "array",
                  "items": {
                    "oneOf": [
                      {
                        "type": "string"
                      },
                      {
                        "type": "object",
                        "required": [
                          "step"
                        ],
                        "properties": {
                          "step": {
                            "type": "string"
                          },
                          "predicate": {
                            "const": "succeeded"
                          }
                        }
                      }
                    ]
                  }
                }
              }
            }
          }
        }
      },
      "Plan": {
        "type": "object",
        "required": [
          "object",
          "id",
          "revision",
          "actions"
        ],
        "properties": {
          "object": {
            "const": "plan"
          },
          "id": {
            "type": "string"
          },
          "run_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "case_id": {
            "type": "string"
          },
          "revision": {
            "type": "integer"
          },
          "latest": {
            "type": "boolean"
          },
          "proposed_by_principal_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "rationale": {
            "type": [
              "string",
              "null"
            ]
          },
          "rejected_steps": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "step": {
                  "type": "object"
                },
                "reasons": {
                  "type": "array",
                  "items": {
                    "type": "string"
                  }
                }
              }
            }
          },
          "actions": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Action"
            }
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "links": {
            "$ref": "#/components/schemas/Links"
          }
        }
      },
      "Action": {
        "type": "object",
        "required": [
          "object",
          "id",
          "state",
          "revision",
          "arguments_digest"
        ],
        "properties": {
          "object": {
            "const": "action"
          },
          "id": {
            "type": "string"
          },
          "plan_id": {
            "type": "string"
          },
          "key": {
            "type": [
              "string",
              "null"
            ]
          },
          "position": {
            "type": [
              "integer",
              "null"
            ]
          },
          "capability": {
            "type": "object",
            "properties": {
              "name": {
                "type": "string"
              },
              "version": {
                "type": "integer"
              }
            }
          },
          "effect_class": {
            "type": "string"
          },
          "state": {
            "type": "string",
            "enum": [
              "proposed",
              "awaiting_approval",
              "ready",
              "running",
              "waiting_external",
              "verifying",
              "succeeded",
              "failed",
              "outcome_unknown",
              "cancelled",
              "superseded"
            ]
          },
          "state_reason": {
            "type": [
              "string",
              "null"
            ]
          },
          "revision": {
            "type": "integer"
          },
          "arguments": {
            "type": "object",
            "additionalProperties": true
          },
          "arguments_digest": {
            "type": "string"
          },
          "effect_key": {
            "type": "string"
          },
          "prerequisites": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "needs_approval": {
            "type": "boolean"
          },
          "approved": {
            "type": "boolean"
          },
          "verified": {
            "type": "boolean"
          },
          "dispatch": {
            "type": [
              "object",
              "null"
            ],
            "properties": {
              "state": {
                "type": "string",
                "enum": [
                  "pending",
                  "claimed",
                  "completed",
                  "failed",
                  "unknown"
                ]
              },
              "requested_at": {
                "type": "string",
                "format": "date-time"
              }
            }
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time"
          },
          "links": {
            "$ref": "#/components/schemas/Links"
          }
        }
      },
      "Approval": {
        "type": "object",
        "required": [
          "object",
          "id",
          "action_id",
          "action_revision",
          "arguments_digest",
          "expires_at"
        ],
        "properties": {
          "object": {
            "const": "approval"
          },
          "id": {
            "type": "string"
          },
          "action_id": {
            "type": "string"
          },
          "action_revision": {
            "type": "integer"
          },
          "arguments_digest": {
            "type": "string"
          },
          "approver_principal_id": {
            "type": "string"
          },
          "policy_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "expires_at": {
            "type": "string",
            "format": "date-time"
          },
          "invalidated_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "action": {
            "$ref": "#/components/schemas/Action"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "links": {
            "$ref": "#/components/schemas/Links"
          }
        }
      },
      "Commitment": {
        "type": "object",
        "required": [
          "object",
          "id",
          "case_id",
          "kind",
          "wording",
          "state"
        ],
        "properties": {
          "object": {
            "const": "commitment"
          },
          "id": {
            "type": "string"
          },
          "case_id": {
            "type": "string"
          },
          "kind": {
            "type": "string"
          },
          "wording": {
            "type": "string"
          },
          "state": {
            "type": "string",
            "enum": [
              "proposed",
              "reserved",
              "communicated",
              "fulfilled",
              "withdrawn",
              "superseded",
              "unfulfillable"
            ]
          },
          "owner_action_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "owner_principal_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "conditions": {
            "type": "array",
            "items": {
              "type": "object",
              "additionalProperties": true
            }
          },
          "review_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "due_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "communicated_by_publication_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time"
          },
          "links": {
            "$ref": "#/components/schemas/Links"
          }
        }
      },
      "Capability": {
        "type": "object",
        "required": [
          "object",
          "name",
          "version",
          "effect_class"
        ],
        "properties": {
          "object": {
            "const": "capability"
          },
          "name": {
            "type": "string"
          },
          "version": {
            "type": "integer"
          },
          "effect_class": {
            "type": "string"
          },
          "executor": {
            "type": "string"
          },
          "verifier_predicate": {
            "type": [
              "string",
              "null"
            ]
          },
          "connection_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "input_schema": {
            "type": [
              "object",
              "null"
            ],
            "additionalProperties": true,
            "description": "The capability's arguments: a strict, closed subset of JSON Schema in which every string, integer, number or boolean declares `x-resource` (the kind of thing it identifies, such as `account` or `order`, or `none`)."
          },
          "approval": {
            "type": "string"
          },
          "requires_account_proof": {
            "type": "boolean"
          },
          "links": {
            "$ref": "#/components/schemas/Links"
          }
        }
      },
      "CapabilityPage": {
        "type": "object",
        "required": [
          "data",
          "next_cursor"
        ],
        "properties": {
          "data": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Capability"
            }
          },
          "next_cursor": {
            "type": [
              "string",
              "null"
            ]
          }
        }
      },
      "Event": {
        "type": "object",
        "required": [
          "id",
          "type",
          "occurred_at"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "type": {
            "type": "string",
            "examples": [
              "need.identified",
              "plan.activated",
              "action.dispatched",
              "source.received"
            ]
          },
          "occurred_at": {
            "type": "string",
            "format": "date-time"
          },
          "object": {
            "type": [
              "object",
              "null"
            ],
            "properties": {
              "type": {
                "type": "string"
              },
              "id": {
                "type": "string"
              }
            }
          },
          "revision": {
            "type": [
              "integer",
              "null"
            ]
          },
          "causation_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "correlation_id": {
            "type": "string"
          },
          "data": {
            "type": "object",
            "additionalProperties": true
          }
        }
      },
      "Wait": {
        "type": "object",
        "required": [
          "object",
          "id",
          "kind",
          "state",
          "instruction"
        ],
        "properties": {
          "object": {
            "const": "wait"
          },
          "id": {
            "type": "string"
          },
          "kind": {
            "type": "string",
            "enum": [
              "provider_confirmation",
              "registration_invalid",
              "late_cost"
            ]
          },
          "state": {
            "type": "string",
            "enum": [
              "open",
              "resolved"
            ]
          },
          "instruction": {
            "type": "string"
          },
          "reason": {
            "type": "string"
          },
          "action_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "capability": {
            "type": "object",
            "properties": {
              "name": {
                "type": "string"
              },
              "version": {
                "type": "integer"
              }
            }
          },
          "problems": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "actual_cents": {
            "type": "integer"
          },
          "captured_cents": {
            "type": "integer"
          },
          "effect_key": {
            "type": "string"
          },
          "provider_refs": {
            "type": "object",
            "additionalProperties": true
          },
          "reconcile": {
            "type": "string"
          },
          "opened_at": {
            "type": "string",
            "format": "date-time"
          },
          "deadline_at": {
            "type": "string",
            "format": "date-time"
          },
          "resolved_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "links": {
            "$ref": "#/components/schemas/Links"
          }
        }
      },
      "WaitPage": {
        "type": "object",
        "required": [
          "data",
          "next_cursor"
        ],
        "properties": {
          "data": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Wait"
            }
          },
          "next_cursor": {
            "type": [
              "string",
              "null"
            ]
          }
        }
      },
      "EventPage": {
        "type": "object",
        "required": [
          "data",
          "next_cursor"
        ],
        "properties": {
          "data": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Event"
            }
          },
          "next_cursor": {
            "type": "string"
          }
        }
      }
    }
  }
}
