{
  "openapi": "3.1.0",
  "info": {
    "title": "Kovlet REST API",
    "version": "1",
    "summary": "Shared, real-time data spaces (typed tables + files) for AI-built apps.",
    "description": "The REST API of `kovletd`. Row writes and file metadata writes go through\nthe sync WebSocket (`GET /v1/sync`), described in the protocol reference\n(https://kovlet.com/llms.txt links it); this document covers every HTTP\nroute kovletd registers.\n\n## Base URL\n\n`https://api.kovlet.com` in production. A local `kovletd --dev` listens on\n`http://127.0.0.1:8080`.\n\n## Authentication\n\nSend the session token (`kvs_...`) as `Authorization: Bearer <token>`.\nGet one from `POST /v1/oauth/token` (device code, PKCE authorization code,\nmachine key or refresh token grant).\n\nEvery operation states who may call it in `x-kovlet-session`:\n\n- `none`: no token needed.\n- `any`: any valid session: an **app session** (from an OAuth grant, the\n  one connected apps use), a headless machine session, or a console session.\n- `console`: a **console session** only: a signed-in user in the web\n  console (`scope` console or admin, no app). App sessions get\n  `403 console_required`. Apps use the sync protocol and the `any` routes.\n- `partner`: a **partner key** (`kvp_...`, security scheme `partnerKey`)\n  only, on `/v1/partner/*`. Every other token answers `401`, and partner\n  keys work nowhere else (docs/guides/partners.md).\n\nSpace routes (`/v1/spaces/{space}/...`) also need a role on the space,\ngiven in `x-kovlet-space-role` (viewer < editor < owner).\n\n**Device proof.** A session from the `authorization_code` grant is bound to\nthe P-256 key the client sent as `device_public_key`. Every request with such\na session MUST carry a fresh proof in the `Kovlet-Device-Proof` header\n(see the `deviceProof` security scheme). Sessions from the device-code and\nmachine-key grants are not device-bound and send no proof. A missing,\nstale or replayed proof fails like a bad token: `401 unauthenticated`.\n\n## Errors\n\nErrors use one envelope (schema `Error`):\n\n```json\n{\"error\": {\"code\": \"space_not_found\", \"message\": \"...\", \"hint\": \"the next step that fixes it\"}}\n```\n\n`code` is a stable snake_case string; each error response lists the codes\nit can carry in `x-kovlet-error-codes`. A plan limit answers\n`402 quota_exceeded` with `metric`, `used`, `limit` and `upgrade_url`\nnext to `code` (schema `QuotaError`). Any route can answer\n`500 internal` on an unexpected server error; retry it with backoff. `POST /v1/oauth/token` and\n`POST /v1/oauth/device_authorization` answer OAuth errors (RFC 6749 §5.2)\nas `{\"error\": \"...\", \"error_description\": \"...\"}` (schema `OAuthError`).\n\nEvery response carries `X-Request-Id` (echoed from the request when given).\n",
    "contact": {
      "name": "Kovlet",
      "url": "https://kovlet.com/docs"
    }
  },
  "servers": [
    {
      "url": "https://api.kovlet.com",
      "description": "Production"
    },
    {
      "url": "http://127.0.0.1:8080",
      "description": "Local `kovletd --dev`"
    }
  ],
  "externalDocs": {
    "description": "llms.txt (the docs index for LLMs; the complete reference is /llms-full.txt)",
    "url": "https://kovlet.com/llms.txt"
  },
  "tags": [
    {
      "name": "health",
      "description": "Liveness, readiness and metrics."
    },
    {
      "name": "discovery",
      "description": "Machine-readable references (llms.txt, llms-full.txt, this document)."
    },
    {
      "name": "sign-in",
      "description": "Console sign-in (dev login, OIDC, email, passkeys) and logout."
    },
    {
      "name": "oauth",
      "description": "App sessions. OAuth 2.1 authorization code + PKCE, device flow (RFC 8628), machine keys, refresh."
    },
    {
      "name": "me",
      "description": "The calling session."
    },
    {
      "name": "workspaces",
      "description": "Workspace settings and members (console)."
    },
    {
      "name": "machines",
      "description": "Machines governance (console)."
    },
    {
      "name": "apps",
      "description": "Applications governance (console)."
    },
    {
      "name": "spaces",
      "description": "Data Space CRUD and sharing (console)."
    },
    {
      "name": "invites",
      "description": "Guest invites (console)."
    },
    {
      "name": "usage",
      "description": "Plan usage and upgrade requests."
    },
    {
      "name": "contact",
      "description": "The public contact form."
    },
    {
      "name": "domain-verification",
      "description": "Prove ownership of an email domain (console)."
    },
    {
      "name": "schema",
      "description": "Tables and schema changes of a space."
    },
    {
      "name": "records",
      "description": "Rows of a space (read and restore; writes go through sync)."
    },
    {
      "name": "end-users",
      "description": "App end users (ADR 0021) — sign-in for apps, and the directory, providers and rules owners manage."
    },
    {
      "name": "activity",
      "description": "The change feed, and rollback (undo)."
    },
    {
      "name": "files",
      "description": "File metadata, presigned uploads and downloads."
    },
    {
      "name": "sync",
      "description": "The sync WebSocket."
    },
    {
      "name": "partners",
      "description": "Partner API for AI app builders, and the console's partner keys and claim page (ADR 0022)."
    },
    {
      "name": "mcp",
      "description": "The MCP server for AI coding agents (JSON-RPC over HTTP)."
    }
  ],
  "paths": {
    "/healthz": {
      "get": {
        "operationId": "getHealth",
        "tags": [
          "health"
        ],
        "summary": "Liveness probe",
        "description": "**Auth:** none.\n\nAnswers 200 as long as the process is up. Does not touch the database\nor the blob store (use `GET /readyz` for that).\n",
        "x-kovlet-session": "none",
        "security": [],
        "responses": {
          "200": {
            "description": "The process is up.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HealthResponse"
                },
                "example": {
                  "status": "ok",
                  "version": "0.4.0",
                  "mode": "production"
                }
              }
            }
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/readyz": {
      "get": {
        "operationId": "getReadiness",
        "tags": [
          "health"
        ],
        "summary": "Readiness probe",
        "description": "**Auth:** none.\n\nChecks (within 2 seconds) that the database and, when it supports a\nping, the blob store answer. Fails with `503 not_ready` while the\nserver is draining for shutdown.\n",
        "x-kovlet-session": "none",
        "security": [],
        "responses": {
          "200": {
            "description": "The database and blob store answer.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ReadyResponse"
                },
                "example": {
                  "status": "ready",
                  "database": "postgres",
                  "blob_store": "ok"
                }
              }
            }
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          },
          "503": {
            "description": "`not_ready`: the server is shutting down, or the database or the\nblob store is unavailable (the message says which).\n",
            "x-kovlet-error-codes": [
              "not_ready"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/metrics": {
      "get": {
        "operationId": "getMetrics",
        "tags": [
          "health"
        ],
        "summary": "Prometheus metrics",
        "description": "**Auth:** the metrics token (not a session token).\n\nServes request and sync metrics in the Prometheus text exposition\nformat. Only mounted when kovletd has a metrics token configured, or\nin `--dev`; otherwise the path is not routed (404). When a metrics\ntoken is configured the request must carry\n`Authorization: Bearer <metrics token>` (the operator-configured\nsecret, compared verbatim; a `kvs_` session token does not work).\nIn `--dev` without a metrics token no authorization is needed.\n",
        "x-kovlet-session": "none",
        "x-kovlet-optional": true,
        "x-kovlet-optional-description": "Only mounted when a metrics token is configured or kovletd runs in\n`--dev`; otherwise `GET /metrics` is not routed.\n",
        "security": [],
        "parameters": [
          {
            "name": "Authorization",
            "in": "header",
            "required": false,
            "description": "`Bearer <metrics token>`. Required when a metrics token is configured.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The metrics in the Prometheus text format.",
            "content": {
              "text/plain": {
                "schema": {
                  "type": "string",
                  "description": "Prometheus text exposition format (`text/plain; version=0.0.4; charset=utf-8`)."
                }
              }
            }
          },
          "401": {
            "description": "A metrics token is configured and the request did not carry\n`Authorization: Bearer <metrics token>`. Plain-text body `unauthorized`.\n",
            "headers": {
              "WWW-Authenticate": {
                "description": "`Bearer realm=\"kovlet-metrics\"`",
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "text/plain": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/llms.txt": {
      "get": {
        "operationId": "getLlmsTxt",
        "tags": [
          "discovery"
        ],
        "summary": "Docs index for LLMs",
        "description": "**Auth:** none.\n\nThe short, machine-readable index of the Kovlet docs for LLMs and AI\ncoding agents (https://llmstxt.org format): a summary, then the most\nimportant links first. The complete reference is `GET /llms-full.txt`.\n",
        "x-kovlet-session": "none",
        "security": [],
        "responses": {
          "200": {
            "description": "The index as Markdown text.",
            "headers": {
              "Cache-Control": {
                "schema": {
                  "type": "string",
                  "const": "public, max-age=300"
                }
              },
              "Access-Control-Allow-Origin": {
                "schema": {
                  "type": "string",
                  "const": "*"
                }
              }
            },
            "content": {
              "text/plain": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/llms-full.txt": {
      "get": {
        "operationId": "getLlmsFullTxt",
        "tags": [
          "discovery"
        ],
        "summary": "Full reference for LLMs, with examples",
        "description": "**Auth:** none.\n\nThe complete SDK, sync protocol, REST and MCP reference for LLMs, plus\ncomplete, runnable examples and the list of guides.\n",
        "x-kovlet-session": "none",
        "security": [],
        "responses": {
          "200": {
            "description": "The full reference as Markdown text.",
            "headers": {
              "Cache-Control": {
                "schema": {
                  "type": "string",
                  "const": "public, max-age=300"
                }
              },
              "Access-Control-Allow-Origin": {
                "schema": {
                  "type": "string",
                  "const": "*"
                }
              }
            },
            "content": {
              "text/plain": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/.well-known/llms.txt": {
      "get": {
        "operationId": "getWellKnownLlmsTxt",
        "tags": [
          "discovery"
        ],
        "summary": "The docs index for LLMs, at the well-known location",
        "description": "**Auth:** none.\n\nThe same document as `GET /llms.txt`, for agents that look under `/.well-known/` first.\n",
        "x-kovlet-session": "none",
        "security": [],
        "responses": {
          "200": {
            "description": "The index as Markdown text.",
            "headers": {
              "Cache-Control": {
                "schema": {
                  "type": "string",
                  "const": "public, max-age=300"
                }
              },
              "Access-Control-Allow-Origin": {
                "schema": {
                  "type": "string",
                  "const": "*"
                }
              }
            },
            "content": {
              "text/plain": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/protocol/schema": {
      "get": {
        "operationId": "listProtocolSchemas",
        "tags": [
          "discovery"
        ],
        "summary": "Index of the sync protocol's JSON Schemas",
        "description": "**Auth:** none.\n\nLists the JSON Schema (draft 2020-12) files of the sync protocol\nframes. Each file's `$id` is its URL here. The human reference is\n`reference` (the `/docs/protocol` guide).\n`GET /protocol/schema/` (trailing slash) answers the same.\n",
        "x-kovlet-session": "none",
        "security": [],
        "responses": {
          "200": {
            "description": "The index.",
            "headers": {
              "Cache-Control": {
                "schema": {
                  "type": "string",
                  "const": "public, max-age=300"
                }
              },
              "Access-Control-Allow-Origin": {
                "schema": {
                  "type": "string",
                  "const": "*"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ProtocolSchemaIndex"
                }
              }
            }
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/protocol/schema/{name}": {
      "parameters": [
        {
          "name": "name",
          "in": "path",
          "required": true,
          "description": "The file name from the index, e.g. `hello.schema.json`.",
          "schema": {
            "type": "string"
          }
        }
      ],
      "get": {
        "operationId": "getProtocolSchema",
        "tags": [
          "discovery"
        ],
        "summary": "One JSON Schema of the sync protocol",
        "description": "**Auth:** none.\n",
        "x-kovlet-session": "none",
        "security": [],
        "responses": {
          "200": {
            "description": "The JSON Schema (draft 2020-12).",
            "headers": {
              "Cache-Control": {
                "schema": {
                  "type": "string",
                  "const": "public, max-age=300"
                }
              },
              "Access-Control-Allow-Origin": {
                "schema": {
                  "type": "string",
                  "const": "*"
                }
              }
            },
            "content": {
              "application/schema+json": {
                "schema": {
                  "type": "object",
                  "description": "A JSON Schema document."
                }
              }
            }
          },
          "404": {
            "description": "`not_found`: no schema has this name; `GET /protocol/schema` lists them.",
            "x-kovlet-error-codes": [
              "not_found"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/openapi.json": {
      "get": {
        "operationId": "getOpenApiJson",
        "tags": [
          "discovery"
        ],
        "summary": "This OpenAPI document (JSON)",
        "description": "**Auth:** none.\n\nThis OpenAPI 3.1 document as JSON.\n",
        "x-kovlet-session": "none",
        "security": [],
        "responses": {
          "200": {
            "description": "The OpenAPI document.",
            "headers": {
              "Cache-Control": {
                "schema": {
                  "type": "string",
                  "const": "public, max-age=300"
                }
              },
              "Access-Control-Allow-Origin": {
                "schema": {
                  "type": "string",
                  "const": "*"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "description": "An OpenAPI 3.1 document describing kovletd's HTTP API (this document)."
                }
              }
            }
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/openapi.yaml": {
      "get": {
        "operationId": "getOpenApiYaml",
        "tags": [
          "discovery"
        ],
        "summary": "This OpenAPI document (YAML)",
        "description": "**Auth:** none.\n\nThis OpenAPI 3.1 document as YAML (the same document as `GET /openapi.json`).\n",
        "x-kovlet-session": "none",
        "security": [],
        "responses": {
          "200": {
            "description": "The OpenAPI document.",
            "headers": {
              "Cache-Control": {
                "schema": {
                  "type": "string",
                  "const": "public, max-age=300"
                }
              },
              "Access-Control-Allow-Origin": {
                "schema": {
                  "type": "string",
                  "const": "*"
                }
              }
            },
            "content": {
              "application/yaml": {
                "schema": {
                  "type": "object",
                  "description": "An OpenAPI 3.1 document describing kovletd's HTTP API (this document)."
                }
              }
            }
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/.well-known/oauth-protected-resource/mcp": {
      "get": {
        "operationId": "getMcpProtectedResourceMetadata",
        "tags": [
          "mcp"
        ],
        "summary": "OAuth protected resource metadata of /mcp (RFC 9728)",
        "description": "**Auth:** none.\n\nWhere an MCP client signs in for `/mcp`. A 401 from `/mcp` points\nhere (`resource_metadata` in `WWW-Authenticate`). The authorization\nserver is kovletd itself; see `GET /.well-known/oauth-authorization-server`.\n",
        "x-kovlet-session": "none",
        "security": [],
        "responses": {
          "200": {
            "description": "The metadata.",
            "headers": {
              "Cache-Control": {
                "schema": {
                  "type": "string",
                  "const": "public, max-age=300"
                }
              },
              "Access-Control-Allow-Origin": {
                "schema": {
                  "type": "string",
                  "const": "*"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OAuthProtectedResourceMetadata"
                }
              }
            }
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/.well-known/oauth-protected-resource": {
      "get": {
        "operationId": "getProtectedResourceMetadata",
        "tags": [
          "mcp"
        ],
        "summary": "OAuth protected resource metadata, at the root",
        "description": "**Auth:** none.\n\nThe same document as `GET /.well-known/oauth-protected-resource/mcp`,\nfor clients that look at the root first.\n",
        "x-kovlet-session": "none",
        "security": [],
        "responses": {
          "200": {
            "description": "The metadata.",
            "headers": {
              "Cache-Control": {
                "schema": {
                  "type": "string",
                  "const": "public, max-age=300"
                }
              },
              "Access-Control-Allow-Origin": {
                "schema": {
                  "type": "string",
                  "const": "*"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OAuthProtectedResourceMetadata"
                }
              }
            }
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/.well-known/oauth-authorization-server": {
      "get": {
        "operationId": "getAuthorizationServerMetadata",
        "tags": [
          "mcp"
        ],
        "summary": "OAuth authorization server metadata (RFC 8414)",
        "description": "**Auth:** none.\n\nHow an MCP client (or any agent) gets a token for `/mcp`\n(ADR 0023): register at `registration_endpoint` (RFC 7591), then\neither the authorization code flow with PKCE S256 at\n`authorization_endpoint` (approved at the console's `/activate`), or\nthe device authorization grant (RFC 8628). Send\n`resource=<base>/mcp` (RFC 8707) to bind the token to `/mcp`. Every\nsign-in through a registered client issues an agent session acting\nfor the approving user. Client ID Metadata Documents are not\nsupported (`client_id_metadata_document_supported: false`).\n",
        "x-kovlet-session": "none",
        "security": [],
        "responses": {
          "200": {
            "description": "The metadata.",
            "headers": {
              "Cache-Control": {
                "schema": {
                  "type": "string",
                  "const": "public, max-age=300"
                }
              },
              "Access-Control-Allow-Origin": {
                "schema": {
                  "type": "string",
                  "const": "*"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OAuthAuthorizationServerMetadata"
                }
              }
            }
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/mcp": {
      "post": {
        "operationId": "mcpPost",
        "tags": [
          "mcp"
        ],
        "summary": "MCP endpoint (JSON-RPC 2.0 over Streamable HTTP)",
        "description": "**Auth:** any session for `tools/call`; `initialize`, `ping`,\n`tools/list` and the `notifications/initialized` /\n`notifications/cancelled` notifications also work without a token.\n\nThe Model Context Protocol server for AI coding agents, using the\nstateless subset of Streamable HTTP: one JSON-RPC 2.0 message (or a\nJSON-RPC batch, an array, for MCP 2025-03-26 clients) per POST,\nanswered with a single `application/json` body. The server never opens\nan SSE stream and issues no `Mcp-Session-Id`.\n\nSupported MCP revisions: `2024-11-05`, `2025-03-26`, `2025-06-18`,\n`2025-11-25`; `initialize` with any other `protocolVersion` is answered\nwith `2025-06-18`.\n\nMethods: `initialize` (result `McpInitializeResult`), `ping` (`{}`),\n`tools/list` (`McpToolsListResult`), `tools/call` (`McpToolCallResult`).\nTools: `list_spaces`, `inspect_space_schema`, `create_space`,\n`request_space_access`, `propose_schema_addition`, `propose_rules`, `list_connected_apps`,\n`generate_app_connection` (see `tools/list` for their input schemas).\nExpected tool failures (no access, unknown space, quota) are a\n`tools/call` *result* with `isError: true` whose structured content\ncarries `error`/`code`, `message` and `hint` (and for quota:\n`metric`, `used`, `limit`, `upgrade_url`, ...), not a JSON-RPC error.\n\nJSON-RPC errors: `-32700` parse error, `-32600` invalid request,\n`-32601` method not found, `-32602` invalid params (`tools/call`\nwithout a name, unknown tool), `-32603` internal error.\n\nA presented token must be valid, even for the anonymous methods.\nA session token works whatever its kind (app, machine or console);\ndevice-bound sessions must send `Kovlet-Device-Proof`.\n",
        "x-kovlet-session": "any",
        "x-kovlet-anonymous-methods": [
          "initialize",
          "ping",
          "tools/list",
          "notifications/initialized",
          "notifications/cancelled"
        ],
        "security": [
          {
            "sessionToken": [],
            "deviceProof": []
          },
          {
            "sessionToken": []
          },
          {}
        ],
        "requestBody": {
          "required": true,
          "description": "One JSON-RPC 2.0 message, or a non-empty array of them (a batch). At most 1 MiB.",
          "content": {
            "application/json": {
              "schema": {
                "oneOf": [
                  {
                    "$ref": "#/components/schemas/JsonRpcRequest"
                  },
                  {
                    "type": "array",
                    "minItems": 1,
                    "items": {
                      "$ref": "#/components/schemas/JsonRpcRequest"
                    }
                  }
                ]
              },
              "examples": {
                "initialize": {
                  "value": {
                    "jsonrpc": "2.0",
                    "id": 1,
                    "method": "initialize",
                    "params": {
                      "protocolVersion": "2025-06-18",
                      "capabilities": {},
                      "clientInfo": {
                        "name": "my-agent",
                        "version": "1.0"
                      }
                    }
                  }
                },
                "toolsList": {
                  "value": {
                    "jsonrpc": "2.0",
                    "id": 2,
                    "method": "tools/list"
                  }
                },
                "toolsCall": {
                  "value": {
                    "jsonrpc": "2.0",
                    "id": 3,
                    "method": "tools/call",
                    "params": {
                      "name": "inspect_space_schema",
                      "arguments": {
                        "space": "finance"
                      }
                    }
                  }
                },
                "notification": {
                  "value": {
                    "jsonrpc": "2.0",
                    "method": "notifications/initialized"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The JSON-RPC response to a request (with `result` or `error`), or,\nfor a batch, an array with one response per request in it\n(notifications get none). A malformed element inside a batch is\nanswered in the array with a `-32700` error, still 200.\n",
            "content": {
              "application/json": {
                "schema": {
                  "oneOf": [
                    {
                      "$ref": "#/components/schemas/JsonRpcResponse"
                    },
                    {
                      "type": "array",
                      "minItems": 1,
                      "items": {
                        "$ref": "#/components/schemas/JsonRpcResponse"
                      }
                    }
                  ]
                },
                "example": {
                  "jsonrpc": "2.0",
                  "id": 2,
                  "result": {
                    "tools": []
                  }
                }
              }
            }
          },
          "202": {
            "description": "The message was a notification (no `id`, or `id: null`), a\nresponse from the client, or a batch of only those: nothing to\nanswer. No body.\n"
          },
          "400": {
            "description": "A JSON-RPC error with HTTP 400: `-32700` parse error (the body, or\na batch array, is not valid JSON or is an empty array; `id` is\nnull) or `-32600` invalid request (`jsonrpc` is not `\"2.0\"`; `id`\nechoes the request's).\n",
            "x-kovlet-jsonrpc-error-codes": [
              -32700,
              -32600
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/JsonRpcResponse"
                },
                "example": {
                  "jsonrpc": "2.0",
                  "id": null,
                  "error": {
                    "code": -32700,
                    "message": "parse error"
                  }
                }
              }
            }
          },
          "401": {
            "description": "The bearer token is invalid, expired or revoked (or a device-bound\nsession sent no valid proof), or there is no token and the message\n(or a message in the batch) is not one of the anonymous methods.\nA JSON-RPC error `-32600` with `id: null`; `error.data.code` is\n`unauthenticated` and `error.data.hint` says how to sign in.\n",
            "x-kovlet-error-codes": [
              "unauthenticated"
            ],
            "x-kovlet-jsonrpc-error-codes": [
              -32600
            ],
            "headers": {
              "WWW-Authenticate": {
                "description": "`Bearer realm=\"kovlet\", error=\"invalid_token\", resource_metadata=\"<base>/.well-known/oauth-protected-resource/mcp\", scope=\"agent\"`;\nwithout a token there is no `error`. MCP clients follow\n`resource_metadata` to the OAuth discovery metadata (RFC 9728).\n",
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/JsonRpcResponse"
                },
                "example": {
                  "jsonrpc": "2.0",
                  "id": null,
                  "error": {
                    "code": -32600,
                    "message": "missing bearer token: sign in with `npx @kovlet/mcp login` or pass a Kovlet session token",
                    "data": {
                      "code": "unauthenticated",
                      "hint": "Run `npx @kovlet/mcp login` and retry."
                    }
                  }
                }
              }
            }
          },
          "413": {
            "description": "The body is over 1 MiB. A JSON-RPC error `-32600`\n(`request body too large`) with `id: null`.\n",
            "x-kovlet-jsonrpc-error-codes": [
              -32600
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/JsonRpcResponse"
                }
              }
            }
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      },
      "get": {
        "operationId": "mcpGetNotAllowed",
        "tags": [
          "mcp"
        ],
        "summary": "Not allowed (no SSE stream)",
        "description": "**Auth:** none.\n\nAlways 405: the server answers POST only and never opens an SSE stream.\n",
        "x-kovlet-session": "none",
        "security": [],
        "responses": {
          "405": {
            "description": "Plain-text body `this MCP server answers POST requests only (no SSE stream, no sessions)`.\n",
            "headers": {
              "Allow": {
                "schema": {
                  "type": "string",
                  "const": "POST"
                }
              }
            },
            "content": {
              "text/plain": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      },
      "delete": {
        "operationId": "mcpDeleteNotAllowed",
        "tags": [
          "mcp"
        ],
        "summary": "Not allowed (stateless, no sessions)",
        "description": "**Auth:** none.\n\nAlways 405: the server is stateless and issues no `Mcp-Session-Id`,\nso there is no session to terminate.\n",
        "x-kovlet-session": "none",
        "security": [],
        "responses": {
          "405": {
            "description": "Plain-text body `this MCP server answers POST requests only (no SSE stream, no sessions)`.\n",
            "headers": {
              "Allow": {
                "schema": {
                  "type": "string",
                  "const": "POST"
                }
              }
            },
            "content": {
              "text/plain": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/v1/auth/providers": {
      "get": {
        "operationId": "listSignInProviders",
        "tags": [
          "sign-in"
        ],
        "summary": "List the configured sign-in methods",
        "description": "**Auth:** none.\n\nThe OIDC / OAuth login providers configured on this server (the\n`{provider}` segment of `/v1/auth/oidc/{provider}/start`), and whether\npasskey and email sign-in are enabled.\n",
        "x-kovlet-session": "none",
        "security": [],
        "responses": {
          "200": {
            "description": "The sign-in methods.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SignInProviders"
                }
              }
            }
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/v1/auth/dev/login": {
      "post": {
        "operationId": "devLogin",
        "tags": [
          "sign-in"
        ],
        "summary": "Sign in by email alone (dev only)",
        "description": "**Auth:** none. Only registered by `kovletd --dev`; production servers answer 404.\n\nSigns in (creating the user and their home workspace on first use)\nwith no proof of the address, and starts a console session bound to\nthe device key in `device.public_key`.\n",
        "x-kovlet-dev-only": true,
        "x-kovlet-session": "none",
        "security": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "email",
                  "device"
                ],
                "properties": {
                  "email": {
                    "type": "string",
                    "format": "email",
                    "description": "The address to sign in as."
                  },
                  "display_name": {
                    "type": "string",
                    "description": "Display name for a new user (default the address' local part)."
                  },
                  "device": {
                    "$ref": "#/components/schemas/DeviceInfo"
                  }
                }
              },
              "example": {
                "email": "alice@example.com",
                "display_name": "Alice",
                "device": {
                  "public_key": {
                    "kty": "EC",
                    "crv": "P-256",
                    "x": "f83OJ3D2xF1Bg8vub9tLe1gHMzV76e8Tus9uPHvRVEU",
                    "y": "x_FEzRu9m36HLN_tue659LNpXW6pCyStikYjKIWI5a0"
                  },
                  "name": "Alice's laptop"
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "A new console session.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/LoginResult"
                }
              }
            }
          },
          "400": {
            "description": "`invalid_request`: the body is not valid JSON for this operation.\n`invalid_email`: `email` is not a valid address.\n`invalid_device_key`: `device.public_key` is not an EC P-256 public JWK.\n",
            "x-kovlet-error-codes": [
              "invalid_request",
              "invalid_email",
              "invalid_device_key"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "`device_revoked`: this device key belongs to a revoked machine; generate a new key.",
            "x-kovlet-error-codes": [
              "device_revoked"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/v1/dev/approve": {
      "post": {
        "operationId": "devApprove",
        "tags": [
          "sign-in"
        ],
        "summary": "Approve a device code or consent as the dev user (dev only)",
        "description": "**Auth:** none. Only registered by `kovletd --dev`; production servers answer 404.\n`kovletd dev approve <code>` calls it.\n\nApproves a pending device code (`user_code`, keyed or not), or a PKCE\nconsent request (`consent_url`, the console URL an app opened), as the\ndev user (`email`, default `dev@example.com`), with no console session\nand no device proof. The app gets `role` (default editor) on\n`space_id`, or on the dev user's space named as the console would\nsuggest, created if needed. A consent answers `redirect_to`, the\napp's redirect URI with the authorization code.\n",
        "x-kovlet-dev-only": true,
        "x-kovlet-session": "none",
        "security": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "user_code": {
                    "type": "string",
                    "description": "A device code's user code, e.g. WDJB-MJHT."
                  },
                  "consent_url": {
                    "type": "string",
                    "description": "The consent URL (`/oauth/consent?client_name=&redirect_uri=&code_challenge=&state=&slots=`)."
                  },
                  "email": {
                    "type": "string",
                    "format": "email",
                    "description": "The approving dev user (default dev@example.com)."
                  },
                  "space_id": {
                    "type": "string",
                    "description": "Share this space instead of the default."
                  },
                  "role": {
                    "type": "string",
                    "enum": [
                      "viewer",
                      "editor"
                    ]
                  }
                }
              },
              "example": {
                "user_code": "WDJB-MJHT"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Approved.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DevApproval"
                }
              }
            }
          },
          "400": {
            "description": "`invalid_request`: give either `user_code` or `consent_url`, or the consent request is invalid.\n`invalid_email`: `email` is not a valid address.\n`invalid_client`: the consent names an unknown `client_id`.\n",
            "x-kovlet-error-codes": [
              "invalid_request",
              "invalid_email",
              "invalid_client"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "402": {
            "$ref": "#/components/responses/QuotaExceeded"
          },
          "403": {
            "description": "`access_denied`: the dev user cannot give the app that role on `space_id`.\n`device_revoked`: the device key belongs to a revoked machine.\n",
            "x-kovlet-error-codes": [
              "access_denied",
              "device_revoked"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "`unknown_user_code`: the code is unknown, expired or already used.",
            "x-kovlet-error-codes": [
              "unknown_user_code",
              "not_found"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/v1/dev/oauth/consent": {
      "get": {
        "operationId": "devConsent",
        "tags": [
          "sign-in"
        ],
        "summary": "Approve a consent and redirect, like the console would (dev only)",
        "description": "**Auth:** none. Only registered by `kovletd --dev`; production servers answer 404.\n\nTakes the query of the console consent URL. Point an app's console URL\nat `{base}/v1/dev` and its consent \"opens\" here: kovletd approves as\nthe dev user (`dev_email`, default `dev@example.com`) and redirects to\n`redirect_uri?code=&client_id=&state=`. A test can read the\n`Location` header instead of driving a browser.\n",
        "x-kovlet-dev-only": true,
        "x-kovlet-session": "none",
        "security": [],
        "parameters": [
          {
            "name": "client_name",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "client_id",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "redirect_uri",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "code_challenge",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "code_challenge_method",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "S256"
              ]
            }
          },
          {
            "name": "state",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "slots",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "JSON (`{\"main\":{\"role\":\"editor\"}}`) or `main:editor,notes:viewer`."
          },
          {
            "name": "space_name",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "dev_email",
            "in": "query",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "302": {
            "description": "Approved; `Location` is the app's redirect URI with `code`, `client_id` and `state`."
          },
          "400": {
            "description": "`invalid_request`: the consent request is invalid (redirect URI, PKCE challenge or slots). `invalid_client`: unknown `client_id`.",
            "x-kovlet-error-codes": [
              "invalid_request",
              "invalid_client"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "402": {
            "$ref": "#/components/responses/QuotaExceeded"
          },
          "403": {
            "description": "`access_denied`: the dev user cannot give the app that role on a pinned space.",
            "x-kovlet-error-codes": [
              "access_denied"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/v1/dev/seed": {
      "post": {
        "operationId": "devSeed",
        "tags": [
          "sign-in"
        ],
        "summary": "Seed a dev user, Data Space, app grant and app session (dev only)",
        "description": "**Auth:** none. Only registered by `kovletd --dev`; production servers answer 404.\n`kovletd dev seed` calls it.\n\nSigns in the dev user, finds or creates their Data Space and app by\nname, grants the app `role` (default editor) on the space and issues\nan app session for it: a bearer token that needs no device proof.\nSeeding again with the same names reuses the space and app.\n",
        "x-kovlet-dev-only": true,
        "x-kovlet-session": "none",
        "security": [],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "email": {
                    "type": "string",
                    "format": "email",
                    "description": "The dev user (default dev@example.com)."
                  },
                  "space_name": {
                    "type": "string",
                    "description": "Default \"Dev Space\"."
                  },
                  "app_name": {
                    "type": "string",
                    "description": "Default \"Dev App\"."
                  },
                  "role": {
                    "type": "string",
                    "enum": [
                      "viewer",
                      "editor"
                    ]
                  }
                }
              },
              "example": {
                "space_name": "Conformance",
                "app_name": "My Client"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The seeded session.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DevSeed"
                }
              }
            }
          },
          "400": {
            "description": "`invalid_request`: the body is not valid JSON for this operation, a name is invalid, or `role` is not viewer or editor.\n`invalid_email`: `email` is not a valid address.\n",
            "x-kovlet-error-codes": [
              "invalid_request",
              "invalid_email"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "402": {
            "$ref": "#/components/responses/QuotaExceeded"
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/v1/auth/oidc/{provider}/start": {
      "get": {
        "operationId": "startProviderLogin",
        "tags": [
          "sign-in"
        ],
        "summary": "Start a provider (OIDC / OAuth) sign-in",
        "description": "**Auth:** none. A browser navigation, not an API call.\n\nRedirects to the provider's authorization page. After the provider\nredirects back to `/v1/auth/oidc/{provider}/callback`, the browser\nlands on `return_to` with `?login_code=` (exchange it at\n`POST /v1/auth/login/exchange` with the same `login_nonce`), or with\n`?error=<code>&provider=<name>` when the login failed.\n",
        "x-kovlet-session": "none",
        "security": [],
        "parameters": [
          {
            "name": "provider",
            "in": "path",
            "required": true,
            "description": "Provider name from `GET /v1/auth/providers` (e.g. `google`, `microsoft`, `apple`, `github`).",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "return_to",
            "in": "query",
            "required": false,
            "description": "Console URL to return to (same scheme and host as the console). Default the console root.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "login_nonce",
            "in": "query",
            "required": true,
            "description": "Random secret (at least 22 characters, 128 bits of base64url) the\nconsole keeps and presents again at `POST /v1/auth/login/exchange`\n(login CSRF protection).\n",
            "schema": {
              "type": "string",
              "minLength": 22
            }
          }
        ],
        "responses": {
          "302": {
            "description": "Redirect to the provider's authorization endpoint.",
            "headers": {
              "Location": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "description": "`invalid_login_nonce`: `login_nonce` is missing or shorter than 22 characters.\n`invalid_return_to`: `return_to` is not on the console's origin.\n",
            "x-kovlet-error-codes": [
              "invalid_login_nonce",
              "invalid_return_to"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "`unknown_provider`: no login provider is configured under that name.",
            "x-kovlet-error-codes": [
              "unknown_provider"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/v1/auth/oidc/{provider}/callback": {
      "parameters": [
        {
          "name": "provider",
          "in": "path",
          "required": true,
          "description": "Provider name, as in the start URL.",
          "schema": {
            "type": "string"
          }
        }
      ],
      "get": {
        "operationId": "providerLoginCallback",
        "tags": [
          "sign-in"
        ],
        "summary": "Provider redirect target",
        "description": "**Auth:** none. The provider redirects the browser here; clients never call it.\n\nCompletes the provider login and redirects (303) to the login's\n`return_to` with `?login_code=<kvc_...>`. Once the state is known,\nfailures also redirect there, with `?error=<cancelled|login_failed|email_not_verified|invalid_email>&provider=<name>`.\n",
        "x-kovlet-session": "none",
        "security": [],
        "parameters": [
          {
            "name": "code",
            "in": "query",
            "required": false,
            "description": "Provider authorization code.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "state",
            "in": "query",
            "required": true,
            "description": "The state Kovlet sent to the provider.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "error",
            "in": "query",
            "required": false,
            "description": "Provider error (e.g. `access_denied`).",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "303": {
            "description": "Redirect back to the console (`?login_code=` on success, `?error=&provider=` on failure).",
            "headers": {
              "Location": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "description": "`invalid_request`: the callback query could not be parsed.\n`invalid_code`: the state is unknown, expired, already used or for another provider.\n",
            "x-kovlet-error-codes": [
              "invalid_request",
              "invalid_code"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "`unknown_provider`: no login provider is configured under that name.",
            "x-kovlet-error-codes": [
              "unknown_provider"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      },
      "post": {
        "operationId": "providerLoginCallbackFormPost",
        "tags": [
          "sign-in"
        ],
        "summary": "Provider redirect target (form_post)",
        "description": "**Auth:** none. Apple posts the callback (`response_mode=form_post`); same behaviour as the GET.\n",
        "x-kovlet-session": "none",
        "security": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/x-www-form-urlencoded": {
              "schema": {
                "type": "object",
                "required": [
                  "state"
                ],
                "properties": {
                  "code": {
                    "type": "string",
                    "description": "Provider authorization code."
                  },
                  "state": {
                    "type": "string",
                    "description": "The state Kovlet sent to the provider."
                  },
                  "error": {
                    "type": "string",
                    "description": "Provider error (e.g. `user_cancelled_authorize`)."
                  },
                  "user": {
                    "type": "string",
                    "description": "Apple's first-sign-in user JSON (`{\"name\":{\"firstName\":...,\"lastName\":...}}`), used for the display name."
                  }
                }
              },
              "example": {
                "code": "c1a2b3",
                "state": "Zm9vYmFy"
              }
            }
          }
        },
        "responses": {
          "303": {
            "description": "Redirect back to the console (`?login_code=` on success, `?error=&provider=` on failure).",
            "headers": {
              "Location": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "description": "`invalid_request`: the form could not be read (malformed or over 1 MiB).\n`invalid_code`: the state is unknown, expired, already used or for another provider.\n",
            "x-kovlet-error-codes": [
              "invalid_request",
              "invalid_code"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "`unknown_provider`: no login provider is configured under that name.",
            "x-kovlet-error-codes": [
              "unknown_provider"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/v1/auth/login/exchange": {
      "post": {
        "operationId": "exchangeLoginCode",
        "tags": [
          "sign-in"
        ],
        "summary": "Exchange a provider login code for a console session",
        "description": "**Auth:** none.\n\nRedeems the one-time `login_code` (2 minutes) from a provider\nsign-in, with the `login_nonce` the login was started with, for a\nconsole session bound to `device.public_key`.\n",
        "x-kovlet-session": "none",
        "security": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "login_code",
                  "login_nonce",
                  "device"
                ],
                "properties": {
                  "login_code": {
                    "type": "string",
                    "description": "The `login_code` from the console redirect (`kvc_...`)."
                  },
                  "login_nonce": {
                    "type": "string",
                    "description": "The `login_nonce` passed to the start URL."
                  },
                  "device": {
                    "$ref": "#/components/schemas/DeviceInfo"
                  }
                }
              },
              "example": {
                "login_code": "kvc_4fN2kq9Zb1yQ0eX7mVdR8sJp3tLwC6hA5uGiKoE1nBc",
                "login_nonce": "m3V9pQ2rT8xW1yZ5aB7cD0eF",
                "device": {
                  "public_key": {
                    "kty": "EC",
                    "crv": "P-256",
                    "x": "f83OJ3D2xF1Bg8vub9tLe1gHMzV76e8Tus9uPHvRVEU",
                    "y": "x_FEzRu9m36HLN_tue659LNpXW6pCyStikYjKIWI5a0"
                  },
                  "name": "Chrome on macOS"
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "A new console session.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/LoginResult"
                }
              }
            }
          },
          "400": {
            "description": "`invalid_request`: the body is not valid JSON for this operation.\n`invalid_device_key`: `device.public_key` is not an EC P-256 public JWK.\n`invalid_code`: the login code is unknown, expired or already used.\n`invalid_login_nonce`: `login_nonce` does not match the one the login was started with.\n",
            "x-kovlet-error-codes": [
              "invalid_request",
              "invalid_device_key",
              "invalid_code",
              "invalid_login_nonce"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "`device_revoked`: this device key belongs to a revoked machine; generate a new key.",
            "x-kovlet-error-codes": [
              "device_revoked"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/v1/auth/email/start": {
      "post": {
        "operationId": "startEmailLogin",
        "tags": [
          "sign-in"
        ],
        "summary": "Email a sign-in link and code",
        "description": "**Auth:** none.\n\nMails a sign-in link and a 6-digit code (valid 15 minutes) to\n`email`. The answer does not depend on whether the address has an\naccount. Rate limited: one email a minute and five an hour per\naddress, twenty an hour per client.\n",
        "x-kovlet-session": "none",
        "security": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "email",
                  "login_nonce"
                ],
                "properties": {
                  "email": {
                    "type": "string",
                    "format": "email"
                  },
                  "login_nonce": {
                    "type": "string",
                    "minLength": 22,
                    "description": "The browser's secret (at least 22 characters); `POST /v1/auth/email/verify` needs the same value."
                  }
                }
              },
              "example": {
                "email": "alice@example.com",
                "login_nonce": "m3V9pQ2rT8xW1yZ5aB7cD0eF"
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "The email was sent.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/EmailLoginStarted"
                }
              }
            }
          },
          "400": {
            "description": "`invalid_request`: the body is not valid JSON for this operation.\n`invalid_email`: `email` is not a valid address.\n`invalid_login_nonce`: `login_nonce` is missing or shorter than 22 characters.\n",
            "x-kovlet-error-codes": [
              "invalid_request",
              "invalid_email",
              "invalid_login_nonce"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "`email_login_disabled`: email sign-in is not enabled on this server.",
            "x-kovlet-error-codes": [
              "email_login_disabled"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "`rate_limited`: too many sign-in emails; retry after `retry_after` seconds.",
            "x-kovlet-error-codes": [
              "rate_limited"
            ],
            "headers": {
              "Retry-After": {
                "description": "Seconds to wait.",
                "schema": {
                  "type": "integer"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SignInRateLimitedError"
                }
              }
            }
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          },
          "502": {
            "description": "`email_failed`: the mail provider did not accept the message.",
            "x-kovlet-error-codes": [
              "email_failed"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/auth/email/verify": {
      "post": {
        "operationId": "verifyEmailLogin",
        "tags": [
          "sign-in"
        ],
        "summary": "Redeem an emailed code or link for a console session",
        "description": "**Auth:** none.\n\nSend exactly one of `code` (the 6 digits from the email) or `token`\n(`email_token` from the link), with the `flow_id` and the\n`login_nonce` used at start. Five wrong tries end the request.\n",
        "x-kovlet-session": "none",
        "security": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "flow_id",
                  "login_nonce",
                  "device"
                ],
                "properties": {
                  "flow_id": {
                    "type": "string",
                    "description": "`flow_id` from `POST /v1/auth/email/start` (or `email_flow` from the link)."
                  },
                  "code": {
                    "type": "string",
                    "description": "The 6-digit code; non-digits are ignored. Give this or `token`."
                  },
                  "token": {
                    "type": "string",
                    "description": "`email_token` from the link. Give this or `code`."
                  },
                  "login_nonce": {
                    "type": "string",
                    "description": "The `login_nonce` sent to `POST /v1/auth/email/start`."
                  },
                  "device": {
                    "$ref": "#/components/schemas/DeviceInfo"
                  }
                }
              },
              "example": {
                "flow_id": "0f8Vb3XkqR1sT9yZ2wP4uC7aE5dH6gJmNoLiKcB3vAs",
                "code": "123456",
                "login_nonce": "m3V9pQ2rT8xW1yZ5aB7cD0eF",
                "device": {
                  "public_key": {
                    "kty": "EC",
                    "crv": "P-256",
                    "x": "f83OJ3D2xF1Bg8vub9tLe1gHMzV76e8Tus9uPHvRVEU",
                    "y": "x_FEzRu9m36HLN_tue659LNpXW6pCyStikYjKIWI5a0"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "A new console session.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/LoginResult"
                }
              }
            }
          },
          "400": {
            "description": "`invalid_request`: the body is not valid JSON for this operation.\n`invalid_device_key`: `device.public_key` is not an EC P-256 public JWK.\n`invalid_email_code`: the code or link is wrong, expired or used up, or both or neither of `code` and `token` were given.\n`invalid_login_nonce`: `login_nonce` does not match the browser that asked for the email.\n",
            "x-kovlet-error-codes": [
              "invalid_request",
              "invalid_device_key",
              "invalid_email_code",
              "invalid_login_nonce"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "`device_revoked`: this device key belongs to a revoked machine; generate a new key.",
            "x-kovlet-error-codes": [
              "device_revoked"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "`email_login_disabled`: email sign-in is not enabled on this server.",
            "x-kovlet-error-codes": [
              "email_login_disabled"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/v1/auth/logout": {
      "post": {
        "operationId": "logout",
        "tags": [
          "sign-in"
        ],
        "summary": "Sign out (revoke the current session)",
        "description": "**Auth:** any session.\n\nRevokes the calling session and every session rotated from the same\nrefresh token, so its refresh token stops working too.\n",
        "x-kovlet-session": "any",
        "security": [
          {
            "sessionToken": [],
            "deviceProof": []
          },
          {
            "sessionToken": []
          }
        ],
        "responses": {
          "204": {
            "description": "Signed out."
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/v1/oauth/authorize/preview": {
      "get": {
        "operationId": "previewOAuthConsent",
        "tags": [
          "oauth"
        ],
        "summary": "Consent screen data",
        "description": "**Auth:** console session.\n\nResolves the app (without registering it) and lists the Data Spaces\nthe signed-in user could connect it to, with their own role. Give\n`client_id` for a registered app or `client_name` for a new one\n(dynamic registration on first consent).\n",
        "x-kovlet-session": "console",
        "security": [
          {
            "sessionToken": [],
            "deviceProof": []
          },
          {
            "sessionToken": []
          }
        ],
        "parameters": [
          {
            "name": "client_id",
            "in": "query",
            "required": false,
            "description": "The app's ID (a registered app in the user's home workspace).",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "client_name",
            "in": "query",
            "required": false,
            "description": "App name (at most 100 characters) when there is no `client_id`.",
            "schema": {
              "type": "string",
              "maxLength": 100
            }
          },
          {
            "name": "space_name",
            "in": "query",
            "required": false,
            "description": "The app's suggested name for a new Data Space; `suggested_space` defaults to the app's name.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "redirect_uri",
            "in": "query",
            "required": true,
            "description": "The app's redirect URI. Absolute, no fragment: https, http on a loopback host (any port matches), or a reverse-DNS private-use scheme such as `com.example.app:/callback`.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "What to show on the consent screen.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ConsentPreview"
                }
              }
            }
          },
          "400": {
            "description": "`invalid_request`: `redirect_uri` is invalid or not registered for this (approved) app, or neither `client_id` nor a valid `client_name` was given.\n`invalid_client`: `client_id` is not an app of the user's home workspace.\n",
            "x-kovlet-error-codes": [
              "invalid_request",
              "invalid_client"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "description": "`console_required`: this endpoint needs a console session.\n`unauthorized_client`: the app was revoked.\n",
            "x-kovlet-error-codes": [
              "console_required",
              "unauthorized_client"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/v1/oauth/register": {
      "post": {
        "operationId": "registerOAuthClient",
        "tags": [
          "oauth"
        ],
        "summary": "Register an OAuth client (RFC 7591)",
        "description": "**Auth:** none.\n\nDynamic client registration for MCP clients and other agents\n(ADR 0023 §1). The client gets a public `client_id` (`kvo_...`, no\nsecret) that belongs to no workspace. Every registered client is an\n**agent** client: any sign-in through it issues a session acting for\nthe approving user, capped at their role. It becomes a Kovlet app only\nwhen someone approves it at `/activate`, in their home workspace,\nmatched by `client_name` and the redirect URI's origin under the\nusual app rules (pending unless an admin approves; an approved app's\nredirect URIs are locked).\n\n- `redirect_uris` (1–10): https, http on a loopback address (any port\n  matches), or a private-use scheme, including single-label ones like\n  `cursor://...` (not `javascript`, `data`, `file`, `vbscript`,\n  `about`, `blob`).\n- `grant_types` defaults to `authorization_code`; name\n  `urn:ietf:params:oauth:grant-type:device_code` to use the device\n  flow. `refresh_token` is accepted but agent sessions without a\n  device key get no refresh token.\n- `token_endpoint_auth_method` is always `none`: a requested\n  secret-based method is answered with `none` (RFC 7591 §3.2.1).\n- Other metadata (`logo_uri`, `client_uri`, `contacts`,\n  `application_type`, `software_statement`, ...) is ignored.\n\nRate limited to 20 registrations per hour per address. A client never\nused is deleted after 7 days, one unused for 180 days after that.\n",
        "x-kovlet-session": "none",
        "security": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ClientRegistrationRequest"
              },
              "example": {
                "client_name": "Cursor",
                "redirect_uris": [
                  "cursor://anysphere.cursor-mcp/oauth/callback",
                  "http://localhost:8787/callback"
                ],
                "grant_types": [
                  "authorization_code",
                  "refresh_token"
                ],
                "response_types": [
                  "code"
                ],
                "token_endpoint_auth_method": "none"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "The registered client. `Cache-Control: no-store`.",
            "headers": {
              "Cache-Control": {
                "schema": {
                  "type": "string",
                  "const": "no-store"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ClientRegistrationResponse"
                }
              }
            }
          },
          "400": {
            "description": "OAuth error (RFC 7591 §3.2.2):\n`invalid_client_metadata`: the body is not a JSON object, `client_name` is missing or over 100 characters, or `grant_types`/`response_types` name something unsupported.\n`invalid_redirect_uri`: there are not 1 to 10 `redirect_uris`, or one is not https, loopback http or an allowed private-use scheme.\n",
            "x-kovlet-error-codes": [
              "invalid_client_metadata",
              "invalid_redirect_uri"
            ],
            "headers": {
              "Cache-Control": {
                "schema": {
                  "type": "string",
                  "const": "no-store"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OAuthError"
                }
              }
            }
          },
          "429": {
            "description": "`rate_limited` (OAuth error shape): too many registrations from this address; see `Retry-After`.",
            "x-kovlet-error-codes": [
              "rate_limited"
            ],
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OAuthError"
                }
              }
            }
          }
        }
      }
    },
    "/v1/oauth/authorize": {
      "get": {
        "operationId": "authorizeAgent",
        "tags": [
          "oauth"
        ],
        "summary": "Agent authorization code + PKCE for a registered client (browser)",
        "description": "**Auth:** none (a browser navigation).\n\nThe standard OAuth authorization endpoint for registered clients\n(`kvo_...`, ADR 0023 §2). Not to be confused with `POST` on the same\npath, which is the console's consent submit for apps.\n\nA valid request is recorded as a pending sign-in and the browser is\nsent (`302`) to the console's `/activate?user_code=...`. The person\nsigns in, sees the agent and the host it returns to, chooses spaces\nand approves or denies. The console then sends the browser to\n`redirect_uri` with `code` (one-time, 2 minutes), `state` and `iss`,\nor with `error=access_denied`. Redeem the code at\n`POST /v1/oauth/token` with `grant_type=authorization_code`,\n`code_verifier`, `client_id`, `redirect_uri` and optionally\n`resource`. No device key is needed.\n\n**Errors never redirect** to `redirect_uri` (RFC 9700 §4.11.2): any\ninvalid request gets a plain HTML error page. Under\n`kovletd --dev --dev-auto-approve` the `302` goes straight to the\nredirect URI with the code.\n\nRate limited to 60 requests per hour per address.\n",
        "x-kovlet-session": "none",
        "security": [],
        "parameters": [
          {
            "name": "response_type",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "const": "code"
            }
          },
          {
            "name": "client_id",
            "in": "query",
            "required": true,
            "description": "A registered client (`kvo_...`).",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "redirect_uri",
            "in": "query",
            "required": true,
            "description": "One of the client's registered redirect URIs (a loopback URI matches on any port).",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "code_challenge",
            "in": "query",
            "required": true,
            "description": "PKCE S256 challenge (43 characters).",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "code_challenge_method",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "const": "S256"
            }
          },
          {
            "name": "state",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "scope",
            "in": "query",
            "required": false,
            "description": "Empty or `agent`.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "resource",
            "in": "query",
            "required": false,
            "description": "RFC 8707: `<base>/mcp`. The token is then bound to `/mcp` and rejected everywhere else.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "302": {
            "description": "To the console's `/activate` page (or, with `--dev-auto-approve`, to `redirect_uri` with the code).",
            "headers": {
              "Location": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "description": "An HTML error page: the client is unknown or not a registered client, `redirect_uri` is not registered for it, `response_type` is not `code`, PKCE S256 is missing, `scope` is not `agent`, or `resource` is not this server's `/mcp` (`invalid_target`).\n",
            "content": {
              "text/html": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "description": "An HTML error page; too many requests from this address. See `Retry-After`.",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                }
              }
            },
            "content": {
              "text/html": {
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        }
      },
      "post": {
        "operationId": "authorizeOAuthApp",
        "tags": [
          "oauth"
        ],
        "summary": "Record consent and get the redirect with an authorization code",
        "description": "**Auth:** console session.\n\nThe console submits the user's answer to \"Allow <app> on <space>?\".\nWith `approve: true` it registers the app on first consent (approved\nif the user administers the workspace, pending otherwise), creates\nany new Data Spaces, grants the app the chosen role on each mapped\nspace and returns `redirect_to` carrying `code` (one-time, 2 minutes),\n`client_id` and `state`. With `approve: false` it returns\n`redirect_to` with `error=access_denied` only when the app already\nregistered that redirect URI, otherwise an empty object.\n\nPKCE S256 is required.\n",
        "x-kovlet-session": "console",
        "security": [
          {
            "sessionToken": [],
            "deviceProof": []
          },
          {
            "sessionToken": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/AuthorizeRequest"
              },
              "example": {
                "client_name": "Budget Tracker",
                "redirect_uri": "http://localhost:5173/callback",
                "code_challenge": "E9Melhoa2OwvFrEMTJguCHaoeK1t8URWbuGJSstw-cM",
                "code_challenge_method": "S256",
                "state": "af0ifjsldkj",
                "slots": {
                  "budget": {
                    "create": {
                      "name": "Personal Finance"
                    },
                    "role": "editor"
                  }
                },
                "approve": true
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Where to send the browser next.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AuthorizeResult"
                }
              }
            }
          },
          "400": {
            "description": "`invalid_request`: the body is not valid JSON for this operation, `redirect_uri` is invalid or not registered, PKCE S256 is missing, there are not 1 to 20 slots, a slot name or role is invalid (role must be viewer or editor), a slot names an unknown space or both `space_id` and `create`, a new space name is empty or over 100 characters, or neither `client_id` nor a valid `client_name` was given.\n`invalid_client`: `client_id` is not an app of the user's home workspace.\n",
            "x-kovlet-error-codes": [
              "invalid_request",
              "invalid_client"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "402": {
            "$ref": "#/components/responses/QuotaExceeded"
          },
          "403": {
            "description": "`console_required`: this endpoint needs a console session.\n`access_denied`: a slot asks for more access than the user has on the space.\n`unauthorized_client`: the app was revoked.\n",
            "x-kovlet-error-codes": [
              "console_required",
              "access_denied",
              "unauthorized_client"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/v1/oauth/token": {
      "post": {
        "operationId": "oauthToken",
        "tags": [
          "oauth"
        ],
        "summary": "Get a session token (all grants)",
        "description": "**Auth:** none (the grant is the credential).\n\nThe OAuth 2.1 token endpoint. Grants (`grant_type`):\n\n- `authorization_code`: redeem the code from `POST /v1/oauth/authorize`\n  with PKCE. Needs `code`, `code_verifier`, `client_id`,\n  `redirect_uri` and `device_public_key` (optional `device_name`).\n  Issues a **device-bound** app session with a `refresh_token`; every\n  request with it needs a `Kovlet-Device-Proof`.\n  For a code from `GET /v1/oauth/authorize` (a registered `kvo_`\n  client, ADR 0023): needs `code`, `code_verifier`, `client_id` and\n  `redirect_uri`, no device key; optional `resource`. Issues an agent\n  session (user-bound, 30 days, no refresh token).\n\n`resource` (RFC 8707, `authorization_code` of a registered client\nand `device_code`) must be `<base>/mcp`; the token is then accepted\nonly by `/mcp`. When it was also given at authorization, both must\nmatch.\n- `urn:ietf:params:oauth:grant-type:device_code` (RFC 8628): poll\n  with `device_code` (optional `client_id`) from\n  `POST /v1/oauth/device_authorization` every `interval` seconds until\n  the user approves at `/activate`. While pending: `400\n  authorization_pending` (or `slow_down` when polling faster than\n  every 5 seconds). Issues a headless app session (with `user_id` for\n  `scope=agent`); no refresh token. A device sign-in (the device\n  authorization had `device_public_key`) must also send a device proof\n  over the **device code** (`ath = base64url(sha256(device_code))`,\n  `Kovlet-Device-Proof` header or `device_proof` field) and gets a\n  **device-bound** session with a `refresh_token`.\n- `urn:kovlet:params:oauth:grant-type:machine_key`: exchange a Machine\n  Auth Key (`machine_key`, `kvm_...`) and `client_id` for a headless\n  app session; no refresh token.\n- `refresh_token`: rotate a device-bound session's `refresh_token`\n  (`kvr_...`). Needs a device proof signed by the session's device key\n  over the **refresh token** (`ath = base64url(sha256(refresh_token))`),\n  in the `Kovlet-Device-Proof` header or the `device_proof` field.\n  Returns a new access and refresh token; the old ones stop working.\n  Presenting an already-rotated refresh token revokes the whole\n  session family.\n\nThe body is `application/x-www-form-urlencoded` (standard) or, as a\nconvenience for SDKs, a JSON object of the same fields\n(`device_public_key` may then be a JWK object). Unknown fields are\nignored. Responses carry `Cache-Control: no-store`; errors use the\nOAuth shape (`OAuthError`).\n",
        "x-kovlet-session": "none",
        "security": [],
        "parameters": [
          {
            "name": "Kovlet-Device-Proof",
            "in": "header",
            "required": false,
            "description": "`refresh_token` grant: device proof over the refresh token; device-code grant of a device sign-in: device proof over the device code. Takes precedence over the `device_proof` field.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/x-www-form-urlencoded": {
              "schema": {
                "$ref": "#/components/schemas/TokenRequest"
              },
              "examples": {
                "device_code": {
                  "summary": "Device code grant (poll)",
                  "value": {
                    "grant_type": "urn:ietf:params:oauth:grant-type:device_code",
                    "device_code": "kvc_GhT3mQ9xV2bN7cK1pL5rW8sY0zA4dE6fJ_uIoXvBnM",
                    "client_id": "01JD8ZQ4X3K7M2N9P5R6S8T0VW"
                  }
                },
                "authorization_code": {
                  "summary": "Authorization code grant with PKCE",
                  "value": {
                    "grant_type": "authorization_code",
                    "code": "kvc_4fN2kq9Zb1yQ0eX7mVdR8sJp3tLwC6hA5uGiKoE1nBc",
                    "code_verifier": "dBjftJeZ4CVP-mB92K27uhbUJU1p1r_wW1gFWFOEjXk",
                    "client_id": "01JD8ZQ4X3K7M2N9P5R6S8T0VW",
                    "redirect_uri": "http://localhost:5173/callback",
                    "device_public_key": "{\"kty\":\"EC\",\"crv\":\"P-256\",\"x\":\"f83OJ3D2xF1Bg8vub9tLe1gHMzV76e8Tus9uPHvRVEU\",\"y\":\"x_FEzRu9m36HLN_tue659LNpXW6pCyStikYjKIWI5a0\"}",
                    "device_name": "Chrome on macOS"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The session. `Cache-Control: no-store`.",
            "headers": {
              "Cache-Control": {
                "schema": {
                  "type": "string",
                  "const": "no-store"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TokenResponse"
                }
              }
            }
          },
          "400": {
            "description": "OAuth error (RFC 6749 §5.2, RFC 8628 §3.5):\n`invalid_request`: the body is unreadable, or a field the grant needs is missing or malformed (e.g. `device_public_key` is not an EC P-256 public JWK, `machine_key` lacks the `kvm_` prefix, `refresh_token` lacks the `kvr_` prefix).\n`unsupported_grant_type`: `grant_type` is not one of the four grants.\n`invalid_target`: `resource` is not this server's `/mcp`, does not match the one given at authorization, or was sent for a console consent code.\n`invalid_grant`: the code, device code, machine key or refresh token is unknown, expired, already used or revoked; `client_id`/`redirect_uri`/`code_verifier` does not match; the device was revoked; the device proof is missing or invalid; or a rotated refresh token was reused (the session family is now revoked).\n`unauthorized_client`: the app was revoked.\n`authorization_pending`: device code grant; the user has not approved yet. Keep polling every `interval` seconds.\n`slow_down`: device code grant; polled within 5 seconds of the last poll. Poll less often.\n`expired_token`: device code grant; the device code expired (10 minutes). Start again.\n`access_denied`: device code grant; the user denied the request (the code is spent).\nWith `reason: device_revoked` (on `invalid_grant` or `access_denied`): this device key's machine was revoked. Generate a new device key and sign in again; retrying with the same key cannot succeed.\n",
            "x-kovlet-error-codes": [
              "invalid_request",
              "unsupported_grant_type",
              "invalid_target",
              "invalid_grant",
              "unauthorized_client",
              "authorization_pending",
              "slow_down",
              "expired_token",
              "access_denied"
            ],
            "headers": {
              "Cache-Control": {
                "schema": {
                  "type": "string",
                  "const": "no-store"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OAuthError"
                }
              }
            }
          },
          "401": {
            "description": "`invalid_client` (OAuth error): machine key grant; `client_id` is not an app of the machine's workspace. Code of a registered client: the client was deleted.",
            "x-kovlet-error-codes": [
              "invalid_client"
            ],
            "headers": {
              "Cache-Control": {
                "schema": {
                  "type": "string",
                  "const": "no-store"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OAuthError"
                }
              }
            }
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/v1/oauth/device_authorization": {
      "post": {
        "operationId": "startDeviceAuthorization",
        "tags": [
          "oauth"
        ],
        "summary": "Start a device flow (RFC 8628)",
        "description": "**Auth:** none.\n\nFor CLIs, headless workloads and AI coding agents. Show the user\n`verification_uri_complete` (or `verification_uri` and `user_code`),\nthen poll `POST /v1/oauth/token` with\n`grant_type=urn:ietf:params:oauth:grant-type:device_code` every\n`interval` seconds. The device code lives 10 minutes.\n\n`scope=agent` asks for a user-bound session for an AI coding agent\n(it never sees or does more than the approving user); otherwise the\nsession is a headless (machine, app) session. A registered client's\n`client_id` (`kvo_...`, from `POST /v1/oauth/register` with the\ndevice grant) needs no `client_name` and always gets an agent\nsession. Approving the same agent again reuses its headless machine,\nso only the first approval counts against the machine limit.\n\n`space_ids` (space-separated, at most 20) names the spaces the app\npinned. It is only a hint: `/activate` preselects the ones the\napprover can see. `resource=<base>/mcp` binds the token to `/mcp`.\n\n**Device sign-in (native apps, ADR 0018).** With `device_public_key`\n(an EC P-256 public JWK the app keeps in the platform keystore), the\napproval enrolls a *device* machine for (that key, the approving user)\ninstead of a headless one, and grants the app the chosen spaces (app\ngrants). The token poll then needs a device proof over the\n**device code** and returns a device-bound session with a\n`refresh_token`, so the app stays signed in. Device machines do not\ncount against the plan's machine limit. Cannot be combined with\n`scope=agent`.\n\nForm-encoded body (or a JSON object of the same fields). Unknown\nfields are ignored. Responses carry `Cache-Control: no-store`.\n",
        "x-kovlet-session": "none",
        "security": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/x-www-form-urlencoded": {
              "schema": {
                "$ref": "#/components/schemas/DeviceAuthorizationRequest"
              },
              "example": {
                "client_name": "Kovlet MCP",
                "machine_name": "build-server-01",
                "scope": "agent"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The device and user codes. `Cache-Control: no-store`.",
            "headers": {
              "Cache-Control": {
                "schema": {
                  "type": "string",
                  "const": "no-store"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DeviceAuthorizationResponse"
                }
              }
            }
          },
          "400": {
            "description": "OAuth error:\n`invalid_request`: the body is unreadable, neither `client_id` nor a `client_name` of 1 to 100 characters was given, `device_public_key` is not an EC P-256 public JWK, or `device_public_key` was combined with `scope=agent`.\n`invalid_scope`: `scope` is neither empty nor `agent`.\n`invalid_target`: `resource` is not this server's `/mcp`.\n`unauthorized_client`: the registered client did not register the device grant.\n",
            "x-kovlet-error-codes": [
              "invalid_request",
              "invalid_scope",
              "invalid_target",
              "unauthorized_client"
            ],
            "headers": {
              "Cache-Control": {
                "schema": {
                  "type": "string",
                  "const": "no-store"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OAuthError"
                }
              }
            }
          },
          "401": {
            "description": "`invalid_client` (OAuth error): `client_id` is an unknown registered client (`kvo_...`).",
            "x-kovlet-error-codes": [
              "invalid_client"
            ],
            "headers": {
              "Cache-Control": {
                "schema": {
                  "type": "string",
                  "const": "no-store"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OAuthError"
                }
              }
            }
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/v1/activate/{user_code}": {
      "get": {
        "operationId": "getPendingDevice",
        "tags": [
          "oauth"
        ],
        "summary": "Pending device details for /activate",
        "description": "**Auth:** console session.\n\nWhat the /activate screen shows before the user approves or denies a\ndevice code.\n",
        "x-kovlet-session": "console",
        "security": [
          {
            "sessionToken": [],
            "deviceProof": []
          },
          {
            "sessionToken": []
          }
        ],
        "parameters": [
          {
            "name": "user_code",
            "in": "path",
            "required": true,
            "description": "The user code (e.g. `WDJB-MJHT`); case and dashes/spaces are normalized.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The pending device code.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PendingDevice"
                }
              }
            }
          },
          "400": {
            "description": "`invalid_client`: the flow's `client_id` is not an app of the user's home workspace.",
            "x-kovlet-error-codes": [
              "invalid_client"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "description": "`console_required`: this endpoint needs a console session.\n`unauthorized_client`: the app was revoked.\n",
            "x-kovlet-error-codes": [
              "console_required",
              "unauthorized_client"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "`unknown_user_code`: the user code is unknown, expired, or already approved or denied.",
            "x-kovlet-error-codes": [
              "unknown_user_code"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/v1/activate": {
      "post": {
        "operationId": "activateDevice",
        "tags": [
          "oauth"
        ],
        "summary": "Approve or deny a device code",
        "description": "**Auth:** console session.\n\nApproval enrolls a headless machine in the user's home workspace\n(approved if the user administers it, pending otherwise), registers\nthe app if needed, and grants it the chosen roles on spaces (machine\ngrants; app grants for `scope=agent` flows). The user must hold at\nleast each granted role. The polling client then gets its session.\n\nA headless machine counts against the plan's machine limit: at the\nlimit the approval answers `402 quota_exceeded` (`metric: machines`)\nunless `replace_machine_id` names a machine from\n`GET /v1/activate/{user_code}`'s `replaceable_machines`, which is\nrevoked in the same transaction.\n\nA device sign-in (`device_bound`) enrolls (or reuses) the device\nmachine for the app's key and the user, and gives the app the chosen\nspaces as app grants; with no `grants` the app must already hold at\nleast one space. Device machines are not counted against the machine\nlimit. A new device key counts against the personal-device limit\n(`metric: devices`) instead, with the same `replace_machine_id` (a\ndevice) and `402`; signing in again from a known key never counts,\nand `replace_machine_id` is refused for it. A `scope=agent` code\nthat carries a known device's key attaches the agent to that device.\n",
        "x-kovlet-session": "console",
        "security": [
          {
            "sessionToken": [],
            "deviceProof": []
          },
          {
            "sessionToken": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "user_code",
                  "approve"
                ],
                "properties": {
                  "user_code": {
                    "type": "string",
                    "description": "The user code shown by the device."
                  },
                  "approve": {
                    "type": "boolean",
                    "description": "True to approve, false to deny."
                  },
                  "grants": {
                    "type": [
                      "array",
                      "null"
                    ],
                    "description": "Spaces to give the machine (or agent app) access to: an\nexisting space (`space_id`), or a new one created in the\napprover's home workspace (`create`, BORG-98). Exactly one\nof the two per grant.\n",
                    "items": {
                      "type": "object",
                      "additionalProperties": false,
                      "required": [
                        "role"
                      ],
                      "properties": {
                        "space_id": {
                          "type": "string"
                        },
                        "create": {
                          "type": "object",
                          "additionalProperties": false,
                          "required": [
                            "name"
                          ],
                          "properties": {
                            "name": {
                              "type": "string",
                              "minLength": 1,
                              "maxLength": 100
                            }
                          }
                        },
                        "role": {
                          "type": "string",
                          "enum": [
                            "viewer",
                            "editor"
                          ]
                        }
                      }
                    }
                  },
                  "replace_machine_id": {
                    "type": "string",
                    "description": "Headless sign-ins at the machine limit. Revoke this active headless machine (yours, or any if you administer the workspace) to make room."
                  }
                }
              },
              "example": {
                "user_code": "WDJB-MJHT",
                "approve": true,
                "grants": [
                  {
                    "space_id": "01JD8ZQ4X3K7M2N9P5R6S8T0VW",
                    "role": "editor"
                  }
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The outcome.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "status",
                    "machine_id",
                    "app_id"
                  ],
                  "properties": {
                    "status": {
                      "type": "string",
                      "enum": [
                        "approved",
                        "denied"
                      ]
                    },
                    "machine_id": {
                      "type": "string",
                      "description": "The enrolled headless machine (or the device machine of a device sign-in); empty when denied."
                    },
                    "app_id": {
                      "type": "string",
                      "description": "The app; empty when denied."
                    },
                    "redirect_to": {
                      "type": "string",
                      "description": "Code-flow sign-ins only. Send the browser here; it carries `code`, `state` and `iss` on approval, `error=access_denied` on denial."
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "`invalid_request`: the body is not valid JSON for this operation, a grant role is not viewer or editor, a grant names an unknown space, `replace_machine_id` is not an active headless machine of the workspace (or was given for a device sign-in), or a device sign-in chose no space and the app holds none.\n`invalid_client`: the flow's `client_id` is not an app of the user's home workspace.\n",
            "x-kovlet-error-codes": [
              "invalid_request",
              "invalid_client"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "402": {
            "description": "`quota_exceeded` (`metric: spaces`): a `create` grant would exceed the plan's Data Space limit; nothing is written and the code stays pending.\n`quota_exceeded` (`metric: machines`): approving would enroll a headless machine beyond the plan's limit. Retry with `replace_machine_id` (see `replaceable_machines` on `GET /v1/activate/{user_code}`), or remove a machine in the console.\n`quota_exceeded` (`metric: devices`): approving a new device key would go past the plan's personal-device limit. Retry with `replace_machine_id` naming a device, or revoke one in the console.\n",
            "x-kovlet-error-codes": [
              "quota_exceeded"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/QuotaError"
                }
              }
            }
          },
          "403": {
            "description": "`console_required`: this endpoint needs a console session.\n`access_denied`: a grant is above the user's own role on the space, or `replace_machine_id` is another person's machine and the user is not a workspace admin.\n`unauthorized_client`: the app was revoked.\n`device_revoked`: device sign-in; this device key's machine was revoked. The flow is denied and the polling app gets `access_denied` with `reason: device_revoked`.\n",
            "x-kovlet-error-codes": [
              "console_required",
              "access_denied",
              "unauthorized_client",
              "device_revoked"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "`unknown_user_code`: the user code is unknown, expired, or already approved or denied.",
            "x-kovlet-error-codes": [
              "unknown_user_code"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/v1/auth/passkeys/login/start": {
      "post": {
        "operationId": "startPasskeyLogin",
        "tags": [
          "sign-in"
        ],
        "summary": "Start a passkey sign-in",
        "description": "**Auth:** none.\n\nReturns WebAuthn request options for `navigator.credentials.get`\n(discoverable credentials: no email needed). The challenge lives 5\nminutes. No request body.\n",
        "x-kovlet-session": "none",
        "security": [],
        "responses": {
          "200": {
            "description": "The ceremony.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PasskeyChallenge"
                }
              }
            }
          },
          "404": {
            "description": "`passkeys_disabled`: passkeys are not enabled on this server.",
            "x-kovlet-error-codes": [
              "passkeys_disabled"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/v1/auth/passkeys/login/finish": {
      "post": {
        "operationId": "finishPasskeyLogin",
        "tags": [
          "sign-in"
        ],
        "summary": "Finish a passkey sign-in",
        "description": "**Auth:** none.\n\nVerifies the assertion from `navigator.credentials.get` and starts a\nconsole session bound to `device.public_key`.\n",
        "x-kovlet-session": "none",
        "security": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "flow_id",
                  "credential",
                  "device"
                ],
                "properties": {
                  "flow_id": {
                    "type": "string",
                    "description": "`flow_id` from `POST /v1/auth/passkeys/login/start`."
                  },
                  "credential": {
                    "description": "The WebAuthn `PublicKeyCredential` (assertion) as JSON."
                  },
                  "device": {
                    "$ref": "#/components/schemas/DeviceInfo"
                  }
                }
              },
              "example": {
                "flow_id": "7pQ2rT8xW1yZ5aB7cD0eFgH3jK6mN9oS4uV",
                "credential": {
                  "id": "AbC1",
                  "rawId": "AbC1",
                  "type": "public-key",
                  "response": {
                    "clientDataJSON": "eyJ...",
                    "authenticatorData": "SZY...",
                    "signature": "MEUC...",
                    "userHandle": "MDFKRDha"
                  }
                },
                "device": {
                  "public_key": {
                    "kty": "EC",
                    "crv": "P-256",
                    "x": "f83OJ3D2xF1Bg8vub9tLe1gHMzV76e8Tus9uPHvRVEU",
                    "y": "x_FEzRu9m36HLN_tue659LNpXW6pCyStikYjKIWI5a0"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "A new console session.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/LoginResult"
                }
              }
            }
          },
          "400": {
            "description": "`invalid_request`: the body is not valid JSON for this operation.\n`invalid_device_key`: `device.public_key` is not an EC P-256 public JWK.\n`passkey_failed`: the passkey could not be verified (expired or reused challenge, wrong origin, unknown credential, bad signature).\n",
            "x-kovlet-error-codes": [
              "invalid_request",
              "invalid_device_key",
              "passkey_failed"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "`device_revoked`: this device key belongs to a revoked machine; generate a new key.",
            "x-kovlet-error-codes": [
              "device_revoked"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "`passkeys_disabled`: passkeys are not enabled on this server.",
            "x-kovlet-error-codes": [
              "passkeys_disabled"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/v1/auth/passkeys/register/start": {
      "post": {
        "operationId": "startPasskeyRegistration",
        "tags": [
          "sign-in"
        ],
        "summary": "Start enrolling a passkey",
        "description": "**Auth:** console session.\n\nReturns WebAuthn creation options for `navigator.credentials.create`\n(the user's existing passkeys are excluded). No request body.\n",
        "x-kovlet-session": "console",
        "security": [
          {
            "sessionToken": [],
            "deviceProof": []
          },
          {
            "sessionToken": []
          }
        ],
        "responses": {
          "200": {
            "description": "The ceremony.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PasskeyChallenge"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "$ref": "#/components/responses/ConsoleRequired"
          },
          "404": {
            "description": "`passkeys_disabled`: passkeys are not enabled on this server.",
            "x-kovlet-error-codes": [
              "passkeys_disabled"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "`too_many_passkeys`: the account already has 20 passkeys.",
            "x-kovlet-error-codes": [
              "too_many_passkeys"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/v1/auth/passkeys/register/finish": {
      "post": {
        "operationId": "finishPasskeyRegistration",
        "tags": [
          "sign-in"
        ],
        "summary": "Finish enrolling a passkey",
        "description": "**Auth:** console session.\n\nVerifies the attestation from `navigator.credentials.create` and\nstores the passkey.\n",
        "x-kovlet-session": "console",
        "security": [
          {
            "sessionToken": [],
            "deviceProof": []
          },
          {
            "sessionToken": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "flow_id",
                  "credential"
                ],
                "properties": {
                  "flow_id": {
                    "type": "string",
                    "description": "`flow_id` from `POST /v1/auth/passkeys/register/start`."
                  },
                  "name": {
                    "type": "string",
                    "description": "Label (trimmed, at most 100 characters kept; default \"Passkey\")."
                  },
                  "credential": {
                    "description": "The WebAuthn `PublicKeyCredential` (attestation) as JSON."
                  }
                }
              },
              "example": {
                "flow_id": "7pQ2rT8xW1yZ5aB7cD0eFgH3jK6mN9oS4uV",
                "name": "MacBook Touch ID",
                "credential": {
                  "id": "AbC1",
                  "rawId": "AbC1",
                  "type": "public-key",
                  "response": {
                    "clientDataJSON": "eyJ...",
                    "attestationObject": "o2Nm..."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "The new passkey.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PasskeyView"
                }
              }
            }
          },
          "400": {
            "description": "`invalid_request`: the body is not valid JSON for this operation.\n`passkey_failed`: the passkey could not be verified (expired or reused challenge, another user's ceremony, wrong origin, bad attestation, or the credential is already registered).\n",
            "x-kovlet-error-codes": [
              "invalid_request",
              "passkey_failed"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "$ref": "#/components/responses/ConsoleRequired"
          },
          "404": {
            "description": "`passkeys_disabled`: passkeys are not enabled on this server.",
            "x-kovlet-error-codes": [
              "passkeys_disabled"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/v1/auth/passkeys": {
      "get": {
        "operationId": "listPasskeys",
        "tags": [
          "sign-in"
        ],
        "summary": "List the caller's passkeys",
        "description": "**Auth:** console session.\n",
        "x-kovlet-session": "console",
        "security": [
          {
            "sessionToken": [],
            "deviceProof": []
          },
          {
            "sessionToken": []
          }
        ],
        "responses": {
          "200": {
            "description": "The passkeys, and whether passkeys are enabled on this server.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "passkeys",
                    "enabled"
                  ],
                  "properties": {
                    "passkeys": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/PasskeyView"
                      }
                    },
                    "enabled": {
                      "type": "boolean",
                      "description": "Whether passkey sign-in is enabled on this server."
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "$ref": "#/components/responses/ConsoleRequired"
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/v1/auth/passkeys/{id}": {
      "delete": {
        "operationId": "deletePasskey",
        "tags": [
          "sign-in"
        ],
        "summary": "Delete one of the caller's passkeys",
        "description": "**Auth:** console session.\n",
        "x-kovlet-session": "console",
        "security": [
          {
            "sessionToken": [],
            "deviceProof": []
          },
          {
            "sessionToken": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "The passkey ID (`PasskeyView.id`).",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "204": {
            "description": "Deleted."
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "$ref": "#/components/responses/ConsoleRequired"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/v1/domain-verification": {
      "get": {
        "operationId": "getDomainVerification",
        "tags": [
          "domain-verification"
        ],
        "summary": "The caller's email domain status",
        "description": "**Auth:** console session.\n\nWhether the caller's email domain is verified, whether they may\nverify it, and the pending claim's TXT record and mailboxes.\n",
        "x-kovlet-session": "console",
        "security": [
          {
            "sessionToken": [],
            "deviceProof": []
          },
          {
            "sessionToken": []
          }
        ],
        "responses": {
          "200": {
            "description": "The domain status.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DomainStatus"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "$ref": "#/components/responses/ConsoleRequired"
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      },
      "post": {
        "operationId": "startDomainVerification",
        "tags": [
          "domain-verification"
        ],
        "summary": "Start (or return) a claim on the caller's email domain",
        "description": "**Auth:** console session.\n\nCreates the caller's claim if there is none, and returns the status\nwith the TXT record to publish (`txt_name`, `txt_value`). Only the\ncaller's own email domain can be claimed; if an org workspace exists\nfor it, only its admins and owners may. No request body.\n",
        "x-kovlet-session": "console",
        "security": [
          {
            "sessionToken": [],
            "deviceProof": []
          },
          {
            "sessionToken": []
          }
        ],
        "responses": {
          "200": {
            "description": "The domain status (state `pending`).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DomainStatus"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "description": "`console_required`: this endpoint needs a console session.\n`domain_not_eligible`: a consumer email domain, or the domain's org workspace exists and the caller does not administer it.\n",
            "x-kovlet-error-codes": [
              "console_required",
              "domain_not_eligible"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "`domain_verified`: the domain is already verified.",
            "x-kovlet-error-codes": [
              "domain_verified"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/v1/domain-verification/dns": {
      "post": {
        "operationId": "checkDomainVerificationDNS",
        "tags": [
          "domain-verification"
        ],
        "summary": "Check the TXT record and verify the domain",
        "description": "**Auth:** console session.\n\nLooks up `_kovlet-verify.<domain>` and verifies the domain (founding\nits org workspace, with the caller as owner, if there is none) when\nthe claim's value is there. No request body.\n",
        "x-kovlet-session": "console",
        "security": [
          {
            "sessionToken": [],
            "deviceProof": []
          },
          {
            "sessionToken": []
          }
        ],
        "responses": {
          "200": {
            "description": "The domain status (state `verified`).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DomainStatus"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "description": "`console_required`: this endpoint needs a console session.\n`domain_not_eligible`: a consumer email domain, or the caller does not administer the domain's org workspace.\n",
            "x-kovlet-error-codes": [
              "console_required",
              "domain_not_eligible"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "`domain_verified`: the domain is already verified.",
            "x-kovlet-error-codes": [
              "domain_verified"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "`txt_record_not_found`: the TXT record was not found (or not yet propagated), or no claim was started (`POST /v1/domain-verification`).",
            "x-kovlet-error-codes": [
              "txt_record_not_found"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/v1/domain-verification/email": {
      "post": {
        "operationId": "sendDomainVerificationEmail",
        "tags": [
          "domain-verification"
        ],
        "summary": "Mail a verification code to an admin mailbox at the domain",
        "description": "**Auth:** console session.\n\nMails an 8-digit code (valid 30 minutes) to `to`, one of\n`admin`, `administrator`, `hostmaster`, `postmaster` or `webmaster`\nat the caller's domain (`email_options`). At most one code a minute.\n",
        "x-kovlet-session": "console",
        "security": [
          {
            "sessionToken": [],
            "deviceProof": []
          },
          {
            "sessionToken": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "to"
                ],
                "properties": {
                  "to": {
                    "type": "string",
                    "format": "email",
                    "description": "An address from `email_options`."
                  }
                }
              },
              "example": {
                "to": "admin@example.com"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The domain status (`email_sent_to` set).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DomainStatus"
                }
              }
            }
          },
          "400": {
            "description": "`invalid_request`: the body is not valid JSON for this operation.\n`invalid_mailbox`: `to` is not one of the allowed mailboxes at the caller's domain.\n",
            "x-kovlet-error-codes": [
              "invalid_request",
              "invalid_mailbox"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "description": "`console_required`: this endpoint needs a console session.\n`domain_not_eligible`: a consumer email domain, or the caller does not administer the domain's org workspace.\n",
            "x-kovlet-error-codes": [
              "console_required",
              "domain_not_eligible"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "`domain_verified`: the domain is already verified.",
            "x-kovlet-error-codes": [
              "domain_verified"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "`txt_record_not_found`: no claim was started; call `POST /v1/domain-verification` first.",
            "x-kovlet-error-codes": [
              "txt_record_not_found"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "`domain_code_too_soon`: a code was sent less than a minute ago.",
            "x-kovlet-error-codes": [
              "domain_code_too_soon"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          },
          "502": {
            "description": "`email_failed`: the mail provider did not accept the message; try again or use the DNS record.",
            "x-kovlet-error-codes": [
              "email_failed"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/domain-verification/email/confirm": {
      "post": {
        "operationId": "confirmDomainVerificationEmail",
        "tags": [
          "domain-verification"
        ],
        "summary": "Verify the domain with the mailed code",
        "description": "**Auth:** console session.\n\nVerifies the domain (founding its org workspace, with the caller as\nowner, if there is none). Five wrong codes lock the code; send a new one.\n",
        "x-kovlet-session": "console",
        "security": [
          {
            "sessionToken": [],
            "deviceProof": []
          },
          {
            "sessionToken": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "code"
                ],
                "properties": {
                  "code": {
                    "type": "string",
                    "description": "The 8-digit code (e.g. `1234-5678`); non-digits are ignored."
                  }
                }
              },
              "example": {
                "code": "1234-5678"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The domain status (state `verified`).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DomainStatus"
                }
              }
            }
          },
          "400": {
            "description": "`invalid_request`: the body is not valid JSON for this operation.",
            "x-kovlet-error-codes": [
              "invalid_request"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "description": "`console_required`: this endpoint needs a console session.\n`domain_not_eligible`: a consumer email domain, or the caller does not administer the domain's org workspace.\n",
            "x-kovlet-error-codes": [
              "console_required",
              "domain_not_eligible"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "`domain_verified`: the domain is already verified.",
            "x-kovlet-error-codes": [
              "domain_verified"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "`txt_record_not_found`: no claim was started; call `POST /v1/domain-verification` first.\n`invalid_domain_code`: the code is wrong or expired, or none was sent.\n",
            "x-kovlet-error-codes": [
              "txt_record_not_found",
              "invalid_domain_code"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "`domain_code_locked`: too many wrong codes; send a new one.",
            "x-kovlet-error-codes": [
              "domain_code_locked"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/v1/me": {
      "get": {
        "operationId": "getMe",
        "tags": [
          "me"
        ],
        "summary": "The calling session, its user, workspace, machine and app",
        "description": "**Auth:** any session (app, headless machine or console).\n\nDescribes the session behind the bearer token. This is how an **app\nsession** finds the Data Spaces it was granted: `session.spaces` maps\neach logical space slot the app asked for at consent (OAuth\nauthorization code + PKCE) to the Data Space the user chose and the\nrole chosen for it, for example\n`{\"finance\": {\"space_id\": \"01J...\", \"role\": \"editor\"}}`. Open those\nspaces with the sync protocol (or the `any` space routes) by\n`space_id`. App sessions cannot call `GET /v1/spaces` (it answers\n`403 console_required`); use this endpoint instead.\n\n`session.spaces` is `{}` for sessions without a consent (console\nsessions, device-code and machine-key sessions); a headless machine\nreaches the spaces it holds machine grants on. The slot map is fixed\nwhen the session is issued and kept across refreshes; the live\neffective role can be lower (for example after an owner lowers the\napp's grant): ask `GET /v1/spaces/{id}/access`.\n\n`user` and `workspaces` are present only for sessions with a user;\n`app` only for sessions with an app.\n",
        "x-kovlet-session": "any",
        "security": [
          {
            "sessionToken": [],
            "deviceProof": []
          },
          {
            "sessionToken": []
          }
        ],
        "responses": {
          "200": {
            "description": "The session.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/MeResponse"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "404": {
            "description": "`not_found`: the session, its workspace, machine, user or app no longer exists.",
            "x-kovlet-error-codes": [
              "not_found"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/v1/me/deletion": {
      "get": {
        "operationId": "getAccountDeletion",
        "tags": [
          "me"
        ],
        "summary": "What blocks deleting the caller's account, and what goes with it",
        "description": "**Auth:** console session.\n\nThe account deletion preflight (ADR 0026). `blockers` lists every\nData Space the caller alone owns (hand it over with\n`PATCH /v1/spaces/{id}/members/{gid}` or delete it), every\nOrganization Workspace with other members that the caller alone owns\n(promote another owner with `PATCH /v1/workspaces/{wid}/members/{uid}`),\nand account workspaces that still hold spaces the caller doesn't\nown alone. `deletes` lists what the deletion removes: the caller's\nPersonal Workspace and any Org Workspace where they are the only\nmember, their passkeys, machines (headless ones included) and\npartner keys, and their space and workspace memberships.\n`reauth_methods` lists how the caller can confirm it's them; when it\nis empty, deletion is by email to Kovlet.\n",
        "x-kovlet-session": "console",
        "security": [
          {
            "sessionToken": [],
            "deviceProof": []
          },
          {
            "sessionToken": []
          }
        ],
        "responses": {
          "200": {
            "description": "The preflight.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AccountDeletion"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "$ref": "#/components/responses/ConsoleRequired"
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/v1/me/reauth": {
      "post": {
        "operationId": "startReauth",
        "tags": [
          "me"
        ],
        "summary": "Start confirming it's you before deleting the account",
        "description": "**Auth:** console session.\n\n`passkey` answers a WebAuthn request (`options`, for\n`navigator.credentials.get`) that allows only the caller's own\npasskeys; verify within 5 minutes. `email` mails a 6-digit code (no\nlink) to the account address; verify within 10 minutes. Send the\nresult to `POST /v1/me/reauth/verify` from the same session.\n",
        "x-kovlet-session": "console",
        "security": [
          {
            "sessionToken": [],
            "deviceProof": []
          },
          {
            "sessionToken": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "method"
                ],
                "properties": {
                  "method": {
                    "type": "string",
                    "enum": [
                      "passkey",
                      "email"
                    ]
                  }
                }
              },
              "example": {
                "method": "passkey"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The started confirmation.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ReauthStart"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/InvalidRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "$ref": "#/components/responses/ConsoleRequired"
          },
          "404": {
            "description": "`passkeys_disabled`: passkeys are not enabled on this server.\n`email_login_disabled`: email codes are not enabled on this server.\n",
            "x-kovlet-error-codes": [
              "passkeys_disabled",
              "email_login_disabled"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "`no_passkeys`: the account has no passkeys; use `email`.",
            "x-kovlet-error-codes": [
              "no_passkeys"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "`rate_limited`: too many codes; retry after `retry_after` seconds (shared with email sign-in).",
            "x-kovlet-error-codes": [
              "rate_limited"
            ],
            "headers": {
              "Retry-After": {
                "description": "Seconds to wait.",
                "schema": {
                  "type": "integer"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SignInRateLimitedError"
                }
              }
            }
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          },
          "502": {
            "description": "`email_failed`: the mail provider did not accept the message.",
            "x-kovlet-error-codes": [
              "email_failed"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/me/reauth/verify": {
      "post": {
        "operationId": "verifyReauth",
        "tags": [
          "me"
        ],
        "summary": "Confirm it's you with a passkey or the emailed code",
        "description": "**Auth:** console session; the session family that started it.\n\nSend `credential` (the WebAuthn assertion) for a passkey\nconfirmation, or `code` for an emailed one. A verified confirmation\ncan be spent by `POST /v1/me/delete` for 5 minutes, from this session\nor one refreshed from it. Five wrong codes end it.\n",
        "x-kovlet-session": "console",
        "security": [
          {
            "sessionToken": [],
            "deviceProof": []
          },
          {
            "sessionToken": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "reauth_id"
                ],
                "properties": {
                  "reauth_id": {
                    "type": "string",
                    "description": "`reauth_id` from `POST /v1/me/reauth`."
                  },
                  "credential": {
                    "description": "The WebAuthn `PublicKeyCredential` (assertion) as JSON."
                  },
                  "code": {
                    "type": "string",
                    "description": "The 6-digit emailed code."
                  }
                }
              },
              "example": {
                "reauth_id": "7pQ2rT8xW1yZ5aB7cD0eFgH3jK6mN9oS4uV",
                "code": "123456"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Verified.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "verified_until"
                  ],
                  "properties": {
                    "verified_until": {
                      "type": "string",
                      "format": "date-time",
                      "description": "When the confirmation stops working for `POST /v1/me/delete`."
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "`invalid_request`: the body is not valid JSON for this operation.\n`reauth_failed`: a wrong code or passkey, an expired, used or ended confirmation, or one started by another user or session.\n",
            "x-kovlet-error-codes": [
              "invalid_request",
              "reauth_failed"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "$ref": "#/components/responses/ConsoleRequired"
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/v1/me/delete": {
      "post": {
        "operationId": "deleteAccount",
        "tags": [
          "me"
        ],
        "summary": "Delete the caller's account",
        "description": "**Auth:** console session, plus a confirmation verified in the last 5\nminutes from the same session family.\n\nDeletes the account in one transaction (ADR 0026 §4): sessions\neverywhere, passkeys, sign-in identities, machines, space and\nworkspace memberships, invites sent to and by the user (pending\nones), domain claims and upgrade requests; partner keys the user\ncreated are revoked; the user's Personal Workspace and any Org\nWorkspace where they were the only member are deleted. No Data Space\nis ever deleted. The user id stays as a tombstone, so changes in\nother people's spaces show as \"Deleted user\", and the address can\nsign up again as a new account.\n\nChecks run in order: `400 confirm_email_mismatch`,\n`403 reauth_required` (never 401), then `409 account_has_blockers`.\nA 409 changes nothing and leaves the confirmation usable.\n",
        "x-kovlet-session": "console",
        "security": [
          {
            "sessionToken": [],
            "deviceProof": []
          },
          {
            "sessionToken": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "reauth_id",
                  "confirm_email"
                ],
                "properties": {
                  "reauth_id": {
                    "type": "string",
                    "description": "The verified `reauth_id`."
                  },
                  "confirm_email": {
                    "type": "string",
                    "description": "The account email",
                    "typed by the user.": null
                  }
                }
              },
              "example": {
                "reauth_id": "7pQ2rT8xW1yZ5aB7cD0eFgH3jK6mN9oS4uV",
                "confirm_email": "ana@example.com"
              }
            }
          }
        },
        "responses": {
          "204": {
            "description": "Deleted. Every session of the account has ended."
          },
          "400": {
            "description": "`invalid_request`: the body is not valid JSON for this operation.\n`confirm_email_mismatch`: `confirm_email` is not the account email.\n",
            "x-kovlet-error-codes": [
              "invalid_request",
              "confirm_email_mismatch"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "description": "`console_required`: not a console session.\n`reauth_required`: no confirmation verified in the last 5 minutes from this session, or it was already used.\n",
            "x-kovlet-error-codes": [
              "console_required",
              "reauth_required"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "`account_has_blockers`: hand over or delete what only the caller owns first (`blockers`, as in `GET /v1/me/deletion`).",
            "x-kovlet-error-codes": [
              "account_has_blockers"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AccountBlockedError"
                }
              }
            }
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/v1/spaces/{id}/access": {
      "get": {
        "operationId": "getSpaceAccess",
        "tags": [
          "spaces"
        ],
        "summary": "What the calling session may do on a space",
        "description": "**Auth:** any session (app, headless machine or console).\n\nEvaluates the access policy for `read`, `write` and `manage` on the\nspace for the calling (user, machine, app). Never answers 404: an\nunknown space, or one the caller has no role on, answers 200 with\n`read: false` and `reason` (`space_not_found`, `no_user_grant`, ...).\n`manage` also needs a console or admin session, so it is always\nfalse for app sessions.\n",
        "x-kovlet-session": "any",
        "security": [
          {
            "sessionToken": [],
            "deviceProof": []
          },
          {
            "sessionToken": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "Data Space ID.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The policy decisions.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SpaceAccess"
                },
                "example": {
                  "space_id": "01JD6M4V8Z0000000000000006",
                  "read": true,
                  "write": true,
                  "manage": false,
                  "role": "editor"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/v1/workspaces/{wid}": {
      "get": {
        "operationId": "getWorkspace",
        "tags": [
          "workspaces"
        ],
        "summary": "Get a workspace",
        "description": "**Auth:** console session; the caller must be a member of the\nworkspace (other workspaces answer 404).\n",
        "x-kovlet-session": "console",
        "security": [
          {
            "sessionToken": [],
            "deviceProof": []
          },
          {
            "sessionToken": []
          }
        ],
        "parameters": [
          {
            "name": "wid",
            "in": "path",
            "required": true,
            "description": "Workspace ID.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The workspace.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/WorkspaceView"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "$ref": "#/components/responses/ConsoleRequired"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      },
      "patch": {
        "operationId": "updateWorkspace",
        "tags": [
          "workspaces"
        ],
        "summary": "Update workspace settings",
        "description": "**Auth:** console session; workspace admin or owner.\n\nRenames the workspace or changes whether machines and apps need\nadmin approval before they can reach its spaces. Omitted fields are\nunchanged. Live sync sessions that lose access are ended.\n",
        "x-kovlet-session": "console",
        "security": [
          {
            "sessionToken": [],
            "deviceProof": []
          },
          {
            "sessionToken": []
          }
        ],
        "parameters": [
          {
            "name": "wid",
            "in": "path",
            "required": true,
            "description": "Workspace ID.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "name": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 100,
                    "description": "New name, 1 to 100 characters after trimming."
                  },
                  "require_approved_machines": {
                    "type": "boolean",
                    "description": "Only admin-approved machines can reach the workspace's spaces."
                  },
                  "require_approved_apps": {
                    "type": "boolean",
                    "description": "Only admin-approved apps can reach the workspace's spaces."
                  }
                }
              },
              "example": {
                "name": "Acme",
                "require_approved_apps": true
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The updated workspace.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/WorkspaceView"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/InvalidRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "description": "`console_required`: not a console session.\n`workspace_admin_required`: the caller is a member but not a workspace admin or owner.\n",
            "x-kovlet-error-codes": [
              "console_required",
              "workspace_admin_required"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/v1/workspaces/{wid}/members": {
      "get": {
        "operationId": "listWorkspaceMembers",
        "tags": [
          "workspaces"
        ],
        "summary": "List workspace members",
        "description": "**Auth:** console session; the caller must be a member of the workspace.",
        "x-kovlet-session": "console",
        "security": [
          {
            "sessionToken": [],
            "deviceProof": []
          },
          {
            "sessionToken": []
          }
        ],
        "parameters": [
          {
            "name": "wid",
            "in": "path",
            "required": true,
            "description": "Workspace ID.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The members.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "members"
                  ],
                  "properties": {
                    "members": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/WorkspaceMember"
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "$ref": "#/components/responses/ConsoleRequired"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/v1/workspaces/{wid}/members/{uid}": {
      "patch": {
        "operationId": "updateWorkspaceMember",
        "tags": [
          "workspaces"
        ],
        "summary": "Change an Organization Workspace member's role",
        "description": "**Auth:** console session; owner of the workspace.\n\nOnly Organization Workspaces have roles to change. A workspace keeps\nat least one owner, so an org founder promotes someone before\nstepping down or deleting their account (ADR 0026).\n",
        "x-kovlet-session": "console",
        "security": [
          {
            "sessionToken": [],
            "deviceProof": []
          },
          {
            "sessionToken": []
          }
        ],
        "parameters": [
          {
            "name": "wid",
            "in": "path",
            "required": true,
            "description": "Workspace ID.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "uid",
            "in": "path",
            "required": true,
            "description": "The member's user ID.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "role"
                ],
                "properties": {
                  "role": {
                    "type": "string",
                    "enum": [
                      "member",
                      "admin",
                      "owner"
                    ]
                  }
                }
              },
              "example": {
                "role": "owner"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The member with the new role.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/WorkspaceMember"
                }
              }
            }
          },
          "400": {
            "description": "`invalid_request`: the body is invalid, or the workspace is a Personal Workspace.\n",
            "x-kovlet-error-codes": [
              "invalid_request"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "description": "`console_required`: not a console session.\n`owner_required`: the caller is not an owner of the workspace.\n",
            "x-kovlet-error-codes": [
              "console_required",
              "owner_required"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "description": "`last_owner`: the change would leave the workspace without an owner.",
            "x-kovlet-error-codes": [
              "last_owner"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/v1/users/lookup": {
      "post": {
        "operationId": "lookupUsers",
        "tags": [
          "me"
        ],
        "summary": "Which user IDs belong to deleted accounts",
        "description": "**Auth:** console session.\n\nThe console shows \"Deleted user\" for these IDs in history and\nattribution (ADR 0026 §6). The answer holds no names or emails;\nunknown and live IDs are left out.\n",
        "x-kovlet-session": "console",
        "security": [
          {
            "sessionToken": [],
            "deviceProof": []
          },
          {
            "sessionToken": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "ids"
                ],
                "properties": {
                  "ids": {
                    "type": "array",
                    "maxItems": 100,
                    "items": {
                      "type": "string"
                    }
                  }
                }
              },
              "example": {
                "ids": [
                  "01J9Z3K4M5N6P7Q8R9S0T1V2W3",
                  "01J9Z3K4M5N6P7Q8R9S0T1V2W4"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The deleted ones.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "deleted_user_ids"
                  ],
                  "properties": {
                    "deleted_user_ids": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/InvalidRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "$ref": "#/components/responses/ConsoleRequired"
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/v1/workspaces/{wid}/invites": {
      "post": {
        "operationId": "inviteColleague",
        "tags": [
          "invites"
        ],
        "summary": "Email a colleague an invite to the organization workspace",
        "description": "**Auth:** console session; workspace admin or owner.\n\nEmails someone at the organization's primary domain an invitation to\nsign in. Membership itself is domain-bound: they join when they sign\nin with a verified address at the domain. Personal workspaces have no\ncolleagues; share a Data Space instead (`POST /v1/spaces/{id}/members`).\n",
        "x-kovlet-session": "console",
        "security": [
          {
            "sessionToken": [],
            "deviceProof": []
          },
          {
            "sessionToken": []
          }
        ],
        "parameters": [
          {
            "name": "wid",
            "in": "path",
            "required": true,
            "description": "Workspace ID.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "email"
                ],
                "properties": {
                  "email": {
                    "type": "string",
                    "format": "email",
                    "description": "An address at the workspace's primary domain."
                  }
                }
              },
              "example": {
                "email": "sam@acme.com"
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "The invite email was accepted by the mail provider.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "sent_to",
                    "mailer"
                  ],
                  "properties": {
                    "sent_to": {
                      "type": "string",
                      "description": "The normalized (lower-case) address the invite went to."
                    },
                    "mailer": {
                      "type": "string",
                      "description": "The mail backend that sent it (`resend`, `smtp`, or `log` when email is not configured)."
                    }
                  }
                },
                "example": {
                  "sent_to": "sam@acme.com",
                  "mailer": "resend"
                }
              }
            }
          },
          "400": {
            "description": "`invalid_request`: invalid JSON body, invalid email address, or the workspace is a personal workspace.\n`wrong_domain`: the address is not at the workspace's primary domain.\n",
            "x-kovlet-error-codes": [
              "invalid_request",
              "wrong_domain"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "description": "`console_required`: not a console session.\n`workspace_admin_required`: the caller is not a workspace admin or owner.\n",
            "x-kovlet-error-codes": [
              "console_required",
              "workspace_admin_required"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "description": "`already_member`: this person is already in the workspace.",
            "x-kovlet-error-codes": [
              "already_member"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          },
          "502": {
            "description": "`email_failed`: the invite email could not be sent; try again later.",
            "x-kovlet-error-codes": [
              "email_failed"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/workspaces/{wid}/machines": {
      "get": {
        "operationId": "listMachines",
        "tags": [
          "machines"
        ],
        "summary": "List machines",
        "description": "**Auth:** console session; the caller must be a member of the\nworkspace. Admins and owners see every machine of the workspace;\nother members see only the machines they own.\n",
        "x-kovlet-session": "console",
        "security": [
          {
            "sessionToken": [],
            "deviceProof": []
          },
          {
            "sessionToken": []
          }
        ],
        "parameters": [
          {
            "name": "wid",
            "in": "path",
            "required": true,
            "description": "Workspace ID.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The machines.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "machines"
                  ],
                  "properties": {
                    "machines": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/MachineView"
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "$ref": "#/components/responses/ConsoleRequired"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      },
      "post": {
        "operationId": "createMachine",
        "tags": [
          "machines"
        ],
        "summary": "Create a headless machine and its Machine Auth Key",
        "description": "**Auth:** console session; workspace admin or owner.\n\nCreates an approved headless machine (a server, CI job or script)\nand returns its Machine Auth Key (`kvm_...`) once; exchange it at\n`POST /v1/oauth/token` (machine key grant). `grants` optionally gives\nthe machine, for an app, a role on spaces the caller can manage, in\nthe same transaction. Counts against the `machines` quota.\n",
        "x-kovlet-session": "console",
        "security": [
          {
            "sessionToken": [],
            "deviceProof": []
          },
          {
            "sessionToken": []
          }
        ],
        "parameters": [
          {
            "name": "wid",
            "in": "path",
            "required": true,
            "description": "Workspace ID.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "name"
                ],
                "properties": {
                  "name": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 100,
                    "description": "Machine name, 1 to 100 characters after trimming."
                  },
                  "grants": {
                    "type": "array",
                    "description": "Machine grants to create with the machine.",
                    "items": {
                      "type": "object",
                      "additionalProperties": false,
                      "required": [
                        "space_id",
                        "app_id",
                        "role"
                      ],
                      "properties": {
                        "space_id": {
                          "type": "string",
                          "description": "A space in this workspace the caller can manage."
                        },
                        "machine_id": {
                          "type": "string",
                          "description": "Ignored; the new machine's ID is used."
                        },
                        "app_id": {
                          "type": "string",
                          "description": "An app registered in the space's workspace."
                        },
                        "role": {
                          "type": "string",
                          "enum": [
                            "viewer",
                            "editor"
                          ]
                        }
                      }
                    }
                  }
                }
              },
              "example": {
                "name": "nightly-etl",
                "grants": [
                  {
                    "space_id": "01JD6M4V8Z0000000000000006",
                    "app_id": "01JD6M4V8Z0000000000000004",
                    "role": "editor"
                  }
                ]
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "The machine and its key. The key is shown only here (and on rotation).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/MachineWithKey"
                }
              }
            }
          },
          "400": {
            "description": "`invalid_request`: invalid JSON body, bad name, a grant role that is not viewer or editor,\nor a grant app not registered in the space's workspace.\n",
            "x-kovlet-error-codes": [
              "invalid_request"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "402": {
            "$ref": "#/components/responses/QuotaExceeded"
          },
          "403": {
            "description": "`console_required`: not a console session.\n`workspace_admin_required`: the caller is not a workspace admin or owner.\n`manage_required`: a grant names a space the caller cannot manage (or that does not exist).\n",
            "x-kovlet-error-codes": [
              "console_required",
              "workspace_admin_required",
              "manage_required"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/v1/machines/{id}/approve": {
      "post": {
        "operationId": "approveMachine",
        "tags": [
          "machines"
        ],
        "summary": "Approve a machine",
        "description": "**Auth:** console session; admin or owner of the machine's workspace.\n\nSets `approval_status` to `approved`. Machines in other workspaces answer 404.\n",
        "x-kovlet-session": "console",
        "security": [
          {
            "sessionToken": [],
            "deviceProof": []
          },
          {
            "sessionToken": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "Machine ID.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The machine as written.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/MachineView"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "description": "`console_required`: not a console session.\n`workspace_admin_required`: the caller is not a workspace admin or owner.\n",
            "x-kovlet-error-codes": [
              "console_required",
              "workspace_admin_required"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/v1/machines/{id}/reject": {
      "post": {
        "operationId": "rejectMachine",
        "tags": [
          "machines"
        ],
        "summary": "Reject a machine",
        "description": "**Auth:** console session; admin or owner of the machine's workspace.\n\nSets `approval_status` to `rejected`. Machines in other workspaces answer 404.\n",
        "x-kovlet-session": "console",
        "security": [
          {
            "sessionToken": [],
            "deviceProof": []
          },
          {
            "sessionToken": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "Machine ID.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The machine as written.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/MachineView"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "description": "`console_required`: not a console session.\n`workspace_admin_required`: the caller is not a workspace admin or owner.\n",
            "x-kovlet-error-codes": [
              "console_required",
              "workspace_admin_required"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/v1/machines/{id}/revoke": {
      "post": {
        "operationId": "revokeMachine",
        "tags": [
          "machines"
        ],
        "summary": "Revoke a machine",
        "description": "**Auth:** console session; admin or owner of the machine's workspace,\nor the machine's owner.\n\nSets `revoked_at` (kept if already revoked) and ends the machine's\nsessions and refresh tokens, so a later restore needs a fresh\nsign-in or Machine Auth Key exchange.\n",
        "x-kovlet-session": "console",
        "security": [
          {
            "sessionToken": [],
            "deviceProof": []
          },
          {
            "sessionToken": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "Machine ID.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The machine as written.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/MachineView"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "description": "`console_required`: not a console session.\n`workspace_admin_required`: the caller is neither a workspace admin or owner nor the machine's owner.\n",
            "x-kovlet-error-codes": [
              "console_required",
              "workspace_admin_required"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/v1/machines/{id}/restore": {
      "post": {
        "operationId": "restoreMachine",
        "tags": [
          "machines"
        ],
        "summary": "Restore a revoked machine",
        "description": "**Auth:** console session; admin or owner of the machine's workspace.\n\nClears `revoked_at`. A device signs in again with its existing key; a\nheadless machine keeps its Machine Auth Key. Restoring a revoked\nheadless machine counts against the `machines` quota.\n",
        "x-kovlet-session": "console",
        "security": [
          {
            "sessionToken": [],
            "deviceProof": []
          },
          {
            "sessionToken": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "Machine ID.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The machine as written.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/MachineView"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "402": {
            "$ref": "#/components/responses/QuotaExceeded"
          },
          "403": {
            "description": "`console_required`: not a console session.\n`workspace_admin_required`: the caller is not a workspace admin or owner.\n",
            "x-kovlet-error-codes": [
              "console_required",
              "workspace_admin_required"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/v1/machines/{id}/rotate-key": {
      "post": {
        "operationId": "rotateMachineKey",
        "tags": [
          "machines"
        ],
        "summary": "Rotate a headless machine's Machine Auth Key",
        "description": "**Auth:** console session; admin or owner of the machine's workspace.\n\nIssues a new Machine Auth Key for an active headless machine; the old\nkey stops working. Existing sessions are not ended.\n",
        "x-kovlet-session": "console",
        "security": [
          {
            "sessionToken": [],
            "deviceProof": []
          },
          {
            "sessionToken": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "Machine ID.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The machine and its new key, shown only here.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/MachineWithKey"
                }
              }
            }
          },
          "400": {
            "description": "`invalid_request`: the machine is not headless or is revoked.",
            "x-kovlet-error-codes": [
              "invalid_request"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "description": "`console_required`: not a console session.\n`workspace_admin_required`: the caller is not a workspace admin or owner.\n",
            "x-kovlet-error-codes": [
              "console_required",
              "workspace_admin_required"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "description": "`concurrent_modification`: the machine was revoked while the key was being rotated.",
            "x-kovlet-error-codes": [
              "concurrent_modification"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/v1/workspaces/{wid}/apps": {
      "get": {
        "operationId": "listApps",
        "tags": [
          "apps"
        ],
        "summary": "List applications",
        "description": "**Auth:** console session; the caller must be a member of the workspace.",
        "x-kovlet-session": "console",
        "security": [
          {
            "sessionToken": [],
            "deviceProof": []
          },
          {
            "sessionToken": []
          }
        ],
        "parameters": [
          {
            "name": "wid",
            "in": "path",
            "required": true,
            "description": "Workspace ID.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The apps registered in the workspace.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "apps"
                  ],
                  "properties": {
                    "apps": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/AppView"
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "$ref": "#/components/responses/ConsoleRequired"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/v1/apps/{id}": {
      "patch": {
        "operationId": "updateApp",
        "tags": [
          "apps"
        ],
        "summary": "Update an application",
        "description": "**Auth:** console session; admin or owner of the app's workspace.\n\nRenames the app, pins its allowed origins, or sets its redirect URIs.\nOmitted fields are unchanged. Each redirect URI must be on an allowed\norigin (after `allowed_origins` from the same request is applied).\nOptimistic: a concurrent change answers 409.\n",
        "x-kovlet-session": "console",
        "security": [
          {
            "sessionToken": [],
            "deviceProof": []
          },
          {
            "sessionToken": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "Application ID.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "name": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 100,
                    "description": "New name, 1 to 100 characters after trimming."
                  },
                  "allowed_origins": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    },
                    "description": "Origins like `https://app.example.com` (scheme, host and optional port; no path), `http://localhost` (a loopback origin matches any port), or a native app's private-use scheme `com.example.app:`. Empty means not pinned."
                  },
                  "redirect_uris": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    },
                    "description": "OAuth redirect URIs; each must be on an allowed origin."
                  }
                }
              },
              "example": {
                "name": "Budget tracker",
                "allowed_origins": [
                  "https://budget.example.com"
                ],
                "redirect_uris": [
                  "https://budget.example.com/callback"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The updated app.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AppView"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/InvalidRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "description": "`console_required`: not a console session.\n`workspace_admin_required`: the caller is not a workspace admin or owner.\n",
            "x-kovlet-error-codes": [
              "console_required",
              "workspace_admin_required"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "description": "`concurrent_modification`: the app was changed concurrently; reload and try again.",
            "x-kovlet-error-codes": [
              "concurrent_modification"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/v1/apps/{id}/approve": {
      "post": {
        "operationId": "approveApp",
        "tags": [
          "apps"
        ],
        "summary": "Approve an application",
        "description": "**Auth:** console session; admin or owner of the app's workspace. Sets `approval_status` to `approved`.",
        "x-kovlet-session": "console",
        "security": [
          {
            "sessionToken": [],
            "deviceProof": []
          },
          {
            "sessionToken": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "Application ID.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The app as written.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AppView"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "description": "`console_required`: not a console session.\n`workspace_admin_required`: the caller is not a workspace admin or owner.\n",
            "x-kovlet-error-codes": [
              "console_required",
              "workspace_admin_required"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/v1/apps/{id}/reject": {
      "post": {
        "operationId": "rejectApp",
        "tags": [
          "apps"
        ],
        "summary": "Reject an application",
        "description": "**Auth:** console session; admin or owner of the app's workspace. Sets `approval_status` to `rejected`.",
        "x-kovlet-session": "console",
        "security": [
          {
            "sessionToken": [],
            "deviceProof": []
          },
          {
            "sessionToken": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "Application ID.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The app as written.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AppView"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "description": "`console_required`: not a console session.\n`workspace_admin_required`: the caller is not a workspace admin or owner.\n",
            "x-kovlet-error-codes": [
              "console_required",
              "workspace_admin_required"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/v1/apps/{id}/revoke": {
      "post": {
        "operationId": "revokeApp",
        "tags": [
          "apps"
        ],
        "summary": "Revoke an application",
        "description": "**Auth:** console session; admin or owner of the app's workspace.\n\nSets `revoked_at` (kept if already revoked) and ends the app's\nsessions and refresh tokens.\n",
        "x-kovlet-session": "console",
        "security": [
          {
            "sessionToken": [],
            "deviceProof": []
          },
          {
            "sessionToken": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "Application ID.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The app as written.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AppView"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "description": "`console_required`: not a console session.\n`workspace_admin_required`: the caller is not a workspace admin or owner.\n",
            "x-kovlet-error-codes": [
              "console_required",
              "workspace_admin_required"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/v1/apps/{id}/restore": {
      "post": {
        "operationId": "restoreApp",
        "tags": [
          "apps"
        ],
        "summary": "Restore a revoked application",
        "description": "**Auth:** console session; admin or owner of the app's workspace.\n\nClears `revoked_at`. Users connect the app again to get new sessions.\n",
        "x-kovlet-session": "console",
        "security": [
          {
            "sessionToken": [],
            "deviceProof": []
          },
          {
            "sessionToken": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "Application ID.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The app as written.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AppView"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "description": "`console_required`: not a console session.\n`workspace_admin_required`: the caller is not a workspace admin or owner.\n",
            "x-kovlet-error-codes": [
              "console_required",
              "workspace_admin_required"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/v1/spaces": {
      "get": {
        "operationId": "listSpaces",
        "tags": [
          "spaces"
        ],
        "summary": "List Data Spaces",
        "description": "**Auth:** any session; the answer depends on the session.\n\n**Console sessions** get every space the user holds a role on: spaces\nin the workspaces they belong to, plus spaces they joined as an\naccepted external guest (`guest: true`).\n\n**App sessions** (BORG-98, ADR 0019) get the spaces their grant target\nholds a grant on, with the app's effective role. A user-bound session\n(PKCE, a device code with a device key, `scope=agent`) holds app\ngrants; a headless one (a keyless device code, a Machine Auth Key)\nholds machine grants. A space an admin must still approve the app or\nmachine for has `role: \"\"` and a `reason`; spaces the user can no\nlonger read are left out. `requestable` counts the user's other\nspaces the app could ask for through a grant request, and\n`can_create` says whether `POST /v1/spaces` would succeed now. A\nmachine key a partner minted for one space lists only that space,\nwith `requestable: 0`, `can_create: false` and `create_blocked.code`\n`space_bound_machine`.\n",
        "x-kovlet-session": "any",
        "security": [
          {
            "sessionToken": [],
            "deviceProof": []
          },
          {
            "sessionToken": []
          }
        ],
        "responses": {
          "200": {
            "description": "The spaces.",
            "content": {
              "application/json": {
                "schema": {
                  "oneOf": [
                    {
                      "type": "object",
                      "description": "Console sessions.",
                      "required": [
                        "spaces"
                      ],
                      "properties": {
                        "spaces": {
                          "type": "array",
                          "items": {
                            "$ref": "#/components/schemas/SpaceView"
                          }
                        }
                      }
                    },
                    {
                      "$ref": "#/components/schemas/AppSpaceList"
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "description": "App sessions: `not_a_member` (the acting user left the workspace).\n",
            "x-kovlet-error-codes": [
              "not_a_member"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      },
      "post": {
        "operationId": "createSpace",
        "tags": [
          "spaces"
        ],
        "summary": "Create a Data Space",
        "description": "**Auth:** any session; the answer depends on the session.\n\n**Console sessions** create a space in the session's workspace with\nthe caller as owner and may set the governance fields. `slug`\ndefaults to a slug of the name, with a numeric suffix when taken; an\nexplicit slug that is taken answers 409 `conflict`. Answers the\n`SpaceView` (`role: owner`).\n\n**App sessions** (BORG-98, ADR 0019) send `name`, `slug`, `icon` and\n`slot` only. The space is owned by the acting user (the session's\nuser, or the headless machine's owner) and the session's grant target\ngets Editor, in one transaction; `slot` maps a session slot to it.\nA workspace that requires approved apps or machines refuses an app or\nmachine that is not approved yet (403, nothing created). Answers\n`{\"space\": AppSpaceView}`. A retry after a network error should send\na `slug`, so it fails with `slug_taken` instead of duplicating.\n\nCounts against the `spaces` quota.\n",
        "x-kovlet-session": "any",
        "security": [
          {
            "sessionToken": [],
            "deviceProof": []
          },
          {
            "sessionToken": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "name"
                ],
                "properties": {
                  "name": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 100,
                    "description": "Space name, 1 to 100 characters after trimming."
                  },
                  "slug": {
                    "type": "string",
                    "pattern": "^[a-z0-9]+(-[a-z0-9]+)*$",
                    "description": "URL slug, unique in the workspace; lower-case ASCII letters, digits and single dashes."
                  },
                  "icon": {
                    "type": "string",
                    "description": "An emoji or up to 16 characters without spaces."
                  },
                  "slot": {
                    "type": "string",
                    "pattern": "^[A-Za-z][A-Za-z0-9_]{0,63}$",
                    "description": "App sessions only. The session slot to map to the new space."
                  },
                  "entire_org_role": {
                    "type": "string",
                    "enum": [
                      "",
                      "viewer",
                      "editor"
                    ],
                    "description": "Console sessions only. Role every member of the organization workspace gets; organization workspaces only."
                  },
                  "require_approved_apps": {
                    "type": "boolean",
                    "description": "Console sessions only."
                  },
                  "require_approved_machines": {
                    "type": "boolean",
                    "description": "Console sessions only."
                  }
                }
              },
              "example": {
                "name": "Finance",
                "icon": "💰"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "The new space.",
            "content": {
              "application/json": {
                "schema": {
                  "oneOf": [
                    {
                      "$ref": "#/components/schemas/SpaceView"
                    },
                    {
                      "type": "object",
                      "description": "App sessions.",
                      "required": [
                        "space"
                      ],
                      "properties": {
                        "space": {
                          "$ref": "#/components/schemas/AppSpaceView"
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/InvalidRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "402": {
            "$ref": "#/components/responses/QuotaExceeded"
          },
          "403": {
            "description": "App sessions: `app_not_approved` or `machine_not_approved` (the workspace requires an admin to approve this app or machine first), `not_a_member` (the acting user left the workspace), `space_bound_machine` (a machine key a partner minted for one space can't create spaces).\n",
            "x-kovlet-error-codes": [
              "app_not_approved",
              "machine_not_approved",
              "not_a_member",
              "space_bound_machine"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "`conflict` (console) or `slug_taken` (app): the slug is already taken in the workspace.",
            "x-kovlet-error-codes": [
              "conflict",
              "slug_taken"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/v1/spaces/{id}/access-events": {
      "get": {
        "operationId": "listAccessEvents",
        "tags": [
          "spaces"
        ],
        "summary": "Who changed access to a Data Space",
        "description": "**Auth:** console session; any role on the space (viewer or above).\n\nThe space's access events, newest first: `space.created` and app or\nmachine grants `grant.added`, `grant.changed` and `grant.removed`,\nwith who made the change and where (`via`). The console's Activity\nview merges them with the change feed (BORG-98, ADR 0019 §7).\n",
        "x-kovlet-session": "console",
        "x-kovlet-space-role": "viewer",
        "security": [
          {
            "sessionToken": [],
            "deviceProof": []
          },
          {
            "sessionToken": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "Data Space ID.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "before",
            "in": "query",
            "required": false,
            "description": "Page with `next_before`.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "description": "1 to 200; default 50.",
            "schema": {
              "type": "integer"
            }
          },
          {
            "name": "user",
            "in": "query",
            "required": false,
            "description": "Only changes made by this user.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "machine",
            "in": "query",
            "required": false,
            "description": "Only changes by or for this machine.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "app",
            "in": "query",
            "required": false,
            "description": "Only changes by or for this app.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The events.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "events"
                  ],
                  "properties": {
                    "events": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/AccessEvent"
                      }
                    },
                    "next_before": {
                      "type": "string",
                      "description": "Present when there may be older events; pass it as `before`."
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/InvalidRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "description": "`console_required`: not a console session.\nPolicy denials (the code is the reason): `machine_revoked`, `machine_not_approved`, `unknown_principal`.\n",
            "x-kovlet-error-codes": [
              "console_required",
              "machine_revoked",
              "machine_not_approved",
              "unknown_principal"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/v1/grant-requests": {
      "post": {
        "operationId": "createGrantRequest",
        "tags": [
          "spaces"
        ],
        "summary": "Ask the user for access to more Data Spaces",
        "description": "**Auth:** app session (console sessions get `403 app_session_required`).\n\nStarts a grant request (BORG-98, ADR 0019 §4). Show `approve_url` to\nthe user (a popup, a system browser sheet, a printed link); the\nacting user approves on Kovlet's `/approve` page, picking existing\nspaces or creating new ones, and the grants are added to this same\nsession's machine and app. Poll `GET /v1/grant-requests/{request}`\nevery `interval` seconds. A request is pending for 10 minutes.\n",
        "x-kovlet-session": "any",
        "security": [
          {
            "sessionToken": [],
            "deviceProof": []
          },
          {
            "sessionToken": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "asks"
                ],
                "properties": {
                  "asks": {
                    "type": "array",
                    "minItems": 1,
                    "maxItems": 20,
                    "items": {
                      "$ref": "#/components/schemas/GrantAsk"
                    }
                  },
                  "redirect_uri": {
                    "type": "string",
                    "description": "One of the app's registered redirect URIs. After the decision the browser goes to `redirect_uri?state=&result=approved|denied`."
                  },
                  "state": {
                    "type": "string",
                    "maxLength": 512,
                    "description": "Echoed on the redirect."
                  }
                }
              },
              "example": {
                "asks": [
                  {
                    "role": "editor",
                    "slot": "archive",
                    "suggested_name": "Archive"
                  }
                ]
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "The request.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "request",
                    "approve_url",
                    "expires_in",
                    "interval"
                  ],
                  "properties": {
                    "request": {
                      "type": "string",
                      "description": "The request's secret ID (`kvg_...`)."
                    },
                    "approve_url": {
                      "type": "string",
                      "description": "Kovlet's approve page for this request."
                    },
                    "expires_in": {
                      "type": "integer",
                      "description": "Seconds the request stays pending."
                    },
                    "interval": {
                      "type": "integer",
                      "description": "Seconds between polls."
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "`invalid_request`: no asks or more than 20, a role that is not viewer or editor, a bad slot name, or a field too long.\n`invalid_redirect_uri`: `redirect_uri` is not registered for the app.\n",
            "x-kovlet-error-codes": [
              "invalid_request",
              "invalid_redirect_uri"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "description": "`app_session_required`: not an app session.\n`not_a_member`: the session's machine has no owner who could approve.\n`space_bound_machine`: a machine key a partner minted for one space can't ask for more.\n",
            "x-kovlet-error-codes": [
              "app_session_required",
              "not_a_member",
              "space_bound_machine"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/v1/grant-requests/{request}": {
      "get": {
        "operationId": "getGrantRequest",
        "tags": [
          "spaces"
        ],
        "summary": "Poll a grant request",
        "description": "**Auth:** app session with the same user, machine and app as the\nsession that created the request (a refresh rotation keeps it);\nanyone else gets 404.\n",
        "x-kovlet-session": "any",
        "security": [
          {
            "sessionToken": [],
            "deviceProof": []
          },
          {
            "sessionToken": []
          }
        ],
        "parameters": [
          {
            "name": "request",
            "in": "path",
            "required": true,
            "description": "The request (`kvg_...`).",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The request's status and, once approved, the spaces granted.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "status",
                    "spaces"
                  ],
                  "properties": {
                    "status": {
                      "type": "string",
                      "enum": [
                        "pending",
                        "approved",
                        "denied",
                        "expired"
                      ]
                    },
                    "spaces": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/GrantResult"
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "description": "`app_session_required`: not an app session.",
            "x-kovlet-error-codes": [
              "app_session_required"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "`unknown_grant_request`: unknown, expired and deleted, or another principal's request.",
            "x-kovlet-error-codes": [
              "unknown_grant_request"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/v1/grant-requests/{request}/review": {
      "get": {
        "operationId": "reviewGrantRequest",
        "tags": [
          "spaces"
        ],
        "summary": "What the /approve page shows",
        "description": "**Auth:** console session of the request's acting user; anyone else,\nworkspace admins included, gets 404.\n\nThe app, the machine, the asks, the spaces the user could grant (with\nwhat the app already holds), the suggested new space and the default\nchoice per ask, and what an admin must still approve.\n",
        "x-kovlet-session": "console",
        "security": [
          {
            "sessionToken": [],
            "deviceProof": []
          },
          {
            "sessionToken": []
          }
        ],
        "parameters": [
          {
            "name": "request",
            "in": "path",
            "required": true,
            "description": "The request (`kvg_...`).",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The review.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/GrantReview"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "$ref": "#/components/responses/ConsoleRequired"
          },
          "404": {
            "description": "`unknown_grant_request`: unknown, expired, or not this user's request.",
            "x-kovlet-error-codes": [
              "unknown_grant_request"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/v1/grant-requests/{request}/decision": {
      "post": {
        "operationId": "decideGrantRequest",
        "tags": [
          "spaces"
        ],
        "summary": "Approve or deny a grant request",
        "description": "**Auth:** console session of the request's acting user; anyone else gets 404.\n\nApproving needs at least one grant; each is an existing space the\nuser holds at least the granted role on (a headless target: in its\nmachine's workspace only) or a new space (`create`). Grants are never\nlowered. Grants, new spaces, slot merges, access events and the\nrequest's status are written in one transaction; any failure leaves\nthe request pending.\n",
        "x-kovlet-session": "console",
        "security": [
          {
            "sessionToken": [],
            "deviceProof": []
          },
          {
            "sessionToken": []
          }
        ],
        "parameters": [
          {
            "name": "request",
            "in": "path",
            "required": true,
            "description": "The request (`kvg_...`).",
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "approve"
                ],
                "properties": {
                  "approve": {
                    "type": "boolean"
                  },
                  "grants": {
                    "type": [
                      "array",
                      "null"
                    ],
                    "maxItems": 20,
                    "items": {
                      "$ref": "#/components/schemas/GrantChoice"
                    }
                  }
                }
              },
              "example": {
                "approve": false
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The decision.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "status",
                    "spaces"
                  ],
                  "properties": {
                    "status": {
                      "type": "string",
                      "enum": [
                        "approved",
                        "denied"
                      ]
                    },
                    "spaces": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/GrantResult"
                      }
                    },
                    "redirect_to": {
                      "type": "string",
                      "description": "Where to send the browser, when the app gave a `redirect_uri`."
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "`invalid_request`: no grants on approve, a grant with neither or both of `space_id` and `create`, an unknown space, a bad role or ask index, or an invalid space name.",
            "x-kovlet-error-codes": [
              "invalid_request"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "402": {
            "$ref": "#/components/responses/QuotaExceeded"
          },
          "403": {
            "description": "`console_required`: not a console session.\n`access_denied`: a grant is above the user's own role on the space.\n`app_revoked`, `machine_revoked`: the app or machine was revoked meanwhile.\n",
            "x-kovlet-error-codes": [
              "console_required",
              "access_denied",
              "app_revoked",
              "machine_revoked"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "`unknown_grant_request`: unknown, expired, or not this user's request.",
            "x-kovlet-error-codes": [
              "unknown_grant_request"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "`grant_request_decided`: the request was already approved or denied.",
            "x-kovlet-error-codes": [
              "grant_request_decided"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/v1/spaces/{id}": {
      "get": {
        "operationId": "getSpace",
        "tags": [
          "spaces"
        ],
        "summary": "Get a Data Space",
        "description": "**Auth:** console session; any role on the space (viewer or above).\nSpaces the caller has no role on answer 404.\n",
        "x-kovlet-session": "console",
        "x-kovlet-space-role": "viewer",
        "security": [
          {
            "sessionToken": [],
            "deviceProof": []
          },
          {
            "sessionToken": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "Data Space ID.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The space with the caller's effective role.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SpaceView"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "description": "`console_required`: not a console session.\nPolicy denials (the code is the reason): `machine_revoked`, `machine_not_approved`\n(the space or workspace requires approved machines), `unknown_principal`.\n",
            "x-kovlet-error-codes": [
              "console_required",
              "machine_revoked",
              "machine_not_approved",
              "unknown_principal"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      },
      "patch": {
        "operationId": "updateSpace",
        "tags": [
          "spaces"
        ],
        "summary": "Update a Data Space",
        "description": "**Auth:** console session; owner of the space.\n\nOmitted fields are unchanged. Live sync sessions that lose access\nare ended.\n",
        "x-kovlet-session": "console",
        "x-kovlet-space-role": "owner",
        "security": [
          {
            "sessionToken": [],
            "deviceProof": []
          },
          {
            "sessionToken": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "Data Space ID.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "name": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 100,
                    "description": "1 to 100 characters after trimming."
                  },
                  "slug": {
                    "type": "string",
                    "pattern": "^[a-z0-9]+(-[a-z0-9]+)*$",
                    "description": "URL slug, unique in the workspace."
                  },
                  "icon": {
                    "type": "string",
                    "description": "An emoji or up to 16 characters without spaces; empty clears it."
                  },
                  "entire_org_role": {
                    "type": "string",
                    "enum": [
                      "",
                      "viewer",
                      "editor"
                    ],
                    "description": "Role every member of the organization workspace gets (`\"\"` = none); non-empty only for organization workspaces."
                  },
                  "require_approved_apps": {
                    "type": "boolean"
                  },
                  "require_approved_machines": {
                    "type": "boolean"
                  }
                }
              },
              "example": {
                "name": "Finance 2027",
                "entire_org_role": "viewer"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The updated space.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SpaceView"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/InvalidRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "description": "`console_required`: not a console session.\nPolicy denials (the code is the reason): `insufficient_role` (not an owner),\n`machine_revoked`, `machine_not_approved`, `unknown_principal`.\n",
            "x-kovlet-error-codes": [
              "console_required",
              "insufficient_role",
              "machine_revoked",
              "machine_not_approved",
              "unknown_principal"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "description": "`conflict`: the slug is already taken in the workspace.",
            "x-kovlet-error-codes": [
              "conflict"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      },
      "delete": {
        "operationId": "deleteSpace",
        "tags": [
          "spaces"
        ],
        "summary": "Delete a Data Space",
        "description": "**Auth:** console session; owner of the space. Deletes the space with its tables, rows, files and grants.",
        "x-kovlet-session": "console",
        "x-kovlet-space-role": "owner",
        "security": [
          {
            "sessionToken": [],
            "deviceProof": []
          },
          {
            "sessionToken": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "Data Space ID.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "204": {
            "description": "Deleted."
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "description": "`console_required`: not a console session.\nPolicy denials (the code is the reason): `insufficient_role` (not an owner),\n`machine_revoked`, `machine_not_approved`, `unknown_principal`.\n",
            "x-kovlet-error-codes": [
              "console_required",
              "insufficient_role",
              "machine_revoked",
              "machine_not_approved",
              "unknown_principal"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/v1/spaces/{id}/members": {
      "get": {
        "operationId": "listSpaceMembers",
        "tags": [
          "spaces"
        ],
        "summary": "List the people a space is shared with",
        "description": "**Auth:** console session; any role on the space.\n\nLists user grants: workspace members and external guests (pending\nand accepted), plus the space's `entire_org_role`.\n",
        "x-kovlet-session": "console",
        "x-kovlet-space-role": "viewer",
        "security": [
          {
            "sessionToken": [],
            "deviceProof": []
          },
          {
            "sessionToken": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "Data Space ID.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The members.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "members",
                    "entire_org_role"
                  ],
                  "properties": {
                    "members": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/SpaceMember"
                      }
                    },
                    "entire_org_role": {
                      "type": "string",
                      "enum": [
                        "",
                        "viewer",
                        "editor"
                      ],
                      "description": "Role every member of the organization workspace gets (`\"\"` = none)."
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "description": "`console_required`: not a console session.\nPolicy denials (the code is the reason): `machine_revoked`, `machine_not_approved`, `unknown_principal`.\n",
            "x-kovlet-error-codes": [
              "console_required",
              "machine_revoked",
              "machine_not_approved",
              "unknown_principal"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      },
      "post": {
        "operationId": "shareSpace",
        "tags": [
          "spaces"
        ],
        "summary": "Share a space with someone by email",
        "description": "**Auth:** console session; owner of the space.\n\nA member of the space's workspace gets a regular, immediately\naccepted grant. Anyone else is invited as an external guest\n(viewer or editor only) who must accept (`POST /v1/invites/{gid}/accept`)\nbefore the grant applies; guests count against the per-space\n`guests` quota. The recipient is emailed; `notified` says whether the\nmail provider accepted it (a failed email never undoes the share).\n",
        "x-kovlet-session": "console",
        "x-kovlet-space-role": "owner",
        "security": [
          {
            "sessionToken": [],
            "deviceProof": []
          },
          {
            "sessionToken": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "Data Space ID.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "email",
                  "role"
                ],
                "properties": {
                  "email": {
                    "type": "string",
                    "format": "email"
                  },
                  "role": {
                    "type": "string",
                    "enum": [
                      "viewer",
                      "editor",
                      "owner"
                    ],
                    "description": "`owner` only for members of the space's workspace."
                  }
                }
              },
              "example": {
                "email": "pat@example.org",
                "role": "editor"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "The new grant (with `notified`).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SpaceMember"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/InvalidRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "402": {
            "$ref": "#/components/responses/QuotaExceeded"
          },
          "403": {
            "description": "`console_required`: not a console session.\nPolicy denials (the code is the reason): `insufficient_role` (not an owner),\n`machine_revoked`, `machine_not_approved`, `unknown_principal`.\n",
            "x-kovlet-error-codes": [
              "console_required",
              "insufficient_role",
              "machine_revoked",
              "machine_not_approved",
              "unknown_principal"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "description": "`already_shared`: this person already has access or is already invited; change their role instead.",
            "x-kovlet-error-codes": [
              "already_shared"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/v1/spaces/{id}/members/{gid}": {
      "patch": {
        "operationId": "updateSpaceMember",
        "tags": [
          "spaces"
        ],
        "summary": "Change a member's role on a space",
        "description": "**Auth:** console session; owner of the space.\n\nExternal guests can be viewer or editor, not owner. A space keeps at\nleast one owner.\n",
        "x-kovlet-session": "console",
        "x-kovlet-space-role": "owner",
        "security": [
          {
            "sessionToken": [],
            "deviceProof": []
          },
          {
            "sessionToken": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "Data Space ID.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "gid",
            "in": "path",
            "required": true,
            "description": "User grant ID (`id` of a space member).",
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "role"
                ],
                "properties": {
                  "role": {
                    "type": "string",
                    "enum": [
                      "viewer",
                      "editor",
                      "owner"
                    ]
                  }
                }
              },
              "example": {
                "role": "viewer"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The updated grant.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SpaceMember"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/InvalidRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "description": "`console_required`: not a console session.\nPolicy denials (the code is the reason): `insufficient_role` (not an owner),\n`machine_revoked`, `machine_not_approved`, `unknown_principal`.\n",
            "x-kovlet-error-codes": [
              "console_required",
              "insufficient_role",
              "machine_revoked",
              "machine_not_approved",
              "unknown_principal"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "description": "`last_owner`: the change would leave the space without an owner.\n`concurrent_modification`: the grant was changed concurrently; reload and try again.\n",
            "x-kovlet-error-codes": [
              "last_owner",
              "concurrent_modification"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      },
      "delete": {
        "operationId": "removeSpaceMember",
        "tags": [
          "spaces"
        ],
        "summary": "Remove a member or withdraw an invite",
        "description": "**Auth:** console session; owner of the space. A space keeps at least one owner.",
        "x-kovlet-session": "console",
        "x-kovlet-space-role": "owner",
        "security": [
          {
            "sessionToken": [],
            "deviceProof": []
          },
          {
            "sessionToken": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "Data Space ID.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "gid",
            "in": "path",
            "required": true,
            "description": "User grant ID (`id` of a space member).",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "204": {
            "description": "Removed."
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "description": "`console_required`: not a console session.\nPolicy denials (the code is the reason): `insufficient_role` (not an owner),\n`machine_revoked`, `machine_not_approved`, `unknown_principal`.\n",
            "x-kovlet-error-codes": [
              "console_required",
              "insufficient_role",
              "machine_revoked",
              "machine_not_approved",
              "unknown_principal"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "description": "`last_owner`: removing this grant would leave the space without an owner.",
            "x-kovlet-error-codes": [
              "last_owner"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/v1/spaces/{id}/apps": {
      "get": {
        "operationId": "listSpaceApps",
        "tags": [
          "spaces"
        ],
        "summary": "List the apps granted access to a space",
        "description": "**Auth:** console session; any role on the space.",
        "x-kovlet-session": "console",
        "x-kovlet-space-role": "viewer",
        "security": [
          {
            "sessionToken": [],
            "deviceProof": []
          },
          {
            "sessionToken": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "Data Space ID.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The app grants.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "apps"
                  ],
                  "properties": {
                    "apps": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/SpaceAppGrant"
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "description": "`console_required`: not a console session.\nPolicy denials (the code is the reason): `machine_revoked`, `machine_not_approved`, `unknown_principal`.\n",
            "x-kovlet-error-codes": [
              "console_required",
              "machine_revoked",
              "machine_not_approved",
              "unknown_principal"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/v1/spaces/{id}/apps/{appId}": {
      "put": {
        "operationId": "putSpaceApp",
        "tags": [
          "spaces"
        ],
        "summary": "Grant an app access to a space",
        "description": "**Auth:** console session; owner of the space.\n\nCreates or replaces the app's grant. `max_role` caps what any user\ncan do on the space through this app. The app must be registered in\nthe space's workspace (otherwise 404).\n",
        "x-kovlet-session": "console",
        "x-kovlet-space-role": "owner",
        "security": [
          {
            "sessionToken": [],
            "deviceProof": []
          },
          {
            "sessionToken": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "Data Space ID.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "appId",
            "in": "path",
            "required": true,
            "description": "Application ID.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "max_role"
                ],
                "properties": {
                  "max_role": {
                    "type": "string",
                    "enum": [
                      "viewer",
                      "editor"
                    ]
                  }
                }
              },
              "example": {
                "max_role": "editor"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The grant.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "app",
                    "max_role"
                  ],
                  "properties": {
                    "app": {
                      "$ref": "#/components/schemas/AppView"
                    },
                    "max_role": {
                      "type": "string",
                      "enum": [
                        "viewer",
                        "editor"
                      ]
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/InvalidRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "description": "`console_required`: not a console session.\nPolicy denials (the code is the reason): `insufficient_role` (not an owner),\n`machine_revoked`, `machine_not_approved`, `unknown_principal`.\n",
            "x-kovlet-error-codes": [
              "console_required",
              "insufficient_role",
              "machine_revoked",
              "machine_not_approved",
              "unknown_principal"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      },
      "delete": {
        "operationId": "deleteSpaceApp",
        "tags": [
          "spaces"
        ],
        "summary": "Remove an app's access to a space",
        "description": "**Auth:** console session; owner of the space. Answers 404 when the app has no grant on the space.",
        "x-kovlet-session": "console",
        "x-kovlet-space-role": "owner",
        "security": [
          {
            "sessionToken": [],
            "deviceProof": []
          },
          {
            "sessionToken": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "Data Space ID.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "appId",
            "in": "path",
            "required": true,
            "description": "Application ID.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "204": {
            "description": "Removed."
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "description": "`console_required`: not a console session.\nPolicy denials (the code is the reason): `insufficient_role` (not an owner),\n`machine_revoked`, `machine_not_approved`, `unknown_principal`.\n",
            "x-kovlet-error-codes": [
              "console_required",
              "insufficient_role",
              "machine_revoked",
              "machine_not_approved",
              "unknown_principal"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/v1/spaces/{id}/machine-grants": {
      "get": {
        "operationId": "listMachineGrants",
        "tags": [
          "spaces"
        ],
        "summary": "List headless machine grants on a space",
        "description": "**Auth:** console session; any role on the space.",
        "x-kovlet-session": "console",
        "x-kovlet-space-role": "viewer",
        "security": [
          {
            "sessionToken": [],
            "deviceProof": []
          },
          {
            "sessionToken": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "Data Space ID.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The machine grants.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "machine_grants"
                  ],
                  "properties": {
                    "machine_grants": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/MachineGrant"
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "description": "`console_required`: not a console session.\nPolicy denials (the code is the reason): `machine_revoked`, `machine_not_approved`, `unknown_principal`.\n",
            "x-kovlet-error-codes": [
              "console_required",
              "machine_revoked",
              "machine_not_approved",
              "unknown_principal"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      },
      "put": {
        "operationId": "putMachineGrant",
        "tags": [
          "spaces"
        ],
        "summary": "Grant a headless machine, for an app, a role on a space",
        "description": "**Auth:** console session; owner of the space.\n\nCreates or replaces the (machine, app) → space grant. The machine\nmust be a headless machine and the app registered in the space's\nworkspace. Headless sessions are capped at editor.\n",
        "x-kovlet-session": "console",
        "x-kovlet-space-role": "owner",
        "security": [
          {
            "sessionToken": [],
            "deviceProof": []
          },
          {
            "sessionToken": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "Data Space ID.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "machine_id",
                  "app_id",
                  "role"
                ],
                "properties": {
                  "space_id": {
                    "type": "string",
                    "description": "Ignored; the path space is used."
                  },
                  "machine_id": {
                    "type": "string",
                    "description": "A headless machine in the space's workspace."
                  },
                  "app_id": {
                    "type": "string",
                    "description": "An app registered in the space's workspace."
                  },
                  "role": {
                    "type": "string",
                    "enum": [
                      "viewer",
                      "editor"
                    ]
                  }
                }
              },
              "example": {
                "machine_id": "01JD6M4V8Z0000000000000003",
                "app_id": "01JD6M4V8Z0000000000000004",
                "role": "viewer"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The grant as written.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "space_id",
                    "machine_id",
                    "app_id",
                    "role"
                  ],
                  "properties": {
                    "space_id": {
                      "type": "string"
                    },
                    "machine_id": {
                      "type": "string"
                    },
                    "app_id": {
                      "type": "string"
                    },
                    "role": {
                      "type": "string",
                      "enum": [
                        "viewer",
                        "editor"
                      ]
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "`invalid_request`: invalid JSON body, a role that is not viewer or editor, a machine that is\nnot a headless machine in the space's workspace, or an app not registered there.\n",
            "x-kovlet-error-codes": [
              "invalid_request"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "description": "`console_required`: not a console session.\n`manage_required`: the caller cannot manage the space.\nPolicy denials (the code is the reason): `insufficient_role` (not an owner),\n`machine_revoked`, `machine_not_approved`, `unknown_principal`.\n",
            "x-kovlet-error-codes": [
              "console_required",
              "manage_required",
              "insufficient_role",
              "machine_revoked",
              "machine_not_approved",
              "unknown_principal"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/v1/spaces/{id}/machine-grants/{mid}/{appId}": {
      "delete": {
        "operationId": "deleteMachineGrant",
        "tags": [
          "spaces"
        ],
        "summary": "Remove a headless machine grant",
        "description": "**Auth:** console session; owner of the space. Answers 404 when there is no such grant.",
        "x-kovlet-session": "console",
        "x-kovlet-space-role": "owner",
        "security": [
          {
            "sessionToken": [],
            "deviceProof": []
          },
          {
            "sessionToken": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "Data Space ID.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "mid",
            "in": "path",
            "required": true,
            "description": "Machine ID.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "appId",
            "in": "path",
            "required": true,
            "description": "Application ID.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "204": {
            "description": "Removed."
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "description": "`console_required`: not a console session.\nPolicy denials (the code is the reason): `insufficient_role` (not an owner),\n`machine_revoked`, `machine_not_approved`, `unknown_principal`.\n",
            "x-kovlet-error-codes": [
              "console_required",
              "insufficient_role",
              "machine_revoked",
              "machine_not_approved",
              "unknown_principal"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/v1/usage": {
      "get": {
        "operationId": "getAppUsage",
        "tags": [
          "usage"
        ],
        "summary": "Plan usage signals for the calling app or session",
        "description": "**Auth:** any session (app, headless machine or console).\n\nThe usage of the session's workspace against its plan, one entry per\nmetric with a `state` (`ok`, `near` at 80% of the soft limit, `over`\nat the limit), so an app can warn its user before writes are paused.\nWith `space_id`, reports the workspace that owns that space (the\ncaller needs read access to it) and adds the per-space `guests`\nmetric. Rows have a soft limit (the plan's included amount) and a hard\nlimit 10% above it: `soft_limit` is set when the two differ.\n",
        "x-kovlet-session": "any",
        "security": [
          {
            "sessionToken": [],
            "deviceProof": []
          },
          {
            "sessionToken": []
          }
        ],
        "parameters": [
          {
            "name": "space_id",
            "in": "query",
            "required": false,
            "description": "Report for the workspace that owns this space, including its guests.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The usage report.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AppUsage"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "description": "`forbidden`: the session cannot read `space_id`.",
            "x-kovlet-error-codes": [
              "forbidden"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "`not_found`: `space_id` does not exist, or the session has no workspace.",
            "x-kovlet-error-codes": [
              "not_found"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/v1/workspace/usage": {
      "get": {
        "operationId": "getWorkspaceUsage",
        "tags": [
          "usage"
        ],
        "summary": "Usage of the session's workspace against its plan limits",
        "description": "**Auth:** console session.\n\nMeasures every quota metric of the workspace the session signed in\nto. `limit` is null for unlimited metrics. `warning` is set at 75 %,\n`critical` at 90 %, `exceeded` at the limit.\n",
        "x-kovlet-session": "console",
        "security": [
          {
            "sessionToken": [],
            "deviceProof": []
          },
          {
            "sessionToken": []
          }
        ],
        "responses": {
          "200": {
            "description": "The usage report.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/UsageReport"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "$ref": "#/components/responses/ConsoleRequired"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/v1/upgrade-requests": {
      "post": {
        "operationId": "createUpgradeRequest",
        "tags": [
          "usage"
        ],
        "summary": "Ask for higher limits (contact-form upgrade)",
        "description": "**Auth:** none needed. A bearer token is optional: when sent it must\nbe a valid session with a user (otherwise 401), and the request is\nthen tied to the user and workspace, takes the email from the\naccount, and records a usage snapshot.\n\nSigned-out requests need `email` and `company`. Only one pending\nrequest is kept per workspace (per email when signed out): a repeat\nanswers 200 with the existing request and `duplicate: true`. Rate\nlimited per rolling hour: 3 signed-out requests per client address\nor email, 5 signed-in requests per email.\n",
        "x-kovlet-session": "none",
        "security": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "email": {
                    "type": "string",
                    "format": "email",
                    "description": "Required when signed out; ignored when signed in."
                  },
                  "tier": {
                    "type": "string",
                    "enum": [
                      "pro",
                      "org",
                      "custom"
                    ],
                    "default": "pro"
                  },
                  "team_size": {
                    "type": "string",
                    "enum": [
                      "1",
                      "2-5",
                      "6-20",
                      "21-100",
                      "100+"
                    ]
                  },
                  "app_count": {
                    "type": "string",
                    "enum": [
                      "1-3",
                      "4-10",
                      "11-30",
                      "30+"
                    ]
                  },
                  "company": {
                    "type": "string",
                    "maxLength": 200,
                    "description": "What you're building; required when signed out."
                  },
                  "notes": {
                    "type": "string",
                    "maxLength": 2000
                  },
                  "source": {
                    "type": "string",
                    "description": "Where the form was opened (`nudge`, `hard_cap`, `usage_page`, `landing`, `direct`); other values become `direct`."
                  },
                  "metric": {
                    "type": "string",
                    "description": "The limit that prompted the request (`spaces`, `rows`, `storage`, `machines`, `guests`); other values are dropped."
                  },
                  "website": {
                    "type": "string",
                    "description": "Honeypot; leave empty. A filled value gets a normal-looking 201 and nothing is stored."
                  }
                }
              },
              "example": {
                "email": "sam@acme.com",
                "tier": "pro",
                "team_size": "2-5",
                "company": "Acme budgeting tools",
                "source": "usage_page",
                "metric": "rows"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "The request was stored.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/UpgradeRequestView"
                }
              }
            }
          },
          "200": {
            "description": "A pending request already existed; it is returned and nothing new is stored (`duplicate` is true).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/UpgradeRequestView"
                }
              }
            }
          },
          "400": {
            "description": "`invalid_request`: invalid JSON body, or invalid fields; `fields` maps each invalid field\nto a message shown next to it.\n",
            "x-kovlet-error-codes": [
              "invalid_request"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/UpgradeRequestError"
                }
              }
            }
          },
          "401": {
            "description": "`unauthenticated`: a bearer token was sent but is invalid, expired or revoked (or a\ndevice-bound session sent no valid device proof), or the session has no user.\n",
            "x-kovlet-error-codes": [
              "unauthenticated"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "`rate_limited`: too many requests in the last hour; retry after `retry_after` seconds.",
            "x-kovlet-error-codes": [
              "rate_limited"
            ],
            "headers": {
              "Retry-After": {
                "description": "Seconds to wait (600).",
                "schema": {
                  "type": "integer"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/UpgradeRateLimitedError"
                }
              }
            }
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/v1/contact": {
      "post": {
        "operationId": "sendContactMessage",
        "tags": [
          "contact"
        ],
        "summary": "Send a message through the public contact form",
        "description": "**Auth:** none.\n\nEmails the message to the operator's mailbox (`KOVLET_CONTACT_EMAIL`,\ndefault `contact@kovlet.com`) with `email` as the Reply-To address.\nNothing is stored. Rate limited in memory per rolling hour: 5\nmessages per client address and per email.\n",
        "x-kovlet-session": "none",
        "security": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "email",
                  "message"
                ],
                "properties": {
                  "name": {
                    "type": "string",
                    "maxLength": 100
                  },
                  "email": {
                    "type": "string",
                    "format": "email",
                    "description": "Where the reply goes."
                  },
                  "subject": {
                    "type": "string",
                    "maxLength": 200
                  },
                  "message": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 5000
                  },
                  "website": {
                    "type": "string",
                    "description": "Honeypot; leave empty. A filled value gets a normal-looking 200 and nothing is sent."
                  }
                }
              },
              "example": {
                "name": "Sam",
                "email": "sam@acme.com",
                "subject": "A question",
                "message": "Hello!"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The message was handed to the mail provider.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "status",
                    "email"
                  ],
                  "properties": {
                    "status": {
                      "type": "string",
                      "const": "sent"
                    },
                    "email": {
                      "type": "string",
                      "description": "The normalized address the reply goes to."
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "`invalid_request`: invalid JSON body, or invalid fields; `fields` maps each invalid field\nto a message shown next to it.\n",
            "x-kovlet-error-codes": [
              "invalid_request"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/UpgradeRequestError"
                }
              }
            }
          },
          "429": {
            "description": "`rate_limited`: too many messages in the last hour; retry after `retry_after` seconds.",
            "x-kovlet-error-codes": [
              "rate_limited"
            ],
            "headers": {
              "Retry-After": {
                "description": "Seconds to wait (600).",
                "schema": {
                  "type": "integer"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/UpgradeRateLimitedError"
                }
              }
            }
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          },
          "503": {
            "description": "`unavailable`: the mail provider refused the message; the message names the address to email instead.",
            "x-kovlet-error-codes": [
              "unavailable"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/invites": {
      "get": {
        "operationId": "listInvites",
        "tags": [
          "invites"
        ],
        "summary": "List the caller's pending guest invites",
        "description": "**Auth:** console session.\n\nPending external-guest invites to the signed-in user's email address.\n",
        "x-kovlet-session": "console",
        "security": [
          {
            "sessionToken": [],
            "deviceProof": []
          },
          {
            "sessionToken": []
          }
        ],
        "responses": {
          "200": {
            "description": "The invites.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "invites"
                  ],
                  "properties": {
                    "invites": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/GuestInvite"
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "$ref": "#/components/responses/ConsoleRequired"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/v1/invites/{gid}/accept": {
      "post": {
        "operationId": "acceptInvite",
        "tags": [
          "invites"
        ],
        "summary": "Accept a guest invite",
        "description": "**Auth:** console session; the invite must be addressed to the\nsigned-in user's email (otherwise 404). The grant applies at once.\n",
        "x-kovlet-session": "console",
        "security": [
          {
            "sessionToken": [],
            "deviceProof": []
          },
          {
            "sessionToken": []
          }
        ],
        "parameters": [
          {
            "name": "gid",
            "in": "path",
            "required": true,
            "description": "Invite (user grant) ID.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The accepted grant.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "id",
                    "space_id",
                    "role",
                    "accepted"
                  ],
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "Grant ID."
                    },
                    "space_id": {
                      "type": "string"
                    },
                    "role": {
                      "type": "string",
                      "enum": [
                        "viewer",
                        "editor"
                      ]
                    },
                    "accepted": {
                      "type": "boolean",
                      "const": true
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "$ref": "#/components/responses/ConsoleRequired"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "description": "`concurrent_modification`: the invite was changed concurrently; reload and try again.",
            "x-kovlet-error-codes": [
              "concurrent_modification"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/v1/invites/{gid}/decline": {
      "post": {
        "operationId": "declineInvite",
        "tags": [
          "invites"
        ],
        "summary": "Decline a guest invite",
        "description": "**Auth:** console session; the invite must be addressed to the\nsigned-in user's email (otherwise 404). Deletes the invite.\n",
        "x-kovlet-session": "console",
        "security": [
          {
            "sessionToken": [],
            "deviceProof": []
          },
          {
            "sessionToken": []
          }
        ],
        "parameters": [
          {
            "name": "gid",
            "in": "path",
            "required": true,
            "description": "Invite (user grant) ID.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "204": {
            "description": "Declined."
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "$ref": "#/components/responses/ConsoleRequired"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/v1/sync": {
      "get": {
        "operationId": "openSyncSocket",
        "tags": [
          "sync"
        ],
        "summary": "Open a sync WebSocket session",
        "description": "**Auth:** none at the HTTP level. The session token goes in the first\nframe (`hello.token`), not in a header or cookie: browsers cannot set\nheaders on a WebSocket upgrade. The server authenticates and\nauthorizes the `hello` and answers an `error` frame and a close code\nif it fails.\n\nUpgrades the connection to a WebSocket (RFC 6455) that carries the\nsync protocol: `hello`, `snapshot`, `delta`, `mutate`, `ack`,\n`broadcast`, `ping`/`pong` and `error` frames. Row writes and file\nmetadata writes (put, move, delete, restore) go through this socket.\nThe frames, merge rules, limits and close codes are specified in the\nprotocol reference (https://kovlet.com/docs/protocol, source\ndocs/PROTOCOL.md, linked from https://kovlet.com/llms.txt); JSON\nSchemas for every frame are in `packages/protocol/schema`\n(`@kovlet/protocol/schema/*`).\n\nAny `Origin` may connect. Requests that are not a valid WebSocket\nhandshake are refused before any frame is read (`400`/`426`,\n`text/plain`). While the server drains for shutdown it answers\n`503 shutting_down`; reconnect (with backoff) after `Retry-After`.\n",
        "externalDocs": {
          "description": "Kovlet sync protocol reference (v1)",
          "url": "https://kovlet.com/docs/protocol"
        },
        "x-kovlet-session": "none",
        "security": [],
        "parameters": [
          {
            "name": "Connection",
            "in": "header",
            "required": true,
            "description": "Must contain the token `Upgrade`.",
            "schema": {
              "type": "string",
              "example": "Upgrade"
            }
          },
          {
            "name": "Upgrade",
            "in": "header",
            "required": true,
            "description": "Must contain the token `websocket`.",
            "schema": {
              "type": "string",
              "example": "websocket"
            }
          },
          {
            "name": "Sec-WebSocket-Version",
            "in": "header",
            "required": true,
            "description": "Must be `13`.",
            "schema": {
              "type": "string",
              "const": "13"
            }
          },
          {
            "name": "Sec-WebSocket-Key",
            "in": "header",
            "required": true,
            "description": "Exactly one header holding a base64-encoded 16-byte nonce (RFC 6455 §4.1).",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "101": {
            "description": "Switching Protocols: the connection is now a WebSocket. Send\n`hello` as the first frame (see the protocol reference).\n",
            "headers": {
              "Upgrade": {
                "schema": {
                  "type": "string",
                  "const": "websocket"
                }
              },
              "Connection": {
                "schema": {
                  "type": "string",
                  "const": "Upgrade"
                }
              },
              "Sec-WebSocket-Accept": {
                "description": "The RFC 6455 accept hash of `Sec-WebSocket-Key`.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "description": "Not a valid WebSocket handshake: `Sec-WebSocket-Version` is not\n`13` (the response then carries `Sec-WebSocket-Version: 13`), or\n`Sec-WebSocket-Key` is missing, repeated or not a base64 16-byte\nvalue. Plain-text message, no error envelope.\n",
            "headers": {
              "Sec-WebSocket-Version": {
                "description": "`13`, when the requested version was refused.",
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "text/plain": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "426": {
            "description": "Upgrade Required: the request is not a WebSocket upgrade\n(`Connection` lacks `Upgrade`, `Upgrade` lacks `websocket`, or the\nrequest is older than HTTP/1.1). Plain-text message, no error\nenvelope.\n",
            "headers": {
              "Upgrade": {
                "schema": {
                  "type": "string",
                  "const": "websocket"
                }
              },
              "Connection": {
                "schema": {
                  "type": "string",
                  "const": "Upgrade"
                }
              }
            },
            "content": {
              "text/plain": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          },
          "503": {
            "description": "`shutting_down`: the server is draining for shutdown; reconnect.",
            "x-kovlet-error-codes": [
              "shutting_down"
            ],
            "headers": {
              "Retry-After": {
                "description": "Seconds to wait before reconnecting (`1`).",
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/spaces/{space}/tables": {
      "parameters": [
        {
          "name": "space",
          "in": "path",
          "required": true,
          "description": "The Data Space ID.",
          "schema": {
            "type": "string"
          }
        }
      ],
      "get": {
        "operationId": "listSpaceTables",
        "tags": [
          "schema"
        ],
        "summary": "Get the space's current schema",
        "description": "**Auth:** any session with at least the viewer role on the space.\n\nReturns every table of the space with its columns, declared column\norder and version.\n",
        "x-kovlet-session": "any",
        "x-kovlet-space-role": "viewer",
        "security": [
          {
            "sessionToken": [],
            "deviceProof": []
          },
          {
            "sessionToken": []
          }
        ],
        "responses": {
          "200": {
            "description": "The space's tables, keyed by table name.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "tables"
                  ],
                  "properties": {
                    "tables": {
                      "$ref": "#/components/schemas/Tables"
                    }
                  }
                },
                "example": {
                  "tables": {
                    "expenses": {
                      "version": 3,
                      "columns": {
                        "amount": {
                          "type": "number"
                        },
                        "note": {
                          "type": "string",
                          "optional": true
                        },
                        "receipt": {
                          "type": "file_ref",
                          "optional": true
                        }
                      },
                      "order": [
                        "amount",
                        "note",
                        "receipt"
                      ]
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "description": "Access to the space is denied (the code is the policy's denial\nreason):\n`insufficient_role`: the effective role on the space is below the\none this operation needs (see `x-kovlet-space-role`), or there is none.\n`scope_required`: manage actions (owner operations), and sessions\nwithout an app, need a console or admin scope.\n`no_user_grant`: the user has no role on the space.\n`no_app_grant`: the app has no grant on the space.\n`no_machine_grant`: a headless (machine, app) session has no machine grant on the space.\n`machine_revoked` / `machine_not_approved`: the machine is revoked,\nor not approved where the space or workspace requires approved machines.\n`app_revoked` / `app_not_approved`: the app is revoked, or not\napproved where the space or workspace requires approved apps.\n`origin_mismatch`: the request `Origin` is not one of the app's pinned origins.\n`unknown_principal`: the session's machine, user, app or end user no longer exists.\n`policy_unconfigured`: kovletd runs without a policy evaluator (fail closed).\nApp end users (ADR 0021): `end_user_forbidden`: this route is not\navailable to end users (only `GET .../tables` and `.../records`\nare), or an end user asked for the Trash. `end_users_disabled`:\nend-user sign-in is off for the app on this space.\n`end_user_blocked`: the end user is blocked. `end_user_wrong_space`:\nan end-user session is valid for one space only.\n`impersonation_not_allowed`: `Kovlet-As-End-User` from a session\nthat isn't a machine, or whose machine grant lacks the impersonate flag.\n`forbidden`: the space's rules don't allow reading the table\n(`details.rule`, e.g. `todos.view`).\n",
            "x-kovlet-error-codes": [
              "end_user_forbidden",
              "end_users_disabled",
              "end_user_blocked",
              "end_user_wrong_space",
              "impersonation_not_allowed",
              "forbidden",
              "insufficient_role",
              "scope_required",
              "no_user_grant",
              "no_app_grant",
              "no_machine_grant",
              "machine_revoked",
              "machine_not_approved",
              "app_revoked",
              "app_not_approved",
              "origin_mismatch",
              "unknown_principal",
              "policy_unconfigured"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "`space_not_found`: the space ID is malformed or no such space exists.",
            "x-kovlet-error-codes": [
              "space_not_found"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/v1/spaces/{space}/schema/changes": {
      "parameters": [
        {
          "name": "space",
          "in": "path",
          "required": true,
          "description": "The Data Space ID.",
          "schema": {
            "type": "string"
          }
        }
      ],
      "post": {
        "operationId": "changeSpaceSchema",
        "tags": [
          "schema"
        ],
        "summary": "Apply explicit schema changes",
        "description": "**Auth:** any session with at least the editor role on the space.\n\nThe whole list must apply cleanly, in order, to the current schema\n(`422 invalid_change` otherwise, and nothing changes). Additive\nchanges (`create_table`, `set_order`, `add_column` of an optional\ncolumn) are committed at once as schema ops. Destructive changes\n(every other op, and `add_column` of a required column) are recorded\nas pending proposals, one per table, for an owner to approve in the\nconsole; the answer is then `202`. An identical pending proposal is\nreused instead of duplicated.\n",
        "x-kovlet-session": "any",
        "x-kovlet-space-role": "editor",
        "security": [
          {
            "sessionToken": [],
            "deviceProof": []
          },
          {
            "sessionToken": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "changes"
                ],
                "properties": {
                  "changes": {
                    "type": "array",
                    "minItems": 1,
                    "description": "The changes, applied in order.",
                    "items": {
                      "$ref": "#/components/schemas/SchemaChangeInput"
                    }
                  }
                }
              },
              "example": {
                "changes": [
                  {
                    "op": "add_column",
                    "table": "expenses",
                    "column": "category",
                    "def": {
                      "type": "string",
                      "optional": true
                    }
                  },
                  {
                    "op": "drop_column",
                    "table": "expenses",
                    "column": "note"
                  }
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Every change was additive and is committed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SchemaChangeResult"
                }
              }
            }
          },
          "202": {
            "description": "Additive changes (if any) are committed; the destructive ones wait\nfor an owner in `proposals` (status `pending`).\n",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SchemaChangeResult"
                }
              }
            }
          },
          "400": {
            "description": "`invalid_frame`: the body is not valid JSON for this operation\n(unknown fields, wrong types, trailing data, over 1 MiB).\n`invalid_change`: `changes` is missing or empty.\n",
            "x-kovlet-error-codes": [
              "invalid_frame",
              "invalid_change"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "description": "Access to the space is denied (the code is the policy's denial\nreason):\n`insufficient_role`: the effective role on the space is below the\none this operation needs (see `x-kovlet-space-role`), or there is none.\n`scope_required`: manage actions (owner operations), and sessions\nwithout an app, need a console or admin scope.\n`no_user_grant`: the user has no role on the space.\n`no_app_grant`: the app has no grant on the space.\n`no_machine_grant`: a headless (machine, app) session has no machine grant on the space.\n`machine_revoked` / `machine_not_approved`: the machine is revoked,\nor not approved where the space or workspace requires approved machines.\n`app_revoked` / `app_not_approved`: the app is revoked, or not\napproved where the space or workspace requires approved apps.\n`origin_mismatch`: the request `Origin` is not one of the app's pinned origins.\n`unknown_principal`: the session's machine, user, app or end user no longer exists.\n`policy_unconfigured`: kovletd runs without a policy evaluator (fail closed).\nApp end users (ADR 0021): `end_user_forbidden`: this route is not\navailable to end users (only `GET .../tables` and `.../records`\nare), or an end user asked for the Trash. `end_users_disabled`:\nend-user sign-in is off for the app on this space.\n`end_user_blocked`: the end user is blocked. `end_user_wrong_space`:\nan end-user session is valid for one space only.\n`impersonation_not_allowed`: `Kovlet-As-End-User` from a session\nthat isn't a machine, or whose machine grant lacks the impersonate flag.\n`forbidden`: the space's rules don't allow reading the table\n(`details.rule`, e.g. `todos.view`).\n",
            "x-kovlet-error-codes": [
              "end_user_forbidden",
              "end_users_disabled",
              "end_user_blocked",
              "end_user_wrong_space",
              "impersonation_not_allowed",
              "forbidden",
              "insufficient_role",
              "scope_required",
              "no_user_grant",
              "no_app_grant",
              "no_machine_grant",
              "machine_revoked",
              "machine_not_approved",
              "app_revoked",
              "app_not_approved",
              "origin_mismatch",
              "unknown_principal",
              "policy_unconfigured"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "`space_not_found`: the space ID is malformed or no such space exists.",
            "x-kovlet-error-codes": [
              "space_not_found"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "`invalid_change`: a change is malformed (unknown op, invalid name,\nmissing `def`, ...) or does not fit the schema it is applied to\n(for example dropping a column that does not exist). Nothing was changed.\n",
            "x-kovlet-error-codes": [
              "invalid_change"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "`trashed_rows_conflict`: a `create_table` would give a dropped\ntable's name a schema again while rows that table left in the\nTrash don't fit it. The error carries `table`, `op`, `count`, up\nto 5 row ids in `examples`, and `first` (why the first one doesn't\nfit). Nothing was changed: declare columns those rows fit.\n",
            "x-kovlet-error-codes": [
              "trashed_rows_conflict"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/v1/spaces/{space}/schema/drop": {
      "parameters": [
        {
          "name": "space",
          "in": "path",
          "required": true,
          "description": "The Data Space ID.",
          "schema": {
            "type": "string"
          }
        }
      ],
      "post": {
        "operationId": "dropSpaceSchema",
        "tags": [
          "schema"
        ],
        "summary": "Drop tables or columns directly (owner)",
        "description": "**Auth:** owner role on the space, from a console (or admin) session.\nApp and headless sessions get `403 scope_required`; editors and\nviewers get `403 insufficient_role`.\n\nAn owner's own `drop_table` and `drop_column` changes, applied at\nonce instead of becoming proposals. They take the same path as an\napproved proposal: a dropped table's live rows go to the Trash\n(purge them with `POST /v1/spaces/{space}/trash/tables/{table}/purge`),\nand a dropped column is removed from every row. No proposal is\nrecorded; a `schema.changed` audit event with `details.direct: true`\nand the `changes` records who applied it. Pending proposals on the\ntable go stale. Other ops (renames included) get `422 invalid_change`:\npropose them with `POST /v1/spaces/{space}/schema/changes`.\n",
        "x-kovlet-session": "any",
        "x-kovlet-space-role": "owner",
        "security": [
          {
            "sessionToken": [],
            "deviceProof": []
          },
          {
            "sessionToken": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "changes"
                ],
                "properties": {
                  "changes": {
                    "type": "array",
                    "minItems": 1,
                    "description": "`drop_table` and `drop_column` changes, applied in order.",
                    "items": {
                      "$ref": "#/components/schemas/SchemaChangeInput"
                    }
                  }
                }
              },
              "example": {
                "changes": [
                  {
                    "op": "drop_column",
                    "table": "expenses",
                    "column": "note"
                  }
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The changes are committed; `proposals` is empty.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SchemaChangeResult"
                }
              }
            }
          },
          "400": {
            "description": "`invalid_request`: the body is not valid JSON for this operation.\n`invalid_change`: `changes` is missing or empty.\n",
            "x-kovlet-error-codes": [
              "invalid_request",
              "invalid_change"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "description": "Access to the space is denied (the code is the policy's denial\nreason):\n`insufficient_role`: the effective role on the space is below the\none this operation needs (see `x-kovlet-space-role`), or there is none.\n`scope_required`: manage actions (owner operations), and sessions\nwithout an app, need a console or admin scope.\n`no_user_grant`: the user has no role on the space.\n`no_app_grant`: the app has no grant on the space.\n`no_machine_grant`: a headless (machine, app) session has no machine grant on the space.\n`machine_revoked` / `machine_not_approved`: the machine is revoked,\nor not approved where the space or workspace requires approved machines.\n`app_revoked` / `app_not_approved`: the app is revoked, or not\napproved where the space or workspace requires approved apps.\n`origin_mismatch`: the request `Origin` is not one of the app's pinned origins.\n`unknown_principal`: the session's machine, user, app or end user no longer exists.\n`policy_unconfigured`: kovletd runs without a policy evaluator (fail closed).\nApp end users (ADR 0021): `end_user_forbidden`: this route is not\navailable to end users (only `GET .../tables` and `.../records`\nare), or an end user asked for the Trash. `end_users_disabled`:\nend-user sign-in is off for the app on this space.\n`end_user_blocked`: the end user is blocked. `end_user_wrong_space`:\nan end-user session is valid for one space only.\n`impersonation_not_allowed`: `Kovlet-As-End-User` from a session\nthat isn't a machine, or whose machine grant lacks the impersonate flag.\n`forbidden`: the space's rules don't allow reading the table\n(`details.rule`, e.g. `todos.view`).\n",
            "x-kovlet-error-codes": [
              "end_user_forbidden",
              "end_users_disabled",
              "end_user_blocked",
              "end_user_wrong_space",
              "impersonation_not_allowed",
              "forbidden",
              "insufficient_role",
              "scope_required",
              "no_user_grant",
              "no_app_grant",
              "no_machine_grant",
              "machine_revoked",
              "machine_not_approved",
              "app_revoked",
              "app_not_approved",
              "origin_mismatch",
              "unknown_principal",
              "policy_unconfigured"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "`space_not_found`: the space ID is malformed or no such space exists.",
            "x-kovlet-error-codes": [
              "space_not_found"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "`rules_invalid`: the drop would break the space's end-user rules\n(a rule reads the column or table). Nothing was changed.\n",
            "x-kovlet-error-codes": [
              "rules_invalid"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "`invalid_change`: a change is not `drop_table` or `drop_column`, names\na system table, or does not fit the current schema (for example a\ncolumn that does not exist). Nothing was changed.\n",
            "x-kovlet-error-codes": [
              "invalid_change"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/v1/spaces/{space}/schema/proposals": {
      "parameters": [
        {
          "name": "space",
          "in": "path",
          "required": true,
          "description": "The Data Space ID.",
          "schema": {
            "type": "string"
          }
        }
      ],
      "get": {
        "operationId": "listSchemaProposals",
        "tags": [
          "schema"
        ],
        "summary": "List schema proposals",
        "description": "**Auth:** any session with at least the viewer role on the space.\n\nLists the space's destructive schema change proposals, optionally\nfiltered by status.\n",
        "x-kovlet-session": "any",
        "x-kovlet-space-role": "viewer",
        "security": [
          {
            "sessionToken": [],
            "deviceProof": []
          },
          {
            "sessionToken": []
          }
        ],
        "parameters": [
          {
            "name": "status",
            "in": "query",
            "required": false,
            "description": "Only proposals with this status. Empty or absent lists all.",
            "schema": {
              "type": "string",
              "enum": [
                "",
                "pending",
                "approved",
                "rejected",
                "superseded"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The proposals.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "proposals"
                  ],
                  "properties": {
                    "proposals": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/SchemaProposal"
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "`invalid_status`: `status` is not one of the listed values.",
            "x-kovlet-error-codes": [
              "invalid_status"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "description": "Access to the space is denied (the code is the policy's denial\nreason):\n`insufficient_role`: the effective role on the space is below the\none this operation needs (see `x-kovlet-space-role`), or there is none.\n`scope_required`: manage actions (owner operations), and sessions\nwithout an app, need a console or admin scope.\n`no_user_grant`: the user has no role on the space.\n`no_app_grant`: the app has no grant on the space.\n`no_machine_grant`: a headless (machine, app) session has no machine grant on the space.\n`machine_revoked` / `machine_not_approved`: the machine is revoked,\nor not approved where the space or workspace requires approved machines.\n`app_revoked` / `app_not_approved`: the app is revoked, or not\napproved where the space or workspace requires approved apps.\n`origin_mismatch`: the request `Origin` is not one of the app's pinned origins.\n`unknown_principal`: the session's machine, user, app or end user no longer exists.\n`policy_unconfigured`: kovletd runs without a policy evaluator (fail closed).\nApp end users (ADR 0021): `end_user_forbidden`: this route is not\navailable to end users (only `GET .../tables` and `.../records`\nare), or an end user asked for the Trash. `end_users_disabled`:\nend-user sign-in is off for the app on this space.\n`end_user_blocked`: the end user is blocked. `end_user_wrong_space`:\nan end-user session is valid for one space only.\n`impersonation_not_allowed`: `Kovlet-As-End-User` from a session\nthat isn't a machine, or whose machine grant lacks the impersonate flag.\n`forbidden`: the space's rules don't allow reading the table\n(`details.rule`, e.g. `todos.view`).\n",
            "x-kovlet-error-codes": [
              "end_user_forbidden",
              "end_users_disabled",
              "end_user_blocked",
              "end_user_wrong_space",
              "impersonation_not_allowed",
              "forbidden",
              "insufficient_role",
              "scope_required",
              "no_user_grant",
              "no_app_grant",
              "no_machine_grant",
              "machine_revoked",
              "machine_not_approved",
              "app_revoked",
              "app_not_approved",
              "origin_mismatch",
              "unknown_principal",
              "policy_unconfigured"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "`space_not_found`: the space ID is malformed or no such space exists.",
            "x-kovlet-error-codes": [
              "space_not_found"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/v1/spaces/{space}/schema/proposals/{id}": {
      "parameters": [
        {
          "name": "space",
          "in": "path",
          "required": true,
          "description": "The Data Space ID.",
          "schema": {
            "type": "string"
          }
        },
        {
          "name": "id",
          "in": "path",
          "required": true,
          "description": "The schema proposal ID.",
          "schema": {
            "type": "string"
          }
        }
      ],
      "get": {
        "operationId": "getSchemaProposal",
        "tags": [
          "schema"
        ],
        "summary": "Get a schema proposal",
        "description": "**Auth:** any session with at least the viewer role on the space.\n",
        "x-kovlet-session": "any",
        "x-kovlet-space-role": "viewer",
        "security": [
          {
            "sessionToken": [],
            "deviceProof": []
          },
          {
            "sessionToken": []
          }
        ],
        "responses": {
          "200": {
            "description": "The proposal.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SchemaProposal"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "description": "Access to the space is denied (the code is the policy's denial\nreason):\n`insufficient_role`: the effective role on the space is below the\none this operation needs (see `x-kovlet-space-role`), or there is none.\n`scope_required`: manage actions (owner operations), and sessions\nwithout an app, need a console or admin scope.\n`no_user_grant`: the user has no role on the space.\n`no_app_grant`: the app has no grant on the space.\n`no_machine_grant`: a headless (machine, app) session has no machine grant on the space.\n`machine_revoked` / `machine_not_approved`: the machine is revoked,\nor not approved where the space or workspace requires approved machines.\n`app_revoked` / `app_not_approved`: the app is revoked, or not\napproved where the space or workspace requires approved apps.\n`origin_mismatch`: the request `Origin` is not one of the app's pinned origins.\n`unknown_principal`: the session's machine, user, app or end user no longer exists.\n`policy_unconfigured`: kovletd runs without a policy evaluator (fail closed).\nApp end users (ADR 0021): `end_user_forbidden`: this route is not\navailable to end users (only `GET .../tables` and `.../records`\nare), or an end user asked for the Trash. `end_users_disabled`:\nend-user sign-in is off for the app on this space.\n`end_user_blocked`: the end user is blocked. `end_user_wrong_space`:\nan end-user session is valid for one space only.\n`impersonation_not_allowed`: `Kovlet-As-End-User` from a session\nthat isn't a machine, or whose machine grant lacks the impersonate flag.\n`forbidden`: the space's rules don't allow reading the table\n(`details.rule`, e.g. `todos.view`).\n",
            "x-kovlet-error-codes": [
              "end_user_forbidden",
              "end_users_disabled",
              "end_user_blocked",
              "end_user_wrong_space",
              "impersonation_not_allowed",
              "forbidden",
              "insufficient_role",
              "scope_required",
              "no_user_grant",
              "no_app_grant",
              "no_machine_grant",
              "machine_revoked",
              "machine_not_approved",
              "app_revoked",
              "app_not_approved",
              "origin_mismatch",
              "unknown_principal",
              "policy_unconfigured"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "`space_not_found`: the space ID is malformed or no such space exists.\n`proposal_not_found`: no proposal with this ID belongs to the space.\n",
            "x-kovlet-error-codes": [
              "space_not_found",
              "proposal_not_found"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/v1/spaces/{space}/schema/proposals/{id}/approve": {
      "parameters": [
        {
          "name": "space",
          "in": "path",
          "required": true,
          "description": "The Data Space ID.",
          "schema": {
            "type": "string"
          }
        },
        {
          "name": "id",
          "in": "path",
          "required": true,
          "description": "The schema proposal ID.",
          "schema": {
            "type": "string"
          }
        }
      ],
      "post": {
        "operationId": "approveSchemaProposal",
        "tags": [
          "schema"
        ],
        "summary": "Approve and apply a schema proposal",
        "description": "**Auth:** owner role on the space, from a console (or admin) session.\nApp and headless sessions get `403 scope_required`.\n\nApplies the proposal's changes as one forward transaction of schema\nops attributed to the caller. If the table changed since the\nproposal was made, or its changes no longer apply, the proposal is\nmarked `superseded` and the call fails with `409 proposal_stale`.\nNo request body.\n\nA rules proposal (table `_rules`, ADR 0021 §3.1) stores its document\nas the space's new rules version; it is stale when the rules changed\nsince it was made or it no longer validates against the schema.\nEnd users' live subscriptions re-plan under the new rules.\n",
        "x-kovlet-session": "any",
        "x-kovlet-space-role": "owner",
        "security": [
          {
            "sessionToken": [],
            "deviceProof": []
          },
          {
            "sessionToken": []
          }
        ],
        "responses": {
          "200": {
            "description": "The proposal is `approved` and applied; `tables`, `ops` and\n`head_seq` describe the result.\n",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ProposalDecision"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "description": "Access to the space is denied (the code is the policy's denial\nreason):\n`insufficient_role`: the effective role on the space is below the\none this operation needs (see `x-kovlet-space-role`), or there is none.\n`scope_required`: manage actions (owner operations), and sessions\nwithout an app, need a console or admin scope.\n`no_user_grant`: the user has no role on the space.\n`no_app_grant`: the app has no grant on the space.\n`no_machine_grant`: a headless (machine, app) session has no machine grant on the space.\n`machine_revoked` / `machine_not_approved`: the machine is revoked,\nor not approved where the space or workspace requires approved machines.\n`app_revoked` / `app_not_approved`: the app is revoked, or not\napproved where the space or workspace requires approved apps.\n`origin_mismatch`: the request `Origin` is not one of the app's pinned origins.\n`unknown_principal`: the session's machine, user, app or end user no longer exists.\n`policy_unconfigured`: kovletd runs without a policy evaluator (fail closed).\nApp end users (ADR 0021): `end_user_forbidden`: this route is not\navailable to end users (only `GET .../tables` and `.../records`\nare), or an end user asked for the Trash. `end_users_disabled`:\nend-user sign-in is off for the app on this space.\n`end_user_blocked`: the end user is blocked. `end_user_wrong_space`:\nan end-user session is valid for one space only.\n`impersonation_not_allowed`: `Kovlet-As-End-User` from a session\nthat isn't a machine, or whose machine grant lacks the impersonate flag.\n`forbidden`: the space's rules don't allow reading the table\n(`details.rule`, e.g. `todos.view`).\n",
            "x-kovlet-error-codes": [
              "end_user_forbidden",
              "end_users_disabled",
              "end_user_blocked",
              "end_user_wrong_space",
              "impersonation_not_allowed",
              "forbidden",
              "insufficient_role",
              "scope_required",
              "no_user_grant",
              "no_app_grant",
              "no_machine_grant",
              "machine_revoked",
              "machine_not_approved",
              "app_revoked",
              "app_not_approved",
              "origin_mismatch",
              "unknown_principal",
              "policy_unconfigured"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "`space_not_found`: the space ID is malformed or no such space exists.\n`proposal_not_found`: no proposal with this ID belongs to the space.\n",
            "x-kovlet-error-codes": [
              "space_not_found",
              "proposal_not_found"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "`proposal_decided`: the proposal is no longer pending (the\nmessage names its status).\n`proposal_stale`: the table changed since the proposal was made\n(approve only); it is now `superseded`. Propose again against the\ncurrent schema.\n`unique_violation` (approve only): the proposal adds `.unique()` but\nlive rows share values; the error lists them in `duplicates`\n(`[{value, ids}]`). The proposal stays pending: fix the rows and\napprove again.\n`rules_invalid` (approve only): the change drops or renames a\ncolumn the space's end-user rules read. The proposal stays\npending: update the rules first.\n`trashed_rows_conflict` (approve only): a `rename_table` onto the\nname of a dropped table whose rows in the Trash don't fit it\n(`table`, `count`, `examples`, `first`). The proposal stays pending.\n`rows_violate_schema` (approve only): `make_required`,\n`change_type` or a required `add_column` would leave rows\n(trashed ones included) that break the new definition. The error\ncarries `table`, `column`, `op`, `reason` (`required_missing` or\n`type_mismatch`), `type`, `count` and up to 5 row ids in\n`examples`. The proposal stays pending: fix the rows and approve\nagain.\n",
            "x-kovlet-error-codes": [
              "proposal_decided",
              "proposal_stale",
              "unique_violation",
              "rules_invalid",
              "rows_violate_schema",
              "trashed_rows_conflict"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/v1/spaces/{space}/schema/proposals/{id}/reject": {
      "parameters": [
        {
          "name": "space",
          "in": "path",
          "required": true,
          "description": "The Data Space ID.",
          "schema": {
            "type": "string"
          }
        },
        {
          "name": "id",
          "in": "path",
          "required": true,
          "description": "The schema proposal ID.",
          "schema": {
            "type": "string"
          }
        }
      ],
      "post": {
        "operationId": "rejectSchemaProposal",
        "tags": [
          "schema"
        ],
        "summary": "Reject a schema proposal",
        "description": "**Auth:** owner role on the space, from a console (or admin) session.\nApp and headless sessions get `403 scope_required`.\n\nMarks a pending proposal `rejected`; the schema is unchanged. No\nrequest body.\n",
        "x-kovlet-session": "any",
        "x-kovlet-space-role": "owner",
        "security": [
          {
            "sessionToken": [],
            "deviceProof": []
          },
          {
            "sessionToken": []
          }
        ],
        "responses": {
          "200": {
            "description": "The proposal is `rejected`. Only `proposal` is present.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ProposalDecision"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "description": "Access to the space is denied (the code is the policy's denial\nreason):\n`insufficient_role`: the effective role on the space is below the\none this operation needs (see `x-kovlet-space-role`), or there is none.\n`scope_required`: manage actions (owner operations), and sessions\nwithout an app, need a console or admin scope.\n`no_user_grant`: the user has no role on the space.\n`no_app_grant`: the app has no grant on the space.\n`no_machine_grant`: a headless (machine, app) session has no machine grant on the space.\n`machine_revoked` / `machine_not_approved`: the machine is revoked,\nor not approved where the space or workspace requires approved machines.\n`app_revoked` / `app_not_approved`: the app is revoked, or not\napproved where the space or workspace requires approved apps.\n`origin_mismatch`: the request `Origin` is not one of the app's pinned origins.\n`unknown_principal`: the session's machine, user, app or end user no longer exists.\n`policy_unconfigured`: kovletd runs without a policy evaluator (fail closed).\nApp end users (ADR 0021): `end_user_forbidden`: this route is not\navailable to end users (only `GET .../tables` and `.../records`\nare), or an end user asked for the Trash. `end_users_disabled`:\nend-user sign-in is off for the app on this space.\n`end_user_blocked`: the end user is blocked. `end_user_wrong_space`:\nan end-user session is valid for one space only.\n`impersonation_not_allowed`: `Kovlet-As-End-User` from a session\nthat isn't a machine, or whose machine grant lacks the impersonate flag.\n`forbidden`: the space's rules don't allow reading the table\n(`details.rule`, e.g. `todos.view`).\n",
            "x-kovlet-error-codes": [
              "end_user_forbidden",
              "end_users_disabled",
              "end_user_blocked",
              "end_user_wrong_space",
              "impersonation_not_allowed",
              "forbidden",
              "insufficient_role",
              "scope_required",
              "no_user_grant",
              "no_app_grant",
              "no_machine_grant",
              "machine_revoked",
              "machine_not_approved",
              "app_revoked",
              "app_not_approved",
              "origin_mismatch",
              "unknown_principal",
              "policy_unconfigured"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "`space_not_found`: the space ID is malformed or no such space exists.\n`proposal_not_found`: no proposal with this ID belongs to the space.\n",
            "x-kovlet-error-codes": [
              "space_not_found",
              "proposal_not_found"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "`proposal_decided`: the proposal is no longer pending (the message names its status).",
            "x-kovlet-error-codes": [
              "proposal_decided"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/v1/spaces/{space}/rules/proposals": {
      "parameters": [
        {
          "name": "space",
          "in": "path",
          "required": true,
          "description": "The Data Space ID.",
          "schema": {
            "type": "string"
          }
        }
      ],
      "post": {
        "operationId": "proposeSpaceRules",
        "tags": [
          "end-users"
        ],
        "summary": "Propose end-user rules for an owner to approve",
        "description": "**Auth:** any session with at least the editor role on the space\n(apps, the CLI, the MCP server's `propose_rules`).\n\nRules live in code (`kovlet.perms.ts`) and change through the same\nowner approval as destructive schema changes (ADR 0021 §3.1): this\nrecords a pending proposal (table `_rules`) that an owner approves\nwith `POST …/schema/proposals/{id}/approve`. An identical pending\nproposal is returned instead of a new one. The document must\nvalidate against the current schema.\n",
        "x-kovlet-session": "any",
        "x-kovlet-space-role": "editor",
        "security": [
          {
            "sessionToken": [],
            "deviceProof": []
          },
          {
            "sessionToken": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "document"
                ],
                "properties": {
                  "document": {
                    "type": "object",
                    "description": "The rules document (docs/guides/rules.md)."
                  }
                }
              },
              "example": {
                "document": {
                  "todos": {
                    "bind": [
                      "isOwner",
                      "auth.id == data.owner"
                    ],
                    "allow": {
                      "view": "isOwner",
                      "create": "isOwner",
                      "update": "isOwner",
                      "delete": "isOwner"
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The pending proposal.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "proposal"
                  ],
                  "properties": {
                    "proposal": {
                      "$ref": "#/components/schemas/SchemaProposal"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "`invalid_request`: the body has no `document`.",
            "x-kovlet-error-codes": [
              "invalid_request"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "description": "Access to the space is denied (the code is the policy's denial\nreason):\n`insufficient_role`: the effective role on the space is below the\none this operation needs (see `x-kovlet-space-role`), or there is none.\n`scope_required`: manage actions (owner operations), and sessions\nwithout an app, need a console or admin scope.\n`no_user_grant`: the user has no role on the space.\n`no_app_grant`: the app has no grant on the space.\n`no_machine_grant`: a headless (machine, app) session has no machine grant on the space.\n`machine_revoked` / `machine_not_approved`: the machine is revoked,\nor not approved where the space or workspace requires approved machines.\n`app_revoked` / `app_not_approved`: the app is revoked, or not\napproved where the space or workspace requires approved apps.\n`origin_mismatch`: the request `Origin` is not one of the app's pinned origins.\n`unknown_principal`: the session's machine, user, app or end user no longer exists.\n`policy_unconfigured`: kovletd runs without a policy evaluator (fail closed).\nApp end users (ADR 0021): `end_user_forbidden`: this route is not\navailable to end users (only `GET .../tables` and `.../records`\nare), or an end user asked for the Trash. `end_users_disabled`:\nend-user sign-in is off for the app on this space.\n`end_user_blocked`: the end user is blocked. `end_user_wrong_space`:\nan end-user session is valid for one space only.\n`impersonation_not_allowed`: `Kovlet-As-End-User` from a session\nthat isn't a machine, or whose machine grant lacks the impersonate flag.\n`forbidden`: the space's rules don't allow reading the table\n(`details.rule`, e.g. `todos.view`).\n",
            "x-kovlet-error-codes": [
              "end_user_forbidden",
              "end_users_disabled",
              "end_user_blocked",
              "end_user_wrong_space",
              "impersonation_not_allowed",
              "forbidden",
              "insufficient_role",
              "scope_required",
              "no_user_grant",
              "no_app_grant",
              "no_machine_grant",
              "machine_revoked",
              "machine_not_approved",
              "app_revoked",
              "app_not_approved",
              "origin_mismatch",
              "unknown_principal",
              "policy_unconfigured"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "`space_not_found`: the space ID is malformed or no such space exists.",
            "x-kovlet-error-codes": [
              "space_not_found"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "`rules_invalid`: the document doesn't validate; `errors` lists each problem by rule.",
            "x-kovlet-error-codes": [
              "rules_invalid"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RulesError"
                }
              }
            }
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/v1/spaces/{space}/rules/test": {
      "parameters": [
        {
          "name": "space",
          "in": "path",
          "required": true,
          "description": "The Data Space ID.",
          "schema": {
            "type": "string"
          }
        }
      ],
      "post": {
        "operationId": "testSpaceRules",
        "tags": [
          "end-users"
        ],
        "summary": "Test the rules as an end user",
        "description": "**Auth:** owner role on the space, from a console (or admin) session.\n\nRead-only: what one end user would see of a table (`action` view,\nthe default), or whether they may create, update or delete a row,\nunder the stored rules or a draft `document`. Nothing is written.\nFor update, `fields` go on top of the stored row to make `newData`.\n",
        "x-kovlet-session": "any",
        "x-kovlet-space-role": "owner",
        "security": [
          {
            "sessionToken": [],
            "deviceProof": []
          },
          {
            "sessionToken": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "table"
                ],
                "properties": {
                  "end_user_id": {
                    "type": "string"
                  },
                  "email": {
                    "type": "string"
                  },
                  "document": {
                    "type": "object",
                    "description": "A draft to test instead of the stored rules."
                  },
                  "table": {
                    "type": "string"
                  },
                  "action": {
                    "type": "string",
                    "enum": [
                      "view",
                      "create",
                      "update",
                      "delete"
                    ]
                  },
                  "record_id": {
                    "type": "string"
                  },
                  "fields": {
                    "type": "object"
                  },
                  "params": {
                    "type": "object"
                  },
                  "limit": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 200
                  }
                }
              },
              "example": {
                "email": "ada@example.com",
                "table": "todos"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The decision.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RulesTestResult"
                }
              }
            }
          },
          "400": {
            "description": "`invalid_request`: no end user named, an unknown table or action, or a malformed body.",
            "x-kovlet-error-codes": [
              "invalid_request"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "description": "Access to the space is denied (the code is the policy's denial\nreason):\n`insufficient_role`: the effective role on the space is below the\none this operation needs (see `x-kovlet-space-role`), or there is none.\n`scope_required`: manage actions (owner operations), and sessions\nwithout an app, need a console or admin scope.\n`no_user_grant`: the user has no role on the space.\n`no_app_grant`: the app has no grant on the space.\n`no_machine_grant`: a headless (machine, app) session has no machine grant on the space.\n`machine_revoked` / `machine_not_approved`: the machine is revoked,\nor not approved where the space or workspace requires approved machines.\n`app_revoked` / `app_not_approved`: the app is revoked, or not\napproved where the space or workspace requires approved apps.\n`origin_mismatch`: the request `Origin` is not one of the app's pinned origins.\n`unknown_principal`: the session's machine, user, app or end user no longer exists.\n`policy_unconfigured`: kovletd runs without a policy evaluator (fail closed).\nApp end users (ADR 0021): `end_user_forbidden`: this route is not\navailable to end users (only `GET .../tables` and `.../records`\nare), or an end user asked for the Trash. `end_users_disabled`:\nend-user sign-in is off for the app on this space.\n`end_user_blocked`: the end user is blocked. `end_user_wrong_space`:\nan end-user session is valid for one space only.\n`impersonation_not_allowed`: `Kovlet-As-End-User` from a session\nthat isn't a machine, or whose machine grant lacks the impersonate flag.\n`forbidden`: the space's rules don't allow reading the table\n(`details.rule`, e.g. `todos.view`).\n",
            "x-kovlet-error-codes": [
              "end_user_forbidden",
              "end_users_disabled",
              "end_user_blocked",
              "end_user_wrong_space",
              "impersonation_not_allowed",
              "forbidden",
              "insufficient_role",
              "scope_required",
              "no_user_grant",
              "no_app_grant",
              "no_machine_grant",
              "machine_revoked",
              "machine_not_approved",
              "app_revoked",
              "app_not_approved",
              "origin_mismatch",
              "unknown_principal",
              "policy_unconfigured"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "`space_not_found`: no such space. `end_user_not_found`: no end\nuser with that ID or email. `record_not_found`: `record_id` is\nnot a live row (update, delete).\n",
            "x-kovlet-error-codes": [
              "space_not_found",
              "end_user_not_found",
              "record_not_found"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "`rules_invalid`: the document doesn't validate; `errors` lists each problem by rule.",
            "x-kovlet-error-codes": [
              "rules_invalid"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RulesError"
                }
              }
            }
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/v1/spaces/{space}/records": {
      "parameters": [
        {
          "name": "space",
          "in": "path",
          "required": true,
          "description": "The Data Space ID.",
          "schema": {
            "type": "string"
          }
        }
      ],
      "get": {
        "operationId": "listSpaceRecords",
        "tags": [
          "records"
        ],
        "summary": "List rows",
        "description": "**Auth:** any session with at least the viewer role on the space.\n\nLists rows in ascending `seq` order (the seq of the op that last\nchanged each row). Page with `after_seq`: when a page is full,\n`next_after_seq` is the value to pass for the next one. Rows are\nwritten through the sync WebSocket, not this API.\n\n**By ID:** with `ids` (and `table`), returns those rows instead, in\nthe order asked, trashed rows included, with their `hlcs`; IDs the\nspace has no row for are left out, and `trashed`, `after_seq` and\n`limit` are ignored. Clients use it to roll back a rejected write\n(ADR 0017).\n",
        "x-kovlet-session": "any",
        "x-kovlet-space-role": "viewer",
        "security": [
          {
            "sessionToken": [],
            "deviceProof": []
          },
          {
            "sessionToken": []
          }
        ],
        "parameters": [
          {
            "name": "table",
            "in": "query",
            "required": false,
            "description": "Only rows of this table. Absent or empty lists every table.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "trashed",
            "in": "query",
            "required": false,
            "description": "`exclude` (default) hides rows in the Trash, `include` lists both,\n`only` lists the Trash.\n",
            "schema": {
              "type": "string",
              "enum": [
                "",
                "exclude",
                "include",
                "only"
              ],
              "default": "exclude"
            }
          },
          {
            "name": "after_seq",
            "in": "query",
            "required": false,
            "description": "Only entries whose `seq` is greater than this (the previous page's `next_after_seq`).",
            "schema": {
              "type": "integer",
              "format": "int64",
              "minimum": 0
            }
          },
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "description": "Page size.",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 5000,
              "default": 500
            }
          },
          {
            "name": "params",
            "in": "query",
            "required": false,
            "description": "End users only: a JSON object of values the view rules read as\n`params` (ADR 0021 §3.2).\n",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "ids",
            "in": "query",
            "required": false,
            "description": "Read these rows by ID (needs `table`). Repeat the parameter once\nper ID (`ids=a&ids=b`), because record IDs may contain commas; at\nmost 500.\n",
            "style": "form",
            "explode": true,
            "schema": {
              "type": "array",
              "items": {
                "type": "string",
                "minLength": 1
              },
              "minItems": 1,
              "maxItems": 500
            }
          }
        ],
        "responses": {
          "200": {
            "description": "One page of rows (or, with `ids`, the rows asked for; no `next_after_seq`).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RecordPage"
                },
                "example": {
                  "records": [
                    {
                      "table": "expenses",
                      "id": "0193a5c2-7a51-7c3e-9b1e-1f2d3c4b5a69",
                      "fields": {
                        "amount": 12.5,
                        "note": "lunch"
                      },
                      "hlcs": {
                        "amount": "1764314700123:00002:mobile-19c2",
                        "note": "1764314700123:00002:mobile-19c2"
                      },
                      "seq": 42
                    }
                  ]
                }
              }
            }
          },
          "400": {
            "description": "`invalid_query`: `trashed` is not `exclude`, `include` or `only`,\n`after_seq` is not a non-negative integer, `limit` is not\nbetween 1 and 5000, or `ids` has no `table`, more than 500 IDs, or\nan invalid record ID.\n",
            "x-kovlet-error-codes": [
              "invalid_query"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "description": "Access to the space is denied (the code is the policy's denial\nreason):\n`insufficient_role`: the effective role on the space is below the\none this operation needs (see `x-kovlet-space-role`), or there is none.\n`scope_required`: manage actions (owner operations), and sessions\nwithout an app, need a console or admin scope.\n`no_user_grant`: the user has no role on the space.\n`no_app_grant`: the app has no grant on the space.\n`no_machine_grant`: a headless (machine, app) session has no machine grant on the space.\n`machine_revoked` / `machine_not_approved`: the machine is revoked,\nor not approved where the space or workspace requires approved machines.\n`app_revoked` / `app_not_approved`: the app is revoked, or not\napproved where the space or workspace requires approved apps.\n`origin_mismatch`: the request `Origin` is not one of the app's pinned origins.\n`unknown_principal`: the session's machine, user, app or end user no longer exists.\n`policy_unconfigured`: kovletd runs without a policy evaluator (fail closed).\nApp end users (ADR 0021): `end_user_forbidden`: this route is not\navailable to end users (only `GET .../tables` and `.../records`\nare), or an end user asked for the Trash. `end_users_disabled`:\nend-user sign-in is off for the app on this space.\n`end_user_blocked`: the end user is blocked. `end_user_wrong_space`:\nan end-user session is valid for one space only.\n`impersonation_not_allowed`: `Kovlet-As-End-User` from a session\nthat isn't a machine, or whose machine grant lacks the impersonate flag.\n`forbidden`: the space's rules don't allow reading the table\n(`details.rule`, e.g. `todos.view`).\n",
            "x-kovlet-error-codes": [
              "end_user_forbidden",
              "end_users_disabled",
              "end_user_blocked",
              "end_user_wrong_space",
              "impersonation_not_allowed",
              "forbidden",
              "insufficient_role",
              "scope_required",
              "no_user_grant",
              "no_app_grant",
              "no_machine_grant",
              "machine_revoked",
              "machine_not_approved",
              "app_revoked",
              "app_not_approved",
              "origin_mismatch",
              "unknown_principal",
              "policy_unconfigured"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "`space_not_found`: the space ID is malformed or no such space exists.",
            "x-kovlet-error-codes": [
              "space_not_found"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/v1/spaces/{space}/query": {
      "parameters": [
        {
          "name": "space",
          "in": "path",
          "required": true,
          "description": "The Data Space ID.",
          "schema": {
            "type": "string"
          }
        }
      ],
      "post": {
        "operationId": "querySpace",
        "tags": [
          "records"
        ],
        "summary": "Run a nested query once",
        "description": "**Auth:** any session with at least the viewer role on the space.\n\nRuns one query (ADR 0021 §4; the language is in the protocol\nreference, §17): a tree keyed by table, where nested keys follow\n`ref` columns forward (`author`) or backward (`comments` under\n`posts`), and `$` takes `where`, `order`, `limit`, `after`,\n`before`, `fields` and `via`. Only top-level keys take `limit` and\ncursors. Trashed rows never match. `@kovlet/client` calls it as\n`kovlet.query(q)`; live results use a protocol 2 subscription\ninstead.\n\n`data` mirrors the query: each top-level key is a list of rows\n(objects with `id` and their fields), a forward link is the linked\nrow or `null`, a reverse link a list. `page_info` pages each\ntop-level key: pass `end_cursor` as `$.after` for the next page.\n",
        "x-kovlet-session": "any",
        "x-kovlet-space-role": "viewer",
        "security": [
          {
            "sessionToken": [],
            "deviceProof": []
          },
          {
            "sessionToken": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "query"
                ],
                "properties": {
                  "query": {
                    "type": "object",
                    "minProperties": 1,
                    "description": "The query tree."
                  },
                  "params": {
                    "type": "object",
                    "description": "Values rules read as `params` (ADR 0021 §3.2). Untrusted data."
                  }
                }
              },
              "example": {
                "query": {
                  "posts": {
                    "$": {
                      "where": {
                        "published": true
                      },
                      "order": {
                        "createdAt": "desc"
                      },
                      "limit": 20
                    },
                    "author": {},
                    "comments": {
                      "$": {
                        "order": {
                          "createdAt": "asc"
                        }
                      },
                      "author": {}
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The nested result.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/QueryResult"
                },
                "example": {
                  "data": {
                    "posts": [
                      {
                        "id": "p1",
                        "title": "Hello",
                        "published": true,
                        "author": {
                          "id": "u1",
                          "name": "Ada"
                        },
                        "comments": [
                          {
                            "id": "c1",
                            "body": "Nice",
                            "author": {
                              "id": "u2",
                              "name": "Bob"
                            }
                          }
                        ]
                      }
                    ]
                  },
                  "page_info": {
                    "posts": {
                      "start_cursor": "WyIyMDI2LTAxLTAxVDA5OjAwOjAwWiIsInAxIl0",
                      "end_cursor": "WyIyMDI2LTAxLTAxVDA5OjAwOjAwWiIsInAxIl0",
                      "has_more": false
                    }
                  },
                  "through_seq": 42
                }
              }
            }
          },
          "400": {
            "description": "`invalid_query`: the body is malformed, or the query doesn't fit\nthe language or the space's schema (unknown table or column, a\nvalue of the wrong type, a link that isn't a ref, more than 3\nlinks deep or 8 tables, a limit on a nested key).\n",
            "x-kovlet-error-codes": [
              "invalid_query"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "description": "Access to the space is denied (the code is the policy's denial\nreason):\n`insufficient_role`: the effective role on the space is below the\none this operation needs (see `x-kovlet-space-role`), or there is none.\n`scope_required`: manage actions (owner operations), and sessions\nwithout an app, need a console or admin scope.\n`no_user_grant`: the user has no role on the space.\n`no_app_grant`: the app has no grant on the space.\n`no_machine_grant`: a headless (machine, app) session has no machine grant on the space.\n`machine_revoked` / `machine_not_approved`: the machine is revoked,\nor not approved where the space or workspace requires approved machines.\n`app_revoked` / `app_not_approved`: the app is revoked, or not\napproved where the space or workspace requires approved apps.\n`origin_mismatch`: the request `Origin` is not one of the app's pinned origins.\n`unknown_principal`: the session's machine, user, app or end user no longer exists.\n`policy_unconfigured`: kovletd runs without a policy evaluator (fail closed).\nApp end users (ADR 0021): `end_user_forbidden`: this route is not\navailable to end users (only `GET .../tables` and `.../records`\nare), or an end user asked for the Trash. `end_users_disabled`:\nend-user sign-in is off for the app on this space.\n`end_user_blocked`: the end user is blocked. `end_user_wrong_space`:\nan end-user session is valid for one space only.\n`impersonation_not_allowed`: `Kovlet-As-End-User` from a session\nthat isn't a machine, or whose machine grant lacks the impersonate flag.\n`forbidden`: the space's rules don't allow reading the table\n(`details.rule`, e.g. `todos.view`).\n",
            "x-kovlet-error-codes": [
              "end_user_forbidden",
              "end_users_disabled",
              "end_user_blocked",
              "end_user_wrong_space",
              "impersonation_not_allowed",
              "forbidden",
              "insufficient_role",
              "scope_required",
              "no_user_grant",
              "no_app_grant",
              "no_machine_grant",
              "machine_revoked",
              "machine_not_approved",
              "app_revoked",
              "app_not_approved",
              "origin_mismatch",
              "unknown_principal",
              "policy_unconfigured"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "`space_not_found`: the space ID is malformed or no such space exists.",
            "x-kovlet-error-codes": [
              "space_not_found"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "`query_too_large`: the query matches more than 10,000 rows (`limit`); narrow it or page it.",
            "x-kovlet-error-codes": [
              "query_too_large"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/v1/spaces/{space}/tables/{table}/records/{id}/restore": {
      "parameters": [
        {
          "name": "space",
          "in": "path",
          "required": true,
          "description": "The Data Space ID.",
          "schema": {
            "type": "string"
          }
        },
        {
          "name": "table",
          "in": "path",
          "required": true,
          "description": "The row's table name.",
          "schema": {
            "type": "string"
          }
        },
        {
          "name": "id",
          "in": "path",
          "required": true,
          "description": "The row ID (1-256 bytes of UTF-8 text, no control characters; URL-encode it).",
          "schema": {
            "type": "string",
            "minLength": 1
          }
        }
      ],
      "post": {
        "operationId": "restoreSpaceRecord",
        "tags": [
          "records"
        ],
        "summary": "Restore a row from the Trash",
        "description": "**Auth:** any session with at least the editor role on the space.\n\nCommits a server-stamped `restore` op attributed to the caller and\nbroadcasts it to connected clients. No request body.\n",
        "x-kovlet-session": "any",
        "x-kovlet-space-role": "editor",
        "security": [
          {
            "sessionToken": [],
            "deviceProof": []
          },
          {
            "sessionToken": []
          }
        ],
        "responses": {
          "200": {
            "description": "The row is restored.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RestoreResult"
                },
                "example": {
                  "restored": true,
                  "seq": 57
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "description": "Access to the space is denied (the code is the policy's denial\nreason):\n`insufficient_role`: the effective role on the space is below the\none this operation needs (see `x-kovlet-space-role`), or there is none.\n`scope_required`: manage actions (owner operations), and sessions\nwithout an app, need a console or admin scope.\n`no_user_grant`: the user has no role on the space.\n`no_app_grant`: the app has no grant on the space.\n`no_machine_grant`: a headless (machine, app) session has no machine grant on the space.\n`machine_revoked` / `machine_not_approved`: the machine is revoked,\nor not approved where the space or workspace requires approved machines.\n`app_revoked` / `app_not_approved`: the app is revoked, or not\napproved where the space or workspace requires approved apps.\n`origin_mismatch`: the request `Origin` is not one of the app's pinned origins.\n`unknown_principal`: the session's machine, user, app or end user no longer exists.\n`policy_unconfigured`: kovletd runs without a policy evaluator (fail closed).\nApp end users (ADR 0021): `end_user_forbidden`: this route is not\navailable to end users (only `GET .../tables` and `.../records`\nare), or an end user asked for the Trash. `end_users_disabled`:\nend-user sign-in is off for the app on this space.\n`end_user_blocked`: the end user is blocked. `end_user_wrong_space`:\nan end-user session is valid for one space only.\n`impersonation_not_allowed`: `Kovlet-As-End-User` from a session\nthat isn't a machine, or whose machine grant lacks the impersonate flag.\n`forbidden`: the space's rules don't allow reading the table\n(`details.rule`, e.g. `todos.view`).\n",
            "x-kovlet-error-codes": [
              "end_user_forbidden",
              "end_users_disabled",
              "end_user_blocked",
              "end_user_wrong_space",
              "impersonation_not_allowed",
              "forbidden",
              "insufficient_role",
              "scope_required",
              "no_user_grant",
              "no_app_grant",
              "no_machine_grant",
              "machine_revoked",
              "machine_not_approved",
              "app_revoked",
              "app_not_approved",
              "origin_mismatch",
              "unknown_principal",
              "policy_unconfigured"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "`space_not_found`: the space ID is malformed or no such space exists.\n`record_not_found`: no row with this table and ID (or a malformed table name or ID).\n",
            "x-kovlet-error-codes": [
              "space_not_found",
              "record_not_found"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "`not_trashed`: the row is not in the Trash.\n`table_missing`: the row's table no longer exists; recreate it first.\n`unique_violation`: another live row now holds one of the row's\nvalues in a unique column; change that row first.\n",
            "x-kovlet-error-codes": [
              "not_trashed",
              "table_missing",
              "unique_violation"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/v1/spaces/{space}/tables/{table}/records/{id}/purge": {
      "parameters": [
        {
          "name": "space",
          "in": "path",
          "required": true,
          "description": "The Data Space ID.",
          "schema": {
            "type": "string"
          }
        },
        {
          "name": "table",
          "in": "path",
          "required": true,
          "description": "The row's table name (a live or a dropped table).",
          "schema": {
            "type": "string"
          }
        },
        {
          "name": "id",
          "in": "path",
          "required": true,
          "description": "The row ID (1-256 bytes of UTF-8 text, no control characters; URL-encode it).",
          "schema": {
            "type": "string",
            "minLength": 1
          }
        }
      ],
      "post": {
        "operationId": "purgeSpaceRecord",
        "tags": [
          "records"
        ],
        "summary": "Permanently delete one row from the Trash",
        "description": "**Auth:** owner role on the space, from a console (or admin) session.\nApp and headless sessions get `403 scope_required`; editors and\nviewers get `403 insufficient_role`.\n\nDeletes the trashed row for good, in one transaction, and scrubs the\nbefore and after images of its ops, so neither Undo nor a\npoint-in-time rollback can bring it back. Commits a record `delete`\nop carrying `purge: {scope: row, count: 1}` and records a\n`trash.purged` audit event. No request body.\n",
        "x-kovlet-session": "any",
        "x-kovlet-space-role": "owner",
        "security": [
          {
            "sessionToken": [],
            "deviceProof": []
          },
          {
            "sessionToken": []
          }
        ],
        "responses": {
          "200": {
            "description": "The row is deleted for good.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PurgeResult"
                },
                "example": {
                  "purged": 1
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "description": "Access to the space is denied (the code is the policy's denial\nreason):\n`insufficient_role`: the effective role on the space is below the\none this operation needs (see `x-kovlet-space-role`), or there is none.\n`scope_required`: manage actions (owner operations), and sessions\nwithout an app, need a console or admin scope.\n`no_user_grant`: the user has no role on the space.\n`no_app_grant`: the app has no grant on the space.\n`no_machine_grant`: a headless (machine, app) session has no machine grant on the space.\n`machine_revoked` / `machine_not_approved`: the machine is revoked,\nor not approved where the space or workspace requires approved machines.\n`app_revoked` / `app_not_approved`: the app is revoked, or not\napproved where the space or workspace requires approved apps.\n`origin_mismatch`: the request `Origin` is not one of the app's pinned origins.\n`unknown_principal`: the session's machine, user, app or end user no longer exists.\n`policy_unconfigured`: kovletd runs without a policy evaluator (fail closed).\nApp end users (ADR 0021): `end_user_forbidden`: this route is not\navailable to end users (only `GET .../tables` and `.../records`\nare), or an end user asked for the Trash. `end_users_disabled`:\nend-user sign-in is off for the app on this space.\n`end_user_blocked`: the end user is blocked. `end_user_wrong_space`:\nan end-user session is valid for one space only.\n`impersonation_not_allowed`: `Kovlet-As-End-User` from a session\nthat isn't a machine, or whose machine grant lacks the impersonate flag.\n`forbidden`: the space's rules don't allow reading the table\n(`details.rule`, e.g. `todos.view`).\n",
            "x-kovlet-error-codes": [
              "end_user_forbidden",
              "end_users_disabled",
              "end_user_blocked",
              "end_user_wrong_space",
              "impersonation_not_allowed",
              "forbidden",
              "insufficient_role",
              "scope_required",
              "no_user_grant",
              "no_app_grant",
              "no_machine_grant",
              "machine_revoked",
              "machine_not_approved",
              "app_revoked",
              "app_not_approved",
              "origin_mismatch",
              "unknown_principal",
              "policy_unconfigured"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "`space_not_found`: the space ID is malformed or no such space exists.\n`record_not_found`: no row with this table and ID (or a malformed table name or ID).\n",
            "x-kovlet-error-codes": [
              "space_not_found",
              "record_not_found"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "`not_in_trash`: the row is live; only rows in the Trash can be purged. Nothing was deleted.",
            "x-kovlet-error-codes": [
              "not_in_trash"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/v1/spaces/{space}/trash/tables": {
      "parameters": [
        {
          "name": "space",
          "in": "path",
          "required": true,
          "description": "The Data Space ID.",
          "schema": {
            "type": "string"
          }
        }
      ],
      "get": {
        "operationId": "listSpaceDroppedTables",
        "tags": [
          "records"
        ],
        "summary": "List dropped tables that left rows in the Trash",
        "description": "**Auth:** any session with at least the viewer role on the space.\n\nTables that are no longer in the schema but whose rows are still in\nthe Trash, with how many, most rows first. Snapshots leave these rows\nout (their table is gone); an owner can purge them with\n`POST /v1/spaces/{space}/trash/tables/{table}/purge`.\n",
        "x-kovlet-session": "any",
        "x-kovlet-space-role": "viewer",
        "security": [
          {
            "sessionToken": [],
            "deviceProof": []
          },
          {
            "sessionToken": []
          }
        ],
        "responses": {
          "200": {
            "description": "The dropped tables with rows in the Trash.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "tables"
                  ],
                  "properties": {
                    "tables": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/DroppedTable"
                      }
                    }
                  }
                },
                "example": {
                  "tables": [
                    {
                      "table": "expenses",
                      "count": 128,
                      "dropped_at": "2026-12-02T09:12:00Z"
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "description": "Access to the space is denied (the code is the policy's denial\nreason):\n`insufficient_role`: the effective role on the space is below the\none this operation needs (see `x-kovlet-space-role`), or there is none.\n`scope_required`: manage actions (owner operations), and sessions\nwithout an app, need a console or admin scope.\n`no_user_grant`: the user has no role on the space.\n`no_app_grant`: the app has no grant on the space.\n`no_machine_grant`: a headless (machine, app) session has no machine grant on the space.\n`machine_revoked` / `machine_not_approved`: the machine is revoked,\nor not approved where the space or workspace requires approved machines.\n`app_revoked` / `app_not_approved`: the app is revoked, or not\napproved where the space or workspace requires approved apps.\n`origin_mismatch`: the request `Origin` is not one of the app's pinned origins.\n`unknown_principal`: the session's machine, user, app or end user no longer exists.\n`policy_unconfigured`: kovletd runs without a policy evaluator (fail closed).\nApp end users (ADR 0021): `end_user_forbidden`: this route is not\navailable to end users (only `GET .../tables` and `.../records`\nare), or an end user asked for the Trash. `end_users_disabled`:\nend-user sign-in is off for the app on this space.\n`end_user_blocked`: the end user is blocked. `end_user_wrong_space`:\nan end-user session is valid for one space only.\n`impersonation_not_allowed`: `Kovlet-As-End-User` from a session\nthat isn't a machine, or whose machine grant lacks the impersonate flag.\n`forbidden`: the space's rules don't allow reading the table\n(`details.rule`, e.g. `todos.view`).\n",
            "x-kovlet-error-codes": [
              "end_user_forbidden",
              "end_users_disabled",
              "end_user_blocked",
              "end_user_wrong_space",
              "impersonation_not_allowed",
              "forbidden",
              "insufficient_role",
              "scope_required",
              "no_user_grant",
              "no_app_grant",
              "no_machine_grant",
              "machine_revoked",
              "machine_not_approved",
              "app_revoked",
              "app_not_approved",
              "origin_mismatch",
              "unknown_principal",
              "policy_unconfigured"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "`space_not_found`: the space ID is malformed or no such space exists.",
            "x-kovlet-error-codes": [
              "space_not_found"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/v1/spaces/{space}/trash/tables/{table}/purge": {
      "parameters": [
        {
          "name": "space",
          "in": "path",
          "required": true,
          "description": "The Data Space ID.",
          "schema": {
            "type": "string"
          }
        },
        {
          "name": "table",
          "in": "path",
          "required": true,
          "description": "The name of a dropped table (one that isn't in the schema).",
          "schema": {
            "type": "string"
          }
        }
      ],
      "post": {
        "operationId": "purgeSpaceTrashTable",
        "tags": [
          "records"
        ],
        "summary": "Permanently delete a dropped table's rows from the Trash",
        "description": "**Auth:** owner role on the space, from a console (or admin) session.\nApp and headless sessions get `403 scope_required`; editors and\nviewers get `403 insufficient_role`.\n\nDeletes every trashed row of a dropped table for good, all or\nnothing, so the name can be created again with any columns (see\n`trashed_rows_conflict`). The rows' op images are scrubbed, so\nneither Undo nor a point-in-time rollback can bring them back.\nCommits one schema `delete` op carrying `purge: {scope: table, count}`\n(clients reload the space) and records a `trash.purged` audit event.\nSend `expect_count`, the number of rows the owner confirmed: if the\nTrash holds another number, nothing is deleted and the answer is\n`409 trash_changed` with the current `count`.\n",
        "x-kovlet-session": "any",
        "x-kovlet-space-role": "owner",
        "security": [
          {
            "sessionToken": [],
            "deviceProof": []
          },
          {
            "sessionToken": []
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "expect_count": {
                    "type": "integer",
                    "minimum": 0,
                    "description": "Refuse unless the table has exactly this many rows in the Trash."
                  }
                }
              },
              "example": {
                "expect_count": 128
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The rows are deleted for good.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PurgeResult"
                },
                "example": {
                  "purged": 128
                }
              }
            }
          },
          "400": {
            "description": "`invalid_request`: the body isn't valid JSON, has unknown fields, or `expect_count` is negative.",
            "x-kovlet-error-codes": [
              "invalid_request"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "description": "Access to the space is denied (the code is the policy's denial\nreason):\n`insufficient_role`: the effective role on the space is below the\none this operation needs (see `x-kovlet-space-role`), or there is none.\n`scope_required`: manage actions (owner operations), and sessions\nwithout an app, need a console or admin scope.\n`no_user_grant`: the user has no role on the space.\n`no_app_grant`: the app has no grant on the space.\n`no_machine_grant`: a headless (machine, app) session has no machine grant on the space.\n`machine_revoked` / `machine_not_approved`: the machine is revoked,\nor not approved where the space or workspace requires approved machines.\n`app_revoked` / `app_not_approved`: the app is revoked, or not\napproved where the space or workspace requires approved apps.\n`origin_mismatch`: the request `Origin` is not one of the app's pinned origins.\n`unknown_principal`: the session's machine, user, app or end user no longer exists.\n`policy_unconfigured`: kovletd runs without a policy evaluator (fail closed).\nApp end users (ADR 0021): `end_user_forbidden`: this route is not\navailable to end users (only `GET .../tables` and `.../records`\nare), or an end user asked for the Trash. `end_users_disabled`:\nend-user sign-in is off for the app on this space.\n`end_user_blocked`: the end user is blocked. `end_user_wrong_space`:\nan end-user session is valid for one space only.\n`impersonation_not_allowed`: `Kovlet-As-End-User` from a session\nthat isn't a machine, or whose machine grant lacks the impersonate flag.\n`forbidden`: the space's rules don't allow reading the table\n(`details.rule`, e.g. `todos.view`).\n",
            "x-kovlet-error-codes": [
              "end_user_forbidden",
              "end_users_disabled",
              "end_user_blocked",
              "end_user_wrong_space",
              "impersonation_not_allowed",
              "forbidden",
              "insufficient_role",
              "scope_required",
              "no_user_grant",
              "no_app_grant",
              "no_machine_grant",
              "machine_revoked",
              "machine_not_approved",
              "app_revoked",
              "app_not_approved",
              "origin_mismatch",
              "unknown_principal",
              "policy_unconfigured"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "`space_not_found`: the space ID is malformed or no such space exists.\n`not_in_trash`: the table has no rows in the Trash.\n",
            "x-kovlet-error-codes": [
              "space_not_found",
              "not_in_trash"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "`trash_changed`: the Trash holds another number of the table's rows\nthan `expect_count` (`table`, `count`: the current number). Nothing was deleted.\n`table_exists`: the table is in the schema; purge its trashed rows\none at a time. Nothing was deleted.\n",
            "x-kovlet-error-codes": [
              "trash_changed",
              "table_exists"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "anyOf": [
                    {
                      "$ref": "#/components/schemas/Error"
                    },
                    {
                      "$ref": "#/components/schemas/TrashChangedError"
                    }
                  ]
                }
              }
            }
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/v1/spaces/{space}/trash": {
      "parameters": [
        {
          "name": "space",
          "in": "path",
          "required": true,
          "description": "The Data Space ID.",
          "schema": {
            "type": "string"
          }
        }
      ],
      "get": {
        "operationId": "getSpaceTrashSummary",
        "tags": [
          "records"
        ],
        "summary": "Count what the Trash holds",
        "description": "**Auth:** any session with at least the viewer role on the space.\n\nHow many rows (of live and dropped tables), dropped tables and files\nare in the Trash: what `POST /v1/spaces/{space}/trash/purge` would\ndelete. System tables such as `_users` are not counted.\n",
        "x-kovlet-session": "any",
        "x-kovlet-space-role": "viewer",
        "security": [
          {
            "sessionToken": [],
            "deviceProof": []
          },
          {
            "sessionToken": []
          }
        ],
        "responses": {
          "200": {
            "description": "The Trash's counts.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TrashCounts"
                },
                "example": {
                  "rows": 131,
                  "dropped_tables": 2,
                  "files": 4
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "description": "Access to the space is denied (the code is the policy's denial\nreason):\n`insufficient_role`: the effective role on the space is below the\none this operation needs (see `x-kovlet-space-role`), or there is none.\n`scope_required`: manage actions (owner operations), and sessions\nwithout an app, need a console or admin scope.\n`no_user_grant`: the user has no role on the space.\n`no_app_grant`: the app has no grant on the space.\n`no_machine_grant`: a headless (machine, app) session has no machine grant on the space.\n`machine_revoked` / `machine_not_approved`: the machine is revoked,\nor not approved where the space or workspace requires approved machines.\n`app_revoked` / `app_not_approved`: the app is revoked, or not\napproved where the space or workspace requires approved apps.\n`origin_mismatch`: the request `Origin` is not one of the app's pinned origins.\n`unknown_principal`: the session's machine, user, app or end user no longer exists.\n`policy_unconfigured`: kovletd runs without a policy evaluator (fail closed).\nApp end users (ADR 0021): `end_user_forbidden`: this route is not\navailable to end users (only `GET .../tables` and `.../records`\nare), or an end user asked for the Trash. `end_users_disabled`:\nend-user sign-in is off for the app on this space.\n`end_user_blocked`: the end user is blocked. `end_user_wrong_space`:\nan end-user session is valid for one space only.\n`impersonation_not_allowed`: `Kovlet-As-End-User` from a session\nthat isn't a machine, or whose machine grant lacks the impersonate flag.\n`forbidden`: the space's rules don't allow reading the table\n(`details.rule`, e.g. `todos.view`).\n",
            "x-kovlet-error-codes": [
              "end_user_forbidden",
              "end_users_disabled",
              "end_user_blocked",
              "end_user_wrong_space",
              "impersonation_not_allowed",
              "forbidden",
              "insufficient_role",
              "scope_required",
              "no_user_grant",
              "no_app_grant",
              "no_machine_grant",
              "machine_revoked",
              "machine_not_approved",
              "app_revoked",
              "app_not_approved",
              "origin_mismatch",
              "unknown_principal",
              "policy_unconfigured"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "`space_not_found`: the space ID is malformed or no such space exists.",
            "x-kovlet-error-codes": [
              "space_not_found"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/v1/spaces/{space}/trash/purge": {
      "parameters": [
        {
          "name": "space",
          "in": "path",
          "required": true,
          "description": "The Data Space ID.",
          "schema": {
            "type": "string"
          }
        }
      ],
      "post": {
        "operationId": "emptySpaceTrash",
        "tags": [
          "records"
        ],
        "summary": "Empty the whole Trash",
        "description": "**Auth:** owner role on the space, from a console (or admin) session.\nApp and headless sessions get `403 scope_required`; editors and\nviewers get `403 insufficient_role`.\n\nPermanently deletes every row (of live and dropped tables) and every\nfile in the Trash, all or nothing, so dropped tables' names can be\ncreated again with any columns. `expect` is required: the counts the\nowner confirmed, as `GET /v1/spaces/{space}/trash` returns them. If\nthe Trash holds anything else, nothing is deleted and the answer is\n`409 trash_changed` with the current counts.\n\nRows are deleted as the per-row and per-table purges delete them\n(their op images are scrubbed). Each file loses its entry and its\nrecorded versions; its bytes are freed by blob GC once nothing else\nin the space uses them (see the protocol guide, section 2.6). Commits\none op per purged item, all sharing one `mutation_id`: a record\n`delete` per row of a live table, a schema `delete` per dropped table,\na file `delete` per file, each carrying `purge`. Records one\n`trash.purged` audit event (`scope: trash`).\n",
        "x-kovlet-session": "any",
        "x-kovlet-space-role": "owner",
        "security": [
          {
            "sessionToken": [],
            "deviceProof": []
          },
          {
            "sessionToken": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "expect"
                ],
                "properties": {
                  "expect": {
                    "$ref": "#/components/schemas/TrashCounts"
                  }
                }
              },
              "example": {
                "expect": {
                  "rows": 131,
                  "dropped_tables": 2,
                  "files": 4
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The Trash is empty.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "purged"
                  ],
                  "properties": {
                    "purged": {
                      "$ref": "#/components/schemas/TrashCounts"
                    }
                  }
                },
                "example": {
                  "purged": {
                    "rows": 131,
                    "dropped_tables": 2,
                    "files": 4
                  }
                }
              }
            }
          },
          "400": {
            "description": "`invalid_request`: the body isn't valid JSON, has unknown fields, lacks `expect`, or has a negative count.",
            "x-kovlet-error-codes": [
              "invalid_request"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "description": "Access to the space is denied (the code is the policy's denial\nreason):\n`insufficient_role`: the effective role on the space is below the\none this operation needs (see `x-kovlet-space-role`), or there is none.\n`scope_required`: manage actions (owner operations), and sessions\nwithout an app, need a console or admin scope.\n`no_user_grant`: the user has no role on the space.\n`no_app_grant`: the app has no grant on the space.\n`no_machine_grant`: a headless (machine, app) session has no machine grant on the space.\n`machine_revoked` / `machine_not_approved`: the machine is revoked,\nor not approved where the space or workspace requires approved machines.\n`app_revoked` / `app_not_approved`: the app is revoked, or not\napproved where the space or workspace requires approved apps.\n`origin_mismatch`: the request `Origin` is not one of the app's pinned origins.\n`unknown_principal`: the session's machine, user, app or end user no longer exists.\n`policy_unconfigured`: kovletd runs without a policy evaluator (fail closed).\nApp end users (ADR 0021): `end_user_forbidden`: this route is not\navailable to end users (only `GET .../tables` and `.../records`\nare), or an end user asked for the Trash. `end_users_disabled`:\nend-user sign-in is off for the app on this space.\n`end_user_blocked`: the end user is blocked. `end_user_wrong_space`:\nan end-user session is valid for one space only.\n`impersonation_not_allowed`: `Kovlet-As-End-User` from a session\nthat isn't a machine, or whose machine grant lacks the impersonate flag.\n`forbidden`: the space's rules don't allow reading the table\n(`details.rule`, e.g. `todos.view`).\n",
            "x-kovlet-error-codes": [
              "end_user_forbidden",
              "end_users_disabled",
              "end_user_blocked",
              "end_user_wrong_space",
              "impersonation_not_allowed",
              "forbidden",
              "insufficient_role",
              "scope_required",
              "no_user_grant",
              "no_app_grant",
              "no_machine_grant",
              "machine_revoked",
              "machine_not_approved",
              "app_revoked",
              "app_not_approved",
              "origin_mismatch",
              "unknown_principal",
              "policy_unconfigured"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "`space_not_found`: the space ID is malformed or no such space exists.\n`not_in_trash`: the Trash is empty.\n",
            "x-kovlet-error-codes": [
              "space_not_found",
              "not_in_trash"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "`trash_changed`: the Trash holds other counts than `expect`\n(`rows`, `dropped_tables`, `files`: the current counts). Nothing was deleted.\n",
            "x-kovlet-error-codes": [
              "trash_changed"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/EmptyTrashChangedError"
                }
              }
            }
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/v1/spaces/{space}/transact": {
      "parameters": [
        {
          "name": "space",
          "in": "path",
          "required": true,
          "description": "The Data Space ID.",
          "schema": {
            "type": "string"
          }
        }
      ],
      "post": {
        "operationId": "transactSpace",
        "tags": [
          "records"
        ],
        "summary": "Apply an atomic batch of writes",
        "description": "**Auth:** any session with at least the editor role on the space.\n\nApplies 1-500 mutations, across tables, all or nothing (ADR 0021 §6.1).\nEach one is validated (schema, unique columns, quota) against the\nstate the ones before it left, in one transaction; one rejection\nrolls the batch back. Mutations take the same shape as in a sync\n`mutate` frame (docs/PROTOCOL.md). Fields still merge last-writer-wins\nby HLC: a field that loses to a newer write is dropped and the batch\nstill applies.\n\nRetrying with the same `batch_id` and mutation IDs is safe: a batch\nthat already applied answers `duplicate`. A batch that mixes applied\nand new mutation IDs is rejected with `invalid_mutation`.\n\n**End users** (an end-user token, or a machine with the\n`Kovlet-As-End-User` header) may call it too: every write is checked\nagainst the space's rules (ADR 0021 §3.4), and a denied write rejects\nthe batch with `forbidden` and `details.rule` (409). `params` are the\nvalues rules read as `params`.\n",
        "x-kovlet-session": "any",
        "x-kovlet-space-role": "editor",
        "security": [
          {
            "sessionToken": [],
            "deviceProof": []
          },
          {
            "sessionToken": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/TransactRequest"
              },
              "example": {
                "batch_id": "b-01",
                "mutations": [
                  {
                    "mutation_id": "m-1",
                    "hlc": "1764590400000:00000:srv-a",
                    "kind": "record",
                    "op": "upsert",
                    "table": "teams",
                    "id": "t1",
                    "fields": {
                      "name": "Core"
                    }
                  },
                  {
                    "mutation_id": "m-2",
                    "hlc": "1764590400000:00001:srv-a",
                    "kind": "record",
                    "op": "upsert",
                    "table": "memberships",
                    "id": "ms1",
                    "fields": {
                      "team": "t1",
                      "user": "u1"
                    }
                  }
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The batch applied (`batch.status` is `applied`), or it is a retry of one that did (`duplicate`).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TransactResult"
                }
              }
            }
          },
          "400": {
            "description": "`invalid_request`: the body is malformed, is empty, holds more than\n500 mutations, or a mutation ID or the batch ID breaks the ID rule.\n",
            "x-kovlet-error-codes": [
              "invalid_request"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "description": "Access to the space is denied (the code is the policy's denial\nreason):\n`insufficient_role`: the effective role on the space is below the\none this operation needs (see `x-kovlet-space-role`), or there is none.\n`scope_required`: manage actions (owner operations), and sessions\nwithout an app, need a console or admin scope.\n`no_user_grant`: the user has no role on the space.\n`no_app_grant`: the app has no grant on the space.\n`no_machine_grant`: a headless (machine, app) session has no machine grant on the space.\n`machine_revoked` / `machine_not_approved`: the machine is revoked,\nor not approved where the space or workspace requires approved machines.\n`app_revoked` / `app_not_approved`: the app is revoked, or not\napproved where the space or workspace requires approved apps.\n`origin_mismatch`: the request `Origin` is not one of the app's pinned origins.\n`unknown_principal`: the session's machine, user, app or end user no longer exists.\n`policy_unconfigured`: kovletd runs without a policy evaluator (fail closed).\nApp end users (ADR 0021): `end_user_forbidden`: this route is not\navailable to end users (only `GET .../tables` and `.../records`\nare), or an end user asked for the Trash. `end_users_disabled`:\nend-user sign-in is off for the app on this space.\n`end_user_blocked`: the end user is blocked. `end_user_wrong_space`:\nan end-user session is valid for one space only.\n`impersonation_not_allowed`: `Kovlet-As-End-User` from a session\nthat isn't a machine, or whose machine grant lacks the impersonate flag.\n`forbidden`: the space's rules don't allow reading the table\n(`details.rule`, e.g. `todos.view`).\n",
            "x-kovlet-error-codes": [
              "end_user_forbidden",
              "end_users_disabled",
              "end_user_blocked",
              "end_user_wrong_space",
              "impersonation_not_allowed",
              "forbidden",
              "insufficient_role",
              "scope_required",
              "no_user_grant",
              "no_app_grant",
              "no_machine_grant",
              "machine_revoked",
              "machine_not_approved",
              "app_revoked",
              "app_not_approved",
              "origin_mismatch",
              "unknown_principal",
              "policy_unconfigured"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "`space_not_found`: the space ID is malformed or no such space exists.",
            "x-kovlet-error-codes": [
              "space_not_found"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "The batch was rejected and nothing applied. `batch.failed_index`\nnames the mutation that failed and `batch.error` why (for example\n`unique_violation`, `schema_violation` or `quota_exceeded`); that\nresult is `rejected` and every other one `aborted`.\n",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TransactResult"
                }
              }
            }
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/v1/spaces/{space}/activity": {
      "parameters": [
        {
          "name": "space",
          "in": "path",
          "required": true,
          "description": "The Data Space ID.",
          "schema": {
            "type": "string"
          }
        }
      ],
      "get": {
        "operationId": "listSpaceActivity",
        "tags": [
          "activity"
        ],
        "summary": "List the activity feed",
        "description": "**Auth:** any session with at least the viewer role on the space.\n\nThe space's committed ops, newest first, each with its before and\nafter images. When a page is full, pass `next_before_seq` as\n`before_seq` to fetch the next (older) page. With `order=asc` the\nfeed runs oldest first and pages with `after_seq` and\n`next_after_seq` instead.\n\n`table` plus `record` is one row's history (ADR 0025 §4): every\nrecord op on that row, served by the `(space_id, entity_key, seq)`\noplog index. `order=asc&limit=1` returns the op that created it. Ops\nscrubbed for an erasure request (ADR 0021 §2.7) keep their place\nwith null (omitted) `before` and `after`. A table rename moves rows\nwithout record ops, so history before a rename is filed under the\nold table name.\n",
        "x-kovlet-session": "any",
        "x-kovlet-space-role": "viewer",
        "security": [
          {
            "sessionToken": [],
            "deviceProof": []
          },
          {
            "sessionToken": []
          }
        ],
        "parameters": [
          {
            "name": "user",
            "in": "query",
            "required": false,
            "description": "Only ops by this user ID.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "machine",
            "in": "query",
            "required": false,
            "description": "Only ops by this machine ID.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "app",
            "in": "query",
            "required": false,
            "description": "Only ops by this app ID.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "table",
            "in": "query",
            "required": false,
            "description": "Only ops on this table.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "record",
            "in": "query",
            "required": false,
            "description": "Only the record ops of this row ID (one row's history). Needs\n`table`, and implies `kind=record`.\n",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "kind",
            "in": "query",
            "required": false,
            "description": "Only ops of this entity kind.",
            "schema": {
              "type": "string",
              "enum": [
                "",
                "record",
                "file",
                "schema"
              ]
            }
          },
          {
            "name": "since",
            "in": "query",
            "required": false,
            "description": "Only ops committed at or after this time (RFC 3339).",
            "schema": {
              "type": "string",
              "format": "date-time"
            }
          },
          {
            "name": "until",
            "in": "query",
            "required": false,
            "description": "Only ops committed before this time (RFC 3339).",
            "schema": {
              "type": "string",
              "format": "date-time"
            }
          },
          {
            "name": "order",
            "in": "query",
            "required": false,
            "description": "`desc` (newest first, paged with `before_seq`) or `asc` (oldest first, paged with `after_seq`).",
            "schema": {
              "type": "string",
              "enum": [
                "asc",
                "desc"
              ],
              "default": "desc"
            }
          },
          {
            "name": "before_seq",
            "in": "query",
            "required": false,
            "description": "Only ops with a smaller seq (the previous page's `next_before_seq`). `order=desc` only.",
            "schema": {
              "type": "integer",
              "format": "int64",
              "minimum": 1
            }
          },
          {
            "name": "after_seq",
            "in": "query",
            "required": false,
            "description": "Only ops with a larger seq (the previous page's `next_after_seq`). `order=asc` only.",
            "schema": {
              "type": "integer",
              "format": "int64",
              "minimum": 0
            }
          },
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "description": "Page size.",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 1000,
              "default": 100
            }
          }
        ],
        "responses": {
          "200": {
            "description": "One page of the feed, newest first unless `order=asc`.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ActivityPage"
                }
              }
            }
          },
          "400": {
            "description": "`invalid_query`: `kind` is not `record`, `file` or `schema`,\n`record` is set without `table` or with a `kind` other than\n`record`, `order` is not `asc` or `desc`, `before_seq` is set with\n`order=asc` or `after_seq` without it, `since`/`until` is not an\nRFC 3339 timestamp, `before_seq` is not a positive integer,\n`after_seq` is negative, or `limit` is not between 1 and 1000.\n",
            "x-kovlet-error-codes": [
              "invalid_query"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "description": "Access to the space is denied (the code is the policy's denial\nreason):\n`insufficient_role`: the effective role on the space is below the\none this operation needs (see `x-kovlet-space-role`), or there is none.\n`scope_required`: manage actions (owner operations), and sessions\nwithout an app, need a console or admin scope.\n`no_user_grant`: the user has no role on the space.\n`no_app_grant`: the app has no grant on the space.\n`no_machine_grant`: a headless (machine, app) session has no machine grant on the space.\n`machine_revoked` / `machine_not_approved`: the machine is revoked,\nor not approved where the space or workspace requires approved machines.\n`app_revoked` / `app_not_approved`: the app is revoked, or not\napproved where the space or workspace requires approved apps.\n`origin_mismatch`: the request `Origin` is not one of the app's pinned origins.\n`unknown_principal`: the session's machine, user, app or end user no longer exists.\n`policy_unconfigured`: kovletd runs without a policy evaluator (fail closed).\nApp end users (ADR 0021): `end_user_forbidden`: this route is not\navailable to end users (only `GET .../tables` and `.../records`\nare), or an end user asked for the Trash. `end_users_disabled`:\nend-user sign-in is off for the app on this space.\n`end_user_blocked`: the end user is blocked. `end_user_wrong_space`:\nan end-user session is valid for one space only.\n`impersonation_not_allowed`: `Kovlet-As-End-User` from a session\nthat isn't a machine, or whose machine grant lacks the impersonate flag.\n`forbidden`: the space's rules don't allow reading the table\n(`details.rule`, e.g. `todos.view`).\n",
            "x-kovlet-error-codes": [
              "end_user_forbidden",
              "end_users_disabled",
              "end_user_blocked",
              "end_user_wrong_space",
              "impersonation_not_allowed",
              "forbidden",
              "insufficient_role",
              "scope_required",
              "no_user_grant",
              "no_app_grant",
              "no_machine_grant",
              "machine_revoked",
              "machine_not_approved",
              "app_revoked",
              "app_not_approved",
              "origin_mismatch",
              "unknown_principal",
              "policy_unconfigured"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "`space_not_found`: the space ID is malformed or no such space exists.",
            "x-kovlet-error-codes": [
              "space_not_found"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/v1/spaces/{space}/rollback/preview": {
      "parameters": [
        {
          "name": "space",
          "in": "path",
          "required": true,
          "description": "The Data Space ID.",
          "schema": {
            "type": "string"
          }
        }
      ],
      "post": {
        "operationId": "previewSpaceRollback",
        "tags": [
          "activity"
        ],
        "summary": "Preview a rollback (dry run)",
        "description": "**Auth:** owner role on the space, from a console (or admin) session.\nApp and headless sessions get `403 scope_required`.\n\nComputes what `POST /v1/spaces/{space}/rollback` would do with the\nsame body, without changing anything. `undo_app` reverts one app's\nrecord and file changes since a point in time (where nobody changed\nthe value afterwards); `undo_end_user` does the same for one app end\nuser; `undo_ops` reverts chosen ops, by `seqs` or `mutation_ids`,\nwith the same rules (one row's history entry, one Live log line, or\nan earlier rollback by its `rollback_id`); `point_in_time` returns\nevery row and file of the space to its state at a seq or timestamp.\nSchema ops are never rolled back. Pass the returned `head_seq` as `expected_head_seq` when\napplying, so the apply refuses if the space changed in between.\n`expected_head_seq` is ignored here.\n",
        "x-kovlet-session": "any",
        "x-kovlet-space-role": "owner",
        "security": [
          {
            "sessionToken": [],
            "deviceProof": []
          },
          {
            "sessionToken": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/RollbackRequest"
              },
              "examples": {
                "undoApp": {
                  "summary": "Undo an app's last 15 minutes on one table",
                  "value": {
                    "kind": "undo_app",
                    "app_id": "0193a5c2-0000-7000-8000-000000000001",
                    "minutes": 15,
                    "table": "expenses"
                  }
                },
                "pointInTime": {
                  "summary": "Return the space to seq 120",
                  "value": {
                    "kind": "point_in_time",
                    "to_seq": 120
                  }
                },
                "undoOps": {
                  "summary": "Revert one op (a row's history entry)",
                  "value": {
                    "kind": "undo_ops",
                    "seqs": [
                      4182
                    ]
                  }
                },
                "undoRollback": {
                  "summary": "Undo an earlier rollback by its rollback_id",
                  "value": {
                    "kind": "undo_ops",
                    "mutation_ids": [
                      "0193a5c2-dddd-7000-8000-000000000001"
                    ]
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The plan.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RollbackPlan"
                }
              }
            }
          },
          "400": {
            "description": "`invalid_frame`: the body is not valid JSON for this operation\n(unknown fields, wrong types, trailing data, over 1 MiB).\n`invalid_rollback`: the request is inconsistent (unknown `kind`,\nmissing `app_id`, `minutes` and `since` together or neither,\n`to_seq` and `to_time` together or neither, narrowing fields on a\n`point_in_time`, `table` and `path_prefix` together, an invalid\ntable name, `sample` out of range, a negative `to_seq`; for\n`undo_ops`: neither `seqs` nor `mutation_ids`, a field of another\nkind, an unknown seq or mutation ID, or more than 1,000 seqs, 20\nmutation IDs or 1,000 selected ops, where the message points to\n`undo_app` or `point_in_time`).\n`retention_window`: the rollback reaches further back than the\nworkspace plan keeps history; `retention_days` and `upgrade_url`\nsay how far it may go and where to upgrade.\n",
            "x-kovlet-error-codes": [
              "invalid_frame",
              "invalid_rollback",
              "retention_window"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "anyOf": [
                    {
                      "$ref": "#/components/schemas/Error"
                    },
                    {
                      "$ref": "#/components/schemas/RetentionWindowError"
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "description": "Access to the space is denied (the code is the policy's denial\nreason):\n`insufficient_role`: the effective role on the space is below the\none this operation needs (see `x-kovlet-space-role`), or there is none.\n`scope_required`: manage actions (owner operations), and sessions\nwithout an app, need a console or admin scope.\n`no_user_grant`: the user has no role on the space.\n`no_app_grant`: the app has no grant on the space.\n`no_machine_grant`: a headless (machine, app) session has no machine grant on the space.\n`machine_revoked` / `machine_not_approved`: the machine is revoked,\nor not approved where the space or workspace requires approved machines.\n`app_revoked` / `app_not_approved`: the app is revoked, or not\napproved where the space or workspace requires approved apps.\n`origin_mismatch`: the request `Origin` is not one of the app's pinned origins.\n`unknown_principal`: the session's machine, user, app or end user no longer exists.\n`policy_unconfigured`: kovletd runs without a policy evaluator (fail closed).\nApp end users (ADR 0021): `end_user_forbidden`: this route is not\navailable to end users (only `GET .../tables` and `.../records`\nare), or an end user asked for the Trash. `end_users_disabled`:\nend-user sign-in is off for the app on this space.\n`end_user_blocked`: the end user is blocked. `end_user_wrong_space`:\nan end-user session is valid for one space only.\n`impersonation_not_allowed`: `Kovlet-As-End-User` from a session\nthat isn't a machine, or whose machine grant lacks the impersonate flag.\n`forbidden`: the space's rules don't allow reading the table\n(`details.rule`, e.g. `todos.view`).\n",
            "x-kovlet-error-codes": [
              "end_user_forbidden",
              "end_users_disabled",
              "end_user_blocked",
              "end_user_wrong_space",
              "impersonation_not_allowed",
              "forbidden",
              "insufficient_role",
              "scope_required",
              "no_user_grant",
              "no_app_grant",
              "no_machine_grant",
              "machine_revoked",
              "machine_not_approved",
              "app_revoked",
              "app_not_approved",
              "origin_mismatch",
              "unknown_principal",
              "policy_unconfigured"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "`space_not_found`: the space ID is malformed or no such space exists.",
            "x-kovlet-error-codes": [
              "space_not_found"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/v1/spaces/{space}/rollback": {
      "parameters": [
        {
          "name": "space",
          "in": "path",
          "required": true,
          "description": "The Data Space ID.",
          "schema": {
            "type": "string"
          }
        }
      ],
      "post": {
        "operationId": "applySpaceRollback",
        "tags": [
          "activity"
        ],
        "summary": "Apply a rollback",
        "description": "**Auth:** owner role on the space, from a console (or admin) session.\nApp and headless sessions get `403 scope_required`.\n\nPlans the rollback (same body as the preview) and applies it as one\nforward transaction of compensating ops attributed to the caller,\nsharing the mutation ID `rollback_id`; each carries `revert`, the\nrollback kind and the seqs it reverts. History is kept: `undo_ops`\nwith `mutation_ids: [rollback_id]` undoes exactly this rollback, and a\n`point_in_time` rollback to `undo_to_seq` undoes it with everything\ncommitted after it.\nWith `expected_head_seq` set, the call refuses with\n`409 stale_preview` if the space's head moved since the preview.\n",
        "x-kovlet-session": "any",
        "x-kovlet-space-role": "owner",
        "security": [
          {
            "sessionToken": [],
            "deviceProof": []
          },
          {
            "sessionToken": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/RollbackRequest"
              },
              "examples": {
                "undoApp": {
                  "summary": "Undo an app's last 15 minutes on one table",
                  "value": {
                    "kind": "undo_app",
                    "app_id": "0193a5c2-0000-7000-8000-000000000001",
                    "minutes": 15,
                    "table": "expenses"
                  }
                },
                "pointInTime": {
                  "summary": "Return the space to seq 120",
                  "value": {
                    "kind": "point_in_time",
                    "to_seq": 120
                  }
                },
                "undoOps": {
                  "summary": "Revert one op (a row's history entry)",
                  "value": {
                    "kind": "undo_ops",
                    "seqs": [
                      4182
                    ]
                  }
                },
                "undoRollback": {
                  "summary": "Undo an earlier rollback by its rollback_id",
                  "value": {
                    "kind": "undo_ops",
                    "mutation_ids": [
                      "0193a5c2-dddd-7000-8000-000000000001"
                    ]
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The rollback is applied.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RollbackResult"
                }
              }
            }
          },
          "400": {
            "description": "`invalid_frame`: the body is not valid JSON for this operation\n(unknown fields, wrong types, trailing data, over 1 MiB).\n`invalid_rollback`: the request is inconsistent (unknown `kind`,\nmissing `app_id`, `minutes` and `since` together or neither,\n`to_seq` and `to_time` together or neither, narrowing fields on a\n`point_in_time`, `table` and `path_prefix` together, an invalid\ntable name, `sample` out of range, a negative `to_seq`; for\n`undo_ops`: neither `seqs` nor `mutation_ids`, a field of another\nkind, an unknown seq or mutation ID, or more than 1,000 seqs, 20\nmutation IDs or 1,000 selected ops, where the message points to\n`undo_app` or `point_in_time`).\n`retention_window`: the rollback reaches further back than the\nworkspace plan keeps history; `retention_days` and `upgrade_url`\nsay how far it may go and where to upgrade.\n",
            "x-kovlet-error-codes": [
              "invalid_frame",
              "invalid_rollback",
              "retention_window"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "anyOf": [
                    {
                      "$ref": "#/components/schemas/Error"
                    },
                    {
                      "$ref": "#/components/schemas/RetentionWindowError"
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "description": "Access to the space is denied (the code is the policy's denial\nreason):\n`insufficient_role`: the effective role on the space is below the\none this operation needs (see `x-kovlet-space-role`), or there is none.\n`scope_required`: manage actions (owner operations), and sessions\nwithout an app, need a console or admin scope.\n`no_user_grant`: the user has no role on the space.\n`no_app_grant`: the app has no grant on the space.\n`no_machine_grant`: a headless (machine, app) session has no machine grant on the space.\n`machine_revoked` / `machine_not_approved`: the machine is revoked,\nor not approved where the space or workspace requires approved machines.\n`app_revoked` / `app_not_approved`: the app is revoked, or not\napproved where the space or workspace requires approved apps.\n`origin_mismatch`: the request `Origin` is not one of the app's pinned origins.\n`unknown_principal`: the session's machine, user, app or end user no longer exists.\n`policy_unconfigured`: kovletd runs without a policy evaluator (fail closed).\nApp end users (ADR 0021): `end_user_forbidden`: this route is not\navailable to end users (only `GET .../tables` and `.../records`\nare), or an end user asked for the Trash. `end_users_disabled`:\nend-user sign-in is off for the app on this space.\n`end_user_blocked`: the end user is blocked. `end_user_wrong_space`:\nan end-user session is valid for one space only.\n`impersonation_not_allowed`: `Kovlet-As-End-User` from a session\nthat isn't a machine, or whose machine grant lacks the impersonate flag.\n`forbidden`: the space's rules don't allow reading the table\n(`details.rule`, e.g. `todos.view`).\n",
            "x-kovlet-error-codes": [
              "end_user_forbidden",
              "end_users_disabled",
              "end_user_blocked",
              "end_user_wrong_space",
              "impersonation_not_allowed",
              "forbidden",
              "insufficient_role",
              "scope_required",
              "no_user_grant",
              "no_app_grant",
              "no_machine_grant",
              "machine_revoked",
              "machine_not_approved",
              "app_revoked",
              "app_not_approved",
              "origin_mismatch",
              "unknown_principal",
              "policy_unconfigured"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "`space_not_found`: the space ID is malformed or no such space exists.",
            "x-kovlet-error-codes": [
              "space_not_found"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "`stale_preview`: the space changed since the preview that returned `expected_head_seq`; preview again.",
            "x-kovlet-error-codes": [
              "stale_preview"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/v1/spaces/{space}/files/uploads": {
      "parameters": [
        {
          "name": "space",
          "in": "path",
          "required": true,
          "description": "The Data Space ID.",
          "schema": {
            "type": "string"
          }
        }
      ],
      "post": {
        "operationId": "createFileUpload",
        "tags": [
          "files"
        ],
        "summary": "Mint an upload URL for file bytes",
        "description": "**Auth:** any session with at least the editor role on the space.\n\nStep 2 of the file upload flow (protocol reference §9). Blobs are\ncontent-addressed per space: when the space already holds these\nbytes at this size, `exists` is true and there is no `upload`;\ncommit the file `put` mutation over the sync socket straight away.\nOtherwise send `upload.method` to `upload.url` with the raw bytes as\nthe body, **every header in `upload.headers` exactly as given**\n(against S3/R2 this is `x-amz-checksum-sha256`, the base64 of the raw\ndigest; the bucket rejects bytes that do not match) and a\n`Content-Length` equal to `size_bytes`, before `expires_at`\n(15 minutes). Repeating this call with the same `sha256` and\n`size_bytes` confirms an upload (`exists: true`).\n\nMinting an upload for bytes the space does not hold yet fails with\n`402 quota_exceeded` (`metric: storage`) when they would not fit in\nthe workspace's storage limit.\n",
        "x-kovlet-session": "any",
        "x-kovlet-space-role": "editor",
        "security": [
          {
            "sessionToken": [],
            "deviceProof": []
          },
          {
            "sessionToken": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "sha256"
                ],
                "properties": {
                  "sha256": {
                    "type": "string",
                    "pattern": "^[0-9a-f]{64}$",
                    "description": "Lowercase hex SHA-256 of the bytes."
                  },
                  "size_bytes": {
                    "type": "integer",
                    "format": "int64",
                    "minimum": 0,
                    "description": "Size of the bytes. Absent means 0. At most 5 GiB by default."
                  },
                  "mime_type": {
                    "type": "string",
                    "description": "Accepted and ignored; the MIME type is set by the file `put` mutation."
                  }
                }
              },
              "example": {
                "sha256": "9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08",
                "size_bytes": 1024,
                "mime_type": "image/png"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The bytes exist already, or an upload request to send.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/UploadResponse"
                },
                "examples": {
                  "s3": {
                    "summary": "Upload needed (S3/R2)",
                    "value": {
                      "sha256": "9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08",
                      "size_bytes": 1024,
                      "exists": false,
                      "upload": {
                        "method": "PUT",
                        "url": "https://bucket.example.r2.cloudflarestorage.com/spaces/sp_1/blobs/9f86...?X-Amz-Signature=...",
                        "headers": {
                          "x-amz-checksum-sha256": "n4bQgYhMfWWaL+qgxVrQFaO/TxsrC4Is0V1sFbDwCgg="
                        },
                        "expires_at": "2026-11-30T12:15:00Z"
                      }
                    }
                  },
                  "exists": {
                    "summary": "The space already holds the bytes",
                    "value": {
                      "sha256": "9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08",
                      "size_bytes": 1024,
                      "exists": true
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "`invalid_request`: the body is not valid JSON for this operation,\n`sha256` is not 64 lowercase hex digits, or `size_bytes` is negative.\n",
            "x-kovlet-error-codes": [
              "invalid_request"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "402": {
            "$ref": "#/components/responses/QuotaExceeded"
          },
          "403": {
            "description": "Access to the space is denied (the code is the policy's denial\nreason):\n`insufficient_role`: the effective role on the space is below the\none this operation needs (see `x-kovlet-space-role`), or there is none.\n`scope_required`: manage actions (owner operations), and sessions\nwithout an app, need a console or admin scope.\n`no_user_grant`: the user has no role on the space.\n`no_app_grant`: the app has no grant on the space.\n`no_machine_grant`: a headless (machine, app) session has no machine grant on the space.\n`machine_revoked` / `machine_not_approved`: the machine is revoked,\nor not approved where the space or workspace requires approved machines.\n`app_revoked` / `app_not_approved`: the app is revoked, or not\napproved where the space or workspace requires approved apps.\n`origin_mismatch`: the request `Origin` is not one of the app's pinned origins.\n`unknown_principal`: the session's machine, user, app or end user no longer exists.\n`policy_unconfigured`: kovletd runs without a policy evaluator (fail closed).\nApp end users (ADR 0021): `end_user_forbidden`: this route is not\navailable to end users (only `GET .../tables` and `.../records`\nare), or an end user asked for the Trash. `end_users_disabled`:\nend-user sign-in is off for the app on this space.\n`end_user_blocked`: the end user is blocked. `end_user_wrong_space`:\nan end-user session is valid for one space only.\n`impersonation_not_allowed`: `Kovlet-As-End-User` from a session\nthat isn't a machine, or whose machine grant lacks the impersonate flag.\n`forbidden`: the space's rules don't allow reading the table\n(`details.rule`, e.g. `todos.view`).\n",
            "x-kovlet-error-codes": [
              "end_user_forbidden",
              "end_users_disabled",
              "end_user_blocked",
              "end_user_wrong_space",
              "impersonation_not_allowed",
              "forbidden",
              "insufficient_role",
              "scope_required",
              "no_user_grant",
              "no_app_grant",
              "no_machine_grant",
              "machine_revoked",
              "machine_not_approved",
              "app_revoked",
              "app_not_approved",
              "origin_mismatch",
              "unknown_principal",
              "policy_unconfigured"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "`space_not_found`: the space ID is malformed or no such space exists.",
            "x-kovlet-error-codes": [
              "space_not_found"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "`too_large`: `size_bytes` is over the per-file limit (5 GiB by default).",
            "x-kovlet-error-codes": [
              "too_large"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/v1/spaces/{space}/files": {
      "parameters": [
        {
          "name": "space",
          "in": "path",
          "required": true,
          "description": "The Data Space ID.",
          "schema": {
            "type": "string"
          }
        }
      ],
      "get": {
        "operationId": "listSpaceFiles",
        "tags": [
          "files"
        ],
        "summary": "List files",
        "description": "**Auth:** any session with at least the viewer role on the space.\n\nTwo modes:\n\n- **Flat** (no `dir`): files whose path starts with `prefix`, in\n  ascending `seq` order, paged with `after_seq`/`limit`\n  (`next_after_seq` is present when a page is full). Response\n  `FilePage`.\n- **One folder level** (`dir` present, even empty): the files\n  directly in `dir` and the folders implied one level below it, both\n  sorted by path; `prefix`, `after_seq` and `limit` are ignored.\n  Response `FileDirListing`.\n\n`trashed` applies to both.\n",
        "x-kovlet-session": "any",
        "x-kovlet-space-role": "viewer",
        "security": [
          {
            "sessionToken": [],
            "deviceProof": []
          },
          {
            "sessionToken": []
          }
        ],
        "parameters": [
          {
            "name": "prefix",
            "in": "query",
            "required": false,
            "description": "Flat mode only. Only files whose path starts with this string.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "dir",
            "in": "query",
            "required": false,
            "allowEmptyValue": true,
            "description": "Selects folder mode: `\"\"` (the root) or a folder path ending in\n`/`, e.g. `receipts/2026/`.\n",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "trashed",
            "in": "query",
            "required": false,
            "description": "`exclude` (default) hides files in the Trash, `include` lists both,\n`only` lists the Trash.\n",
            "schema": {
              "type": "string",
              "enum": [
                "",
                "exclude",
                "include",
                "only"
              ],
              "default": "exclude"
            }
          },
          {
            "name": "after_seq",
            "in": "query",
            "required": false,
            "description": "Only entries whose `seq` is greater than this (the previous page's `next_after_seq`).",
            "schema": {
              "type": "integer",
              "format": "int64",
              "minimum": 0
            }
          },
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "description": "Page size.",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 5000,
              "default": 500
            }
          }
        ],
        "responses": {
          "200": {
            "description": "A page of files (flat mode) or one folder level (`dir` given).",
            "content": {
              "application/json": {
                "schema": {
                  "anyOf": [
                    {
                      "$ref": "#/components/schemas/FilePage"
                    },
                    {
                      "$ref": "#/components/schemas/FileDirListing"
                    }
                  ]
                }
              }
            }
          },
          "400": {
            "description": "`invalid_query`: `trashed` is not `exclude`, `include` or `only`,\n`dir` is neither empty nor a valid folder path ending in `/`,\n`after_seq` is not a non-negative integer, or `limit` is not\nbetween 1 and 5000.\n",
            "x-kovlet-error-codes": [
              "invalid_query"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "description": "Access to the space is denied (the code is the policy's denial\nreason):\n`insufficient_role`: the effective role on the space is below the\none this operation needs (see `x-kovlet-space-role`), or there is none.\n`scope_required`: manage actions (owner operations), and sessions\nwithout an app, need a console or admin scope.\n`no_user_grant`: the user has no role on the space.\n`no_app_grant`: the app has no grant on the space.\n`no_machine_grant`: a headless (machine, app) session has no machine grant on the space.\n`machine_revoked` / `machine_not_approved`: the machine is revoked,\nor not approved where the space or workspace requires approved machines.\n`app_revoked` / `app_not_approved`: the app is revoked, or not\napproved where the space or workspace requires approved apps.\n`origin_mismatch`: the request `Origin` is not one of the app's pinned origins.\n`unknown_principal`: the session's machine, user, app or end user no longer exists.\n`policy_unconfigured`: kovletd runs without a policy evaluator (fail closed).\nApp end users (ADR 0021): `end_user_forbidden`: this route is not\navailable to end users (only `GET .../tables` and `.../records`\nare), or an end user asked for the Trash. `end_users_disabled`:\nend-user sign-in is off for the app on this space.\n`end_user_blocked`: the end user is blocked. `end_user_wrong_space`:\nan end-user session is valid for one space only.\n`impersonation_not_allowed`: `Kovlet-As-End-User` from a session\nthat isn't a machine, or whose machine grant lacks the impersonate flag.\n`forbidden`: the space's rules don't allow reading the table\n(`details.rule`, e.g. `todos.view`).\n",
            "x-kovlet-error-codes": [
              "end_user_forbidden",
              "end_users_disabled",
              "end_user_blocked",
              "end_user_wrong_space",
              "impersonation_not_allowed",
              "forbidden",
              "insufficient_role",
              "scope_required",
              "no_user_grant",
              "no_app_grant",
              "no_machine_grant",
              "machine_revoked",
              "machine_not_approved",
              "app_revoked",
              "app_not_approved",
              "origin_mismatch",
              "unknown_principal",
              "policy_unconfigured"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "`space_not_found`: the space ID is malformed or no such space exists.",
            "x-kovlet-error-codes": [
              "space_not_found"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/v1/spaces/{space}/files/{id}": {
      "parameters": [
        {
          "name": "space",
          "in": "path",
          "required": true,
          "description": "The Data Space ID.",
          "schema": {
            "type": "string"
          }
        },
        {
          "name": "id",
          "in": "path",
          "required": true,
          "description": "The file ID.",
          "schema": {
            "type": "string"
          }
        }
      ],
      "get": {
        "operationId": "getSpaceFile",
        "tags": [
          "files"
        ],
        "summary": "Get a file's metadata",
        "description": "**Auth:** any session with at least the viewer role on the space.\n\nReturns the file entry, also when it is in the Trash (`deleted: true`).\n",
        "x-kovlet-session": "any",
        "x-kovlet-space-role": "viewer",
        "security": [
          {
            "sessionToken": [],
            "deviceProof": []
          },
          {
            "sessionToken": []
          }
        ],
        "responses": {
          "200": {
            "description": "The file's current metadata.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/FileMeta"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "description": "Access to the space is denied (the code is the policy's denial\nreason):\n`insufficient_role`: the effective role on the space is below the\none this operation needs (see `x-kovlet-space-role`), or there is none.\n`scope_required`: manage actions (owner operations), and sessions\nwithout an app, need a console or admin scope.\n`no_user_grant`: the user has no role on the space.\n`no_app_grant`: the app has no grant on the space.\n`no_machine_grant`: a headless (machine, app) session has no machine grant on the space.\n`machine_revoked` / `machine_not_approved`: the machine is revoked,\nor not approved where the space or workspace requires approved machines.\n`app_revoked` / `app_not_approved`: the app is revoked, or not\napproved where the space or workspace requires approved apps.\n`origin_mismatch`: the request `Origin` is not one of the app's pinned origins.\n`unknown_principal`: the session's machine, user, app or end user no longer exists.\n`policy_unconfigured`: kovletd runs without a policy evaluator (fail closed).\nApp end users (ADR 0021): `end_user_forbidden`: this route is not\navailable to end users (only `GET .../tables` and `.../records`\nare), or an end user asked for the Trash. `end_users_disabled`:\nend-user sign-in is off for the app on this space.\n`end_user_blocked`: the end user is blocked. `end_user_wrong_space`:\nan end-user session is valid for one space only.\n`impersonation_not_allowed`: `Kovlet-As-End-User` from a session\nthat isn't a machine, or whose machine grant lacks the impersonate flag.\n`forbidden`: the space's rules don't allow reading the table\n(`details.rule`, e.g. `todos.view`).\n",
            "x-kovlet-error-codes": [
              "end_user_forbidden",
              "end_users_disabled",
              "end_user_blocked",
              "end_user_wrong_space",
              "impersonation_not_allowed",
              "forbidden",
              "insufficient_role",
              "scope_required",
              "no_user_grant",
              "no_app_grant",
              "no_machine_grant",
              "machine_revoked",
              "machine_not_approved",
              "app_revoked",
              "app_not_approved",
              "origin_mismatch",
              "unknown_principal",
              "policy_unconfigured"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "`space_not_found`: the space ID is malformed or no such space exists.\n`file_not_found`: no file with this ID in the space (or a malformed ID).\n",
            "x-kovlet-error-codes": [
              "space_not_found",
              "file_not_found"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/v1/spaces/{space}/files/{id}/versions": {
      "parameters": [
        {
          "name": "space",
          "in": "path",
          "required": true,
          "description": "The Data Space ID.",
          "schema": {
            "type": "string"
          }
        },
        {
          "name": "id",
          "in": "path",
          "required": true,
          "description": "The file ID.",
          "schema": {
            "type": "string"
          }
        }
      ],
      "get": {
        "operationId": "listSpaceFileVersions",
        "tags": [
          "files"
        ],
        "summary": "List a file's versions",
        "description": "**Auth:** any session with at least the viewer role on the space.\n\nThe recorded content versions of the file, oldest first. Moves do\nnot create versions.\n",
        "x-kovlet-session": "any",
        "x-kovlet-space-role": "viewer",
        "security": [
          {
            "sessionToken": [],
            "deviceProof": []
          },
          {
            "sessionToken": []
          }
        ],
        "responses": {
          "200": {
            "description": "The file's versions.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "file_id",
                    "versions"
                  ],
                  "properties": {
                    "file_id": {
                      "type": "string"
                    },
                    "versions": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/FileVersion"
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "description": "Access to the space is denied (the code is the policy's denial\nreason):\n`insufficient_role`: the effective role on the space is below the\none this operation needs (see `x-kovlet-space-role`), or there is none.\n`scope_required`: manage actions (owner operations), and sessions\nwithout an app, need a console or admin scope.\n`no_user_grant`: the user has no role on the space.\n`no_app_grant`: the app has no grant on the space.\n`no_machine_grant`: a headless (machine, app) session has no machine grant on the space.\n`machine_revoked` / `machine_not_approved`: the machine is revoked,\nor not approved where the space or workspace requires approved machines.\n`app_revoked` / `app_not_approved`: the app is revoked, or not\napproved where the space or workspace requires approved apps.\n`origin_mismatch`: the request `Origin` is not one of the app's pinned origins.\n`unknown_principal`: the session's machine, user, app or end user no longer exists.\n`policy_unconfigured`: kovletd runs without a policy evaluator (fail closed).\nApp end users (ADR 0021): `end_user_forbidden`: this route is not\navailable to end users (only `GET .../tables` and `.../records`\nare), or an end user asked for the Trash. `end_users_disabled`:\nend-user sign-in is off for the app on this space.\n`end_user_blocked`: the end user is blocked. `end_user_wrong_space`:\nan end-user session is valid for one space only.\n`impersonation_not_allowed`: `Kovlet-As-End-User` from a session\nthat isn't a machine, or whose machine grant lacks the impersonate flag.\n`forbidden`: the space's rules don't allow reading the table\n(`details.rule`, e.g. `todos.view`).\n",
            "x-kovlet-error-codes": [
              "end_user_forbidden",
              "end_users_disabled",
              "end_user_blocked",
              "end_user_wrong_space",
              "impersonation_not_allowed",
              "forbidden",
              "insufficient_role",
              "scope_required",
              "no_user_grant",
              "no_app_grant",
              "no_machine_grant",
              "machine_revoked",
              "machine_not_approved",
              "app_revoked",
              "app_not_approved",
              "origin_mismatch",
              "unknown_principal",
              "policy_unconfigured"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "`space_not_found`: the space ID is malformed or no such space exists.\n`file_not_found`: no file with this ID in the space (or a malformed ID).\n",
            "x-kovlet-error-codes": [
              "space_not_found",
              "file_not_found"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/v1/spaces/{space}/files/{id}/download": {
      "parameters": [
        {
          "name": "space",
          "in": "path",
          "required": true,
          "description": "The Data Space ID.",
          "schema": {
            "type": "string"
          }
        },
        {
          "name": "id",
          "in": "path",
          "required": true,
          "description": "The file ID.",
          "schema": {
            "type": "string"
          }
        }
      ],
      "get": {
        "operationId": "createFileDownload",
        "tags": [
          "files"
        ],
        "summary": "Mint a download URL",
        "description": "**Auth:** any session with at least the viewer role on the space.\n\nReturns a presigned request for the file's bytes (the current\nversion, or `version`) plus the metadata of that version. Fetch\n`url` with `method` and any `headers` before `expires_at`; the\nresponse carries the file's MIME type and an inline\n`Content-Disposition` with its base name. Clients SHOULD check the\nSHA-256 of what they receive. Works for trashed files too.\n",
        "x-kovlet-session": "any",
        "x-kovlet-space-role": "viewer",
        "security": [
          {
            "sessionToken": [],
            "deviceProof": []
          },
          {
            "sessionToken": []
          }
        ],
        "parameters": [
          {
            "name": "version",
            "in": "query",
            "required": false,
            "description": "A version number from `GET .../versions`. Default the current version.",
            "schema": {
              "type": "integer",
              "minimum": 1
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The presigned download request.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/FileDownload"
                }
              }
            }
          },
          "400": {
            "description": "`invalid_query`: `version` is not a positive integer.",
            "x-kovlet-error-codes": [
              "invalid_query"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "description": "Access to the space is denied (the code is the policy's denial\nreason):\n`insufficient_role`: the effective role on the space is below the\none this operation needs (see `x-kovlet-space-role`), or there is none.\n`scope_required`: manage actions (owner operations), and sessions\nwithout an app, need a console or admin scope.\n`no_user_grant`: the user has no role on the space.\n`no_app_grant`: the app has no grant on the space.\n`no_machine_grant`: a headless (machine, app) session has no machine grant on the space.\n`machine_revoked` / `machine_not_approved`: the machine is revoked,\nor not approved where the space or workspace requires approved machines.\n`app_revoked` / `app_not_approved`: the app is revoked, or not\napproved where the space or workspace requires approved apps.\n`origin_mismatch`: the request `Origin` is not one of the app's pinned origins.\n`unknown_principal`: the session's machine, user, app or end user no longer exists.\n`policy_unconfigured`: kovletd runs without a policy evaluator (fail closed).\nApp end users (ADR 0021): `end_user_forbidden`: this route is not\navailable to end users (only `GET .../tables` and `.../records`\nare), or an end user asked for the Trash. `end_users_disabled`:\nend-user sign-in is off for the app on this space.\n`end_user_blocked`: the end user is blocked. `end_user_wrong_space`:\nan end-user session is valid for one space only.\n`impersonation_not_allowed`: `Kovlet-As-End-User` from a session\nthat isn't a machine, or whose machine grant lacks the impersonate flag.\n`forbidden`: the space's rules don't allow reading the table\n(`details.rule`, e.g. `todos.view`).\n",
            "x-kovlet-error-codes": [
              "end_user_forbidden",
              "end_users_disabled",
              "end_user_blocked",
              "end_user_wrong_space",
              "impersonation_not_allowed",
              "forbidden",
              "insufficient_role",
              "scope_required",
              "no_user_grant",
              "no_app_grant",
              "no_machine_grant",
              "machine_revoked",
              "machine_not_approved",
              "app_revoked",
              "app_not_approved",
              "origin_mismatch",
              "unknown_principal",
              "policy_unconfigured"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "`space_not_found`: the space ID is malformed or no such space exists.\n`file_not_found`: no file with this ID in the space (or a malformed ID).\n`version_not_found`: the file has no such version.\n",
            "x-kovlet-error-codes": [
              "space_not_found",
              "file_not_found",
              "version_not_found"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/v1/spaces/{space}/files/{id}/restore": {
      "parameters": [
        {
          "name": "space",
          "in": "path",
          "required": true,
          "description": "The Data Space ID.",
          "schema": {
            "type": "string"
          }
        },
        {
          "name": "id",
          "in": "path",
          "required": true,
          "description": "The file ID.",
          "schema": {
            "type": "string"
          }
        }
      ],
      "post": {
        "operationId": "restoreSpaceFile",
        "tags": [
          "files"
        ],
        "summary": "Restore a file from the Trash",
        "description": "**Auth:** any session with at least the editor role on the space.\n\nCommits a server-stamped file `restore` op attributed to the caller,\nputting the file back at the path it was deleted from, and broadcasts\nit. No request body.\n",
        "x-kovlet-session": "any",
        "x-kovlet-space-role": "editor",
        "security": [
          {
            "sessionToken": [],
            "deviceProof": []
          },
          {
            "sessionToken": []
          }
        ],
        "responses": {
          "200": {
            "description": "The file is restored.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RestoreResult"
                },
                "example": {
                  "restored": true,
                  "seq": 58
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "description": "Access to the space is denied (the code is the policy's denial\nreason):\n`insufficient_role`: the effective role on the space is below the\none this operation needs (see `x-kovlet-space-role`), or there is none.\n`scope_required`: manage actions (owner operations), and sessions\nwithout an app, need a console or admin scope.\n`no_user_grant`: the user has no role on the space.\n`no_app_grant`: the app has no grant on the space.\n`no_machine_grant`: a headless (machine, app) session has no machine grant on the space.\n`machine_revoked` / `machine_not_approved`: the machine is revoked,\nor not approved where the space or workspace requires approved machines.\n`app_revoked` / `app_not_approved`: the app is revoked, or not\napproved where the space or workspace requires approved apps.\n`origin_mismatch`: the request `Origin` is not one of the app's pinned origins.\n`unknown_principal`: the session's machine, user, app or end user no longer exists.\n`policy_unconfigured`: kovletd runs without a policy evaluator (fail closed).\nApp end users (ADR 0021): `end_user_forbidden`: this route is not\navailable to end users (only `GET .../tables` and `.../records`\nare), or an end user asked for the Trash. `end_users_disabled`:\nend-user sign-in is off for the app on this space.\n`end_user_blocked`: the end user is blocked. `end_user_wrong_space`:\nan end-user session is valid for one space only.\n`impersonation_not_allowed`: `Kovlet-As-End-User` from a session\nthat isn't a machine, or whose machine grant lacks the impersonate flag.\n`forbidden`: the space's rules don't allow reading the table\n(`details.rule`, e.g. `todos.view`).\n",
            "x-kovlet-error-codes": [
              "end_user_forbidden",
              "end_users_disabled",
              "end_user_blocked",
              "end_user_wrong_space",
              "impersonation_not_allowed",
              "forbidden",
              "insufficient_role",
              "scope_required",
              "no_user_grant",
              "no_app_grant",
              "no_machine_grant",
              "machine_revoked",
              "machine_not_approved",
              "app_revoked",
              "app_not_approved",
              "origin_mismatch",
              "unknown_principal",
              "policy_unconfigured"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "`space_not_found`: the space ID is malformed or no such space exists.\n`file_not_found`: no file with this ID in the space (or a malformed ID).\n",
            "x-kovlet-error-codes": [
              "space_not_found",
              "file_not_found"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "`not_trashed`: the file is not in the Trash.\n`path_conflict`: another live file now holds its path; move or delete it first.\n",
            "x-kovlet-error-codes": [
              "not_trashed",
              "path_conflict"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/v1/spaces/{space}/files/move-folder": {
      "parameters": [
        {
          "name": "space",
          "in": "path",
          "required": true,
          "description": "The Data Space ID.",
          "schema": {
            "type": "string"
          }
        }
      ],
      "post": {
        "operationId": "moveSpaceFolder",
        "tags": [
          "files"
        ],
        "summary": "Rename a folder atomically",
        "description": "**Auth:** any session with at least the editor role on the space.\n\nMoves every live file whose path starts with `from` to the same\nrelative path under `to`, in one transaction: either all move or\nnone does. Each file gets an ordinary server-stamped `move` op\n(broadcast, and reverted by undo or rollback). Trashed files keep\ntheir path.\n",
        "x-kovlet-session": "any",
        "x-kovlet-space-role": "editor",
        "security": [
          {
            "sessionToken": [],
            "deviceProof": []
          },
          {
            "sessionToken": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "from",
                  "to"
                ],
                "properties": {
                  "from": {
                    "type": "string",
                    "description": "The folder to move, a valid path ending in `/`."
                  },
                  "to": {
                    "type": "string",
                    "description": "The new folder path, ending in `/`. Neither folder may contain the other."
                  }
                }
              },
              "example": {
                "from": "receipts/2025/",
                "to": "archive/receipts-2025/"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The folder is moved.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/FolderMoveResult"
                },
                "example": {
                  "from": "receipts/2025/",
                  "to": "archive/receipts-2025/",
                  "moved": 12,
                  "head_seq": 140
                }
              }
            }
          },
          "400": {
            "description": "`invalid_request`: the body is not valid JSON for this operation,\na folder path is not a valid path ending in `/`, one folder\ncontains the other, or a moved path would become invalid (too long).\n",
            "x-kovlet-error-codes": [
              "invalid_request"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "description": "Access to the space is denied (the code is the policy's denial\nreason):\n`insufficient_role`: the effective role on the space is below the\none this operation needs (see `x-kovlet-space-role`), or there is none.\n`scope_required`: manage actions (owner operations), and sessions\nwithout an app, need a console or admin scope.\n`no_user_grant`: the user has no role on the space.\n`no_app_grant`: the app has no grant on the space.\n`no_machine_grant`: a headless (machine, app) session has no machine grant on the space.\n`machine_revoked` / `machine_not_approved`: the machine is revoked,\nor not approved where the space or workspace requires approved machines.\n`app_revoked` / `app_not_approved`: the app is revoked, or not\napproved where the space or workspace requires approved apps.\n`origin_mismatch`: the request `Origin` is not one of the app's pinned origins.\n`unknown_principal`: the session's machine, user, app or end user no longer exists.\n`policy_unconfigured`: kovletd runs without a policy evaluator (fail closed).\nApp end users (ADR 0021): `end_user_forbidden`: this route is not\navailable to end users (only `GET .../tables` and `.../records`\nare), or an end user asked for the Trash. `end_users_disabled`:\nend-user sign-in is off for the app on this space.\n`end_user_blocked`: the end user is blocked. `end_user_wrong_space`:\nan end-user session is valid for one space only.\n`impersonation_not_allowed`: `Kovlet-As-End-User` from a session\nthat isn't a machine, or whose machine grant lacks the impersonate flag.\n`forbidden`: the space's rules don't allow reading the table\n(`details.rule`, e.g. `todos.view`).\n",
            "x-kovlet-error-codes": [
              "end_user_forbidden",
              "end_users_disabled",
              "end_user_blocked",
              "end_user_wrong_space",
              "impersonation_not_allowed",
              "forbidden",
              "insufficient_role",
              "scope_required",
              "no_user_grant",
              "no_app_grant",
              "no_machine_grant",
              "machine_revoked",
              "machine_not_approved",
              "app_revoked",
              "app_not_approved",
              "origin_mismatch",
              "unknown_principal",
              "policy_unconfigured"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "`space_not_found`: the space ID is malformed or no such space exists.\n`folder_not_found`: no live file is in the `from` folder.\n",
            "x-kovlet-error-codes": [
              "space_not_found",
              "folder_not_found"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "`path_conflict`: a live file outside the folder already holds a target path; nothing was moved.",
            "x-kovlet-error-codes": [
              "path_conflict"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/v1/blobs/{space}/{sha}": {
      "description": "Signed blob URLs of the local blob store. **Only routed when kovletd\nstores blobs on disk** (`--dev`, or no S3/R2 bucket configured). With\nS3/R2 the presigned URLs from `POST .../files/uploads` and\n`GET .../files/{id}/download` point at the bucket instead and these\nroutes do not exist. Clients never build these URLs: use the `url`\n(and `headers`) the API returns, verbatim. The HMAC signature in the\nquery is the only credential, so no session token is sent and any\norigin may call it (`Access-Control-Allow-Origin: *`). Methods other\nthan PUT, GET, HEAD and OPTIONS answer a plain-text `405` with an\n`Allow` header, like every other route called with the wrong method.\n",
      "parameters": [
        {
          "name": "space",
          "in": "path",
          "required": true,
          "description": "The Data Space ID.",
          "schema": {
            "type": "string"
          }
        },
        {
          "name": "sha",
          "in": "path",
          "required": true,
          "description": "Lowercase hex SHA-256 of the blob.",
          "schema": {
            "type": "string",
            "pattern": "^[0-9a-f]{64}$"
          }
        },
        {
          "name": "exp",
          "in": "query",
          "required": true,
          "description": "Signed expiry, Unix seconds.",
          "schema": {
            "type": "integer",
            "format": "int64"
          }
        },
        {
          "name": "ct",
          "in": "query",
          "required": false,
          "description": "Signed `Content-Type` of the download (GET only).",
          "schema": {
            "type": "string"
          }
        },
        {
          "name": "cd",
          "in": "query",
          "required": false,
          "description": "Signed `Content-Disposition` of the download (GET only).",
          "schema": {
            "type": "string"
          }
        },
        {
          "name": "sig",
          "in": "query",
          "required": true,
          "description": "Hex HMAC-SHA256 signature over the other parameters.",
          "schema": {
            "type": "string"
          }
        }
      ],
      "put": {
        "operationId": "putLocalBlob",
        "tags": [
          "files"
        ],
        "summary": "Upload blob bytes (local blob store)",
        "description": "**Auth:** none (signed URL from `POST .../files/uploads`).\n\nThe body must be exactly the signed `size` bytes and hash to `sha`.\nIt is written to a temporary file and renamed into place, so a blob\nis never visible half-written. Uploading bytes that are already\nstored is a no-op `200`.\n",
        "x-kovlet-session": "none",
        "x-kovlet-local-blob-store": true,
        "security": [],
        "parameters": [
          {
            "name": "op",
            "in": "query",
            "required": true,
            "description": "Signed operation; `put` for uploads.",
            "schema": {
              "type": "string",
              "const": "put"
            }
          },
          {
            "name": "size",
            "in": "query",
            "required": true,
            "description": "Signed size of the upload, in bytes.",
            "schema": {
              "type": "integer",
              "format": "int64",
              "minimum": 0
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "*/*": {
              "schema": {}
            }
          }
        },
        "responses": {
          "200": {
            "description": "The bytes are stored. Empty body."
          },
          "400": {
            "description": "`size_mismatch`: `Content-Length` or the bytes read differ from the signed size.\n`checksum_mismatch`: the bytes do not hash to `sha`.\n`upload_failed`: reading the body failed.\n",
            "x-kovlet-error-codes": [
              "size_mismatch",
              "checksum_mismatch",
              "upload_failed"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "`invalid_signature`: the upload URL is invalid or expired; ask for a new one.",
            "x-kovlet-error-codes": [
              "invalid_signature"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      },
      "get": {
        "operationId": "getLocalBlob",
        "tags": [
          "files"
        ],
        "summary": "Download blob bytes (local blob store)",
        "description": "**Auth:** none (signed URL from `GET .../files/{id}/download`).\n\nServes the bytes with the signed `Content-Type` (default\n`application/octet-stream`) and `Content-Disposition`, an\n`ETag` of the SHA-256 and an immutable cache policy. Supports\n`Range`, `If-None-Match` and the other conditional request headers.\n",
        "x-kovlet-session": "none",
        "x-kovlet-local-blob-store": true,
        "security": [],
        "parameters": [
          {
            "name": "op",
            "in": "query",
            "required": true,
            "description": "Signed operation; `get` for downloads.",
            "schema": {
              "type": "string",
              "const": "get"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The blob's bytes.",
            "headers": {
              "Content-Type": {
                "description": "The signed `ct`, or `application/octet-stream`.",
                "schema": {
                  "type": "string"
                }
              },
              "Content-Disposition": {
                "description": "The signed `cd`, when set.",
                "schema": {
                  "type": "string"
                }
              },
              "ETag": {
                "description": "`\"<sha256>\"`.",
                "schema": {
                  "type": "string"
                }
              },
              "Cache-Control": {
                "schema": {
                  "type": "string",
                  "const": "private, max-age=31536000, immutable"
                }
              }
            },
            "content": {
              "*/*": {
                "schema": {}
              }
            }
          },
          "206": {
            "description": "Partial content for a `Range` request.",
            "headers": {
              "Content-Type": {
                "description": "The signed `ct`, or `application/octet-stream`.",
                "schema": {
                  "type": "string"
                }
              },
              "Content-Disposition": {
                "description": "The signed `cd`, when set.",
                "schema": {
                  "type": "string"
                }
              },
              "ETag": {
                "description": "`\"<sha256>\"`.",
                "schema": {
                  "type": "string"
                }
              },
              "Cache-Control": {
                "schema": {
                  "type": "string",
                  "const": "private, max-age=31536000, immutable"
                }
              }
            },
            "content": {
              "*/*": {
                "schema": {}
              }
            }
          },
          "304": {
            "description": "Not modified (`If-None-Match` matches the ETag)."
          },
          "403": {
            "description": "`invalid_signature`: the download URL is invalid or expired; ask for a new one.",
            "x-kovlet-error-codes": [
              "invalid_signature"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "`blob_not_found`: no blob with this digest is stored for the space.",
            "x-kovlet-error-codes": [
              "blob_not_found"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "412": {
            "description": "A precondition header (`If-Match`, `If-Unmodified-Since`) failed. Plain-text body.",
            "content": {
              "text/plain": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "416": {
            "description": "The `Range` is not satisfiable. Plain-text body.",
            "content": {
              "text/plain": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      },
      "head": {
        "operationId": "headLocalBlob",
        "tags": [
          "files"
        ],
        "summary": "Check blob bytes (local blob store)",
        "description": "**Auth:** none (signed download URL, `op=get`).\n\nLike the GET, without a body.\n",
        "x-kovlet-session": "none",
        "x-kovlet-local-blob-store": true,
        "security": [],
        "parameters": [
          {
            "name": "op",
            "in": "query",
            "required": true,
            "description": "Signed operation; `get` for downloads.",
            "schema": {
              "type": "string",
              "const": "get"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The blob exists; the headers are those of a GET.",
            "headers": {
              "Content-Type": {
                "description": "The signed `ct`, or `application/octet-stream`.",
                "schema": {
                  "type": "string"
                }
              },
              "Content-Disposition": {
                "description": "The signed `cd`, when set.",
                "schema": {
                  "type": "string"
                }
              },
              "ETag": {
                "description": "`\"<sha256>\"`.",
                "schema": {
                  "type": "string"
                }
              },
              "Cache-Control": {
                "schema": {
                  "type": "string",
                  "const": "private, max-age=31536000, immutable"
                }
              }
            }
          },
          "304": {
            "description": "Not modified (`If-None-Match` matches the ETag)."
          },
          "403": {
            "description": "`invalid_signature`: the URL is invalid or expired (no body).",
            "x-kovlet-error-codes": [
              "invalid_signature"
            ]
          },
          "404": {
            "description": "`blob_not_found`: no blob with this digest is stored for the space (no body).",
            "x-kovlet-error-codes": [
              "blob_not_found"
            ]
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      },
      "options": {
        "operationId": "preflightLocalBlob",
        "tags": [
          "files"
        ],
        "summary": "CORS preflight for blob URLs (local blob store)",
        "description": "**Auth:** none.\n\nLets browser apps on any origin PUT, GET and HEAD the signed URLs.\n(A browser preflight with `Origin` and `Access-Control-Request-Method`\nis answered by kovletd's API-wide CORS layer, also with `204`.)\n",
        "x-kovlet-session": "none",
        "x-kovlet-local-blob-store": true,
        "security": [],
        "responses": {
          "204": {
            "description": "Preflight accepted.",
            "headers": {
              "Access-Control-Allow-Origin": {
                "schema": {
                  "type": "string",
                  "const": "*"
                }
              },
              "Access-Control-Allow-Methods": {
                "schema": {
                  "type": "string"
                }
              },
              "Access-Control-Allow-Headers": {
                "schema": {
                  "type": "string"
                }
              },
              "Access-Control-Max-Age": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/v1/eu/{space}/config": {
      "parameters": [
        {
          "name": "space",
          "in": "path",
          "required": true,
          "description": "The Data Space ID.",
          "schema": {
            "type": "string"
          }
        }
      ],
      "get": {
        "operationId": "getEndUserConfig",
        "tags": [
          "end-users"
        ],
        "summary": "An app's end-user sign-in methods",
        "description": "**Auth:** none (the app's `Origin` must be one it pinned).\n\nSays whether end-user sign-in is on for the app on this space and\nwhich methods it offers: `email` codes always, plus the OAuth and\nID-token providers the owner set up.\n",
        "x-kovlet-session": "none",
        "security": [],
        "parameters": [
          {
            "name": "app_id",
            "in": "query",
            "required": true,
            "description": "The app's ID.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The sign-in configuration (`enabled: false` and no providers when it is off).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/EndUserConfig"
                }
              }
            }
          },
          "400": {
            "description": "`invalid_request`: a required field (such as `app_id`) is missing or the body is not valid JSON.",
            "x-kovlet-error-codes": [
              "invalid_request"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "`origin_mismatch`: the request `Origin` is not one of the app's pinned origins.",
            "x-kovlet-error-codes": [
              "origin_mismatch"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "`space_not_found`: no such space.",
            "x-kovlet-error-codes": [
              "space_not_found"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/v1/eu/{space}/codes": {
      "parameters": [
        {
          "name": "space",
          "in": "path",
          "required": true,
          "description": "The Data Space ID.",
          "schema": {
            "type": "string"
          }
        }
      ],
      "post": {
        "operationId": "sendEndUserCode",
        "tags": [
          "end-users"
        ],
        "summary": "Email an end user a sign-in code",
        "description": "**Auth:** none.\n\nEmails a 6-digit code, valid 10 minutes, that `POST .../token` with\n`grant_type=magic_code` redeems. The answer is the same whether or\nnot the address is in the directory. Rate limited per email, client\nand space, and capped per workspace per day by the plan.\n",
        "x-kovlet-session": "none",
        "security": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "app_id",
                  "email"
                ],
                "properties": {
                  "app_id": {
                    "type": "string"
                  },
                  "email": {
                    "type": "string",
                    "format": "email"
                  }
                }
              },
              "example": {
                "app_id": "x",
                "email": "ann@example.com"
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "The code was sent.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "sent",
                    "expires_in"
                  ],
                  "properties": {
                    "sent": {
                      "type": "boolean"
                    },
                    "expires_in": {
                      "type": "integer",
                      "description": "Seconds the code stays valid."
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "`invalid_request`: `app_id` is missing or the body is not valid JSON.\n`invalid_email`: `email` is not a valid address.\n",
            "x-kovlet-error-codes": [
              "invalid_request",
              "invalid_email"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "`end_users_disabled`: end-user sign-in is not on for this app on\nthis space (or the app is not approved, not pinned, or unknown).\n`origin_mismatch`: the request `Origin` is not one of the app's pinned origins.\n`end_user_blocked`: the end user is blocked in this app.\n",
            "x-kovlet-error-codes": [
              "end_users_disabled",
              "origin_mismatch",
              "end_user_blocked"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "`space_not_found`: no such space.",
            "x-kovlet-error-codes": [
              "space_not_found"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "`rate_limited`: too many codes for this address or client; retry after `details.retry_after` seconds.\n`email_cap_reached`: the workspace sent its daily sign-in emails (plan cap).\n",
            "x-kovlet-error-codes": [
              "rate_limited",
              "email_cap_reached"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          },
          "502": {
            "description": "`email_failed`: the mail provider did not accept the email.",
            "x-kovlet-error-codes": [
              "email_failed"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/eu/{space}/guest": {
      "parameters": [
        {
          "name": "space",
          "in": "path",
          "required": true,
          "description": "The Data Space ID.",
          "schema": {
            "type": "string"
          }
        }
      ],
      "post": {
        "operationId": "endUserGuestSignIn",
        "tags": [
          "end-users"
        ],
        "summary": "Sign in as a guest end user",
        "description": "**Auth:** none.\n\nCreates a guest end user and a session bound to `device_key`. Signing\nin later by any method with the guest's token in `Authorization`\nupgrades the guest in place.\n",
        "x-kovlet-session": "none",
        "security": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "app_id",
                  "device_key"
                ],
                "properties": {
                  "app_id": {
                    "type": "string"
                  },
                  "device_key": {
                    "$ref": "#/components/schemas/DeviceKey"
                  }
                }
              },
              "example": {
                "app_id": "x",
                "device_key": {
                  "kty": "EC",
                  "crv": "P-256",
                  "x": "x",
                  "y": "y"
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "An end-user session.",
            "headers": {
              "Cache-Control": {
                "description": "`no-store`.",
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/EndUserToken"
                }
              }
            }
          },
          "400": {
            "description": "`invalid_request`: `app_id` is missing or the body is not valid JSON.\n`invalid_device_key`: `device_key` is not an EC P-256 public JWK.\n",
            "x-kovlet-error-codes": [
              "invalid_request",
              "invalid_device_key"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "402": {
            "description": "`quota_exceeded`: the workspace reached its monthly active end\nusers (`metric: end_users`); existing end users keep signing in.\n",
            "x-kovlet-error-codes": [
              "quota_exceeded"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/QuotaError"
                }
              }
            }
          },
          "403": {
            "description": "`end_users_disabled`: end-user sign-in is not on for this app on\nthis space (or the app is not approved, not pinned, or unknown).\n`origin_mismatch`: the request `Origin` is not one of the app's pinned origins.\n`end_user_blocked`: the end user is blocked in this app.\n",
            "x-kovlet-error-codes": [
              "end_users_disabled",
              "origin_mismatch",
              "end_user_blocked"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "`space_not_found`: no such space.",
            "x-kovlet-error-codes": [
              "space_not_found"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "`rate_limited`: too many guest sign-ins from this client.",
            "x-kovlet-error-codes": [
              "rate_limited"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/v1/eu/{space}/oauth/{provider}/start": {
      "parameters": [
        {
          "name": "space",
          "in": "path",
          "required": true,
          "description": "The Data Space ID.",
          "schema": {
            "type": "string"
          }
        },
        {
          "name": "provider",
          "in": "path",
          "required": true,
          "description": "`google`, `apple`, `github` or `linkedin`.",
          "schema": {
            "type": "string"
          }
        }
      ],
      "get": {
        "operationId": "startEndUserOAuth",
        "tags": [
          "end-users"
        ],
        "summary": "Start an end-user OAuth sign-in",
        "description": "**Auth:** none.\n\nRedirects the browser to the provider, using the owner's own OAuth\nclient. After the provider, Kovlet redirects to `redirect_uri` with\n`code` and `state` (or `error` and `state`); the app redeems the code\nat `POST .../token` with `grant_type=authorization_code` and its PKCE\n`code_verifier`. `redirect_uri` must be one of the app's redirect URIs\nor a URL on one of its pinned origins.\n",
        "x-kovlet-session": "none",
        "security": [],
        "parameters": [
          {
            "name": "app_id",
            "in": "query",
            "required": true,
            "description": "The app's ID.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "redirect_uri",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "state",
            "in": "query",
            "required": true,
            "description": "The app's own state, returned unchanged.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "code_challenge",
            "in": "query",
            "required": true,
            "description": "S256 PKCE challenge.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "code_challenge_method",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "S256"
              ]
            }
          }
        ],
        "responses": {
          "302": {
            "description": "Redirect to the provider.",
            "headers": {
              "Location": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "description": "`invalid_request`: `app_id`, `state` or a valid S256 `code_challenge` is missing.\n`invalid_redirect_uri`: `redirect_uri` is not one the app registered or pinned.\n",
            "x-kovlet-error-codes": [
              "invalid_request",
              "invalid_redirect_uri"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "`end_users_disabled`: end-user sign-in is not on for this app on\nthis space (or the app is not approved, not pinned, or unknown).\n`origin_mismatch`: the request `Origin` is not one of the app's pinned origins.\n`end_user_blocked`: the end user is blocked in this app.\n",
            "x-kovlet-error-codes": [
              "end_users_disabled",
              "origin_mismatch",
              "end_user_blocked"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "`space_not_found`: no such space.\n`unknown_provider`: the owner has not set up this provider for the space.\n",
            "x-kovlet-error-codes": [
              "space_not_found",
              "unknown_provider"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/v1/eu/oauth/{provider}/callback": {
      "parameters": [
        {
          "name": "provider",
          "in": "path",
          "required": true,
          "description": "`google`, `apple`, `github` or `linkedin`.",
          "schema": {
            "type": "string"
          }
        }
      ],
      "get": {
        "operationId": "endUserOAuthCallback",
        "tags": [
          "end-users"
        ],
        "summary": "End-user OAuth callback (one URL for every space)",
        "description": "**Auth:** none. The provider sends the browser here; register this\nURL in the provider's console (the console shows it per provider).\nRedirects (303) to the app's `redirect_uri` with `code` and `state`,\nor with `error` (`access_denied`, `server_error`) and `state`.\n",
        "x-kovlet-session": "none",
        "security": [],
        "parameters": [
          {
            "name": "state",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "code",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "303": {
            "description": "Redirect to the app.",
            "headers": {
              "Location": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "description": "`invalid_request`: `state` is missing or the callback is unreadable.\n`invalid_state`: the sign-in expired, was used, or doesn't match.\n",
            "x-kovlet-error-codes": [
              "invalid_request",
              "invalid_state"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      },
      "post": {
        "operationId": "endUserOAuthCallbackPost",
        "tags": [
          "end-users"
        ],
        "summary": "End-user OAuth callback (form_post, Apple)",
        "description": "**Auth:** none. The same as the GET callback, for providers that post it (Apple).",
        "x-kovlet-session": "none",
        "security": [],
        "requestBody": {
          "required": false,
          "content": {
            "application/x-www-form-urlencoded": {
              "schema": {
                "type": "object",
                "properties": {
                  "state": {
                    "type": "string"
                  },
                  "code": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "303": {
            "description": "Redirect to the app.",
            "headers": {
              "Location": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "description": "`invalid_request`: `state` is missing or the callback is unreadable.\n`invalid_state`: the sign-in expired, was used, or doesn't match.\n",
            "x-kovlet-error-codes": [
              "invalid_request",
              "invalid_state"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/v1/eu/{space}/token": {
      "parameters": [
        {
          "name": "space",
          "in": "path",
          "required": true,
          "description": "The Data Space ID.",
          "schema": {
            "type": "string"
          }
        }
      ],
      "post": {
        "operationId": "endUserToken",
        "tags": [
          "end-users"
        ],
        "summary": "Redeem an end-user grant",
        "description": "**Auth:** none; send a guest's token in `Authorization` (with its\ndevice proof) to upgrade that guest.\n\nGrants: `magic_code` (`email`, `code`), `authorization_code`\n(`code`, `code_verifier`, `redirect_uri`), `id_token` (`provider`,\n`id_token`: an ID token from the external issuer the owner set up,\nchecked against its JWKS, `iss`, `aud` and `exp`), `sign_in_code`\n(`code`, minted by a server) and `refresh_token` (`refresh_token`,\nwith a `Kovlet-Device-Proof` signed over it). Every grant but\n`refresh_token` takes `app_id` and `device_key`.\n\nA provider-verified email signs in to the end user with that email.\nA guest whose identity belongs to another end user switches to them,\nand `guest_id` names the guest. New sign-ups past the workspace's\n`end_users` quota get `quota_exceeded`.\n",
        "x-kovlet-session": "none",
        "security": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "grant_type"
                ],
                "properties": {
                  "grant_type": {
                    "type": "string",
                    "enum": [
                      "magic_code",
                      "authorization_code",
                      "id_token",
                      "sign_in_code",
                      "refresh_token"
                    ]
                  },
                  "app_id": {
                    "type": "string"
                  },
                  "email": {
                    "type": "string"
                  },
                  "code": {
                    "type": "string"
                  },
                  "code_verifier": {
                    "type": "string"
                  },
                  "redirect_uri": {
                    "type": "string"
                  },
                  "provider": {
                    "type": "string"
                  },
                  "id_token": {
                    "type": "string"
                  },
                  "refresh_token": {
                    "type": "string"
                  },
                  "device_key": {
                    "$ref": "#/components/schemas/DeviceKey"
                  }
                }
              },
              "example": {
                "grant_type": "magic_code",
                "app_id": "x",
                "email": "ann@example.com",
                "code": "123456",
                "device_key": {
                  "kty": "EC",
                  "crv": "P-256",
                  "x": "x",
                  "y": "y"
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "An end-user session.",
            "headers": {
              "Cache-Control": {
                "description": "`no-store`.",
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/EndUserToken"
                }
              }
            }
          },
          "400": {
            "description": "`invalid_request`: a required field is missing or the body is not valid JSON.\n`invalid_grant`: the code, token or refresh token is wrong, used, expired or doesn't verify.\n`unsupported_grant_type`: unknown `grant_type`.\n`invalid_device_key`: `device_key` is not an EC P-256 public JWK.\n",
            "x-kovlet-error-codes": [
              "invalid_request",
              "invalid_grant",
              "unsupported_grant_type",
              "invalid_device_key"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "`unauthenticated`: the guest token in `Authorization` is invalid or expired.",
            "x-kovlet-error-codes": [
              "unauthenticated"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "402": {
            "description": "`quota_exceeded`: the workspace reached its monthly active end\nusers (`metric: end_users`); existing end users keep signing in.\n",
            "x-kovlet-error-codes": [
              "quota_exceeded"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/QuotaError"
                }
              }
            }
          },
          "403": {
            "description": "`end_users_disabled`, `origin_mismatch`, `end_user_blocked`: as for sending codes.",
            "x-kovlet-error-codes": [
              "end_users_disabled",
              "origin_mismatch",
              "end_user_blocked"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "`space_not_found`: no such space.\n`unknown_provider`: no ID-token provider of that name for the space.\n",
            "x-kovlet-error-codes": [
              "space_not_found",
              "unknown_provider"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "`concurrent_sign_in`: another sign-in for the same account raced this one; retry.",
            "x-kovlet-error-codes": [
              "concurrent_sign_in"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          },
          "502": {
            "description": "`issuer_unavailable`: the external issuer's keys could not be fetched.",
            "x-kovlet-error-codes": [
              "issuer_unavailable"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/eu/{space}/me": {
      "parameters": [
        {
          "name": "space",
          "in": "path",
          "required": true,
          "description": "The Data Space ID.",
          "schema": {
            "type": "string"
          }
        }
      ],
      "get": {
        "operationId": "getEndUserMe",
        "tags": [
          "end-users"
        ],
        "summary": "The signed-in end user",
        "description": "**Auth:** an end-user session (`kvu_` token and its device proof) for this space.\n",
        "x-kovlet-session": "any",
        "security": [
          {
            "endUserToken": [],
            "deviceProof": []
          }
        ],
        "responses": {
          "200": {
            "description": "The end user.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "user"
                  ],
                  "properties": {
                    "user": {
                      "$ref": "#/components/schemas/EndUser"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "`unauthenticated`: not an end-user token, or an invalid, expired or revoked session or device proof.",
            "x-kovlet-error-codes": [
              "unauthenticated"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "`forbidden`: the session belongs to another space.",
            "x-kovlet-error-codes": [
              "forbidden"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "`space_not_found`: no such space.",
            "x-kovlet-error-codes": [
              "space_not_found"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/v1/eu/{space}/sign-out": {
      "parameters": [
        {
          "name": "space",
          "in": "path",
          "required": true,
          "description": "The Data Space ID.",
          "schema": {
            "type": "string"
          }
        }
      ],
      "post": {
        "operationId": "endUserSignOut",
        "tags": [
          "end-users"
        ],
        "summary": "End an end-user session",
        "description": "**Auth:** an end-user session for this space. Revokes the session and its refresh token.\n",
        "x-kovlet-session": "any",
        "security": [
          {
            "endUserToken": [],
            "deviceProof": []
          }
        ],
        "responses": {
          "204": {
            "description": "Signed out."
          },
          "401": {
            "description": "`unauthenticated`: not an end-user token, or an invalid, expired or revoked session or device proof.",
            "x-kovlet-error-codes": [
              "unauthenticated"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "`forbidden`: the session belongs to another space.",
            "x-kovlet-error-codes": [
              "forbidden"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "`space_not_found`: no such space.",
            "x-kovlet-error-codes": [
              "space_not_found"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/v1/spaces/{id}/end-users": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "description": "The Data Space ID.",
          "schema": {
            "type": "string"
          }
        }
      ],
      "get": {
        "operationId": "listEndUsers",
        "tags": [
          "end-users"
        ],
        "summary": "List a space's end users",
        "description": "**Auth:** console session of a space owner, or a machine session\nwhose grant on the space has the impersonate flag.\n\nThe end-user directory, newest first. `q` searches emails; pass\n`next_after` as `after` for the next page.\n",
        "x-kovlet-session": "any",
        "x-kovlet-space-role": "owner",
        "security": [
          {
            "sessionToken": [],
            "deviceProof": []
          },
          {
            "sessionToken": []
          }
        ],
        "parameters": [
          {
            "name": "q",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "after",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 500,
              "default": 50
            }
          }
        ],
        "responses": {
          "200": {
            "description": "One page of the directory.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "end_users"
                  ],
                  "properties": {
                    "end_users": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/EndUserAdmin"
                      }
                    },
                    "next_after": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/InvalidRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "description": "`console_required`: not a console session or a machine.\n`impersonation_not_allowed`: the machine's grant lacks the impersonate flag.\nPolicy denials (the code is the reason), as for other space routes.\n",
            "x-kovlet-error-codes": [
              "console_required",
              "impersonation_not_allowed",
              "insufficient_role",
              "scope_required",
              "no_machine_grant",
              "no_app_grant",
              "machine_revoked",
              "machine_not_approved",
              "app_revoked",
              "app_not_approved",
              "origin_mismatch",
              "unknown_principal"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      },
      "post": {
        "operationId": "createEndUser",
        "tags": [
          "end-users"
        ],
        "summary": "Add an end user by email",
        "description": "**Auth:** as for listing, or an app session of the space's owner\nwith write access (`kovlet-mcp migrate instantdb` imports `$users`\nthis way). `id` keeps an imported ID (a UUID, e.g. from InstantDB's\n`$users`); without it the server assigns one. The address is\nverified once the person signs in with it.\n",
        "x-kovlet-session": "any",
        "x-kovlet-space-role": "owner",
        "security": [
          {
            "sessionToken": [],
            "deviceProof": []
          },
          {
            "sessionToken": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "email"
                ],
                "properties": {
                  "email": {
                    "type": "string",
                    "format": "email"
                  },
                  "id": {
                    "type": "string",
                    "format": "uuid"
                  }
                }
              },
              "example": {
                "email": "imported@example.com"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "end_user"
                  ],
                  "properties": {
                    "end_user": {
                      "$ref": "#/components/schemas/EndUserAdmin"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "`invalid_request`: the body is not valid JSON.\n`invalid_email`: not a valid address. `invalid_id`: `id` is not a canonical UUID.\n",
            "x-kovlet-error-codes": [
              "invalid_request",
              "invalid_email",
              "invalid_id"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "description": "`console_required`: not a console session or a machine.\n`impersonation_not_allowed`: the machine's grant lacks the impersonate flag.\nPolicy denials (the code is the reason), as for other space routes.\n",
            "x-kovlet-error-codes": [
              "console_required",
              "impersonation_not_allowed",
              "insufficient_role",
              "scope_required",
              "no_machine_grant",
              "no_app_grant",
              "machine_revoked",
              "machine_not_approved",
              "app_revoked",
              "app_not_approved",
              "origin_mismatch",
              "unknown_principal"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "description": "`end_user_exists`: the ID or email is taken in this space.",
            "x-kovlet-error-codes": [
              "end_user_exists"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/v1/spaces/{id}/end-users/{eid}": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "description": "The Data Space ID.",
          "schema": {
            "type": "string"
          }
        },
        {
          "name": "eid",
          "in": "path",
          "required": true,
          "description": "The end user's ID.",
          "schema": {
            "type": "string"
          }
        }
      ],
      "get": {
        "operationId": "getEndUser",
        "tags": [
          "end-users"
        ],
        "summary": "One end user",
        "description": "**Auth:** as for listing end users.",
        "x-kovlet-session": "any",
        "x-kovlet-space-role": "owner",
        "security": [
          {
            "sessionToken": [],
            "deviceProof": []
          },
          {
            "sessionToken": []
          }
        ],
        "responses": {
          "200": {
            "description": "The end user.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "end_user"
                  ],
                  "properties": {
                    "end_user": {
                      "$ref": "#/components/schemas/EndUserAdmin"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "description": "`console_required`: not a console session or a machine.\n`impersonation_not_allowed`: the machine's grant lacks the impersonate flag.\nPolicy denials (the code is the reason), as for other space routes.\n",
            "x-kovlet-error-codes": [
              "console_required",
              "impersonation_not_allowed",
              "insufficient_role",
              "scope_required",
              "no_machine_grant",
              "no_app_grant",
              "machine_revoked",
              "machine_not_approved",
              "app_revoked",
              "app_not_approved",
              "origin_mismatch",
              "unknown_principal"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      },
      "patch": {
        "operationId": "patchEndUser",
        "tags": [
          "end-users"
        ],
        "summary": "Block or unblock an end user",
        "description": "**Auth:** as for listing end users. Blocking revokes the end user's\nsessions and refuses sign-in.\n",
        "x-kovlet-session": "any",
        "x-kovlet-space-role": "owner",
        "security": [
          {
            "sessionToken": [],
            "deviceProof": []
          },
          {
            "sessionToken": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "blocked"
                ],
                "properties": {
                  "blocked": {
                    "type": "boolean"
                  }
                }
              },
              "example": {
                "blocked": true
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The end user.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "end_user"
                  ],
                  "properties": {
                    "end_user": {
                      "$ref": "#/components/schemas/EndUserAdmin"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/InvalidRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "description": "`console_required`: not a console session or a machine.\n`impersonation_not_allowed`: the machine's grant lacks the impersonate flag.\nPolicy denials (the code is the reason), as for other space routes.\n",
            "x-kovlet-error-codes": [
              "console_required",
              "impersonation_not_allowed",
              "insufficient_role",
              "scope_required",
              "no_machine_grant",
              "no_app_grant",
              "machine_revoked",
              "machine_not_approved",
              "app_revoked",
              "app_not_approved",
              "origin_mismatch",
              "unknown_principal"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      },
      "delete": {
        "operationId": "deleteEndUser",
        "tags": [
          "end-users"
        ],
        "summary": "Erase an end user",
        "description": "**Auth:** as for listing end users. Removes the directory entry,\nidentities, sessions and the `_users` row, which is hard-deleted with\nits oplog images scrubbed (erasure requests). Rows the end user wrote\nstay with the app: find them with the activity filter `end_user=`\nand undo them with the rollback kind `undo_end_user`.\n",
        "x-kovlet-session": "any",
        "x-kovlet-space-role": "owner",
        "security": [
          {
            "sessionToken": [],
            "deviceProof": []
          },
          {
            "sessionToken": []
          }
        ],
        "responses": {
          "204": {
            "description": "Erased."
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "description": "`console_required`: not a console session or a machine.\n`impersonation_not_allowed`: the machine's grant lacks the impersonate flag.\nPolicy denials (the code is the reason), as for other space routes.\n",
            "x-kovlet-error-codes": [
              "console_required",
              "impersonation_not_allowed",
              "insufficient_role",
              "scope_required",
              "no_machine_grant",
              "no_app_grant",
              "machine_revoked",
              "machine_not_approved",
              "app_revoked",
              "app_not_approved",
              "origin_mismatch",
              "unknown_principal"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/v1/spaces/{id}/end-users/{eid}/sign-in-codes": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "description": "The Data Space ID.",
          "schema": {
            "type": "string"
          }
        },
        {
          "name": "eid",
          "in": "path",
          "required": true,
          "description": "The end user's ID.",
          "schema": {
            "type": "string"
          }
        }
      ],
      "post": {
        "operationId": "mintEndUserSignInCode",
        "tags": [
          "end-users"
        ],
        "summary": "Mint a one-time sign-in code for an end user",
        "description": "**Auth:** as for listing end users. For custom auth backends\n(InstantDB's `auth.createToken`): the server hands the code to its\nclient, which redeems it at `POST /v1/eu/{space}/token` with\n`grant_type=sign_in_code` and its own device key. Valid 10 minutes, once.\nA machine may leave `app_id` out to mint for its own app.\n",
        "x-kovlet-session": "any",
        "x-kovlet-space-role": "owner",
        "security": [
          {
            "sessionToken": [],
            "deviceProof": []
          },
          {
            "sessionToken": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "app_id": {
                    "type": "string"
                  }
                }
              },
              "example": {
                "app_id": "x"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The code.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "code",
                    "expires_at"
                  ],
                  "properties": {
                    "code": {
                      "type": "string"
                    },
                    "expires_at": {
                      "type": "string",
                      "format": "date-time"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/InvalidRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "description": "As for listing end users, plus `end_users_disabled` (sign-in is off for the app) and `end_user_blocked`.\n",
            "x-kovlet-error-codes": [
              "console_required",
              "impersonation_not_allowed",
              "end_users_disabled",
              "end_user_blocked",
              "origin_mismatch",
              "insufficient_role",
              "scope_required",
              "no_machine_grant",
              "no_app_grant",
              "machine_revoked",
              "machine_not_approved",
              "app_revoked",
              "app_not_approved",
              "unknown_principal"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "`not_found` or `space_not_found`.",
            "x-kovlet-error-codes": [
              "not_found",
              "space_not_found"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/v1/spaces/{id}/end-user-settings": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "description": "The Data Space ID.",
          "schema": {
            "type": "string"
          }
        }
      ],
      "get": {
        "operationId": "getEndUserSettings",
        "tags": [
          "end-users"
        ],
        "summary": "End-user settings of a space",
        "description": "**Auth:** console session; owner of the space. The apps with a grant\non the space and whether end-user sign-in is on for each (with what\nis `missing` to turn it on), the configured providers, and the\ncallback URL to register with each OAuth provider.\n",
        "x-kovlet-session": "console",
        "x-kovlet-space-role": "owner",
        "security": [
          {
            "sessionToken": [],
            "deviceProof": []
          },
          {
            "sessionToken": []
          }
        ],
        "responses": {
          "200": {
            "description": "The settings.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "callback_url",
                    "callback_urls",
                    "apps",
                    "providers"
                  ],
                  "properties": {
                    "callback_url": {
                      "type": "string",
                      "description": "The callback URL with a `{provider}` placeholder."
                    },
                    "callback_urls": {
                      "type": "object",
                      "additionalProperties": {
                        "type": "string"
                      }
                    },
                    "apps": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "required": [
                          "app_id",
                          "name",
                          "enabled",
                          "max_role",
                          "missing"
                        ],
                        "properties": {
                          "app_id": {
                            "type": "string"
                          },
                          "name": {
                            "type": "string"
                          },
                          "enabled": {
                            "type": "boolean"
                          },
                          "max_role": {
                            "type": "string"
                          },
                          "missing": {
                            "type": "array",
                            "items": {
                              "type": "string",
                              "enum": [
                                "approval",
                                "origins_or_redirect_uris"
                              ]
                            }
                          }
                        }
                      }
                    },
                    "providers": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/AuthProvider"
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "description": "`console_required`: not a console session.\nPolicy denials (the code is the reason): `insufficient_role`, `scope_required`, `machine_revoked`, `machine_not_approved`, `unknown_principal`.\n",
            "x-kovlet-error-codes": [
              "console_required",
              "insufficient_role",
              "scope_required",
              "machine_revoked",
              "machine_not_approved",
              "unknown_principal"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/v1/spaces/{id}/apps/{appId}/end-users": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "description": "The Data Space ID.",
          "schema": {
            "type": "string"
          }
        },
        {
          "name": "appId",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string"
          }
        }
      ],
      "put": {
        "operationId": "putAppEndUsers",
        "tags": [
          "end-users"
        ],
        "summary": "Turn end-user sign-in on or off for an app",
        "description": "**Auth:** console session; owner of the space. Turning it on needs an\napproved app with pinned origins or redirect URIs. Turning it off\nends the app's end-user sessions on the space.\n",
        "x-kovlet-session": "console",
        "x-kovlet-space-role": "owner",
        "security": [
          {
            "sessionToken": [],
            "deviceProof": []
          },
          {
            "sessionToken": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "enabled"
                ],
                "properties": {
                  "enabled": {
                    "type": "boolean"
                  }
                }
              },
              "example": {
                "enabled": false
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Done.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "app_id",
                    "enabled"
                  ],
                  "properties": {
                    "app_id": {
                      "type": "string"
                    },
                    "enabled": {
                      "type": "boolean"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/InvalidRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "description": "`console_required`: not a console session.\nPolicy denials (the code is the reason): `insufficient_role`, `scope_required`, `machine_revoked`, `machine_not_approved`, `unknown_principal`.\n",
            "x-kovlet-error-codes": [
              "console_required",
              "insufficient_role",
              "scope_required",
              "machine_revoked",
              "machine_not_approved",
              "unknown_principal"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "description": "`end_users_requirements`: the app isn't ready; `details.missing` lists `approval` and/or `origins_or_redirect_uris`.\n`no_app_grant`: grant the app access to the space first.\n",
            "x-kovlet-error-codes": [
              "end_users_requirements",
              "no_app_grant"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/v1/spaces/{id}/auth-providers/{name}": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "description": "The Data Space ID.",
          "schema": {
            "type": "string"
          }
        },
        {
          "name": "name",
          "in": "path",
          "required": true,
          "description": "`google`, `apple`, `github`, `linkedin`, or the name of an ID-token provider (`clerk`, `firebase`, ...).",
          "schema": {
            "type": "string"
          }
        }
      ],
      "put": {
        "operationId": "putAuthProvider",
        "tags": [
          "end-users"
        ],
        "summary": "Set up an end-user sign-in provider",
        "description": "**Auth:** console session; owner of the space. OAuth providers take\nthe owner's own client (`client_id`, `client_secret`; Apple:\n`client_id`, `team_id`, `key_id`, `private_key`). Secrets are sealed\nwith `KOVLET_SECRETS_KEY` and never returned; leaving the secret out\non an update keeps it. Other names are ID-token providers: `issuer`\n(https), `audience` and optionally `jwks_url`.\n",
        "x-kovlet-session": "console",
        "x-kovlet-space-role": "owner",
        "security": [
          {
            "sessionToken": [],
            "deviceProof": []
          },
          {
            "sessionToken": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "client_id": {
                    "type": "string"
                  },
                  "client_secret": {
                    "type": "string"
                  },
                  "team_id": {
                    "type": "string"
                  },
                  "key_id": {
                    "type": "string"
                  },
                  "private_key": {
                    "type": "string"
                  },
                  "issuer": {
                    "type": "string"
                  },
                  "audience": {
                    "type": "string"
                  },
                  "jwks_url": {
                    "type": "string"
                  }
                }
              },
              "example": {
                "issuer": "https://clerk.example.com",
                "audience": "board"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The provider.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "provider"
                  ],
                  "properties": {
                    "provider": {
                      "$ref": "#/components/schemas/AuthProvider"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "`invalid_request`: the body is not valid JSON.\n`invalid_provider`: a field is missing or invalid for this provider.\n",
            "x-kovlet-error-codes": [
              "invalid_request",
              "invalid_provider"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "description": "`console_required`: not a console session.\nPolicy denials (the code is the reason): `insufficient_role`, `scope_required`, `machine_revoked`, `machine_not_approved`, `unknown_principal`.\n",
            "x-kovlet-error-codes": [
              "console_required",
              "insufficient_role",
              "scope_required",
              "machine_revoked",
              "machine_not_approved",
              "unknown_principal"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          },
          "503": {
            "description": "`secrets_key_missing`: this server has no `KOVLET_SECRETS_KEY`, so it can't store client secrets.",
            "x-kovlet-error-codes": [
              "secrets_key_missing"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "delete": {
        "operationId": "deleteAuthProvider",
        "tags": [
          "end-users"
        ],
        "summary": "Remove an end-user sign-in provider",
        "description": "**Auth:** console session; owner of the space.",
        "x-kovlet-session": "console",
        "x-kovlet-space-role": "owner",
        "security": [
          {
            "sessionToken": [],
            "deviceProof": []
          },
          {
            "sessionToken": []
          }
        ],
        "responses": {
          "204": {
            "description": "Removed."
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "description": "`console_required`: not a console session.\nPolicy denials (the code is the reason): `insufficient_role`, `scope_required`, `machine_revoked`, `machine_not_approved`, `unknown_principal`.\n",
            "x-kovlet-error-codes": [
              "console_required",
              "insufficient_role",
              "scope_required",
              "machine_revoked",
              "machine_not_approved",
              "unknown_principal"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/v1/spaces/{id}/machine-grants/{mid}/{appId}/impersonate": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "description": "The Data Space ID.",
          "schema": {
            "type": "string"
          }
        },
        {
          "name": "mid",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string"
          }
        },
        {
          "name": "appId",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string"
          }
        }
      ],
      "put": {
        "operationId": "putMachineGrantImpersonate",
        "tags": [
          "end-users"
        ],
        "summary": "Let a machine act as end users",
        "description": "**Auth:** console session; owner of the space. With the flag on, the\nmachine's sessions may send `Kovlet-As-End-User` (evaluated exactly\nas that end user, capped by the machine grant) and manage the\nend-user directory.\n",
        "x-kovlet-session": "console",
        "x-kovlet-space-role": "owner",
        "security": [
          {
            "sessionToken": [],
            "deviceProof": []
          },
          {
            "sessionToken": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "enabled"
                ],
                "properties": {
                  "enabled": {
                    "type": "boolean"
                  }
                }
              },
              "example": {
                "enabled": false
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Done.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "machine_id",
                    "app_id",
                    "impersonate"
                  ],
                  "properties": {
                    "machine_id": {
                      "type": "string"
                    },
                    "app_id": {
                      "type": "string"
                    },
                    "impersonate": {
                      "type": "boolean"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/InvalidRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "description": "`console_required`: not a console session.\nPolicy denials (the code is the reason): `insufficient_role`, `scope_required`, `machine_revoked`, `machine_not_approved`, `unknown_principal`.\n",
            "x-kovlet-error-codes": [
              "console_required",
              "insufficient_role",
              "scope_required",
              "machine_revoked",
              "machine_not_approved",
              "unknown_principal"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/v1/spaces/{id}/rules": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "description": "The Data Space ID.",
          "schema": {
            "type": "string"
          }
        }
      ],
      "get": {
        "operationId": "getSpaceRules",
        "tags": [
          "end-users"
        ],
        "summary": "A space's end-user rules",
        "description": "**Auth:** console session; owner of the space. Version 0 and an empty\ndocument mean no rules are stored: end users are closed by default,\nand see their own `_users` row.\n",
        "x-kovlet-session": "console",
        "x-kovlet-space-role": "owner",
        "security": [
          {
            "sessionToken": [],
            "deviceProof": []
          },
          {
            "sessionToken": []
          }
        ],
        "responses": {
          "200": {
            "description": "The rules.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SpaceRules"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "description": "`console_required`: not a console session.\nPolicy denials (the code is the reason): `insufficient_role`, `scope_required`, `machine_revoked`, `machine_not_approved`, `unknown_principal`.\n",
            "x-kovlet-error-codes": [
              "console_required",
              "insufficient_role",
              "scope_required",
              "machine_revoked",
              "machine_not_approved",
              "unknown_principal"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      },
      "put": {
        "operationId": "putSpaceRules",
        "tags": [
          "end-users"
        ],
        "summary": "Replace a space's end-user rules",
        "description": "**Auth:** console session; owner of the space. Stores a new version\n(the owner's own approval; apps propose rules with\n`POST /v1/spaces/{space}/rules/proposals`). The document has the\nshape of InstantDB's `instant.perms.ts`: per table, CEL rules for\n`view`, `create`, `update` and `delete`, plus `bind` and `$default`\n(docs/guides/rules.md). Every rule is checked against the space's\nschema; `_users` only takes `view`, `_files` takes the four actions\nand `_rooms` takes `join`. End users' live subscriptions re-plan\nunder the new rules.\n",
        "x-kovlet-session": "console",
        "x-kovlet-space-role": "owner",
        "security": [
          {
            "sessionToken": [],
            "deviceProof": []
          },
          {
            "sessionToken": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "document"
                ],
                "properties": {
                  "document": {
                    "type": "object"
                  }
                }
              },
              "example": {
                "document": {
                  "todos": {
                    "bind": [
                      "isOwner",
                      "auth.id == data.owner"
                    ],
                    "allow": {
                      "view": "isOwner",
                      "create": "isOwner"
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The rules.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SpaceRules"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/InvalidRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "description": "`console_required`: not a console session.\nPolicy denials (the code is the reason): `insufficient_role`, `scope_required`, `machine_revoked`, `machine_not_approved`, `unknown_principal`.\n",
            "x-kovlet-error-codes": [
              "console_required",
              "insufficient_role",
              "scope_required",
              "machine_revoked",
              "machine_not_approved",
              "unknown_principal"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "422": {
            "description": "`rules_invalid`: the document doesn't validate; `errors` lists each problem by rule.",
            "x-kovlet-error-codes": [
              "rules_invalid"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RulesError"
                }
              }
            }
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/v1/workspaces/{wid}/partner-keys": {
      "get": {
        "operationId": "listPartnerKeys",
        "tags": [
          "partners"
        ],
        "summary": "Partner status and keys",
        "description": "**Auth:** console session; workspace owner or admin.\n\n`partner` is null until Kovlet staff turn partner access on for the\nworkspace (`kovletd admin partner enable`); then it holds the display\nname customers see on claim pages. Keys never include their secret.\nSee docs/guides/partners.md and ADR 0022.\n",
        "x-kovlet-session": "console",
        "security": [
          {
            "sessionToken": [],
            "deviceProof": []
          },
          {
            "sessionToken": []
          }
        ],
        "parameters": [
          {
            "name": "wid",
            "in": "path",
            "required": true,
            "description": "Workspace ID.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The partner and its keys, newest first.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "partner",
                    "keys"
                  ],
                  "properties": {
                    "partner": {
                      "oneOf": [
                        {
                          "type": "null"
                        },
                        {
                          "$ref": "#/components/schemas/Partner"
                        }
                      ]
                    },
                    "keys": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/PartnerKey"
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "description": "`console_required`, or `workspace_admin_required`: only owners and admins manage partner keys.",
            "x-kovlet-error-codes": [
              "console_required",
              "workspace_admin_required"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      },
      "post": {
        "operationId": "createPartnerKey",
        "tags": [
          "partners"
        ],
        "summary": "Create a partner key",
        "description": "**Auth:** console session; workspace owner or admin. A partner key can\nnever create, list or revoke partner keys.\n\nReturns the key (`kvp_...`) once. `scopes` defaults to `read` and\n`manage`; `keys` (minting Machine Auth Keys, the only way a partner\nreaches data or end users) must be asked for. At most 20 active keys\nper partner: rotate by creating a new key, switching, then revoking\nthe old one.\n",
        "x-kovlet-session": "console",
        "security": [
          {
            "sessionToken": [],
            "deviceProof": []
          },
          {
            "sessionToken": []
          }
        ],
        "parameters": [
          {
            "name": "wid",
            "in": "path",
            "required": true,
            "description": "Workspace ID.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "name"
                ],
                "properties": {
                  "name": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 100
                  },
                  "scopes": {
                    "type": "array",
                    "items": {
                      "type": "string",
                      "enum": [
                        "read",
                        "manage",
                        "keys"
                      ]
                    },
                    "description": "Default `[\"read\", \"manage\"]`. `manage` and `keys` imply `read`."
                  },
                  "expires_in": {
                    "type": "integer",
                    "minimum": 0,
                    "description": "Seconds until the key expires; 0 or absent never."
                  }
                }
              },
              "example": {
                "name": "production backend",
                "scopes": [
                  "read",
                  "manage",
                  "keys"
                ]
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "The key's metadata and the secret, shown once.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "key",
                    "partner_key"
                  ],
                  "properties": {
                    "key": {
                      "$ref": "#/components/schemas/PartnerKey"
                    },
                    "partner_key": {
                      "type": "string",
                      "description": "The `kvp_` secret. Store it; it isn't shown again."
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/InvalidRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "description": "`console_required`, `workspace_admin_required`, `partner_not_enabled`\n(ask Kovlet to become a partner) or `partner_suspended`.\n",
            "x-kovlet-error-codes": [
              "console_required",
              "workspace_admin_required",
              "partner_not_enabled",
              "partner_suspended"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "description": "`too_many_keys`: the partner holds 20 active keys; revoke one first.",
            "x-kovlet-error-codes": [
              "too_many_keys"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/v1/partner-keys/{id}/revoke": {
      "post": {
        "operationId": "revokePartnerKey",
        "tags": [
          "partners"
        ],
        "summary": "Revoke a partner key",
        "description": "**Auth:** console session; owner or admin of the key's workspace.\n\nThe key stops working at once (`401 invalid_partner_key`). With\n`revoke_machine_keys`, also revokes every Machine Auth Key it minted\nthat is still in the partner workspace, ending their sessions\n(incident response). Keys on transferred spaces belong to the customer\nand are left alone. The body is optional.\n",
        "x-kovlet-session": "console",
        "security": [
          {
            "sessionToken": [],
            "deviceProof": []
          },
          {
            "sessionToken": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "Partner key ID.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "revoke_machine_keys": {
                    "type": "boolean"
                  }
                }
              },
              "example": {
                "revoke_machine_keys": false
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The revoked key.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "key",
                    "machine_keys_revoked"
                  ],
                  "properties": {
                    "key": {
                      "$ref": "#/components/schemas/PartnerKey"
                    },
                    "machine_keys_revoked": {
                      "type": "integer"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/InvalidRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "description": "`console_required` or `workspace_admin_required`.",
            "x-kovlet-error-codes": [
              "console_required",
              "workspace_admin_required"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/v1/transfers/{token}": {
      "get": {
        "operationId": "reviewTransfer",
        "tags": [
          "partners"
        ],
        "summary": "Review a claim link",
        "description": "**Auth:** console session (the customer, signed in).\n\nWhat the console's `/claim?t=kvt_...` page shows before a customer\ntakes over a space a partner generated: the partner, the space and\nits counts, its apps and origins, the Machine Auth Keys the partner\nminted, its sign-in providers, and each workspace the user may claim\nit into with whether it fits there. A link bound to another email,\nexpired, cancelled or unknown answers `404 unknown_transfer`.\n",
        "x-kovlet-session": "console",
        "security": [
          {
            "sessionToken": [],
            "deviceProof": []
          },
          {
            "sessionToken": []
          }
        ],
        "parameters": [
          {
            "name": "token",
            "in": "path",
            "required": true,
            "description": "The claim token (`kvt_...`) from the claim URL.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The review.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TransferReview"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "$ref": "#/components/responses/ConsoleRequired"
          },
          "404": {
            "$ref": "#/components/responses/UnknownTransfer"
          },
          "409": {
            "description": "`transfer_accepted`: this space was already claimed.",
            "x-kovlet-error-codes": [
              "transfer_accepted"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/v1/transfers/{token}/accept": {
      "post": {
        "operationId": "acceptTransfer",
        "tags": [
          "partners"
        ],
        "summary": "Claim a space",
        "description": "**Auth:** console session (the customer); the user must be a member\nof `workspace_id`, which can't be the partner's own workspace.\n\nMoves the space, in one transaction, into `workspace_id` with the\nsame IDs: records, files, schema, rules, end users and their\nsessions, and auth providers stay as they are, so the deployed app\nkeeps working. The claimer becomes the owner. Apps move too, approved\nwhen the claimer is an admin or owner there, otherwise pending\n(`apps_pending_approval`). `machine_keys` decides the partner-minted\nMachine Auth Keys: `keep` (default) moves them to the claimer,\n`revoke` ends them. Partner access ends at once. If the destination\nlacks room (spaces, rows, storage, end users, kept machines) the claim\nanswers `402 quota_exceeded`, nothing moves and the link stays valid.\n",
        "x-kovlet-session": "console",
        "security": [
          {
            "sessionToken": [],
            "deviceProof": []
          },
          {
            "sessionToken": []
          }
        ],
        "parameters": [
          {
            "name": "token",
            "in": "path",
            "required": true,
            "description": "The claim token (`kvt_...`).",
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "workspace_id"
                ],
                "properties": {
                  "workspace_id": {
                    "type": "string"
                  },
                  "machine_keys": {
                    "type": "string",
                    "enum": [
                      "keep",
                      "revoke"
                    ],
                    "default": "keep"
                  }
                }
              },
              "example": {
                "workspace_id": "0192f3a4-0000-7000-8000-000000000001",
                "machine_keys": "keep"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The claimed space, now owned by the caller.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "space",
                    "apps_pending_approval"
                  ],
                  "properties": {
                    "space": {
                      "$ref": "#/components/schemas/SpaceView"
                    },
                    "apps_pending_approval": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      },
                      "description": "Apps that wait for a workspace admin's approval; their end users can't sign in until then."
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/InvalidRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "402": {
            "$ref": "#/components/responses/QuotaExceeded"
          },
          "403": {
            "$ref": "#/components/responses/ConsoleRequired"
          },
          "404": {
            "description": "`unknown_transfer`, or `not_found`: you aren't a member of that workspace.",
            "x-kovlet-error-codes": [
              "unknown_transfer",
              "not_found"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "`transfer_accepted` (already claimed) or `same_workspace` (the partner's own workspace).",
            "x-kovlet-error-codes": [
              "transfer_accepted",
              "same_workspace"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/v1/partner": {
      "get": {
        "operationId": "getPartner",
        "tags": [
          "partners"
        ],
        "summary": "The partner, the key's scopes and pooled usage",
        "description": "**Auth:** partner key with `read`. The partner's limits are its\nworkspace's quotas, pooled across every app it generated.\n",
        "x-kovlet-session": "partner",
        "security": [
          {
            "partnerKey": []
          }
        ],
        "responses": {
          "200": {
            "description": "The partner.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "partner",
                    "key",
                    "usage"
                  ],
                  "properties": {
                    "partner": {
                      "type": "object",
                      "required": [
                        "workspace_id",
                        "display_name"
                      ],
                      "properties": {
                        "workspace_id": {
                          "type": "string"
                        },
                        "display_name": {
                          "type": "string"
                        }
                      }
                    },
                    "key": {
                      "type": "object",
                      "required": [
                        "id",
                        "scopes"
                      ],
                      "properties": {
                        "id": {
                          "type": "string"
                        },
                        "scopes": {
                          "type": "array",
                          "items": {
                            "type": "string",
                            "enum": [
                              "read",
                              "manage",
                              "keys"
                            ]
                          }
                        }
                      }
                    },
                    "usage": {
                      "$ref": "#/components/schemas/UsageReport"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/PartnerUnauthenticated"
          },
          "403": {
            "$ref": "#/components/responses/PartnerForbidden"
          },
          "429": {
            "$ref": "#/components/responses/PartnerRateLimited"
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/v1/partner/usage/daily": {
      "get": {
        "operationId": "partnerUsageDaily",
        "tags": [
          "partners"
        ],
        "summary": "Daily usage snapshots",
        "description": "**Auth:** partner key with `read`. One row per managed space per UTC\nday (rows, storage, active end users), what a partner is invoiced\nfrom. Spaces stop appearing the day after they are transferred.\n",
        "x-kovlet-session": "partner",
        "security": [
          {
            "partnerKey": []
          }
        ],
        "parameters": [
          {
            "name": "from",
            "in": "query",
            "required": false,
            "description": "First day (YYYY-MM-DD); default 30 days ago.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "to",
            "in": "query",
            "required": false,
            "description": "Last day (YYYY-MM-DD); default today.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "space",
            "in": "query",
            "required": false,
            "description": "Only this space.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The snapshots, by day then space.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "from",
                    "to",
                    "days"
                  ],
                  "properties": {
                    "from": {
                      "type": "string"
                    },
                    "to": {
                      "type": "string"
                    },
                    "days": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "required": [
                          "space_id",
                          "day",
                          "rows",
                          "storage_bytes",
                          "end_users_active"
                        ],
                        "properties": {
                          "space_id": {
                            "type": "string"
                          },
                          "day": {
                            "type": "string"
                          },
                          "rows": {
                            "type": "integer"
                          },
                          "storage_bytes": {
                            "type": "integer"
                          },
                          "end_users_active": {
                            "type": "integer"
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/InvalidRequest"
          },
          "401": {
            "$ref": "#/components/responses/PartnerUnauthenticated"
          },
          "403": {
            "$ref": "#/components/responses/PartnerForbidden"
          },
          "404": {
            "$ref": "#/components/responses/UnknownSpace"
          },
          "429": {
            "$ref": "#/components/responses/PartnerRateLimited"
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/v1/partner/audit-events": {
      "get": {
        "operationId": "partnerAuditEvents",
        "tags": [
          "partners"
        ],
        "summary": "The partner's audit trail",
        "description": "**Auth:** partner key with `read`. Every control-plane change in the\npartner workspace, newest first: keys, spaces, schema, rules, apps,\nproviders, machine keys, limits and transfers, each with the partner\nkey (`actor_partner_key_id`) or user behind it.\n",
        "x-kovlet-session": "partner",
        "security": [
          {
            "partnerKey": []
          }
        ],
        "parameters": [
          {
            "name": "space",
            "in": "query",
            "required": false,
            "description": "Only this space.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "kind",
            "in": "query",
            "required": false,
            "description": "Only this kind, e.g. `machine_key.created`.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "before",
            "in": "query",
            "required": false,
            "description": "Page with `next_before`.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "description": "1 to 200; default 50.",
            "schema": {
              "type": "integer"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The events.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "events"
                  ],
                  "properties": {
                    "events": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/PartnerAuditEvent"
                      }
                    },
                    "next_before": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/InvalidRequest"
          },
          "401": {
            "$ref": "#/components/responses/PartnerUnauthenticated"
          },
          "403": {
            "$ref": "#/components/responses/PartnerForbidden"
          },
          "429": {
            "$ref": "#/components/responses/PartnerRateLimited"
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/v1/partner/spaces": {
      "get": {
        "operationId": "listPartnerSpaces",
        "tags": [
          "partners"
        ],
        "summary": "List the partner's spaces",
        "description": "**Auth:** partner key with `read`. Managed spaces come with their\nusage and limits; transferred ones only as `{id, external_id,\nstatus: \"transferred\", transferred_at}`. Poll\n`?status=transferred` to learn about claims.\n",
        "x-kovlet-session": "partner",
        "security": [
          {
            "partnerKey": []
          }
        ],
        "parameters": [
          {
            "name": "external_id",
            "in": "query",
            "required": false,
            "description": "Only the space with this external ID.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "status",
            "in": "query",
            "required": false,
            "description": "`managed` or `transferred`.",
            "schema": {
              "type": "string",
              "enum": [
                "managed",
                "transferred"
              ]
            }
          },
          {
            "name": "after",
            "in": "query",
            "required": false,
            "description": "Page with `next_after`.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "description": "1 to 200; default 50.",
            "schema": {
              "type": "integer"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The spaces in ID order.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "spaces"
                  ],
                  "properties": {
                    "spaces": {
                      "type": "array",
                      "items": {
                        "oneOf": [
                          {
                            "$ref": "#/components/schemas/PartnerSpace"
                          },
                          {
                            "$ref": "#/components/schemas/TransferredSpace"
                          }
                        ]
                      }
                    },
                    "next_after": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/InvalidRequest"
          },
          "401": {
            "$ref": "#/components/responses/PartnerUnauthenticated"
          },
          "403": {
            "$ref": "#/components/responses/PartnerForbidden"
          },
          "429": {
            "$ref": "#/components/responses/PartnerRateLimited"
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      },
      "post": {
        "operationId": "createPartnerSpace",
        "tags": [
          "partners"
        ],
        "summary": "Create a space for a generated app",
        "description": "**Auth:** partner key with `manage`. Counts against the partner's\nspaces quota. The space has no user grants: apps reach it through app\ngrants, servers through Machine Auth Keys, end users through the app\nplus rules. `external_id` is the partner's own ID: a retry with a\ntaken one answers `409 external_id_taken` with `space_id`. `limits`\nare per-app caps that only narrow the partner's pooled limits.\n",
        "x-kovlet-session": "partner",
        "security": [
          {
            "partnerKey": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "name"
                ],
                "properties": {
                  "name": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 100
                  },
                  "external_id": {
                    "type": "string",
                    "maxLength": 200
                  },
                  "limits": {
                    "$ref": "#/components/schemas/SpaceLimits"
                  }
                }
              },
              "example": {
                "name": "Todo app",
                "external_id": "gen-8f2c",
                "limits": {
                  "max_end_users": 500
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "The space.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "space"
                  ],
                  "properties": {
                    "space": {
                      "$ref": "#/components/schemas/PartnerSpace"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/InvalidRequest"
          },
          "401": {
            "$ref": "#/components/responses/PartnerUnauthenticated"
          },
          "402": {
            "$ref": "#/components/responses/QuotaExceeded"
          },
          "403": {
            "$ref": "#/components/responses/PartnerForbidden"
          },
          "409": {
            "description": "`external_id_taken`: `space_id` (next to `code`) is the space created earlier with this external ID.",
            "x-kovlet-error-codes": [
              "external_id_taken"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "$ref": "#/components/responses/PartnerRateLimited"
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/v1/partner/spaces/{id}": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "description": "Data Space ID.",
          "schema": {
            "type": "string"
          }
        }
      ],
      "get": {
        "operationId": "getPartnerSpace",
        "tags": [
          "partners"
        ],
        "summary": "A managed space with its apps, keys, providers and open transfer",
        "description": "**Auth:** partner key with `read`. Spaces the partner doesn't manage\nanswer `404 unknown_space`, never 403. After a transfer, only\n`{id, external_id, status: \"transferred\", transferred_at}`.\n",
        "x-kovlet-session": "partner",
        "security": [
          {
            "partnerKey": []
          }
        ],
        "responses": {
          "200": {
            "description": "The space.",
            "content": {
              "application/json": {
                "schema": {
                  "oneOf": [
                    {
                      "type": "object",
                      "required": [
                        "space",
                        "apps",
                        "machine_keys",
                        "auth_providers",
                        "pending_proposals",
                        "transfer"
                      ],
                      "properties": {
                        "space": {
                          "$ref": "#/components/schemas/PartnerSpace"
                        },
                        "apps": {
                          "type": "array",
                          "items": {
                            "$ref": "#/components/schemas/PartnerApp"
                          }
                        },
                        "machine_keys": {
                          "type": "array",
                          "items": {
                            "$ref": "#/components/schemas/PartnerMachineKey"
                          }
                        },
                        "auth_providers": {
                          "type": "array",
                          "items": {
                            "$ref": "#/components/schemas/AuthProvider"
                          }
                        },
                        "pending_proposals": {
                          "type": "array",
                          "items": {
                            "$ref": "#/components/schemas/SchemaProposal"
                          }
                        },
                        "transfer": {
                          "oneOf": [
                            {
                              "type": "null"
                            },
                            {
                              "$ref": "#/components/schemas/Transfer"
                            }
                          ]
                        }
                      }
                    },
                    {
                      "type": "object",
                      "required": [
                        "space"
                      ],
                      "properties": {
                        "space": {
                          "$ref": "#/components/schemas/TransferredSpace"
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/PartnerUnauthenticated"
          },
          "403": {
            "$ref": "#/components/responses/PartnerForbidden"
          },
          "404": {
            "$ref": "#/components/responses/UnknownSpace"
          },
          "429": {
            "$ref": "#/components/responses/PartnerRateLimited"
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      },
      "patch": {
        "operationId": "patchPartnerSpace",
        "tags": [
          "partners"
        ],
        "summary": "Rename a space or set its per-app limits",
        "description": "**Auth:** partner key with `manage`. `limits` replaces every cap: a\nlimit left out is removed.\n",
        "x-kovlet-session": "partner",
        "security": [
          {
            "partnerKey": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "name": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 100
                  },
                  "limits": {
                    "$ref": "#/components/schemas/SpaceLimits"
                  }
                }
              },
              "example": {
                "limits": {
                  "max_rows": 100000,
                  "max_end_users": 1000
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The space.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "space"
                  ],
                  "properties": {
                    "space": {
                      "$ref": "#/components/schemas/PartnerSpace"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/InvalidRequest"
          },
          "401": {
            "$ref": "#/components/responses/PartnerUnauthenticated"
          },
          "403": {
            "$ref": "#/components/responses/PartnerForbidden"
          },
          "404": {
            "$ref": "#/components/responses/UnknownSpace"
          },
          "429": {
            "$ref": "#/components/responses/PartnerRateLimited"
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      },
      "delete": {
        "operationId": "deletePartnerSpace",
        "tags": [
          "partners"
        ],
        "summary": "Delete a space",
        "description": "**Auth:** partner key with `manage`. Deletes the space and everything\nin it, revokes its apps and Machine Auth Keys and cancels an open\ntransfer. `space.deleted` stays in the audit trail.\n",
        "x-kovlet-session": "partner",
        "security": [
          {
            "partnerKey": []
          }
        ],
        "responses": {
          "204": {
            "description": "Deleted."
          },
          "401": {
            "$ref": "#/components/responses/PartnerUnauthenticated"
          },
          "403": {
            "$ref": "#/components/responses/PartnerForbidden"
          },
          "404": {
            "$ref": "#/components/responses/UnknownSpace"
          },
          "429": {
            "$ref": "#/components/responses/PartnerRateLimited"
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/v1/partner/spaces/{id}/schema": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "description": "Data Space ID.",
          "schema": {
            "type": "string"
          }
        }
      ],
      "get": {
        "operationId": "getPartnerSchema",
        "tags": [
          "partners"
        ],
        "summary": "The space's schema and pending proposals",
        "description": "**Auth:** partner key with `read`.",
        "x-kovlet-session": "partner",
        "security": [
          {
            "partnerKey": []
          }
        ],
        "responses": {
          "200": {
            "description": "The schema.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "tables",
                    "pending_proposals"
                  ],
                  "properties": {
                    "tables": {
                      "$ref": "#/components/schemas/Tables"
                    },
                    "pending_proposals": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/SchemaProposal"
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/PartnerUnauthenticated"
          },
          "403": {
            "$ref": "#/components/responses/PartnerForbidden"
          },
          "404": {
            "$ref": "#/components/responses/UnknownSpace"
          },
          "429": {
            "$ref": "#/components/responses/PartnerRateLimited"
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      },
      "post": {
        "operationId": "postPartnerSchema",
        "tags": [
          "partners"
        ],
        "summary": "Declare tables or apply schema changes",
        "description": "**Auth:** partner key with `manage`. Send exactly one of `tables`\n(the declared schema, the same JSON as `hello.schema`; differences\nare computed) or `changes` (the same JSON as\n`POST /v1/spaces/{space}/schema/changes`). Additive changes apply at\nonce; destructive ones become proposals, which `approve: true`\napproves right away. Answers 202 while proposals still wait. Schema\nops are attributed to the partner key (`by` is empty on the wire).\n",
        "x-kovlet-session": "partner",
        "security": [
          {
            "partnerKey": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "tables": {
                    "type": "object",
                    "additionalProperties": {
                      "$ref": "#/components/schemas/TableSchema"
                    }
                  },
                  "changes": {
                    "type": "array",
                    "items": {
                      "$ref": "#/components/schemas/SchemaChangeInput"
                    }
                  },
                  "approve": {
                    "type": "boolean"
                  }
                }
              },
              "example": {
                "tables": {
                  "todos": {
                    "columns": {
                      "title": {
                        "type": "string"
                      },
                      "done": {
                        "type": "boolean",
                        "optional": true
                      }
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Applied.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SchemaChangeResult"
                }
              }
            }
          },
          "202": {
            "description": "Applied, with destructive changes waiting as proposals.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SchemaChangeResult"
                }
              }
            }
          },
          "400": {
            "description": "`invalid_request` or `invalid_change`.",
            "x-kovlet-error-codes": [
              "invalid_request",
              "invalid_change"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/PartnerUnauthenticated"
          },
          "403": {
            "$ref": "#/components/responses/PartnerForbidden"
          },
          "404": {
            "$ref": "#/components/responses/UnknownSpace"
          },
          "409": {
            "description": "`proposal_stale`, `proposal_decided`, `unique_violation`, `rows_violate_schema` or `trashed_rows_conflict` while approving; `trashed_rows_conflict` for a `create_table` in `changes` over a dropped table's misfitting rows in the Trash.",
            "x-kovlet-error-codes": [
              "proposal_stale",
              "proposal_decided",
              "unique_violation",
              "rows_violate_schema",
              "trashed_rows_conflict"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "`invalid_change`: the changes don't apply to the current schema.",
            "x-kovlet-error-codes": [
              "invalid_change"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "$ref": "#/components/responses/PartnerRateLimited"
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/v1/partner/spaces/{id}/schema/proposals/{pid}/decision": {
      "post": {
        "operationId": "decidePartnerProposal",
        "tags": [
          "partners"
        ],
        "summary": "Approve or reject a schema proposal",
        "description": "**Auth:** partner key with `manage`. For proposals the generated app itself caused.",
        "x-kovlet-session": "partner",
        "security": [
          {
            "partnerKey": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "Data Space ID.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "pid",
            "in": "path",
            "required": true,
            "description": "Proposal ID.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "approve"
                ],
                "properties": {
                  "approve": {
                    "type": "boolean"
                  }
                }
              },
              "example": {
                "approve": true
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The decided proposal.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ProposalDecision"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/InvalidRequest"
          },
          "401": {
            "$ref": "#/components/responses/PartnerUnauthenticated"
          },
          "403": {
            "$ref": "#/components/responses/PartnerForbidden"
          },
          "404": {
            "description": "`unknown_space` or `proposal_not_found`.",
            "x-kovlet-error-codes": [
              "unknown_space",
              "proposal_not_found"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "`proposal_decided`, `proposal_stale`, `unique_violation`, `rows_violate_schema` or `trashed_rows_conflict`.",
            "x-kovlet-error-codes": [
              "proposal_decided",
              "proposal_stale",
              "unique_violation",
              "rows_violate_schema",
              "trashed_rows_conflict"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "$ref": "#/components/responses/PartnerRateLimited"
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/v1/partner/spaces/{id}/rules": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "description": "Data Space ID.",
          "schema": {
            "type": "string"
          }
        }
      ],
      "get": {
        "operationId": "getPartnerRules",
        "tags": [
          "partners"
        ],
        "summary": "The space's rules",
        "description": "**Auth:** partner key with `read`.",
        "x-kovlet-session": "partner",
        "security": [
          {
            "partnerKey": []
          }
        ],
        "responses": {
          "200": {
            "description": "The current rules (version 0 and `{}` before any are stored).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SpaceRules"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/PartnerUnauthenticated"
          },
          "403": {
            "$ref": "#/components/responses/PartnerForbidden"
          },
          "404": {
            "$ref": "#/components/responses/UnknownSpace"
          },
          "429": {
            "$ref": "#/components/responses/PartnerRateLimited"
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      },
      "put": {
        "operationId": "putPartnerRules",
        "tags": [
          "partners"
        ],
        "summary": "Set the space's rules",
        "description": "**Auth:** partner key with `manage`. The same body, rules format and\ncode path as `PUT /v1/spaces/{id}/rules`; applied directly, with no\nproposal (ADR 0021 §3.1, ADR 0022 §3.1).\n",
        "x-kovlet-session": "partner",
        "security": [
          {
            "partnerKey": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "document"
                ],
                "properties": {
                  "document": {
                    "type": "object"
                  }
                }
              },
              "example": {
                "document": {
                  "todos": {
                    "allow": {
                      "$default": "true"
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The stored rules.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SpaceRules"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/InvalidRequest"
          },
          "401": {
            "$ref": "#/components/responses/PartnerUnauthenticated"
          },
          "403": {
            "$ref": "#/components/responses/PartnerForbidden"
          },
          "404": {
            "$ref": "#/components/responses/UnknownSpace"
          },
          "422": {
            "description": "`rules_invalid`: the document doesn't validate; `errors` lists why.",
            "x-kovlet-error-codes": [
              "rules_invalid"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "$ref": "#/components/responses/PartnerRateLimited"
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/v1/partner/spaces/{id}/apps": {
      "post": {
        "operationId": "createPartnerApp",
        "tags": [
          "partners"
        ],
        "summary": "Create an app with end-user sign-in",
        "description": "**Auth:** partner key with `manage`. Creates an approved app pinned\nto `origins` (and `redirect_uris` on them), grants it `role` on the\nspace (default editor), and with `end_users: true` turns on end-user\nsign-in. The app's ID is the `appId` the generated app configures.\nAt most 10 apps per space.\n",
        "x-kovlet-session": "partner",
        "security": [
          {
            "partnerKey": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "Data Space ID.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PartnerAppInput"
              },
              "example": {
                "name": "Todo web",
                "origins": [
                  "https://todo-8f2c.example.app"
                ],
                "role": "editor",
                "end_users": true
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "The app.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "app"
                  ],
                  "properties": {
                    "app": {
                      "$ref": "#/components/schemas/PartnerApp"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/InvalidRequest"
          },
          "401": {
            "$ref": "#/components/responses/PartnerUnauthenticated"
          },
          "403": {
            "$ref": "#/components/responses/PartnerForbidden"
          },
          "404": {
            "$ref": "#/components/responses/UnknownSpace"
          },
          "409": {
            "description": "`too_many_apps` (10 per space) or `end_users_requirements`.",
            "x-kovlet-error-codes": [
              "too_many_apps",
              "end_users_requirements"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "$ref": "#/components/responses/PartnerRateLimited"
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/v1/partner/spaces/{id}/apps/{appId}": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "description": "Data Space ID.",
          "schema": {
            "type": "string"
          }
        },
        {
          "name": "appId",
          "in": "path",
          "required": true,
          "description": "App ID.",
          "schema": {
            "type": "string"
          }
        }
      ],
      "patch": {
        "operationId": "patchPartnerApp",
        "tags": [
          "partners"
        ],
        "summary": "Change an app",
        "description": "**Auth:** partner key with `manage`. `end_users: false` ends the app's end-user sessions.",
        "x-kovlet-session": "partner",
        "security": [
          {
            "partnerKey": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PartnerAppInput"
              },
              "example": {
                "name": "Todo web (beta)"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The app.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "app"
                  ],
                  "properties": {
                    "app": {
                      "$ref": "#/components/schemas/PartnerApp"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/InvalidRequest"
          },
          "401": {
            "$ref": "#/components/responses/PartnerUnauthenticated"
          },
          "403": {
            "$ref": "#/components/responses/PartnerForbidden"
          },
          "404": {
            "description": "`unknown_space` or `unknown_app`.",
            "x-kovlet-error-codes": [
              "unknown_space",
              "unknown_app"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "`end_users_requirements`, or a concurrent change (`conflict`).",
            "x-kovlet-error-codes": [
              "end_users_requirements",
              "conflict",
              "concurrent_modification"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "$ref": "#/components/responses/PartnerRateLimited"
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      },
      "delete": {
        "operationId": "deletePartnerApp",
        "tags": [
          "partners"
        ],
        "summary": "Revoke an app",
        "description": "**Auth:** partner key with `manage`. Ends its sessions and its end users' sessions.",
        "x-kovlet-session": "partner",
        "security": [
          {
            "partnerKey": []
          }
        ],
        "responses": {
          "204": {
            "description": "Revoked."
          },
          "401": {
            "$ref": "#/components/responses/PartnerUnauthenticated"
          },
          "403": {
            "$ref": "#/components/responses/PartnerForbidden"
          },
          "404": {
            "description": "`unknown_space` or `unknown_app`.",
            "x-kovlet-error-codes": [
              "unknown_space",
              "unknown_app"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "$ref": "#/components/responses/PartnerRateLimited"
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/v1/partner/spaces/{id}/auth-providers/{name}": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "description": "Data Space ID.",
          "schema": {
            "type": "string"
          }
        },
        {
          "name": "name",
          "in": "path",
          "required": true,
          "description": "Provider name: google, apple, github, linkedin, or an ID-token issuer's name.",
          "schema": {
            "type": "string"
          }
        }
      ],
      "put": {
        "operationId": "putPartnerAuthProvider",
        "tags": [
          "partners"
        ],
        "summary": "Set an end-user sign-in provider",
        "description": "**Auth:** partner key with `manage`. The same body as\n`PUT /v1/spaces/{id}/auth-providers/{name}`; secrets are write-only.\nProviders move with the space on transfer: delete one first if the\ncustomer shouldn't keep using your OAuth client.\n",
        "x-kovlet-session": "partner",
        "security": [
          {
            "partnerKey": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object"
              },
              "example": {
                "client_id": "123.apps.googleusercontent.com",
                "client_secret": "GOCSPX-example"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The provider.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "provider"
                  ],
                  "properties": {
                    "provider": {
                      "$ref": "#/components/schemas/AuthProvider"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "`invalid_request` or `invalid_provider`.",
            "x-kovlet-error-codes": [
              "invalid_request",
              "invalid_provider"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/PartnerUnauthenticated"
          },
          "403": {
            "$ref": "#/components/responses/PartnerForbidden"
          },
          "404": {
            "$ref": "#/components/responses/UnknownSpace"
          },
          "429": {
            "$ref": "#/components/responses/PartnerRateLimited"
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          },
          "503": {
            "description": "`secrets_key_missing`: the server has no KOVLET_SECRETS_KEY to seal client secrets.",
            "x-kovlet-error-codes": [
              "secrets_key_missing"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "delete": {
        "operationId": "deletePartnerAuthProvider",
        "tags": [
          "partners"
        ],
        "summary": "Remove an end-user sign-in provider",
        "description": "**Auth:** partner key with `manage`.",
        "x-kovlet-session": "partner",
        "security": [
          {
            "partnerKey": []
          }
        ],
        "responses": {
          "204": {
            "description": "Removed."
          },
          "401": {
            "$ref": "#/components/responses/PartnerUnauthenticated"
          },
          "403": {
            "$ref": "#/components/responses/PartnerForbidden"
          },
          "404": {
            "description": "`unknown_space`, or `not_found`: no such provider.",
            "x-kovlet-error-codes": [
              "unknown_space",
              "not_found"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "$ref": "#/components/responses/PartnerRateLimited"
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/v1/partner/spaces/{id}/machine-keys": {
      "post": {
        "operationId": "createPartnerMachineKey",
        "tags": [
          "partners"
        ],
        "summary": "Mint a Machine Auth Key for a server",
        "description": "**Auth:** partner key with `keys`. The only way a partner reaches data\nor end users: a headless machine bound to this one space, granted\n`role` for `app_id` (an app of this space), optionally allowed to act\nas end users (`impersonate`). Returns the key (`kvm_...`) once;\nexchange it at `POST /v1/oauth/token`. Counts against the `machines`\nquota, is audited, and is shown to the customer on the claim page.\n",
        "x-kovlet-session": "partner",
        "security": [
          {
            "partnerKey": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "Data Space ID.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "name",
                  "app_id"
                ],
                "properties": {
                  "name": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 100
                  },
                  "app_id": {
                    "type": "string"
                  },
                  "role": {
                    "type": "string",
                    "enum": [
                      "viewer",
                      "editor"
                    ],
                    "default": "editor"
                  },
                  "impersonate": {
                    "type": "boolean"
                  }
                }
              },
              "example": {
                "name": "api server",
                "app_id": "0192f3a4-0000-7000-8000-000000000003",
                "role": "editor"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "The key, shown once.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "machine_id",
                    "machine_key",
                    "machine_key_info"
                  ],
                  "properties": {
                    "machine_id": {
                      "type": "string"
                    },
                    "machine_key": {
                      "type": "string",
                      "description": "The `kvm_` secret."
                    },
                    "machine_key_info": {
                      "$ref": "#/components/schemas/PartnerMachineKey"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/InvalidRequest"
          },
          "401": {
            "$ref": "#/components/responses/PartnerUnauthenticated"
          },
          "402": {
            "$ref": "#/components/responses/QuotaExceeded"
          },
          "403": {
            "$ref": "#/components/responses/PartnerForbidden"
          },
          "404": {
            "description": "`unknown_space` or `unknown_app`.",
            "x-kovlet-error-codes": [
              "unknown_space",
              "unknown_app"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "$ref": "#/components/responses/PartnerRateLimited"
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/v1/partner/spaces/{id}/machine-keys/{mid}/rotate": {
      "post": {
        "operationId": "rotatePartnerMachineKey",
        "tags": [
          "partners"
        ],
        "summary": "Rotate a Machine Auth Key",
        "description": "**Auth:** partner key with `keys`. The old key stops working; live sessions continue until they expire.",
        "x-kovlet-session": "partner",
        "security": [
          {
            "partnerKey": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "Data Space ID.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "mid",
            "in": "path",
            "required": true,
            "description": "Machine ID.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The new key, shown once.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "machine_id",
                    "machine_key"
                  ],
                  "properties": {
                    "machine_id": {
                      "type": "string"
                    },
                    "machine_key": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/PartnerUnauthenticated"
          },
          "403": {
            "$ref": "#/components/responses/PartnerForbidden"
          },
          "404": {
            "description": "`unknown_space` or `unknown_machine_key`.",
            "x-kovlet-error-codes": [
              "unknown_space",
              "unknown_machine_key"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "`machine_key_revoked`.",
            "x-kovlet-error-codes": [
              "machine_key_revoked",
              "conflict",
              "concurrent_modification"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "$ref": "#/components/responses/PartnerRateLimited"
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/v1/partner/spaces/{id}/machine-keys/{mid}": {
      "delete": {
        "operationId": "revokePartnerMachineKey",
        "tags": [
          "partners"
        ],
        "summary": "Revoke a Machine Auth Key",
        "description": "**Auth:** partner key with `keys`. Ends the machine's sessions.",
        "x-kovlet-session": "partner",
        "security": [
          {
            "partnerKey": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "Data Space ID.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "mid",
            "in": "path",
            "required": true,
            "description": "Machine ID.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "204": {
            "description": "Revoked."
          },
          "401": {
            "$ref": "#/components/responses/PartnerUnauthenticated"
          },
          "403": {
            "$ref": "#/components/responses/PartnerForbidden"
          },
          "404": {
            "description": "`unknown_space` or `unknown_machine_key`.",
            "x-kovlet-error-codes": [
              "unknown_space",
              "unknown_machine_key"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "$ref": "#/components/responses/PartnerRateLimited"
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/v1/partner/spaces/{id}/transfers": {
      "post": {
        "operationId": "createTransfer",
        "tags": [
          "partners"
        ],
        "summary": "Create a claim link",
        "description": "**Auth:** partner key with `manage`. A single-use link the customer\nopens to take the space over into their own workspace: `claim_url`,\nshown once, expires after `expires_in` seconds (default 7 days, at\nmost 30). Always set `to_email`: only a Kovlet user with that email\ncan see or accept it. A new link cancels the space's open one.\n",
        "x-kovlet-session": "partner",
        "security": [
          {
            "partnerKey": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "Data Space ID.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "to_email": {
                    "type": "string",
                    "format": "email"
                  },
                  "expires_in": {
                    "type": "integer",
                    "minimum": 60,
                    "maximum": 2592000
                  }
                }
              },
              "example": {
                "to_email": "founder@example.com"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "The transfer with its claim URL.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "transfer"
                  ],
                  "properties": {
                    "transfer": {
                      "$ref": "#/components/schemas/Transfer"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/InvalidRequest"
          },
          "401": {
            "$ref": "#/components/responses/PartnerUnauthenticated"
          },
          "403": {
            "$ref": "#/components/responses/PartnerForbidden"
          },
          "404": {
            "$ref": "#/components/responses/UnknownSpace"
          },
          "429": {
            "$ref": "#/components/responses/PartnerRateLimited"
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    },
    "/v1/partner/spaces/{id}/transfers/{tid}": {
      "delete": {
        "operationId": "cancelTransfer",
        "tags": [
          "partners"
        ],
        "summary": "Cancel a claim link",
        "description": "**Auth:** partner key with `manage`.",
        "x-kovlet-session": "partner",
        "security": [
          {
            "partnerKey": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "Data Space ID.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "tid",
            "in": "path",
            "required": true,
            "description": "Transfer ID.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "204": {
            "description": "Cancelled."
          },
          "401": {
            "$ref": "#/components/responses/PartnerUnauthenticated"
          },
          "403": {
            "$ref": "#/components/responses/PartnerForbidden"
          },
          "404": {
            "description": "`unknown_space` or `unknown_transfer`.",
            "x-kovlet-error-codes": [
              "unknown_space",
              "unknown_transfer"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "$ref": "#/components/responses/PartnerRateLimited"
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "sessionToken": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "kvs_ session token",
        "description": "A Kovlet session token (`kvs_...`) from `POST /v1/oauth/token` or a\nconsole sign-in. Which kinds of session an operation accepts is in its\n`x-kovlet-session` extension.\n"
      },
      "partnerKey": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "kvp_ partner key",
        "description": "A partner key (`kvp_...`) a partner workspace's owner created in the\nconsole. Only `/v1/partner/*` accepts it; it is never a session token.\n"
      },
      "endUserToken": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "kvu_ end-user token",
        "description": "An app end user's access token (`kvu_...`) from `POST /v1/eu/{space}/token`,\nvalid for one space. Always device-bound: send `Kovlet-Device-Proof`.\n"
      },
      "deviceProof": {
        "type": "apiKey",
        "in": "header",
        "name": "Kovlet-Device-Proof",
        "description": "Required with device-bound sessions (from the `authorization_code`\ngrant), ignored otherwise. A fresh proof per request:\n`base64url(JSON({\"ath\": base64url(sha256(token)), \"iat\": <unix seconds>, \"jti\": \"<unique>\"})) + \".\" + base64url(ECDSA P-256 SHA-256 raw r||s signature over the first segment)`.\n`iat` within 5 minutes of server time; each `jti` is accepted once.\n"
      }
    },
    "responses": {
      "PartnerUnauthenticated": {
        "description": "`unauthenticated`: no bearer token, or one that isn't a partner key\n(`kvp_...`); `invalid_partner_key`: unknown, revoked or expired.\n",
        "x-kovlet-error-codes": [
          "unauthenticated",
          "invalid_partner_key"
        ],
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "PartnerForbidden": {
        "description": "`insufficient_scope`: the key lacks the scope this route needs\n(`required`, next to `code`); `partner_suspended`: Kovlet paused this\npartner's access.\n",
        "x-kovlet-error-codes": [
          "insufficient_scope",
          "partner_suspended"
        ],
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "PartnerRateLimited": {
        "description": "`rate_limited`: more than 20 requests per second (bursts of 100) on this key; wait `Retry-After` seconds.",
        "x-kovlet-error-codes": [
          "rate_limited"
        ],
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "UnknownSpace": {
        "description": "`unknown_space`: the partner doesn't manage this space (or never did, or it was transferred).",
        "x-kovlet-error-codes": [
          "unknown_space"
        ],
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "UnknownTransfer": {
        "description": "`unknown_transfer`: the claim link is invalid, expired, cancelled or meant for another account.",
        "x-kovlet-error-codes": [
          "unknown_transfer"
        ],
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "Unauthenticated": {
        "description": "`unauthenticated`: the bearer token is missing, invalid, expired or\nrevoked, or a device-bound session sent no (or a stale, replayed or\nwrongly signed) device proof. Refresh (device-bound sessions) or sign in again.\n",
        "x-kovlet-error-codes": [
          "unauthenticated"
        ],
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "ConsoleRequired": {
        "description": "`console_required`: this endpoint needs a console session (a signed-in\nuser in the web console); app and headless sessions cannot call it.\n",
        "x-kovlet-error-codes": [
          "console_required"
        ],
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "InvalidRequest": {
        "description": "`invalid_request`: the body is not valid JSON for this operation\n(unknown fields, trailing data, over 1 MiB) or a field is invalid.\n",
        "x-kovlet-error-codes": [
          "invalid_request"
        ],
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "NotFound": {
        "description": "`not_found`: the resource does not exist or is not visible to the caller.",
        "x-kovlet-error-codes": [
          "not_found"
        ],
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "Internal": {
        "description": "`internal`: an unexpected server error (the server logs it with the\nresponse's `X-Request-Id`). Retry with backoff; if it keeps failing,\nreport the request id.\n",
        "x-kovlet-error-codes": [
          "internal"
        ],
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "QuotaExceeded": {
        "description": "`quota_exceeded`: a plan limit is reached. `metric`, `used`, `limit`\nand `upgrade_url` say which and where to upgrade.\n",
        "x-kovlet-error-codes": [
          "quota_exceeded"
        ],
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/QuotaError"
            }
          }
        }
      }
    },
    "schemas": {
      "Partner": {
        "type": "object",
        "description": "A workspace with partner access (ADR 0022 §1).",
        "required": [
          "workspace_id",
          "display_name",
          "enabled_at",
          "suspended_at"
        ],
        "properties": {
          "workspace_id": {
            "type": "string"
          },
          "display_name": {
            "type": "string",
            "description": "Shown to customers on claim pages."
          },
          "enabled_at": {
            "type": "string",
            "format": "date-time"
          },
          "suspended_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          }
        }
      },
      "PartnerKey": {
        "type": "object",
        "description": "A partner key's metadata; the secret is only returned when it is created.",
        "required": [
          "id",
          "name",
          "scopes",
          "status",
          "created_at",
          "last_used_at",
          "expires_at",
          "revoked_at"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "scopes": {
            "type": "array",
            "items": {
              "type": "string",
              "enum": [
                "read",
                "manage",
                "keys"
              ]
            }
          },
          "status": {
            "type": "string",
            "enum": [
              "active",
              "expired",
              "revoked"
            ]
          },
          "created_by_user_id": {
            "type": "string"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "last_used_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "expires_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "revoked_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          }
        }
      },
      "SpaceLimits": {
        "type": "object",
        "description": "Per-app caps (ADR 0022 §5). They only narrow the partner's pooled\nlimits; going past one answers `quota_exceeded` with `scope: \"space\"`.\nA limit left out is no cap.\n",
        "additionalProperties": false,
        "properties": {
          "max_rows": {
            "type": "integer",
            "minimum": 0
          },
          "max_storage_bytes": {
            "type": "integer",
            "minimum": 0
          },
          "max_end_users": {
            "type": "integer",
            "minimum": 0,
            "description": "Monthly active end users."
          },
          "max_end_user_emails_per_day": {
            "type": "integer",
            "minimum": 0
          }
        }
      },
      "PartnerSpace": {
        "type": "object",
        "description": "A space a partner manages.",
        "required": [
          "id",
          "status",
          "head_seq",
          "rules_version",
          "limits",
          "created_at"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "external_id": {
            "type": "string"
          },
          "status": {
            "type": "string",
            "const": "managed"
          },
          "name": {
            "type": "string"
          },
          "slug": {
            "type": "string"
          },
          "head_seq": {
            "type": "integer",
            "format": "int64"
          },
          "rules_version": {
            "type": "integer"
          },
          "limits": {
            "$ref": "#/components/schemas/SpaceLimits"
          },
          "usage": {
            "type": "object",
            "required": [
              "rows",
              "storage_bytes",
              "end_users_active",
              "machine_keys"
            ],
            "properties": {
              "rows": {
                "type": "integer"
              },
              "storage_bytes": {
                "type": "integer"
              },
              "end_users_active": {
                "type": "integer"
              },
              "machine_keys": {
                "type": "integer"
              }
            }
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "TransferredSpace": {
        "type": "object",
        "description": "All a partner sees of a space it handed over.",
        "required": [
          "id",
          "status",
          "transferred_at"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "external_id": {
            "type": "string"
          },
          "status": {
            "type": "string",
            "const": "transferred"
          },
          "transferred_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          }
        }
      },
      "PartnerAppInput": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "name": {
            "type": "string",
            "minLength": 1,
            "maxLength": 100
          },
          "origins": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Web origins (or `com.example.app:` for native apps) the app runs on."
          },
          "redirect_uris": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "OAuth redirect URIs on those origins."
          },
          "role": {
            "type": "string",
            "enum": [
              "viewer",
              "editor"
            ]
          },
          "end_users": {
            "type": "boolean",
            "description": "Turn end-user sign-in on or off."
          }
        }
      },
      "PartnerApp": {
        "type": "object",
        "description": "An app a partner created for one space (AppView plus its grant).",
        "required": [
          "id",
          "workspace_id",
          "name",
          "allowed_origins",
          "redirect_uris",
          "approval_status",
          "revoked_at",
          "created_at",
          "role",
          "end_users"
        ],
        "properties": {
          "id": {
            "type": "string",
            "description": "The app's ID: the `appId` the generated app configures, and the `client_id` for machine keys."
          },
          "workspace_id": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "allowed_origins": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "redirect_uris": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "approval_status": {
            "type": "string",
            "enum": [
              "pending",
              "approved",
              "rejected"
            ]
          },
          "created_by_user_id": {
            "type": "string"
          },
          "revoked_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "role": {
            "type": "string",
            "enum": [
              "viewer",
              "editor"
            ]
          },
          "end_users": {
            "type": "boolean"
          }
        }
      },
      "PartnerMachineKey": {
        "type": "object",
        "required": [
          "id",
          "name",
          "impersonate",
          "created_at",
          "last_seen_at",
          "revoked_at"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "app_id": {
            "type": "string"
          },
          "role": {
            "type": "string",
            "enum": [
              "viewer",
              "editor"
            ]
          },
          "impersonate": {
            "type": "boolean"
          },
          "created_by_key_id": {
            "type": "string",
            "description": "The partner key that minted it."
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "last_seen_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "revoked_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          }
        }
      },
      "Transfer": {
        "type": "object",
        "required": [
          "id",
          "status",
          "expires_at",
          "created_at"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "status": {
            "type": "string",
            "enum": [
              "pending",
              "accepted",
              "cancelled"
            ]
          },
          "to_email": {
            "type": "string"
          },
          "claim_url": {
            "type": "string",
            "description": "Only when created: `<console>/claim?t=kvt_...`. Send it to the customer."
          },
          "expires_at": {
            "type": "string",
            "format": "date-time"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "TransferReview": {
        "type": "object",
        "required": [
          "transfer",
          "partner",
          "space",
          "counts",
          "apps",
          "machine_keys",
          "auth_providers",
          "workspaces"
        ],
        "properties": {
          "transfer": {
            "$ref": "#/components/schemas/Transfer"
          },
          "partner": {
            "type": "object",
            "required": [
              "display_name"
            ],
            "properties": {
              "display_name": {
                "type": "string"
              }
            }
          },
          "space": {
            "type": "object",
            "required": [
              "id",
              "name"
            ],
            "properties": {
              "id": {
                "type": "string"
              },
              "name": {
                "type": "string"
              }
            }
          },
          "counts": {
            "type": "object",
            "required": [
              "tables",
              "rows",
              "storage_bytes",
              "end_users_active"
            ],
            "properties": {
              "tables": {
                "type": "integer"
              },
              "rows": {
                "type": "integer"
              },
              "storage_bytes": {
                "type": "integer"
              },
              "end_users_active": {
                "type": "integer"
              }
            }
          },
          "apps": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "id",
                "name",
                "origins"
              ],
              "properties": {
                "id": {
                  "type": "string"
                },
                "name": {
                  "type": "string"
                },
                "origins": {
                  "type": "array",
                  "items": {
                    "type": "string"
                  }
                }
              }
            }
          },
          "machine_keys": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "id",
                "name",
                "created_at",
                "last_seen_at",
                "created_by"
              ],
              "properties": {
                "id": {
                  "type": "string"
                },
                "name": {
                  "type": "string"
                },
                "created_at": {
                  "type": "string",
                  "format": "date-time"
                },
                "last_seen_at": {
                  "type": [
                    "string",
                    "null"
                  ],
                  "format": "date-time"
                },
                "created_by": {
                  "type": "string",
                  "description": "The partner's display name."
                }
              }
            }
          },
          "auth_providers": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "workspaces": {
            "type": "array",
            "description": "Where the user may claim the space, and whether it fits there.",
            "items": {
              "type": "object",
              "required": [
                "workspace_id",
                "name",
                "kind",
                "fits",
                "exceeded",
                "app_approval"
              ],
              "properties": {
                "workspace_id": {
                  "type": "string"
                },
                "name": {
                  "type": "string"
                },
                "kind": {
                  "type": "string",
                  "enum": [
                    "personal",
                    "org"
                  ]
                },
                "fits": {
                  "type": "boolean"
                },
                "exceeded": {
                  "type": "array",
                  "items": {
                    "type": "string"
                  }
                },
                "app_approval": {
                  "type": "string",
                  "enum": [
                    "approved",
                    "pending"
                  ],
                  "description": "What the apps get there; pending means end users lose access until an admin approves."
                }
              }
            }
          }
        }
      },
      "PartnerAuditEvent": {
        "type": "object",
        "required": [
          "id",
          "kind",
          "via",
          "created_at"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "kind": {
            "type": "string",
            "description": "e.g. `space.created`, `rules.changed`, `machine_key.created`, `space.transferred`."
          },
          "space_id": {
            "type": "string"
          },
          "actor_user_id": {
            "type": "string"
          },
          "actor_machine_id": {
            "type": "string"
          },
          "actor_app_id": {
            "type": "string"
          },
          "actor_partner_key_id": {
            "type": "string"
          },
          "app_id": {
            "type": "string"
          },
          "machine_id": {
            "type": "string"
          },
          "role": {
            "type": "string",
            "enum": [
              "viewer",
              "editor",
              "owner"
            ]
          },
          "previous_role": {
            "type": "string",
            "enum": [
              "viewer",
              "editor",
              "owner"
            ]
          },
          "via": {
            "type": "string"
          },
          "details": {
            "type": "object"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "DeviceKey": {
        "type": "object",
        "description": "The SDK's device key, an EC P-256 public JWK.",
        "required": [
          "kty",
          "crv",
          "x",
          "y"
        ],
        "properties": {
          "kty": {
            "type": "string",
            "const": "EC"
          },
          "crv": {
            "type": "string",
            "const": "P-256"
          },
          "x": {
            "type": "string"
          },
          "y": {
            "type": "string"
          }
        }
      },
      "EndUser": {
        "type": "object",
        "description": "An app end user (ADR 0021 §2).",
        "required": [
          "id",
          "email",
          "email_verified",
          "is_guest",
          "created_at"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "email": {
            "type": [
              "string",
              "null"
            ],
            "description": "Null for guests."
          },
          "email_verified": {
            "type": "boolean"
          },
          "is_guest": {
            "type": "boolean"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "EndUserToken": {
        "type": "object",
        "required": [
          "access_token",
          "refresh_token",
          "token_type",
          "expires_in",
          "user"
        ],
        "properties": {
          "access_token": {
            "type": "string",
            "description": "`kvu_` access token; send it with a device proof."
          },
          "refresh_token": {
            "type": "string",
            "description": "`kvur_` refresh token; rotates on use."
          },
          "token_type": {
            "type": "string",
            "const": "Bearer"
          },
          "expires_in": {
            "type": "integer"
          },
          "user": {
            "$ref": "#/components/schemas/EndUser"
          },
          "guest_id": {
            "type": "string",
            "description": "The guest this sign-in switched away from (the identity belonged to another end user)."
          }
        }
      },
      "EndUserAdmin": {
        "type": "object",
        "required": [
          "id",
          "email",
          "email_verified",
          "is_guest",
          "providers",
          "created_at",
          "last_active_at",
          "blocked_at"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "email": {
            "type": [
              "string",
              "null"
            ]
          },
          "email_verified": {
            "type": "boolean"
          },
          "is_guest": {
            "type": "boolean"
          },
          "providers": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Sign-in methods: `email`, `google`, ..."
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "last_active_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "blocked_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          }
        }
      },
      "EndUserConfig": {
        "type": "object",
        "required": [
          "enabled",
          "providers"
        ],
        "properties": {
          "enabled": {
            "type": "boolean"
          },
          "providers": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "name",
                "kind"
              ],
              "properties": {
                "name": {
                  "type": "string"
                },
                "kind": {
                  "type": "string",
                  "enum": [
                    "email",
                    "oauth",
                    "id_token"
                  ]
                }
              }
            }
          }
        }
      },
      "AuthProvider": {
        "type": "object",
        "description": "An end-user sign-in provider. Secrets are never returned; `has_secret` says one is stored.",
        "required": [
          "name",
          "kind",
          "has_secret",
          "updated_at"
        ],
        "properties": {
          "name": {
            "type": "string"
          },
          "kind": {
            "type": "string",
            "enum": [
              "oauth",
              "id_token"
            ]
          },
          "client_id": {
            "type": "string"
          },
          "team_id": {
            "type": "string"
          },
          "key_id": {
            "type": "string"
          },
          "issuer": {
            "type": "string"
          },
          "audience": {
            "type": "string"
          },
          "jwks_url": {
            "type": "string"
          },
          "has_secret": {
            "type": "boolean"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "RulesError": {
        "type": "object",
        "required": [
          "error"
        ],
        "properties": {
          "error": {
            "type": "object",
            "required": [
              "code",
              "message",
              "errors"
            ],
            "properties": {
              "code": {
                "type": "string",
                "const": "rules_invalid"
              },
              "message": {
                "type": "string"
              },
              "hint": {
                "type": "string"
              },
              "errors": {
                "type": "array",
                "items": {
                  "type": "string"
                },
                "description": "One message per problem, prefixed with the rule (`todos.view: ...`)."
              }
            }
          }
        }
      },
      "RulesTestResult": {
        "type": "object",
        "required": [
          "allowed",
          "visible",
          "total"
        ],
        "properties": {
          "allowed": {
            "type": "boolean",
            "description": "View: the end user sees at least one row (or `record_id`). Writes: the rules allow the write."
          },
          "rule": {
            "type": "string",
            "description": "The rule that denied, such as `todos.update`."
          },
          "rows": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/RecordState"
            },
            "description": "View only, at most `limit`."
          },
          "visible": {
            "type": "integer",
            "description": "View only: rows the end user sees."
          },
          "total": {
            "type": "integer",
            "description": "View only: live rows of the table."
          },
          "filter": {
            "type": "string",
            "description": "View only: the compiled view rule, for debugging."
          }
        }
      },
      "SpaceRules": {
        "type": "object",
        "required": [
          "version",
          "document"
        ],
        "properties": {
          "version": {
            "type": "integer",
            "minimum": 0
          },
          "document": {
            "type": "object",
            "description": "The rules document (InstantDB `instant.perms.ts` shape)."
          },
          "updated_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "Error": {
        "type": "object",
        "required": [
          "error"
        ],
        "properties": {
          "error": {
            "type": "object",
            "required": [
              "code",
              "message"
            ],
            "properties": {
              "code": {
                "type": "string",
                "description": "Stable snake_case error code."
              },
              "message": {
                "type": "string"
              },
              "hint": {
                "type": "string",
                "description": "The next step that fixes the error, for an AI coding agent or developer."
              }
            }
          }
        }
      },
      "QuotaError": {
        "type": "object",
        "required": [
          "error"
        ],
        "properties": {
          "error": {
            "type": "object",
            "required": [
              "code",
              "message",
              "metric",
              "used",
              "limit",
              "upgrade_url",
              "reads_open"
            ],
            "properties": {
              "code": {
                "type": "string",
                "const": "quota_exceeded"
              },
              "message": {
                "type": "string"
              },
              "hint": {
                "type": "string"
              },
              "metric": {
                "type": "string",
                "enum": [
                  "spaces",
                  "rows",
                  "storage",
                  "machines",
                  "devices",
                  "guests",
                  "end_users"
                ],
                "description": "The limited metric (`storage` is in bytes)."
              },
              "used": {
                "type": "integer"
              },
              "limit": {
                "type": "integer"
              },
              "upgrade_url": {
                "type": "string"
              },
              "reads_open": {
                "type": "boolean",
                "description": "Always true. Reads, exports and deletes never hit a quota."
              },
              "space_id": {
                "type": "string",
                "description": "The space the limit applies to, for per-space limits."
              },
              "scope": {
                "type": "string",
                "const": "space",
                "description": "Set when a per-app cap a partner set was hit, not the workspace's limit (ADR 0022 §5)."
              },
              "soft_limit": {
                "type": "integer",
                "description": "Rows only, when the grace buffer is used up; the plan's included amount (`limit` is then the hard limit)."
              }
            }
          }
        }
      },
      "OAuthError": {
        "type": "object",
        "required": [
          "error"
        ],
        "properties": {
          "error": {
            "type": "string",
            "description": "OAuth error code (RFC 6749 §5.2, RFC 8628 §3.5)."
          },
          "error_description": {
            "type": "string"
          },
          "reason": {
            "type": "string",
            "enum": [
              "device_revoked"
            ],
            "description": "A machine-readable refinement of `error`. `device_revoked`: the\ndevice key's machine was revoked; generate a new key and sign in\nagain instead of retrying.\n"
          }
        }
      },
      "HealthResponse": {
        "type": "object",
        "required": [
          "status",
          "version",
          "mode"
        ],
        "properties": {
          "status": {
            "type": "string",
            "const": "ok"
          },
          "version": {
            "type": "string",
            "description": "The kovletd build version (may be empty in builds without one)."
          },
          "mode": {
            "type": "string",
            "enum": [
              "production",
              "dev"
            ],
            "description": "`dev` when kovletd runs with `--dev`."
          }
        }
      },
      "ReadyResponse": {
        "type": "object",
        "required": [
          "status",
          "database",
          "blob_store"
        ],
        "properties": {
          "status": {
            "type": "string",
            "const": "ready"
          },
          "database": {
            "type": "string",
            "enum": [
              "sqlite",
              "postgres"
            ],
            "description": "The database dialect."
          },
          "blob_store": {
            "type": "string",
            "const": "ok"
          }
        }
      },
      "JsonRpcRequest": {
        "type": "object",
        "description": "A JSON-RPC 2.0 request (with `id`) or notification (no `id`, or `id: null`).\nA message without `method` is treated as a client response and ignored.\n",
        "required": [
          "jsonrpc",
          "method"
        ],
        "properties": {
          "jsonrpc": {
            "type": "string",
            "const": "2.0"
          },
          "id": {
            "type": [
              "string",
              "integer",
              "null"
            ],
            "description": "Request id, echoed in the response. Absent or null for notifications."
          },
          "method": {
            "type": "string",
            "description": "`initialize`, `ping`, `tools/list`, `tools/call`, `notifications/initialized` or `notifications/cancelled`."
          },
          "params": {
            "description": "Method parameters, e.g. `{\"protocolVersion\": \"2025-06-18\"}` for `initialize` or `{\"name\": \"...\", \"arguments\": {...}}` for `tools/call`."
          }
        }
      },
      "JsonRpcResponse": {
        "type": "object",
        "description": "A JSON-RPC 2.0 response. Carries `result` on success or `error` on\nfailure (a request for a method that returns nothing, such as\n`notifications/initialized` sent with an id, carries neither).\n",
        "required": [
          "jsonrpc",
          "id"
        ],
        "properties": {
          "jsonrpc": {
            "type": "string",
            "const": "2.0"
          },
          "id": {
            "type": [
              "string",
              "integer",
              "null"
            ],
            "description": "The request's id; null when the request could not be read or was rejected before parsing."
          },
          "result": {
            "description": "The method's result: `McpInitializeResult` for `initialize`, `{}`\nfor `ping`, `McpToolsListResult` for `tools/list`,\n`McpToolCallResult` for `tools/call`.\n",
            "anyOf": [
              {
                "$ref": "#/components/schemas/McpInitializeResult"
              },
              {
                "$ref": "#/components/schemas/McpToolsListResult"
              },
              {
                "$ref": "#/components/schemas/McpToolCallResult"
              },
              {
                "type": "object"
              }
            ]
          },
          "error": {
            "$ref": "#/components/schemas/JsonRpcError"
          }
        }
      },
      "JsonRpcError": {
        "type": "object",
        "required": [
          "code",
          "message"
        ],
        "properties": {
          "code": {
            "type": "integer",
            "enum": [
              -32700,
              -32600,
              -32601,
              -32602,
              -32603
            ],
            "description": "`-32700` parse error, `-32600` invalid request (also used for\n401 unauthenticated and 413 body too large), `-32601` method not\nfound, `-32602` invalid params, `-32603` internal error.\n"
          },
          "message": {
            "type": "string"
          },
          "data": {
            "type": "object",
            "description": "Set on 401 responses only.",
            "properties": {
              "code": {
                "type": "string",
                "const": "unauthenticated"
              },
              "hint": {
                "type": "string",
                "description": "How to sign in and retry."
              }
            }
          }
        }
      },
      "OAuthProtectedResourceMetadata": {
        "type": "object",
        "description": "RFC 9728 protected resource metadata.",
        "required": [
          "resource",
          "authorization_servers",
          "scopes_supported",
          "bearer_methods_supported"
        ],
        "properties": {
          "resource": {
            "type": "string",
            "format": "uri",
            "description": "`<base>/mcp`"
          },
          "authorization_servers": {
            "type": "array",
            "items": {
              "type": "string",
              "format": "uri"
            },
            "description": "kovletd's base URL, the issuer."
          },
          "scopes_supported": {
            "type": "array",
            "items": {
              "type": "string",
              "const": "agent"
            }
          },
          "bearer_methods_supported": {
            "type": "array",
            "items": {
              "type": "string",
              "const": "header"
            }
          },
          "resource_name": {
            "type": "string"
          },
          "resource_documentation": {
            "type": "string",
            "format": "uri",
            "description": "`<base>/llms.txt`"
          }
        }
      },
      "OAuthAuthorizationServerMetadata": {
        "type": "object",
        "description": "RFC 8414 authorization server metadata.",
        "required": [
          "issuer",
          "authorization_endpoint",
          "token_endpoint",
          "registration_endpoint",
          "device_authorization_endpoint",
          "grant_types_supported",
          "response_types_supported"
        ],
        "properties": {
          "issuer": {
            "type": "string",
            "format": "uri",
            "description": "kovletd's base URL."
          },
          "authorization_endpoint": {
            "type": "string",
            "format": "uri",
            "description": "`<base>/v1/oauth/authorize` (GET)"
          },
          "token_endpoint": {
            "type": "string",
            "format": "uri",
            "description": "`<base>/v1/oauth/token`"
          },
          "registration_endpoint": {
            "type": "string",
            "format": "uri",
            "description": "`<base>/v1/oauth/register`"
          },
          "device_authorization_endpoint": {
            "type": "string",
            "format": "uri",
            "description": "`<base>/v1/oauth/device_authorization`"
          },
          "grant_types_supported": {
            "type": "array",
            "items": {
              "type": "string",
              "enum": [
                "authorization_code",
                "urn:ietf:params:oauth:grant-type:device_code",
                "refresh_token"
              ]
            }
          },
          "response_types_supported": {
            "type": "array",
            "items": {
              "type": "string",
              "const": "code"
            }
          },
          "response_modes_supported": {
            "type": "array",
            "items": {
              "type": "string",
              "const": "query"
            }
          },
          "code_challenge_methods_supported": {
            "type": "array",
            "items": {
              "type": "string",
              "const": "S256"
            }
          },
          "authorization_response_iss_parameter_supported": {
            "type": "boolean",
            "const": true,
            "description": "The redirect carries `iss` (RFC 9207)."
          },
          "client_id_metadata_document_supported": {
            "type": "boolean",
            "const": false,
            "description": "Client ID Metadata Documents are not supported; register with RFC 7591."
          },
          "scopes_supported": {
            "type": "array",
            "items": {
              "type": "string",
              "const": "agent"
            }
          },
          "token_endpoint_auth_methods_supported": {
            "type": "array",
            "items": {
              "type": "string",
              "const": "none"
            }
          },
          "service_documentation": {
            "type": "string",
            "format": "uri"
          }
        }
      },
      "McpInitializeResult": {
        "type": "object",
        "required": [
          "protocolVersion",
          "capabilities",
          "serverInfo",
          "instructions"
        ],
        "properties": {
          "protocolVersion": {
            "type": "string",
            "enum": [
              "2024-11-05",
              "2025-03-26",
              "2025-06-18",
              "2025-11-25"
            ],
            "description": "The client's requested revision when supported, else `2025-06-18`."
          },
          "capabilities": {
            "type": "object",
            "description": "Always `{\"tools\": {\"listChanged\": false}}`.",
            "properties": {
              "tools": {
                "type": "object",
                "properties": {
                  "listChanged": {
                    "type": "boolean",
                    "const": false
                  }
                }
              }
            }
          },
          "serverInfo": {
            "type": "object",
            "required": [
              "name",
              "title",
              "version"
            ],
            "properties": {
              "name": {
                "type": "string",
                "const": "kovlet"
              },
              "title": {
                "type": "string",
                "const": "Kovlet"
              },
              "version": {
                "type": "string"
              }
            }
          },
          "instructions": {
            "type": "string",
            "description": "How an agent should use the tools (list, inspect, propose, generate)."
          }
        }
      },
      "McpToolsListResult": {
        "type": "object",
        "required": [
          "tools"
        ],
        "properties": {
          "tools": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/McpTool"
            }
          }
        }
      },
      "McpTool": {
        "type": "object",
        "required": [
          "name",
          "title",
          "description",
          "inputSchema",
          "annotations"
        ],
        "properties": {
          "name": {
            "type": "string"
          },
          "title": {
            "type": "string"
          },
          "description": {
            "type": "string"
          },
          "inputSchema": {
            "type": "object",
            "description": "JSON Schema of the tool's `arguments`."
          },
          "annotations": {
            "type": "object",
            "description": "MCP tool annotations (`readOnlyHint`, `destructiveHint`, `idempotentHint`, `openWorldHint`)."
          }
        }
      },
      "McpToolCallResult": {
        "type": "object",
        "required": [
          "content",
          "isError"
        ],
        "properties": {
          "content": {
            "type": "array",
            "description": "One text item holding the tool's output as indented JSON.",
            "items": {
              "type": "object",
              "required": [
                "type",
                "text"
              ],
              "properties": {
                "type": {
                  "type": "string",
                  "const": "text"
                },
                "text": {
                  "type": "string"
                }
              }
            }
          },
          "isError": {
            "type": "boolean",
            "description": "True for an expected tool failure; the output then carries `error`/`code`, `message` and `hint`."
          },
          "structuredContent": {
            "type": "object",
            "description": "The same output as an object, when the output is a JSON object."
          }
        }
      },
      "UserView": {
        "type": "object",
        "description": "A user.",
        "required": [
          "id",
          "email",
          "display_name"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "email": {
            "type": "string"
          },
          "display_name": {
            "type": "string"
          }
        }
      },
      "WorkspaceView": {
        "type": "object",
        "description": "A workspace.",
        "required": [
          "id",
          "kind",
          "name",
          "plan_tier",
          "require_approved_machines",
          "require_approved_apps",
          "domain_verified"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "kind": {
            "type": "string",
            "enum": [
              "personal",
              "org"
            ],
            "description": "`personal` (one user) or `org` (bound to an email domain)."
          },
          "name": {
            "type": "string"
          },
          "primary_domain": {
            "type": "string",
            "description": "The email domain of an org workspace. Absent for personal workspaces."
          },
          "plan_tier": {
            "type": "string",
            "description": "Plan tier (`free` by default)."
          },
          "require_approved_machines": {
            "type": "boolean",
            "description": "Only approved machines may reach the workspace's spaces."
          },
          "require_approved_apps": {
            "type": "boolean",
            "description": "Only approved apps may reach the workspace's spaces."
          },
          "domain_verified": {
            "type": "boolean",
            "description": "An owner proved `primary_domain` by DNS or email."
          },
          "domain_verification_method": {
            "type": "string",
            "enum": [
              "dns",
              "email"
            ],
            "description": "How the domain was verified. Absent when not verified."
          },
          "domain_verified_at": {
            "type": "string",
            "format": "date-time",
            "description": "When the domain was verified. Absent when not verified."
          }
        }
      },
      "MachineView": {
        "type": "object",
        "description": "A machine (a human's device, or a headless workload). Keys are never shown.",
        "required": [
          "id",
          "workspace_id",
          "kind",
          "name",
          "approval_status",
          "last_seen_at",
          "revoked_at",
          "created_at"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "workspace_id": {
            "type": "string"
          },
          "owner_user_id": {
            "type": "string",
            "description": "The user who enrolled it. Absent when none (e.g. a key-only headless machine)."
          },
          "kind": {
            "type": "string",
            "enum": [
              "device",
              "headless"
            ]
          },
          "name": {
            "type": "string"
          },
          "approval_status": {
            "type": "string",
            "enum": [
              "pending",
              "approved",
              "rejected"
            ]
          },
          "last_seen_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "revoked_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "ReplaceableMachine": {
        "type": "object",
        "description": "A `MachineView` that `/activate` offers to replace at the limit (BORG-109).",
        "required": [
          "id",
          "workspace_id",
          "kind",
          "name",
          "approval_status",
          "last_seen_at",
          "revoked_at",
          "created_at",
          "inactive",
          "apps"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "workspace_id": {
            "type": "string"
          },
          "owner_user_id": {
            "type": "string"
          },
          "kind": {
            "type": "string",
            "enum": [
              "device",
              "headless"
            ]
          },
          "name": {
            "type": "string"
          },
          "approval_status": {
            "type": "string",
            "enum": [
              "pending",
              "approved",
              "rejected"
            ]
          },
          "last_seen_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "revoked_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "inactive": {
            "type": "boolean",
            "description": "Not seen (or, never seen, not created) for 90 days. Never revoked automatically."
          },
          "apps": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Names of the apps with a machine grant on, or a live session from, the machine."
          }
        }
      },
      "AppView": {
        "type": "object",
        "description": "An application.",
        "required": [
          "id",
          "workspace_id",
          "name",
          "allowed_origins",
          "redirect_uris",
          "approval_status",
          "revoked_at",
          "created_at"
        ],
        "properties": {
          "id": {
            "type": "string",
            "description": "The app's ID; also its OAuth `client_id`."
          },
          "workspace_id": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "allowed_origins": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Web origins the app may connect from (empty for native and CLI apps)."
          },
          "redirect_uris": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "approval_status": {
            "type": "string",
            "enum": [
              "pending",
              "approved",
              "rejected"
            ]
          },
          "created_by_user_id": {
            "type": "string",
            "description": "Who registered it. Absent when unknown."
          },
          "revoked_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "LoginResult": {
        "type": "object",
        "description": "A new console session (dev, provider, email or passkey sign-in). The\nsession is bound to the device key sent with the request: every\nrequest needs a `Kovlet-Device-Proof`.\n",
        "required": [
          "access_token",
          "token_type",
          "expires_at",
          "refresh_token",
          "refresh_token_expires_at",
          "user",
          "workspace",
          "machine"
        ],
        "properties": {
          "access_token": {
            "type": "string",
            "description": "The console session token (`kvs_...`)."
          },
          "token_type": {
            "type": "string",
            "const": "Bearer"
          },
          "expires_at": {
            "type": "string",
            "format": "date-time",
            "description": "When the access token expires (7 days by default)."
          },
          "refresh_token": {
            "type": "string",
            "description": "`kvr_...`; renews the session at `POST /v1/oauth/token` (`grant_type=refresh_token`) without signing in again."
          },
          "refresh_token_expires_at": {
            "type": "string",
            "format": "date-time"
          },
          "user": {
            "$ref": "#/components/schemas/UserView"
          },
          "workspace": {
            "$ref": "#/components/schemas/WorkspaceView",
            "description": "The user's home workspace."
          },
          "machine": {
            "$ref": "#/components/schemas/MachineView",
            "description": "The device machine bound to the presented key."
          }
        }
      },
      "DeviceInfo": {
        "type": "object",
        "additionalProperties": false,
        "description": "The device key a client presents when a session is created.",
        "required": [
          "public_key"
        ],
        "properties": {
          "public_key": {
            "$ref": "#/components/schemas/DevicePublicJWK"
          },
          "name": {
            "type": "string",
            "description": "Device name for a newly enrolled device (at most 100 characters kept; default \"Unnamed device\")."
          }
        }
      },
      "DevicePublicJWK": {
        "type": "object",
        "description": "An ECDSA P-256 public key as a JWK (a non-exportable WebCrypto key).\nOnly `kty`, `crv`, `x` and `y` are used; other members are ignored.\n",
        "required": [
          "kty",
          "crv",
          "x",
          "y"
        ],
        "properties": {
          "kty": {
            "type": "string",
            "const": "EC"
          },
          "crv": {
            "type": "string",
            "const": "P-256"
          },
          "x": {
            "type": "string",
            "description": "base64url of the 32-byte X coordinate."
          },
          "y": {
            "type": "string",
            "description": "base64url of the 32-byte Y coordinate."
          }
        }
      },
      "SignInProviders": {
        "type": "object",
        "required": [
          "providers",
          "passkeys",
          "email_login"
        ],
        "properties": {
          "providers": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Configured provider names, sorted (e.g. `apple`, `github`, `google`, `microsoft`)."
          },
          "passkeys": {
            "type": "boolean",
            "description": "Passkey sign-in is enabled."
          },
          "email_login": {
            "type": "boolean",
            "description": "Email sign-in is enabled."
          }
        }
      },
      "EmailLoginStarted": {
        "type": "object",
        "required": [
          "flow_id",
          "expires_in",
          "resend_in"
        ],
        "properties": {
          "flow_id": {
            "type": "string",
            "description": "Send back with the code to `POST /v1/auth/email/verify`."
          },
          "expires_in": {
            "type": "integer",
            "description": "Seconds the link and code stay valid (900)."
          },
          "resend_in": {
            "type": "integer",
            "description": "Seconds before another email may be requested (60)."
          }
        }
      },
      "SignInRateLimitedError": {
        "type": "object",
        "required": [
          "error"
        ],
        "properties": {
          "error": {
            "type": "object",
            "required": [
              "code",
              "message",
              "retry_after"
            ],
            "properties": {
              "code": {
                "type": "string",
                "const": "rate_limited"
              },
              "message": {
                "type": "string"
              },
              "hint": {
                "type": "string"
              },
              "retry_after": {
                "type": "integer",
                "description": "Seconds to wait before retrying (also in `Retry-After`)."
              }
            }
          }
        }
      },
      "PasskeyChallenge": {
        "type": "object",
        "description": "A WebAuthn ceremony. Pass `options` to `navigator.credentials.create`/`get` and send `flow_id` back with the result.",
        "required": [
          "flow_id",
          "options"
        ],
        "properties": {
          "flow_id": {
            "type": "string",
            "description": "The ceremony's secret ID (valid 5 minutes, answered once)."
          },
          "options": {
            "type": "object",
            "description": "WebAuthn options: `{\"publicKey\": PublicKeyCredentialCreationOptions}`\nfor registration or `{\"publicKey\": PublicKeyCredentialRequestOptions}`\nfor sign-in (binary values base64url-encoded), possibly with `mediation`.\n"
          }
        }
      },
      "PasskeyView": {
        "type": "object",
        "description": "A passkey. Key material is never shown.",
        "required": [
          "id",
          "name",
          "created_at",
          "last_used_at"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "last_used_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          }
        }
      },
      "ConsentPreview": {
        "type": "object",
        "required": [
          "app",
          "registered",
          "origin",
          "workspace",
          "spaces"
        ],
        "properties": {
          "app": {
            "description": "The registered app, or null if consent will register it.",
            "oneOf": [
              {
                "$ref": "#/components/schemas/AppView"
              },
              {
                "type": "null"
              }
            ]
          },
          "registered": {
            "type": "boolean",
            "description": "Whether the app is already registered (`app` is not null)."
          },
          "origin": {
            "type": "string",
            "description": "The redirect URI's origin (`scheme://host[:port]`)."
          },
          "workspace": {
            "$ref": "#/components/schemas/WorkspaceView",
            "description": "The user's home workspace (where the app is or will be registered)."
          },
          "spaces": {
            "type": "array",
            "description": "Data Spaces the user can map a slot to, with the user's own role.",
            "items": {
              "$ref": "#/components/schemas/SpaceView"
            }
          },
          "suggested_space": {
            "$ref": "#/components/schemas/SuggestedSpace"
          },
          "needs_approval": {
            "$ref": "#/components/schemas/NeedsApproval"
          }
        }
      },
      "AuthorizeRequest": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "redirect_uri",
          "code_challenge",
          "code_challenge_method",
          "approve"
        ],
        "description": "Give `client_id` (a registered app) or `client_name` (register on first consent).",
        "properties": {
          "client_id": {
            "type": "string",
            "description": "A registered app of the user's home workspace."
          },
          "client_name": {
            "type": "string",
            "maxLength": 100,
            "description": "The app's name when it has no `client_id` yet."
          },
          "redirect_uri": {
            "type": "string",
            "description": "Absolute, no fragment. One of: `https://...`; `http://` on a\nloopback host (`localhost`, `127.0.0.1`, `[::1]`), where any port\nmatches a registered loopback URI with the same path (RFC 8252\n§7.3); or a reverse-DNS private-use scheme for native apps, such\nas `com.example.app:/callback` (lowercase, must contain a dot).\nMust be registered for an approved app.\n"
          },
          "code_challenge": {
            "type": "string",
            "pattern": "^[A-Za-z0-9_-]{43}$",
            "description": "PKCE S256 challenge, base64url(sha256(code_verifier))."
          },
          "code_challenge_method": {
            "type": "string",
            "const": "S256"
          },
          "state": {
            "type": "string",
            "description": "Echoed on the redirect."
          },
          "slots": {
            "type": [
              "object",
              "null"
            ],
            "description": "Logical space slots (name `^[A-Za-z][A-Za-z0-9_]{0,63}$`) mapped to a\nspace. 1 to 20 required when `approve` is true.\n",
            "maxProperties": 20,
            "additionalProperties": {
              "type": "object",
              "additionalProperties": false,
              "required": [
                "role"
              ],
              "description": "Give `space_id` (an existing space) or `create` (a new one), not both.",
              "properties": {
                "space_id": {
                  "type": "string"
                },
                "create": {
                  "type": "object",
                  "additionalProperties": false,
                  "required": [
                    "name"
                  ],
                  "properties": {
                    "name": {
                      "type": "string",
                      "minLength": 1,
                      "maxLength": 100
                    }
                  }
                },
                "role": {
                  "type": "string",
                  "enum": [
                    "viewer",
                    "editor"
                  ],
                  "description": "At most the user's own role on the space."
                }
              }
            }
          },
          "approve": {
            "type": "boolean",
            "description": "True to allow, false to deny."
          }
        }
      },
      "AuthorizeResult": {
        "type": "object",
        "description": "Where to send the browser next. An empty object after a denial the app cannot be told about.",
        "properties": {
          "redirect_to": {
            "type": "string",
            "description": "The redirect URI with `code` and `client_id` (approval) or\n`error=access_denied` (denial), plus `state`.\n"
          },
          "app_id": {
            "type": "string",
            "description": "The app's ID (also `client_id`). Approval only."
          },
          "slots": {
            "type": "object",
            "description": "Each slot's space and role. Approval only.",
            "additionalProperties": {
              "$ref": "#/components/schemas/OAuthSlot"
            }
          }
        }
      },
      "DevApproval": {
        "type": "object",
        "required": [
          "status",
          "user_id",
          "app_id"
        ],
        "properties": {
          "status": {
            "type": "string",
            "enum": [
              "approved",
              "denied"
            ]
          },
          "user_id": {
            "type": "string"
          },
          "app_id": {
            "type": "string"
          },
          "machine_id": {
            "type": "string",
            "description": "The approved device code's machine."
          },
          "space_id": {
            "type": "string",
            "description": "The space a device approval shared."
          },
          "redirect_to": {
            "type": "string",
            "description": "A consent: the app's redirect URI with `code`, `client_id` and `state`."
          },
          "slots": {
            "type": "object",
            "description": "A consent's slot → space map.",
            "additionalProperties": {
              "$ref": "#/components/schemas/OAuthSlot"
            }
          }
        }
      },
      "DevSeed": {
        "type": "object",
        "required": [
          "user_id",
          "email",
          "workspace_id",
          "space_id",
          "app_id",
          "machine_id",
          "role",
          "access_token",
          "token_type",
          "expires_in"
        ],
        "properties": {
          "user_id": {
            "type": "string"
          },
          "email": {
            "type": "string"
          },
          "workspace_id": {
            "type": "string"
          },
          "space_id": {
            "type": "string"
          },
          "app_id": {
            "type": "string"
          },
          "machine_id": {
            "type": "string"
          },
          "role": {
            "type": "string",
            "enum": [
              "viewer",
              "editor"
            ]
          },
          "access_token": {
            "type": "string",
            "description": "An app session token (`kvs_...`); no device proof needed."
          },
          "token_type": {
            "type": "string",
            "enum": [
              "Bearer"
            ]
          },
          "expires_in": {
            "type": "integer"
          }
        }
      },
      "OAuthSlot": {
        "type": "object",
        "required": [
          "space_id",
          "role"
        ],
        "properties": {
          "space_id": {
            "type": "string"
          },
          "role": {
            "type": "string",
            "enum": [
              "viewer",
              "editor"
            ]
          }
        }
      },
      "TokenRequest": {
        "type": "object",
        "required": [
          "grant_type"
        ],
        "description": "Fields per grant (others are ignored):\n\n| grant_type | required | optional |\n| --- | --- | --- |\n| `authorization_code` | `code`, `code_verifier`, `client_id`, `redirect_uri`, `device_public_key` (not for a registered `kvo_` client) | `device_name`, `resource` (registered clients) |\n| `urn:ietf:params:oauth:grant-type:device_code` | `device_code`; for a device sign-in also a device proof over the device code; `client_id` when the flow was started with a registered client | `client_id` (must match the flow's), `resource` |\n| `urn:kovlet:params:oauth:grant-type:machine_key` | `machine_key`, `client_id` | |\n| `refresh_token` | `refresh_token`, a device proof (`Kovlet-Device-Proof` header or `device_proof`) | |\n",
        "properties": {
          "grant_type": {
            "type": "string",
            "enum": [
              "authorization_code",
              "urn:ietf:params:oauth:grant-type:device_code",
              "urn:kovlet:params:oauth:grant-type:machine_key",
              "refresh_token"
            ]
          },
          "code": {
            "type": "string",
            "description": "`authorization_code`: the `code` from the consent redirect (`kvc_...`, one-time, 2 minutes)."
          },
          "code_verifier": {
            "type": "string",
            "description": "`authorization_code`: the PKCE verifier whose S256 hash was the `code_challenge`."
          },
          "redirect_uri": {
            "type": "string",
            "description": "`authorization_code`: the same redirect URI as in the authorization request."
          },
          "client_id": {
            "type": "string",
            "description": "The app's ID. `authorization_code` and `machine_key`: required.\n`device_code`: optional; must match the device authorization's `client_id` when both are set.\n"
          },
          "device_public_key": {
            "description": "`authorization_code`: the client's ECDSA P-256 public JWK the session\nis bound to. In a form body, the JWK as JSON text; in a JSON body, a\nJWK object or JSON text.\n",
            "oneOf": [
              {
                "type": "string"
              },
              {
                "$ref": "#/components/schemas/DevicePublicJWK"
              }
            ]
          },
          "device_name": {
            "type": "string",
            "description": "`authorization_code`: name for a newly enrolled device (default \"Unnamed device\")."
          },
          "device_code": {
            "type": "string",
            "description": "`device_code`: the `device_code` from `POST /v1/oauth/device_authorization`."
          },
          "machine_key": {
            "type": "string",
            "description": "`machine_key`: a Machine Auth Key (`kvm_...`) of a headless machine."
          },
          "resource": {
            "type": "string",
            "description": "RFC 8707: `<base>/mcp` binds the token to `/mcp` (ADR 0023 §3)."
          },
          "refresh_token": {
            "type": "string",
            "description": "`refresh_token`: the refresh token (`kvr_...`) of a device-bound session (authorization code or device sign-in)."
          },
          "device_proof": {
            "type": "string",
            "description": "`refresh_token`: device proof signed by the session's device key with\n`ath = base64url(sha256(refresh_token))`; device-code grant of a\ndevice sign-in: proof over the device code. Used when not sent in the\n`Kovlet-Device-Proof` header.\n"
          }
        }
      },
      "TokenResponse": {
        "type": "object",
        "description": "A new session (RFC 6749 §5.1 plus Kovlet fields).",
        "required": [
          "access_token",
          "token_type",
          "expires_in",
          "scope",
          "client_id",
          "machine_id",
          "workspace_id"
        ],
        "properties": {
          "access_token": {
            "type": "string",
            "description": "The session token (`kvs_...`); send as `Authorization: Bearer`."
          },
          "token_type": {
            "type": "string",
            "const": "Bearer"
          },
          "expires_in": {
            "type": "integer",
            "description": "Seconds until the access token expires."
          },
          "refresh_token": {
            "type": "string",
            "description": "`kvr_...`. Device-bound sessions only (`authorization_code` and\n`refresh_token` grants); absent for device code and machine key sessions.\n"
          },
          "refresh_token_expires_in": {
            "type": "integer",
            "description": "Seconds until the refresh token expires. Present with `refresh_token`."
          },
          "scope": {
            "type": "string",
            "enum": [
              "app",
              "console",
              "admin"
            ],
            "description": "`app` for every grant except refreshing a console session (`console`)."
          },
          "client_id": {
            "type": "string",
            "description": "The app's ID; empty for a refreshed console session."
          },
          "user_id": {
            "type": "string",
            "description": "The acting user. Absent for headless sessions (device code without `scope=agent`, machine key)."
          },
          "machine_id": {
            "type": "string"
          },
          "workspace_id": {
            "type": "string"
          },
          "spaces": {
            "type": "object",
            "description": "`authorization_code` (and its refreshes): the consented slots, slot name → space and role. Absent otherwise.",
            "additionalProperties": {
              "$ref": "#/components/schemas/OAuthSlot"
            }
          }
        }
      },
      "DeviceAuthorizationRequest": {
        "type": "object",
        "description": "Give `client_id` (a registered app) or `client_name` (registered on approval). Unknown fields are ignored.",
        "properties": {
          "client_id": {
            "type": "string",
            "description": "A registered app's ID."
          },
          "client_name": {
            "type": "string",
            "maxLength": 100,
            "description": "The app's name when it has no `client_id`."
          },
          "machine_name": {
            "type": "string",
            "description": "Name for the headless machine enrolled on approval (default \"Headless machine\"; at most 100 characters kept)."
          },
          "scope": {
            "type": "string",
            "enum": [
              "",
              "agent"
            ],
            "description": "Empty for a headless (machine, app) session; `agent` for an AI coding agent acting for the approving user."
          },
          "space_name": {
            "type": "string",
            "description": "The app's suggested name for the new Data Space a first-time user gets at approval (default the app's name; at most 100 characters kept)."
          },
          "device_public_key": {
            "type": "string",
            "description": "Device sign-in: the app's EC P-256 public JWK as JSON text (in a\nJSON body, a JWK object is accepted too). The approval enrolls a\ndevice machine and the token poll returns a device-bound session\nwith a refresh token. Not with `scope=agent`. `machine_name`\ndefaults to \"Unnamed device\".\n"
          },
          "space_ids": {
            "type": "string",
            "description": "The app's pinned space ids, space-separated (at most 20). A hint for `/activate` to preselect; grants nothing."
          },
          "resource": {
            "type": "string",
            "description": "RFC 8707: `<base>/mcp` binds the token to `/mcp`."
          }
        }
      },
      "ClientRegistrationRequest": {
        "type": "object",
        "description": "RFC 7591 §2 client metadata. Fields not listed are ignored.",
        "required": [
          "client_name",
          "redirect_uris"
        ],
        "properties": {
          "client_name": {
            "type": "string",
            "minLength": 1,
            "maxLength": 100,
            "description": "The name people see at approval; with the redirect URI's origin it names the Kovlet app."
          },
          "redirect_uris": {
            "type": "array",
            "minItems": 1,
            "maxItems": 10,
            "items": {
              "type": "string"
            }
          },
          "grant_types": {
            "type": "array",
            "description": "Default `[authorization_code]`.",
            "items": {
              "type": "string",
              "enum": [
                "authorization_code",
                "refresh_token",
                "urn:ietf:params:oauth:grant-type:device_code"
              ]
            }
          },
          "response_types": {
            "type": "array",
            "items": {
              "type": "string",
              "const": "code"
            }
          },
          "token_endpoint_auth_method": {
            "type": "string",
            "description": "Answered with `none` whatever is asked."
          },
          "scope": {
            "type": "string",
            "description": "Ignored; registered clients always get `agent`."
          },
          "software_id": {
            "type": "string"
          },
          "software_version": {
            "type": "string"
          }
        }
      },
      "ClientRegistrationResponse": {
        "type": "object",
        "description": "RFC 7591 §3.2.1 client information. There is no client secret and no registration access token.",
        "required": [
          "client_id",
          "client_id_issued_at",
          "client_name",
          "redirect_uris",
          "grant_types",
          "response_types",
          "token_endpoint_auth_method",
          "scope"
        ],
        "properties": {
          "client_id": {
            "type": "string",
            "pattern": "^kvo_[0-9A-Za-z]{22}$"
          },
          "client_id_issued_at": {
            "type": "integer",
            "format": "int64"
          },
          "client_name": {
            "type": "string"
          },
          "redirect_uris": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "grant_types": {
            "type": "array",
            "items": {
              "type": "string",
              "enum": [
                "authorization_code",
                "refresh_token",
                "urn:ietf:params:oauth:grant-type:device_code"
              ]
            }
          },
          "response_types": {
            "type": "array",
            "items": {
              "type": "string",
              "const": "code"
            }
          },
          "token_endpoint_auth_method": {
            "type": "string",
            "const": "none"
          },
          "scope": {
            "type": "string",
            "const": "agent"
          },
          "software_id": {
            "type": "string"
          },
          "software_version": {
            "type": "string"
          }
        }
      },
      "DeviceAuthorizationResponse": {
        "type": "object",
        "description": "RFC 8628 §3.2 device authorization response.",
        "required": [
          "device_code",
          "user_code",
          "verification_uri",
          "verification_uri_complete",
          "expires_in",
          "interval"
        ],
        "properties": {
          "device_code": {
            "type": "string",
            "description": "Secret (`kvc_...`) to poll `POST /v1/oauth/token` with."
          },
          "user_code": {
            "type": "string",
            "pattern": "^[A-Z0-9]{4}-[A-Z0-9]{4}$",
            "description": "Code the user confirms at `verification_uri`, e.g. `WDJB-MJHT`."
          },
          "verification_uri": {
            "type": "string",
            "description": "The console's `/activate` page."
          },
          "verification_uri_complete": {
            "type": "string",
            "description": "`verification_uri` with `?user_code=`."
          },
          "expires_in": {
            "type": "integer",
            "description": "Seconds the codes stay valid (600)."
          },
          "interval": {
            "type": "integer",
            "description": "Minimum seconds between polls (5)."
          }
        }
      },
      "PendingDevice": {
        "type": "object",
        "description": "A pending device code, for the /activate screen.",
        "required": [
          "user_code",
          "client_name",
          "client_id",
          "machine_name",
          "app",
          "expires_at",
          "agent",
          "device_bound",
          "workspace",
          "suggested_space",
          "needs_approval"
        ],
        "properties": {
          "user_code": {
            "type": "string"
          },
          "client_name": {
            "type": "string",
            "description": "The app name from the device authorization (empty if it gave `client_id`)."
          },
          "client_id": {
            "type": "string",
            "description": "The `client_id` from the device authorization (empty if it gave `client_name`)."
          },
          "machine_name": {
            "type": "string"
          },
          "app": {
            "description": "The registered app, or null if approval will register it.",
            "oneOf": [
              {
                "$ref": "#/components/schemas/AppView"
              },
              {
                "type": "null"
              }
            ]
          },
          "expires_at": {
            "type": "string",
            "format": "date-time"
          },
          "agent": {
            "type": "boolean",
            "description": "`scope=agent`: approving gives an AI coding agent a session acting for the user."
          },
          "device_bound": {
            "type": "boolean",
            "description": "A device sign-in (`device_public_key`); approving enrolls a device machine, not a headless one."
          },
          "workspace": {
            "$ref": "#/components/schemas/WorkspaceView",
            "description": "The approver's home workspace, where `create` grants make new spaces."
          },
          "suggested_space": {
            "$ref": "#/components/schemas/SuggestedSpace"
          },
          "needs_approval": {
            "$ref": "#/components/schemas/NeedsApproval"
          },
          "app_grants": {
            "type": "array",
            "description": "Present for device sign-ins and `scope=agent`. The spaces the app already holds (visible to the user); approving with no `grants` keeps them.",
            "items": {
              "type": "object",
              "required": [
                "space_id",
                "space_name",
                "role"
              ],
              "properties": {
                "space_id": {
                  "type": "string"
                },
                "space_name": {
                  "type": "string"
                },
                "role": {
                  "type": "string",
                  "enum": [
                    "viewer",
                    "editor",
                    "owner"
                  ]
                }
              }
            }
          },
          "machine": {
            "description": "Device sign-ins only. The user's existing device machine for this key, or null for a new device. `revoked` true means approval will fail with `device_revoked`.",
            "oneOf": [
              {
                "type": "object",
                "required": [
                  "id",
                  "name",
                  "revoked"
                ],
                "properties": {
                  "id": {
                    "type": "string"
                  },
                  "name": {
                    "type": "string"
                  },
                  "revoked": {
                    "type": "boolean"
                  }
                }
              },
              {
                "type": "null"
              }
            ]
          },
          "machine_quota": {
            "type": "object",
            "description": "The plan limit approving counts against (BORG-109): `machines` for a headless or keyless `scope=agent` code, `devices` for a new device key. Absent when the sign-in reuses a known device (signing in again, or an agent on a known device), which never counts.\n",
            "required": [
              "metric",
              "used",
              "limit"
            ],
            "properties": {
              "metric": {
                "type": "string",
                "enum": [
                  "machines",
                  "devices"
                ]
              },
              "used": {
                "type": "integer",
                "format": "int64"
              },
              "limit": {
                "type": [
                  "integer",
                  "null"
                ],
                "format": "int64",
                "description": "Null when unlimited."
              }
            }
          },
          "pinned_spaces": {
            "type": "array",
            "description": "The spaces the app pinned (`space_ids`) that the approver can see, with the approver's role; preselect them. Others are dropped without notice.",
            "items": {
              "type": "object",
              "required": [
                "id",
                "name",
                "role"
              ],
              "properties": {
                "id": {
                  "type": "string"
                },
                "name": {
                  "type": "string"
                },
                "role": {
                  "type": "string",
                  "enum": [
                    "viewer",
                    "editor",
                    "owner"
                  ]
                }
              }
            }
          },
          "redirect_host": {
            "type": "string",
            "description": "Code-flow sign-ins (`GET /v1/oauth/authorize`): where the code goes, the redirect URI's host (`127.0.0.1`, `cursor.com`) or private scheme (`cursor:`)."
          },
          "agent_machine": {
            "type": "object",
            "description": "Agent sign-ins without a device key that reconnect an agent approved before. Approval reuses this headless machine; `machine_quota` is absent.",
            "required": [
              "id",
              "name"
            ],
            "properties": {
              "id": {
                "type": "string"
              },
              "name": {
                "type": "string"
              }
            }
          },
          "replaceable_machines": {
            "type": "array",
            "description": "Present at or over the limit. Active machines of `machine_quota.metric`'s kind (headless machines or personal devices) the user may revoke to make room (their own; all for workspace admins), inactive first, then the longest unseen; pass one as `replace_machine_id` to `POST /v1/activate`.",
            "items": {
              "$ref": "#/components/schemas/ReplaceableMachine"
            }
          }
        }
      },
      "DomainStatus": {
        "type": "object",
        "description": "The caller's email domain.",
        "required": [
          "domain",
          "state",
          "eligible"
        ],
        "properties": {
          "domain": {
            "type": "string"
          },
          "state": {
            "type": "string",
            "enum": [
              "unverified",
              "pending",
              "verified"
            ],
            "description": "`pending`: the caller started a claim."
          },
          "eligible": {
            "type": "boolean",
            "description": "The caller may verify the domain."
          },
          "reason": {
            "type": "string",
            "enum": [
              "consumer_domain",
              "org_admin_required",
              "verified"
            ],
            "description": "Why the caller is not eligible. Absent when eligible."
          },
          "workspace_id": {
            "type": "string",
            "description": "The domain's org workspace, if there is one."
          },
          "method": {
            "type": "string",
            "enum": [
              "dns",
              "email"
            ],
            "description": "How the domain was verified (verified only)."
          },
          "verified_at": {
            "type": "string",
            "format": "date-time",
            "description": "When it was verified (verified only)."
          },
          "txt_name": {
            "type": "string",
            "description": "TXT record name to publish, `_kovlet-verify.<domain>` (pending only)."
          },
          "txt_value": {
            "type": "string",
            "description": "TXT record value, `kovlet-verify=...` (pending only)."
          },
          "email_sent_to": {
            "type": "string",
            "description": "Where the last code went (pending only)."
          },
          "email_options": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Mailboxes a code may be sent to (eligible, not verified)."
          },
          "switch_workspace": {
            "type": "boolean",
            "description": "The domain is verified but the caller's session is in another workspace; sign in again to move there."
          }
        }
      },
      "MeResponse": {
        "type": "object",
        "description": "`GET /v1/me`. `user` and `workspaces` are present only when the\nsession has a user (`session.user_id` non-empty); `app` only when it\nhas an app (`session.app_id` non-empty).\n",
        "required": [
          "session",
          "workspace",
          "machine"
        ],
        "properties": {
          "session": {
            "$ref": "#/components/schemas/MeSession"
          },
          "workspace": {
            "$ref": "#/components/schemas/WorkspaceView",
            "description": "The workspace the session signed in to."
          },
          "machine": {
            "$ref": "#/components/schemas/MachineView",
            "description": "The session's machine (device or headless)."
          },
          "user": {
            "$ref": "#/components/schemas/UserView",
            "description": "The signed-in user; absent for headless sessions."
          },
          "workspaces": {
            "type": "array",
            "description": "Every workspace the user belongs to; absent for headless sessions.",
            "items": {
              "$ref": "#/components/schemas/WorkspaceView"
            }
          },
          "app": {
            "$ref": "#/components/schemas/AppView",
            "description": "The connected app; absent for console sessions."
          }
        }
      },
      "MeSession": {
        "type": "object",
        "description": "The session behind the bearer token.",
        "required": [
          "id",
          "scope",
          "expires_at",
          "user_id",
          "machine_id",
          "app_id",
          "workspace_id",
          "spaces"
        ],
        "properties": {
          "id": {
            "type": "string",
            "description": "Session ID."
          },
          "scope": {
            "type": "string",
            "enum": [
              "app",
              "console",
              "admin"
            ],
            "description": "`app` for app and headless sessions, `console` for the web console, `admin` for an explicit admin grant."
          },
          "expires_at": {
            "type": "string",
            "format": "date-time"
          },
          "user_id": {
            "type": "string",
            "description": "The signed-in user; empty for headless (machine, app) sessions."
          },
          "machine_id": {
            "type": "string"
          },
          "app_id": {
            "type": "string",
            "description": "The connected app; empty for console sessions."
          },
          "workspace_id": {
            "type": "string",
            "description": "The workspace the session signed in to."
          },
          "spaces": {
            "$ref": "#/components/schemas/SessionSlots"
          }
        }
      },
      "SessionSlots": {
        "type": "object",
        "description": "The Data Spaces granted to an app session, keyed by the logical slot\nname the app asked for at consent (`^[A-Za-z][A-Za-z0-9_]{0,63}$`, 1\nto 20 slots). Each value is the space the user chose (or created) for\nthat slot and the role chosen for it. `{}` for sessions without a\nconsent (console, device-code and machine-key sessions).\n",
        "propertyNames": {
          "pattern": "^[A-Za-z][A-Za-z0-9_]{0,63}$"
        },
        "additionalProperties": {
          "$ref": "#/components/schemas/SpaceSlot"
        },
        "example": {
          "finance": {
            "space_id": "01JD6M4V8Z0000000000000006",
            "role": "editor"
          }
        }
      },
      "SpaceSlot": {
        "type": "object",
        "description": "One app space slot mapped at consent.",
        "required": [
          "space_id",
          "role"
        ],
        "properties": {
          "space_id": {
            "type": "string",
            "description": "The Data Space ID; use it with the sync protocol and the space routes."
          },
          "role": {
            "type": "string",
            "enum": [
              "viewer",
              "editor"
            ],
            "description": "Role chosen at consent. The live effective role is in `GET /v1/spaces/{id}/access`."
          }
        }
      },
      "SpaceAccess": {
        "type": "object",
        "description": "The policy decisions of the calling session on a space.",
        "required": [
          "space_id",
          "read",
          "write",
          "manage",
          "role"
        ],
        "properties": {
          "space_id": {
            "type": "string"
          },
          "read": {
            "type": "boolean"
          },
          "write": {
            "type": "boolean"
          },
          "manage": {
            "type": "boolean",
            "description": "Needs owner and a console or admin session."
          },
          "role": {
            "type": "string",
            "enum": [
              "",
              "viewer",
              "editor",
              "owner"
            ],
            "description": "The effective role (min of the user's and the app's role); `\"\"` when there is none."
          },
          "reason": {
            "type": "string",
            "description": "Why `read` is denied; present only when `read` is false.",
            "enum": [
              "policy_unconfigured",
              "space_not_found",
              "machine_revoked",
              "machine_not_approved",
              "app_revoked",
              "app_not_approved",
              "origin_mismatch",
              "no_user_grant",
              "no_app_grant",
              "no_machine_grant",
              "insufficient_role",
              "scope_required",
              "unknown_principal"
            ]
          }
        }
      },
      "SuggestedSpace": {
        "type": "object",
        "description": "The default new Data Space a sign-in or grant request offers (BORG-98).",
        "required": [
          "name",
          "can_create"
        ],
        "properties": {
          "name": {
            "type": "string",
            "description": "The app's suggestion, otherwise the app's name."
          },
          "can_create": {
            "type": "boolean"
          },
          "blocked": {
            "type": "object",
            "description": "Why a new space cannot be created, e.g. the plan's space limit.",
            "required": [
              "code",
              "message"
            ],
            "properties": {
              "code": {
                "type": "string"
              },
              "message": {
                "type": "string"
              },
              "upgrade_url": {
                "type": "string"
              }
            }
          }
        }
      },
      "NeedsApproval": {
        "type": "array",
        "description": "What an admin must still approve before the app can use a new space.",
        "items": {
          "type": "string",
          "enum": [
            "app",
            "machine"
          ]
        }
      },
      "AppSpaceView": {
        "type": "object",
        "description": "A Data Space in an app session's list, with the app's effective role.",
        "required": [
          "id",
          "workspace_id",
          "name",
          "slug",
          "entire_org_role",
          "require_approved_apps",
          "require_approved_machines",
          "head_seq",
          "role",
          "guest",
          "created_at"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "workspace_id": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "slug": {
            "type": "string"
          },
          "icon": {
            "type": "string"
          },
          "entire_org_role": {
            "type": "string",
            "enum": [
              "",
              "viewer",
              "editor"
            ]
          },
          "require_approved_apps": {
            "type": "boolean"
          },
          "require_approved_machines": {
            "type": "boolean"
          },
          "head_seq": {
            "type": "integer",
            "format": "int64"
          },
          "role": {
            "type": "string",
            "enum": [
              "",
              "viewer",
              "editor"
            ],
            "description": "The app's effective role; empty while an admin must approve (see `reason`)."
          },
          "reason": {
            "type": "string",
            "enum": [
              "app_not_approved",
              "machine_not_approved"
            ]
          },
          "guest": {
            "type": "boolean"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "AppSpaceList": {
        "type": "object",
        "description": "`GET /v1/spaces` for an app session.",
        "required": [
          "spaces",
          "requestable",
          "can_create"
        ],
        "properties": {
          "spaces": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/AppSpaceView"
            }
          },
          "requestable": {
            "type": "integer",
            "description": "The user's other spaces the app could ask for (names stay on Kovlet's approve page)."
          },
          "can_create": {
            "type": "boolean"
          },
          "create_blocked": {
            "type": "object",
            "required": [
              "code",
              "message"
            ],
            "properties": {
              "code": {
                "type": "string"
              },
              "message": {
                "type": "string"
              },
              "upgrade_url": {
                "type": "string"
              }
            }
          }
        }
      },
      "GrantAsk": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "role"
        ],
        "properties": {
          "role": {
            "type": "string",
            "enum": [
              "viewer",
              "editor"
            ]
          },
          "slot": {
            "type": "string",
            "pattern": "^[A-Za-z][A-Za-z0-9_]{0,63}$",
            "description": "The session slot to map the granted space to."
          },
          "space_id": {
            "type": "string",
            "description": "A space the app knows of; preselected if the user can grant it."
          },
          "suggested_name": {
            "type": "string",
            "maxLength": 100,
            "description": "Name for a new space for this ask."
          }
        }
      },
      "GrantChoice": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "role"
        ],
        "properties": {
          "ask": {
            "type": "integer",
            "description": "Index of the ask this grant answers."
          },
          "space_id": {
            "type": "string"
          },
          "create": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "name"
            ],
            "properties": {
              "name": {
                "type": "string",
                "description": "Empty falls back to the suggested name."
              }
            }
          },
          "role": {
            "type": "string",
            "enum": [
              "viewer",
              "editor"
            ]
          }
        }
      },
      "GrantResult": {
        "type": "object",
        "required": [
          "space_id",
          "name",
          "role",
          "created"
        ],
        "properties": {
          "space_id": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "role": {
            "type": "string",
            "enum": [
              "viewer",
              "editor"
            ]
          },
          "slot": {
            "type": "string"
          },
          "created": {
            "type": "boolean"
          }
        }
      },
      "GrantReview": {
        "type": "object",
        "required": [
          "status",
          "app",
          "machine",
          "headless",
          "workspace",
          "asks",
          "spaces",
          "suggested_space",
          "defaults",
          "needs_approval",
          "expires_at"
        ],
        "properties": {
          "status": {
            "type": "string",
            "enum": [
              "pending",
              "approved",
              "denied"
            ]
          },
          "app": {
            "$ref": "#/components/schemas/AppView"
          },
          "machine": {
            "$ref": "#/components/schemas/MachineView"
          },
          "headless": {
            "type": "boolean",
            "description": "True for machine grants; false for app grants."
          },
          "workspace": {
            "$ref": "#/components/schemas/WorkspaceView"
          },
          "asks": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/GrantAsk"
            }
          },
          "spaces": {
            "type": "array",
            "description": "The spaces the user could grant, with the user's role and what the app already holds.",
            "items": {
              "type": "object",
              "required": [
                "id",
                "workspace_id",
                "name",
                "slug",
                "entire_org_role",
                "require_approved_apps",
                "require_approved_machines",
                "head_seq",
                "role",
                "guest",
                "created_at",
                "granted_role"
              ],
              "properties": {
                "id": {
                  "type": "string"
                },
                "workspace_id": {
                  "type": "string"
                },
                "name": {
                  "type": "string"
                },
                "slug": {
                  "type": "string"
                },
                "icon": {
                  "type": "string"
                },
                "entire_org_role": {
                  "type": "string",
                  "enum": [
                    "",
                    "viewer",
                    "editor"
                  ]
                },
                "require_approved_apps": {
                  "type": "boolean"
                },
                "require_approved_machines": {
                  "type": "boolean"
                },
                "head_seq": {
                  "type": "integer",
                  "format": "int64"
                },
                "role": {
                  "type": "string",
                  "enum": [
                    "viewer",
                    "editor",
                    "owner"
                  ]
                },
                "guest": {
                  "type": "boolean"
                },
                "created_at": {
                  "type": "string",
                  "format": "date-time"
                },
                "granted_role": {
                  "type": "string",
                  "enum": [
                    "",
                    "viewer",
                    "editor"
                  ]
                }
              }
            }
          },
          "suggested_space": {
            "type": "array",
            "description": "One per ask.",
            "items": {
              "$ref": "#/components/schemas/SuggestedSpace"
            }
          },
          "defaults": {
            "type": "array",
            "description": "The preselected choice per ask (no `space_id` and no `create` when nothing is preselected).",
            "items": {
              "$ref": "#/components/schemas/GrantChoice"
            }
          },
          "needs_approval": {
            "$ref": "#/components/schemas/NeedsApproval"
          },
          "expires_at": {
            "type": "string",
            "format": "date-time"
          },
          "result": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/GrantResult"
            }
          }
        }
      },
      "AccessEvent": {
        "type": "object",
        "description": "One change to who can reach a Data Space.",
        "required": [
          "id",
          "kind",
          "space_id",
          "via",
          "created_at"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "kind": {
            "type": "string",
            "description": "`space.created`, `grant.added`, `grant.changed`, `grant.removed`;\ncontrol-plane changes (ADR 0022 §7) such as `rules.changed`,\n`schema.changed`, `app.created`, `machine_key.created`,\n`auth_provider.set` and `space.transferred`.\n"
          },
          "space_id": {
            "type": "string"
          },
          "actor_user_id": {
            "type": "string"
          },
          "actor_machine_id": {
            "type": "string"
          },
          "actor_app_id": {
            "type": "string"
          },
          "app_id": {
            "type": "string",
            "description": "The app the grant is for (or the space was created for)."
          },
          "machine_id": {
            "type": "string",
            "description": "The machine of a machine grant."
          },
          "role": {
            "type": "string",
            "enum": [
              "viewer",
              "editor",
              "owner"
            ]
          },
          "previous_role": {
            "type": "string",
            "enum": [
              "viewer",
              "editor",
              "owner"
            ]
          },
          "via": {
            "type": "string",
            "enum": [
              "console",
              "consent",
              "activate",
              "grant_request",
              "app",
              "mcp",
              "partner",
              "transfer",
              "admin"
            ]
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "actor_partner_key_id": {
            "type": "string",
            "description": "The partner key that made the change",
            "before the space was transferred.": null
          },
          "details": {
            "type": "object"
          },
          "actor_name": {
            "type": "string"
          },
          "actor_deleted": {
            "type": "boolean",
            "description": "The actor deleted their account; `actor_name` is \"Deleted user\"."
          },
          "app_name": {
            "type": "string"
          },
          "machine_name": {
            "type": "string"
          }
        }
      },
      "SpaceView": {
        "type": "object",
        "description": "A Data Space with the caller's effective role on it.",
        "required": [
          "id",
          "workspace_id",
          "name",
          "slug",
          "entire_org_role",
          "require_approved_apps",
          "require_approved_machines",
          "head_seq",
          "role",
          "guest",
          "created_at"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "workspace_id": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "slug": {
            "type": "string"
          },
          "icon": {
            "type": "string",
            "description": "Emoji or short text; absent when not set."
          },
          "entire_org_role": {
            "type": "string",
            "enum": [
              "",
              "viewer",
              "editor"
            ],
            "description": "Role every member of the organization workspace gets (`\"\"` = none)."
          },
          "require_approved_apps": {
            "type": "boolean"
          },
          "require_approved_machines": {
            "type": "boolean"
          },
          "head_seq": {
            "type": "integer",
            "format": "int64",
            "description": "Sequence number of the latest change."
          },
          "role": {
            "type": "string",
            "enum": [
              "viewer",
              "editor",
              "owner"
            ],
            "description": "The caller's effective role."
          },
          "guest": {
            "type": "boolean",
            "description": "True when the space belongs to another workspace and the caller reaches it as an external guest."
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "AccountDeletionCandidate": {
        "type": "object",
        "required": [
          "user_id",
          "display_name",
          "email"
        ],
        "properties": {
          "user_id": {
            "type": "string"
          },
          "grant_id": {
            "type": "string",
            "description": "Space blockers: the candidate's grant, for `PATCH /v1/spaces/{id}/members/{gid}`."
          },
          "display_name": {
            "type": "string"
          },
          "email": {
            "type": "string"
          },
          "role": {
            "type": "string",
            "description": "The candidate's current space or workspace role."
          }
        }
      },
      "AccountDeletionBlocker": {
        "type": "object",
        "required": [
          "kind",
          "workspace_id",
          "workspace_name"
        ],
        "properties": {
          "kind": {
            "type": "string",
            "enum": [
              "space_sole_owner",
              "workspace_sole_owner",
              "workspace_not_empty"
            ]
          },
          "space_id": {
            "type": "string"
          },
          "space_name": {
            "type": "string"
          },
          "workspace_id": {
            "type": "string"
          },
          "workspace_name": {
            "type": "string"
          },
          "space_count": {
            "type": "integer",
            "description": "`workspace_not_empty`: spaces left in the workspace that the caller doesn't own alone."
          },
          "candidates": {
            "type": "array",
            "description": "Who the space or workspace can be handed to; missing or empty when nobody can.",
            "items": {
              "$ref": "#/components/schemas/AccountDeletionCandidate"
            }
          }
        }
      },
      "AccountDeletion": {
        "type": "object",
        "required": [
          "email",
          "reauth_methods",
          "blockers",
          "deletes"
        ],
        "properties": {
          "email": {
            "type": "string"
          },
          "reauth_methods": {
            "type": "array",
            "items": {
              "type": "string",
              "enum": [
                "passkey",
                "email"
              ]
            }
          },
          "blockers": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/AccountDeletionBlocker"
            }
          },
          "deletes": {
            "type": "object",
            "required": [
              "workspaces",
              "passkeys",
              "machines",
              "partner_keys",
              "space_memberships",
              "workspace_memberships"
            ],
            "properties": {
              "workspaces": {
                "type": "array",
                "items": {
                  "type": "object",
                  "required": [
                    "id",
                    "name",
                    "kind"
                  ],
                  "properties": {
                    "id": {
                      "type": "string"
                    },
                    "name": {
                      "type": "string"
                    },
                    "kind": {
                      "type": "string",
                      "enum": [
                        "personal",
                        "org"
                      ]
                    }
                  }
                }
              },
              "passkeys": {
                "type": "integer"
              },
              "machines": {
                "type": "integer",
                "description": "Machines the caller owns in any workspace",
                "headless ones included.": null
              },
              "partner_keys": {
                "type": "integer"
              },
              "space_memberships": {
                "type": "integer"
              },
              "workspace_memberships": {
                "type": "integer",
                "description": "Memberships in workspaces that stay."
              }
            }
          }
        }
      },
      "AccountBlockedError": {
        "type": "object",
        "required": [
          "error"
        ],
        "properties": {
          "error": {
            "type": "object",
            "required": [
              "code",
              "message",
              "blockers"
            ],
            "properties": {
              "code": {
                "type": "string",
                "const": "account_has_blockers"
              },
              "message": {
                "type": "string"
              },
              "hint": {
                "type": "string"
              },
              "blockers": {
                "type": "array",
                "items": {
                  "$ref": "#/components/schemas/AccountDeletionBlocker"
                }
              }
            }
          }
        }
      },
      "ReauthStart": {
        "type": "object",
        "required": [
          "reauth_id",
          "method",
          "expires_in"
        ],
        "properties": {
          "reauth_id": {
            "type": "string",
            "description": "Send it to `POST /v1/me/reauth/verify` and `POST /v1/me/delete`."
          },
          "method": {
            "type": "string",
            "enum": [
              "passkey",
              "email"
            ]
          },
          "options": {
            "type": "object",
            "description": "Passkey: the `navigator.credentials.get` request."
          },
          "expires_in": {
            "type": "integer",
            "description": "Seconds to verify (300 for a passkey",
            "600 for a code).": null
          },
          "resend_in": {
            "type": "integer",
            "description": "Email: seconds before another code may be requested."
          }
        }
      },
      "WorkspaceMember": {
        "type": "object",
        "required": [
          "user",
          "role",
          "joined_at"
        ],
        "properties": {
          "user": {
            "$ref": "#/components/schemas/UserView"
          },
          "role": {
            "type": "string",
            "enum": [
              "member",
              "admin",
              "owner"
            ]
          },
          "joined_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "MachineWithKey": {
        "type": "object",
        "required": [
          "machine",
          "machine_key"
        ],
        "properties": {
          "machine": {
            "$ref": "#/components/schemas/MachineView"
          },
          "machine_key": {
            "type": "string",
            "description": "The Machine Auth Key (`kvm_...`). Shown once; store it as a secret."
          }
        }
      },
      "SpaceMember": {
        "type": "object",
        "description": "A user grant on a space (workspace member or external guest).",
        "required": [
          "id",
          "email",
          "role",
          "guest",
          "accepted",
          "created_at"
        ],
        "properties": {
          "id": {
            "type": "string",
            "description": "Grant ID (the `gid` of the member routes)."
          },
          "user_id": {
            "type": "string",
            "description": "The user; absent for a guest invite to an address with no account yet."
          },
          "email": {
            "type": "string",
            "description": "The user's email, or the invited address."
          },
          "display_name": {
            "type": "string"
          },
          "role": {
            "type": "string",
            "enum": [
              "viewer",
              "editor",
              "owner"
            ]
          },
          "guest": {
            "type": "boolean",
            "description": "An external guest (not a member of the space's workspace)."
          },
          "accepted": {
            "type": "boolean",
            "description": "False while a guest invite is pending."
          },
          "invited_by_user_id": {
            "type": "string"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "invited_email": {
            "type": "string",
            "description": "The address a guest was invited at."
          },
          "notified": {
            "type": "boolean",
            "description": "Only in the response to sharing; whether the invite email was accepted by the mail provider."
          }
        }
      },
      "SpaceAppGrant": {
        "type": "object",
        "required": [
          "app",
          "max_role",
          "granted_by_user_id",
          "updated_at"
        ],
        "properties": {
          "app": {
            "$ref": "#/components/schemas/AppView"
          },
          "max_role": {
            "type": "string",
            "enum": [
              "viewer",
              "editor",
              "owner"
            ],
            "description": "Caps the role of any user on the space through this app (owner is capped to editor)."
          },
          "end_users": {
            "type": "boolean",
            "description": "End-user sign-in is on for this app on this space (ADR 0021 §2.4)."
          },
          "granted_by_user_id": {
            "type": "string",
            "description": "Empty when unknown."
          },
          "updated_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "MachineGrant": {
        "type": "object",
        "description": "A (headless machine, app) → space grant.",
        "required": [
          "machine_id",
          "app_id",
          "role",
          "updated_at"
        ],
        "properties": {
          "machine_id": {
            "type": "string"
          },
          "app_id": {
            "type": "string"
          },
          "role": {
            "type": "string",
            "enum": [
              "viewer",
              "editor",
              "owner"
            ],
            "description": "Capped to editor when evaluated."
          },
          "impersonate": {
            "type": "boolean",
            "description": "The machine may act as the space's end users (`Kovlet-As-End-User`; owner-set, ADR 0021 §2.6)."
          },
          "updated_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "GuestInvite": {
        "type": "object",
        "description": "A pending external-guest invite to the caller.",
        "required": [
          "id",
          "role",
          "space",
          "workspace",
          "invited_by_user_id",
          "created_at"
        ],
        "properties": {
          "id": {
            "type": "string",
            "description": "Invite (grant) ID, the `gid` of accept/decline."
          },
          "role": {
            "type": "string",
            "enum": [
              "viewer",
              "editor"
            ]
          },
          "space": {
            "type": "object",
            "required": [
              "id",
              "name"
            ],
            "properties": {
              "id": {
                "type": "string"
              },
              "name": {
                "type": "string"
              }
            }
          },
          "workspace": {
            "type": "object",
            "required": [
              "id",
              "name"
            ],
            "properties": {
              "id": {
                "type": "string"
              },
              "name": {
                "type": "string"
              }
            }
          },
          "invited_by_user_id": {
            "type": "string"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "UsageReport": {
        "type": "object",
        "description": "A workspace's usage against its plan limits.",
        "required": [
          "workspace_id",
          "workspace_name",
          "plan",
          "custom_limits",
          "retention_days",
          "plan_retention_days",
          "metrics",
          "warning",
          "critical",
          "exceeded",
          "upgrade_url"
        ],
        "properties": {
          "workspace_id": {
            "type": "string"
          },
          "workspace_name": {
            "type": "string"
          },
          "plan": {
            "type": "string",
            "enum": [
              "free",
              "pro",
              "org",
              "custom"
            ]
          },
          "custom_limits": {
            "type": "boolean",
            "description": "An admin set per-workspace limit overrides."
          },
          "retention_days": {
            "type": [
              "integer",
              "null"
            ],
            "description": "Days of history that can be rolled back; null when unlimited."
          },
          "plan_retention_days": {
            "type": "object",
            "description": "Retention days per plan (`free`, `pro`, `org`), for comparison; `{}` when quotas are not configured.",
            "additionalProperties": {
              "type": "integer"
            }
          },
          "metrics": {
            "type": "object",
            "required": [
              "spaces",
              "rows",
              "storage",
              "machines",
              "devices",
              "guests",
              "end_users"
            ],
            "properties": {
              "spaces": {
                "$ref": "#/components/schemas/MetricUsage"
              },
              "rows": {
                "$ref": "#/components/schemas/MetricUsage"
              },
              "storage": {
                "$ref": "#/components/schemas/MetricUsage",
                "description": "In bytes."
              },
              "machines": {
                "$ref": "#/components/schemas/MetricUsage",
                "description": "Active headless machines (servers, CI, Machine Auth Keys)."
              },
              "devices": {
                "$ref": "#/components/schemas/MetricUsage",
                "description": "Active personal devices (laptops, phones, desktop apps, and agents on them)."
              },
              "guests": {
                "$ref": "#/components/schemas/MetricUsage",
                "description": "External guests of the busiest space (`space_id`)."
              },
              "end_users": {
                "$ref": "#/components/schemas/MetricUsage",
                "description": "Monthly active app end users across the workspace's spaces (ADR 0021)."
              }
            }
          },
          "warning": {
            "type": "boolean",
            "description": "Any metric at or above 75 %."
          },
          "critical": {
            "type": "boolean",
            "description": "Any metric at or above 90 %."
          },
          "exceeded": {
            "type": "boolean",
            "description": "Any metric at its limit."
          },
          "upgrade_url": {
            "type": "string",
            "description": "Console path of the upgrade request form (`/upgrade`)."
          }
        }
      },
      "ProtocolSchemaIndex": {
        "type": "object",
        "required": [
          "reference",
          "schemas"
        ],
        "properties": {
          "reference": {
            "type": "string",
            "description": "The human protocol reference."
          },
          "schemas": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "name",
                "url"
              ],
              "properties": {
                "name": {
                  "type": "string",
                  "description": "File name, e.g. `hello.schema.json`."
                },
                "url": {
                  "type": "string",
                  "description": "The file's URL (its `$id`)."
                }
              }
            }
          }
        }
      },
      "AppUsage": {
        "type": "object",
        "required": [
          "workspace_id",
          "plan",
          "metrics",
          "upgrade_url"
        ],
        "properties": {
          "workspace_id": {
            "type": "string"
          },
          "space_id": {
            "type": "string",
            "description": "The `space_id` asked for; absent otherwise."
          },
          "plan": {
            "type": "string",
            "enum": [
              "free",
              "pro",
              "org",
              "custom"
            ]
          },
          "metrics": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/UsageSignal"
            }
          },
          "upgrade_url": {
            "type": "string",
            "description": "Where the user requests more (the console's upgrade page)."
          }
        }
      },
      "UsageSignal": {
        "type": "object",
        "required": [
          "metric",
          "used",
          "limit",
          "state"
        ],
        "properties": {
          "metric": {
            "type": "string",
            "enum": [
              "spaces",
              "rows",
              "storage",
              "machines",
              "devices",
              "guests",
              "end_users"
            ]
          },
          "used": {
            "type": "integer",
            "format": "int64"
          },
          "limit": {
            "type": [
              "integer",
              "null"
            ],
            "format": "int64",
            "description": "The hard limit; null when unlimited."
          },
          "soft_limit": {
            "type": "integer",
            "format": "int64",
            "description": "The plan's included amount when it is below the hard limit (rows)."
          },
          "state": {
            "type": "string",
            "enum": [
              "ok",
              "near",
              "over"
            ]
          }
        }
      },
      "MetricUsage": {
        "type": "object",
        "required": [
          "used",
          "limit",
          "percent",
          "warning",
          "critical",
          "exceeded"
        ],
        "properties": {
          "used": {
            "type": "integer",
            "format": "int64"
          },
          "limit": {
            "type": [
              "integer",
              "null"
            ],
            "format": "int64",
            "description": "The plan's amount (for rows, the soft limit); null when unlimited."
          },
          "hard_limit": {
            "type": "integer",
            "format": "int64",
            "description": "Where growth stops, when above `limit` (rows have a 10% grace buffer)."
          },
          "percent": {
            "type": "integer",
            "minimum": 0,
            "maximum": 100
          },
          "warning": {
            "type": "boolean"
          },
          "critical": {
            "type": "boolean"
          },
          "exceeded": {
            "type": "boolean"
          },
          "space_id": {
            "type": "string",
            "description": "For `guests`, the space with the most guests; absent otherwise."
          }
        }
      },
      "UpgradeRequestView": {
        "type": "object",
        "required": [
          "id",
          "status",
          "email",
          "tier",
          "duplicate",
          "created_at"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "status": {
            "type": "string",
            "description": "`pending` for new and duplicate requests."
          },
          "email": {
            "type": "string"
          },
          "tier": {
            "type": "string",
            "enum": [
              "pro",
              "org",
              "custom"
            ]
          },
          "duplicate": {
            "type": "boolean",
            "description": "A pending request already existed; nothing new was stored."
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "UpgradeRequestError": {
        "type": "object",
        "description": "The error envelope of `POST /v1/upgrade-requests` validation failures.",
        "required": [
          "error"
        ],
        "properties": {
          "error": {
            "type": "object",
            "required": [
              "code",
              "message"
            ],
            "properties": {
              "code": {
                "type": "string",
                "const": "invalid_request"
              },
              "message": {
                "type": "string",
                "description": "The message of the first invalid field (by name), or the JSON decode error."
              },
              "hint": {
                "type": "string"
              },
              "fields": {
                "type": "object",
                "description": "Invalid field name → message to show next to it. Absent when the body is not valid JSON.",
                "additionalProperties": {
                  "type": "string"
                }
              }
            }
          }
        }
      },
      "UpgradeRateLimitedError": {
        "type": "object",
        "required": [
          "error"
        ],
        "properties": {
          "error": {
            "type": "object",
            "required": [
              "code",
              "message",
              "retry_after"
            ],
            "properties": {
              "code": {
                "type": "string",
                "const": "rate_limited"
              },
              "message": {
                "type": "string"
              },
              "hint": {
                "type": "string"
              },
              "retry_after": {
                "type": "integer",
                "description": "Seconds to wait before trying again."
              }
            }
          }
        }
      },
      "ChangeActor": {
        "type": "object",
        "description": "The (user, machine, app) that made a change. Each field is omitted when\nempty: headless sessions have no user; console sessions have no app.\n",
        "properties": {
          "user_id": {
            "type": "string"
          },
          "machine_id": {
            "type": "string"
          },
          "app_id": {
            "type": "string"
          },
          "end_user_id": {
            "type": "string",
            "description": "The app end user behind the change (ADR 0021); with `machine_id`, a server acting as that end user."
          }
        }
      },
      "ColumnSchema": {
        "type": "object",
        "description": "One column of a table schema.",
        "required": [
          "type"
        ],
        "properties": {
          "type": {
            "type": "string",
            "enum": [
              "string",
              "number",
              "boolean",
              "datetime",
              "json",
              "ref",
              "file_ref"
            ]
          },
          "optional": {
            "type": "boolean",
            "description": "Optional columns accept null and may be absent. Omitted when false."
          },
          "ref_table": {
            "type": "string",
            "description": "For `ref` columns, the referenced table. Omitted when unset."
          },
          "unique": {
            "type": "boolean",
            "description": "No two live rows may hold the same non-null value; a write that would is\nrejected with `unique_violation`. Omitted when false. Not allowed on json columns.\n"
          },
          "indexed": {
            "type": "boolean",
            "description": "Queries may compare and order on the column. Unique and ref columns are\nindexed too. Omitted when false. Not allowed on json columns.\n"
          }
        }
      },
      "TableSchema": {
        "type": "object",
        "description": "A table's columns, declared column order and version.",
        "required": [
          "columns"
        ],
        "properties": {
          "version": {
            "type": "integer",
            "minimum": 0,
            "description": "Set by the server and bumped on every schema change. Omitted when 0."
          },
          "columns": {
            "type": "object",
            "description": "Column name to definition.",
            "additionalProperties": {
              "$ref": "#/components/schemas/ColumnSchema"
            }
          },
          "order": {
            "type": "array",
            "description": "Every column name exactly once, in declared order. Omitted when unknown.",
            "items": {
              "type": "string"
            }
          }
        }
      },
      "Tables": {
        "type": "object",
        "description": "Table name to schema.",
        "additionalProperties": {
          "$ref": "#/components/schemas/TableSchema"
        }
      },
      "ColumnSchemaInput": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "type"
        ],
        "properties": {
          "type": {
            "type": "string",
            "enum": [
              "string",
              "number",
              "boolean",
              "datetime",
              "json",
              "ref",
              "file_ref"
            ]
          },
          "optional": {
            "type": "boolean",
            "description": "Optional columns accept null and may be absent."
          },
          "ref_table": {
            "type": "string",
            "pattern": "^[A-Za-z][A-Za-z0-9_]{0,62}$",
            "description": "For `ref` columns only, the referenced table."
          },
          "unique": {
            "type": "boolean",
            "description": "No two live rows may hold the same non-null value. Not on json columns."
          },
          "indexed": {
            "type": "boolean",
            "description": "Queries may compare and order on the column. Not on json columns."
          }
        }
      },
      "SchemaChangeInput": {
        "type": "object",
        "additionalProperties": false,
        "description": "One schema change. Which fields are used depends on `op`:\n`create_table` (table, columns, order?), `set_order` (table, order),\n`add_column` (table, column, def), `drop_column` (table, column),\n`rename_column` (table, column, new_name), `change_type` (table,\ncolumn, def: the new type and ref_table), `make_required` (table,\ncolumn), `drop_table` (table), `rename_table` (table, new_name),\n`add_unique`, `drop_unique`, `add_index`, `drop_index` (table, column).\n`create_table`, `set_order`, `add_index` and `add_column` of an optional\ncolumn are additive; every other change is destructive and becomes a\nproposal. Approving `add_unique` fails with `409 unique_violation` while\nlive rows share a value.\n",
        "required": [
          "op",
          "table"
        ],
        "properties": {
          "op": {
            "type": "string",
            "enum": [
              "create_table",
              "set_order",
              "add_column",
              "drop_column",
              "rename_column",
              "change_type",
              "make_required",
              "drop_table",
              "rename_table",
              "add_unique",
              "drop_unique",
              "add_index",
              "drop_index"
            ]
          },
          "table": {
            "type": "string",
            "pattern": "^[A-Za-z][A-Za-z0-9_]{0,62}$"
          },
          "column": {
            "type": "string",
            "pattern": "^[A-Za-z][A-Za-z0-9_]{0,62}$"
          },
          "new_name": {
            "type": "string",
            "pattern": "^[A-Za-z][A-Za-z0-9_]{0,62}$"
          },
          "def": {
            "$ref": "#/components/schemas/ColumnSchemaInput"
          },
          "columns": {
            "type": "object",
            "additionalProperties": {
              "$ref": "#/components/schemas/ColumnSchemaInput"
            }
          },
          "order": {
            "type": "array",
            "items": {
              "type": "string"
            }
          }
        }
      },
      "SchemaChange": {
        "type": "object",
        "description": "One schema change as stored in a proposal (see `SchemaChangeInput` for the ops). Empty fields are omitted.",
        "required": [
          "op",
          "table"
        ],
        "properties": {
          "op": {
            "type": "string",
            "enum": [
              "create_table",
              "set_order",
              "add_column",
              "drop_column",
              "rename_column",
              "change_type",
              "make_required",
              "drop_table",
              "rename_table",
              "add_unique",
              "drop_unique",
              "add_index",
              "drop_index",
              "set_rules"
            ]
          },
          "table": {
            "type": "string"
          },
          "column": {
            "type": "string"
          },
          "new_name": {
            "type": "string"
          },
          "def": {
            "$ref": "#/components/schemas/ColumnSchema"
          },
          "columns": {
            "type": "object",
            "additionalProperties": {
              "$ref": "#/components/schemas/ColumnSchema"
            }
          },
          "order": {
            "type": "array",
            "items": {
              "type": "string"
            }
          }
        }
      },
      "SchemaProposal": {
        "type": "object",
        "description": "A destructive schema change waiting for (or decided by) a space owner.",
        "required": [
          "id",
          "space_id",
          "table",
          "base_version",
          "changes",
          "status",
          "proposed_by",
          "created_at"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "space_id": {
            "type": "string"
          },
          "table": {
            "type": "string"
          },
          "base_version": {
            "type": "integer",
            "description": "The table version the proposal was made against (0 for a table that did not exist)."
          },
          "changes": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/SchemaChange"
            }
          },
          "status": {
            "type": "string",
            "enum": [
              "pending",
              "approved",
              "rejected",
              "superseded"
            ]
          },
          "proposed_by": {
            "$ref": "#/components/schemas/ChangeActor"
          },
          "rules": {
            "type": "object",
            "description": "The proposed rules document of a rules proposal (table `_rules`,\nchanges `[{\"op\": \"set_rules\", \"table\": \"_rules\"}]`, `base_version`\nthe rules version it was made against). Absent otherwise.\n"
          },
          "decided_by": {
            "type": "string",
            "description": "User ID of the owner who decided it. Omitted while pending."
          },
          "decided_at": {
            "type": "string",
            "format": "date-time",
            "description": "Omitted while pending."
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "SyncOp": {
        "type": "object",
        "description": "One committed oplog entry, as in sync `delta`/`broadcast` frames.\nRecord ops carry `table`, `id` and, for upserts, the `fields` this op\nwon; file ops carry `id` and the resulting `file`; schema ops carry\n`table` and, for `put`, the resulting `schema`.\n",
        "required": [
          "seq",
          "mutation_id",
          "hlc",
          "at",
          "by",
          "kind",
          "op"
        ],
        "properties": {
          "seq": {
            "type": "integer",
            "format": "int64"
          },
          "mutation_id": {
            "type": "string"
          },
          "hlc": {
            "type": "string",
            "description": "Hybrid logical clock stamp `wall_ms:counter:node_id`."
          },
          "at": {
            "type": "string",
            "format": "date-time",
            "description": "Server commit time."
          },
          "by": {
            "$ref": "#/components/schemas/ChangeActor"
          },
          "kind": {
            "type": "string",
            "enum": [
              "record",
              "file",
              "schema"
            ]
          },
          "op": {
            "type": "string",
            "enum": [
              "upsert",
              "put",
              "move",
              "delete",
              "restore"
            ]
          },
          "table": {
            "type": "string"
          },
          "id": {
            "type": "string"
          },
          "fields": {
            "type": "object",
            "description": "Column name to JSON value (null for a cleared optional field)."
          },
          "file": {
            "$ref": "#/components/schemas/FileMeta"
          },
          "schema": {
            "$ref": "#/components/schemas/TableSchema"
          },
          "purge": {
            "$ref": "#/components/schemas/OpPurge"
          },
          "revert": {
            "$ref": "#/components/schemas/RevertRef"
          }
        }
      },
      "OpPurge": {
        "type": "object",
        "description": "Set when an owner permanently deleted rows or files from the Trash: on\na schema `delete` op for every trashed row of a dropped table\n(`scope: table`), on a record `delete` op for one trashed row\n(`scope: row`), or on a file `delete` op for one trashed file\n(`scope: file`; the op still carries the file's last state).\n",
        "required": [
          "scope",
          "count"
        ],
        "properties": {
          "scope": {
            "type": "string",
            "enum": [
              "table",
              "row",
              "file"
            ]
          },
          "count": {
            "type": "integer",
            "minimum": 1
          }
        }
      },
      "DroppedTable": {
        "type": "object",
        "required": [
          "table",
          "count"
        ],
        "properties": {
          "table": {
            "type": "string"
          },
          "count": {
            "type": "integer",
            "description": "The table's rows in the Trash."
          },
          "dropped_at": {
            "type": "string",
            "format": "date-time",
            "description": "When the table was last dropped, when the oplog has it."
          }
        }
      },
      "TrashCounts": {
        "type": "object",
        "description": "What a space's Trash holds, by kind.",
        "required": [
          "rows",
          "dropped_tables",
          "files"
        ],
        "properties": {
          "rows": {
            "type": "integer",
            "minimum": 0,
            "description": "Trashed rows, of live tables and of dropped tables."
          },
          "dropped_tables": {
            "type": "integer",
            "minimum": 0,
            "description": "Dropped tables that left rows in the Trash (their rows are counted in `rows`)."
          },
          "files": {
            "type": "integer",
            "minimum": 0,
            "description": "Trashed files."
          }
        }
      },
      "EmptyTrashChangedError": {
        "type": "object",
        "required": [
          "error"
        ],
        "properties": {
          "error": {
            "type": "object",
            "required": [
              "code",
              "message",
              "rows",
              "dropped_tables",
              "files"
            ],
            "properties": {
              "code": {
                "type": "string",
                "const": "trash_changed"
              },
              "message": {
                "type": "string"
              },
              "hint": {
                "type": "string"
              },
              "rows": {
                "type": "integer",
                "description": "Trashed rows now."
              },
              "dropped_tables": {
                "type": "integer",
                "description": "Dropped tables with rows in the Trash now."
              },
              "files": {
                "type": "integer",
                "description": "Trashed files now."
              }
            }
          }
        }
      },
      "PurgeResult": {
        "type": "object",
        "required": [
          "purged"
        ],
        "properties": {
          "purged": {
            "type": "integer",
            "description": "How many rows were permanently deleted."
          }
        }
      },
      "SchemaChangeResult": {
        "type": "object",
        "required": [
          "tables",
          "ops",
          "proposals",
          "head_seq"
        ],
        "properties": {
          "tables": {
            "$ref": "#/components/schemas/Tables"
          },
          "ops": {
            "type": "array",
            "description": "The schema ops committed for the additive changes (may be empty).",
            "items": {
              "$ref": "#/components/schemas/SyncOp"
            }
          },
          "proposals": {
            "type": "array",
            "description": "Proposals recorded (or reused) for the destructive changes, one per table.",
            "items": {
              "$ref": "#/components/schemas/SchemaProposal"
            }
          },
          "head_seq": {
            "type": "integer",
            "format": "int64"
          },
          "refused": {
            "type": "array",
            "description": "Partner API, declared `tables` only: tables that could not be\ncreated because a dropped table of that name left rows in the\nTrash that don't fit them. Each is a `trashed_rows_conflict` error\n(`code`, `message`, `table`, `op`, `count`, `examples`, `first`,\n`hint`). The rest of the declaration was applied.\n",
            "items": {
              "type": "object",
              "additionalProperties": true
            }
          }
        }
      },
      "ProposalDecision": {
        "type": "object",
        "description": "The decided proposal. On approve, also the schema after it was\napplied (`tables`), the schema ops committed (`ops`) and `head_seq`;\non reject only `proposal`.\n",
        "required": [
          "proposal"
        ],
        "properties": {
          "proposal": {
            "$ref": "#/components/schemas/SchemaProposal"
          },
          "tables": {
            "$ref": "#/components/schemas/Tables"
          },
          "ops": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/SyncOp"
            }
          },
          "head_seq": {
            "type": "integer",
            "format": "int64"
          }
        }
      },
      "RecordState": {
        "type": "object",
        "description": "One row. Every field carries the HLC of the write that set it;\n`deleted` (the Trash flag) is a register of its own stamped by `deleted_hlc`.\n",
        "required": [
          "table",
          "id",
          "fields",
          "hlcs",
          "seq"
        ],
        "properties": {
          "table": {
            "type": "string"
          },
          "id": {
            "type": "string"
          },
          "fields": {
            "type": "object",
            "description": "Column name to JSON value."
          },
          "hlcs": {
            "type": "object",
            "description": "Column name to the HLC stamp of its value.",
            "additionalProperties": {
              "type": "string"
            }
          },
          "deleted": {
            "type": "boolean",
            "description": "True for a row in the Trash. Omitted when false."
          },
          "deleted_hlc": {
            "type": "string",
            "description": "HLC of the last delete/restore. Omitted when never deleted."
          },
          "seq": {
            "type": "integer",
            "format": "int64",
            "description": "Seq of the op that last changed the row."
          }
        }
      },
      "RecordPage": {
        "type": "object",
        "required": [
          "records"
        ],
        "properties": {
          "records": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/RecordState"
            }
          },
          "next_after_seq": {
            "type": "integer",
            "format": "int64",
            "description": "Present when the page is full; pass it as `after_seq` for the next page."
          }
        }
      },
      "QueryResult": {
        "type": "object",
        "required": [
          "data",
          "page_info",
          "through_seq"
        ],
        "properties": {
          "data": {
            "type": "object",
            "description": "The nested result, keyed like the query.",
            "additionalProperties": {
              "type": "array",
              "items": {
                "type": "object",
                "required": [
                  "id"
                ],
                "properties": {
                  "id": {
                    "type": "string"
                  }
                }
              }
            }
          },
          "page_info": {
            "type": "object",
            "description": "Paging per top-level key.",
            "additionalProperties": {
              "type": "object",
              "required": [
                "has_more"
              ],
              "properties": {
                "start_cursor": {
                  "type": "string",
                  "description": "The first row's cursor (for `$.before`)."
                },
                "end_cursor": {
                  "type": "string",
                  "description": "The last row's cursor (for `$.after`)."
                },
                "has_more": {
                  "type": "boolean",
                  "description": "Rows exist beyond `limit` in the paging direction."
                }
              }
            }
          },
          "through_seq": {
            "type": "integer",
            "format": "int64",
            "description": "The space's head when the query ran; the result includes every commit up to it."
          }
        }
      },
      "RestoreResult": {
        "type": "object",
        "required": [
          "restored",
          "seq"
        ],
        "properties": {
          "restored": {
            "type": "boolean",
            "const": true
          },
          "seq": {
            "type": "integer",
            "format": "int64",
            "description": "Seq of the restore op."
          }
        }
      },
      "RevertRef": {
        "type": "object",
        "description": "Links a compensating (rollback) op to the ops it reverts. Set on the op in sync frames, rollback results and the activity feed.",
        "required": [
          "kind",
          "seqs"
        ],
        "properties": {
          "kind": {
            "type": "string",
            "enum": [
              "undo_app",
              "undo_end_user",
              "point_in_time",
              "undo_ops"
            ]
          },
          "seqs": {
            "type": "array",
            "items": {
              "type": "integer",
              "format": "int64"
            }
          }
        }
      },
      "ActivityEntry": {
        "type": "object",
        "description": "An op of the activity feed (the fields of `SyncOp`) with its before and after images.",
        "required": [
          "seq",
          "mutation_id",
          "hlc",
          "at",
          "by",
          "kind",
          "op"
        ],
        "properties": {
          "seq": {
            "type": "integer",
            "format": "int64"
          },
          "mutation_id": {
            "type": "string"
          },
          "hlc": {
            "type": "string"
          },
          "at": {
            "type": "string",
            "format": "date-time",
            "description": "Server commit time."
          },
          "by": {
            "$ref": "#/components/schemas/ChangeActor"
          },
          "kind": {
            "type": "string",
            "enum": [
              "record",
              "file",
              "schema"
            ]
          },
          "op": {
            "type": "string",
            "enum": [
              "upsert",
              "put",
              "move",
              "delete",
              "restore"
            ]
          },
          "table": {
            "type": "string"
          },
          "id": {
            "type": "string"
          },
          "fields": {
            "type": "object",
            "description": "Record upserts. Column name to JSON value."
          },
          "file": {
            "$ref": "#/components/schemas/FileMeta"
          },
          "schema": {
            "$ref": "#/components/schemas/TableSchema"
          },
          "before": {
            "description": "The entity's state before the op (JSON, may be null; shape depends on `kind`). Omitted when none."
          },
          "after": {
            "description": "The entity's state after the op (JSON, may be null; shape depends on `kind`). Omitted when none."
          },
          "revert": {
            "$ref": "#/components/schemas/RevertRef"
          },
          "purge": {
            "$ref": "#/components/schemas/OpPurge"
          }
        }
      },
      "ActivityPage": {
        "type": "object",
        "required": [
          "ops"
        ],
        "properties": {
          "ops": {
            "type": "array",
            "description": "Newest first, or oldest first with `order=asc`.",
            "items": {
              "$ref": "#/components/schemas/ActivityEntry"
            }
          },
          "next_before_seq": {
            "type": "integer",
            "format": "int64",
            "description": "Present when a newest-first page is full; pass it as `before_seq` for the next (older) page."
          },
          "next_after_seq": {
            "type": "integer",
            "format": "int64",
            "description": "Present when an `order=asc` page is full; pass it as `after_seq` for the next (newer) page."
          }
        }
      },
      "RollbackRequest": {
        "type": "object",
        "additionalProperties": false,
        "description": "`undo_app` needs `app_id` and `minutes` or `since` (not both), and may\nnarrow with `table` or `path_prefix` (not both). `undo_end_user`\ntakes `end_user_id` instead of `app_id`. `point_in_time` needs\n`to_seq` or `to_time` (not both) and takes no narrowing fields.\n`undo_ops` needs `seqs`, `mutation_ids` or both (their union is\nreverted, at most 1,000 ops) and takes no other selector.\n",
        "required": [
          "kind"
        ],
        "properties": {
          "kind": {
            "type": "string",
            "enum": [
              "undo_app",
              "undo_end_user",
              "point_in_time",
              "undo_ops"
            ]
          },
          "app_id": {
            "type": "string",
            "description": "undo_app only. The app whose changes are reverted."
          },
          "end_user_id": {
            "type": "string",
            "description": "undo_end_user only. The app end user whose changes are reverted."
          },
          "minutes": {
            "type": "integer",
            "description": "undo_app only. Revert the last N minutes."
          },
          "since": {
            "type": "string",
            "format": "date-time",
            "description": "undo_app only, instead of `minutes`."
          },
          "table": {
            "type": "string",
            "pattern": "^[A-Za-z][A-Za-z0-9_]{0,62}$",
            "description": "undo_app only. Only rows of this table."
          },
          "path_prefix": {
            "type": "string",
            "description": "undo_app only. Only files under this path."
          },
          "to_seq": {
            "type": "integer",
            "format": "int64",
            "minimum": 0,
            "description": "point_in_time only. The seq to return to."
          },
          "to_time": {
            "type": "string",
            "format": "date-time",
            "description": "point_in_time only. Return to the last op committed at or before this time."
          },
          "seqs": {
            "type": "array",
            "minItems": 1,
            "maxItems": 1000,
            "items": {
              "type": "integer",
              "format": "int64",
              "minimum": 1
            },
            "description": "undo_ops only. Revert the ops with these seqs."
          },
          "mutation_ids": {
            "type": "array",
            "minItems": 1,
            "maxItems": 20,
            "items": {
              "type": "string",
              "minLength": 1
            },
            "description": "undo_ops only. Revert every op of these mutations; pass a rollback's `rollback_id` to undo it."
          },
          "expected_head_seq": {
            "type": "integer",
            "format": "int64",
            "description": "Apply only. The preview's `head_seq`; refuse with `409 stale_preview` if the space moved."
          },
          "sample": {
            "type": "integer",
            "minimum": 0,
            "maximum": 100,
            "description": "How many changes `sample` holds (0 or absent = 20)."
          }
        }
      },
      "RollbackFieldChange": {
        "type": "object",
        "description": "A field's value now (`from`) and after the rollback (`to`); null means no value.",
        "required": [
          "from",
          "to"
        ],
        "properties": {
          "from": {},
          "to": {}
        }
      },
      "RollbackEntityChange": {
        "type": "object",
        "description": "What a rollback does to one row or file.",
        "required": [
          "kind",
          "id",
          "reverts"
        ],
        "properties": {
          "kind": {
            "type": "string",
            "enum": [
              "record",
              "file"
            ]
          },
          "table": {
            "type": "string",
            "description": "Rows only."
          },
          "id": {
            "type": "string"
          },
          "fields": {
            "type": "object",
            "description": "Rows only. Column name to its change. Omitted when no field changes.",
            "additionalProperties": {
              "$ref": "#/components/schemas/RollbackFieldChange"
            }
          },
          "deleted": {
            "type": "object",
            "description": "The Trash flag now and after the rollback. Omitted when unchanged.",
            "required": [
              "from",
              "to"
            ],
            "properties": {
              "from": {
                "type": "boolean"
              },
              "to": {
                "type": "boolean"
              }
            }
          },
          "file": {
            "type": "object",
            "description": "Files only. The metadata now and after the rollback.",
            "required": [
              "from",
              "to"
            ],
            "properties": {
              "from": {
                "$ref": "#/components/schemas/FileMeta"
              },
              "to": {
                "$ref": "#/components/schemas/FileMeta"
              }
            }
          },
          "reverts": {
            "type": "array",
            "description": "The seqs of the ops this change compensates.",
            "items": {
              "type": "integer",
              "format": "int64"
            }
          }
        }
      },
      "TransactRequest": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "mutations"
        ],
        "properties": {
          "batch_id": {
            "type": "string",
            "pattern": "^[A-Za-z0-9_-]{1,128}$",
            "description": "Names the batch for retries. The server picks one when omitted."
          },
          "mutations": {
            "type": "array",
            "minItems": 1,
            "maxItems": 500,
            "items": {
              "$ref": "#/components/schemas/SyncMutation"
            }
          },
          "params": {
            "type": "object",
            "description": "Values end users' write rules read as `params` (ADR 0021 §3.2). Untrusted data, never an identity."
          }
        }
      },
      "SyncMutation": {
        "type": "object",
        "description": "One write, as in a sync `mutate` frame (docs/PROTOCOL.md).",
        "required": [
          "mutation_id",
          "hlc",
          "kind",
          "op",
          "id"
        ],
        "properties": {
          "mutation_id": {
            "type": "string",
            "pattern": "^[A-Za-z0-9_-]{1,128}$"
          },
          "hlc": {
            "type": "string",
            "description": "Hybrid logical clock stamp, `<13-digit ms>:<5-digit counter>:<node>`."
          },
          "kind": {
            "type": "string",
            "enum": [
              "record",
              "file"
            ]
          },
          "op": {
            "type": "string",
            "enum": [
              "upsert",
              "delete",
              "restore",
              "put",
              "move"
            ]
          },
          "table": {
            "type": "string",
            "description": "Record mutations only."
          },
          "id": {
            "type": "string"
          },
          "fields": {
            "type": "object",
            "description": "Record upserts only. Column name to JSON value.",
            "additionalProperties": true
          },
          "file": {
            "type": "object",
            "description": "File puts and moves only (path, sha256, size_bytes, mime_type).",
            "additionalProperties": true
          }
        }
      },
      "SyncMutationResult": {
        "type": "object",
        "required": [
          "mutation_id",
          "status"
        ],
        "properties": {
          "mutation_id": {
            "type": "string"
          },
          "status": {
            "type": "string",
            "enum": [
              "applied",
              "duplicate",
              "rejected",
              "aborted"
            ],
            "description": "`aborted`: not applied because another mutation of the batch was rejected."
          },
          "seq": {
            "type": "integer",
            "format": "int64",
            "description": "Seq of the op the mutation produced. Omitted when it changed nothing."
          },
          "error": {
            "$ref": "#/components/schemas/SyncErrorBody"
          }
        }
      },
      "SyncErrorBody": {
        "type": "object",
        "required": [
          "code",
          "message"
        ],
        "properties": {
          "code": {
            "type": "string"
          },
          "message": {
            "type": "string"
          },
          "details": {
            "type": "object",
            "additionalProperties": true
          },
          "hint": {
            "type": "string"
          }
        }
      },
      "BatchResult": {
        "type": "object",
        "required": [
          "id",
          "status"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "status": {
            "type": "string",
            "enum": [
              "applied",
              "rejected",
              "duplicate"
            ]
          },
          "failed_index": {
            "type": "integer",
            "minimum": 0,
            "description": "Rejected batches only. The mutation that failed."
          },
          "error": {
            "$ref": "#/components/schemas/SyncErrorBody"
          }
        }
      },
      "TransactResult": {
        "type": "object",
        "required": [
          "space_id",
          "batch",
          "results",
          "head_seq"
        ],
        "properties": {
          "space_id": {
            "type": "string"
          },
          "batch": {
            "$ref": "#/components/schemas/BatchResult"
          },
          "results": {
            "type": "array",
            "description": "One per mutation, in order.",
            "items": {
              "$ref": "#/components/schemas/SyncMutationResult"
            }
          },
          "head_seq": {
            "type": "integer",
            "format": "int64"
          },
          "warnings": {
            "type": "array",
            "description": "quota_near notices, as in an ack.",
            "items": {
              "type": "object",
              "additionalProperties": true
            }
          }
        }
      },
      "RollbackConflict": {
        "type": "object",
        "description": "A change the rollback leaves alone.",
        "required": [
          "kind",
          "id",
          "reason",
          "by"
        ],
        "properties": {
          "kind": {
            "type": "string",
            "enum": [
              "record",
              "file"
            ]
          },
          "table": {
            "type": "string"
          },
          "id": {
            "type": "string"
          },
          "field": {
            "type": "string"
          },
          "reason": {
            "type": "string",
            "enum": [
              "overwritten_later",
              "table_missing",
              "column_missing",
              "path_taken",
              "required_column",
              "unique_taken",
              "type_mismatch"
            ]
          },
          "seq": {
            "type": "integer",
            "format": "int64",
            "description": "overwritten_later only. The later op that kept the value."
          },
          "by": {
            "$ref": "#/components/schemas/ChangeActor"
          }
        }
      },
      "RollbackPlan": {
        "type": "object",
        "description": "What a rollback would do (preview) or did (apply). Counts cover every change; `sample` holds the first few.",
        "required": [
          "kind",
          "head_seq",
          "rows",
          "fields",
          "files",
          "ops_reverted",
          "schema_ops_skipped",
          "conflicts",
          "sample"
        ],
        "properties": {
          "kind": {
            "type": "string",
            "enum": [
              "undo_app",
              "point_in_time"
            ]
          },
          "head_seq": {
            "type": "integer",
            "format": "int64",
            "description": "The head the plan was computed at."
          },
          "target_seq": {
            "type": "integer",
            "format": "int64",
            "description": "point_in_time only (omitted when 0)."
          },
          "rows": {
            "type": "integer",
            "description": "Rows changed."
          },
          "fields": {
            "type": "integer",
            "description": "Field values changed."
          },
          "files": {
            "type": "integer",
            "description": "Files changed."
          },
          "ops_reverted": {
            "type": "integer",
            "description": "Record and file ops selected."
          },
          "schema_ops_skipped": {
            "type": "integer",
            "description": "Schema ops in range; rollback never touches them."
          },
          "conflicts": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/RollbackConflict"
            }
          },
          "sample": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/RollbackEntityChange"
            }
          }
        }
      },
      "RollbackResult": {
        "type": "object",
        "required": [
          "rollback_id",
          "plan",
          "ops",
          "head_seq",
          "undo_to_seq"
        ],
        "properties": {
          "rollback_id": {
            "type": "string",
            "description": "The mutation ID shared by every compensating op."
          },
          "plan": {
            "$ref": "#/components/schemas/RollbackPlan"
          },
          "ops": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/SyncOp"
            }
          },
          "head_seq": {
            "type": "integer",
            "format": "int64"
          },
          "undo_to_seq": {
            "type": "integer",
            "format": "int64",
            "description": "The head before the rollback; a point_in_time rollback to it undoes this one."
          }
        }
      },
      "RetentionWindowError": {
        "type": "object",
        "required": [
          "error"
        ],
        "properties": {
          "error": {
            "type": "object",
            "required": [
              "code",
              "message",
              "retention_days",
              "upgrade_url"
            ],
            "properties": {
              "code": {
                "type": "string",
                "const": "retention_window"
              },
              "message": {
                "type": "string"
              },
              "hint": {
                "type": "string"
              },
              "retention_days": {
                "type": "integer",
                "description": "How many days of history the workspace plan keeps."
              },
              "upgrade_url": {
                "type": "string"
              }
            }
          }
        }
      },
      "TrashChangedError": {
        "type": "object",
        "required": [
          "error"
        ],
        "properties": {
          "error": {
            "type": "object",
            "required": [
              "code",
              "message",
              "table",
              "count"
            ],
            "properties": {
              "code": {
                "type": "string",
                "const": "trash_changed"
              },
              "message": {
                "type": "string"
              },
              "hint": {
                "type": "string"
              },
              "table": {
                "type": "string"
              },
              "count": {
                "type": "integer",
                "description": "How many of the table's rows are in the Trash now."
              }
            }
          }
        }
      },
      "FileMeta": {
        "type": "object",
        "description": "A file's metadata. Bytes are fetched with presigned URLs.",
        "required": [
          "id",
          "path",
          "sha256",
          "size_bytes",
          "mime_type",
          "version",
          "hlc",
          "seq",
          "updated_by"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "path": {
            "type": "string"
          },
          "sha256": {
            "type": "string",
            "description": "Lowercase hex SHA-256 of the bytes."
          },
          "size_bytes": {
            "type": "integer",
            "format": "int64"
          },
          "mime_type": {
            "type": "string"
          },
          "version": {
            "type": "integer",
            "description": "Content version; bumped by puts."
          },
          "hlc": {
            "type": "string"
          },
          "deleted": {
            "type": "boolean",
            "description": "True for a file in the Trash. Omitted when false."
          },
          "seq": {
            "type": "integer",
            "format": "int64",
            "description": "Seq of the op that last changed the file."
          },
          "updated_by": {
            "$ref": "#/components/schemas/ChangeActor"
          }
        }
      },
      "FilePage": {
        "type": "object",
        "required": [
          "files"
        ],
        "properties": {
          "files": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/FileMeta"
            }
          },
          "next_after_seq": {
            "type": "integer",
            "format": "int64",
            "description": "Present when the page is full; pass it as `after_seq` for the next page."
          }
        }
      },
      "FileFolder": {
        "type": "object",
        "description": "A folder implied by the paths of the files below it.",
        "required": [
          "path",
          "file_count"
        ],
        "properties": {
          "path": {
            "type": "string",
            "description": "Ends in `/`."
          },
          "file_count": {
            "type": "integer",
            "description": "Files anywhere below it."
          }
        }
      },
      "FileDirListing": {
        "type": "object",
        "required": [
          "dir",
          "folders",
          "files"
        ],
        "properties": {
          "dir": {
            "type": "string"
          },
          "folders": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/FileFolder"
            }
          },
          "files": {
            "type": "array",
            "description": "Files directly in `dir`.",
            "items": {
              "$ref": "#/components/schemas/FileMeta"
            }
          }
        }
      },
      "FileVersion": {
        "type": "object",
        "required": [
          "version",
          "path",
          "sha256",
          "size_bytes",
          "mime_type",
          "seq",
          "created_by",
          "created_at"
        ],
        "properties": {
          "version": {
            "type": "integer"
          },
          "path": {
            "type": "string"
          },
          "sha256": {
            "type": "string"
          },
          "size_bytes": {
            "type": "integer",
            "format": "int64"
          },
          "mime_type": {
            "type": "string"
          },
          "seq": {
            "type": "integer",
            "format": "int64"
          },
          "created_by": {
            "$ref": "#/components/schemas/ChangeActor"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "PresignedURL": {
        "type": "object",
        "description": "A request the client makes directly against blob storage. Send\n`method` to `url` with **every header in `headers` exactly as given**.\nWith S3/R2 an upload carries `x-amz-checksum-sha256` (base64 of the\nraw digest); the bucket rejects bytes that do not match. With the\nlocal blob store (`--dev`) the URL points at kovletd's\n`/v1/blobs/{space}/{sha}` and there are no headers.\n",
        "required": [
          "method",
          "url",
          "expires_at"
        ],
        "properties": {
          "method": {
            "type": "string",
            "enum": [
              "PUT",
              "GET"
            ]
          },
          "url": {
            "type": "string",
            "description": "Absolute URL; signed, use it verbatim."
          },
          "headers": {
            "type": "object",
            "description": "Headers to send exactly as given. Omitted when none.",
            "additionalProperties": {
              "type": "string"
            },
            "properties": {
              "x-amz-checksum-sha256": {
                "type": "string",
                "description": "S3/R2 uploads. Base64 of the raw SHA-256 digest; required by the signature."
              }
            }
          },
          "expires_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "UploadResponse": {
        "type": "object",
        "required": [
          "sha256",
          "size_bytes",
          "exists"
        ],
        "properties": {
          "sha256": {
            "type": "string"
          },
          "size_bytes": {
            "type": "integer",
            "format": "int64"
          },
          "exists": {
            "type": "boolean",
            "description": "True when the space already holds these bytes at this size; then there is no `upload`."
          },
          "upload": {
            "$ref": "#/components/schemas/PresignedURL"
          }
        }
      },
      "FileDownload": {
        "type": "object",
        "description": "A presigned download request (see `PresignedURL`) plus the metadata of the version it serves.",
        "required": [
          "method",
          "url",
          "expires_at",
          "file_id",
          "version",
          "path",
          "sha256",
          "size_bytes",
          "mime_type"
        ],
        "properties": {
          "method": {
            "type": "string",
            "const": "GET"
          },
          "url": {
            "type": "string",
            "description": "Absolute URL; signed, use it verbatim."
          },
          "headers": {
            "type": "object",
            "description": "Headers to send exactly as given. Omitted when none.",
            "additionalProperties": {
              "type": "string"
            }
          },
          "expires_at": {
            "type": "string",
            "format": "date-time"
          },
          "file_id": {
            "type": "string"
          },
          "version": {
            "type": "integer"
          },
          "path": {
            "type": "string"
          },
          "sha256": {
            "type": "string"
          },
          "size_bytes": {
            "type": "integer",
            "format": "int64"
          },
          "mime_type": {
            "type": "string"
          }
        }
      },
      "FolderMoveResult": {
        "type": "object",
        "required": [
          "from",
          "to",
          "moved",
          "head_seq"
        ],
        "properties": {
          "from": {
            "type": "string"
          },
          "to": {
            "type": "string"
          },
          "moved": {
            "type": "integer",
            "description": "Files moved."
          },
          "head_seq": {
            "type": "integer",
            "format": "int64"
          }
        }
      }
    }
  }
}
