{
  "openapi": "3.1.0",
  "info": {
    "title": "JotDoc document API",
    "version": "1.0.0",
    "summary": "Cloud document copies, comments and revision proposals.",
    "description": "The HTTP surface behind JotDoc's MCP server: a cloud copy of a document, the comment threads anchored to quotes in it, and revision proposals that a person accepts or rejects.\n\nTwo rules hold everywhere in this API, and they are enforced by the server rather than asked for in a prompt:\n\n1. The document body is written by its author. A connection that is not the author can read a shared document, comment on it and propose a revision, but cannot write text into it. Proposals come back as threads with `intent: \"rewrite\"` and wait for a person.\n2. Permissions live on the document, not on the credential. A document is either shared or not shared; there is no per-connection scope and no read-only tier.\n\nThe same endpoints are what the JotDoc editor calls. Most integrations should use https://mcp.jotdoc.net/mcp instead — the tools there are these calls with the bookkeeping done for you. This document describes that contract for clients that need to talk HTTP directly.",
    "contact": {
      "name": "JotDoc",
      "url": "https://jotdoc.net/docs/reference/api/",
      "email": "hello@jotdoc.net"
    },
    "license": {
      "name": "Proprietary",
      "identifier": "LicenseRef-JotDoc-Proprietary"
    }
  },
  "servers": [
    {
      "url": "https://api.jotdoc.net",
      "description": "Production"
    }
  ],
  "security": [
    {
      "oauth2": [
        "mcp:account:read"
      ]
    }
  ],
  "tags": [
    {
      "name": "Documents",
      "description": "Cloud copies of a document. Created when a document is handed to an AI connection or a review link."
    },
    {
      "name": "Threads",
      "description": "Comments and revision proposals, each anchored to a verbatim quote of the text it was written on."
    },
    {
      "name": "Delivery",
      "description": "Exporting the current text."
    },
    {
      "name": "Status",
      "description": "Liveness and build identity."
    }
  ],
  "paths": {
    "/healthz": {
      "get": {
        "operationId": "getHealth",
        "tags": [
          "Status"
        ],
        "summary": "Liveness probe and the release actually running",
        "description": "Returns 200 whenever the process is up. `build` is the release SHA injected at deploy time; compare it before assuming a fix is live.",
        "security": [],
        "responses": {
          "200": {
            "description": "The service is up.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "ok"
                  ],
                  "properties": {
                    "ok": {
                      "type": "boolean",
                      "const": true
                    },
                    "build": {
                      "type": [
                        "string",
                        "null"
                      ],
                      "description": "Release SHA, or null when the process was started without MINDMAX_BUILD.",
                      "examples": [
                        "8cc895fd"
                      ]
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/v1/documents": {
      "get": {
        "operationId": "listDocuments",
        "tags": [
          "Documents"
        ],
        "summary": "List the documents you own",
        "description": "Documents shared in by someone else are never listed here — they are reachable by id only. Not a full-text search.",
        "parameters": [
          {
            "name": "query",
            "in": "query",
            "required": false,
            "description": "Title filter.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "sort",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "modified_desc",
                "created_desc"
              ],
              "default": "modified_desc"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 50
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Your cloud copies, newest first by default.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "documents"
                  ],
                  "properties": {
                    "documents": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Document"
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Error"
          }
        }
      },
      "post": {
        "operationId": "putDocument",
        "tags": [
          "Documents"
        ],
        "summary": "Create or update a cloud copy",
        "description": "Idempotent on `local_id`: the same local id updates the same cloud copy instead of creating a second one. Requires the write scope.\n\nThe cloud copy is a read-only mirror. It is what an AI connection reads; the author's browser stays the only writer of the text.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "title",
                  "content"
                ],
                "properties": {
                  "title": {
                    "type": "string",
                    "minLength": 1
                  },
                  "content": {
                    "type": "string",
                    "description": "The whole document as Markdown."
                  },
                  "local_id": {
                    "type": "string",
                    "description": "The id the editor uses locally. Pass it once and the cloud copy keeps the same identity across pushes."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The cloud copy after the push.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/Document"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "ok": {
                          "type": "boolean",
                          "const": true
                        },
                        "election_key": {
                          "$ref": "#/components/schemas/ElectionKey"
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "description": "`cloud_doc_limit` (the plan's cloud-document cap is used up, body carries `limit` and `used`), `product_mismatch`, or `insufficient_scope`.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "`document_id_conflict` — that id already belongs to another document. The client must pick a new id or claim the existing copy; it must not create a second copy under the same id.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "oauth2": [
              "mcp:account:write"
            ]
          }
        ]
      }
    },
    "/v1/documents/temporary": {
      "post": {
        "operationId": "createTemporaryDocument",
        "tags": [
          "Documents"
        ],
        "summary": "Create a temporary cloud copy without an account",
        "description": "The inbox for a first draft an AI creates before any person is involved. The copy is readable by anyone holding its link, expires after `ttl_seconds` (24 hours by default), and has no author yet: the first person to open it in the editor takes it over, after which it can be claimed into an account.\n\nTemporary copies do not count against a plan's cloud-document limit. Rate limited per IP.",
        "security": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "title",
                  "content"
                ],
                "properties": {
                  "title": {
                    "type": "string",
                    "minLength": 1
                  },
                  "content": {
                    "type": "string",
                    "minLength": 1,
                    "description": "The whole body. There is no second call to fill it in later."
                  },
                  "ttl_seconds": {
                    "type": "integer",
                    "minimum": 60,
                    "default": 86400
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The temporary copy.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "ok",
                    "document_id"
                  ],
                  "properties": {
                    "ok": {
                      "type": "boolean",
                      "const": true
                    },
                    "document_id": {
                      "type": "string",
                      "examples": [
                        "doc_tmp_tq3cv0ovakgp"
                      ]
                    },
                    "version": {
                      "type": "integer"
                    },
                    "phase": {
                      "type": "string",
                      "enum": [
                        "draft",
                        "working"
                      ]
                    },
                    "taken_over": {
                      "type": "boolean"
                    },
                    "pending_proposals_count": {
                      "type": "integer"
                    },
                    "temporary": {
                      "type": "boolean",
                      "const": true
                    },
                    "expires_at": {
                      "type": "string",
                      "format": "date-time",
                      "description": "When this cloud copy disappears. The text in anyone's editor is unaffected."
                    },
                    "url": {
                      "type": "string",
                      "format": "uri"
                    },
                    "election_key": {
                      "$ref": "#/components/schemas/ElectionKey"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/v1/documents/{id}": {
      "get": {
        "operationId": "getDocument",
        "tags": [
          "Documents"
        ],
        "summary": "Read a cloud copy",
        "description": "Returns the metadata plus the current Markdown body. `access` says what this caller may do next: `owner` can write, `commenter` can comment and propose. A temporary copy is readable by anyone holding its id.\n\nWhen the author's browser has unsynced edits, the server briefly waits for the mirror so a reader does not get a stale body; `sync_pending` and `stale` say how fresh it is.",
        "parameters": [
          {
            "$ref": "#/components/parameters/DocumentId"
          }
        ],
        "responses": {
          "200": {
            "description": "The cloud copy.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/Document"
                    },
                    {
                      "type": "object",
                      "required": [
                        "content"
                      ],
                      "properties": {
                        "content": {
                          "type": "string",
                          "description": "The document as Markdown, as of `version`."
                        },
                        "election_key": {
                          "$ref": "#/components/schemas/ElectionKey"
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "404": {
            "description": "`document_not_found` — no such document, or it is not shared with this caller. The two cases are deliberately indistinguishable.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "410": {
            "description": "`document_expired` — a temporary copy past its TTL.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "delete": {
        "operationId": "deleteDocument",
        "tags": [
          "Documents"
        ],
        "summary": "Delete the cloud copy",
        "description": "Deletes the cloud copy and revokes every grant on it. The author's local text is untouched — the copy is a mirror, not the original. Idempotent: deleting an already deleted copy still returns 200 so an offline queue stops retrying.",
        "parameters": [
          {
            "$ref": "#/components/parameters/DocumentId"
          }
        ],
        "responses": {
          "200": {
            "description": "Deleted, or already deleted.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": {
                      "type": "boolean",
                      "const": true
                    },
                    "status": {
                      "type": "string",
                      "const": "deleted"
                    },
                    "already": {
                      "type": "boolean",
                      "description": "Present when the copy had already been deleted."
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/v1/documents/{id}/share": {
      "put": {
        "operationId": "setDocumentShare",
        "tags": [
          "Documents"
        ],
        "summary": "Turn sharing on or off",
        "description": "Two states only. `true` means any connection holding this id can read the document, comment on it and propose revisions; `false` means everyone except the author gets 404 from then on. Written text stays with the author either way, and turning sharing off does not delete the copy.\n\nAuthor only, and idempotent: setting the state it is already in succeeds without changing `since`. A temporary copy must be claimed first (`share_requires_claim`).",
        "parameters": [
          {
            "$ref": "#/components/parameters/DocumentId"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "shared"
                ],
                "properties": {
                  "shared": {
                    "type": "boolean"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The state after the call.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": {
                      "type": "boolean",
                      "const": true
                    },
                    "shared": {
                      "type": "boolean"
                    },
                    "url": {
                      "type": "string",
                      "format": "uri"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "description": "`share_requires_claim` (temporary copy) or `author_only`.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/v1/documents/{id}/mirror": {
      "patch": {
        "operationId": "appendToDocument",
        "tags": [
          "Documents"
        ],
        "summary": "Append text to the end of the document",
        "description": "Additive only; `mode` must be `append`. Two outcomes:\n\n- On a draft the author owns and nobody has opened, the text is appended and the body version goes up by one.\n- Everywhere else — a temporary copy, or a document the author has opened — the append becomes a revision proposal (`intent: \"rewrite\"`, `proposal: \"append\"`) and waits for a person. The response then carries `thread_id` and `proposal_reason` instead of `version`.\n\nThis is the tool behind `append_to_document`.",
        "parameters": [
          {
            "$ref": "#/components/parameters/DocumentId"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "content",
                  "mode"
                ],
                "properties": {
                  "content": {
                    "type": "string",
                    "minLength": 1
                  },
                  "mode": {
                    "type": "string",
                    "const": "append"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Appended, or accepted as a proposal.",
            "content": {
              "application/json": {
                "schema": {
                  "oneOf": [
                    {
                      "title": "Appended",
                      "type": "object",
                      "required": [
                        "ok",
                        "document_id",
                        "mode",
                        "version"
                      ],
                      "properties": {
                        "ok": {
                          "type": "boolean",
                          "const": true
                        },
                        "document_id": {
                          "type": "string"
                        },
                        "mode": {
                          "type": "string",
                          "const": "append"
                        },
                        "version": {
                          "type": "integer",
                          "description": "The new body version."
                        },
                        "ui_refreshed": {
                          "type": "boolean"
                        }
                      }
                    },
                    {
                      "title": "Proposed",
                      "type": "object",
                      "required": [
                        "ok",
                        "document_id",
                        "thread_id",
                        "proposal_reason"
                      ],
                      "properties": {
                        "ok": {
                          "type": "boolean",
                          "const": true
                        },
                        "document_id": {
                          "type": "string"
                        },
                        "mode": {
                          "type": "string",
                          "const": "append"
                        },
                        "thread_id": {
                          "type": "string",
                          "description": "Read it back with GET /v1/documents/{id}/threads/{tid}."
                        },
                        "base_version": {
                          "type": "integer"
                        },
                        "proposal_reason": {
                          "type": "string",
                          "enum": [
                            "temporary",
                            "working"
                          ],
                          "description": "`temporary` — the copy has no author yet. `working` — the author has opened the text."
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "400": {
            "description": "`invalid_body`, or `append_only_proposals` when `mode` is not `append`.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "`thread_limit` — this document already has the maximum number of open threads.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "description": "`takeover_required` — the author took over between the read and the write; retry as a proposal.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "oauth2": [
              "mcp:account:write"
            ]
          }
        ]
      }
    },
    "/v1/documents/{id}/threads": {
      "get": {
        "operationId": "listThreads",
        "tags": [
          "Threads"
        ],
        "summary": "Every comment thread on the document",
        "description": "Includes each thread's quoted anchor, all messages, its intent, its status, and whose turn it is. `mine` is present when the caller has an identity — it says whether this thread's latest move was theirs.",
        "parameters": [
          {
            "$ref": "#/components/parameters/DocumentId"
          }
        ],
        "responses": {
          "200": {
            "description": "The threads, oldest first.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "threads"
                  ],
                  "properties": {
                    "threads": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Thread"
                      }
                    }
                  }
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/Error"
          }
        }
      },
      "post": {
        "operationId": "createThread",
        "tags": [
          "Threads"
        ],
        "summary": "Comment on a passage, or propose a rewrite of it",
        "description": "The anchor is a verbatim quote of the text being talked about — the whole block is fine — not a paragraph number. `intent: \"rewrite\"` carries the proposed replacement in `suggestion` and is available to AI connections only; the author's own pen is the editor.\n\nIdempotent on `client_request_id`: a retried request returns the thread that already exists instead of creating a second one.",
        "parameters": [
          {
            "$ref": "#/components/parameters/DocumentId"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "anchor",
                  "body"
                ],
                "properties": {
                  "anchor": {
                    "$ref": "#/components/schemas/Anchor"
                  },
                  "body": {
                    "type": "string",
                    "minLength": 1,
                    "description": "Why the change, or what the comment is about. Required even for a rewrite."
                  },
                  "intent": {
                    "type": "string",
                    "enum": [
                      "note",
                      "question",
                      "rewrite",
                      "fact-check",
                      "source-needed"
                    ],
                    "default": "note"
                  },
                  "suggestion": {
                    "type": "string",
                    "description": "The replacement text. Required in practice for `intent: \"rewrite\"`; ignored otherwise."
                  },
                  "base_version": {
                    "type": "integer",
                    "minimum": 1,
                    "description": "The body version this proposal was written against. Defaults to the current version."
                  },
                  "client_request_id": {
                    "type": "string",
                    "description": "Idempotency key for a retried create."
                  },
                  "reviewer_name": {
                    "type": "string",
                    "description": "How this caller should be signed in the thread. An AI cannot sign as the author."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "The thread that was created, or the one whose `client_request_id` matched.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": {
                      "type": "boolean",
                      "const": true
                    },
                    "thread_id": {
                      "type": "string"
                    },
                    "thread": {
                      "$ref": "#/components/schemas/Thread"
                    },
                    "edit_request": {
                      "$ref": "#/components/schemas/Thread"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "`invalid_body` — the message names the missing field.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "`reviewer_role_requires_agent` (an account claimed a reviewer-only move), `thread_limit`, or `insufficient_scope`.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/Error"
          }
        },
        "security": [
          {
            "oauth2": [
              "mcp:account:write"
            ]
          }
        ]
      }
    },
    "/v1/documents/{id}/threads/{tid}/messages": {
      "post": {
        "operationId": "replyToThread",
        "tags": [
          "Threads"
        ],
        "summary": "Reply inside a thread",
        "description": "Adds one message signed with this caller's identity and hands the turn back. Idempotent on `client_request_id`.",
        "parameters": [
          {
            "$ref": "#/components/parameters/DocumentId"
          },
          {
            "name": "tid",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "body"
                ],
                "properties": {
                  "body": {
                    "type": "string",
                    "minLength": 1
                  },
                  "client_request_id": {
                    "type": "string"
                  },
                  "name": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The thread with the new message appended.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "thread": {
                      "$ref": "#/components/schemas/Thread"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          }
        },
        "security": [
          {
            "oauth2": [
              "mcp:account:write"
            ]
          }
        ]
      }
    },
    "/v1/documents/{id}/export": {
      "post": {
        "operationId": "exportDocument",
        "tags": [
          "Delivery"
        ],
        "summary": "Export the current text",
        "description": "Serialises the body as it stands. Markdown, plain text and HTML are the text in another form; DOCX and PDF are rendered from the same Markdown. Comments and suggestions are never part of an export — only accepted text is.\n\nThe response is the file itself, with `Content-Disposition: attachment`.",
        "parameters": [
          {
            "$ref": "#/components/parameters/DocumentId"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "format"
                ],
                "properties": {
                  "format": {
                    "type": "string",
                    "enum": [
                      "markdown",
                      "txt",
                      "html",
                      "docx",
                      "pdf"
                    ],
                    "default": "markdown"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The exported file.",
            "content": {
              "text/markdown": {
                "schema": {
                  "type": "string"
                }
              },
              "text/plain": {
                "schema": {
                  "type": "string"
                }
              },
              "text/html": {
                "schema": {
                  "type": "string"
                }
              },
              "application/vnd.openxmlformats-officedocument.wordprocessingml.document": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              },
              "application/pdf": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              }
            }
          },
          "400": {
            "description": "`unsupported_export_format`.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "oauth2": {
        "type": "oauth2",
        "description": "OAuth 2.1 with PKCE. The authorization server is api.mindmax.me; its metadata is at https://api.mindmax.me/.well-known/oauth-authorization-server. Clients can register themselves at /oauth/register. `mcp:account:read` covers reading, threads and export; `mcp:account:write` is also needed to create copies, append and comment.",
        "flows": {
          "authorizationCode": {
            "authorizationUrl": "https://api.mindmax.me/oauth/authorize",
            "tokenUrl": "https://api.mindmax.me/oauth/token",
            "scopes": {
              "mcp:account:read": "Read documents shared with this connection, their threads, and export.",
              "mcp:account:write": "Create and update cloud copies, append, comment and propose revisions."
            }
          }
        }
      }
    },
    "parameters": {
      "DocumentId": {
        "name": "id",
        "in": "path",
        "required": true,
        "description": "The cloud copy id (`doc_…`), or the editor's local id for the same document.",
        "schema": {
          "type": "string"
        }
      }
    },
    "responses": {
      "Error": {
        "description": "The request was refused. Read `error`, not the prose: codes are stable, descriptions are not.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "required": [
          "error"
        ],
        "properties": {
          "error": {
            "type": "string",
            "description": "Stable machine code, e.g. `invalid_body`, `document_not_found`, `cloud_doc_limit`, `insufficient_scope`, `thread_limit`, `mirror_version_conflict`.",
            "examples": [
              "document_not_found"
            ]
          },
          "error_description": {
            "type": "string",
            "description": "Human-readable detail. Do not parse it."
          },
          "retry_after": {
            "type": "integer",
            "description": "Seconds, on 429."
          }
        },
        "additionalProperties": true
      },
      "ElectionKey": {
        "type": "object",
        "description": "Server-issued identity for this version of the copy. Send it back with writes instead of inventing one.",
        "properties": {
          "doc_id": {
            "type": "string"
          },
          "version": {
            "type": "integer"
          },
          "seq": {
            "type": "integer"
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "Document": {
        "type": "object",
        "required": [
          "document_id",
          "title",
          "version",
          "access"
        ],
        "properties": {
          "document_id": {
            "type": "string"
          },
          "local_id": {
            "type": "string"
          },
          "title": {
            "type": "string"
          },
          "bytes": {
            "type": "integer",
            "description": "Size of the stored Markdown in UTF-8 bytes."
          },
          "version": {
            "type": "integer",
            "description": "Body version. Goes up on every author sync; proposals are written against it."
          },
          "phase": {
            "type": "string",
            "enum": [
              "draft",
              "working"
            ],
            "description": "`draft` — nobody has opened the text yet, so a direct append is possible. `working` — the author has taken it over; writes become proposals."
          },
          "taken_over": {
            "type": "boolean"
          },
          "taken_over_at": {
            "type": "string",
            "format": "date-time"
          },
          "pending_edit_requests_count": {
            "type": "integer",
            "description": "Threads where it is the AI's turn."
          },
          "pending_proposals_count": {
            "type": "integer",
            "description": "Proposals waiting for the author to accept or reject."
          },
          "synced_at": {
            "type": "string",
            "format": "date-time"
          },
          "sync_pending": {
            "type": "boolean",
            "description": "The author's browser has edits that have not reached the copy yet."
          },
          "stale": {
            "type": "boolean",
            "description": "The copy has not been synced for long enough that it may no longer be the current text."
          },
          "stale_days": {
            "type": "integer"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time"
          },
          "temporary": {
            "type": "boolean",
            "description": "Present and true for a copy created without an account."
          },
          "expires_at": {
            "type": "string",
            "format": "date-time"
          },
          "access": {
            "type": "string",
            "enum": [
              "owner",
              "commenter"
            ],
            "description": "What this caller may do. `owner` writes; `commenter` reads, comments and proposes."
          },
          "can_write": {
            "type": "boolean"
          },
          "shared": {
            "type": "boolean"
          },
          "url": {
            "type": "string",
            "format": "uri",
            "description": "The editor URL for this document."
          }
        }
      },
      "Anchor": {
        "type": "object",
        "required": [
          "quote"
        ],
        "description": "Where the thread points. The quote must appear verbatim in the text; the server locates it and refuses a thread whose quote it cannot find.",
        "properties": {
          "quote": {
            "type": "string",
            "minLength": 1,
            "description": "The exact text being commented on or replaced."
          },
          "prefix": {
            "type": "string",
            "description": "A little text before the quote, to disambiguate a repeated phrase."
          },
          "suffix": {
            "type": "string"
          },
          "line_from": {
            "type": "integer",
            "minimum": 0
          },
          "line_to": {
            "type": "integer",
            "minimum": 0
          }
        }
      },
      "ThreadMessage": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "author": {
            "type": "string",
            "enum": [
              "author",
              "reviewer",
              "guest"
            ]
          },
          "body": {
            "type": "string"
          },
          "reviewer_name": {
            "type": "string"
          },
          "deleted": {
            "type": "boolean"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "Thread": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "intent": {
            "type": "string",
            "enum": [
              "note",
              "question",
              "rewrite",
              "fact-check",
              "source-needed"
            ]
          },
          "origin": {
            "type": "string",
            "enum": [
              "reviewer",
              "author"
            ],
            "description": "Who opened it. A reviewer thread is a comment or a proposal; an author thread is a request for the AI."
          },
          "status": {
            "type": "string",
            "enum": [
              "open",
              "answered",
              "applied",
              "declined",
              "resolved"
            ],
            "description": "Only a person moves a thread to `applied`, `declined` or `resolved`. An AI can withdraw its own message but cannot resolve a thread."
          },
          "status_note": {
            "type": "string"
          },
          "base_version": {
            "type": "integer"
          },
          "proposal": {
            "type": "string",
            "enum": [
              "append"
            ],
            "description": "Set when this thread proposes appended text rather than a replacement."
          },
          "anchor": {
            "$ref": "#/components/schemas/Anchor"
          },
          "messages": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/ThreadMessage"
            }
          },
          "deleted": {
            "type": "boolean"
          },
          "mine": {
            "type": "boolean",
            "description": "Whether the latest move in this thread was this caller's."
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      }
    }
  }
}
