{
 "openapi": "3.1.0",
 "info": {
  "title": "YouSelfBot API",
  "version": "1.3.0",
  "summary": "The platform's complete HTTP API: building an agent (flow, triggers, knowledge, actions), conversations and escalation to a live operator, the widget, the account and billing. Plus webhooks: the agent's incoming trigger and outgoing handoff-to-a-human events.",
  "description": "The YouSelfBot platform HTTP API: build agents, wake them up, train them and embed them in your own app, chat or CRM.\n\n## What's here\n\nYouSelfBot is an agent builder. An agent wakes up on a **trigger** (a message, a schedule, a webhook, polling, a manual run), walks its **graph of nodes** and ends with a **run** (Run) that is accounted for in credits.\n\nThis document describes the **entire** API, not just the integration calls. The dashboard is simply the first client of this same API, so everything it can do is available to your code too:\n\n| Surface | What it is | How it authenticates |\n| --- | --- | --- |\n| `/v1/api/*` | Conversation with the agent, handoff to a human, knowledge base, operator API. | secret key `sk_…` |\n| `POST /v1/hooks/{tid}` | **Incoming webhook**: an external system wakes the agent. | HMAC signature of the body |\n| `/v1/widget/*` | Calls from the visitor's browser: conversation, attachments, ratings, contacts. | publishable key `pk_…` |\n| `/v1/dashboard/*` | Building the agent: flow, triggers, knowledge, actions, requests, team. | user session |\n| `/v1/auth/*`, `/v1/billing/*` | Account, sessions, plans, credits. | user session |\n| Outgoing webhooks | We call **your** URL when a conversation is handed to a human, when the visitor writes, and when a request is closed. | your signing secret |\n\nThe surfaces differ not in how \"public\" they are, but in how they authenticate and who they are meant for. `/v1/dashboard/*` is designed for a browser session, so from your own backend it is easier to stick to `/v1/api/*` and incoming webhooks: they are more stable and need no cookie.\n\n## Authentication\n\nIntegration calls use the `X-Bot-Key` header with the agent's **secret** key (`sk_…`) from the dashboard. Dashboard surfaces authenticate with a session cookie.\n\n| Key | Where to get it | Where it works |\n| --- | --- | --- |\n| `sk_…` (secret) | dashboard → agent → Connections → Keys | `/v1/api/*`, `/v1/admin/*` |\n| `pk_…` (publishable) | the widget snippet | only `/v1/widget/*` in the browser |\n| session | `POST /v1/auth/login` | `/v1/dashboard/*`, `/v1/auth/*`, `/v1/billing/*` |\n\nThe publishable key `pk_…` from the widget snippet **does not work** for this API: any `/v1/api/*` call with a `pk_` key returns **403** (`wrong_key_type`), not 401. The key is valid, just of the wrong type. This is the most common mistake when starting an integration.\n\nThe secret key must never end up in a browser, a mobile app or a public repository: call this API only from your own backend. That is exactly why CORS is not configured for `/v1/api/*`.\n\n## Test chat in the dashboard\n\nThere is no separate \"talk to the agent with a dashboard session\" endpoint, and none is needed. The dashboard talks to the agent the same way the widget does:\n\n1. take the agent's `publishable_key` from `GET /v1/dashboard` (the field is present in every `bots[]` item);\n2. call `POST /v1/widget/chat` with that key straight from the browser.\n\nAllowed domains don't get in the way: **the platform's own pages are always allowed**, separately from the agent's list. So testing works even when the owner has narrowed the list down to a single site of their own, and that is exactly why the list can be narrowed without breaking your own testing.\n\n## Dashboard from the browser\n\n`/v1/dashboard/*` and `/v1/auth/*`, on the contrary, are designed specifically for the browser, and the frontend may live on a different domain.\n\n- **Requests must carry the cookie.** `fetch(url, {credentials: \"include\"})`. Without it every dashboard endpoint responds `401`, and it looks like \"the session didn't start\".\n- **The frontend domain must be in the allowed list.** The response then carries `Access-Control-Allow-Credentials: true`; from any other domain the browser won't show even a successful response. The domains are set by whoever deploys the build.\n- **The cookie is set by `POST /v1/auth/login`** and lives on all subdomains. When the frontend and the API are on different domains, the cookie is issued as `SameSite=None; Secure`, which means such a build REQUIRES https on both sides. On a shared domain the cookie stays `Lax`.\n- **Writes are protected by origin, not by a token.** See `sessionCookie`: there is no separate CSRF header here.\n- **`401` means exactly \"there is no session\".** If the service COULD NOT check the session (the store is unavailable), the response is `503` with the code `service_unavailable`, not `401`. The difference is not cosmetic: otherwise a database outage would tell every owner they had been logged out, and they couldn't go and log in again, because login hits the same database. Show the login screen on `401`, and \"the server isn't responding, try again in a moment\" on `503`. Any `/v1/dashboard/*` endpoint can return `503` for this reason.\n- **Writes that change existing data reject unknown fields.** `PUT` and `PATCH` on `/v1/dashboard/*` respond `400` (`bad_request`) and name the field they don't know, and in that case NOTHING is saved, including the known fields from the same body. Otherwise a misspelled field would silently disappear while the response said \"saved\" about something nobody saved. Send only the fields described in the request body; don't send read-only fields (`id`, `created_at` and so on) back.\n\n## Hello world (curl)\n\n```bash\nKEY=\"sk_your_secret_key\"\nSESSION=$(uuidgen)   # an unpredictable conversation id, one per dialog\n\n# 1. First message\ncurl -sS -X POST \"https://api.youselfbot.com/v1/api/chat\" \\\n  -H \"X-Bot-Key: $KEY\" -H \"Content-Type: application/json\" \\\n  -d \"{\\\"session_id\\\":\\\"$SESSION\\\",\\\"message\\\":\\\"What are your opening hours?\\\"}\"\n# {\"answer\":\"We're open 9:00 to 18:00, Mon–Fri.\",\"session_id\":\"…\"}\n\n# 2. The next message of THE SAME dialog uses the same session_id (that's how the bot remembers the context)\ncurl -sS -X POST \"https://api.youselfbot.com/v1/api/chat\" \\\n  -H \"X-Bot-Key: $KEY\" -H \"Content-Type: application/json\" \\\n  -d \"{\\\"session_id\\\":\\\"$SESSION\\\",\\\"message\\\":\\\"And on Saturday?\\\"}\"\n\n# 3. The customer asks for a live operator\ncurl -sS -X POST \"https://api.youselfbot.com/v1/api/handoff\" \\\n  -H \"X-Bot-Key: $KEY\" -H \"Content-Type: application/json\" \\\n  -d \"{\\\"session_id\\\":\\\"$SESSION\\\"}\"\n# {\"status\":\"waiting\"}\n\n# 4. Poll for the operator's replies. after is the `at` field of the last RECEIVED\n#    message (Unix ms); on the first request after=0.\ncurl -sS \"https://api.youselfbot.com/v1/api/messages?session_id=$SESSION&after=0\" -H \"X-Bot-Key: $KEY\"\n# {\"messages\":[{\"id\":\"…\",\"author\":\"operator\",\"text\":\"Hello!\",\"at\":1753600000123}],\n#  \"status\":\"operator\",\"operator_typing\":false}\n```\n\n## Conversation identifier (`session_id`)\n\n`session_id` is the key to the conversation history. Requirements:\n\n* **Unpredictable and unique within the bot.** UUIDv4 is recommended: `uuidgen`, `crypto.randomUUID()`, `uuid.uuid4()`.\n* **Don't use a user id, email, phone number, order number or counters** (`user-42`, `client_7`). Predictable ids collide between your own users: two different people end up in one conversation and see each other's messages. (There is no cross-bot leak: a session is pinned to a bot on first use, and another bot's key gets an empty response or 404. But collisions within your bot are your responsibility.)\n* One conversation = one `session_id`, for all endpoints (`/chat`, `/handoff`, `/messages`, `/typing`).\n* If you don't pass one, the server generates a random one and returns it in the `session_id` field of the response. Store it on your side.\n\nNeed a link to your user? There is a separate `user_token` field in `POST /v1/api/chat` for that: use it, not `session_id`.\n\n## Rate limits\n\nLimits are counted in a fixed 1-minute window, separately for each (key + IP) pair:\n\n| Group | Endpoints | Limit |\n| --- | --- | --- |\n| Dialog and writes | `POST /chat`, `POST /chat/stream`, `POST /handoff`, `POST /knowledge`, `DELETE /knowledge/{id}` | **60 requests/min** |\n| Reads and signals | `GET /messages`, `GET /knowledge`, `GET /knowledge/{id}`, `POST /typing`, all `/operator/*` | **240 requests/min** |\n\nThese are two independent budgets: heavy polling doesn't eat into the dialog limit. Exceeding a limit → `429` with the code `rate_limited`; retry in a few seconds with exponential backoff. Polling `GET /messages` once every 2–3 seconds (20–30 requests/min) fits comfortably. Limits don't apply to `/v1/admin/*`.\n\n## Error format\n\nEvery error is JSON `{\"error\": \"…\", \"code\": \"…\"}`.\n\n* `error` is human-readable text. It can change at any time, **don't build logic on it**.\n* `code` is a stable machine code. Branch on it (or on the HTTP status).\n\nCodes this API actually returns:\n\n| Code | Status | When |\n| --- | --- | --- |\n| `bad_request` | 400 | A required field is missing or empty. |\n| `missing_key` | 401 | Missing header `X-Bot-Key`. |\n| `invalid_key` | 401 | The key is unknown or revoked. |\n| `wrong_key_type` | 403 | A `pk_` key was passed where `sk_` is required. |\n| `not_found` | 404 | The conversation/source doesn't exist or belongs to another bot; handoff is turned off. |\n| `conflict` | 409 | The operation is already running (a site scan). |\n| `rate_limited` | 429 | The rate limit was exceeded. |\n| `internal_error` | 500 | Internal error. Safe to retry. |\n| `llm_unavailable` | 503 | The AI backend is temporarily unavailable. Retry later. |\n| `service_unavailable` | 503 | Other temporary unavailability. |\n\nTwo exceptions worth knowing up front:\n\n1. **`quota_exceeded` is not an error.** An exhausted monthly conversation limit is returned as `200` with `\"quota_exceeded\": true` in the body of `POST /v1/api/chat` (see `ChatResponse`).\n2. **In the `/v1/api/chat/stream` stream**, an error frame carries `code` only for `llm_unavailable`; an internal error frame arrives as `{\"error\":\"internal error\"}` **without** `code`. So in the stream, detect an error by the presence of the `error` field, not by `code`.\n\n## Idempotency\n\nEvery write accepts the `Idempotency-Key` header, both in the public API (`POST /chat`, `/chat/stream`, `/handoff`, `/knowledge`, `/operator/threads/{sid}/reply`, `/visitors/erase`) **and in the dashboard** (any unsafe method on `/v1/dashboard/*`):\n\n```\nIdempotency-Key: 3f6c1b9e-7f42-4d2a-9a6f-0d5b1f0b21c7\n```\n\n* The first request runs normally, and its response is stored for **24 hours**.\n* A repeat with the same key **doesn't perform the action a second time**: the stored response is returned with the `Idempotency-Replayed: true` header. That way a retry after a network timeout won't burn tokens twice, duplicate a message in the transcript or send a second webhook.\n* A key is scoped to your API key: other people's keys never collide with yours.\n* The same key with a **different** request body → `409` (`idempotency_key_reused`). If the first attempt is still running → `409` (`idempotency_in_progress`); retry in a second.\n* Reads (`GET`) don't accept a key: they aren't replayed but simply made again, precisely to see fresh data.\n* In the dashboard this is the same button clicked twice. Without a key, a second click on \"Create agent\" really does create a second one (and eats into the plan limit), and a repeated operator reply reaches the customer twice. Send a key with every form submission; the server decides by itself whether it's a repeat.\n* Error responses (5xx, 429) aren't stored: a retry reaches the server normally.\n\nGenerate a key per **logical** operation (UUIDv4) and reuse it only for retries of that operation.\n\n## Pagination\n\n`GET /operator/threads`, `GET /operator/threads/{sid}` and `GET /knowledge` return data in pages:\n\n* `?limit=` is the page size (1–200, default 50); anything above 200 is capped.\n* `?cursor=` is an opaque cursor from the `next_cursor` field of the previous response.\n* An empty `next_cursor` means \"this is the last page\".\n\nThe cursor format is an implementation detail; don't parse or construct it yourself.\n\n## Request size limits\n\nThe request body is limited to **1 MiB** for all `/v1/api/*`, except `POST /v1/api/knowledge`, where it is **5 MiB**. Exceeding it → `413` with the code `payload_too_large`. In addition: `message` is up to 8000 characters, `session_id` up to 128 characters (otherwise `400`).\n\n## Outgoing webhooks: verifying the signature\n\nIf a webhook URL is configured for the agent, we send a `POST` to it on three handoff-to-a-human events: `escalated`, `visitor_message` and `resolved`. The body schema and examples are in the **Webhooks** section of this reference.\n\nEvery delivery is signed:\n\n```\nX-YouSelfBot-Timestamp: 1753600000\nX-YouSelfBot-Signature: sha256=<hex>\n```\n\nThe signature is `HMAC-SHA256(secret, \"<timestamp>.<raw request body>\")`, in hex. The agent's secret is in the dashboard (the `handoff_webhook_secret` field of the agent's config); it starts with `whsec_`.\n\nHow to verify:\n\n1. Compute the HMAC over the string `timestamp + \".\" + raw_body` (with the raw body, before JSON parsing).\n2. Compare it with `X-YouSelfBot-Signature` (without the `sha256=` prefix) **in constant time** (`hmac.compare_digest`, `crypto.timingSafeEqual`).\n3. Reject deliveries older than a few minutes, so a signed request can't be replayed later.\n\n```python\nimport hashlib, hmac, time\n\ndef verify(raw_body: bytes, headers, secret: str, tolerance=300) -> bool:\n    ts = headers.get(\"X-YouSelfBot-Timestamp\", \"\")\n    got = headers.get(\"X-YouSelfBot-Signature\", \"\").removeprefix(\"sha256=\")\n    if not ts.isdigit() or abs(time.time() - int(ts)) > tolerance:\n        return False                       # stale delivery, reject it\n    mac = hmac.new(secret.encode(), ts.encode() + b\".\" + raw_body, hashlib.sha256)\n    return hmac.compare_digest(mac.hexdigest(), got)\n```\n\nWe retry a failed delivery (5xx or a network error) three times: after 1 s, 5 s and 25 s. So your handler must be **idempotent**: the same event may arrive twice. A `4xx` response is considered final and is not retried. A delivery gets 5 seconds: respond `200` right away and do the work afterwards.\n\nThe URL must be public: we deliberately don't make requests to private networks (SSRF protection).\n\n## Incoming webhook: waking the agent\n\nThe opposite direction. You create a trigger of type `webhook` in the dashboard and get the URL `POST /v1/hooks/{triggerID}` and a secret (it is shown **exactly once**, on creation). From then on any system of yours can wake the agent by signing the body with that secret:\n\n```\nX-Hook-Signature: sha256=<hex HMAC-SHA256(secret, body)>\n```\n\nNote: here **only the body** is signed, without a timestamp, unlike the outgoing webhooks above. Details, the `sync`/`async` modes and examples are in the **Triggers** section.\n\n## Verifying the visitor's identity\n\nWe don't verify the `user_token` field: it is meant for your own API. The widget runs in the visitor's browser and the request body is put together by the page, so any value in it can be arbitrary. That is exactly why `user_token` can't be used to grant extra rights.\n\nIf you want a SPECIFIC visitor to have access to actions marked \"admin only\", your **server** confirms their identity with a secret that we share with you. The bot's secret is in the dashboard, on the \"Actions\" tab (the `visitor_identity_secret` field of the bot's config). It must stay on your server and never end up in a browser, a page or a mobile app.\n\nThe confirmation is a string of three parts separated by dots:\n\n```\nv1.<data in base64url>.<HMAC-SHA256 in hex>\n```\n\nThe **data** is JSON with four fields:\n\n| Field | What it is |\n| --- | --- |\n| `user` | who this is: the same user identifier you pass in `user_token` |\n| `role` | `admin` for an administrator; anything else means a regular visitor |\n| `bot` | the id of the bot the confirmation is issued for |\n| `exp` | the moment until which it is valid (Unix seconds) |\n\nThe **signature** is `HMAC-SHA256(secret, \"v1.\" + <data in base64url>)`, in hex. The whole string is signed together with the version prefix; base64url without `=` padding.\n\nExample (Python):\n\n```python\nimport base64, hashlib, hmac, json, time\n\nSECRET = \"idsec_…\"          # from the dashboard; server-side only\nBOT    = \"bot_…\"\n\ndef confirm(user_id: str, role: str = \"admin\", ttl: int = 300) -> str:\n    data = {\"user\": user_id, \"role\": role, \"bot\": BOT, \"exp\": int(time.time()) + ttl}\n    payload = base64.urlsafe_b64encode(json.dumps(data).encode()).rstrip(b\"=\").decode()\n    signed = \"v1.\" + payload\n    sig = hmac.new(SECRET.encode(), signed.encode(), hashlib.sha256).hexdigest()\n    return signed + \".\" + sig\n```\n\nHand the finished string to your page and pass it in the `user_auth` field of every message.\n\nNo server of your own? You can still try a restricted action: in the dashboard's test chat you are already confirmed as an administrator of that very bot.\n\nWorth knowing:\n\n* **An expiry is required and limited.** The maximum is **24 hours**; a confirmation without `exp`, or with an expired or too distant `exp`, is not accepted. The confirmation sits in the browser, so whoever copies it can use it until it expires; that's why you should issue short-lived ones (a few minutes) and refresh them.\n* **Bound to the bot.** A confirmation issued for one bot doesn't work for another, even within your own dashboard.\n* **There is no error.** A missing, corrupted, expired or foreign confirmation doesn't interrupt the conversation: the visitor simply stays a regular one. That way a site without this setup works as before.\n* **`user` from the confirmation takes priority** over the `user_token` field: a page can't keep someone else's confirmation and substitute its own identifier.\n* **When the secret changes, previous confirmations stop working.** Plan secret rotation for a time when that is acceptable.\n\n\n## Request identifier\n\nEvery response carries the `X-Request-Id` header: a short identifier of that particular request. It is present on both successful responses and errors.\n\n* Store it in your logs next to your own record of the call. If you ever need to contact support, this identifier points straight to the right entry in our logs; without it the search goes by time and description, which takes longer.\n* You can send your own `X-Request-Id` in the request; we then use it instead of ours, and a single identifier runs end to end through your systems and ours. The value must be short (up to 64 characters) and consist of Latin letters, digits and `-` `_` `.` `:`; anything else is discarded and we generate our own.\n\n## Versioning\n\n* The `/v1` path prefix fixes the contract. As long as it is in this spec, it works.\n* Within `/v1` changes are only **additive**: new endpoints, new fields in responses and new optional fields in requests are added, and new `code` and `status` values appear. Existing fields are not renamed, don't change type and don't disappear.\n* So your client **must ignore unknown fields** and tolerate unknown enum values (for example, a new `code`) rather than crash on them. Fields are added to this spec without notice; that is not a breaking change.\n* An incompatible change = a new prefix (`/v2`) that runs **in parallel** with `/v1`; there will be no automatic switchover.\n* Deprecation: at least **6 months** of notice: an email to key owners, a `deprecated` mark in this spec and `Deprecation` and `Sunset` headers in the responses of the affected endpoints.\n* The current machine-readable version of the contract is always here: `GET https://api.youselfbot.com/v1/openapi.json`. The document version is in the `info.version` field."
 },
 "servers": [
  {
   "url": "https://api.youselfbot.com",
   "description": "YouSelfBot API"
  }
 ],
 "security": [
  {
   "apiKeyAuth": []
  }
 ],
 "tags": [
  {
   "name": "Chat",
   "description": "Dialog with the bot"
  },
  {
   "name": "Handoff",
   "description": "Handing the conversation to a live operator"
  },
  {
   "name": "Knowledge",
   "description": "Training the bot's knowledge base"
  },
  {
   "name": "Operator",
   "description": "Operator work through your own backend (interop)"
  },
  {
   "name": "Admin",
   "description": "Service endpoints for filling the knowledge base (same secret key)"
  },
  {
   "name": "Triggers",
   "description": "Incoming webhook: wake the agent from your own system"
  },
  {
   "name": "Dashboard · Agents",
   "description": "Creating agents, settings, keys, statistics"
  },
  {
   "name": "Dashboard · Agent flow",
   "description": "The agent's graph as data: applying with a diff, version history."
  },
  {
   "name": "Dashboard · Triggers",
   "description": "Schedule, webhooks, polling; runs and agent state"
  },
  {
   "name": "Dashboard · Knowledge",
   "description": "Knowledge base sources: texts, sites, files, media"
  },
  {
   "name": "Dashboard · Actions",
   "description": "The agent's HTTP actions: custom ones and ones imported from documentation"
  },
  {
   "name": "Dashboard · Requests",
   "description": "Operator queue: conversations, replies, closing"
  },
  {
   "name": "Dashboard · Connections",
   "description": "Telegram for operators, external developer"
  },
  {
   "name": "Dashboard · Team",
   "description": "Workspace members, invitations, roles"
  },
  {
   "name": "Authentication",
   "description": "Sign-up, login, sessions, password"
  },
  {
   "name": "Billing",
   "description": "Plans, credit packs, payment, subscription"
  },
  {
   "name": "Widget",
   "description": "Public calls from the visitor's browser (pk_ key)"
  },
  {
   "name": "Service",
   "description": "Probes, version, spec, media files"
  },
  {
   "name": "Dashboard · Channels",
   "description": "Where conversations come from: Telegram, your own messenger via the API"
  },
  {
   "name": "Dashboard · Builder",
   "description": "The assistant that builds an agent for you: it asks about the task, creates the agent, writes its personality, fills it with knowledge and connects a channel. It performs every action with the same calls you would make by hand, with the same role check and plan limit."
  },
  {
   "name": "Dashboard · What the agent doesn't know",
   "description": "Questions the agent couldn't find an answer to in its materials."
  },
  {
   "name": "Dashboard · Product catalog",
   "description": "Shop products from a feed (YML price list or Google Merchant): connect a link, find the feed on the site automatically, re-read it now, search the products. The assistant searches this catalog by itself as soon as it has products."
  },
  {
   "name": "Dashboard · Calendar",
   "description": "The owner's calendar the agent checks against: a secret iCal address (read only) or CalDAV with an app password (read and write). The link and the password come in here and are never returned."
  },
  {
   "name": "Dashboard · Long tasks",
   "description": "Agent work over hours and days: a goal, scheduled passes, a report and result cards."
  },
  {
   "name": "Dashboard · Agent cards",
   "description": "The agent's notebook: card sets it keeps between runs (objects found, contacts, metrics). View, correct, discard, export as a table."
  },
  {
   "name": "Dashboard · Deferred work",
   "description": "Runs the agent promised to do later (\"I'll check and get back to you\")."
  },
  {
   "name": "Dashboard · Changes",
   "description": "The agent's change log, with undo."
  },
  {
   "name": "Dashboard · Agent questions",
   "description": "Questions the agent asked the owner mid-work, and the answers to them."
  },
  {
   "name": "Dashboard · Approvals",
   "description": "Actions the agent submitted to a human for approval before running them."
  },
  {
   "name": "Dashboard · Incidents",
   "description": "What broke in the agent and what to do about it."
  },
  {
   "name": "Dashboard · Secrets",
   "description": "The agent's key store: write and remove; values can't be read back."
  },
  {
   "name": "Dashboard · Stop list",
   "description": "Whom the agent doesn't message or call."
  },
  {
   "name": "Dashboard · Connected accounts",
   "description": "The agent's access to connected accounts (OAuth): Google, email, calendar."
  },
  {
   "name": "Dashboard · Shop",
   "description": "Whether the shop consultant sells, and what to add to the range: the chat window funnel and shopper queries that found nothing in the catalog. Counters only: no names, conversation text or page URLs."
  },
  {
   "name": "Dashboard · Owner memory",
   "description": "What the agent remembers about its owner: notes it writes itself in the conversation with the owner, which the owner sees and edits."
  },
  {
   "name": "Dashboard · Agent files",
   "description": "The agent's persistent folder: files it keeps between runs (a log, notes, intermediate data, its own scripts). The owner sees them, downloads and deletes them."
  },
  {
   "name": "Dashboard · Skills",
   "description": "The agent's skills: instructions for specific tasks in SKILL.md format. The agent loads the text itself when the task fits; it proposes drafts only in the conversation with the owner, and they take effect after the owner agrees."
  },
  {
   "name": "Dashboard · Payments",
   "description": "Payment in the conversation: the agent gives the shopper a payment link through the owner's LiqPay and knows whether it has been paid. The amount comes from the catalog, a verified order or the price list, not from the shopper's words."
  },
  {
   "name": "Dashboard · Access for other agents",
   "description": "Keys that other agents and programs (Claude, Cursor, another bot) use to call this agent as a tool, and the agent card for other agents. A key is shown once; each one is revoked separately."
  },
  {
   "name": "Agent for other agents",
   "description": "The agent itself as an MCP server and as an A2A agent: an external program asks it questions, gives it a long task and reads its description. Access is with an agent access key (`ak_…`); the caller always has visitor rights."
  },
  {
   "name": "Dashboard · Agent transfer",
   "description": "Hand a single agent over to another person, without giving away the rest or inviting them to your team. The workspace owner enters the recipient's email; the recipient sees the request in their dashboard and either accepts the agent into their own workspace or declines. The window's publishable key (`pk_`) stays the same."
  },
  {
   "name": "Dashboard · Training",
   "description": "Training mode: a human sees every agent reply to a customer first, and sends it as is, corrects it or answers themselves, and can write what was wrong. Actions with external consequences wait together with the reply. The agent learns from the decisions: for a similar question it takes past corrections as examples, and from similar corrections the platform puts together suggestions for the owner. Enabled with the `training` field in the agent settings; off by default."
  },
  {
   "name": "Dashboard · Search base",
   "description": "The source registry, results, saved searches, the publication log and the agent's search quality. The cards themselves (sources, results, contacts, publications) live in the notebook and are read through its endpoint with field conditions; this section holds the actions on them."
  },
  {
   "name": "Dashboard · Notifications",
   "description": "Where customers' requests for a human and the owner's digests arrive: a linked chat in a messenger, Telegram support, email. The rules themselves (quiet hours at night, reminders, the digest schedule) are agent settings, `PATCH …/config`."
  },
  {
   "name": "Platform",
   "description": "For the owner of the platform itself: a summary across all workspaces."
  }
 ],
 "paths": {
  "/v1/platform/log": {
   "get": {
    "tags": [
     "Platform"
    ],
    "summary": "Application log of this instance",
    "description": "The latest log entries (slog) of this server instance, from memory: up to 8000, since it started; a restart clears the log, and each instance has its own (`instance`). Secrets in messages and fields are hidden. Returns the newest `limit` matching entries in chronological order; `after` reads only the new ones. Visible only to a platform person; for everyone else this address doesn't exist (404).",
    "security": [
     {
      "sessionCookie": []
     }
    ],
    "parameters": [
     {
      "name": "after",
      "in": "query",
      "required": false,
      "schema": {
       "type": "integer",
       "minimum": 0
      },
      "description": "Only entries with a `seq` greater than this one (the cursor is `last` from the previous response). A cursor greater than the latest number (the instance restarted) is treated as no cursor."
     },
     {
      "name": "level",
      "in": "query",
      "required": false,
      "schema": {
       "type": "string",
       "enum": [
        "debug",
        "info",
        "warn",
        "error"
       ]
      },
      "description": "Lowest level (warn: warnings and errors)."
     },
     {
      "name": "q",
      "in": "query",
      "required": false,
      "schema": {
       "type": "string",
       "maxLength": 200
      },
      "description": "Substring in the message or fields, case-insensitive."
     },
     {
      "name": "limit",
      "in": "query",
      "required": false,
      "schema": {
       "type": "integer",
       "minimum": 1,
       "maximum": 2000
      },
      "description": "How many entries (default 500)."
     }
    ],
    "responses": {
     "200": {
      "description": "Log entries.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/PlatformLog"
        }
       }
      }
     },
     "400": {
      "description": "Invalid filter parameter.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "description": "No valid session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "Request made with a key, not a human session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "The person isn't on the platform list (or this build doesn't include it).",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/platform/db/tables": {
   "get": {
    "tags": [
     "Platform"
    ],
    "summary": "Database tables",
    "description": "Tables of the working database (current schema) with estimated row counts and sizes. Visible only to a platform person (404 for everyone else).",
    "security": [
     {
      "sessionCookie": []
     }
    ],
    "responses": {
     "200": {
      "description": "List of tables.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/DBTables"
        }
       }
      }
     },
     "401": {
      "description": "No valid session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "Request made with a key, not a human session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "The person isn't on the platform list (or this build doesn't include it).",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "503": {
      "description": "The database didn't respond.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/platform/db/tables/{name}": {
   "get": {
    "tags": [
     "Platform"
    ],
    "summary": "Table page",
    "description": "A page of table rows, in a READ ONLY transaction with an 8 s limit. Values are text, as Postgres shows them (NULL is `null`); a cell is up to 2000 characters (longer ones are listed in `clipped`). Secret columns (`masked`) are shown as `***`; cells whose text had a secret hidden are listed in `hidden`. The exact row count is computed with a 3 s limit (if it doesn't finish, `total: -1`). Without `sort`, rows are ordered by primary key.",
    "security": [
     {
      "sessionCookie": []
     }
    ],
    "parameters": [
     {
      "name": "name",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Table name."
     },
     {
      "name": "offset",
      "in": "query",
      "required": false,
      "schema": {
       "type": "integer",
       "minimum": 0
      }
     },
     {
      "name": "limit",
      "in": "query",
      "required": false,
      "schema": {
       "type": "integer",
       "minimum": 1,
       "maximum": 500
      },
      "description": "Rows per page (default 50)."
     },
     {
      "name": "sort",
      "in": "query",
      "required": false,
      "schema": {
       "type": "string"
      },
      "description": "Sort column; `-column` for reverse order."
     }
    ],
    "responses": {
     "200": {
      "description": "Table page.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/DBPage"
        }
       }
      }
     },
     "400": {
      "description": "Invalid parameter or no such column.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "description": "No valid session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "Request made with a key, not a human session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "No such table, or the person isn't on the platform list.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "429": {
      "description": "The console is already running several queries.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "503": {
      "description": "The database didn't respond.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/platform/db/query": {
   "post": {
    "tags": [
     "Platform"
    ],
    "summary": "Database query from the console",
    "description": "A single SQL statement against the PRODUCTION database. By default (`write: false`) it runs in a READ ONLY transaction that is rolled back, with an 8 s limit: it cannot change data. With `write: true` it is a normal transaction with COMMIT and a 20 s limit: anything the database role allows is permitted. Transaction and session control (BEGIN, COMMIT, SET, RESET…) is rejected; the database doesn't accept a second statement in the same request. The response holds up to 500 rows (`truncated`), a cell up to 2000 characters; secret columns are masked. An error from the database itself (syntax, permissions, time limit, a write in READ ONLY: `sqlstate` 25006) is a 200 with `error`. Every query goes to the platform people's action log (`db_query`) and to the server log.",
    "security": [
     {
      "sessionCookie": []
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "required": [
         "sql"
        ],
        "properties": {
         "sql": {
          "type": "string",
          "maxLength": 20000
         },
         "write": {
          "type": "boolean",
          "description": "Allow data changes (COMMIT)."
         }
        }
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Console response: rows or a database error.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/DBQueryResult"
        }
       }
      }
     },
     "400": {
      "description": "Empty query, or transaction and session control.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "description": "No valid session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "Request made with a key, not a human session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "The person isn't on the platform list (or this build doesn't include it).",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "413": {
      "description": "Query too long.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "429": {
      "description": "The console is already running several queries.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "503": {
      "description": "The database didn't respond.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/platform/db/cell": {
   "post": {
    "tags": [
     "Platform"
    ],
    "summary": "Change a single cell",
    "description": "A new value for one column of one row, found by primary key. `old` is the value the person saw (as text, `null` for NULL): if the database already holds something else, the answer is a 409 refusal rather than overwriting someone else's change. The database itself casts the value to the column type (wrong type: 422 with its message). The primary key, secret columns, values with hidden secrets and clipped values can't be edited. Exactly one row, in a transaction with a 20 s limit. Every edit goes to the action log (`db_cell`) and to the server log.",
    "security": [
     {
      "sessionCookie": []
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "required": [
         "table",
         "pk",
         "column",
         "old",
         "new"
        ],
        "properties": {
         "table": {
          "type": "string"
         },
         "pk": {
          "type": "object",
          "additionalProperties": {
           "type": "string"
          },
          "description": "Primary key value as text: {column: value}."
         },
         "column": {
          "type": "string"
         },
         "old": {
          "oneOf": [
           {
            "type": "string"
           },
           {
            "type": "null"
           }
          ]
         },
         "new": {
          "oneOf": [
           {
            "type": "string"
           },
           {
            "type": "null"
           }
          ]
         }
        }
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Saved.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/DBCellResult"
        }
       }
      }
     },
     "400": {
      "description": "This cell can't be changed from the viewer.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "description": "No valid session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "Request made with a key, not a human session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "The person isn't on the platform list (or this build doesn't include it).",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "409": {
      "description": "The value is already different, or the row is gone.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "422": {
      "description": "The database didn't accept the value.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "429": {
      "description": "The console is already running several queries.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "503": {
      "description": "The database didn't respond.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/docs": {
   "get": {
    "tags": [
     "Service"
    ],
    "summary": "API reference",
    "description": "This page. The language of the page and of the reference in it follows `lang` or `Accept-Language`, as in `GET /v1/openapi.json`.",
    "security": [],
    "parameters": [
     {
      "name": "lang",
      "in": "query",
      "required": false,
      "description": "Language of the descriptions: `en` or `uk`. Takes precedence over `Accept-Language`.",
      "schema": {
       "type": "string",
       "enum": [
        "uk",
        "en"
       ]
      }
     },
     {
      "name": "Accept-Language",
      "in": "header",
      "required": false,
      "description": "Without `lang`: `en…` gives English, anything else Ukrainian.",
      "schema": {
       "type": "string"
      }
     }
    ],
    "responses": {
     "200": {
      "description": "HTML."
     }
    }
   }
  },
  "/healthz": {
   "get": {
    "tags": [
     "Service"
    ],
    "summary": "Liveness probe",
    "description": "Whether the process is alive. It deliberately touches nothing external: a probe that failed together with the database would restart all replicas at once and turn a recoverable outage into a total one.",
    "security": [],
    "responses": {
     "200": {
      "description": "Alive.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "status": {
           "type": "string",
           "example": "ok"
          }
         }
        }
       }
      }
     }
    }
   }
  },
  "/media/{id}": {
   "get": {
    "tags": [
     "Service"
    ],
    "summary": "Media file",
    "description": "Serves an uploaded image by its permanent link.",
    "security": [],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      }
     }
    ],
    "responses": {
     "200": {
      "description": "The file."
     },
     "404": {
      "description": "No such file.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/wordpress-plugin.zip": {
   "get": {
    "tags": [
     "Service"
    ],
    "summary": "WordPress plugin as an archive",
    "description": "A plugin that puts the chat window on a WordPress site without editing the theme. Open and keyless: it is installed **before** the owner has any key at all.\n\nThe archive is built from the code of this same build, so it can't drift from the source: a new deploy means a new file. Inside is a single folder `youselfbot-chatbot/`, exactly the form in which WordPress accepts an upload via \"Plugins → Add New → Upload Plugin\".\n\nIn the plugin settings an empty field means \"take it from the dashboard\": a filled-in value goes in as a widget attribute and **overrides** the bot's settings.",
    "security": [],
    "responses": {
     "200": {
      "description": "ZIP archive of the plugin.",
      "content": {
       "application/zip": {
        "schema": {
         "type": "string",
         "format": "binary"
        }
       }
      }
     }
    }
   }
  },
  "/readyz": {
   "get": {
    "tags": [
     "Service"
    ],
    "summary": "Readiness probe",
    "description": "Whether the process can serve requests. Separate from the liveness probe: otherwise an unavailable store would only show up as an error on someone's login.",
    "security": [],
    "responses": {
     "200": {
      "description": "Ready."
     },
     "503": {
      "description": "Not ready.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/admin/scrape": {
   "post": {
    "tags": [
     "Admin"
    ],
    "summary": "Index a site into the knowledge base",
    "description": "Scans the given site and indexes its text into the bot's knowledge base. The scan runs **in the background**: the `202` response comes back immediately, while crawling the pages can take tens of seconds or minutes.\n\nThe endpoint doesn't report completion and has no status of its own; progress is visible in the YouSelfBot dashboard. To make sure the text has been indexed, check `GET /v1/api/knowledge` a few minutes later.\n\nOnly one scan can run for a bot at a time: a repeat request while the previous one is running returns `409`. Rate limits don't apply to `/v1/admin/*`, so there is no `429` here.\n\nPrivate and internal addresses are blocked (SSRF protection); an unreachable site, a site without text or a blocked crawl don't return an HTTP error: they simply add nothing to the knowledge base.",
    "operationId": "adminScrape",
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "required": [
         "url"
        ],
        "properties": {
         "url": {
          "type": "string",
          "format": "uri",
          "description": "Public URL of the page or site."
         },
         "max_pages": {
          "type": "integer",
          "minimum": 1,
          "maximum": 500,
          "default": 1,
          "description": "How many pages of the site to read in this pass. Less than 1 → 1; more than the plan ceiling → the plan ceiling (the plan's `max_site_pages`: Free 50, Starter 150, Pro 300, Business 500). The ceiling also caps all the site's pages in the knowledge base together: once there are that many, new ones aren't added, and the summary says so. With a number greater than 1, pages are taken from the site map (sitemap.xml) and by following links."
         },
         "refresh_days": {
          "type": "integer",
          "minimum": 0,
          "maximum": 180,
          "description": "How often, in days, to re-read what was read. Not set: once every 7 days; 0: never re-read."
         }
        }
       },
       "examples": {
        "singlePage": {
         "summary": "A single page",
         "value": {
          "url": "https://example.com/faq"
         }
        },
        "crawl": {
         "summary": "Crawl of up to 20 pages",
         "value": {
          "url": "https://example.com",
          "max_pages": 20
         }
        }
       }
      }
     }
    },
    "responses": {
     "202": {
      "description": "The scan has started in the background.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "required": [
          "status",
          "url"
         ],
         "properties": {
          "status": {
           "type": "string",
           "const": "scanning"
          },
          "url": {
           "type": "string"
          },
          "refresh_days": {
           "type": "integer",
           "description": "What the schedule will be after a successful read: once every this many days. 0: won't be re-read."
          }
         }
        },
        "examples": {
         "started": {
          "value": {
           "status": "scanning",
           "url": "https://example.com/faq"
          }
         }
        }
       }
      }
     },
     "400": {
      "$ref": "#/components/responses/BadRequest"
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "409": {
      "description": "A scan of this bot is already running. Wait for it to finish.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "examples": {
         "default": {
          "value": {
           "error": "scanning of this bot is already in progress",
           "code": "conflict"
          }
         }
        }
       }
      }
     },
     "413": {
      "$ref": "#/components/responses/PayloadTooLarge"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/v1/admin/sources": {
   "post": {
    "tags": [
     "Admin"
    ],
    "summary": "Train the knowledge base (service alias)",
    "description": "Technically identical to `POST /v1/api/knowledge`: the same secret key, the same body, the same response. Kept for compatibility with older integrations.\n\n**For new integrations use `POST /v1/api/knowledge`**: that is where the rest of the knowledge base operations live (list, read, delete).\n\nThere is only one difference: rate limits don't apply to `/v1/admin/*`, so there is no `429` here.",
    "operationId": "adminAddSource",
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "required": [
         "text"
        ],
        "properties": {
         "source_id": {
          "type": "string",
          "description": "Stable fragment ID (for updates). Optional: if empty, the server derives it from the CONTENT, so the same text for the same agent is the same source, and a repeated request leaves no copy."
         },
         "title": {
          "type": "string",
          "description": "Source title."
         },
         "text": {
          "type": "string",
          "description": "The text the bot should learn."
         }
        }
       },
       "examples": {
        "faq": {
         "value": {
          "title": "Warranty",
          "text": "24-month warranty on all equipment."
         }
        }
       }
      }
     }
    },
    "responses": {
     "202": {
      "description": "The source has been accepted for indexing.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "required": [
          "status",
          "source_id"
         ],
         "properties": {
          "status": {
           "type": "string",
           "const": "indexed"
          },
          "source_id": {
           "type": "string"
          },
          "existed": {
           "type": "boolean",
           "description": "`true`: this agent already had a source with exactly the same text; nothing was written, and `source_id` names the existing one. Only when `source_id` in the request is empty."
          }
         }
        },
        "examples": {
         "accepted": {
          "value": {
           "status": "indexed",
           "source_id": "a3f19c7b21"
          }
         }
        }
       }
      }
     },
     "400": {
      "$ref": "#/components/responses/BadRequest"
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "413": {
      "description": "The request body is too large (`payload_too_large`) or the text is too large for a single source (`knowledge_too_large`): a retry won't succeed; splitting it into several topics will help.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "500": {
      "$ref": "#/components/responses/InternalError"
     },
     "503": {
      "description": "The knowledge store isn't accepting writes right now. `knowledge_store_busy`: overloaded; the server has already retried the write several times, it should go through within a minute. `service_unavailable`: a failure or refusal on the platform's side.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/v1/api/chat": {
   "post": {
    "tags": [
     "Chat"
    ],
    "summary": "Send a message to the bot",
    "description": "One message of the dialog. The bot's reply is returned in full (no streaming).\n\nKeep `session_id` the same within one conversation: that's how the bot remembers the context. If you don't pass it, the server generates a new one and returns it in the response.\n\nThe `200` response has **three different modes**, and all of them come with the same status:\n\n1. **A regular bot reply**: `answer` and `session_id` are present.\n2. **A human is handling the conversation**: `\"handoff\": true`. The bot stays silent on purpose. `answer` contains the escalation confirmation (`\"I'm passing you to an operator…\"`) or an **empty string** if the operator is already connected and the message was simply forwarded to them. Don't show an empty `answer` as a message. From here on, poll `GET /v1/api/messages`.\n3. **The monthly conversation limit is exhausted**: `\"quota_exceeded\": true`, and `answer` contains placeholder text for the customer. New conversations don't start until the next period or a top-up; conversations already in progress keep working.\n\nBoth flags are absent from a regular response, so check them as `resp.handoff === true`.\n\n**`notice`.** If the response contains `\"notice\": \"outage\"`, the text in `answer` is not a bot reply but a service message about a failure or a limit (e.g. the knowledge base is unavailable). Show it separately from replies and don't offer to rate it: otherwise the customer rates an outage, and you get feedback about a reply that never happened.\n\n**Overload.** If the AI backend is busy or the run didn't finish in time, you get `503` with `code: \"llm_overloaded\"` and a `Retry-After` header; unlike `llm_unavailable`, such a request is worth retrying.\n\n**Idempotency.** Add the `Idempotency-Key` header and a retry after a timeout won't perform the action a second time: the stored response of the first attempt is returned with `Idempotency-Replayed: true` (the key lives for 24 hours).",
    "operationId": "chat",
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/ChatRequest"
       },
       "examples": {
        "simple": {
         "summary": "A simple message",
         "value": {
          "session_id": "3f6c1b9e-7f42-4d2a-9a6f-0d5b1f0b21c7",
          "message": "What are your opening hours?"
         }
        },
        "withContext": {
         "summary": "With page context and a customer identifier",
         "value": {
          "session_id": "3f6c1b9e-7f42-4d2a-9a6f-0d5b1f0b21c7",
          "message": "Is this model available in blue?",
          "user_token": "crm-customer-8891",
          "page_context": "Product page: Aurora X2 coffee machine, 8,490 UAH, in stock"
         }
        },
        "escalate": {
         "summary": "\"Operator\" button: straight into the queue for a human",
         "value": {
          "session_id": "3f6c1b9e-7f42-4d2a-9a6f-0d5b1f0b21c7",
          "message": "I want to talk to a person",
          "escalate": true
         }
        }
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "The bot's reply, an escalation confirmation (`handoff`) or an exhausted limit (`quota_exceeded`).",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/ChatResponse"
        },
        "examples": {
         "answer": {
          "summary": "A regular bot reply",
          "value": {
           "answer": "We're open 9:00 to 18:00, Mon–Fri.",
           "session_id": "3f6c1b9e-7f42-4d2a-9a6f-0d5b1f0b21c7"
          }
         },
         "handoffQueued": {
          "summary": "Escalation: the customer has been queued",
          "value": {
           "answer": "I'm passing you to an operator. Please wait — they'll reply in this chat.",
           "session_id": "3f6c1b9e-7f42-4d2a-9a6f-0d5b1f0b21c7",
           "handoff": true
          }
         },
         "handoffLive": {
          "summary": "The operator is already connected: the message was forwarded, nothing to show",
          "value": {
           "answer": "",
           "session_id": "3f6c1b9e-7f42-4d2a-9a6f-0d5b1f0b21c7",
           "handoff": true
          }
         },
         "quotaExceeded": {
          "summary": "The monthly conversation limit is exhausted",
          "value": {
           "answer": "The assistant is temporarily unavailable. Please try again later.",
           "session_id": "3f6c1b9e-7f42-4d2a-9a6f-0d5b1f0b21c7",
           "quota_exceeded": true
          }
         }
        }
       }
      },
      "headers": {
       "Idempotency-Replayed": {
        "schema": {
         "type": "string",
         "enum": [
          "true"
         ]
        },
        "description": "Present only when this is a replayed response to a previous request with the same `Idempotency-Key` (the action was NOT performed again)."
       }
      }
     },
     "400": {
      "$ref": "#/components/responses/BadRequest"
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "409": {
      "$ref": "#/components/responses/IdempotencyConflict"
     },
     "413": {
      "$ref": "#/components/responses/PayloadTooLarge"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     },
     "500": {
      "$ref": "#/components/responses/InternalError"
     },
     "503": {
      "description": "The AI backend is unavailable (`llm_unavailable`: the key or funds; the owner needs to act) or overloaded (`llm_overloaded`: worth retrying after `Retry-After`). Tell them apart by `code`.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "examples": {
         "unavailable": {
          "summary": "Invalid key or exhausted funds",
          "value": {
           "error": "The assistant is temporarily unavailable. We already know about it — please try again a little later.",
           "code": "llm_unavailable",
           "session_id": "3f6c1b9e-7f42-4d2a-9a6f-0d5b1f0b21c7"
          }
         },
         "overloaded": {
          "summary": "Overload: retry after Retry-After",
          "value": {
           "error": "There are too many requests right now, and the answer did not arrive in time. Please send your message again.",
           "code": "llm_overloaded",
           "retry_after": 20,
           "session_id": "3f6c1b9e-7f42-4d2a-9a6f-0d5b1f0b21c7"
          }
         }
        }
       }
      },
      "headers": {
       "Retry-After": {
        "description": "How many seconds to wait before retrying. Comes only with `llm_overloaded`.",
        "schema": {
         "type": "integer"
        }
       }
      }
     }
    },
    "parameters": [
     {
      "$ref": "#/components/parameters/IdempotencyKey"
     }
    ]
   }
  },
  "/v1/api/chat/stream": {
   "post": {
    "tags": [
     "Chat"
    ],
    "summary": "Send a message (streaming response, SSE)",
    "description": "Same as `POST /v1/api/chat`, but the response is streamed via Server-Sent Events (`Content-Type: text/event-stream`). Each line looks like `data: <json>` and is followed by an empty line.\n\n**Frame types** (tell them apart by which field is present):\n\n| Frame | Fields | Meaning |\n| --- | --- | --- |\n| chunk | `delta`, sometimes `notice` | The next piece of text. Append it to what you've already received. |\n| error | `error`, sometimes `code` and `retry_after` | Generation broke off. It arrives **after** the headers, so the HTTP status stays `200`. |\n| end | `done`, `session_id`, `handoff`, `quota_exceeded`, sometimes `notice` | The last frame. Sent **always**, including after an error frame. |\n\n```\ndata: {\"delta\":\"We're open \"}\n\ndata: {\"delta\":\"9:00 to 18:00.\"}\n\ndata: {\"done\":true,\"session_id\":\"3f6c1b9e-7f42-4d2a-9a6f-0d5b1f0b21c7\",\"handoff\":false,\"quota_exceeded\":false}\n\n```\n\nAn error frame comes in three forms:\n\n* `{\"error\":\"The assistant is temporarily unavailable…\",\"code\":\"llm_unavailable\"}`: the AI backend is unavailable (the key or funds); retrying won't help;\n* `{\"error\":\"There are too many requests right now…\",\"code\":\"llm_overloaded\",\"retry_after\":20}`: overload or the run's time ran out; retry after `retry_after` seconds;\n* `{\"error\":\"internal error\"}`: an internal error, **without** the `code` field.\n\nSo check exactly `if (frame.error)`, not `frame.code`.\n\n### Service messages (`notice`)\n\nA frame with `\"notice\": \"outage\"` means the text of this run is not a bot reply but a message about a failure or an exhausted limit. The text still arrives in `delta` (clients written before the field appeared work as before), and the marker is repeated in the end frame, because some of these messages only become known after the run finishes. Show them separately from replies and without ratings.\n\n### Differences from `/v1/api/chat`\n\nEscalation and an exhausted limit arrive as a regular `delta` frame (and when the operator is already connected, no `delta` arrives at all, only `done`). Read the run state from the end frame: `handoff` and `quota_exceeded` there are the same as in `POST /v1/api/chat`.\n\nAuthentication, limit and validation errors are returned **before** the stream starts, as regular JSON with the corresponding status.\n\n**Idempotency.** Add the `Idempotency-Key` header and a retry after a timeout won't perform the action a second time: the stored response of the first attempt is returned with `Idempotency-Replayed: true` (the key lives for 24 hours).",
    "operationId": "chatStream",
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/ChatRequest"
       },
       "examples": {
        "simple": {
         "summary": "A simple message",
         "value": {
          "session_id": "3f6c1b9e-7f42-4d2a-9a6f-0d5b1f0b21c7",
          "message": "Tell me about delivery"
         }
        }
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "A Server-Sent Events stream. The schema below describes **one frame**, i.e. the JSON in the `data:` field; physically the response body is a sequence of such frames.",
      "content": {
       "text/event-stream": {
        "schema": {
         "$ref": "#/components/schemas/StreamFrame"
        }
       }
      },
      "headers": {
       "Idempotency-Replayed": {
        "schema": {
         "type": "string",
         "enum": [
          "true"
         ]
        },
        "description": "Present only when this is a replayed response to a previous request with the same `Idempotency-Key` (the action was NOT performed again)."
       }
      }
     },
     "400": {
      "$ref": "#/components/responses/BadRequest"
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "409": {
      "$ref": "#/components/responses/IdempotencyConflict"
     },
     "413": {
      "$ref": "#/components/responses/PayloadTooLarge"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    },
    "parameters": [
     {
      "$ref": "#/components/parameters/IdempotencyKey"
     }
    ]
   }
  },
  "/v1/api/handoff": {
   "post": {
    "tags": [
     "Handoff"
    ],
    "summary": "Hand the conversation to a live operator",
    "description": "Puts the session in the operator queue (status `waiting`). After that, poll `GET /v1/api/messages` to get the operator's replies and show them in your own chat.\n\n`POST /v1/api/chat` with `\"escalate\": true` and an explicit request for an operator in the customer's text do the same; this endpoint is needed when the escalation happens without a new message (for example, a \"Talk to a person\" button).\n\n**Idempotency.** Add the `Idempotency-Key` header and a retry after a timeout won't perform the action a second time: the stored response of the first attempt is returned with `Idempotency-Replayed: true` (the key lives for 24 hours).",
    "operationId": "handoff",
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "required": [
         "session_id"
        ],
        "properties": {
         "session_id": {
          "$ref": "#/components/schemas/SessionID"
         }
        }
       },
       "examples": {
        "simple": {
         "value": {
          "session_id": "3f6c1b9e-7f42-4d2a-9a6f-0d5b1f0b21c7"
         }
        }
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "The session has been queued for an operator.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "status": {
           "type": "string",
           "const": "waiting"
          }
         }
        },
        "examples": {
         "queued": {
          "value": {
           "status": "waiting"
          }
         }
        }
       }
      },
      "headers": {
       "Idempotency-Replayed": {
        "schema": {
         "type": "string",
         "enum": [
          "true"
         ]
        },
        "description": "Present only when this is a replayed response to a previous request with the same `Idempotency-Key` (the action was NOT performed again)."
       }
      }
     },
     "400": {
      "$ref": "#/components/responses/BadRequest"
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "404": {
      "description": "Handoff unavailable: turned off for this bot, or the session belongs to another bot.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "examples": {
         "default": {
          "value": {
           "error": "Handing conversations to a person is turned off for this agent.",
           "code": "not_found"
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "This `session_id` already belongs to another agent (`session_taken`). You choose the conversation identifier: take an unpredictable one (a uuid), not \"user-42\": two tenants with the same string are inevitable, and one tenant's conversation would then become visible to the other's operators.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "413": {
      "$ref": "#/components/responses/PayloadTooLarge"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     },
     "500": {
      "$ref": "#/components/responses/InternalError"
     }
    },
    "parameters": [
     {
      "$ref": "#/components/parameters/IdempotencyKey"
     }
    ]
   }
  },
  "/v1/api/knowledge": {
   "post": {
    "tags": [
     "Knowledge"
    ],
    "summary": "Train the bot's knowledge base",
    "description": "Indexes arbitrary text into the bot's knowledge base (RAG). Pass a stable `source_id` to update the same fragment; without it a new one is created every time. Use it to sync FAQs, products, documentation and so on from your side.\n\n**Idempotency.** Add the `Idempotency-Key` header and a retry after a timeout won't perform the action a second time: the stored response of the first attempt is returned with `Idempotency-Replayed: true` (the key lives for 24 hours).",
    "operationId": "teachKnowledge",
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "required": [
         "text"
        ],
        "properties": {
         "source_id": {
          "type": "string",
          "description": "Stable fragment ID (for updates). Optional."
         },
         "title": {
          "type": "string",
          "description": "Source title (for references in replies)."
         },
         "text": {
          "type": "string",
          "description": "The text the bot should learn."
         }
        }
       },
       "examples": {
        "faq": {
         "summary": "A new FAQ fragment",
         "value": {
          "title": "Opening hours",
          "text": "We're open 9:00 to 18:00, Mon–Fri. On Saturday until 14:00. Sunday is a day off."
         }
        },
        "upsert": {
         "summary": "Updating an existing source by a stable id",
         "value": {
          "source_id": "faq-delivery",
          "title": "Delivery",
          "text": "We deliver with Nova Poshta in 1–2 days. Free from 2,000 UAH."
         }
        }
       }
      }
     }
    },
    "responses": {
     "202": {
      "description": "The source has been accepted for indexing. The bot's reply cache has been reset.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "required": [
          "status",
          "source_id"
         ],
         "properties": {
          "status": {
           "type": "string",
           "const": "indexed"
          },
          "source_id": {
           "type": "string",
           "description": "The `source_id` you passed, or a generated one if there was none."
          }
         }
        },
        "examples": {
         "accepted": {
          "value": {
           "status": "indexed",
           "source_id": "faq-delivery"
          }
         }
        }
       }
      },
      "headers": {
       "Idempotency-Replayed": {
        "schema": {
         "type": "string",
         "enum": [
          "true"
         ]
        },
        "description": "Present only when this is a replayed response to a previous request with the same `Idempotency-Key` (the action was NOT performed again)."
       }
      }
     },
     "400": {
      "$ref": "#/components/responses/BadRequest"
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "409": {
      "$ref": "#/components/responses/IdempotencyConflict"
     },
     "413": {
      "$ref": "#/components/responses/PayloadTooLarge"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     },
     "500": {
      "$ref": "#/components/responses/InternalError"
     }
    },
    "parameters": [
     {
      "$ref": "#/components/parameters/IdempotencyKey"
     }
    ]
   },
   "get": {
    "tags": [
     "Knowledge"
    ],
    "summary": "List knowledge base sources",
    "description": "What exactly has been indexed for this bot: the title, identifier and number of fragments of each source. Handy for reconciling your system with the bot's knowledge base before a sync.\n\n**Paginated.** The response is limited by `?limit=` (default 50, maximum 200). If `next_cursor` is non-empty, there is more data: repeat the request with `?cursor=<next_cursor>`. Without parameters you get the first page in the usual format.",
    "operationId": "listKnowledge",
    "responses": {
     "200": {
      "description": "List of sources (an empty array if the knowledge base hasn't been filled yet).",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "required": [
          "sources"
         ],
         "properties": {
          "sources": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/Source"
           }
          },
          "next_cursor": {
           "type": "string",
           "description": "Next page cursor. An empty string means there are no more pages. Pass it as `?cursor=` to get the continuation."
          }
         }
        },
        "examples": {
         "list": {
          "value": {
           "sources": [
            {
             "id": "faq-delivery",
             "title": "Delivery",
             "chunks": 2
            },
            {
             "id": "a3f19c7b21",
             "title": "Opening hours",
             "chunks": 1
            }
           ]
          }
         }
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     },
     "500": {
      "$ref": "#/components/responses/InternalError"
     }
    },
    "parameters": [
     {
      "$ref": "#/components/parameters/PageLimit"
     },
     {
      "$ref": "#/components/parameters/PageCursor"
     }
    ]
   }
  },
  "/v1/api/knowledge/{id}": {
   "get": {
    "tags": [
     "Knowledge"
    ],
    "summary": "Read a source in full",
    "description": "Returns the stored text of the source unabridged, unlike the bot's reply, which relies only on the relevant fragments.",
    "operationId": "readKnowledge",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Source ID from the list.",
      "example": "faq-delivery"
     }
    ],
    "responses": {
     "200": {
      "description": "The source.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "required": [
          "id",
          "title",
          "text"
         ],
         "properties": {
          "id": {
           "type": "string"
          },
          "title": {
           "type": "string"
          },
          "text": {
           "type": "string"
          }
         }
        },
        "examples": {
         "source": {
          "value": {
           "id": "faq-delivery",
           "title": "Delivery",
           "text": "We deliver with Nova Poshta in 1–2 days. Free from 2,000 UAH."
          }
         }
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "404": {
      "description": "Source not found, or it belongs to another bot.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "examples": {
         "default": {
          "value": {
           "error": "Source not found.",
           "code": "not_found"
          }
         }
        }
       }
      }
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   },
   "delete": {
    "tags": [
     "Knowledge"
    ],
    "summary": "Delete a source",
    "description": "Removes the source from the knowledge base and clears the cache of answers built on it.",
    "operationId": "deleteKnowledge",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Source ID.",
      "example": "faq-delivery"
     }
    ],
    "responses": {
     "200": {
      "description": "Deleted. Idempotent: deleting a nonexistent id also returns `200`.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "required": [
          "status",
          "id"
         ],
         "properties": {
          "status": {
           "type": "string",
           "const": "deleted"
          },
          "id": {
           "type": "string"
          }
         }
        },
        "examples": {
         "deleted": {
          "value": {
           "status": "deleted",
           "id": "faq-delivery"
          }
         }
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "404": {
      "description": "The knowledge base isn't available for this bot.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "examples": {
         "default": {
          "value": {
           "error": "Knowledge is unavailable.",
           "code": "not_found"
          }
         }
        }
       }
      }
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     },
     "500": {
      "$ref": "#/components/responses/InternalError"
     }
    }
   }
  },
  "/v1/api/messages": {
   "get": {
    "tags": [
     "Handoff"
    ],
    "summary": "Get new operator messages",
    "description": "Returns the live operator's messages for the session that are newer than your cursor, plus the current conversation status. Poll periodically (every 2–3 s) while `status` is `waiting` or `operator`.\n\n**Cursor.** After each response, save `next_cursor` and pass it as `?cursor=` in the next request. On the first request pass nothing — results start from the beginning of the conversation. If you don't advance the cursor, every request returns the whole history again, and messages get duplicated in your chat.\n\nAn unknown session (or another bot's session) is not an error: you get `200` with empty `messages` and `status: \"bot\"`.\n\n**Why a cursor and not a timestamp.** Millisecond timestamps aren't precise enough: if an operator sent two messages in the same millisecond, filtering by timestamp would never return the second one. `next_cursor` carries a (time, id) pair, so it never loses messages.",
    "operationId": "messages",
    "parameters": [
     {
      "name": "session_id",
      "in": "query",
      "required": true,
      "schema": {
       "$ref": "#/components/schemas/SessionID"
      },
      "description": "Conversation ID.",
      "example": "3f6c1b9e-7f42-4d2a-9a6f-0d5b1f0b21c7"
     },
     {
      "$ref": "#/components/parameters/PageCursor"
     },
     {
      "name": "limit",
      "in": "query",
      "required": false,
      "schema": {
       "type": "integer",
       "minimum": 1,
       "maximum": 200,
       "default": 200
      },
      "description": "How many messages to return. **Note:** the default here is 200, not 50 as on other paginated endpoints: a poll must return everything that piled up during the pause. Larger values are capped at 200."
     }
    ],
    "responses": {
     "200": {
      "description": "New operator messages, the conversation status, and the \"operator is typing\" flag.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "required": [
          "messages",
          "status"
         ],
         "properties": {
          "messages": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/Message"
           },
           "description": "Only OPERATOR messages newer than `after`, in chronological order."
          },
          "status": {
           "$ref": "#/components/schemas/HandoffStatus"
          },
          "operator_typing": {
           "type": "boolean",
           "description": "`true` → the operator is typing a message right now. Show \"The operator is typing…\" in your chat. The signal fades on its own after about 6 seconds, so just redraw the indicator from the value in each poll. The field is absent if handoff to a human isn't available for this agent — treat absence as `false`."
          },
          "operator_here": {
           "type": "boolean",
           "description": "`true` → the conversation is in the queue (`status: \"waiting\"`) and an operator has already taken it (\"Take over\"), though they haven't written anything yet. Show \"An operator is with you\" in your chat instead of \"Waiting for an operator…\". In other states it's `false`: there `status` says it all."
          },
          "next_cursor": {
           "type": "string",
           "description": "Cursor for the NEXT poll. Pass it as `?cursor=` — unlike `after`, it tells apart messages sent in the same millisecond."
          },
          "tasks": {
           "type": "array",
           "description": "Long-running agent actions in progress right now (for example, a call to your system that takes minutes). Show them as progress cards next to the chat. An empty array means nothing is running.",
           "items": {
            "$ref": "#/components/schemas/Task"
           }
          },
          "review": {
           "type": "boolean",
           "description": "`true` → the answer to the customer's last message is still being reviewed by a human (training mode): keep polling. The answer arrives as a regular message in `messages`, and the field turns `false`."
          },
          "review_later": {
           "type": "boolean",
           "description": "`true` → the operator didn't reply within the time the owner set, and the customer was promised an answer later: show them this once (in the widget, the `review_later` label). The review continues; `review` stays `true`. In messengers the platform sends this line itself."
          }
         }
        },
        "examples": {
         "newMessage": {
          "summary": "New operator reply",
          "value": {
           "messages": [
            {
             "id": "8f1c0b2a4e",
             "author": "operator",
             "text": "Hello! Yes, we'll deliver tomorrow.",
             "at": 1753600000123
            }
           ],
           "status": "operator",
           "operator_typing": false
          }
         },
         "typing": {
          "summary": "Nothing new, the operator is typing",
          "value": {
           "messages": [],
           "status": "operator",
           "operator_typing": true
          }
         },
         "waiting": {
          "summary": "In the queue, no operator has joined yet",
          "value": {
           "messages": [],
           "status": "waiting",
           "operator_typing": false
          }
         }
        }
       }
      }
     },
     "400": {
      "$ref": "#/components/responses/BadRequest"
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     },
     "503": {
      "$ref": "#/components/responses/Unavailable"
     }
    }
   }
  },
  "/v1/api/operator/threads": {
   "get": {
    "tags": [
     "Operator"
    ],
    "summary": "List operator requests",
    "description": "Returns the bot's conversations that are waiting for an operator or already being handled by one. Use it in your own operator dashboard to connect your own support agents to our bot.\n\n**Pagination.** The response is limited by `?limit=` (default 50, max 200). If `next_cursor` is non-empty, there is more data: repeat the request with `?cursor=<next_cursor>`. Without parameters you get the first page in the usual format.",
    "operationId": "operatorThreads",
    "responses": {
     "200": {
      "description": "List of requests along with live typing signals.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "required": [
          "threads",
          "typing",
          "drafts"
         ],
         "properties": {
          "threads": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/Thread"
           }
          },
          "typing": {
           "type": "array",
           "items": {
            "type": "string"
           },
           "description": "`session_id` values of threads where the visitor is typing right now."
          },
          "drafts": {
           "type": "object",
           "additionalProperties": {
            "type": "string"
           },
           "description": "Visitor drafts: `session_id` → the text typed so far (up to 500 characters). Present only for threads where the visitor is typing and sending a preview (the `text` field in `POST /v1/api/typing`). A thread can be in `typing` without an entry in `drafts`."
          },
          "next_cursor": {
           "type": "string",
           "description": "Next page cursor. An empty string means there are no more pages. Pass it as `?cursor=` to get the continuation."
          }
         }
        },
        "examples": {
         "threads": {
          "value": {
           "threads": [
            {
             "session_id": "3f6c1b9e-7f42-4d2a-9a6f-0d5b1f0b21c7",
             "bot_id": "bot_9f2c",
             "status": "waiting",
             "last_text": "I want to talk to a person",
             "updated_at": 1753600000123
            }
           ],
           "typing": [
            "3f6c1b9e-7f42-4d2a-9a6f-0d5b1f0b21c7"
           ],
           "drafts": {
            "3f6c1b9e-7f42-4d2a-9a6f-0d5b1f0b21c7": "can I order for Sat"
           }
          }
         }
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "404": {
      "description": "Handoff isn't available for this bot.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "examples": {
         "default": {
          "value": {
           "error": "Handing the conversation to a person isn’t available.",
           "code": "not_found"
          }
         }
        }
       }
      }
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     },
     "500": {
      "$ref": "#/components/responses/InternalError"
     }
    },
    "parameters": [
     {
      "$ref": "#/components/parameters/PageLimit"
     },
     {
      "$ref": "#/components/parameters/PageCursor"
     }
    ]
   }
  },
  "/v1/api/operator/threads/{sid}": {
   "get": {
    "tags": [
     "Operator"
    ],
    "summary": "Full request transcript",
    "description": "All messages of the conversation — visitor, bot and operator — in chronological order.\n\n**Pagination.** The response is limited by `?limit=` (default 50, max 200). If `next_cursor` is non-empty, there is more data: repeat the request with `?cursor=<next_cursor>`. Without parameters you get the first page in the usual format. Messages go from oldest to newest.",
    "operationId": "operatorTranscript",
    "parameters": [
     {
      "name": "sid",
      "in": "path",
      "required": true,
      "schema": {
       "$ref": "#/components/schemas/SessionID"
      },
      "description": "Conversation ID (`session_id`).",
      "example": "3f6c1b9e-7f42-4d2a-9a6f-0d5b1f0b21c7"
     },
     {
      "$ref": "#/components/parameters/PageLimit"
     },
     {
      "$ref": "#/components/parameters/PageCursor"
     }
    ],
    "responses": {
     "200": {
      "description": "All messages of the conversation and the visitor's live typing state.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "required": [
          "messages",
          "visitor_typing",
          "visitor_draft"
         ],
         "properties": {
          "messages": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/Message"
           }
          },
          "visitor_typing": {
           "type": "boolean",
           "description": "Whether the visitor is typing a message right now."
          },
          "visitor_draft": {
           "type": "string",
           "description": "Visitor draft — the text typed so far (up to 500 characters), if preview is enabled and being sent. An empty string if there is no draft. Show it to the operator dimmed, as \"typing: …\", so it isn't mistaken for a sent message."
          },
          "next_cursor": {
           "type": "string",
           "description": "Next page cursor. An empty string means there are no more pages. Pass it as `?cursor=` to get the continuation."
          }
         }
        },
        "examples": {
         "transcript": {
          "value": {
           "messages": [
            {
             "id": "1a2b3c4d5e",
             "author": "visitor",
             "text": "I want to talk to a person",
             "at": 1753599990000
            },
            {
             "id": "8f1c0b2a4e",
             "author": "operator",
             "text": "Hello! How can I help?",
             "at": 1753600000123
            }
           ],
           "visitor_typing": true,
           "visitor_draft": "can I order for Sat"
          }
         }
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "404": {
      "description": "Request not found, or it belongs to another bot.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "examples": {
         "default": {
          "value": {
           "error": "Conversation not found.",
           "code": "not_found"
          }
         }
        }
       }
      }
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     },
     "500": {
      "$ref": "#/components/responses/InternalError"
     }
    }
   }
  },
  "/v1/api/operator/threads/{sid}/reply": {
   "post": {
    "tags": [
     "Operator"
    ],
    "summary": "Post an operator reply to a conversation",
    "description": "Sends an operator message into the conversation. The visitor sees it instantly (as a reply from a live operator) — both in our widget and via `GET /v1/api/messages` in your own chat.\n\nIf the bot has auto-translation enabled, the text is translated into the visitor's language before delivery.\n\n**Idempotency.** Add an `Idempotency-Key` header, and a retry after a timeout won't perform the action twice: you get the stored response of the first attempt with `Idempotency-Replayed: true` (the key lives for 24 hours).",
    "operationId": "operatorReply",
    "parameters": [
     {
      "name": "sid",
      "in": "path",
      "required": true,
      "schema": {
       "$ref": "#/components/schemas/SessionID"
      },
      "description": "Conversation ID (`session_id`).",
      "example": "3f6c1b9e-7f42-4d2a-9a6f-0d5b1f0b21c7"
     },
     {
      "$ref": "#/components/parameters/IdempotencyKey"
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "required": [
         "text"
        ],
        "properties": {
         "text": {
          "type": "string",
          "minLength": 1,
          "description": "Operator reply text. Empty string → 400."
         }
        }
       },
       "examples": {
        "reply": {
         "value": {
          "text": "Hello! Yes, we'll deliver tomorrow by 14:00."
         }
        }
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "The recorded message — with it you can append to the feed right away without re-reading the transcript, and later reconcile it by `id` with what arrives over the stream.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "message": {
           "$ref": "#/components/schemas/Message"
          }
         },
         "required": [
          "message"
         ]
        }
       }
      }
     },
     "400": {
      "$ref": "#/components/responses/BadRequest"
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "404": {
      "description": "Request not found, or it belongs to another bot.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "examples": {
         "default": {
          "value": {
           "error": "Conversation not found.",
           "code": "not_found"
          }
         }
        }
       }
      }
     },
     "409": {
      "$ref": "#/components/responses/IdempotencyConflict"
     },
     "413": {
      "$ref": "#/components/responses/PayloadTooLarge"
     },
     "422": {
      "description": "This is a conversation of another program using an agent access key (`ak_`): it waits only for the answer to its own call and won't read a human's message. The reply was not recorded.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     },
     "500": {
      "$ref": "#/components/responses/InternalError"
     }
    }
   }
  },
  "/v1/api/operator/threads/{sid}/resolve": {
   "post": {
    "tags": [
     "Operator"
    ],
    "summary": "Resolve a request",
    "description": "Ends the operator request — from then on the bot answers the visitor again. The conversation status becomes `resolved`. No request body is needed.",
    "operationId": "operatorResolve",
    "parameters": [
     {
      "name": "sid",
      "in": "path",
      "required": true,
      "schema": {
       "$ref": "#/components/schemas/SessionID"
      },
      "description": "Conversation ID (`session_id`).",
      "example": "3f6c1b9e-7f42-4d2a-9a6f-0d5b1f0b21c7"
     }
    ],
    "responses": {
     "200": {
      "description": "Resolved.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "required": [
          "status"
         ],
         "properties": {
          "status": {
           "type": "string",
           "const": "resolved"
          }
         }
        },
        "examples": {
         "resolved": {
          "value": {
           "status": "resolved"
          }
         }
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "404": {
      "description": "Request not found, or it belongs to another bot.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "examples": {
         "default": {
          "value": {
           "error": "Conversation not found.",
           "code": "not_found"
          }
         }
        }
       }
      }
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     },
     "500": {
      "$ref": "#/components/responses/InternalError"
     }
    }
   }
  },
  "/v1/api/operator/threads/{sid}/typing": {
   "post": {
    "tags": [
     "Operator"
    ],
    "summary": "Operator is typing",
    "description": "The mirror signal in the other direction: the visitor sees \"The operator is typing…\" in the widget, and your own chat gets `operator_typing: true` in `GET /v1/api/messages`. Same rules for frequency (once per 3 s) and fading (~6 s). No request body is needed; no preview of the operator's text is sent.",
    "operationId": "operatorTyping",
    "parameters": [
     {
      "name": "sid",
      "in": "path",
      "required": true,
      "schema": {
       "$ref": "#/components/schemas/SessionID"
      },
      "description": "Conversation ID (`session_id`).",
      "example": "3f6c1b9e-7f42-4d2a-9a6f-0d5b1f0b21c7"
     }
    ],
    "responses": {
     "204": {
      "description": "Accepted. No body."
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "404": {
      "description": "Thread not found, or it belongs to another bot.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "examples": {
         "default": {
          "value": {
           "error": "Conversation not found.",
           "code": "not_found"
          }
         }
        }
       }
      }
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/v1/api/typing": {
   "post": {
    "tags": [
     "Handoff"
    ],
    "summary": "Customer is typing",
    "description": "Signals that the visitor is typing a message right now. The operator sees \"customer is typing…\" in the dashboard (or in your operator UI — via `typing`/`drafts` in `GET /v1/api/operator/threads`).\n\nSend it no more than once every 3 seconds while the customer is typing; the signal fades on its own after about 6 seconds.\n\nThe optional `text` field carries a **draft** — what the customer is typing right now, before sending it. The operator sees it live and can prepare a reply in time. Don't send `text` if you don't want to expose unfinished input (this makes private typing visible — enable it deliberately). The draft is truncated to 500 characters.\n\nThe endpoint is silent: if the session belongs to another bot, the response is still `204`, but the signal is ignored.",
    "operationId": "visitorTyping",
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "required": [
         "session_id"
        ],
        "properties": {
         "session_id": {
          "$ref": "#/components/schemas/SessionID"
         },
         "text": {
          "type": "string",
          "maxLength": 500,
          "description": "Draft: the text the customer is typing right now. Optional. Anything longer than 500 characters is truncated. An empty string or a missing field → just the \"typing…\" indicator, with no preview."
         }
        }
       },
       "examples": {
        "signalOnly": {
         "summary": "Indicator only",
         "value": {
          "session_id": "3f6c1b9e-7f42-4d2a-9a6f-0d5b1f0b21c7"
         }
        },
        "withDraft": {
         "summary": "With a draft preview",
         "value": {
          "session_id": "3f6c1b9e-7f42-4d2a-9a6f-0d5b1f0b21c7",
          "text": "can I order for Sat"
         }
        }
       }
      }
     }
    },
    "responses": {
     "204": {
      "description": "Accepted. No body."
     },
     "400": {
      "$ref": "#/components/responses/BadRequest"
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "413": {
      "$ref": "#/components/responses/PayloadTooLarge"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/v1/api/visitors/erase": {
   "post": {
    "tags": [
     "Chat"
    ],
    "summary": "Delete visitor data",
    "description": "Erases everything the bot has stored about one visitor: the message history, operator requests and long-term memory. This is how you fulfill a person's demand to \"delete everything you have about me\".\n\nProvide `session_id` (a specific conversation) or `user_token` (the same identifier you pass to the widget to recognize the customer) — or both. With `user_token`, data from all of that customer's conversations with this bot is erased.\n\nWorks only within the bot the key belongs to.\n\nThe operation is irreversible. You get `200` only when the data has actually been deleted: if erasure failed, you get an error, not a cheerful \"done\".",
    "operationId": "eraseVisitor",
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "description": "At least one of the fields is required.",
        "properties": {
         "session_id": {
          "$ref": "#/components/schemas/SessionID"
         },
         "user_token": {
          "type": "string",
          "maxLength": 256,
          "description": "Your customer identifier, passed to the widget for recognition.",
          "example": "user-4821"
         }
        }
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Data deleted.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "status": {
           "type": "string",
           "example": "erased"
          }
         }
        }
       }
      },
      "headers": {
       "Idempotency-Replayed": {
        "schema": {
         "type": "string",
         "enum": [
          "true"
         ]
        },
        "description": "Present only when this is a replayed response to an earlier request with the same `Idempotency-Key` (the deletion was NOT performed again)."
       }
      }
     },
     "400": {
      "$ref": "#/components/responses/BadRequest"
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "404": {
      "description": "Visitor data deletion isn't available for this agent.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "examples": {
         "default": {
          "value": {
           "error": "Data erasure isn’t available.",
           "code": "not_found"
          }
         }
        }
       }
      }
     },
     "409": {
      "$ref": "#/components/responses/IdempotencyConflict"
     },
     "413": {
      "$ref": "#/components/responses/PayloadTooLarge"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     },
     "500": {
      "description": "Deletion failed — the data is still in place. Retry the request."
     }
    },
    "parameters": [
     {
      "$ref": "#/components/parameters/IdempotencyKey"
     }
    ]
   }
  },
  "/v1/auth/login": {
   "post": {
    "tags": [
     "Authentication"
    ],
    "summary": "Log in",
    "description": "Opens a session. The cookie is set on the registrable domain, so it works in the dashboard, on the landing page and in the guide.\n\nThe password is stored RIGHT HERE, in this service. A forgotten password is recovered by email: `POST /v1/auth/password/forgot` sends a one-time link, and `POST /v1/auth/password/reset` accepts a new password through it. `POST /v1/auth/password` is something else: a change for someone who knows the current password.\n\n`GET /v1/auth/sso` remains a separate entrance for builds with a shared account service.",
    "security": [],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "email": {
          "type": "string",
          "format": "email"
         },
         "password": {
          "type": "string"
         }
        },
        "required": [
         "email",
         "password"
        ]
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Session opened.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "status": {
           "type": "string",
           "enum": [
            "ok"
           ]
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "The email and password didn't match. The response is the same for an unknown address and a wrong password.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "429": {
      "description": "Too many attempts.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/auth/logout": {
   "post": {
    "tags": [
     "Authentication"
    ],
    "summary": "Log out",
    "description": "Ends the current session.",
    "security": [
     {
      "sessionCookie": []
     }
    ],
    "responses": {
     "200": {
      "description": "Session closed.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "status": {
           "type": "string",
           "enum": [
            "ok"
           ]
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "There was no session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "Cross-site request. Roles have nothing to do with it — these endpoints don't check them; see `sessionCookie` on origin-based protection of writes.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/auth/logout-all": {
   "post": {
    "tags": [
     "Authentication"
    ],
    "summary": "Log out on all devices",
    "description": "Ends ALL sessions of the account. This is what you use after a password leak.",
    "security": [
     {
      "sessionCookie": []
     }
    ],
    "responses": {
     "200": {
      "description": "All sessions closed.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "status": {
           "type": "string",
           "enum": [
            "ok"
           ]
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "No session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "Cross-site request. Roles have nothing to do with it — these endpoints don't check them; see `sessionCookie` on origin-based protection of writes.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/auth/me": {
   "get": {
    "tags": [
     "Authentication"
    ],
    "summary": "Who am I",
    "description": "Who is signed in to this session and what's going on with their account. THERE IS NO ROLE HERE.\n\nThe role and workspace membership come from `GET /v1/dashboard` (the `role` field). The dashboard calls both endpoints: this one answers \"the session is alive, it's you, here is the state of your address\", and that one answers \"here is your workspace and what you're allowed to do in it\".\n\n`email_state` is what the platform knows about the address: `verified` (confirmed by email), `pending` (awaiting confirmation; until then you can't invite people to a team, accept invitations or accept a transferred agent — code `email_unconfirmed`), `unchecked` (nobody has checked the address, and there's no reason or way to require it now: the account was created before confirmation existed, or mail isn't configured in this build), `none` (the account has no mailbox — sign-in by phone number).\n\nThis endpoint also responds for an account that is being deleted (the `closing` field): that's how the dashboard knows what to show instead of itself.",
    "security": [
     {
      "sessionCookie": []
     }
    ],
    "responses": {
     "200": {
      "description": "The current user.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "id": {
           "type": "string"
          },
          "email": {
           "type": "string"
          },
          "email_state": {
           "type": "string",
           "description": "State of the account's email address.",
           "enum": [
            "verified",
            "pending",
            "unchecked",
            "none"
           ]
          },
          "has_password": {
           "type": "boolean",
           "description": "Whether the account has a password. An account created via shared sign-in has no password: it can't be asked to re-enter one, and such an account's address can't be changed here."
          },
          "can_confirm": {
           "type": "boolean",
           "description": "Whether `POST /v1/auth/email/verify` will do anything: mail is configured, the address is a mailbox, and it isn't confirmed yet."
          },
          "can_change_email": {
           "type": "boolean",
           "description": "Whether the address can be changed here: this requires mail (an email to the new address) and a password."
          },
          "pending_email": {
           "type": "string",
           "description": "The new address awaiting email confirmation. Present only while a change is in progress."
          },
          "pending_email_until": {
           "type": "string",
           "description": "Until when the link sent to the new address is valid.",
           "format": "date-time"
          },
          "closing": {
           "type": "object",
           "description": "Present only when the account is being deleted.",
           "properties": {
            "deleted_at": {
             "type": "string",
             "description": "When deletion was requested.",
             "format": "date-time"
            },
            "erase_at": {
             "type": "string",
             "description": "When the data will be erased for good; until then the account can be restored.",
             "format": "date-time"
            }
           }
          },
          "platform_admin": {
           "type": "boolean",
           "description": "Present only for platform staff (`true`): the dashboard shows them the entrance to the cost summary. For everyone else the field is absent."
          },
          "admin_entry": {
           "type": "object",
           "description": "Present only when the session was opened by platform staff via a sign-in link.",
           "properties": {
            "admin_email": {
             "type": "string"
            },
            "expires_at": {
             "type": "string",
             "format": "date-time"
            }
           }
          }
         },
         "required": [
          "id",
          "email",
          "email_state",
          "has_password",
          "can_confirm",
          "can_change_email"
         ]
        }
       }
      }
     },
     "204": {
      "description": "No session, and the request had `quiet=1`."
     },
     "401": {
      "description": "Session missing or expired.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "503": {
      "$ref": "#/components/responses/Unavailable"
     }
    },
    "parameters": [
     {
      "name": "quiet",
      "in": "query",
      "required": false,
      "schema": {
       "type": "string",
       "enum": [
        "1"
       ]
      },
      "description": "`1` — the website is asking, not the dashboard: without a session the response is 204 with no body instead of 401, so the browser doesn't log an error to the console on every anonymous visit."
     }
    ]
   }
  },
  "/v1/auth/password": {
   "post": {
    "tags": [
     "Authentication"
    ],
    "summary": "Change password",
    "description": "Requires the current password. On success, the account's other sessions are ended, but the one making the change stays alive: it has just proven it knows the current password, and logging the person out mid-action would stop them from doing exactly what they came here to do.\n\nIf the current password isn't known, use `POST /v1/auth/password/forgot`.",
    "security": [
     {
      "sessionCookie": []
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "current_password": {
          "type": "string"
         },
         "new_password": {
          "type": "string",
          "minLength": 8
         }
        },
        "required": [
         "current_password",
         "new_password"
        ]
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Password changed.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "status": {
           "type": "string",
           "enum": [
            "ok"
           ]
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "The current password didn't match.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "Cross-site request. Roles have nothing to do with it — these endpoints don't check them; see `sessionCookie` on origin-based protection of writes.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/auth/password/forgot": {
   "post": {
    "tags": [
     "Authentication"
    ],
    "summary": "Request a password reset link",
    "description": "Sends an email to the given address with a ONE-TIME link to the dashboard's `/forgotpassword` page.\n\nThe `200` response is the same for existing and nonexistent addresses — on purpose: otherwise this endpoint would be a free way to check whether someone else's email is registered. A `200` does NOT mean an email went to anyone.\n\nWhat it does NOT do is pretend the email was sent when there is nothing to send it with. If mail isn't configured in the build (`SMTP_ADDR`) or there's nothing to build the link URL from (`APP_URL` / `PUBLIC_BASE_URL`), the response is `503` with code `recovery_not_configured`. If mail is configured but this particular email didn't go out, it's `502` with `mail_send_failed`.\n\nOnly the token's SHA-256 is stored; the token itself exists only in the email. The link is valid for 30 minutes and works once. The rate is limited by two budgets: per caller address and per mailbox.",
    "security": [],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "email": {
          "type": "string",
          "format": "email"
         }
        },
        "required": [
         "email"
        ]
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Request accepted. The same for an address we don't have.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "status": {
           "type": "string",
           "enum": [
            "ok"
           ]
          },
          "expires_in_minutes": {
           "type": "integer",
           "description": "How many minutes the link in the email will stay valid. The server returns the number so the client doesn't have to keep a second copy of the expiry that would drift from ours."
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "The address is empty or has no \"@\". This is a property of the submitted text, not an answer about an account.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "429": {
      "description": "Too many requests — from this caller address or to this mailbox. `Retry-After` says how long to wait.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "502": {
      "description": "Mail is configured, but the email didn't go out (`mail_send_failed`). Retrying makes sense.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "503": {
      "description": "Recovery isn't configured in this build (`recovery_not_configured`): no SMTP, dashboard address or token store. The email was NOT sent; retrying won't help.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/auth/password/reset": {
   "post": {
    "tags": [
     "Authentication"
    ],
    "summary": "Set a new password with the token from the email",
    "description": "Accepts the token from the link and a new password. Doesn't ask for the current password — that's exactly what isn't known.\n\nOn success, ALL of the account's sessions are ended, including the current one: passwords are reset precisely when someone else may be inside. There's no session afterwards — you need to log in again.\n\nThe token is single-use: the store removes it in the same operation that finds it. Password length is checked BEFORE the token is consumed, so a `400` doesn't burn the link.",
    "security": [],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "token": {
          "type": "string",
          "description": "The value of the `token` parameter from the link in the email."
         },
         "new_password": {
          "type": "string",
          "minLength": 8
         }
        },
        "required": [
         "token",
         "new_password"
        ]
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Password changed; all of the account's sessions are closed.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "status": {
           "type": "string",
           "enum": [
            "ok"
           ]
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "The token or password is missing, or the password is shorter than 8 characters. The token stays valid in that case.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "410": {
      "description": "The link is invalid (`reset_token_invalid`): it expired, was already used, or is forged. Three reasons under one code on purpose.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "429": {
      "description": "Too many attempts. `Retry-After` says how long to wait.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "503": {
      "description": "Recovery isn't configured in this build (`recovery_not_configured`).",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/auth/signup": {
   "post": {
    "tags": [
     "Authentication"
    ],
    "summary": "Create an account",
    "description": "Registers an account, opens a session right away and sends a confirmation email to the address.\n\nThe address counts as unconfirmed until the link from the email is opened (`POST /v1/auth/email/confirm`). Until then, everything the person controls themselves works; what doesn't work is anything that affects other people on the strength of the address — see `email_state` in `GET /v1/auth/me`.\n\nThe `confirmation` field tells the truth about the email: `sent` — sent; `failed` — mail is set up, but the email didn't go out (you can request it again: `POST /v1/auth/email/verify`); `off` — this build sends no email, and confirmation isn't required from the person.\n\n**The address already has an account.** The response doesn't tell outsiders whether an address is registered. If the password is right, this is a sign-in to the existing account: `200` with `existing: true`, the session is set, and there's no new account and no email. If the password is wrong — `400` with the code `signup_refused` and the same text as any other failed signup, without the word \"taken\"; the way forward is signing in or resetting the password. Attempts on one address share the same bucket as sign-in (`POST /v1/auth/login`).",
    "security": [],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "email": {
          "type": "string",
          "format": "email"
         },
         "password": {
          "type": "string",
          "minLength": 8
         }
        },
        "required": [
         "email",
         "password"
        ]
       }
      }
     }
    },
    "responses": {
     "201": {
      "description": "Account created, session cookie set.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "id": {
           "type": "string",
           "description": "User ID."
          },
          "email": {
           "type": "string"
          },
          "confirmation": {
           "type": "string",
           "description": "How sending the confirmation email ended.",
           "enum": [
            "sent",
            "failed",
            "off"
           ]
          }
         }
        }
       }
      }
     },
     "200": {
      "description": "The address already had an account, and the password for it is right: this is a sign-in to the existing account, the session cookie is set. There's no new account and no confirmation email.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "id": {
           "type": "string",
           "description": "User ID."
          },
          "email": {
           "type": "string"
          },
          "existing": {
           "type": "boolean",
           "description": "Always `true`: the person signed in to an account they already had."
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "The email doesn't look like an address, or the password is too short — or an account couldn't be created with these details (`signup_refused`: the response doesn't say why; the way forward is signing in or resetting the password).",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "429": {
      "description": "Too many attempts from this address.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/auth/sso": {
   "get": {
    "tags": [
     "Authentication"
    ],
    "summary": "Sign in via an external provider",
    "description": "**Sign-in with a shared account.** The person arrives here from the shared account service with a token, and this endpoint exchanges it for a dashboard session. The dashboard itself signs in with email and password (`POST /v1/auth/signup`, `/login`, password recovery); this endpoint is an additional entrance.\n\n**Where it lets you in.** Only into an account it created itself: one without a password. The shared service doesn't confirm email, so the same address there doesn't prove that its owner has arrived. An account with a password — confirmed or not — is never opened through this entrance: the person gets `sso_password_account` and signs in with the password. The endpoint won't claim a new address if an unresolved \"This wasn't me\" from another account holds it (`sso_address_unavailable`).\n\n**What it looks like in the browser.** Open this URL by navigating to it (not with `fetch`): normally it responds with a redirect and sets the session as a cookie.\n\n- no token → redirect to `/`, where the sign-in buttons are;\n- the token failed verification → redirect to `/?sso=failed`;\n- all good → session cookie and a redirect to `next`.\n\nOther refusals come back as a body, not a redirect, because the person needs to learn about them: `sso_identity_unusable` — the account has neither an email nor a phone, so there's nothing to match it by; `sso_password_account` and `sso_address_unavailable` — see above; `sso_storage_unavailable` — neither our fault nor yours, try again in a few minutes.",
    "security": [],
    "responses": {
     "302": {
      "description": "The normal result — both for success and for \"no token / failed verification\". For where exactly, see the description."
     },
     "400": {
      "description": "There's nothing to match the account by (`sso_identity_unusable`).",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "409": {
      "description": "The address was found, but this entrance doesn't let you in there: the account signs in with a password (`sso_password_account`), or another account's \"This wasn't me\" holds the address (`sso_address_unavailable`).",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "500": {
      "description": "Sign-in didn't complete, through no fault of the person signing in (`sso_storage_unavailable`).",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "501": {
      "description": "Shared sign-in isn't set up in this build — `signup`/`login` remain.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "parameters": [
     {
      "name": "token",
      "in": "query",
      "required": false,
      "schema": {
       "type": "string"
      },
      "description": "The shared service token. Can be omitted if it's already in the `token` cookie on the shared domain — then the endpoint takes it from there."
     },
     {
      "name": "next",
      "in": "query",
      "required": false,
      "schema": {
       "type": "string"
      },
      "description": "Where to send the browser after sign-in. A relative path or a URL on an allowed frontend domain is permitted; anything else is ignored — otherwise this would be an open redirect for anyone to abuse."
     }
    ]
   }
  },
  "/v1/billing/callback": {
   "post": {
    "tags": [
     "Billing"
    ],
    "summary": "Payment gateway callback",
    "description": "Called by the gateway, not by you. The body is a signed form; an unknown order gets a 2xx, because redelivery won't make it known.",
    "security": [],
    "requestBody": {
     "required": true,
     "content": {
      "application/x-www-form-urlencoded": {
       "schema": {
        "type": "object",
        "properties": {
         "data": {
          "type": "string"
         },
         "signature": {
          "type": "string"
         }
        },
        "required": [
         "data",
         "signature"
        ]
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Accepted."
     }
    }
   }
  },
  "/v1/billing/cancel": {
   "post": {
    "tags": [
     "Billing"
    ],
    "summary": "Cancel the subscription",
    "description": "The subscription runs until the end of the paid period and doesn't renew.",
    "security": [
     {
      "sessionCookie": []
     }
    ],
    "responses": {
     "200": {
      "description": "Canceled.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "canceled": {
           "type": "boolean",
           "description": "`false` — there was nothing to cancel: there's no active subscription."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "No valid session — log in again.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The current user's role doesn't allow this action.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/billing/history": {
   "get": {
    "tags": [
     "Billing"
    ],
    "summary": "Payment history",
    "description": "All of the owner's invoices, newest first: subscriptions and credit packs together, including failed ones and those still in progress. A history without the failed attempts would answer a different question from the one people ask while looking at a bank statement.",
    "security": [
     {
      "sessionCookie": []
     }
    ],
    "responses": {
     "200": {
      "description": "Payments.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "charges": {
           "type": "array",
           "items": {
            "type": "object",
            "properties": {
             "order_id": {
              "type": "string"
             },
             "kind": {
              "type": "string",
              "enum": [
               "plan",
               "credits"
              ],
              "description": "plan — a subscription, credits — a one-time credit pack."
             },
             "name": {
              "type": "string",
              "description": "Name of the plan or pack at display time: the catalog is live, and a plan withdrawn from sale stays in the history under its id."
             },
             "amount": {
              "type": "number"
             },
             "currency": {
              "type": "string"
             },
             "status": {
              "type": "string",
              "description": "pending | active | failed | canceled | expired | refunding | refunded | refund_failed — as is, without smoothing. canceled — the owner canceled the payment attempt; expired — the payment deadline passed with no money received; refunding/refunded/refund_failed — the payment was unnecessary (a double payment, or one for a canceled attempt): it is being refunded, has been refunded, or couldn't be refunded automatically."
             },
             "at": {
              "type": "string",
              "format": "date-time"
             },
             "credits": {
              "type": "integer",
              "description": "How many credits the pack purchase added; absent for a subscription."
             },
             "note": {
              "type": "string",
              "description": "Why the invoice is in this state, in plain words: for example, \"refunded automatically: double payment\". Only for invoices whose payment is being refunded."
             }
            }
           }
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "No valid session — log in again.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The current user's role doesn't allow this action.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/billing/checkout": {
   "post": {
    "tags": [
     "Billing"
    ],
    "summary": "Start a subscription checkout",
    "description": "Returns the payment gateway form data. A person has only one unfinished plan invoice: while it's open, a request for the same plan returns the form of that same invoice (`resumed: true`), and a request for a different plan returns 409 `checkout_open`. Before that, the platform itself asks the gateway about the open invoice, so a payment whose callback is still on its way will be found and credited.",
    "security": [
     {
      "sessionCookie": []
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "plan_id": {
          "type": "string"
         }
        },
        "required": [
         "plan_id"
        ]
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Data for redirecting to payment.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Checkout"
        }
       }
      }
     },
     "401": {
      "description": "No valid session — log in again.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The current user's role doesn't allow this action.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "409": {
      "description": "A payment is already open (`checkout_open`; the `open` field says which one), or this plan is already active (`conflict`).",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/billing/credit-checkout": {
   "post": {
    "tags": [
     "Billing"
    ],
    "summary": "Buy a credit pack",
    "description": "A one-time payment; the credits go on top of the monthly allowance. Until the invoice for this pack is complete, a repeat request returns the form of that same invoice. The same pack within ten minutes of a paid one returns 409 `confirm_another`: repeat the request with `another: true` if you need one more.",
    "security": [
     {
      "sessionCookie": []
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "pack_id": {
          "type": "string"
         },
         "another": {
          "type": "boolean",
          "description": "Confirms that ONE MORE identical pack is needed right after a paid one."
         }
        },
        "required": [
         "pack_id"
        ]
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Data for redirecting to payment.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Checkout"
        }
       }
      }
     },
     "401": {
      "description": "No valid session — log in again.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The current user's role doesn't allow this action.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "503": {
      "$ref": "#/components/responses/Unavailable"
     },
     "409": {
      "description": "Payment for this pack is already open and the bank is confirming it (`checkout_open`), or an identical pack was just bought (`confirm_another`).",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/billing/credit-packs": {
   "get": {
    "tags": [
     "Billing"
    ],
    "summary": "Credit packs",
    "description": "One-time packs on top of the plan's monthly allowance.",
    "security": [],
    "responses": {
     "200": {
      "description": "Packs.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "packs": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/CreditPack"
           }
          }
         }
        }
       }
      }
     }
    }
   }
  },
  "/v1/billing/plans": {
   "get": {
    "tags": [
     "Billing"
    ],
    "summary": "List plans",
    "description": "Available plans with their monthly credit allowance.",
    "security": [],
    "responses": {
     "200": {
      "description": "Plans.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "plans": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/Plan"
           }
          }
         }
        }
       }
      }
     }
    }
   }
  },
  "/v1/billing/sync": {
   "post": {
    "tags": [
     "Billing"
    ],
    "summary": "Reconcile a payment",
    "description": "Pulls the status from the payment gateway manually — in case the callback didn't arrive. Without a body, it checks the unfinished plan invoice; with `order_id`, the named invoice (including a credit pack).",
    "security": [
     {
      "sessionCookie": []
     }
    ],
    "responses": {
     "200": {
      "description": "State updated.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "settled": {
           "type": "boolean",
           "description": "The payment went through; the subscription is active."
          },
          "subscription": {
           "type": "object",
           "properties": {
            "plan_id": {
             "type": "string"
            },
            "status": {
             "type": "string"
            },
            "amount": {
             "type": "number"
            },
            "cancel_at_period_end": {
             "type": "boolean"
            }
           },
           "description": "Only when `settled`."
          },
          "current_period_end": {
           "type": "string",
           "format": "date-time",
           "description": "Only when `settled` and the date is known."
          },
          "state": {
           "type": "string",
           "description": "Only with `order_id`: the invoice state after reconciliation — pending, active, failed, canceled, expired, refunding, refunded, refund_failed."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "No valid session — log in again.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The current user's role doesn't allow this action.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "You have no such invoice.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "requestBody": {
     "required": false,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "order_id": {
          "type": "string",
          "description": "The invoice to ask the gateway about."
         }
        }
       }
      }
     }
    }
   }
  },
  "/v1/channels/{cid}/inbound/{secret}": {
   "get": {
    "tags": [
     "Dashboard · Channels"
    ],
    "summary": "Callback URL verification (WhatsApp)",
    "description": "Meta first verifies the callback URL with a GET request and only then sends events. The verification code (verify token) is the secret in the path, so there's no separate field. The response is just `hub.challenge` as text.",
    "parameters": [
     {
      "name": "cid",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      }
     },
     {
      "name": "secret",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      }
     },
     {
      "name": "hub.mode",
      "in": "query",
      "required": true,
      "schema": {
       "type": "string",
       "enum": [
        "subscribe"
       ]
      }
     },
     {
      "name": "hub.challenge",
      "in": "query",
      "required": true,
      "schema": {
       "type": "string"
      }
     },
     {
      "name": "hub.verify_token",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "Not checked separately: the secret is already in the path."
     }
    ],
    "responses": {
     "200": {
      "description": "hub.challenge as is",
      "content": {
       "text/plain": {
        "schema": {
         "type": "string"
        }
       }
      }
     },
     "400": {
      "description": "Missing hub.mode=subscribe or hub.challenge"
     },
     "404": {
      "description": "Channel not found, or the secret is wrong"
     }
    },
    "security": []
   },
   "post": {
    "tags": [
     "Dashboard · Channels"
    ],
    "summary": "Incoming channel message",
    "description": "The URL you give to the messenger. Authentication is the secret in the path; there's no session here and there can't be, because a third-party system is calling.\n\nThe body depends on the channel type: `telegram` accepts a Bot API update as is, `viber` a Viber Bot API event, `whatsapp` a Meta Cloud API event, `discord` a Discord interaction (Interactions), `slack` a Slack Events API event, `email` a raw email (RFC 822 MIME), and `api` the three fields below. The agent's answer comes back in the `answer` field of the same call: the universal channel has nowhere else to deliver it, and it doesn't get in the way of messengers.\n\nService events (edits, joining a group) get `200` with an empty `answer` and don't wake the agent.\n\nSignature. A messenger that authenticates the sender signs every delivery, and the signature is verified in constant time BEFORE any processing: `viber` — `X-Viber-Content-Signature` (HMAC-SHA256 of the body with the bot token), `whatsapp` — `X-Hub-Signature-256` (`sha256=` plus HMAC-SHA256 of the body with the App secret), `telegram` — `X-Telegram-Bot-Api-Secret-Token` (the secret the platform sets in setWebhook), `discord` — `X-Signature-Ed25519` over `X-Signature-Timestamp` and the body (the application's public key), `slack` — `X-Slack-Signature` (`v0=` plus HMAC-SHA256 over `v0:<X-Slack-Request-Timestamp>:<body>` with the Signing Secret); for `discord` and `slack`, a signature older than 5 minutes is also rejected. If the signature doesn't match, the response is `401` and the delivery isn't processed at all. A WhatsApp channel without an App secret (connected before it started being required) and a Telegram bot with an old webhook without a secret are accepted as before, but as unauthenticated: the chat linking code doesn't work for them, and nobody gets the owner role.\n\nDiscord and Slack expect a response to the call itself within three seconds, and an agent run takes longer. So they get a response immediately, and the run happens after it: Discord gets `{\"type\":5}` (the person sees \"thinking…\", which the answer later replaces), Slack gets an empty `200`. URL verification is answered without a run: a Discord PING gets `{\"type\":1}`, a Slack `url_verification` gets just the `challenge` as text. A failure of such a run can no longer be returned to anyone, so it becomes an incident for the owner.",
    "security": [],
    "parameters": [
     {
      "name": "cid",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Channel ID."
     },
     {
      "name": "secret",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "The inbound URL secret, issued when the channel was created."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "conversation": {
          "type": "string",
          "description": "Only for `api`: a stable key for the person on the other end in YOUR system. It alone decides what counts as the same conversation, so it must survive restarts of your client."
         },
         "text": {
          "type": "string",
          "description": "Only for `api`: what the person wrote."
         },
         "sender_name": {
          "type": "string",
          "description": "Only for `api`: the name for the operator inbox."
         }
        }
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Accepted. `answer` is empty if there was nothing to reply. For `discord` and `slack` the body is different — see the description above.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "answer": {
           "type": "string"
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "The delivery signature didn't match (or it's missing where the messenger always sets it): the delivery wasn't sent by the messenger. Nothing is processed — neither the run nor the chat linking code.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "The channel doesn't exist or the secret didn't match. The response is identical on purpose: enumerating IDs must not become a way to probe.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "502": {
      "description": "The message couldn't be processed — the messenger should retry.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/dashboard": {
   "get": {
    "tags": [
     "Dashboard · Agents"
    ],
    "summary": "Workspace overview",
    "description": "Agents, credit balance, plan and recently deleted agents (`deleted_bots`) — there's no separate endpoint for the trash.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "responses": {
     "200": {
      "description": "The workspace: agents with keys, the plan and its limits, usage for the period.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "email": {
           "type": "string",
           "description": "Email of the signed-in user."
          },
          "role": {
           "$ref": "#/components/schemas/Role"
          },
          "plan_id": {
           "type": "string",
           "description": "The WORKSPACE plan (the owner's plan), not the viewer's."
          },
          "max_bots": {
           "type": "integer",
           "description": "How many agents this plan allows."
          },
          "bots": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/WorkspaceBot"
           }
          },
          "subscription": {
           "description": "Subscription. `null` for everyone except the owner, and for a request with a key: the price and billing date are the owner's relationship with us, not the workspace state.",
           "nullable": true,
           "allOf": [
            {
             "type": "object",
             "properties": {
              "plan_id": {
               "type": "string"
              },
              "status": {
               "type": "string"
              },
              "amount": {
               "type": "number"
              },
              "cancel_at_period_end": {
               "type": "boolean"
              },
              "current_period_end": {
               "type": "string",
               "format": "date-time"
              }
             }
            }
           ]
          },
          "usage": {
           "$ref": "#/components/schemas/Usage"
          },
          "deleted_bots": {
           "type": "array",
           "items": {
            "type": "object",
            "properties": {
             "id": {
              "type": "string"
             },
             "name": {
              "type": "string"
             },
             "deleted_at": {
              "type": "string",
              "format": "date-time"
             },
             "purge_at": {
              "type": "string",
              "format": "date-time"
             }
            }
           },
           "description": "Agents within the restore period. They are NOT in `bots`; without this list the point-of-no-return date is invisible, and a mistake can't be told apart from a permanent loss. Only for the owner, and only when there are any."
          },
          "pending_payment": {
           "type": "object",
           "properties": {
            "order_id": {
             "type": "string"
            },
            "plan_id": {
             "type": "string"
            },
            "amount": {
             "type": "number"
            },
            "currency": {
             "type": "string",
             "description": "Currency of the amount. The server takes it from the order's plan, or, if that plan was removed from the catalog, from the deployment currency: a plan disappearing doesn't change the currency the person was already invoiced in. Without this field the dashboard couldn't show the amount and hid it."
            },
            "expires_at": {
             "type": "string",
             "format": "date-time",
             "description": "Until when the gateway accepts payment for this invoice."
            }
           },
           "description": "An order still awaiting a payment result. Only for the owner (not a request with a key), and only when there is one."
          },
          "limits_from": {
           "type": "object",
           "properties": {
            "plan_id": {
             "type": "string"
            },
            "until": {
             "type": "string",
             "format": "date-time"
            }
           },
           "description": "The agent and credit limits come from another subscription that is still in force, not the one in plan_id (for example, the paid period of the previous plan). That subscription's plan and when it ends. Only for the owner, and only when this is the case."
          },
          "workspace": {
           "type": "string",
           "description": "The workspace this response is about."
          },
          "workspaces": {
           "type": "array",
           "nullable": true,
           "description": "All of the person's workspaces: their own first, then teams. `null` — the list couldn't be read. Not returned to a request with a key: a key belongs to one workspace, and the owner's other teams (with their owners' emails) are none of its business.",
           "items": {
            "$ref": "#/components/schemas/Workspace"
           }
          }
         },
         "required": [
          "email",
          "role",
          "plan_id",
          "max_bots",
          "bots",
          "subscription"
         ]
        }
       }
      }
     },
     "401": {
      "description": "No valid session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The role doesn't allow this action.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Agent not found, or it belongs to another workspace.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/dashboard/bots": {
   "post": {
    "tags": [
     "Dashboard · Agents"
    ],
    "summary": "Create an agent",
    "description": "A new agent with the default flow — a single model node. Configuring the graph is optional: the agent works right away, and most agents never touch it.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "name": {
          "type": "string"
         },
         "preset_id": {
          "type": "string",
          "description": "The preset to copy the personality and flow from (see GET /v1/dashboard/agent-presets). Empty — an empty agent with the default flow. An unknown ID doesn't cancel the agent: it is created empty, and the response contains preset_error."
         }
        },
        "required": [
         "name"
        ]
       }
      }
     }
    },
    "responses": {
     "201": {
      "description": "Created.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "bot": {
           "$ref": "#/components/schemas/WorkspaceBot"
          },
          "preset": {
           "$ref": "#/components/schemas/AgentPreset"
          },
          "next_steps": {
           "type": "array",
           "items": {
            "type": "string"
           },
           "description": "What the preset does NOT provide and what you'll have to add yourself."
          },
          "preset_failed": {
           "type": "array",
           "items": {
            "type": "string"
           },
           "description": "Parts of the preset that didn't apply: «характер» (\"personality\"), «хід» (\"flow\"). The agent is still created: an error here doesn't roll back what the person asked for."
          },
          "preset_error": {
           "type": "string",
           "description": "There's no preset with this ID — the agent was created empty."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "No valid session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "Either the role doesn't allow it (`code: forbidden`), or no more agents can be created on the current plan (`code: quota_exceeded`). Tell them apart by `code`: the status is the same in both cases, but the advice is the opposite — \"ask the owner for permission\" versus \"change your plan\".",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Agent not found, or it belongs to another workspace.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}": {
   "get": {
    "tags": [
     "Dashboard · Agents"
    ],
    "summary": "Get a single agent",
    "description": "Name, keys and allowed domains of a single agent — without the rest of the overview.\n\nThe dashboard keeps an agent status panel next to the conversation and re-reads it after every Builder turn. Previously the only option was `GET /v1/dashboard`, which carries the list of all agents, the plan, limits, subscription, any in-flight payment and deleted agents — all for the sake of one name and a counter.\n\nThe secret key is masked, as in the list: it is returned in full exactly once, when the agent is created.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     }
    ],
    "responses": {
     "200": {
      "description": "The agent.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "bot": {
           "$ref": "#/components/schemas/WorkspaceBot"
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "No valid session — log in again.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "This session has no access to the dashboard.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "There's no such agent in your workspace.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   },
   "patch": {
    "tags": [
     "Dashboard · Agents"
    ],
    "summary": "Rename an agent",
    "description": "Changes the name only.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "name": {
          "type": "string"
         }
        },
        "required": [
         "name"
        ]
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Updated.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "bot": {
           "$ref": "#/components/schemas/WorkspaceBot"
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "No valid session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The role doesn't allow this action.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Agent not found, or it belongs to another workspace.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   },
   "delete": {
    "tags": [
     "Dashboard · Agents"
    ],
    "summary": "Delete an agent",
    "description": "Soft delete: the agent disappears from the list and stops answering, but it can be restored until the final erasure date. That date is returned in `purge_at`.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     }
    ],
    "responses": {
     "200": {
      "description": "Deleted.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "status": {
           "type": "string",
           "enum": [
            "deleted"
           ]
          },
          "bot_id": {
           "type": "string"
          },
          "purge_at": {
           "type": "string",
           "format": "date-time",
           "description": "When the agent's data will be destroyed for good."
          },
          "restore_until": {
           "type": "string",
           "format": "date-time",
           "description": "Until when the agent can be restored (the same moment as `purge_at`)."
          },
          "message": {
           "type": "string",
           "description": "The same, as a sentence for a human."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "No valid session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The role doesn't allow this action.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Agent not found, or it belongs to another workspace.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "409": {
      "description": "A new owner has already accepted the agent — it's being transferred and can't be deleted.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/channels": {
   "get": {
    "tags": [
     "Dashboard · Channels"
    ],
    "summary": "Agent channels",
    "description": "A channel is one way to reach the agent by message. The messenger behind it is hidden by an adapter, so the agent gets the same normalized input from everywhere, and a conversation in a channel has the same memory, knowledge, quotas and handoff to an operator as a conversation in the widget.\n\n**`telegram`** — the owner pastes the token from @BotFather, and visitors message the bot.\n\n**`api`** — a universal entrance for a messenger we didn't anticipate: your side translates its format into three fields and reads the answer from the same call.\n\nThe `types` field lists what can be connected in this build — take the list from here, not from your own copy.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     }
    ],
    "responses": {
     "200": {
      "description": "Channels.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "channels": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/Channel"
           }
          },
          "types": {
           "type": "array",
           "items": {
            "type": "string",
            "enum": [
             "telegram",
             "viber",
             "whatsapp",
             "discord",
             "slack",
             "api",
             "email"
            ]
           }
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "No valid session — log in again.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The current user's role doesn't allow this action.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Agent or channel not found.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   },
   "post": {
    "tags": [
     "Dashboard · Channels"
    ],
    "summary": "Connect a channel",
    "description": "The inbound URL with the secret (`inbound_url`) is returned **here and nowhere else**. A lost one can't be recovered — the channel is recreated, and the old URL stops accepting calls.\n\nFor `telegram`, this URL must be given to Telegram via `setWebhook`.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "type": {
          "type": "string",
          "enum": [
           "telegram",
           "viber",
           "whatsapp",
           "discord",
           "slack",
           "api",
           "email"
          ]
         },
         "name": {
          "type": "string"
         },
         "enabled": {
          "type": "boolean",
          "description": "A channel is connected enabled, so the field can be omitted. `false` is rejected with 400: you can disable the channel with a separate change (PUT) after connecting it."
         },
         "config": {
          "type": "object",
          "properties": {
           "token": {
            "type": "string",
            "description": "For `telegram` — the token from @BotFather; for `viber` — the public account token; for `discord` — the bot token (Developer Portal → Bot → Reset Token): with it, the platform fetches the application ID and the signature verification key from Discord itself; for `slack` — the Bot User OAuth Token (`xoxb-…`) of your own Slack app."
           },
           "phone_id": {
            "type": "string",
            "description": "Only for `whatsapp`: the Phone number ID from the Meta dashboard. The token is a permanent system user token. The subscription is set up in the Meta dashboard: the callback URL is the channel's inbound URL, and the verify token is its secret; Meta verifies the URL with a GET carrying hub.challenge."
           },
           "app_secret": {
            "type": "string",
            "description": "Only for `whatsapp`, required for a new channel: the App secret of the Meta app (App settings → Basic). It's used to verify the `X-Hub-Signature-256` signature of every event; without it, an event from Meta can't be told apart from one forged to the URL. For an existing channel that lacks it, add it by updating the channel — until then, a chat can't be linked in that channel."
           },
           "signing_secret": {
            "type": "string",
            "description": "Only for `slack`, required: the Signing Secret of the Slack app (Basic Information → App Credentials). It's used to verify the `X-Slack-Signature` signature of every event; the owner enters the events URL in the app's Event Subscriptions → Request URL."
           },
           "smtp_host": {
            "type": "string",
            "description": "Only for `email`: the SMTP server replies are sent from. For well-known services (Gmail, Outlook, ukr.net, i.ua, meta.ua, Yahoo, iCloud) it's detected automatically from the `from` address — together with the incoming mail server."
           },
           "imap_host": {
            "type": "string",
            "description": "Only for `email`: the incoming mail server (IMAP). When it's known, the platform reads the mailbox itself once a minute — only unread emails, marking them as read before the agent run. Without it, incoming emails are forwarded as raw MIME (RFC 822) via POST to the channel's inbound URL."
           },
           "imap_port": {
            "type": "string",
            "description": "Only for `email`. Default 993 (TLS); any other port means STARTTLS."
           },
           "imap_user": {
            "type": "string",
            "description": "Only for `email`. Defaults to the same value as `smtp_user`."
           },
           "imap_pass": {
            "type": "string",
            "description": "Only for `email`. Defaults to the same value as `smtp_pass`."
           },
           "smtp_port": {
            "type": "string",
            "description": "Only for `email`. Default 587."
           },
           "smtp_user": {
            "type": "string",
            "description": "Only for `email`."
           },
           "smtp_pass": {
            "type": "string",
            "description": "Only for `email`. Stored in the channel config the same way as a bot token."
           },
           "from": {
            "type": "string",
            "description": "Only for `email`: the address replies are sent from. The person on the other end is identified by the email's sender address: the same mailbox continues the same conversation."
           },
           "from_name": {
            "type": "string",
            "description": "Only for `email`: the sender's display name."
           },
           "reply": {
            "type": "string",
            "enum": [
             "on",
             "off"
            ],
            "description": "Only for `email`: `off` — the mailbox only reads and never replies on its own (personal mail); requires an incoming mail server. Default `on`. Change it later via `PUT …/channels/{cid}/mailbox`."
           },
           "send": {
            "type": "string",
            "enum": [
             "approve",
             "self"
            ],
            "description": "Only for `email`: `self` — the owner's agent sends emails without an approval card. Default `approve`."
           }
          }
         }
        },
        "required": [
         "type",
         "name"
        ]
       }
      }
     }
    },
    "responses": {
     "201": {
      "description": "Channel created.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "channel": {
           "allOf": [
            {
             "$ref": "#/components/schemas/Channel"
            },
            {
             "type": "object",
             "properties": {
              "inbound_url": {
               "type": "string",
               "description": "The URL with the secret. Shown once."
              },
              "connected": {
               "type": "boolean",
               "description": "The channel is subscribed to the messenger's messages. `false` — the channel is saved, but the bot won't receive anything; the reason is in `connect_error`."
              },
              "connect_error": {
               "type": "string",
               "description": "Why subscribing failed, in plain words. Only when `connected: false`."
              }
             }
            }
           ]
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "Unknown type, the config fails the adapter's validation, or the channel is being connected disabled (`enabled: false`).",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "description": "No valid session — log in again.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The current user's role doesn't allow this action.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Agent or channel not found.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/channels/{cid}": {
   "put": {
    "tags": [
     "Dashboard · Channels"
    ],
    "summary": "Update a channel",
    "description": "A field missing from the body isn't changed: a `name` with no value keeps the name, and a missing `enabled` leaves the channel in its current state (a disabled channel isn't enabled by a rename).\n\nAn empty value for a secret field (`config.token`) means \"untouched\": the form doesn't show the token and sends it empty, so otherwise saving just the name would wipe a working connection.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     },
     {
      "name": "cid",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Channel ID."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "name": {
          "type": "string"
         },
         "enabled": {
          "type": "boolean",
          "description": "Enable or disable the channel. No field — the state doesn't change."
         },
         "config": {
          "type": "object",
          "properties": {
           "token": {
            "type": "string"
           }
          }
         }
        }
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Updated.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "channel": {
           "allOf": [
            {
             "$ref": "#/components/schemas/Channel"
            },
            {
             "type": "object",
             "properties": {
              "connected": {
               "type": "boolean",
               "description": "The channel is subscribed to the messenger's messages. `false` — the channel is saved, but the bot won't receive anything; the reason is in `connect_error`."
              },
              "connect_error": {
               "type": "string",
               "description": "Why subscribing failed, in plain words. Only when `connected: false`."
              }
             },
             "description": "Only for an enabled channel: a disabled one isn't subscribed."
            }
           ]
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "The config fails the adapter's validation.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "description": "No valid session — log in again.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The current user's role doesn't allow this action.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Agent or channel not found.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   },
   "delete": {
    "tags": [
     "Dashboard · Channels"
    ],
    "summary": "Disconnect a channel",
    "description": "The channel stops accepting messages; its inbound URL no longer exists.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     },
     {
      "name": "cid",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Channel ID."
     }
    ],
    "responses": {
     "200": {
      "description": "Disconnected.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "status": {
           "type": "string",
           "enum": [
            "deleted"
           ]
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "No valid session — log in again.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The current user's role doesn't allow this action.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Agent or channel not found.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/config": {
   "get": {
    "tags": [
     "Dashboard · Agents"
    ],
    "summary": "Agent settings",
    "description": "Behavior, tone, greeting, restrictions — everything that isn't the flow.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     }
    ],
    "responses": {
     "200": {
      "description": "Agent settings.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "config": {
           "$ref": "#/components/schemas/BotConfig"
          },
          "mcp": {
           "type": "array",
           "items": {
            "type": "object",
            "properties": {
             "alias": {
              "type": "string",
              "description": "Short server name."
             },
             "url": {
              "type": "string"
             }
            }
           },
           "description": "Connected MCP servers, without keys."
          },
          "monthly_credit_spent": {
           "type": "integer",
           "description": "How many credits the agent has spent since the start of the current month — the same number as in the run log.\n\nIt makes sense next to `monthly_credit_cap`: a cap without the amount spent says nothing — whether \"5000\" is a lot or a little only shows when you see both.\n\n−1 means \"couldn't read it\". Exactly −1, not 0: zero would read as \"nothing spent\"."
          }
         },
         "required": [
          "config",
          "mcp"
         ]
        }
       }
      }
     },
     "401": {
      "description": "No valid session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The role doesn't allow this action.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Agent not found, or it belongs to another workspace.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   },
   "put": {
    "tags": [
     "Dashboard · Agents"
    ],
    "summary": "Save settings",
    "description": "The change takes effect immediately: unlike the flow, this isn't a versioned resource.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/BotConfig"
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Saved.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "config": {
           "$ref": "#/components/schemas/BotConfig"
          },
          "mcp": {
           "type": "array",
           "items": {
            "type": "object",
            "properties": {
             "alias": {
              "type": "string",
              "description": "Short server name."
             },
             "url": {
              "type": "string"
             }
            }
           },
           "description": "Connected MCP servers — without tokens."
          }
         },
         "description": "What was SAVED, not what was sent: normalization may have trimmed text or dropped a color."
        }
       }
      }
     },
     "401": {
      "description": "No valid session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The role doesn't allow this action.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Agent not found, or it belongs to another workspace.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "503": {
      "$ref": "#/components/responses/Unavailable"
     }
    }
   },
   "patch": {
    "tags": [
     "Dashboard · Agents"
    ],
    "summary": "Change individual personality fields",
    "description": "A partial change: send only what you're changing. An empty field means \"untouched\" — to CLEAR a field, name it in `clear`.\n\nUnlike `PUT`, you don't need to read the whole config and send it back: two simultaneous writes done that way overwrite each other, and a client that doesn't know about a field added after its release silently resets it to zero.\n\nThe response contains `changed` and `refused`. A refused field doesn't cancel the rest: throwing out the whole request because of a bad color would leave the client thinking that only the colors didn't work. The refusal reason is written so you can fix the problem from it — with a list of allowed values.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/BotConfigPatch"
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "What changed, what was refused, and the config after the write.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/BotConfigPatchResult"
        }
       }
      }
     },
     "400": {
      "description": "The body isn't a valid patch.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "description": "No valid session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The role doesn't allow this action.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Agent not found.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "503": {
      "$ref": "#/components/responses/Unavailable"
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/dev-connection": {
   "get": {
    "tags": [
     "Dashboard · Connections"
    ],
    "summary": "External developer",
    "description": "The account key is never returned — only a hint by which the owner can recognize the connected key.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     }
    ],
    "responses": {
     "200": {
      "description": "External developer connection.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/DevConnection"
        }
       }
      }
     },
     "401": {
      "description": "No valid session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The role doesn't allow this action.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Agent not found, or it belongs to another workspace.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   },
   "put": {
    "tags": [
     "Dashboard · Connections"
    ],
    "summary": "Save the connection",
    "description": "Pass the `api_key` field ONLY when you're actually entering a key: a missing field means \"untouched\", and an empty string means \"disconnect\". An empty value sent out of habit along with the limits would silently disable a working connection.\n\nThe same goes for limits: a `max_concurrent` or `max_per_day` missing from the body stays as it was; `0` restores the platform default.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "max_concurrent": {
          "type": "integer",
          "description": "How many conversations can run at once. No field — unchanged; 0 — the default."
         },
         "max_per_day": {
          "type": "integer",
          "description": "How many conversations per day. No field — unchanged; 0 — the default."
         },
         "api_key": {
          "type": "string"
         }
        }
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Saved.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/DevConnection"
        }
       }
      }
     },
     "401": {
      "description": "No valid session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The role doesn't allow this action.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Agent not found, or it belongs to another workspace.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "409": {
      "description": "The saved key couldn't be read (the server's encryption key has changed). The limit change without a key was not saved, so as not to erase the key: send `api_key` together with the limits. The text in `error` is ready to display.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/erase-visitor": {
   "post": {
    "tags": [
     "Dashboard · Agents"
    ],
    "summary": "Erase visitor data",
    "description": "Removes a specific visitor's memory and conversations — fulfilling the right to be forgotten from the dashboard.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "session_id": {
          "type": "string",
          "description": "The visitor's conversation."
         },
         "user_token": {
          "type": "string",
          "description": "The visitor's verified identity (what the website passed in the signature)."
         }
        },
        "description": "At least one of the two is required."
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Erased.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "status": {
           "type": "string",
           "enum": [
            "erased"
           ]
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "The body isn't valid JSON, or `session_id` is missing.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "description": "No valid session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The role doesn't allow this action.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Agent not found, or it belongs to another workspace.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/events": {
   "get": {
    "tags": [
     "Dashboard · Agents"
    ],
    "summary": "Agent event stream (SSE)",
    "description": "A long-lived `text/event-stream`: new requests, status changes, completed runs. The dashboard keeps it open instead of polling.\n\nThe live channel for operator screens: a new request, a colleague's reply, a changed status and \"customer is typing\" arrive on their own, without polling.\n\n**Format.** There are no named events — each frame is a single `data:` line with an `InboxFrame` object:\n\n```\ndata: {\"threads\":[…],\"typing\":[],\"drafts\":{}}\n\n: ping\n\ndata: {\"typing\":[\"s_17…\"],\"drafts\":{\"s_17…\":\"and when will it\"}}\n\n```\n\nThe `: ping` line is an SSE comment, not data: it comes every 25 seconds and keeps proxies from closing a quiet connection. `EventSource` delivers it to you as nothing.\n\n**Tell frames apart by which field is present**, not by their order: `threads` isn't always there (see the schema).\n\n**Disconnects.** `Last-Event-ID` isn't supported — there's nothing to resume: every frame with `threads` carries the full state of the first page, not a delta. `EventSource` reconnects on its own, and the very first frame after that catches up on what was missed.\n\n**If the stream isn't available in this build**, you get `204` with no body. This isn't an error: it means escalation to a human isn't set up here.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     }
    ],
    "responses": {
     "200": {
      "description": "Inbox event stream.",
      "content": {
       "text/event-stream": {
        "schema": {
         "$ref": "#/components/schemas/InboxFrame"
        }
       }
      }
     },
     "401": {
      "description": "No valid session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The role doesn't allow this action.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Agent not found, or it belongs to another workspace.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "204": {
      "description": "Escalation to a human isn't available in this build — there will be no stream."
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/faq/suggest": {
   "post": {
    "tags": [
     "Dashboard · Agents"
    ],
    "summary": "Suggest FAQs",
    "description": "Drafts an FAQ from what the agent was actually asked. Saves nothing — the decision is yours. The draft is written by the model, so it spends the workspace's credits.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {}
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "The draft.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "items": {
           "type": "array",
           "items": {
            "type": "object",
            "properties": {
             "question": {
              "type": "string"
             },
             "answer": {
              "type": "string"
             }
            }
           }
          },
          "reason": {
           "type": "string",
           "enum": [
            "no_data"
           ],
           "description": "Why it's empty: there are no conversations yet to build questions from."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "Billing didn't allow it: the workspace is out of credits, or the workspace or agent spending cap has been reached. Drafting an FAQ is a model call, and the workspace pays for it, just as for a run.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "description": "No valid session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The role doesn't allow this action.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Agent not found, or it belongs to another workspace.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "503": {
      "$ref": "#/components/responses/Unavailable"
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/feedback": {
   "get": {
    "tags": [
     "Dashboard · Agents"
    ],
    "summary": "Answer ratings",
    "description": "How many times visitors approved the agent's answers, and how many times they didn't.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     }
    ],
    "responses": {
     "200": {
      "description": "Summary.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "up": {
           "type": "integer"
          },
          "down": {
           "type": "integer"
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "No valid session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The role doesn't allow this action.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Agent not found, or it belongs to another workspace.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/files": {
   "post": {
    "tags": [
     "Dashboard · Knowledge"
    ],
    "summary": "Upload a document",
    "description": "PDF, DOCX, XLSX, CSV, TXT or MD files become a knowledge source.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "multipart/form-data": {
       "schema": {
        "type": "object",
        "properties": {
         "file": {
          "type": "string",
          "format": "binary"
         }
        },
        "required": [
         "file"
        ]
       }
      }
     }
    },
    "responses": {
     "202": {
      "description": "Added.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "status": {
           "type": "string",
           "enum": [
            "indexed",
            "updated"
           ],
           "description": "`updated` — a file with this name already existed; its content was replaced."
          },
          "filename": {
           "type": "string"
          },
          "source_id": {
           "type": "string"
          },
          "replaced": {
           "type": "boolean",
           "description": "Whether a file with this name already existed."
          },
          "message": {
           "type": "string",
           "description": "The same, as a sentence for a human."
          },
          "catalog": {
           "type": "object",
           "description": "Only for a table with name and price columns: what happened to the product catalog. Absent — the file went into knowledge only.",
           "properties": {
            "count": {
             "type": "integer",
             "description": "How many products are in the catalog now."
            },
            "skipped": {
             "type": "integer",
             "description": "How many rows were skipped for lacking a name or price."
            },
            "kept": {
             "type": "boolean",
             "description": "Products are already read from a feed by URL, and the table didn't replace it."
            },
            "replaced": {
             "type": "string",
             "description": "Name of the previous table whose products were replaced."
            },
            "dropped": {
             "type": "boolean",
             "description": "The new version of the same table no longer has name and price columns — the products from the previous version were removed."
            },
            "need_admin": {
             "type": "boolean",
             "description": "The table could have become a catalog, but only an administrator can create or replace the catalog — it went into knowledge only."
            }
           },
           "required": [
            "count",
            "skipped"
           ]
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "No valid session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The role doesn't allow this action.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Agent not found, or it belongs to another workspace.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "413": {
      "description": "File too large.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "503": {
      "$ref": "#/components/responses/Unavailable"
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/identity-secret": {
   "post": {
    "tags": [
     "Dashboard · Agents"
    ],
    "summary": "Reissue the identity verification key",
    "description": "Your server uses it to sign a confirmation that the visitor is exactly who they claim to be. It is returned only at the moment of issue. The previous key stops working immediately.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     }
    ],
    "responses": {
     "200": {
      "description": "The new key.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "required": [
          "secret",
          "bot_id",
          "wordpress"
         ],
         "properties": {
          "secret": {
           "type": "string",
           "description": "Signing key (`idsec_…`)."
          },
          "bot_id": {
           "type": "string",
           "description": "The agent to sign for: the `bot` field of the envelope."
          },
          "wordpress": {
           "type": "string",
           "description": "The same as a single `agent:key` line — for the \"Visitor signing key\" field in the WordPress plugin."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "No valid session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The role doesn't allow this action.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Agent not found, or it belongs to another workspace.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "503": {
      "$ref": "#/components/responses/Unavailable"
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/leads": {
   "get": {
    "tags": [
     "Dashboard · Agents"
    ],
    "summary": "Collected contacts",
    "description": "What visitors left with the agent so they can be contacted.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     }
    ],
    "responses": {
     "200": {
      "description": "Contacts.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "leads": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/Lead"
           }
          },
          "truncated": {
           "type": "boolean",
           "description": "The list is truncated: there are more rows than a page holds (50). Say so explicitly — otherwise the owner reads the slice as the whole list. There's no cursor pagination here yet; older history is available only from storage."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "No valid session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The role doesn't allow this action.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Agent not found, or it belongs to another workspace.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/media": {
   "get": {
    "tags": [
     "Dashboard · Knowledge"
    ],
    "summary": "Agent media",
    "description": "Images the agent can show in its answers.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     }
    ],
    "responses": {
     "200": {
      "description": "Media.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "media": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/Media"
           }
          },
          "truncated": {
           "type": "boolean",
           "description": "The list is truncated: there are more rows than a page holds (50). Say so explicitly — otherwise the owner reads the slice as the whole list. There's no cursor pagination here yet; older history is available only from storage."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "No valid session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The role doesn't allow this action.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Agent not found, or it belongs to another workspace.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   },
   "post": {
    "tags": [
     "Dashboard · Knowledge"
    ],
    "summary": "Upload media",
    "description": "The description matters more than the file: it's what the agent uses to decide when showing the image is appropriate.\n\nA separate note on the bot: along with the file, the platform adds a NOTE to its knowledge — without it, the assistant doesn't know the file exists and will never send it. If the note couldn't be added, the file is still saved (201), and the response gets a `notice` field with an explanation: the file itself isn't lost, but the bot can't send it yet. The field comes ONLY in that case. Requires the administrator role: a library file becomes a public URL that the bot shows to customers.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "multipart/form-data": {
       "schema": {
        "type": "object",
        "properties": {
         "file": {
          "type": "string",
          "format": "binary"
         },
         "description": {
          "type": "string"
         }
        },
        "required": [
         "file"
        ]
       }
      }
     }
    },
    "responses": {
     "201": {
      "description": "Uploaded.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "media": {
           "$ref": "#/components/schemas/Media"
          },
          "notice": {
           "type": "string",
           "description": "The file is saved, but the agent doesn't know about it yet — and why. The field is absent when everything is fine."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "No valid session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The role doesn't allow this action.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Agent not found, or it belongs to another workspace.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "413": {
      "$ref": "#/components/responses/PayloadTooLarge"
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/media/{mediaID}": {
   "delete": {
    "tags": [
     "Dashboard · Knowledge"
    ],
    "summary": "Delete media",
    "description": "Removes the file and the links to it. Requires the administrator role: a library file becomes a public URL that the bot shows to customers.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     },
     {
      "name": "mediaID",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      }
     }
    ],
    "responses": {
     "200": {
      "description": "Deleted.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "status": {
           "type": "string",
           "enum": [
            "deleted"
           ]
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "No valid session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The role doesn't allow this action.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Agent not found, or it belongs to another workspace.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/origins": {
   "post": {
    "tags": [
     "Dashboard · Agents"
    ],
    "summary": "Allowed widget domains",
    "description": "The list of websites where this agent's widget is allowed to run. Empty = allowed anywhere.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "origins": {
          "type": "array",
          "items": {
           "type": "string",
           "example": "https://example.com"
          }
         }
        },
        "required": [
         "origins"
        ]
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Saved.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "bot": {
           "$ref": "#/components/schemas/WorkspaceBot"
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "No valid session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The role doesn't allow this action.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Agent not found, or it belongs to another workspace.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/graph": {
   "get": {
    "tags": [
     "Dashboard · Agent flow"
    ],
    "summary": "Agent flow",
    "description": "Shows the platform's default flow and the published version (`live`). `live: null` means the agent runs on the default graph — a single model node.\n\n**Headers with credentials come back masked as `••••`.** A `{{secrets.NAME}}` placeholder stays visible: it names the key, not the key itself.\n\nSend the mask back as is — on write it's replaced with the real value from the current flow. If the current flow no longer has such a header, it's removed, and `warnings` will say so.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     }
    ],
    "responses": {
     "200": {
      "description": "The default graph and the one running now.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "default": {
           "$ref": "#/components/schemas/Graph"
          },
          "live": {
           "allOf": [
            {
             "$ref": "#/components/schemas/AgentVersion"
            }
           ],
           "nullable": true,
           "description": "null = the agent runs on the default graph."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "No valid session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The role doesn't allow this action.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Agent not found, or it belongs to another workspace.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   },
   "put": {
    "tags": [
     "Dashboard · Agent flow"
    ],
    "summary": "Apply a graph",
    "description": "Applies the graph and returns a diff against what was running before.\n\nThere are no drafts and no separate publish step (V3-02). The two-step process was a deploy metaphor; on the server side it guaranteed nothing — the second call was made by the same client as the first. The diff hasn't gone away: it's in the response, and you can show it BEFORE the write by comparing with `GET`.\n\nEvery apply creates a version — that's what undoing a change set returns to.\n\nThe response includes `estimate` — what to expect from this graph per run. There's deliberately no cap on the number of nodes: if someone wants twenty model calls, it's their money and their decision. But it has to be an INFORMED decision: otherwise the difference between a one-call graph and a ten-call graph only shows up in the bill at the end of the month.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "required": [
         "base_version",
         "graph"
        ],
        "properties": {
         "base_version": {
          "type": "integer",
          "description": "The number of the live version you saw when you started editing — take it from `live.number` in `GET /graph`. Zero means \"no version of its own yet, the default is running\", and that's an honest value, not \"don't know\": in that case `GET /graph` has `live: null`.\n\nREQUIRED. Without it, a write would silently overwrite someone else's work, and there's no such thing as optional overwrite protection: a client that doesn't send it looks protected but isn't."
         },
         "graph": {
          "$ref": "#/components/schemas/Graph"
         }
        }
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Applied.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "live": {
           "$ref": "#/components/schemas/AgentVersion"
          },
          "diff": {
           "$ref": "#/components/schemas/GraphDiff"
          },
          "warnings": {
           "type": "array",
           "items": {
            "type": "string"
           },
           "description": "Suspicious but valid — e.g. a node whose output goes nowhere. Doesn't block the write: you have the right to build an odd graph, but not to do it unknowingly."
          },
          "estimate": {
           "$ref": "#/components/schemas/GraphEstimate"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "The graph doesn't hold together: it's empty, has an unknown node kind, a name declared twice or not following the rule (lowercase Latin letters, digits and underscores, up to 40 characters, starting with a letter), an edge to a nonexistent node, two inputs with the same name, or a cycle. The reason is in `error`, with the node name.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "description": "No valid session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The role doesn't allow this action.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Agent not found, or it belongs to another workspace.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "409": {
      "description": "The flow was changed while you were editing it (`code: conflict`). Nothing was written. Re-read `GET /graph`, carry your changes over to the new graph and send them with the new `base_version` — resending the same request would overwrite someone else's work.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "503": {
      "$ref": "#/components/responses/Unavailable"
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/preview-identity": {
   "post": {
    "tags": [
     "Dashboard · Agents"
    ],
    "summary": "Owner identity for the chat window preview",
    "description": "Issues a short-lived signed `user_auth` envelope that lets the chat window in the dashboard preview talk to the agent as the owner. There is no request body. If the agent has no visitor signing key yet, one is created.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     }
    ],
    "responses": {
     "200": {
      "description": "The signed envelope.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "user_auth": {
           "type": "string",
           "description": "Signed envelope — pass it to the chat window as `user_auth`."
          },
          "expires_in": {
           "type": "integer",
           "description": "How many seconds the envelope stays valid."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "No valid session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The signature is issued only to the workspace owner signed in to the dashboard: a turn made with it sees the owner's email, calendar and notes. An admin or a member, like a request made with a key, is refused.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Agent not found, or it belongs to another workspace.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "503": {
      "$ref": "#/components/responses/Unavailable"
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/restore": {
   "post": {
    "tags": [
     "Dashboard · Agents"
    ],
    "summary": "Restore a deleted agent",
    "description": "Works until the permanent erasure date; after that the data is gone.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     }
    ],
    "responses": {
     "200": {
      "description": "Restored.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "bot": {
           "$ref": "#/components/schemas/WorkspaceBot"
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "No valid session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The role doesn't allow this action.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Agent not found, or it belongs to another workspace.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/runs": {
   "get": {
    "tags": [
     "Dashboard · Triggers"
    ],
    "summary": "Run log",
    "description": "Every agent run with its cost in credits and the reason it failed. This is what answers the question \"why did the agent do that\".",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     }
    ],
    "responses": {
     "200": {
      "description": "Runs.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "runs": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/Run"
           }
          },
          "truncated": {
           "type": "boolean",
           "description": "The list is truncated: there are more rows than a page holds (50). Say so explicitly — otherwise the owner reads the slice as the whole list. There's no cursor pagination here yet; older history is available only from storage."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "No valid session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The role doesn't allow this action.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Agent not found, or it belongs to another workspace.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/scrape": {
   "get": {
    "tags": [
     "Dashboard · Knowledge"
    ],
    "summary": "Site crawl status",
    "description": "Polls the background job: site reading (`POST …/scrape`), rereading everything (`POST …/pages/reread`) and scheduled rereading all put their summary here. The numbers tell the truth about coverage: how many pages were found and where, how many were read, what failed to open and why, and what didn't fit.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     }
    ],
    "responses": {
     "200": {
      "description": "Status.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "status": {
           "type": "string",
           "enum": [
            "idle",
            "scanning",
            "done",
            "error"
           ]
          },
          "url": {
           "type": "string",
           "description": "The site that was crawled. Absent when `idle`."
          },
          "pages_found": {
           "type": "integer",
           "description": "How many pages of the site the crawl knows about — including those it didn't reach. From this field on, values arrive only after the crawl finishes."
          },
          "crawled": {
           "type": "boolean",
           "description": "The crawl discovered pages itself (sitemap and links). Absent — exactly the named addresses were read, and the numbers say nothing about the rest of the site."
          },
          "from_sitemap": {
           "type": "integer",
           "description": "How many of the found pages are listed in the sitemap (sitemap.xml: from robots.txt, standard locations, nested indexes, compressed files)."
          },
          "from_links": {
           "type": "integer",
           "description": "How many were found by following links from pages — the sitemap complements the crawl rather than replacing it."
          },
          "from_known": {
           "type": "integer",
           "description": "How many of them were already in knowledge but the site no longer links to them. They are requested directly."
          },
          "pages_indexed": {
           "type": "integer",
           "description": "How many pages of the site are in knowledge after the crawl: read now, unchanged, and those where a human edit was kept."
          },
          "pages_fresh": {
           "type": "integer",
           "description": "How many of them were read now — new and changed. Only these get saved."
          },
          "pages_unchanged": {
           "type": "integer",
           "description": "How many didn't change: they were not reread or saved again."
          },
          "pages_held": {
           "type": "integer",
           "description": "How many changed on the site but have a human edit: the edit was kept and the pages were flagged (`site_changed`)."
          },
          "pages_gone": {
           "type": "integer",
           "description": "How many pages disappeared from the site this time. They were removed from the agent's answers but not erased."
          },
          "pages_returned": {
           "type": "integer",
           "description": "How many previously disappeared pages came back to the site — the agent answers from them again."
          },
          "pages_scripted": {
           "type": "integer",
           "description": "How many pages are empty because their content is rendered by a script in the browser. The crawl has no browser, so there is no text from them."
          },
          "pages_skipped": {
           "type": "integer",
           "description": "How many pages were not read: the owner removed them from knowledge or turned off rereading for them."
          },
          "pages_left": {
           "type": "integer",
           "description": "How many pages that are NOT yet in knowledge the crawl didn't reach — it hit the page cap or ran out of time. The next read takes them first."
          },
          "pages_left_stored": {
           "type": "integer",
           "description": "How many pages the crawl didn't reach even though they are already in knowledge: this pass didn't check them for changes. Nothing is missing here."
          },
          "pages_stored": {
           "type": "integer",
           "description": "How many pages of this site are in knowledge in total after the read."
          },
          "left": {
           "type": "array",
           "items": {
            "type": "string"
           },
           "description": "The first of them by name (the list is capped)."
          },
          "out_of_time": {
           "type": "boolean",
           "description": "Stopped because of time, not the cap: reading again will continue from the unread pages."
          },
          "kept": {
           "type": "integer",
           "description": "The site answered \"not found\" for most of the stored pages at once — this looks like a site failure, so knowledge was left as it was. The number is how many such pages."
          },
          "page_limit": {
           "type": "integer",
           "description": "How many pages this pass took: as named in the request, but no more than the plan cap (`max_site_pages`)."
          },
          "pages_removed": {
           "type": "integer",
           "description": "How many duplicates were removed — sources holding the same page under a different spelling of the address (with and without a trailing slash, with and without \"www.\", with a utm tag). Pages that disappeared from the site are NOT erased from knowledge — see `pages_gone`."
          },
          "partial": {
           "type": "boolean",
           "description": "The crawl is incomplete: some pages were not reached (`pages_left`)."
          },
          "failed_count": {
           "type": "integer",
           "description": "How many pages didn't make it into knowledge: failed to open, disappeared, disallowed by the site, no text."
          },
          "failures": {
           "type": "array",
           "items": {
            "type": "object",
            "properties": {
             "url": {
              "type": "string"
             },
             "reason": {
              "type": "string"
             }
            }
           },
           "description": "Which ones and why (not all of them — the list is capped)."
          },
          "notice": {
           "type": "string",
           "description": "Human-readable summary: how many were found and where, how many were read, what failed to open and why, what didn't fit."
          },
          "refresh_days": {
           "type": "integer",
           "description": "Every how many days the read pages will be reread automatically. Absent — they won't be reread."
          },
          "api_spec_url": {
           "type": "string",
           "description": "An API specification was found on the site."
          },
          "api_docs_url": {
           "type": "string",
           "description": "API documentation was found on the site."
          },
          "api_actions": {
           "type": "integer",
           "description": "How many actions from it can be added."
          },
          "candidates": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/SkillCandidate"
           },
           "description": "Actions already built from the documentation: they can be added without importing again."
          },
          "error": {
           "type": "string"
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "No valid session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The role doesn't allow this action.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Agent not found, or it belongs to another workspace.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   },
   "post": {
    "tags": [
     "Dashboard · Knowledge"
    ],
    "summary": "Crawl a site",
    "description": "Reads the site's pages and turns them into knowledge sources. With `max_pages` greater than 1 it reads the whole site: pages come from the sitemap (sitemap.xml) and from links; with 1 — exactly the named page. The same page under a different spelling of the address (trailing slash, \"www.\", http/https, anchor, utm tags) is the same source, not a second one. Runs in the background — poll the status on the same path with `GET`.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "url": {
          "type": "string",
          "format": "uri"
         },
         "max_pages": {
          "type": "integer",
          "minimum": 1,
          "maximum": 500,
          "description": "How many pages of the site to read in this pass. Less than 1 → 1; more than the plan cap → the plan cap (`max_site_pages`: Free — 50, Starter — 150, Pro — 300, Business — 500). The cap also limits all of the site's pages in knowledge combined. Whatever didn't fit is named in the summary."
         },
         "refresh_days": {
          "type": "integer",
          "minimum": 0,
          "maximum": 180,
          "description": "Every how many days to reread what was read. NOT set — every 7 days: knowledge from an address nobody rereads goes stale silently. 0 — don't reread. The schedule is created after a successful read and only for those allowed to manage it (admin, key); a read by a member doesn't create a schedule. An existing schedule for the site isn't changed by a repeat read without this field."
         }
        },
        "required": [
         "url"
        ]
       }
      }
     }
    },
    "responses": {
     "202": {
      "description": "Crawl started.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "status": {
           "type": "string",
           "enum": [
            "scanning"
           ]
          },
          "url": {
           "type": "string"
          },
          "refresh_days": {
           "type": "integer",
           "description": "What the schedule will be after a successful read: once every this many days. 0: won't be re-read."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "No valid session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The role doesn't allow this action.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Agent not found, or it belongs to another workspace.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "409": {
      "description": "A site read for this agent is already in progress.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/secret": {
   "post": {
    "tags": [
     "Dashboard · Agents"
    ],
    "summary": "Reissue the server key",
    "description": "Issues a new `sk_` key for server-to-server calls. **The full key is returned exactly once** — after that the system only knows its fingerprint. The old key stops working immediately.\n\n**Not to be confused with `PUT /v1/dashboard/bots/{id}/secrets/{name}`** (plural). This endpoint reissues the agent's SECRET KEY and breaks the old one immediately — every integration using it stops working. That one stores a value for `{{secrets.NAME}}` substitution and breaks nothing. The paths differ by a single letter.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     }
    ],
    "responses": {
     "200": {
      "description": "The new key.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "secret_key": {
           "type": "string",
           "example": "sk_live_…"
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "No valid session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The role doesn't allow this action.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Agent not found, or it belongs to another workspace.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/skills": {
   "get": {
    "tags": [
     "Dashboard · Actions"
    ],
    "summary": "Agent actions",
    "description": "HTTP calls the agent can make on its own.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     }
    ],
    "responses": {
     "200": {
      "description": "Actions.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "skills": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/Skill"
           }
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "No valid session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The role doesn't allow this action.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Agent not found, or it belongs to another workspace.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   },
   "post": {
    "tags": [
     "Dashboard · Actions"
    ],
    "summary": "Add an action",
    "description": "The action's description is what the model uses to decide when to call it. Secrets go into headers and are not shown in responses.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/NewSkill"
       }
      }
     }
    },
    "responses": {
     "201": {
      "description": "Added.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "skill": {
           "$ref": "#/components/schemas/Skill"
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "No valid session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The role doesn't allow this action.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Agent not found, or it belongs to another workspace.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/skills/import": {
   "post": {
    "tags": [
     "Dashboard · Actions"
    ],
    "summary": "Import actions from a link",
    "description": "Reads the OpenAPI at the address and proposes candidate actions.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "url": {
          "type": "string",
          "format": "uri"
         }
        },
        "required": [
         "url"
        ]
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Candidates from the documentation.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "candidates": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/SkillCandidate"
           },
           "description": "**Candidates are NOT saved.** These are proposals for review: send each one you keep separately with `POST /v1/dashboard/bots/{id}/skills` as a `NewSkill` — and add authorization yourself, because the documentation doesn't contain it and can't."
          },
          "source": {
           "type": "string",
           "enum": [
            "openapi",
            "llm"
           ],
           "description": "`openapi` — a machine-readable specification was read, the fields are exact. `llm` — extracted from prose by the model, so check the addresses and parameters more carefully."
          }
         },
         "required": [
          "candidates",
          "source"
         ]
        }
       }
      }
     },
     "401": {
      "description": "No valid session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The role doesn't allow this action.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Agent not found, or it belongs to another workspace.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "422": {
      "description": "The link has neither a specification nor usable documentation (`unprocessable`).",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/skills/import-file": {
   "post": {
    "tags": [
     "Dashboard · Actions"
    ],
    "summary": "Import actions from documentation files",
    "description": "Accepts specification files. `base_url` is required if the documentation describes only paths without a host.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "multipart/form-data": {
       "schema": {
        "type": "object",
        "properties": {
         "file": {
          "type": "array",
          "items": {
           "type": "string",
           "format": "binary"
          }
         },
         "base_url": {
          "type": "string"
         },
         "install": {
          "type": "string",
          "enum": [
           "1"
          ],
          "description": "`1` — not only find actions but also install on the agent the ones that passed the check (summary in `installed`). Without the field — candidates only, as before."
         }
        },
        "required": [
         "file"
        ]
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Candidates from the uploaded files.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "candidates": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/SkillCandidate"
           },
           "description": "**Candidates are NOT saved.** These are proposals for review: send each one you keep separately with `POST /v1/dashboard/bots/{id}/skills` as a `NewSkill` — and add authorization yourself, because the documentation doesn't contain it and can't."
          },
          "files": {
           "type": "array",
           "description": "A summary FOR EACH file. In a batch, some files describe endpoints and others are overview texts with nothing to extract; one failure must not hide the candidates the rest produced.",
           "items": {
            "type": "object",
            "properties": {
             "name": {
              "type": "string"
             },
             "count": {
              "type": "integer",
              "description": "How many candidates this file produced."
             },
             "error": {
              "type": "string",
              "description": "Why nothing came out of it. Absent if everything is fine."
             }
            },
            "required": [
             "name",
             "count"
            ]
           }
          },
          "installed": {
           "type": "object",
           "description": "Only with `install=1`: what of the found actions was installed on the agent.",
           "properties": {
            "added": {
             "type": "integer"
            },
            "updated": {
             "type": "integer"
            },
            "rejected": {
             "type": "string",
             "description": "What didn't pass the check and why — in words."
            },
            "unchecked": {
             "type": "string",
             "description": "What was installed without a test call because it changes data."
            },
            "dropped": {
             "type": "integer",
             "description": "How many found calls were not taken because of the per-import cap."
            }
           }
          }
         },
         "required": [
          "candidates",
          "files"
         ]
        }
       }
      }
     },
     "401": {
      "description": "No valid session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The role doesn't allow this action.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Agent not found, or it belongs to another workspace.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "422": {
      "description": "`install=1`, but none of the found actions passed the check — nothing was installed.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/skills/presets": {
   "get": {
    "tags": [
     "Dashboard · Actions"
    ],
    "summary": "Ready-made action sets",
    "description": "Integrations you don't have to describe by hand.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     }
    ],
    "responses": {
     "200": {
      "description": "Sets.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "presets": {
           "type": "array",
           "items": {
            "type": "object",
            "properties": {
             "id": {
              "type": "string"
             },
             "title": {
              "type": "string"
             },
             "description": {
              "type": "string"
             },
             "emoji": {
              "type": "string"
             },
             "category": {
              "type": "string"
             },
             "inputs": {
              "type": "array",
              "items": {
               "type": "object",
               "properties": {
                "key": {
                 "type": "string",
                 "description": "Field name — the key in `inputs` when installing."
                },
                "label": {
                 "type": "string"
                },
                "placeholder": {
                 "type": "string"
                },
                "help": {
                 "type": "string"
                },
                "secret": {
                 "type": "boolean",
                 "description": "A field holding a key: display it as a password."
                },
                "optional": {
                 "type": "boolean"
                }
               }
              }
             },
             "installed": {
              "type": "boolean",
              "description": "The agent already has this integration's actions."
             }
            }
           }
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "No valid session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The role doesn't allow this action.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Agent not found, or it belongs to another workspace.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   },
   "post": {
    "tags": [
     "Dashboard · Actions"
    ],
    "summary": "Connect an action set",
    "description": "`inputs` — what the set needs: keys, identifiers. Secret values are not returned in later responses.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "preset_id": {
          "type": "string"
         },
         "inputs": {
          "type": "object",
          "additionalProperties": {
           "type": "string"
          }
         }
        },
        "required": [
         "preset_id"
        ]
       }
      }
     }
    },
    "responses": {
     "201": {
      "description": "Connected.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "skills": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/Skill"
           },
           "description": "All of the agent's actions after installation."
          },
          "updated": {
           "type": "integer",
           "description": "How many existing actions were replaced."
          },
          "added": {
           "type": "integer",
           "description": "How many actions were added."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "No valid session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The role doesn't allow this action.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Agent not found, or it belongs to another workspace.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "503": {
      "$ref": "#/components/responses/Unavailable"
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/skills/presets/{preset}/sync": {
   "post": {
    "tags": [
     "Dashboard · Actions"
    ],
    "summary": "Update an action set",
    "description": "Pulls in changes to the set while keeping the values entered earlier: descriptions, parameters and the long-running work protocol are updated, addresses and keys are not. A new action in the set that depends only on a key is added with the same key; a new action whose address carries your values (site address, chat ID, webhook address) is not added — its name comes back in `needs_setup`, and only reconnecting the integration adds it.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     },
     {
      "name": "preset",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      }
     }
    ],
    "responses": {
     "200": {
      "description": "Updated.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "required": [
          "updated",
          "added",
          "needs_setup"
         ],
         "properties": {
          "updated": {
           "type": "integer",
           "description": "How many existing actions were updated."
          },
          "added": {
           "type": "integer",
           "description": "How many new actions were added."
          },
          "needs_setup": {
           "type": "array",
           "items": {
            "type": "string"
           },
           "description": "New actions the update didn't add: they need your values. Reconnecting the integration with the same values adds them."
          },
          "note": {
           "type": "string",
           "description": "What to tell the owner when `needs_setup` is not empty."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "No valid session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The role doesn't allow this action.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Agent not found, or it belongs to another workspace.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/skills/{skillID}": {
   "patch": {
    "tags": [
     "Dashboard · Actions"
    ],
    "summary": "Change an action's access or timeout",
    "description": "Two fields the owner changes from the action list without rewriting the address and access keys — exactly the ones where a mistake disables the integration. Both are optional and independent; a request with neither of them is rejected rather than executed as a no-op. `admin_only` restricts the action to the authorized site owner. `timeout_sec` — how long to wait for a response; 0 restores the platform default.\n\nThe action can be edited IN PLACE: `name`, `description`, `params`, `headers`. Its `id`, address and limits stay — there's no need to delete and recreate the action just to change a description or a parameter. The edit is applied first: if it is rejected (name taken — 409, invalid parameter or name — 400), the other fields of the request change nothing either.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     },
     {
      "name": "skillID",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      }
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "admin_only": {
          "type": "boolean"
         },
         "timeout_sec": {
          "type": "integer",
          "minimum": 0,
          "maximum": 300
         },
         "url": {
          "type": "string",
          "description": "The action's new address. Third-party APIs move; the access keys stay in place."
         },
         "method": {
          "type": "string",
          "enum": [
           "GET",
           "POST"
          ],
          "description": "Read only together with url. No field — the action's method stays as it was."
         },
         "needs_approval": {
          "type": "boolean",
          "description": "Switch the action to require approval (or back). true — the agent no longer performs it on its own: the call becomes a card in the dashboard, and until the owner clicks, nothing has happened in the world."
         },
         "known_only": {
          "type": "boolean",
          "description": "The action is only for visitors the site has identified (passed an identifier — the `{{user_token}}` substitution). For a guest it isn't in the set at all: the assistant doesn't see it and won't call it. This is not proof of identity — the identifier is written by the page."
         },
         "name": {
          "type": "string",
          "description": "The action's new name (Latin letters, digits, `_`, `-`; up to 64). This is what the model calls it by, so it is unique within the agent — a taken name returns 409. The action's `id` doesn't change."
         },
         "description": {
          "type": "string",
          "description": "The new description for the model: when to call this action."
         },
         "params": {
          "type": "array",
          "description": "The full new list of parameters (a replacement, not an addition). An object or list parameter is described by its own schema in the `schema` field — with nested `properties` and `enum`.",
          "items": {
           "$ref": "#/components/schemas/SkillParamInput"
          }
         },
         "headers": {
          "type": "object",
          "additionalProperties": {
           "type": "string"
          },
          "description": "Full replacement of the action's headers (they hold the access keys). The `{{user_token}}` substitution works in values. Headers are never returned."
         },
         "status_label": {
          "type": "string",
          "description": "What the person sees in the window while the action is running (\"Building the diagram…\"). Up to 80 characters, one line; empty — the window's generic line."
         },
         "expose_result": {
          "type": "boolean",
          "description": "The action's raw result and its arguments are passed to the page code (`actions[].args`, `actions[].result`, the window event `action_result`). Off by default."
         }
        },
        "minProperties": 1
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Updated. Returns only the fields that were changed.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "admin_only": {
           "type": "boolean"
          },
          "timeout_sec": {
           "type": "integer"
          },
          "note": {
           "type": "string",
           "description": "What the number alone doesn't show: for example, that the timeout you set applies in a background run but never in a conversation. Empty when there's nothing to say. Show it — otherwise the owner is left with a setting that won't apply."
          },
          "known_only": {
           "type": "boolean",
           "description": "The action is only for visitors the site has identified (passed an identifier — the `{{user_token}}` substitution). For a guest it isn't in the set at all: the assistant doesn't see it and won't call it. This is not proof of identity — the identifier is written by the page."
          },
          "name": {
           "type": "string"
          },
          "description": {
           "type": "string"
          },
          "params": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/SkillParam"
           }
          },
          "headers_replaced": {
           "type": "boolean",
           "description": "Headers were replaced. The headers themselves are not included in the response."
          },
          "status_label": {
           "type": "string",
           "description": "What the person sees in the window while the action is running (\"Building the diagram…\"). Up to 80 characters, one line; empty — the window's generic line."
          },
          "expose_result": {
           "type": "boolean",
           "description": "The action's raw result and its arguments are passed to the page code (`actions[].args`, `actions[].result`, the window event `action_result`). Off by default."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "No valid session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The role doesn't allow this action.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Agent not found, or it belongs to another workspace.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "400": {
      "description": "No field was named, or the timeout is outside 0…300 s.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "409": {
      "description": "The agent already has an action with this name.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   },
   "delete": {
    "tags": [
     "Dashboard · Actions"
    ],
    "summary": "Delete an action",
    "description": "The agent no longer sees it in its set.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     },
     {
      "name": "skillID",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      }
     }
    ],
    "responses": {
     "200": {
      "description": "Deleted.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "status": {
           "type": "string",
           "enum": [
            "deleted"
           ]
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "No valid session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The role doesn't allow this action.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Agent not found, or it belongs to another workspace.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/skills/{skillID}/test": {
   "post": {
    "tags": [
     "Dashboard · Actions"
    ],
    "summary": "Test an action",
    "description": "Makes a real call with the given arguments and shows the raw response. This is how you catch a mistake in the description before a visitor finds it.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     },
     {
      "name": "skillID",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      }
     }
    ],
    "requestBody": {
     "required": false,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "args": {
          "type": "object",
          "additionalProperties": true,
          "description": "The same arguments object the model would build. An empty body is a valid test: the action may have no parameters."
         }
        }
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "The call result. 200 even when the action failed: the request TO US succeeded, and the outcome is in the body.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "result": {
           "$ref": "#/components/schemas/SkillTest"
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "No valid session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The role doesn't allow this action.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Agent not found, or it belongs to another workspace.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/rehearse": {
   "post": {
    "tags": [
     "Dashboard · Agent flow"
    ],
    "summary": "Rehearsal: what the agent would answer and what it would do",
    "description": "The agent goes through the run for real, but RECORDS every outbound action instead of performing it: no order is placed, no email is sent, no card is written, no operator is called. Two kinds. With `message` — a CONVERSATION: what the agent would answer the customer to this message (role — visitor). With `trigger_id` — a BACKGROUND run of that schedule: what it will do when it wakes up, with its own task and on behalf of the owner; the agent's memory cursor doesn't move. History, cache and memory are not touched — a rehearsal leaves no trace. Reads (knowledge, search, read cards) are performed for real, otherwise the answer wouldn't be the agent's answer. The money for the model run is real: it is logged as \"rehearsal\" and charged like a regular run. Available to every workspace member.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "message": {
          "type": "string",
          "description": "The customer's message — as they would write it. A conversation rehearsal."
         },
         "trigger_id": {
          "type": "string",
          "description": "A schedule from the agent's list of triggers. A background run rehearsal; message is not needed then."
         }
        },
        "description": "One of the two is required: message or trigger_id."
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Rehearsal completed",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "required": [
          "answer",
          "would_do"
         ],
         "properties": {
          "answer": {
           "type": "string",
           "description": "What the agent would answer (conversation) or how the run would end (background)."
          },
          "would_do": {
           "type": "array",
           "items": {
            "type": "string"
           },
           "description": "Outbound actions, in the order the agent would perform them, with arguments. An empty array means \"nothing external\", and that is an answer too."
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "Neither a message nor a schedule — or this agent has no such schedule"
     },
     "401": {
      "description": "Sign-in required"
     },
     "403": {
      "description": "Wrong key type"
     },
     "502": {
      "description": "The model didn't respond"
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/source": {
   "get": {
    "tags": [
     "Dashboard · Knowledge"
    ],
    "summary": "A single source",
    "description": "The full text of the source.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     },
     {
      "name": "source_id",
      "in": "query",
      "required": true,
      "schema": {
       "type": "string"
      }
     }
    ],
    "responses": {
     "200": {
      "description": "The full text of the source.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "source_id": {
           "type": "string"
          },
          "title": {
           "type": "string"
          },
          "text": {
           "type": "string",
           "description": "The whole text, as search sees it."
          }
         },
         "required": [
          "source_id",
          "title",
          "text"
         ]
        }
       }
      }
     },
     "401": {
      "description": "No valid session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The role doesn't allow this action.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Agent not found, or it belongs to another workspace.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "503": {
      "$ref": "#/components/responses/Unavailable"
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/sources": {
   "get": {
    "tags": [
     "Dashboard · Knowledge"
    ],
    "summary": "Knowledge sources",
    "description": "Everything the agent has been taught.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     },
     {
      "$ref": "#/components/parameters/PageLimit"
     },
     {
      "$ref": "#/components/parameters/PageCursor"
     }
    ],
    "responses": {
     "200": {
      "description": "Sources.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "sources": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/Source"
           }
          },
          "next_cursor": {
           "type": "string",
           "description": "Cursor for the next page. AN EMPTY STRING means there are no more pages (not `null`)."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "No valid session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The role doesn't allow this action.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Agent not found, or it belongs to another workspace.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   },
   "post": {
    "tags": [
     "Dashboard · Knowledge"
    ],
    "summary": "Add text",
    "description": "A text source written by hand.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "title": {
          "type": "string"
         },
         "text": {
          "type": "string"
         },
         "source_id": {
          "type": "string",
          "description": "Your own topic identifier. Empty — the server derives it from the CONTENT: the same text for the same agent is the same source, so a repeated request (double click, retry after a dropped connection) doesn't leave a copy."
         }
        },
        "required": [
         "title",
         "text"
        ]
       }
      }
     }
    },
    "responses": {
     "202": {
      "description": "Accepted for indexing. `source_id` is the same identifier you later need for `PUT` and `DELETE`; without it you'd have to look up the just-added row in the list by title, and titles aren't unique.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "status": {
           "type": "string",
           "enum": [
            "indexed"
           ]
          },
          "source_id": {
           "type": "string"
          },
          "existed": {
           "type": "boolean",
           "description": "`true`: this agent already had a source with exactly the same text; nothing was written, and `source_id` names the existing one. Only when `source_id` in the request is empty."
          },
          "title": {
           "type": "string",
           "description": "The title this text is already stored under. Only together with `existed: true`."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "No valid session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The role doesn't allow this action.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Agent not found, or it belongs to another workspace.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "413": {
      "description": "The text is too large for one source (`knowledge_too_large`): a retry won't succeed; splitting it into several topics will.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "503": {
      "description": "The knowledge store isn't accepting writes right now. `knowledge_store_busy` — overloaded: the server already retried the write several times; it should go through within a minute. `service_unavailable` — a failure or refusal on the platform side. Nothing changed in knowledge.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   },
   "put": {
    "tags": [
     "Dashboard · Knowledge"
    ],
    "summary": "Update a source",
    "description": "Rewrites the content; the agent will see the new version after reindexing.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "source_id": {
          "type": "string"
         },
         "title": {
          "type": "string",
          "description": "Topic title. No field or empty — the title stays as it was."
         },
         "text": {
          "type": "string"
         }
        },
        "required": [
         "source_id"
        ]
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Updated.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "status": {
           "type": "string",
           "enum": [
            "updated"
           ]
          },
          "source_id": {
           "type": "string"
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "No valid session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The role doesn't allow this action.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Agent not found, or it belongs to another workspace.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "503": {
      "$ref": "#/components/responses/Unavailable"
     }
    }
   },
   "delete": {
    "tags": [
     "Dashboard · Knowledge"
    ],
    "summary": "Delete a source",
    "description": "The identifier goes in a **query parameter**, not in the path: for pages taken from a site it is an address, and the slashes would break the path.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     },
     {
      "name": "source_id",
      "in": "query",
      "required": true,
      "schema": {
       "type": "string"
      }
     }
    ],
    "responses": {
     "200": {
      "description": "Deleted.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "status": {
           "type": "string",
           "enum": [
            "deleted"
           ]
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "No valid session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The role doesn't allow this action.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Agent not found, or it belongs to another workspace.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "503": {
      "$ref": "#/components/responses/Unavailable"
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/knowledge/duplicates": {
   "get": {
    "tags": [
     "Dashboard · Knowledge"
    ],
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     }
    ],
    "summary": "Identical sources and repetitions",
    "description": "Compares the agent's sources with each other and each one with itself. Changes nothing: shows which sources have the same text and in which the text repeats. Cleanup is done by `POST …/knowledge/duplicates/clean` — whatever the person names.",
    "responses": {
     "200": {
      "description": "What was found.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/KnowledgeDuplicates"
        }
       }
      }
     },
     "401": {
      "description": "No valid session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The role doesn't allow this action.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Agent not found.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "500": {
      "description": "Couldn't compare the sources.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/knowledge/duplicates/clean": {
   "post": {
    "tags": [
     "Dashboard · Knowledge"
    ],
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     }
    ],
    "summary": "Remove copies and repetitions",
    "description": "Removes the named copies (`remove`) and keeps the text only once in the named sources (`fold`). The server checks what was named again: a source that is no longer a copy at that moment is left alone; from each group of identical sources at least one is kept, even if all of them were named. Every change goes into the change log and can be undone.",
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "remove": {
          "type": "array",
          "items": {
           "type": "string"
          },
          "description": "Identifiers of the copies to remove."
         },
         "fold": {
          "type": "array",
          "items": {
           "type": "string"
          },
          "description": "Identifiers of the sources in which to remove repeated text."
         }
        },
        "additionalProperties": false
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "What was removed and what was left alone.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/KnowledgeDuplicatesCleaned"
        }
       }
      }
     },
     "400": {
      "description": "Neither copies nor sources with repetitions were named, or the body contains an unknown field.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "description": "No valid session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The role doesn't allow this action.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Agent not found.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "500": {
      "description": "Couldn't compare the sources.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/knowledge/names": {
   "get": {
    "tags": [
     "Dashboard · Knowledge"
    ],
    "summary": "Names the agent knows",
    "description": "The knowledge index: names and terms from the agent's materials — products, plans, standards, abbreviations, names.\n\nThe platform builds it itself, by rules, as soon as a source is added: a name gets here because it was in quotes, in a heading, in the first column of a table, was an abbreviation, a standard designation or a word in another alphabet. For knowledge added earlier, the list is built in the background after the agent's first conversation — so right after an update it may be empty.\n\nWhy the agent needs this. The weightiest names go into the prompt of every run — the agent knows that «Купина» (\"Kupyna\") comes from its materials and goes searching instead of answering from general knowledge. And a query containing a name from here finds the place where it is defined, **in any spelling and grammatical case**: «Купину», \"Kupyna\", «ДСТУ 7564» (\"DSTU 7564\") and \"7564\" all lead to the same place.\n\nWeightiest first: names from quotes and standard designations first, then abbreviations, then headings.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     },
     {
      "name": "q",
      "in": "query",
      "required": false,
      "schema": {
       "type": "string"
      },
      "description": "Search: any spelling of the name or its beginning."
     },
     {
      "name": "limit",
      "in": "query",
      "required": false,
      "schema": {
       "type": "integer",
       "default": 50,
       "maximum": 200
      },
      "description": "How many names per page."
     },
     {
      "name": "offset",
      "in": "query",
      "required": false,
      "schema": {
       "type": "integer",
       "default": 0
      },
      "description": "Which name to start from (the `next_offset` value of the previous page)."
     }
    ],
    "responses": {
     "200": {
      "description": "A page of the name list.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "required": [
          "names",
          "total",
          "next_offset"
         ],
         "properties": {
          "names": {
           "type": "array",
           "items": {
            "type": "object",
            "required": [
             "name",
             "forms",
             "about",
             "sources",
             "same",
             "by_owner"
            ],
            "properties": {
             "name": {
              "type": "string",
              "description": "The name as it is most reliably spelled in the materials."
             },
             "forms": {
              "type": "array",
              "items": {
               "type": "string"
              },
              "description": "Other spellings found in the materials: in another alphabet, in another grammatical case, with the standard's year."
             },
             "about": {
              "type": "string",
              "description": "The sentence from the materials where the name is defined (or a table row). Empty if the name is only mentioned."
             },
             "sources": {
              "type": "integer",
              "description": "How many knowledge sources contain the name."
             },
             "same": {
              "type": "array",
              "items": {
               "type": "string"
              },
              "description": "Names that mean the same thing: the link was found in the materials («Купина» (\"Kupyna\") — DSTU 7564) or named by the owner."
             },
             "by_owner": {
              "type": "boolean",
              "description": "The spelling was named by the owner, not found in the materials. Only these can be removed with `unlink`."
             }
            }
           }
          },
          "total": {
           "type": "integer",
           "description": "How many names in total match this search."
          },
          "next_offset": {
           "type": "integer",
           "description": "Where to read from next; 0 — the list is exhausted."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "No valid session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The role doesn't allow this action.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Agent not found.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/knowledge/names/link": {
   "post": {
    "tags": [
     "Dashboard · Knowledge"
    ],
    "summary": "Merge spellings into one name",
    "description": "Admin only. Tells the platform that several spellings mean one thing: «Купина» (\"Kupyna\"), «Неопалима» (\"Neopalyma\"), «хеш ДСТУ» (\"DSTU hash\").\n\nOnly needed for genuinely **different words** for one thing. The platform handles letter case, grammatical case and alphabet itself: «Купина», «купиною» and \"Kupyna\" are already one name and don't need merging (a request with two such spellings is rejected like a request with one).\n\nAfter this, a query with any of the merged spellings finds the places where the others are defined. The agent's saved answers are reset.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "required": [
         "names"
        ],
        "properties": {
         "names": {
          "type": "array",
          "minItems": 2,
          "maxItems": 12,
          "items": {
           "type": "string"
          },
          "description": "All spellings of one name, at least two distinct ones."
         }
        }
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Spellings merged.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "required": [
          "names"
         ],
         "properties": {
          "names": {
           "type": "array",
           "items": {
            "type": "string"
           },
           "description": "The spellings that were merged (without duplicates)."
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "Fewer than two distinct spellings or more than twelve were named.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "description": "No valid session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The role doesn't allow this action.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Agent not found, or there is no such spelling among the merged ones.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/knowledge/names/unlink": {
   "post": {
    "tags": [
     "Dashboard · Knowledge"
    ],
    "summary": "Remove a merged spelling",
    "description": "Admin only. Removes a spelling the owner merged earlier, together with its links.\n\nNames found in the materials themselves can't be removed this way: they disappear only together with the source text.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "required": [
         "name"
        ],
        "properties": {
         "name": {
          "type": "string",
          "description": "The spelling to remove."
         }
        }
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Spelling removed.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "required": [
          "removed"
         ],
         "properties": {
          "removed": {
           "type": "boolean"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "No spelling was named.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "description": "No valid session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The role doesn't allow this action.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Agent not found, or there is no such spelling among the merged ones.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/site-plans": {
   "get": {
    "tags": [
     "Dashboard · Knowledge"
    ],
    "summary": "Automatic reread schedules",
    "description": "Which sites the agent rereads on its own and how often. An empty list means what was read stays as it was on the day of the crawl.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      }
     }
    ],
    "responses": {
     "200": {
      "description": "Schedules.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "plans": {
           "type": "array",
           "items": {
            "type": "object",
            "properties": {
             "site": {
              "type": "string",
              "description": "The site's origin (scheme + host): the site is crawled, not a single address."
             },
             "every_days": {
              "type": "integer",
              "description": "Every how many days to reread. 0 = don't reread; this is a deliberate answer, not \"not configured\"."
             },
             "last_at": {
              "type": "string",
              "format": "date-time",
              "description": "When it was last crawled. Absent until there has been a crawl."
             }
            }
           }
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "No valid session — log in again.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "Wrong key type, or the role doesn't allow it.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "The agent doesn't exist or isn't yours.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "503": {
      "$ref": "#/components/responses/Unavailable"
     }
    }
   },
   "put": {
    "tags": [
     "Dashboard · Knowledge"
    ],
    "summary": "Turn automatic site rereading on or off",
    "description": "A site is scanned ONCE — after that its prices change while the knowledge stays the same, and the bot confidently quotes last year's prices. Every crawl spends the tenant's credits, so the schedule requires the admin role, and 0 days removes it.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      }
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "required": [
         "site",
         "every_days"
        ],
        "properties": {
         "site": {
          "type": "string"
         },
         "every_days": {
          "type": "integer",
          "minimum": 0,
          "maximum": 365,
          "description": "Required: a request without it gets 400 rather than removing the schedule. 0 removes the schedule."
         }
        }
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Saved.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "plan": {
           "type": "object",
           "properties": {
            "site": {
             "type": "string",
             "description": "The site's origin (scheme + host): the site is crawled, not a single address."
            },
            "every_days": {
             "type": "integer",
             "description": "Every how many days to reread. 0 = don't reread; this is a deliberate answer, not \"not configured\"."
            },
            "last_at": {
             "type": "string",
             "format": "date-time",
             "description": "When it was last crawled. Absent until there has been a crawl."
            }
           }
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "No address given, or the interval is outside 0–365.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "description": "No valid session — log in again.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The current user's role doesn't allow this action.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "503": {
      "description": "Automatic rereading is not included in this build.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/state": {
   "get": {
    "tags": [
     "Dashboard · Triggers"
    ],
    "summary": "Agent memory",
    "description": "A key-value store where the agent keeps cursors and counters between runs. `version` is required for writing.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     }
    ],
    "responses": {
     "200": {
      "description": "Status.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/AgentState"
        }
       }
      }
     },
     "401": {
      "description": "No valid session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The role doesn't allow this action.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Agent not found, or it belongs to another workspace.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   },
   "put": {
    "tags": [
     "Dashboard · Triggers"
    ],
    "summary": "Write agent memory",
    "description": "Compare-and-swap: pass the `version` you just read. If the agent has changed the state itself in the meantime, the write is rejected rather than overwriting its work.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "values": {
          "type": "object",
          "additionalProperties": {
           "type": "string"
          }
         },
         "version": {
          "type": "integer"
         }
        },
        "required": [
         "values",
         "version"
        ]
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Saved.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "version": {
           "type": "integer"
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "No valid session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The role doesn't allow this action.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Agent not found, or it belongs to another workspace.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "409": {
      "description": "The version is stale — the state was changed concurrently. Read it again and retry.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/stats": {
   "get": {
    "tags": [
     "Dashboard · Agents"
    ],
    "summary": "Agent statistics",
    "description": "Conversations and spending by day.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     },
     {
      "name": "tz",
      "in": "query",
      "schema": {
       "type": "string",
       "example": "Europe/Kyiv"
      },
      "description": "Time zone used to split days. Without it — UTC."
     }
    ],
    "responses": {
     "200": {
      "description": "Statistics.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "stats": {
           "type": "object",
           "properties": {
            "conversations": {
             "type": "integer",
             "description": "Distinct conversations."
            },
            "messages": {
             "type": "integer",
             "description": "All messages — both the customer's and the agent's."
            },
            "user_messages": {
             "type": "integer",
             "description": "Only the customer's messages."
            },
            "recent_questions": {
             "type": "array",
             "items": {
              "type": "string"
             },
             "description": "The latest customer questions, newest first."
            },
            "daily": {
             "type": "array",
             "items": {
              "type": "object",
              "properties": {
               "date": {
                "type": "string",
                "format": "date"
               },
               "count": {
                "type": "integer",
                "description": "Conversations that day."
               }
              }
             },
             "description": "The last 7 days."
            }
           }
          }
         },
         "required": [
          "stats"
         ]
        }
       }
      }
     },
     "401": {
      "description": "No valid session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The role doesn't allow this action.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Agent not found, or it belongs to another workspace.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/telegram": {
   "get": {
    "tags": [
     "Dashboard · Connections"
    ],
    "summary": "Telegram for operators",
    "description": "The token is never returned — only a flag that it is set, and the bot's name.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     }
    ],
    "responses": {
     "200": {
      "description": "Settings.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/TelegramSupport"
        }
       }
      }
     },
     "401": {
      "description": "No valid session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The role doesn't allow this action.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Agent not found, or it belongs to another workspace.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   },
   "put": {
    "tags": [
     "Dashboard · Connections"
    ],
    "summary": "Save Telegram settings",
    "description": "A field missing from the body is not changed: the token, time zone and on-duty list stay as they were. Only `disconnect: true` disconnects the integration.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "bot_token": {
          "type": "string",
          "description": "Token from @BotFather. Empty — keep the current one."
         },
         "disconnect": {
          "type": "boolean",
          "description": "Disconnect Telegram: the token is erased."
         },
         "timezone": {
          "type": "string",
          "description": "Time zone of the on-duty schedule (IANA). No field or empty — keep the current one."
         },
         "agents": {
          "type": "array",
          "items": {
           "type": "object",
           "properties": {
            "chat_id": {
             "type": "string"
            },
            "name": {
             "type": "string"
            },
            "active": {
             "type": "boolean"
            },
            "shifts": {
             "type": "array",
             "items": {
              "type": "object",
              "properties": {
               "days": {
                "type": "array",
                "items": {
                 "type": "integer"
                },
                "description": "0=Sunday … 6=Saturday."
               },
               "from": {
                "type": "integer",
                "description": "Minutes from midnight."
               },
               "to": {
                "type": "integer"
               }
              }
             }
            }
           }
          },
          "description": "On-duty operators. The list you send replaces the current one entirely (`[]` removes everyone); no field — the on-duty operators stay as they were."
         }
        }
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Saved.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/TelegramSupport"
        }
       }
      }
     },
     "401": {
      "description": "No valid session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The role doesn't allow this action.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Agent not found, or it belongs to another workspace.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "409": {
      "description": "This token is already connected to another agent in this workspace (`telegram_token_taken`). Telegram keeps one webhook per token, so a second connection would silently disconnect the first.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "502": {
      "description": "Telegram didn't respond or rejected the connection (`telegram_unreachable`). Two cases, told apart by the `saved` field. `saved: false` — the settings were NOT saved: body `{error, code, saved}`. `saved: true` — the settings WERE SAVED, but the channel doesn't work: the saved state (as in the 200 response) plus `error`, `code` and `saved`.",
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "allOf": [
            {
             "$ref": "#/components/schemas/Error"
            },
            {
             "type": "object",
             "properties": {
              "saved": {
               "type": "boolean",
               "description": "Whether the submitted settings were written. `false` — nothing changed; `true` — written, but the channel doesn't work.",
               "enum": [
                false
               ]
              }
             },
             "required": [
              "saved"
             ]
            }
           ]
          },
          {
           "allOf": [
            {
             "$ref": "#/components/schemas/TelegramSupport"
            },
            {
             "type": "object",
             "properties": {
              "error": {
               "type": "string",
               "description": "Human-readable reason."
              },
              "code": {
               "type": "string"
              },
              "saved": {
               "type": "boolean",
               "description": "Whether the submitted settings were written. `false` — nothing changed; `true` — written, but the channel doesn't work.",
               "enum": [
                true
               ]
              }
             },
             "required": [
              "error",
              "code",
              "saved"
             ]
            }
           ]
          }
         ]
        }
       }
      }
     },
     "503": {
      "$ref": "#/components/responses/Unavailable"
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/threads": {
   "get": {
    "tags": [
     "Dashboard · Requests"
    ],
    "summary": "Request queue",
    "description": "Search runs over the whole conversation on the server, so it finds a word said in the middle of a dialogue, not only in the last line.\n\nThe owner's personal conversations (`personal: true`) are shown to a member without admin rights as a row without text, and don't appear at all in word search.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     },
     {
      "name": "status",
      "in": "query",
      "required": false,
      "schema": {
       "type": "string",
       "enum": [
        "bot",
        "resolved",
        "all"
       ]
      },
      "description": "What to show. **Without the parameter — the queue**: `waiting` + `operator`, i.e. what is waiting for a human or already being handled. `bot` — conversations the bot handled ON ITS OWN (this is where \"why did it answer that way\" starts). `resolved` — closed. `all` — everything.\n\nThere are fewer status values here than in `Thread.status`, and that is intentional: the screen asks \"what to show\", not \"which status line\"."
     },
     {
      "name": "q",
      "in": "query",
      "required": false,
      "schema": {
       "type": "string"
      },
      "description": "Search the text of conversations."
     },
     {
      "name": "mark",
      "in": "query",
      "required": false,
      "schema": {
       "type": "string",
       "enum": [
        "contact",
        "unhappy"
       ]
      },
      "description": "Only conversations with a flag: `contact` — the customer left a contact, `unhappy` — their latest rating was \"not helpful\". Combines with `status` and `q`. Any other value — `400`."
     },
     {
      "$ref": "#/components/parameters/PageLimit"
     },
     {
      "$ref": "#/components/parameters/PageCursor"
     }
    ],
    "responses": {
     "200": {
      "description": "Requests.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "threads": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/Thread"
           }
          },
          "next_cursor": {
           "type": "string",
           "description": "Cursor for the next page. AN EMPTY STRING means there are no more pages (not `null`)."
          },
          "typing": {
           "type": "array",
           "items": {
            "type": "string"
           },
           "description": "session_id of the conversations where the customer is typing RIGHT NOW."
          },
          "drafts": {
           "type": "object",
           "properties": {},
           "additionalProperties": {
            "type": "string"
           },
           "description": "session_id → what the customer is typing but hasn't sent yet. Empty if draft preview is turned off in the agent's settings."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "No valid session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The role doesn't allow this action.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Agent not found, or it belongs to another workspace.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/threads/{sid}": {
   "get": {
    "tags": [
     "Dashboard · Requests"
    ],
    "summary": "A single request",
    "description": "The full conversation history.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     },
     {
      "name": "sid",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Conversation ID."
     }
    ],
    "responses": {
     "200": {
      "description": "The transcript and the state of the request.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "messages": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/Message"
           },
           "description": "The whole conversation, oldest to newest. There is no incremental read (`after`) here — the transcript is read in full."
          },
          "status": {
           "$ref": "#/components/schemas/HandoffStatus"
          },
          "thread": {
           "$ref": "#/components/schemas/Thread",
           "description": "The request itself — including `assignee_id`, i.e. whether someone has already taken it."
          },
          "visitor_typing": {
           "type": "boolean",
           "description": "The customer is typing right now."
          },
          "visitor_draft": {
           "type": "string",
           "description": "What the customer is typing but hasn't sent yet. Empty if draft preview is turned off."
          },
          "attachments": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/Attachment"
           },
           "description": "What the visitor sent in THIS conversation. A separate list rather than inside messages: a file belongs to the conversation, not to a message, and stitching it to the message nearest in time would be guessing. Each item has a timestamp — place them in the timeline yourself."
          }
         },
         "required": [
          "attachments",
          "messages",
          "status",
          "thread",
          "visitor_draft",
          "visitor_typing"
         ]
        }
       }
      }
     },
     "401": {
      "description": "No valid session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The role doesn't allow this action. The owner's personal conversation (`personal`) for a member without admin rights — `403` with an explanation: the conversation exists, but only admins see its content.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Agent not found, or it belongs to another workspace.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "503": {
      "$ref": "#/components/responses/Unavailable"
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/threads/{sid}/claim": {
   "post": {
    "tags": [
     "Dashboard · Requests"
    ],
    "summary": "Take or release a request",
    "description": "Take a request yourself — or release it.\n\nAn empty body means \"take it\". Who took it is shown in `thread.assignee_id`; compare it with `user_id` from `GET /v1/auth/me`.\n\nYou can take over someone else's request: a second call simply overwrites the assignee, with no conflict. This is deliberate — an operator who left the chat must not block the customer — but it means the queue is held by agreement within the team, not by the server.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     },
     {
      "name": "sid",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Conversation ID."
     }
    ],
    "requestBody": {
     "required": false,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "release": {
          "type": "boolean",
          "description": "`true` — remove the assignee and return the request to the queue."
         }
        }
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "The request after the change.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "thread": {
           "$ref": "#/components/schemas/Thread"
          }
         },
         "required": [
          "thread"
         ]
        }
       }
      }
     },
     "401": {
      "description": "No valid session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The role doesn't allow this action. The owner's personal conversation (`personal`) for a member without admin rights — `403` with an explanation: the conversation exists, but only admins see its content.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Agent not found, or it belongs to another workspace.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/threads/{sid}/reply": {
   "post": {
    "tags": [
     "Dashboard · Requests"
    ],
    "summary": "Reply as an operator",
    "description": "While a human is handling the conversation, the agent deliberately stays silent.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     },
     {
      "name": "sid",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Conversation ID."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "text": {
          "type": "string"
         }
        },
        "required": [
         "text"
        ]
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "The recorded message — with it you can append to the feed right away without re-reading the transcript, and later reconcile it by `id` with what arrives over the stream.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "message": {
           "$ref": "#/components/schemas/Message"
          }
         },
         "required": [
          "message"
         ]
        }
       }
      }
     },
     "401": {
      "description": "No valid session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The role doesn't allow this action. The owner's personal conversation (`personal`) for a member without admin rights — `403` with an explanation: the conversation exists, but only admins see its content.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Agent not found, or it belongs to another workspace.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "422": {
      "description": "This is a conversation of another program using an agent access key (`ak_`): it waits only for the answer to its own call and won't read a human's message. The reply was not recorded.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/threads/{sid}/resolve": {
   "post": {
    "tags": [
     "Dashboard · Requests"
    ],
    "summary": "Close a request",
    "description": "Returns the conversation to the agent.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     },
     {
      "name": "sid",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Conversation ID."
     }
    ],
    "responses": {
     "200": {
      "description": "Closed.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "status": {
           "type": "string",
           "enum": [
            "resolved"
           ]
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "No valid session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The role doesn't allow this action. The owner's personal conversation (`personal`) for a member without admin rights — `403` with an explanation: the conversation exists, but only admins see its content.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Agent not found, or it belongs to another workspace.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/threads/{sid}/typing": {
   "post": {
    "tags": [
     "Dashboard · Requests"
    ],
    "summary": "Operator is typing",
    "description": "Shows the visitor a typing indicator. Called often, so it is rate-limited.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     },
     {
      "name": "sid",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Conversation ID."
     }
    ],
    "responses": {
     "204": {
      "description": "Accepted."
     },
     "401": {
      "description": "No valid session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The role doesn't allow this action. The owner's personal conversation (`personal`) for a member without admin rights — `403` with an explanation: the conversation exists, but only admins see its content.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Agent not found, or it belongs to another workspace.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/triggers": {
   "get": {
    "tags": [
     "Dashboard · Triggers"
    ],
    "summary": "Agent triggers",
    "description": "Everything that can wake the agent.\n\n**`event`** — the agent reacts to an event of the platform itself: `run.failed`, `handoff.request`, `lead.captured`, `credits.low`, `mail.received` (a new email in a read-only mailbox; the `from` field narrows it to a sender). No address or secret is needed: the source is internal, and several agents can subscribe to one event.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     }
    ],
    "responses": {
     "200": {
      "description": "Triggers.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "triggers": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/Trigger"
           }
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "No valid session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The role doesn't allow this action.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Agent not found, or it belongs to another workspace.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   },
   "post": {
    "tags": [
     "Dashboard · Triggers"
    ],
    "summary": "Create a trigger",
    "description": "For `webhook`, the signing secret is returned **here and nowhere else**.\n\n**`event`** — the agent reacts to an event of the platform itself: `run.failed`, `handoff.request`, `lead.captured`, `credits.low`, `mail.received` (a new email in a read-only mailbox; the `from` field narrows it to a sender). No address or secret is needed: the source is internal, and several agents can subscribe to one event.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "required": [
         "type"
        ],
        "properties": {
         "type": {
          "type": "string",
          "enum": [
           "schedule",
           "webhook",
           "poll",
           "manual",
           "event"
          ],
          "description": "What wakes the agent. `schedule` — the clock. `webhook` — an external call. `poll` — its own check at a set rhythm (what exactly to check is defined by the graph steps, not the trigger). `manual` — a button. `event` — an event of the platform itself."
         },
         "name": {
          "type": "string"
         },
         "enabled": {
          "type": "boolean"
         },
         "input": {
          "type": "string",
          "description": "The task the agent wakes up with."
         },
         "cron": {
          "type": "string",
          "description": "Only for `schedule`. Runs in the agent's time zone, not in UTC."
         },
         "timezone": {
          "type": "string",
          "example": "Europe/Kyiv"
         },
         "event": {
          "type": "string",
          "enum": [
           "run.failed",
           "handoff.request",
           "lead.captured",
           "credits.low",
           "mail.received",
           "payment.received"
          ],
          "description": "Only for `type: event`: the platform event the agent is subscribed to. The list is closed — a made-up name would be a trigger that simply never fires. `mail.received` — an email arrived in a read-only mailbox (`replies: false`); the run's answer goes to the owner."
         },
         "from": {
          "type": "string",
          "description": "Only for `event: mail.received`: the trigger fires when the sender (address or name) contains this string, case-insensitively. Empty — any email. The filter runs on the platform side: an email \"from the wrong sender\" doesn't cost a run."
         },
         "sync": {
          "type": "boolean",
          "description": "Only for `webhook`: wait for the agent's answer instead of 202."
         },
         "interval_sec": {
          "type": "integer",
          "description": "Only for `poll`, from 30."
         }
        }
       }
      }
     }
    },
    "responses": {
     "201": {
      "description": "Created.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "trigger": {
           "$ref": "#/components/schemas/Trigger"
          },
          "secret": {
           "type": "string",
           "description": "Only for `webhook`, only on creation."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "No valid session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The role doesn't allow this action.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Agent not found, or it belongs to another workspace.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/triggers/{tid}": {
   "put": {
    "tags": [
     "Dashboard · Triggers"
    ],
    "summary": "Update a trigger",
    "description": "A field missing from the body is not changed: `{\"enabled\": false}` pauses the trigger and touches nothing else. A field sent empty (`\"name\": \"\"`) becomes empty. The trigger type doesn't change. A schedule change applies from the next tick.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     },
     {
      "name": "tid",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      }
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "description": "Only what changes.",
        "properties": {
         "type": {
          "type": "string",
          "enum": [
           "schedule",
           "webhook",
           "poll",
           "manual",
           "event"
          ],
          "description": "The type doesn't change. You can omit it; if sent, it must match the current one, otherwise `400`."
         },
         "name": {
          "type": "string"
         },
         "enabled": {
          "type": "boolean",
          "description": "Enable or pause. Enabling clears the auto-pause after failures."
         },
         "input": {
          "type": "string",
          "description": "The task the agent wakes up with."
         },
         "cron": {
          "type": "string",
          "description": "Only for `schedule`. Runs in the agent's time zone, not in UTC."
         },
         "timezone": {
          "type": "string",
          "example": "Europe/Kyiv"
         },
         "event": {
          "type": "string",
          "enum": [
           "run.failed",
           "handoff.request",
           "lead.captured",
           "credits.low",
           "mail.received",
           "payment.received"
          ],
          "description": "Only for `type: event`: the platform event the agent is subscribed to. The list is closed — a made-up name would be a trigger that simply never fires. `mail.received` — an email arrived in a read-only mailbox (`replies: false`); the run's answer goes to the owner."
         },
         "from": {
          "type": "string",
          "description": "Only for `event: mail.received`: the trigger fires when the sender (address or name) contains this string, case-insensitively. Empty — any email. The filter runs on the platform side: an email \"from the wrong sender\" doesn't cost a run."
         },
         "sync": {
          "type": "boolean",
          "description": "Only for `webhook`: wait for the agent's answer instead of 202."
         },
         "interval_sec": {
          "type": "integer",
          "description": "Only for `poll`, from 30."
         }
        }
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Updated.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "trigger": {
           "$ref": "#/components/schemas/Trigger"
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "No valid session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The role doesn't allow this action.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Agent not found, or it belongs to another workspace.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   },
   "delete": {
    "tags": [
     "Dashboard · Triggers"
    ],
    "summary": "Delete a trigger",
    "description": "Scheduled ticks are removed from the queue.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     },
     {
      "name": "tid",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      }
     }
    ],
    "responses": {
     "200": {
      "description": "Deleted."
     },
     "401": {
      "description": "No valid session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The role doesn't allow this action.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Agent not found, or it belongs to another workspace.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/triggers/{tid}/run": {
   "post": {
    "tags": [
     "Dashboard · Triggers"
    ],
    "summary": "Run now",
    "description": "A test run without waiting for the schedule. Without it, a scheduled agent can't be checked without waiting until morning.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     },
     {
      "name": "tid",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      }
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "input": {
          "type": "string",
          "description": "What to replace the trigger's usual task with. Empty = use its own."
         }
        }
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Run completed.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "run_id": {
           "type": "string"
          },
          "status": {
           "type": "string",
           "enum": [
            "done",
            "failed"
           ]
          },
          "answer": {
           "type": "string"
          },
          "error": {
           "type": "string"
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "No valid session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The role doesn't allow this action.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Agent not found, or it belongs to another workspace.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/dashboard/export": {
   "get": {
    "tags": [
     "Dashboard · Agents"
    ],
    "summary": "Export settings and contacts as one JSON (legacy endpoint)",
    "description": "LEGACY ENDPOINT. Returns a single JSON file with agent settings, contacts and a few other sections — as much as fits in one request. It does NOT include customer conversations, knowledge texts or files.\n\nThe full export is an archive built in the background: `POST /v1/dashboard/exports`. This endpoint remains for those who already call it from code.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "responses": {
     "200": {
      "description": "The archive — a JSON file for download (`Content-Disposition: attachment`).",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "additionalProperties": true,
         "description": "Workspace data for a human and for migration. The archive's shape is not part of the contract: don't parse it programmatically."
        }
       }
      }
     },
     "401": {
      "description": "No valid session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The role doesn't allow this action.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Agent not found, or it belongs to another workspace.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "deprecated": true
   }
  },
  "/v1/dashboard/invites": {
   "post": {
    "tags": [
     "Dashboard · Team"
    ],
    "summary": "Invite a person",
    "description": "`invite_url` is returned **only once**: the system stores only its fingerprint. A lost link can't be recovered — revoke it and create a new one.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "email": {
          "type": "string",
          "format": "email"
         },
         "role": {
          "type": "string",
          "enum": [
           "admin",
           "member"
          ],
          "description": "Empty — `member`. The owner isn't invited: there is only one per workspace."
         }
        },
        "required": [
         "email"
        ]
       }
      }
     }
    },
    "responses": {
     "201": {
      "description": "Invitation created.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "invite": {
           "$ref": "#/components/schemas/Invite"
          },
          "invite_url": {
           "type": "string"
          },
          "message": {
           "type": "string"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "Doesn't look like an email address, or there is no such role.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "description": "No valid session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The role doesn't allow this action.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Agent not found, or it belongs to another workspace.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "409": {
      "description": "This is the owner's own address, or this person is already on the team.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/dashboard/invites/{inviteID}": {
   "delete": {
    "tags": [
     "Dashboard · Team"
    ],
    "summary": "Revoke an invitation",
    "description": "The link stops working.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "inviteID",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      }
     }
    ],
    "responses": {
     "200": {
      "description": "Revoked.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "status": {
           "type": "string",
           "enum": [
            "revoked"
           ]
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "No valid session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The role doesn't allow this action.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Agent not found, or it belongs to another workspace.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/dashboard/join": {
   "post": {
    "tags": [
     "Dashboard · Team"
    ],
    "summary": "Accept an invitation",
    "description": "No role is passed here: the link itself is the permission, and it works only for the address it was issued to. Having your own workspace doesn't prevent joining: the person stays in it and also becomes a team member. From then on the person works in the workspace they joined — this is remembered in the account, on all their devices.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "token": {
          "type": "string"
         }
        },
        "required": [
         "token"
        ]
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Joined.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "status": {
           "type": "string",
           "enum": [
            "joined"
           ]
          },
          "role": {
           "$ref": "#/components/schemas/Role"
          },
          "workspace": {
           "type": "string",
           "description": "The workspace that was joined."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "No valid session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The role doesn't allow this action.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Agent not found, or it belongs to another workspace.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "409": {
      "description": "The invitation has already been used, or the person is already on this team.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "410": {
      "description": "The invitation has expired.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/dashboard/members": {
   "get": {
    "tags": [
     "Dashboard · Team"
    ],
    "summary": "Members and invitations",
    "description": "Only the owner can see the workspace's members.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "responses": {
     "200": {
      "description": "Members.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "members": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/Member"
           }
          },
          "invites": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/Invite"
           }
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "No valid session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The role doesn't allow this action.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Agent not found, or it belongs to another workspace.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/dashboard/members/{userID}": {
   "patch": {
    "tags": [
     "Dashboard · Team"
    ],
    "summary": "Change role",
    "description": "The role decides exactly one thing: what the person can change.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "userID",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      }
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "role": {
          "type": "string",
          "enum": [
           "admin",
           "member"
          ]
         }
        },
        "required": [
         "role"
        ]
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Updated.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "status": {
           "type": "string",
           "enum": [
            "updated"
           ]
          },
          "constructor_keys_revoked": {
           "type": "boolean",
           "description": "An admin left (removed or demoted) — the workspace's builder keys were revoked: they could have seen them. The owner pairs the MCP clients again."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "No valid session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The role doesn't allow this action.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Agent not found, or it belongs to another workspace.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   },
   "delete": {
    "tags": [
     "Dashboard · Team"
    ],
    "summary": "Remove a member",
    "description": "Access is revoked immediately, along with sessions.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "userID",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      }
     }
    ],
    "responses": {
     "200": {
      "description": "Removed.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "status": {
           "type": "string",
           "enum": [
            "removed"
           ]
          },
          "constructor_keys_revoked": {
           "type": "boolean",
           "description": "An admin left (removed or demoted) — the workspace's builder keys were revoked: they could have seen them. The owner pairs the MCP clients again."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "No valid session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The role doesn't allow this action.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Agent not found, or it belongs to another workspace.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/dashboard/graph/node-types": {
   "get": {
    "tags": [
     "Dashboard · Agent flow"
    ],
    "summary": "Step type catalog",
    "description": "The list is closed, and the editor shouldn't keep its own copy that will drift from it.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "responses": {
     "200": {
      "description": "Node kinds available in this build.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "node_types": {
           "type": "array",
           "items": {
            "type": "string",
            "enum": [
             "model",
             "fetch",
             "code"
            ]
           }
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "No valid session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The role doesn't allow this action.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Agent not found, or it belongs to another workspace.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/hooks/{tid}": {
   "post": {
    "tags": [
     "Triggers"
    ],
    "summary": "Wake an agent with a webhook",
    "operationId": "runWebhookTrigger",
    "security": [],
    "description": "Entry point for a webhook trigger: an external system sends an event — the agent wakes up and makes a run.\n\n**Where the address and secret come from.** In the dashboard, create a trigger of type `webhook` for the agent. In response you get `hook_url` (exactly this path) and `secret`. **The secret is shown once** — save it right away; if you lose it, create the trigger again.\n\n**Authentication is a signature, not a key.** `X-Bot-Key` is not used here. The `X-Hook-Signature` header contains `sha256=` + hex of `HMAC-SHA256(secret, raw request body)`. **Only the body** is signed — or, if you send the `X-Hook-Timestamp` header (Unix seconds), the string `timestamp.body`: `HMAC-SHA256(secret, \"1767225600.\" + body)`. A timestamp that differs from our clock by more than 5 minutes is not accepted (`401`).\n\nThe `triggerID` itself is unguessable, but the URL is not treated as a secret: it ends up in other systems' configs and logs. So without a valid signature it's `401`, always.\n\n```bash\nBODY='{\"order_id\":4417,\"status\":\"delayed\"}'\nSIG=$(printf '%s' \"$BODY\" | openssl dgst -sha256 -hmac \"$HOOK_SECRET\" -hex | awk '{print $2}')\n\ncurl -sS -X POST \"https://api.youselfbot.com/v1/hooks/trg_01j9x2h7q0\" \\\n  -H \"X-Hook-Signature: sha256=$SIG\" \\\n  -H \"Content-Type: application/json\" \\\n  -d \"$BODY\"\n```\n\n**What the agent sees.** The run's input is the task written in the trigger (the `input` field), plus the raw webhook body under the heading «Подія (тіло вебхука)» (\"Event (webhook body)\"). In other words, in the trigger you write *what to do*, and the webhook brings *what to do it with*.\n\n**Two modes.** Set by the trigger's `sync` field:\n\n* `sync: false` (default) — `202 Accepted` immediately, the run proceeds in the background. Almost always the right choice: external systems often have a short timeout, and an agent run can take minutes.\n* `sync: true` — we hold the connection until the run ends and return `200` with the agent's answer. Suitable when the caller needs the answer right away; set your own timeout.\n\n**Limits.** Body — up to 256 KiB. Up to 120 deliveries per minute from one address and up to 120 per trigger (beyond that — `429` with `Retry-After`). The trigger must be enabled: a disabled one (including automatically — after 5 failed runs in a row) responds `409`.\n\n**Retries.** The same delivery (the same body, and with `X-Hook-Timestamp` — the same body with the same timestamp) within 10 minutes **does not make a second run**: the response is `202` with `status: \"duplicate\"`. This way an intercepted request can't be replayed on your credits, and a retry after a dropped connection doesn't wake the agent twice. A delivery that didn't result in a run (`502`, `503`) goes through on retry. If your system needs to send identical bodies more often (a heartbeat), add `X-Hook-Timestamp`.",
    "parameters": [
     {
      "name": "tid",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "examples": [
        "trg_01j9x2h7q0"
       ]
      },
      "description": "The trigger identifier from `hook_url`."
     },
     {
      "name": "X-Hook-Signature",
      "in": "header",
      "required": true,
      "schema": {
       "type": "string",
       "examples": [
        "sha256=9b2f…"
       ]
      },
      "description": "`sha256=` + hex of `HMAC-SHA256(trigger secret, raw body)`. The `sha256=` prefix is optional — a bare hex is accepted too."
     },
     {
      "name": "X-Hook-Timestamp",
      "in": "header",
      "required": false,
      "schema": {
       "type": "string",
       "examples": [
        "1767225600"
       ]
      },
      "description": "Optional. Delivery time in Unix seconds. If the header is present, `X-Hook-Signature` is computed over `timestamp.body`, the timestamp must be within 5 minutes of our clock, and the same event with a new timestamp is a new delivery."
     }
    ],
    "requestBody": {
     "required": true,
     "description": "Any body for your event, up to 256 KiB. We don't parse or validate it — it goes into the agent's run as text.",
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "additionalProperties": true
       },
       "examples": {
        "default": {
         "summary": "An event from your system",
         "value": {
          "order_id": 4417,
          "status": "delayed",
          "customer": "olena@example.com"
         }
        }
       }
      },
      "text/plain": {
       "schema": {
        "type": "string"
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Synchronous mode (`sync: true`): the run finished, the agent's answer is in `answer`.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "required": [
          "run_id",
          "status"
         ],
         "properties": {
          "run_id": {
           "type": "string",
           "description": "Run identifier. The same id appears in the run log in the dashboard."
          },
          "status": {
           "type": "string",
           "enum": [
            "done"
           ]
          },
          "answer": {
           "type": "string",
           "description": "What the agent answered."
          }
         }
        },
        "examples": {
         "default": {
          "value": {
           "run_id": "run_01j9x2m4p8",
           "status": "done",
           "answer": "The customer has been notified; delivery has been moved to tomorrow."
          }
         }
        }
       }
      }
     },
     "202": {
      "description": "Asynchronous mode (default): the event was accepted, the run proceeds in the background. See the result in the run log in the dashboard. Or (in either mode) — a repeat delivery within the last 10 minutes: `status: \"duplicate\"`, no run.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "status": {
           "type": "string",
           "enum": [
            "accepted",
            "duplicate"
           ]
          }
         }
        },
        "examples": {
         "default": {
          "value": {
           "status": "accepted"
          }
         },
         "duplicate": {
          "summary": "Repeat delivery",
          "value": {
           "status": "duplicate"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "Couldn't read the request body.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "description": "The signature is missing or doesn't match. The most common cause — the HMAC was computed over reformatted JSON rather than the raw body. With `X-Hook-Timestamp` — also a timestamp more than 5 minutes off our clock, or a signature computed without it.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "examples": {
         "default": {
          "value": {
           "error": "invalid signature",
           "code": "unauthorized"
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "No such webhook trigger (deleted, or someone else's id).",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "examples": {
         "default": {
          "value": {
           "error": "unknown webhook",
           "code": "not_found"
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "The trigger is disabled. Either the owner disabled it manually, or the auto-pause kicked in after 5 failed runs in a row — enable it in the dashboard.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "examples": {
         "default": {
          "value": {
           "error": "the trigger is disabled",
           "code": "conflict"
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "Synchronous mode: the run did not happen — the workspace ran out of credits or hit the workspace or agent spending cap. The delivery is not counted as accepted: the same request will go through after a top-up instead of coming back as `duplicate`.",
      "content": {
       "application/json": {
        "schema": {
         "allOf": [
          {
           "$ref": "#/components/schemas/Error"
          },
          {
           "type": "object",
           "properties": {
            "run_id": {
             "type": "string"
            },
            "status": {
             "type": "string",
             "enum": [
              "failed"
             ]
            }
           }
          }
         ]
        },
        "examples": {
         "default": {
          "value": {
           "run_id": "run_01j9x2m4p8",
           "status": "failed",
           "error": "the workspace is out of credits — the run did not happen",
           "code": "quota_exceeded"
          }
         }
        }
       }
      }
     },
     "413": {
      "$ref": "#/components/responses/PayloadTooLarge"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     },
     "502": {
      "description": "Synchronous mode: the agent's run failed. `run_id` tells you which one — details are in the run log.",
      "content": {
       "application/json": {
        "schema": {
         "allOf": [
          {
           "$ref": "#/components/schemas/Error"
          },
          {
           "type": "object",
           "properties": {
            "run_id": {
             "type": "string"
            },
            "status": {
             "type": "string",
             "enum": [
              "failed"
             ]
            }
           }
          }
         ]
        },
        "examples": {
         "default": {
          "value": {
           "run_id": "run_01j9x2m4p8",
           "status": "failed",
           "error": "The agent couldn't complete the run. What exactly happened is in the dashboard run log, under this run_id.",
           "code": "service_unavailable"
          }
         }
        }
       }
      }
     },
     "503": {
      "$ref": "#/components/responses/Unavailable"
     }
    }
   }
  },
  "/v1/openapi.json": {
   "get": {
    "tags": [
     "Service"
    ],
    "summary": "This specification",
    "description": "The OpenAPI document itself, with the server URL filled in. Served without authentication.\n\nIn two languages: the English one is the same document with only the descriptions, section names and examples translated; paths, parameters, schemas, `required` and `enum` are byte-for-byte identical. The language follows `lang`, otherwise `Accept-Language`; with neither, Ukrainian. The response carries `Content-Language` and `Vary: Accept-Language`.",
    "security": [],
    "parameters": [
     {
      "name": "lang",
      "in": "query",
      "required": false,
      "description": "Language of the descriptions: `en` or `uk`. Takes precedence over `Accept-Language`.",
      "schema": {
       "type": "string",
       "enum": [
        "uk",
        "en"
       ]
      }
     },
     {
      "name": "Accept-Language",
      "in": "header",
      "required": false,
      "description": "Without `lang`: `en…` gives English, anything else Ukrainian.",
      "schema": {
       "type": "string"
      }
     }
    ],
    "responses": {
     "200": {
      "description": "The specification."
     }
    }
   }
  },
  "/v1/telegram/webhook/{secret}": {
   "post": {
    "tags": [
     "Service"
    ],
    "summary": "Incoming Telegram webhook",
    "description": "Called by Telegram, not by you. The secret in the path is what proves where the call came from.",
    "security": [],
    "parameters": [
     {
      "name": "secret",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      }
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "additionalProperties": true
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Accepted."
     },
     "413": {
      "description": "Body larger than 1 MiB (`payload_too_large`). Telegram updates take a few kilobytes.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/widget/chat": {
   "post": {
    "tags": [
     "Widget"
    ],
    "summary": "Visitor message",
    "description": "The same as `POST /v1/api/chat`, but with the publishable key and a domain check. The response likewise has three modes: a regular answer, a human is handling the conversation, the limit is exhausted.",
    "security": [
     {
      "widgetKey": []
     }
    ],
    "parameters": [
     {
      "name": "X-Bot-Key",
      "in": "header",
      "required": true,
      "schema": {
       "type": "string",
       "example": "pk_…"
      },
      "description": "The agent's publishable key."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/ChatRequest"
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "The agent's answer.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/ChatResponse"
        }
       }
      }
     },
     "401": {
      "description": "Unknown key.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "Domain not allowed.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "429": {
      "description": "Rate limit exceeded.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "503": {
      "description": "The AI backend is unavailable (`llm_unavailable` — key or funds, the owner needs to act) or overloaded (`llm_overloaded` — worth retrying after `Retry-After`). Tell them apart by `code`. If storage (not the model) is unavailable, `code` = `unavailable`: retry the same request in a moment.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "examples": {
         "unavailable": {
          "summary": "Invalid key or exhausted funds",
          "value": {
           "error": "The assistant is temporarily unavailable. We already know about it — please try again a little later.",
           "code": "llm_unavailable",
           "session_id": "3f6c1b9e-7f42-4d2a-9a6f-0d5b1f0b21c7"
          }
         },
         "overloaded": {
          "summary": "Overload: retry after Retry-After",
          "value": {
           "error": "There are too many requests right now, and the answer did not arrive in time. Please send your message again.",
           "code": "llm_overloaded",
           "retry_after": 20,
           "session_id": "3f6c1b9e-7f42-4d2a-9a6f-0d5b1f0b21c7"
          }
         }
        }
       }
      },
      "headers": {
       "Retry-After": {
        "description": "How many seconds to wait before retrying. Comes only with `llm_overloaded`.",
        "schema": {
         "type": "integer"
        }
       }
      }
     }
    }
   }
  },
  "/v1/widget/chat/stream": {
   "post": {
    "tags": [
     "Widget"
    ],
    "summary": "Visitor message (streaming)",
    "description": "`text/event-stream`: the answer arrives in parts. The frames are described by the `StreamFrame` schema. The turn is not cut short when the client closes the connection mid-answer (reloads the page): the assistant finishes, the answer is saved to the conversation, and it can be read back via `GET /v1/widget/reply`.",
    "security": [
     {
      "widgetKey": []
     }
    ],
    "parameters": [
     {
      "name": "X-Bot-Key",
      "in": "header",
      "required": true,
      "schema": {
       "type": "string",
       "example": "pk_…"
      },
      "description": "The agent's publishable key."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/ChatRequest"
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Stream of frames."
     },
     "401": {
      "description": "The agent key is unknown or revoked.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "Wrong key type, or the domain is not on the agent's allowed list.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/widget/config": {
   "get": {
    "tags": [
     "Widget"
    ],
    "summary": "Widget settings",
    "description": "Appearance, greeting and which actions are available. Read before the first message.",
    "security": [
     {
      "widgetKey": []
     }
    ],
    "parameters": [
     {
      "name": "X-Bot-Key",
      "in": "header",
      "required": true,
      "schema": {
       "type": "string",
       "example": "pk_…"
      },
      "description": "The agent's publishable key."
     }
    ],
    "responses": {
     "200": {
      "description": "Settings.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/WidgetConfig"
        }
       }
      }
     },
     "401": {
      "description": "Unknown key.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The domain is not on the allowed list.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/widget/feedback": {
   "post": {
    "tags": [
     "Widget"
    ],
    "summary": "Rate an answer",
    "description": "Thumbs up/down under an agent message. If `session` is given, the operator sees the rating as a line in the transcript — under the answer whose text matches `answer`.",
    "security": [
     {
      "widgetKey": []
     }
    ],
    "parameters": [
     {
      "name": "X-Bot-Key",
      "in": "header",
      "required": true,
      "schema": {
       "type": "string",
       "example": "pk_…"
      },
      "description": "The agent's publishable key."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "session": {
          "type": "string",
          "description": "Conversation identifier. Also accepted as `session_id`."
         },
         "rating": {
          "type": "string",
          "enum": [
           "up",
           "down"
          ],
          "description": "`up` — helpful, `down` — not helpful."
         },
         "question": {
          "type": "string",
          "description": "The question that was answered."
         },
         "answer": {
          "type": "string",
          "description": "The text of the rated answer — used to attach the rating to the message in the transcript."
         }
        },
        "required": [
         "rating"
        ]
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Rating recorded.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "required": [
          "offer"
         ],
         "properties": {
          "offer": {
           "type": "string",
           "enum": [
            "",
            "operator",
            "contacts",
            "lead"
           ],
           "description": "What to offer the person after a \"not helpful\" rating: `operator` — call a human, `contacts` — contact buttons, `lead` — leave a contact. Empty — nothing (the rating was positive, or the owner hasn't enabled any of these)."
          }
         }
        }
       }
      }
     },
     "204": {
      "description": "Ratings are not included in this build — the request is accepted silently."
     },
     "401": {
      "description": "The agent key is unknown or revoked.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "Wrong key type, or the domain is not on the agent's allowed list.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/widget/handoff": {
   "post": {
    "tags": [
     "Widget"
    ],
    "summary": "Call a human",
    "description": "Puts the conversation in the operator queue.",
    "security": [
     {
      "widgetKey": []
     }
    ],
    "parameters": [
     {
      "name": "X-Bot-Key",
      "in": "header",
      "required": true,
      "schema": {
       "type": "string",
       "example": "pk_…"
      },
      "description": "The agent's publishable key."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "session_id": {
          "type": "string"
         }
        },
        "required": [
         "session_id"
        ]
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "The session has been queued for an operator.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "required": [
          "status",
          "ack"
         ],
         "properties": {
          "status": {
           "type": "string",
           "enum": [
            "waiting"
           ]
          },
          "ack": {
           "type": "string",
           "description": "What to tell the visitor: the same promise they hear after typing «оператор» (\"operator\") (someone is on shift, a reply later, or after quiet hours), in the visitor's language."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "The agent key is unknown or revoked.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "Wrong key type, or the domain is not on the agent's allowed list.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "409": {
      "description": "This `session_id` already belongs to another agent (`session_taken`). You choose the conversation identifier: take an unpredictable one (a uuid), not \"user-42\": two tenants with the same string are inevitable, and one tenant's conversation would then become visible to the other's operators.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "503": {
      "$ref": "#/components/responses/Unavailable"
     }
    }
   }
  },
  "/v1/widget/lead": {
   "post": {
    "tags": [
     "Widget"
    ],
    "summary": "Leave a contact",
    "description": "A name and a way to get in touch, which then show up in the dashboard: in the contact list, in the notification to the owner and — if `session` is given — as a line in that conversation's transcript («Клієнт залишив контакт: …», \"The customer left a contact: …\") and as a flag in the conversation list.",
    "security": [
     {
      "widgetKey": []
     }
    ],
    "parameters": [
     {
      "name": "X-Bot-Key",
      "in": "header",
      "required": true,
      "schema": {
       "type": "string",
       "example": "pk_…"
      },
      "description": "The agent's publishable key."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "session": {
          "type": "string",
          "description": "Identifier of the conversation in which the contact was left. Without it the contact is saved but won't appear in the transcript. Also accepted as `session_id`."
         },
         "name": {
          "type": "string"
         },
         "contact": {
          "type": "string",
          "description": "Phone or email."
         },
         "message": {
          "type": "string"
         }
        },
        "required": [
         "contact"
        ]
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Contact saved.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "required": [
          "status"
         ],
         "properties": {
          "status": {
           "type": "string",
           "enum": [
            "received"
           ]
          }
         }
        }
       }
      }
     },
     "204": {
      "description": "Contact collection is not included in this build — the request is accepted silently, nothing is saved."
     },
     "401": {
      "description": "The agent key is unknown or revoked.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "Wrong key type, or the domain is not on the agent's allowed list.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/widget/leave": {
   "post": {
    "tags": [
     "Widget"
    ],
    "summary": "Visitor cleared the conversation",
    "description": "The chat window reports that the visitor cleared the conversation in their browser and started a new one. If in that conversation they were waiting for a human (or a human had already replied), the request is closed with a note in the transcript — so the operator doesn't reply into a conversation that no longer exists in the window. For a conversation handled by the assistant, the call does nothing.",
    "security": [
     {
      "widgetKey": []
     }
    ],
    "parameters": [
     {
      "name": "X-Bot-Key",
      "in": "header",
      "required": true,
      "schema": {
       "type": "string",
       "example": "pk_…"
      },
      "description": "The agent's publishable key."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "session_id": {
          "type": "string"
         }
        },
        "required": [
         "session_id"
        ]
       }
      }
     }
    },
    "responses": {
     "204": {
      "description": "Accepted."
     },
     "401": {
      "description": "The agent key is unknown or revoked.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "Wrong key type, or the domain is not on the agent's allowed list.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "503": {
      "description": "Couldn't read or close the conversation — retry in a moment.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/widget/reply": {
   "get": {
    "tags": [
     "Widget"
    ],
    "summary": "An answer the visitor did not wait for",
    "description": "The assistant's answer to the LAST visitor message in this conversation. A conversation turn is finished even when the client left in the middle of a streamed answer (reloaded the page, navigated away): the answer is saved to the conversation, and the window reads it back here. Poll every few seconds while `replies` is empty — but no longer than a turn lasts (about two minutes from the question): an answer that has not arrived by then will not come, and the visitor should be offered to ask again. Someone else's conversation cannot be read: neither with another agent's key nor with a foreign `session_id` — the response is then the same as for a conversation with no messages.",
    "security": [
     {
      "widgetKey": []
     }
    ],
    "parameters": [
     {
      "name": "X-Bot-Key",
      "in": "header",
      "required": true,
      "schema": {
       "type": "string",
       "example": "pk_…"
      },
      "description": "The agent's publishable key."
     },
     {
      "name": "session_id",
      "in": "query",
      "required": true,
      "schema": {
       "type": "string"
      }
     }
    ],
    "responses": {
     "200": {
      "description": "The visitor's last message and the assistant's answers recorded after it.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "required": [
          "question",
          "replies"
         ],
         "properties": {
          "question": {
           "type": "string",
           "description": "The visitor's last message in this conversation, as recorded. Compare it with your question: the answer refers to exactly this message. An empty string means the conversation has no visitor message yet (or it belongs to another agent)."
          },
          "replies": {
           "type": "array",
           "description": "The assistant's messages after `question`, in chronological order. An empty array means the assistant has not answered yet: the turn may still be running. Operator messages are not included — they arrive via `GET /v1/widget/messages`.",
           "items": {
            "type": "object",
            "required": [
             "id",
             "text",
             "at"
            ],
            "properties": {
             "id": {
              "type": "string",
              "description": "Message id — use it to avoid showing an answer twice when it already arrived over the stream."
             },
             "text": {
              "type": "string",
              "description": "Answer text (Markdown, as in the stream)."
             },
             "at": {
              "type": "integer",
              "format": "int64",
              "description": "When it was recorded, ms since the Unix epoch."
             },
             "notice": {
              "type": "boolean",
              "description": "`true` → this is a platform service line (for example, the knowledge base is unavailable), not the assistant's answer: show it as a system message, without rating. The field is absent for a regular answer."
             }
            }
           }
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "`session_id` is missing or too long.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "description": "The agent key is unknown or revoked.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "Wrong key type, or the domain is not on the agent's allowed list.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "503": {
      "$ref": "#/components/responses/Unavailable"
     }
    }
   }
  },
  "/v1/widget/messages": {
   "get": {
    "tags": [
     "Widget"
    ],
    "summary": "New messages",
    "description": "Polling while an operator is handling the conversation.",
    "security": [
     {
      "widgetKey": []
     }
    ],
    "parameters": [
     {
      "name": "X-Bot-Key",
      "in": "header",
      "required": true,
      "schema": {
       "type": "string",
       "example": "pk_…"
      },
      "description": "The agent's publishable key."
     },
     {
      "name": "session_id",
      "in": "query",
      "required": true,
      "schema": {
       "type": "string"
      }
     }
    ],
    "responses": {
     "200": {
      "description": "New operator messages, the conversation status and the \"operator is typing\" flag — the same as `GET /v1/api/messages` returns.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "required": [
          "messages",
          "status"
         ],
         "properties": {
          "messages": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/Message"
           },
           "description": "Only OPERATOR messages newer than `after`, in chronological order."
          },
          "status": {
           "$ref": "#/components/schemas/HandoffStatus"
          },
          "operator_typing": {
           "type": "boolean",
           "description": "`true` → the operator is typing a message right now. Show \"The operator is typing…\" in your chat. The signal fades on its own after about 6 seconds, so just redraw the indicator from the value in each poll. The field is absent if handoff to a human isn't available for this agent — treat absence as `false`."
          },
          "operator_here": {
           "type": "boolean",
           "description": "`true` → the conversation is in the queue (`status: \"waiting\"`) and an operator has already taken it (\"Take over\") but hasn't written anything yet. The window shows \"An operator is with you\" instead of \"Waiting for an operator…\". In other states — `false`: there `status` says it all."
          },
          "next_cursor": {
           "type": "string",
           "description": "Cursor for the NEXT poll. Pass it as `?cursor=` — unlike `after`, it tells apart messages sent in the same millisecond."
          },
          "tasks": {
           "type": "array",
           "description": "Long-running agent actions in progress right now (for example, a call to your system that takes minutes). Show them as progress cards next to the chat. An empty array means nothing is running.",
           "items": {
            "$ref": "#/components/schemas/Task"
           }
          },
          "review": {
           "type": "boolean",
           "description": "`true` → the answer to the customer's last message is still being reviewed by a human (training mode): keep polling. The answer arrives as a regular message in `messages`, and the field turns `false`."
          },
          "review_later": {
           "type": "boolean",
           "description": "`true` → the operator didn't reply within the time the owner set, and the customer was promised an answer later: show them this once (in the widget, the `review_later` label). The review continues; `review` stays `true`. In messengers the platform sends this line itself."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "The agent key is unknown or revoked.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "Wrong key type, or the domain is not on the agent's allowed list.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "503": {
      "$ref": "#/components/responses/Unavailable"
     }
    }
   }
  },
  "/v1/widget/messages/stream": {
   "get": {
    "tags": [
     "Widget"
    ],
    "summary": "New messages (streaming)",
    "description": "SSE instead of polling: the same, but without delay or extra requests.",
    "security": [
     {
      "widgetKey": []
     }
    ],
    "parameters": [
     {
      "name": "X-Bot-Key",
      "in": "header",
      "required": true,
      "schema": {
       "type": "string",
       "example": "pk_…"
      },
      "description": "The agent's publishable key."
     },
     {
      "name": "session_id",
      "in": "query",
      "required": true,
      "schema": {
       "type": "string"
      }
     }
    ],
    "responses": {
     "200": {
      "description": "Stream."
     },
     "401": {
      "description": "The agent key is unknown or revoked.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "Wrong key type, or the domain is not on the agent's allowed list.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "503": {
      "$ref": "#/components/responses/Unavailable"
     }
    }
   }
  },
  "/v1/widget/typing": {
   "post": {
    "tags": [
     "Widget"
    ],
    "summary": "Visitor is typing",
    "description": "Shows the operator a typing indicator.",
    "security": [
     {
      "widgetKey": []
     }
    ],
    "parameters": [
     {
      "name": "X-Bot-Key",
      "in": "header",
      "required": true,
      "schema": {
       "type": "string",
       "example": "pk_…"
      },
      "description": "The agent's publishable key."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "session_id": {
          "type": "string"
         }
        },
        "required": [
         "session_id"
        ]
       }
      }
     }
    },
    "responses": {
     "204": {
      "description": "Accepted."
     },
     "401": {
      "description": "The agent key is unknown or revoked.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "Wrong key type, or the domain is not on the agent's allowed list.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/widget/upload": {
   "post": {
    "tags": [
     "Widget"
    ],
    "summary": "Visitor attachment",
    "description": "A file the visitor adds to the conversation.",
    "security": [
     {
      "widgetKey": []
     }
    ],
    "parameters": [
     {
      "name": "X-Bot-Key",
      "in": "header",
      "required": true,
      "schema": {
       "type": "string",
       "example": "pk_…"
      },
      "description": "The agent's publishable key."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "multipart/form-data": {
       "schema": {
        "type": "object",
        "properties": {
         "file": {
          "type": "string",
          "format": "binary"
         },
         "session_id": {
          "type": "string"
         }
        },
        "required": [
         "file"
        ]
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Uploaded.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "required": [
          "url",
          "name",
          "content_type",
          "image",
          "session"
         ],
         "properties": {
          "url": {
           "type": "string",
           "description": "The file's address. Pass it in the next message."
          },
          "name": {
           "type": "string",
           "description": "The file name, as it was sent."
          },
          "content_type": {
           "type": "string"
          },
          "image": {
           "type": "boolean",
           "description": "The file is an image: the window shows it as a thumbnail."
          },
          "session": {
           "type": "string",
           "description": "The conversation the file is attached to. If there was no conversation yet, the attachment starts it — subsequent messages go with this identifier."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "The agent key is unknown or revoked.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "Wrong key type, or the domain is not on the agent's allowed list.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "413": {
      "description": "The file is too large (`payload_too_large`) or this agent's visitor attachment storage is full (`quota_exceeded`) — in that case a smaller file won't help: old attachments are removed when their retention period ends.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/version": {
   "get": {
    "tags": [
     "Service"
    ],
    "summary": "Build version",
    "description": "The commit the process was built from.",
    "security": [],
    "responses": {
     "200": {
      "description": "Version.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "required": [
          "service",
          "commit"
         ],
         "properties": {
          "service": {
           "type": "string",
           "description": "Service name: `youselfbot-api`."
          },
          "commit": {
           "type": "string",
           "description": "The commit this server was built from; `unknown` when the build doesn't know it."
          }
         }
        }
       }
      }
     }
    }
   }
  },
  "/v1/dashboard/builder": {
   "get": {
    "tags": [
     "Dashboard · Builder"
    ],
    "summary": "Previous conversation with the Builder",
    "description": "Returns the saved conversation so the dashboard opens where you left it: messages together with what accompanied the answers — applied changes (`steps`) and answer options shown as buttons (`choices`). The last 200 messages are returned; `earlier: true` means the conversation has older ones. The conversation belongs to the workspace you're currently working in: in a team you don't see the conversation about your own workspace's agents, and vice versa. `available: false` means the Builder is not connected in this build.\n\nThere can be several chats about one agent (`GET /v1/dashboard/builder/chats`). Pass `agent` — and the chat where it was discussed most recently opens; `thread` together with `agent` opens exactly that chat, and if it was deleted — the most recent one again. Which conversation was opened is given by the `thread` field of the response: pass exactly that in subsequent turns.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "thread",
      "in": "query",
      "required": false,
      "schema": {
       "type": "string"
      },
      "description": "Chat (conversation thread). Without `agent`, defaults to `main`."
     },
     {
      "name": "agent",
      "in": "query",
      "required": false,
      "schema": {
       "type": "string"
      },
      "description": "The agent the conversation is about. With it and without `thread`, the chat where it was discussed most recently opens."
     }
    ],
    "responses": {
     "200": {
      "description": "The conversation.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "available": {
           "type": "boolean"
          },
          "messages": {
           "type": "array",
           "items": {
            "type": "object",
            "properties": {
             "role": {
              "type": "string",
              "enum": [
               "user",
               "assistant"
              ]
             },
             "content": {
              "type": "string"
             },
             "steps": {
              "type": "array",
              "description": "Changes applied by the turn that ended with this answer — the same ones that came as `step` frames in the stream. No field — the turn changed nothing.",
              "items": {
               "type": "object",
               "properties": {
                "what": {
                 "type": "string",
                 "description": "What was done, in words."
                },
                "section": {
                 "type": "string",
                 "description": "The section of the agent the change touched; empty — no section named."
                }
               }
              }
             },
             "choices": {
              "type": "array",
              "description": "Answer options the Builder showed as buttons under this message.",
              "items": {
               "type": "string"
              }
             }
            }
           }
          },
          "earlier": {
           "type": "boolean",
           "description": "The conversation has older messages not included in this response."
          },
          "thread": {
           "type": "string",
           "description": "The chat that was opened. Pass it in `thread` on subsequent turns."
          },
          "title": {
           "type": "string",
           "description": "The title of the opened chat; empty if nothing has been said in it yet."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "No valid session — log in again.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "This session has no access to the dashboard.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "There is no agent with this identifier in this workspace.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "502": {
      "description": "Couldn't read the chat list — try again.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   },
   "post": {
    "tags": [
     "Dashboard · Builder"
    ],
    "summary": "Message the Builder",
    "description": "The Builder is a regular platform agent with one special toolset: `agent_list`, `agent_create`, `agent_configure`, `agent_knowledge_list`, `agent_learn_site`, `agent_knowledge_add`, `agent_action_list`, `agent_action_add`, `agent_action_test`, `agent_action_import`, `agent_trigger_list`, `agent_trigger_add`, `agent_trigger_remove`, `agent_flow_show`, `agent_flow_set`, `agent_trigger_run`, `agent_rename`, `agent_undo`, `agent_incidents`, `agent_runs`, `agent_channels`, `agent_secret`, `team_invite`, `agent_channel_connect`. They act on the DASHBOARD, so they are available only to a run started by a person with a valid session, and they do exactly what that person has permissions for.\n\nThe conversation is stored per triple (user, workspace, `thread`): each workspace the person works in has its own feed. To start over, create a new chat (`POST /v1/dashboard/builder/chats`) and send its identifier in `thread` — the previous chat stays in the list.\n\nThe chat window's appearance (title, accent, position, theme, colors) is set by the Builder with the same `agent_configure`; each \"text on background\" pair is checked for AA 4.5:1 contrast, and the Builder won't save an unreadable one.\n\nNothing disappears without consent: replacing knowledge sources, clearing personality fields and deleting a trigger first return a description of what will be lost, and are performed only on a repeat call with `confirm: true`.\n\nThe Builder changes the agent flow in one step and only after consent: `agent_flow_set` without `confirm: true` does nothing and returns what exactly needs confirming. All changes that customers will see right away, that can't be undone, or whose effect lands in a third-party system behave the same way. Everything else the Builder does without asking and offers `agent_undo`.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "required": [
         "message"
        ],
        "properties": {
         "message": {
          "type": "string",
          "description": "Your message."
         },
         "thread": {
          "type": "string",
          "description": "Chat (conversation thread); defaults to `main`. A thread not yet in the chat list becomes a chat with its first turn."
         },
         "agent": {
          "type": "string",
          "description": "Identifier of the agent whose screen the conversation is on. The Builder then doesn't ask who it's about."
         },
         "screen": {
          "type": "string",
          "description": "The dashboard section the person is on: overview, flow, channels, triggers, runs, state, knowledge, actions, connect, inbox, agents, account, team. A question without specifics is most likely about it. An unknown value is ignored — the list is closed because this string goes into the system prompt."
         },
         "attachment": {
          "type": "object",
          "description": "The file the person attached to the message: only its name, size and type. The file itself stays in the browser — the Builder says where to put it (`place_file` in the response), and the dashboard puts it there via the regular upload endpoints.",
          "properties": {
           "name": {
            "type": "string"
           },
           "size": {
            "type": "integer",
            "description": "Size in bytes."
           },
           "type": {
            "type": "string",
            "description": "Content type, as reported by the browser."
           }
          }
         }
        }
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "The Builder's response. Any actions it managed to take have already been carried out.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "answer": {
           "type": "string"
          },
          "choices": {
           "type": "array",
           "items": {
            "type": "string"
           },
           "description": "Answer options for the Builder's question, shown as buttons. Absent when it didn't ask anything."
          },
          "thread": {
           "type": "string",
           "description": "The chat this turn was recorded in. A dashboard that names no chat (or names another agent's chat) gets this agent's chat and keeps talking in it."
          },
          "created_agent": {
           "type": "string",
           "description": "The agent this turn created. The dashboard switches to it: the person's next messages are about that agent."
          },
          "created_thread": {
           "type": "string",
           "description": "The new agent's chat, where this request and the response were moved so the conversation about it continues instead of starting over."
          },
          "switch_workspace": {
           "type": "string",
           "description": "The workspace the dashboard should switch to after this turn (the person asked to move to another workspace or create their own). The browser holds the workspace cookie, so the browser does the switching: `POST /v1/dashboard/workspace`."
          },
          "reload": {
           "type": "boolean",
           "description": "The dashboard should reload completely: the person left the team, and the workspace under them changed."
          },
          "signed_out": {
           "type": "boolean",
           "description": "The person was signed out on all devices, including this one: the dashboard ends the session (`POST /v1/auth/logout`) and goes to sign-in."
          },
          "place_file": {
           "type": "object",
           "description": "Where to put the file attached to this message. The dashboard does the placing: `learn` → `POST …/files`, `send` → `POST …/media`, `actions` → `POST …/skills/import-file` with `install=1`.",
           "properties": {
            "kind": {
             "type": "string",
             "enum": [
              "learn",
              "send",
              "actions"
             ]
            },
            "agent": {
             "type": "string",
             "description": "The agent the file belongs to."
            },
            "base_url": {
             "type": "string",
             "description": "For `actions`: the service address, if the person gave one."
            }
           }
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "Empty message.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "description": "No valid session — log in again.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "This session has no access to the dashboard.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "The Builder isn't available in this build.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "429": {
      "description": "Too many messages per minute. Wait as long as Retry-After asks.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "502": {
      "description": "The Builder didn't respond. Try again.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "409": {
      "description": "`chat_deleted`: this chat was erased. Restore it (`POST /v1/dashboard/builder/chats/{chat}/restore`) or write in another one. `conflict`: the previous turn in this conversation is still running, and this one didn't wait for it (turns in one conversation run one at a time). Nothing was changed; send the message again once that turn has answered.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/dashboard/builder/stream": {
   "post": {
    "tags": [
     "Dashboard · Builder"
    ],
    "summary": "Message the Builder and watch the turn while it runs",
    "description": "Same as `POST /v1/dashboard/builder`, but the response arrives as a `text/event-stream` instead of a single body at the end.\n\nA Builder turn is long by design: it reads a website, creates an agent, connects a channel. On the regular endpoint all of that happens behind a silent request, and there is no way to tell work from a dropped connection.\n\nStream frames (each is a separate `data:` line with JSON):\n\n- `{\"delta\": \"…\"}`: the next chunk of the response text;\n- `{\"step\": \"…\", \"section\": \"knowledge\"}`: a change that was just applied, in the tool's own words; `section` names the affected part of the agent (`knowledge`, `actions`, `channels`, `triggers`, `persona`, `window` (what's visible in the chat window on the website changed), `agents`, `flow`, `secrets`, `team`, `tasks`, `catalog` (shop products from the feed)); empty means unknown, so re-read everything;\n- `{\"error\": \"…\", \"code\": \"…\", \"clean\": true}`: a failure that happened after the stream started. `clean: true` means the turn changed and started nothing, so the same request can be sent again; a turn that managed to do something doesn't end with this frame but with `done`, listing what was done in the response;\n- `{\"action\": \"running\"}`: a tool is running right now (a call to a third-party API can take a dozen seconds);\n- `{\"done\": true, \"answer\": \"…\", \"changed\": [\"knowledge\", \"actions\"]}`: the end of the turn, the full response text and the list of affected sections. `changed` always arrives, even when empty: an empty list means \"nothing was applied\", which is not the same as a missing field.\n\nThe last frame carries exactly what was saved to the conversation, and the client must bring what it displayed in line with it. Only the model's first pass is streamed: as soon as it turns to tools, the rest of the response arrives in one piece, and whatever had streamed before that doesn't make it into the saved conversation. Without this reconciliation, a page reload would show a different conversation from the one the person just read.\n\nChanges the Builder managed to apply are already in effect, even if the stream broke off without a `done` frame: in that case, re-read the agent's state and don't send the same request a second time. The final `done` frame also carries `thread` (the chat the turn was recorded in) and, if the turn created an agent, `created_agent` and `created_thread`: the dashboard switches to the new agent, and the conversation about it continues in its chat. Turns in one conversation run one at a time: a second turn sent while the first is running waits for it; if it can't wait long enough, it ends with an `error` frame with code `conflict` and `clean: true`: nothing was changed, and it can be retried.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "required": [
         "message"
        ],
        "properties": {
         "message": {
          "type": "string",
          "description": "Your message."
         },
         "thread": {
          "type": "string",
          "description": "Chat (conversation thread); defaults to `main`. A thread not yet in the chat list becomes a chat with its first turn."
         },
         "agent": {
          "type": "string",
          "description": "Identifier of the agent whose screen the conversation is on. The Builder then doesn't ask who it's about."
         },
         "screen": {
          "type": "string",
          "description": "The dashboard section the person is in: overview, flow, channels, triggers, runs, state, knowledge, actions, connect, inbox, agents, account, team. Unknown values are ignored."
         },
         "attachment": {
          "type": "object",
          "description": "The file the person attached to the message: only its name, size and type. The file itself stays in the browser — the Builder says where to put it (`place_file` in the response), and the dashboard puts it there via the regular upload endpoints.",
          "properties": {
           "name": {
            "type": "string"
           },
           "size": {
            "type": "integer",
            "description": "Size in bytes."
           },
           "type": {
            "type": "string",
            "description": "Content type, as reported by the browser."
           }
          }
         }
        }
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "A stream of turn frames. Errors that happen after the stream starts arrive as an `error` frame, because the headers have already been sent.",
      "content": {
       "text/event-stream": {
        "schema": {
         "$ref": "#/components/schemas/BuilderFrame"
        }
       }
      }
     },
     "400": {
      "description": "Empty message.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "description": "No valid session — log in again.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "This session has no access to the dashboard.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "The Builder isn't available in this build.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "429": {
      "description": "Too many messages per minute. Wait as long as Retry-After asks.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "409": {
      "description": "`chat_deleted`: this chat was erased. Restore it (`POST /v1/dashboard/builder/chats/{chat}/restore`) or write in another one.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/dashboard/builder/chats": {
   "get": {
    "tags": [
     "Dashboard · Builder"
    ],
    "summary": "Builder chats about an agent",
    "description": "Your conversations with the Builder about one agent, most recently active first. Erased chats are listed separately: they are kept for `keep_days` days and can be restored at any time during that period. Chats are personal: other workspace members can't see yours. The conversation you had about the agent before this list existed appears in it as the first chat, without a time, because the platform doesn't know it.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "agent",
      "in": "query",
      "required": false,
      "schema": {
       "type": "string"
      },
      "description": "The agent the chats are about. Empty: the conversation started when there were no agents yet."
     }
    ],
    "responses": {
     "200": {
      "description": "Chats.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "chats": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/BuilderChat"
           }
          },
          "deleted": {
           "type": "array",
           "description": "Erased chats that can still be restored.",
           "items": {
            "$ref": "#/components/schemas/BuilderChat"
           }
          },
          "limit": {
           "type": "integer",
           "description": "How many chats about one agent you can keep at once (erased ones don't count)."
          },
          "keep_days": {
           "type": "integer",
           "description": "How many days an erased chat is kept."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "No valid session — log in again.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "This session has no access to the dashboard.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "There is no agent with this ID in this workspace, or the chat list isn't enabled in this build.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "502": {
      "description": "Couldn't read the chat list — try again.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   },
   "post": {
    "tags": [
     "Dashboard · Builder"
    ],
    "summary": "Start a new chat",
    "description": "Creates an empty conversation with the Builder about the same agent; previous ones stay in the list. Empty chats don't pile up: if one already exists, it is returned (200) instead of a new one. In a new chat the Builder knows just as much about what the agent can do and how it's set up: that's the agent's state, not the conversation's memory.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "required": [
         "agent"
        ],
        "properties": {
         "agent": {
          "type": "string",
          "description": "The agent the chat is about."
         }
        }
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "An empty chat already existed and was returned.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/BuilderChat"
        }
       }
      }
     },
     "201": {
      "description": "Chat created.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/BuilderChat"
        }
       }
      }
     },
     "400": {
      "description": "No agent specified.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "description": "No valid session — log in again.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "This session has no access to the dashboard.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "There is no agent with this ID in this workspace, or the chat list isn't enabled in this build.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "409": {
      "description": "`chat_limit`: this agent already has as many chats as you can keep (`limit`). Erase one you don't need.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "502": {
      "description": "Couldn't create the chat. Try again.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/dashboard/builder/chats/{chat}": {
   "patch": {
    "tags": [
     "Dashboard · Builder"
    ],
    "summary": "Rename a chat",
    "description": "Gives the chat a title. Once a person has named a chat, its title no longer changes; until then, it's taken from the first request.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "chat",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Chat ID."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "required": [
         "title"
        ],
        "properties": {
         "title": {
          "type": "string",
          "description": "The new title, up to 80 characters (longer ones are truncated)."
         }
        }
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "The chat with its new title.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/BuilderChat"
        }
       }
      }
     },
     "400": {
      "description": "Empty title or an unknown field in the body.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "description": "No valid session — log in again.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "This session has no access to the dashboard.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "You have no such chat.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "502": {
      "description": "That didn't work. Try again.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   },
   "delete": {
    "tags": [
     "Dashboard · Builder"
    ],
    "summary": "Erase a chat",
    "description": "The chat disappears from the list and moves to the erased ones: it's kept there for `keep_days` days and can be brought back with `POST …/restore`. After that period it's gone for good, along with its messages. The agent isn't affected: changes made in the chat stay, and they can still be undone from any other chat.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "chat",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Chat ID."
     }
    ],
    "responses": {
     "200": {
      "description": "The erased chat, with the time it will be gone for good.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/BuilderChat"
        }
       }
      }
     },
     "401": {
      "description": "No valid session — log in again.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "This session has no access to the dashboard.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "You have no such chat.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "502": {
      "description": "That didn't work. Try again.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/dashboard/builder/chats/{chat}/restore": {
   "post": {
    "tags": [
     "Dashboard · Builder"
    ],
    "summary": "Restore an erased chat",
    "description": "Returns the chat to the list exactly as it was.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "chat",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Chat ID."
     }
    ],
    "responses": {
     "200": {
      "description": "The chat is back in the list.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/BuilderChat"
        }
       }
      }
     },
     "409": {
      "description": "`chat_limit`: the list already has as many chats about this agent as you can keep. Erase one you don't need first.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "description": "No valid session — log in again.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "This session has no access to the dashboard.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "You have no such chat.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "502": {
      "description": "That didn't work. Try again.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/runs/{runID}/trace": {
   "get": {
    "tags": [
     "Dashboard · Triggers"
    ],
    "summary": "Trace of a single run",
    "description": "What exactly the agent did while composing this response: which steps ran, which were skipped and because of which condition, what was found in knowledge, which actions were called and how they ended. This answers \"why did the agent say that\"; the status and token count don't.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     },
     {
      "name": "runID",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Run ID from the log."
     }
    ],
    "responses": {
     "200": {
      "description": "The run trace.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "run": {
           "type": "string"
          },
          "status": {
           "type": "string"
          },
          "trace": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/RunStep"
           }
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "No valid session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The role doesn't allow this action. The owner's personal conversation (`personal`) for a member without admin rights — `403` with an explanation: the conversation exists, but only admins see its content.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Agent or run not found.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/secrets": {
   "get": {
    "tags": [
     "Dashboard · Secrets"
    ],
    "summary": "Agent secrets",
    "description": "Names of the values the agent substitutes via `{{secrets.NAME}}`, and the time each was last changed.\n\n**Values aren't here and never will be.** A key that can't be read back can't be leaked either: not through a screenshot sent to support, not through the browser log. An owner who lost a key issues a new one in the service they got it from.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     }
    ],
    "responses": {
     "200": {
      "description": "List of names.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/SecretList"
        }
       }
      }
     },
     "401": {
      "description": "No valid session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The role doesn't allow this action.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Agent not found, or the key store is turned off.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/secrets/{name}": {
   "put": {
    "tags": [
     "Dashboard · Secrets"
    ],
    "summary": "Write a secret",
    "description": "Creates or overwrites a value. The value travels in the BODY, not the URL, so it never ends up in an access log or a proxy history.\n\nOverwriting an existing name works even when the store is full: that's exactly when an expired key gets replaced.\n\n**Don't confuse with `POST /v1/dashboard/bots/{id}/secret`** (singular): that one reissues the agent's secret key and breaks the old one immediately.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     },
     {
      "name": "name",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "pattern": "^[A-Za-z][A-Za-z0-9_]{0,63}$"
      },
      "description": "Secret name, as in `.env` (STRIPE_KEY). Converted to uppercase."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/SecretWrite"
       }
      }
     }
    },
    "responses": {
     "204": {
      "description": "Saved."
     },
     "400": {
      "description": "The name isn't in .env form, the value is empty, or the store is full.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "description": "No valid session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The role doesn't allow this action.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Agent not found, or the key store is turned off.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   },
   "delete": {
    "tags": [
     "Dashboard · Secrets"
    ],
    "summary": "Remove a secret",
    "description": "Idempotent: a missing secret is also a success.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     },
     {
      "name": "name",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "pattern": "^[A-Za-z][A-Za-z0-9_]{0,63}$"
      },
      "description": "Secret name, as in `.env` (STRIPE_KEY). Converted to uppercase."
     }
    ],
    "responses": {
     "204": {
      "description": "Removed."
     },
     "401": {
      "description": "No valid session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The role doesn't allow this action.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Agent not found, or the key store is turned off.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/incidents": {
   "get": {
    "tags": [
     "Dashboard · Incidents"
    ],
    "summary": "Agent incidents",
    "description": "What broke and what to do about it. Open ones first.\n\nThe incident notification reaches the owner **on its own**; this list is for someone who already got it and went to fix things: is this the only incident, how many times did it repeat, did the rest get fixed.\n\nThe unit here is the **cause** (kind + subject), not the event. An action that has dropped off breaks on every run, so repeats only increase `count`; a repeat notification is sent only after the cause has been closed by a successful call and then breaks again.\n\n`message` is a ready-made text, the same one the owner received. Don't compose it again in your own words: two wordings of the same incident drift apart over time.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     }
    ],
    "responses": {
     "200": {
      "description": "List of incidents.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/IncidentList"
        }
       }
      }
     },
     "401": {
      "description": "No valid session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The role doesn't allow this action.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Agent not found, or the log is turned off.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/gaps": {
   "get": {
    "tags": [
     "Dashboard · What the agent doesn't know"
    ],
    "summary": "What the agent doesn't know",
    "description": "Questions the agent searched the knowledge base for and **didn't find**, most frequent first.\n\nThe unit here is **the query the agent searched with**, not the customer's message. The model doesn't go to the knowledge base for \"hi\" and \"thanks\": it searches only when it lacks facts for an answer. That's why the list stays a list of questions rather than an excerpt from the correspondence.\n\nQuestions with the same meaning are merged into one row (\"do you deliver to Lviv\" and \"delivery Lviv\" are one question), and `count` says how many times it was asked. That's what tells a random question apart from a gap that costs you customers every day.\n\nAn empty list **doesn't mean** the knowledge base is complete: the agent may simply not have been asked much yet. A question nobody has asked for two months drops off the list on its own.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     }
    ],
    "responses": {
     "200": {
      "description": "List of unanswered questions.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/GapList"
        }
       }
      }
     },
     "401": {
      "description": "No valid session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The role doesn't allow this action.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Agent not found.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/gaps/{gapID}/answer": {
   "post": {
    "tags": [
     "Dashboard · What the agent doesn't know"
    ],
    "summary": "Answer a question from the list",
    "description": "Admin only: an answer given here goes into the knowledge base and customers will hear it tomorrow.\n\nThe platform takes the question text **from its own records**, not from the request: what goes into knowledge must be the thing the agent actually failed to find an answer to. The knowledge is stored as a \"question – answer\" pair: a passage that doesn't contain the question is found worse than one that does, meaning the bot would again fail to answer exactly this question.\n\nThe row is removed from the list once the knowledge has been indexed.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     },
     {
      "name": "gapID",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "ID of the question from the list."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "required": [
         "answer"
        ],
        "properties": {
         "answer": {
          "type": "string",
          "description": "The answer to this question, in the owner's words."
         }
        }
       }
      }
     }
    },
    "responses": {
     "202": {
      "description": "Knowledge accepted for indexing.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "required": [
          "status",
          "source_id"
         ],
         "properties": {
          "status": {
           "type": "string",
           "enum": [
            "indexed"
           ]
          },
          "source_id": {
           "type": "string",
           "description": "ID of the added knowledge source."
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "No answer given.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "description": "Sign-in required.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "Admin rights required.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "There is no such question in the list.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/gaps/{gapID}": {
   "delete": {
    "tags": [
     "Dashboard · What the agent doesn't know"
    ],
    "summary": "Remove a question from the list",
    "description": "Admin only. Not \"answered\" but \"this isn't a question\": the owner sees the agent searched for nonsense and removes the row.\n\nOnly the next real customer can bring it back, and that's correct: the list describes what people are asking about **now**.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     },
     {
      "name": "gapID",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "ID of the question from the list."
     }
    ],
    "responses": {
     "204": {
      "description": "Removed."
     },
     "401": {
      "description": "Sign-in required.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "Admin rights required.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "There is no such question in the list.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/changes": {
   "get": {
    "tags": [
     "Dashboard · Changes"
    ],
    "summary": "What was changed and when",
    "description": "A set is everything done in ONE turn of the conversation with the bot: it's applied together and undone together. Otherwise \"undo\" turns into archaeology, with the person having to remember which of seven changes were part of the same idea.\n\n`undoable: false` means the set contains a change that can't be reverted: a re-created channel would get a new inbound address, and we don't know the old key value and have no way to find it out. Such changes sit on the far side of the approval threshold, meaning they were already agreed to deliberately.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     }
    ],
    "responses": {
     "200": {
      "description": "Change sets, newest first.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/ChangeList"
        }
       }
      }
     },
     "401": {
      "description": "No valid session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The role doesn't allow this action.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Agent not found, or the log is turned off.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/changes/{sid}/undo": {
   "post": {
    "tags": [
     "Dashboard · Changes"
    ],
    "summary": "Undo a set",
    "description": "Reverts the set IN FULL, in reverse order: if the bot first created an action and then referenced it in the personality, the personality has to be reverted first; otherwise a reference to something that no longer exists would remain.\n\nThere is no partial undo: a set with even one irreversible change is rejected, and no part of it is touched. Half of an undone idea is worse than either of its complete versions.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     },
     {
      "name": "sid",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Change set ID."
     }
    ],
    "responses": {
     "204": {
      "description": "Restored."
     },
     "401": {
      "description": "No valid session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The role doesn't allow this action.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "There is no such set.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "409": {
      "description": "The set contains changes that can't be reverted.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/snapshots": {
   "get": {
    "summary": "Agent restore points",
    "description": "A snapshot answers \"put it back the way it was on Thursday\", a question that undo by design doesn't answer: undo is about one change, not about a moment in time.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     }
    ],
    "responses": {
     "200": {
      "description": "Restore points, newest first.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "snapshots": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/AgentSnapshot"
           }
          },
          "not_covered": {
           "type": "array",
           "items": {
            "type": "string"
           }
          },
          "truncated": {
           "type": "boolean",
           "description": "The list is truncated: there are more rows than a page holds (50). Say so explicitly — otherwise the owner reads the slice as the whole list. There's no cursor pagination here yet; older history is available only from storage."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "No valid session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The role doesn't allow this action.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   },
   "post": {
    "summary": "Take a restore point",
    "description": "Records the agent's current state: personality, flow, triggers. Body: {\"reason\":\"…\"}, optional.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     }
    ],
    "requestBody": {
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "reason": {
          "type": "string",
          "description": "Why the snapshot was taken. Empty means \"manual\"."
         }
        }
       }
      }
     }
    },
    "responses": {
     "201": {
      "description": "Snapshot taken.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "snapshot": {
           "$ref": "#/components/schemas/AgentSnapshot"
          },
          "not_covered": {
           "type": "array",
           "items": {
            "type": "string"
           }
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "No valid session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The role doesn't allow this action.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/snapshots/{number}/restore": {
   "post": {
    "summary": "Restore an agent to a restore point",
    "description": "The personality, flow and triggers become what they were then. Access keys, connected channels and knowledge are NOT restored; see not_covered.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     },
     {
      "name": "number",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      },
      "description": "Restore point number from the list."
     }
    ],
    "responses": {
     "200": {
      "description": "State restored. 200 even when some parts weren't restored: restoring is several independent operations, and the body shows what exactly worked.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "restored": {
           "$ref": "#/components/schemas/SnapshotRestored"
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "There is no such snapshot."
     },
     "401": {
      "description": "No valid session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The role doesn't allow this action.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/dashboard/agent-presets": {
   "get": {
    "tags": [
     "Dashboard · Agents"
    ],
    "summary": "Agent presets",
    "description": "A ready-made agent to copy: personality and flow. A preset has no knowledge, actions or keys: that's the owner's data, and it can't be guessed in advance; what exactly will need to be added is listed in each preset's next_steps. Don't confuse with integration presets (/bots/{id}/skills/presets): those add an ACTION to an existing agent.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "responses": {
     "200": {
      "description": "List of presets.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "presets": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/AgentPreset"
           }
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "No valid session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The role doesn't allow this action, or the key is of the wrong kind.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/api/mcp": {
   "post": {
    "summary": "Builder MCP server (JSON-RPC 2.0, streamable HTTP)",
    "description": "Model Context Protocol over a single POST. Tools: `agents` and `incidents` (read-only) and `constructor`, a conversation with the Builder in plain words on behalf of the workspace owner; the Builder itself records the changes in the log. Authentication: a BUILDER KEY (`ck_`) in `Authorization: Bearer` or `X-Bot-Key`, from a button in the dashboard (Account → MCP) or via browser sign-in at `/v1/mcp-pair`. Bot keys (`sk_`/`pk_`) aren't accepted here: `sk_` is an integration key, not a management key.\n\nThe server understands two eras of the MCP specification, just like the agent's MCP server. Current (`2026-07-28`): no handshake; every request carries `params._meta` with `io.modelcontextprotocol/protocolVersion` and `io.modelcontextprotocol/clientCapabilities` and repeats the version, method and tool name in the `MCP-Protocol-Version`, `Mcp-Method` and `Mcp-Name` headers; a mismatch with the body returns `400` with code `-32020`; an unknown version returns `400` with code `-32022` and a list of supported ones; an unknown method returns `404` with code `-32601`; `server/discover` is available. Previous (`2025-03-26`, `2025-06-18`, `2025-11-25`): `initialize`, then requests without `_meta`. The response is always `application/json`; the server doesn't open a stream. One message per POST: a batch (array) returns `400`.\n\nThe rate limit is per the key's workspace: Builder messages (`tools/call` → `constructor`) have their own rate, and service requests and reads have a separate, more generous one.\n\nDon't confuse with `POST /v1/agents/{id}/mcp`: that's the AGENT's MCP (key `ak_`), used to talk to the agent.",
    "security": [
     {
      "constructorKey": []
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "jsonrpc": {
          "type": "string",
          "enum": [
           "2.0"
          ]
         },
         "id": {
          "description": "A number or a string; the response returns it as is. Without `id` it's a notification."
         },
         "method": {
          "type": "string"
         },
         "params": {
          "type": "object"
         }
        },
        "required": [
         "jsonrpc",
         "method"
        ]
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "JSON-RPC response: result or error. Tool errors are result.isError=true with a text.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object"
        }
       }
      }
     },
     "202": {
      "description": "Notification message accepted (no response)."
     },
     "400": {
      "description": "The body isn't a single JSON-RPC message (`-32700`); in the current version, the headers don't match the body (`-32020`), the version isn't supported (`-32022`), or the required `_meta` field is missing (`-32602`). The body is a JSON-RPC error.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object"
        }
       }
      }
     },
     "401": {
      "description": "No key, or the key is invalid or revoked.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "Wrong kind of key: a builder key (`ck_`) is required; `sk_` and `pk_` aren't accepted here. Or the request came from a page on a third-party website (the `Origin` header); in that case the body is a JSON-RPC error without `id`.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object"
        }
       }
      }
     },
     "404": {
      "description": "Current version: no such method (`-32601`, the body is a JSON-RPC error).",
      "content": {
       "application/json": {
        "schema": {
         "type": "object"
        }
       }
      }
     },
     "413": {
      "description": "Body too large.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "429": {
      "description": "Too many requests from this workspace (the server's overall limit); `Retry-After` says how long to wait. The message limit of the `constructor` tool (twelve per minute) doesn't belong here: exceeding it returns a regular `200` response with an `isError: true` tool result that says in words that the message wasn't processed and how long to wait, along with the same `Retry-After` header.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "parameters": [
     {
      "name": "MCP-Protocol-Version",
      "in": "header",
      "required": false,
      "schema": {
       "type": "string"
      },
      "description": "Protocol version. Required in the current version; without it, a request without `_meta` is served as `2025-03-26`."
     },
     {
      "name": "Mcp-Method",
      "in": "header",
      "required": false,
      "schema": {
       "type": "string"
      },
      "description": "Current version: the same method as in the body."
     },
     {
      "name": "Mcp-Name",
      "in": "header",
      "required": false,
      "schema": {
       "type": "string"
      },
      "description": "Current version, for `tools/call`: the tool name from the body."
     }
    ]
   },
   "get": {
    "summary": "MCP: the server doesn't hold a stream",
    "description": "The server only answers POST; GET honestly returns 405, which tells MCP clients \"use POST only\".",
    "security": [
     {
      "constructorKey": []
     }
    ],
    "responses": {
     "405": {
      "description": "Method Not Allowed; header Allow: POST."
     },
     "401": {
      "description": "No key, or the key is invalid or revoked."
     },
     "403": {
      "description": "Wrong kind of key: a builder key (ck_) is required."
     }
    }
   }
  },
  "/v1/dashboard/constructor-key": {
   "post": {
    "summary": "New builder key (ck_)",
    "description": "Issues a workspace management key for MCP and the management API. Reissuing: all previous ck_ keys stop working the same instant. The full value is returned exactly once. Role: admin.",
    "responses": {
     "200": {
      "description": "{constructor_key}",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "constructor_key": {
           "type": "string",
           "description": "The `ck_…` key. Shown once."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "No session."
     },
     "403": {
      "description": "Role is below admin."
     },
     "404": {
      "description": "Builder keys aren't available in this build."
     }
    }
   }
  },
  "/v1/dashboard/mcp-pair": {
   "get": {
    "summary": "Which device is asking (MCP pairing)",
    "description": "For the approval page in the dashboard: the device name and whether it's already approved. The pairing secret is never returned.",
    "parameters": [
     {
      "name": "code",
      "in": "query",
      "required": true,
      "schema": {
       "type": "string"
      }
     }
    ],
    "responses": {
     "200": {
      "description": "The device asking for access.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "device": {
           "type": "string",
           "description": "What the device asking for access calls itself."
          },
          "approved": {
           "type": "boolean",
           "description": "The connection is already approved."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "No session."
     },
     "404": {
      "description": "Code not found or expired."
     },
     "503": {
      "description": "The code can't be checked right now. Retry in a moment (code: unavailable).",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/dashboard/mcp-pair/approve": {
   "post": {
    "summary": "Allow a device to access the Builder",
    "description": "Browser approval of pairing: issues a new ck_ IN ADDITION, without revoking the ones issued earlier. Role: admin.",
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "code": {
          "type": "string"
         }
        },
        "required": [
         "code"
        ]
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "{ok:true}",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "ok": {
           "type": "boolean"
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "No session."
     },
     "403": {
      "description": "Role is below admin."
     },
     "404": {
      "description": "Code not found or expired."
     }
    }
   }
  },
  "/v1/mcp-pair/start": {
   "post": {
    "summary": "Start an MCP client's browser sign-in",
    "description": "No authorization (this is how you get it); rate-limited per IP. Returns code (show it to the person), secret (only the client keeps it), verify_url (open it in a browser).",
    "requestBody": {
     "required": false,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "device": {
          "type": "string",
          "description": "Human-readable device/client name."
         }
        }
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "{code, secret, verify_url, expires_in, interval}"
     },
     "404": {
      "description": "Builder keys aren't available in this build."
     },
     "429": {
      "description": "Too many attempts from this address."
     },
     "503": {
      "description": "The pending-request store is unavailable right now. Retry in a moment (code: unavailable).",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "security": []
   }
  },
  "/v1/mcp-pair/poll": {
   "get": {
    "summary": "Collect the builder key after approval",
    "description": "The gate is the secret from start. Before approval: {status:pending}. After: {status:ok, constructor_key}, exactly once; then the code is gone.",
    "parameters": [
     {
      "name": "code",
      "in": "query",
      "required": true,
      "schema": {
       "type": "string"
      }
     },
     {
      "name": "secret",
      "in": "query",
      "required": true,
      "schema": {
       "type": "string"
      }
     }
    ],
    "responses": {
     "200": {
      "description": "pending, or the key (once)."
     },
     "404": {
      "description": "Code not found, expired, or the secret belongs to someone else."
     },
     "429": {
      "description": "Too many polls from this address. This bucket is separate from `start` and sized for polling at the suggested `interval`: a client that follows it never hits this limit."
     },
     "503": {
      "description": "The code can't be checked right now. Poll again in a moment (code: unavailable).",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "security": []
   }
  },
  "/v1/dashboard/bots/{id}/approvals": {
   "get": {
    "tags": [
     "Dashboard · Approvals"
    ],
    "summary": "Approval queue",
    "description": "Actions the agent did NOT carry out on its own: they're waiting for a person.\n\nAn action with `needs_approval` doesn't touch the world: it becomes a card here, and until it's answered, nothing has happened. This is what makes agents that write to customers, publish listings or charge money possible: the first touch goes through the owner.\n\n`pending` is counted **always** and independently of the filter: it's the number for the menu badge, not for the current tab.\n\nA card lives for a day. After that it becomes «протерміновано» (\"expired\") and won't run: \"we'll call back today\" approved a week later is worse than nothing.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     },
     {
      "name": "status",
      "in": "query",
      "required": false,
      "schema": {
       "type": "string"
      },
      "description": "Show only cards in this state."
     },
     {
      "name": "cursor",
      "in": "query",
      "required": false,
      "schema": {
       "type": "string"
      },
      "description": "Continue the list: the `next` value from the previous response."
     }
    ],
    "responses": {
     "200": {
      "description": "The queue",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "approvals": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/ApprovalCard"
           }
          },
          "next": {
           "type": "string"
          },
          "pending": {
           "type": "integer"
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "Sign-in required"
     },
     "403": {
      "description": "No access to this agent, or decisions are made by the workspace admin"
     },
     "404": {
      "description": "There's no approval queue in this build"
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/approvals/{cardID}/approve": {
   "post": {
    "tags": [
     "Dashboard · Approvals"
    ],
    "summary": "Approve an action",
    "description": "Runs the action the agent queued.\n\n**Exactly one** decision goes through: a second request (another tab, a repeated click) gets 409, not a second email to the customer.\n\n`args` lets you fix the arguments before running: \"almost right\" is the most common case, and without an edit it turns into a rejection and the agent asking again.\n\nThe response is the card itself with the outcome: the action may have run or may have failed, and the status «не вдалося» (\"failed\") says exactly that.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     },
     {
      "name": "cardID",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      }
     }
    ],
    "requestBody": {
     "required": false,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "args": {
          "type": "object",
          "additionalProperties": true,
          "description": "Corrected arguments. Omit to run as is."
         }
        }
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "The card with the outcome",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/ApprovalCard"
        }
       }
      }
     },
     "401": {
      "description": "Sign-in required"
     },
     "403": {
      "description": "Decisions are made by the workspace admin"
     },
     "404": {
      "description": "No such card"
     },
     "409": {
      "description": "A decision on this card has already been made. Re-read the list instead of repeating the request"
     },
     "410": {
      "description": "The card has expired, and the action wasn't run. The card itself comes with the error, to show what exactly was missed.",
      "content": {
       "application/json": {
        "schema": {
         "allOf": [
          {
           "$ref": "#/components/schemas/Error"
          },
          {
           "$ref": "#/components/schemas/ApprovalCard"
          }
         ]
        }
       }
      }
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/approvals/{cardID}/reject": {
   "post": {
    "tags": [
     "Dashboard · Approvals"
    ],
    "summary": "Reject an action",
    "description": "The action won't happen. `reason` stays on the card: \"why wasn't it sent\" is what people ask most often later.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     },
     {
      "name": "cardID",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      }
     }
    ],
    "requestBody": {
     "required": false,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "reason": {
          "type": "string",
          "description": "Why it was rejected."
         }
        }
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "The card with the outcome",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/ApprovalCard"
        }
       }
      }
     },
     "401": {
      "description": "Sign-in required"
     },
     "403": {
      "description": "Decisions are made by the workspace admin"
     },
     "404": {
      "description": "No such card"
     },
     "409": {
      "description": "A decision on this card has already been made. Re-read the list instead of repeating the request"
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/blocked": {
   "get": {
    "tags": [
     "Dashboard · Stop list"
    ],
    "summary": "Who the agent no longer contacts",
    "description": "Contacts the agent doesn't reach out to with any action.\n\nThe stop list is about the **person**, not the action: \"don't write to me\" applies to all of the agent's actions, because the person doesn't tell your integrations apart.\n\nBoth the owner and the agent itself fill it: people say \"don't write to me\" TO THE AGENT, and without this the request would go nowhere. Who added an entry is shown in the `by` field.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     },
     {
      "name": "cursor",
      "in": "query",
      "required": false,
      "schema": {
       "type": "string"
      },
      "description": "Continue the list: the `next` value from the previous response."
     }
    ],
    "responses": {
     "200": {
      "description": "The list",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "blocked": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/BlockedContact"
           }
          },
          "next": {
           "type": "string"
          },
          "total": {
           "type": "integer",
           "description": "How many entries the stop list has IN TOTAL. This is the number for the panel badge, not the page length: otherwise \"Not contacting 50\" would show for both fifty and five thousand."
          },
          "appeals": {
           "type": "integer",
           "description": "How many people are ASKING to be contacted again, across the whole stop list, not just this page. This is a decision waiting for the owner."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "Sign-in required"
     },
     "403": {
      "description": "No access to this agent"
     },
     "404": {
      "description": "There's no stop list in this build"
     }
    }
   },
   "post": {
    "tags": [
     "Dashboard · Stop list"
    ],
    "summary": "Add a contact",
    "description": "The agent will no longer write to this contact, with any action.\n\nDoesn't require admin rights: adding an entry NARROWS the agent's permissions rather than widening them.\n\nAny spelling works: the platform normalizes the contact to its canonical form itself; otherwise the same person spelled differently would get the next message.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "contact": {
          "type": "string",
          "description": "Phone, email or handle."
         },
         "why": {
          "type": "string",
          "description": "Why we're not writing, in the person's words, if they gave any."
         }
        },
        "required": [
         "contact"
        ]
       }
      }
     }
    },
    "responses": {
     "204": {
      "description": "Added"
     },
     "400": {
      "description": "No contact, or it's too long"
     },
     "401": {
      "description": "Sign-in required"
     },
     "403": {
      "description": "No access to this agent"
     },
     "404": {
      "description": "There's no stop list in this build"
     },
     "409": {
      "description": "The stop list is full; it's no longer a list of exceptions"
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/blocked/{contact}": {
   "delete": {
    "tags": [
     "Dashboard · Stop list"
    ],
    "summary": "Remove a contact",
    "description": "The agent will be able to write to this contact again.\n\nAn **admin** rail: this is permission to write to a person who asked not to be contacted, a decision of the same kind as approving an action.\n\nThe path takes the canonical form (`key` from the list), not the way the contact was written.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     },
     {
      "name": "contact",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Canonical form of the contact: the `key` field from the list."
     }
    ],
    "responses": {
     "204": {
      "description": "Removed"
     },
     "401": {
      "description": "Sign-in required"
     },
     "403": {
      "description": "No access to this agent"
     },
     "404": {
      "description": "There's no stop list in this build"
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/followups": {
   "get": {
    "tags": [
     "Dashboard · Deferred work"
    ],
    "summary": "What the agent will do later",
    "description": "One-off deferrals: \"I'll check the metrics in a day\", \"I'll remind you tomorrow\".\n\nThese are **not triggers**. The owner sets up a trigger, and it wakes the agent every time; the agent creates a deferral itself while working, once and about a specific subject. If we mixed them, the owner's five triggers would drown in three hundred rows of \"remind Petrenko\".\n\nNearest first: the list answers \"what happens next\", not \"what did I ever set up\".",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     },
     {
      "name": "cursor",
      "in": "query",
      "required": false,
      "schema": {
       "type": "string"
      }
     }
    ],
    "responses": {
     "200": {
      "description": "The list",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "followups": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/PlannedWork"
           }
          },
          "next": {
           "type": "string"
          },
          "pending": {
           "type": "integer",
           "description": "How many are still waiting IN TOTAL. The number for the panel badge, not the page length."
          },
          "stuck": {
           "type": "integer",
           "description": "How much work did NOT happen in the last week: missed and failed. Separate from pending: that's still ahead, while this already didn't happen and is waiting for \"Replay\"."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "Sign-in required"
     },
     "403": {
      "description": "No access to this agent"
     },
     "404": {
      "description": "There's no deferred work in this build"
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/followups/{noteID}": {
   "delete": {
    "tags": [
     "Dashboard · Deferred work"
    ],
    "summary": "Cancel a deferral",
    "description": "The agent won't come back to this.\n\nDoesn't require admin rights: this TAKES work away rather than giving the agent new permissions.\n\nOnly what's still waiting can be cancelled: something already done returns 404, since there's nothing to cancel.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     },
     {
      "name": "noteID",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      }
     }
    ],
    "responses": {
     "204": {
      "description": "Cancelled"
     },
     "401": {
      "description": "Sign-in required"
     },
     "403": {
      "description": "No access to this agent"
     },
     "404": {
      "description": "No such work in the list (or there's no deferred work in this build)"
     },
     "409": {
      "description": "Too late to cancel: the work is no longer waiting; the agent has picked it up or done it. It stays in the list in its current state."
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/followups/{noteID}/retry": {
   "post": {
    "tags": [
     "Dashboard · Deferred work"
    ],
    "summary": "Retry work that was missed or failed",
    "description": "Queues THE SAME work again, in the agent's own words: the owner sees \"remind Petrenko about the invoice\" in the list, and the exact wording of the task is stored in the row.\n\nThis is a new deferral, not a revival of the old one. What was missed stays missed: the moment the agent scheduled it for has passed, and pretending it hasn't would mean carrying out \"remind me today before 18:00\" at three in the morning. The old row stays in the list as evidence that the work wasn't done at the time.\n\nOnly «проґавлено» (\"missed\") and «не вдалося» (\"failed\") can be retried: completed work is repeated with an ordinary request to the agent, and there's no point retrying something that's still waiting.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     },
     {
      "name": "noteID",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      }
     }
    ],
    "requestBody": {
     "required": false,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "after_minutes": {
          "type": "integer",
          "description": "In how many minutes to retry. 0 or absent means as soon as possible."
         }
        }
       }
      }
     }
    },
    "responses": {
     "201": {
      "description": "Queued again",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "id": {
           "type": "string"
          },
          "run_at": {
           "type": "string",
           "format": "date-time"
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "Sign-in required"
     },
     "403": {
      "description": "No access to this agent"
     },
     "404": {
      "description": "No such work in the list"
     },
     "409": {
      "description": "This state can't be retried, the deferred queue is full, or this work has already been queued again and is still waiting (we don't create a second identical one)"
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/questions": {
   "get": {
    "tags": [
     "Dashboard · Agent questions"
    ],
    "summary": "What the agent is asking about",
    "description": "Questions the agent asked the owner and is waiting on.\n\nThe agent has three ways to reach a person: \"allow an action\" (the approval queue), \"notify\" (an email) and this one, \"ask and continue after the answer\". It asks the question and ends its run; when the owner answers, the platform starts a separate run for it with the answer as input.\n\nWaiting ones first, then the newest at the top. Anyone with access can read.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     },
     {
      "name": "status",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "Only this state."
     },
     {
      "name": "cursor",
      "in": "query",
      "schema": {
       "type": "string"
      }
     }
    ],
    "responses": {
     "200": {
      "description": "A page of questions",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "questions": {
           "type": "array",
           "items": {
            "type": "object",
            "properties": {
             "id": {
              "type": "string"
             },
             "text": {
              "type": "string",
              "description": "The question itself, in the agent's words."
             },
             "next": {
              "type": "string",
              "description": "What the agent will do with the answer. This is the input of its next run: it will wake up with no memory of the conversation."
             },
             "status": {
              "type": "string",
              "enum": [
               "чекає",
               "відповіли",
               "протерміновано"
              ]
             },
             "answer": {
              "type": "string"
             },
             "answered_by": {
              "type": "string"
             },
             "session_id": {
              "type": "string"
             },
             "created_at": {
              "type": "string"
             },
             "expires_at": {
              "type": "string",
              "description": "A week from the question: an answer a month later answers something that no longer exists."
             },
             "answered_at": {
              "type": "string"
             },
             "personal": {
              "type": "boolean",
              "description": "Composed after reading the owner's email or calendar. For a member without admin rights, the content is replaced with the sentence «Особисте власника: …» (\"The owner's personal: …\"); only the workspace admins see what exactly it says."
             }
            }
           }
          },
          "next": {
           "type": "string"
          },
          "pending": {
           "type": "integer",
           "description": "How many are waiting IN TOTAL, without the filter: the number for the panel."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "Sign-in required"
     },
     "403": {
      "description": "No access to this agent"
     },
     "404": {
      "description": "Questions to the owner aren't available in this build"
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/questions/{qid}/answer": {
   "post": {
    "tags": [
     "Dashboard · Agent questions"
    ],
    "summary": "Answer the agent",
    "description": "Admin only: the answer starts the agent's work on behalf of the company.\n\nEXACTLY ONE answer is accepted: a second one gets 409; otherwise the agent would continue twice. An expired question returns 410 with the question itself: the agent is no longer waiting for it.\n\nAfter the answer, the agent continues in a SEPARATE run a minute later, with the question, the answer and what it was going to do as input.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     },
     {
      "name": "qid",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Question ID."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "required": [
         "answer"
        ],
        "properties": {
         "answer": {
          "type": "string",
          "description": "The owner's answer, in their own words."
         }
        }
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Answer passed on, the agent's run has been started",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "question": {
           "type": "object",
           "properties": {
            "id": {
             "type": "string"
            },
            "text": {
             "type": "string",
             "description": "The question itself, in the agent's words."
            },
            "next": {
             "type": "string",
             "description": "What the agent will do with the answer. This is the input of its next run: it will wake up with no memory of the conversation."
            },
            "status": {
             "type": "string",
             "enum": [
              "чекає",
              "відповіли",
              "протерміновано"
             ]
            },
            "answer": {
             "type": "string"
            },
            "answered_by": {
             "type": "string"
            },
            "session_id": {
             "type": "string"
            },
            "created_at": {
             "type": "string"
            },
            "expires_at": {
             "type": "string",
             "description": "A week from the question: an answer a month later answers something that no longer exists."
            },
            "answered_at": {
             "type": "string"
            },
            "personal": {
             "type": "boolean",
             "description": "Composed after reading the owner's email or calendar. For a member without admin rights, the content is replaced with the sentence «Особисте власника: …» (\"The owner's personal: …\"); only the workspace admins see what exactly it says."
            }
           }
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "Empty or too long answer"
     },
     "401": {
      "description": "Sign-in required"
     },
     "403": {
      "description": "Admin rights required"
     },
     "404": {
      "description": "No such question"
     },
     "409": {
      "description": "This question has already been answered"
     },
     "410": {
      "description": "The question has expired; the agent is no longer waiting for it. The question itself (`question`) comes with the error, to show what exactly was missed.",
      "content": {
       "application/json": {
        "schema": {
         "allOf": [
          {
           "$ref": "#/components/schemas/Error"
          },
          {
           "type": "object",
           "properties": {
            "question": {
             "type": "object",
             "properties": {
              "id": {
               "type": "string"
              },
              "text": {
               "type": "string",
               "description": "The question itself, in the agent's words."
              },
              "next": {
               "type": "string",
               "description": "What the agent will do with the answer. This is the input of its next run: it will wake up with no memory of the conversation."
              },
              "status": {
               "type": "string",
               "enum": [
                "чекає",
                "відповіли",
                "протерміновано"
               ]
              },
              "answer": {
               "type": "string"
              },
              "answered_by": {
               "type": "string"
              },
              "session_id": {
               "type": "string"
              },
              "created_at": {
               "type": "string"
              },
              "expires_at": {
               "type": "string",
               "description": "A week from the question: an answer a month later answers something that no longer exists."
              },
              "answered_at": {
               "type": "string"
              },
              "personal": {
               "type": "boolean",
               "description": "Composed after reading the owner's email or calendar. For a member without admin rights, the content is replaced with the sentence «Особисте власника: …» (\"The owner's personal: …\"); only the workspace admins see what exactly it says."
              }
             }
            }
           }
          }
         ]
        }
       }
      }
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/records": {
   "get": {
    "tags": [
     "Dashboard · Agent cards"
    ],
    "summary": "What the agent has collected",
    "description": "Agent cards: objects it found, venues, contacts, drafts, metrics.\n\nThis isn't knowledge. The agent retells knowledge in its own words; a card is a row the agent ACTS on, with a natural key for deduplication and a state it's looked up by.\n\nAnyone with access can read: an operator must see what the agent has already found; otherwise they'd do the same work a second time.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     },
     {
      "name": "kind",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "Only this card set."
     },
     {
      "name": "status",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "Only this state."
     },
     {
      "name": "q",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "A substring in the card's fields: this is how you find an object by address or phone."
     },
     {
      "name": "like",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "Cards SIMILAR IN MEANING to this description. Deliberately separate from `q`: \"Valencia\" is a substring, while \"income property by the sea\" is a description that shares no words with the card. Works together with `kind` and `status`: it changes the order of results, not the filter. Only where the platform has a semantic search model; without one, a request with `like` gets 400 with the words \"search by words\": a freshness-ordered list isn't passed off as the most similar."
     },
     {
      "name": "since",
      "in": "query",
      "schema": {
       "type": "string",
       "format": "date-time"
      },
      "description": "Only cards updated after this timestamp: this is how a daily report tells new items from yesterday's."
     },
     {
      "name": "task",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "View through a long task's eyes: only the cards it marked, with the states they have IN THAT TASK. The notebook holds one card per key, no matter how many tasks come across it; \"checked\" or \"meets the criteria\" is a work state, and each task has its own."
     },
     {
      "name": "cursor",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "Continuation of the previous page."
     },
     {
      "name": "where",
      "in": "query",
      "schema": {
       "type": "array",
       "items": {
        "type": "string"
       }
      },
      "style": "form",
      "explode": true,
      "description": "A condition on a card field; the parameter can be repeated. `price<=450000`, `plot>=2000`, `district~chamberí` (contains), `phone has` (the field exists), `phone none` (the field is missing); operators: <=, >=, <, >, =, !=, ~. `_.rating=fits` is a field in the service part. This is a comparison in the database: it works even without semantic search. A card that lacks the field STAYS in the results by default, below the confirmed ones (see explain): \"we don't know\" isn't the same as \"doesn't fit\"."
     },
     {
      "name": "strict",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "true: only cards where every where condition is confirmed."
     },
     {
      "name": "sort",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "The field to sort by; a leading \"-\" means descending. Numbers are compared as numbers; cards without the field go last."
     },
     {
      "name": "collapse",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "true: a group of duplicates as a single card (the best of those that passed the filter), with a copies count."
     },
     {
      "name": "created_since",
      "in": "query",
      "schema": {
       "type": "string",
       "format": "date-time"
      },
      "description": "Only cards that appeared after this timestamp. Not the same as since: a sweep also updates old cards, while \"new since last time\" means cards that didn't exist then."
     }
    ],
    "responses": {
     "200": {
      "description": "A page of cards",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "records": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/RecordCard"
           }
          },
          "next": {
           "type": "string",
           "description": "Cursor for the next page. Empty means that's everything."
          },
          "total": {
           "type": "integer",
           "description": "How many records the agent has IN TOTAL, without filters: so the ceiling is visible before you hit it."
          },
          "matched": {
           "type": "integer",
           "description": "How many cards match the query in total, not just on this page."
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "`like` in a build without semantic search.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "description": "Sign-in required"
     },
     "403": {
      "description": "No access to this agent"
     },
     "404": {
      "description": "Cards aren't available in this build"
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/records/kinds": {
   "get": {
    "tags": [
     "Dashboard · Agent cards"
    ],
    "summary": "Which card sets the agent keeps",
    "description": "Card sets with counters, total and by state. Separate from the list because this answers \"what has it collected at all\", and that's needed BEFORE choosing a set. The per-state counters are what make up \"checked 347 of 520\".",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     },
     {
      "name": "task",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "Counters for one long task: only its cards and their states in it."
     }
    ],
    "responses": {
     "200": {
      "description": "Card sets",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "kinds": {
           "type": "array",
           "items": {
            "type": "object",
            "properties": {
             "kind": {
              "type": "string"
             },
             "count": {
              "type": "integer"
             },
             "statuses": {
              "type": "array",
              "items": {
               "$ref": "#/components/schemas/StatusCount"
              },
              "description": "How many cards in the set are in each state."
             }
            }
           }
          },
          "total": {
           "type": "integer"
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "Sign-in required"
     },
     "403": {
      "description": "No access to this agent"
     },
     "404": {
      "description": "Cards aren't available in this build"
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/records/{kind}/{key}": {
   "get": {
    "tags": [
     "Dashboard · Agent cards"
    ],
    "summary": "A single card",
    "description": "A single card's address isn't there for completeness: the agent's daily report is made of rows, each of which links TO A CARD.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     },
     {
      "name": "kind",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Card set name: listing, investor, platform, post. The owner gives it; the platform doesn't invent its own."
     },
     {
      "name": "key",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "The card's natural key: a link, an id, a phone number."
     }
    ],
    "responses": {
     "200": {
      "description": "The card",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "record": {
           "$ref": "#/components/schemas/RecordCard"
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "Sign-in required"
     },
     "403": {
      "description": "No access to this agent"
     },
     "404": {
      "description": "No such card"
     }
    }
   },
   "put": {
    "tags": [
     "Dashboard · Agent cards"
    ],
    "summary": "Fix or add a card",
    "description": "Admin only: the agent will act on these cards tomorrow, and a fix here changes its behavior just as a change to an action does.\n\nA write with the same key UPDATES the existing card instead of being added next to it.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     },
     {
      "name": "kind",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Card set name: listing, investor, platform, post. The owner gives it; the platform doesn't invent its own."
     },
     {
      "name": "key",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "The card's natural key: a link, an id, a phone number."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "status": {
          "type": "string"
         },
         "data": {
          "type": "object",
          "additionalProperties": true
         }
        }
       }
      }
     }
    },
    "responses": {
     "201": {
      "description": "Card created"
     },
     "204": {
      "description": "Card updated"
     },
     "400": {
      "description": "Card fields required"
     },
     "401": {
      "description": "Sign-in required"
     },
     "403": {
      "description": "Admin rights required"
     },
     "409": {
      "description": "Limit reached: the card is too large, the set is full, or there are already too many sets"
     }
    }
   },
   "delete": {
    "tags": [
     "Dashboard · Agent cards"
    ],
    "summary": "Discard a card",
    "description": "Admin only. A discarded card means the agent no longer knows it has already seen this, and it will find it again on its next sweep.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     },
     {
      "name": "kind",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Card set name: listing, investor, platform, post. The owner gives it; the platform doesn't invent its own."
     },
     {
      "name": "key",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "The card's natural key: a link, an id, a phone number."
     }
    ],
    "responses": {
     "204": {
      "description": "Discarded"
     },
     "401": {
      "description": "Sign-in required"
     },
     "403": {
      "description": "Admin rights required"
     },
     "404": {
      "description": "No such card"
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/records/{kind}": {
   "delete": {
    "tags": [
     "Dashboard · Agent cards"
    ],
    "summary": "Discard an entire card set",
    "description": "Admin only. Removes all cards in the set. Needed where the ceiling is the number of sets: an agent that created a set for every date hits it, and there's exactly one way out: discard the extra ones. Afterwards the agent doesn't know it has already seen these cards, and it will find them again on its next sweep.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     },
     {
      "name": "kind",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Card set name: listing, investor, platform, post. The owner gives it; the platform doesn't invent its own."
     }
    ],
    "responses": {
     "200": {
      "description": "Removed",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "required": [
          "removed"
         ],
         "properties": {
          "removed": {
           "type": "integer",
           "description": "How many cards were removed."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "Sign-in required"
     },
     "403": {
      "description": "Admin rights required"
     },
     "404": {
      "description": "No such card set"
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/records/{kind}/forget-old": {
   "post": {
    "tags": [
     "Dashboard · Agent cards"
    ],
    "summary": "Remove old cards from a set",
    "description": "Admin only. Removes from the set everything the agent hasn't touched for this many days (we look at the time of the last change, not when the card appeared: a card the agent saw yesterday isn't old). This is the way out of the \"notebook is full\" incident: the set's ceiling exists either way, and it's better to clear out old cards than to hit it in the middle of work.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     },
     {
      "name": "kind",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Card set name: listing, investor, platform, post. The owner gives it; the platform doesn't invent its own."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "required": [
         "older_than_days"
        ],
        "properties": {
         "older_than_days": {
          "type": "integer",
          "minimum": 1,
          "description": "How many days to keep cards. Less than a day is refused: that's no longer \"clearing out the old\", it's erasing work that was just done."
         }
        }
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Removed",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "required": [
          "removed"
         ],
         "properties": {
          "removed": {
           "type": "integer",
           "description": "How many cards were removed."
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "No number of days to keep given, or the age is less than a day"
     },
     "401": {
      "description": "Sign-in required"
     },
     "403": {
      "description": "Admin rights required"
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/connections": {
   "get": {
    "tags": [
     "Dashboard · Connected accounts"
    ],
    "summary": "Connected accounts",
    "description": "Access the agent has to OTHER PEOPLE'S accounts with their owners' consent: a customer's page, their calendar, their email.\n\nThis isn't the same as a key in an action's header: a key acts on behalf of the agent's owner, while a connection acts on behalf of whoever gave consent in the service itself.\n\nThe platform deliberately doesn't keep a list of ready-made services: the owner provides the consent and exchange URLs, just like the URL of any other action. A list would be convenient and would become a promise: anything not on it would read as \"the platform can't do this\".",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     }
    ],
    "responses": {
     "200": {
      "description": "The list",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "connections": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/Connection"
           }
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "Sign-in required"
     },
     "403": {
      "description": "No access to this agent"
     },
     "404": {
      "description": "Access to connected accounts isn't included in this build"
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/connections/{name}/start": {
   "post": {
    "tags": [
     "Dashboard · Connected accounts"
    ],
    "summary": "Consent link",
    "description": "Returns the URL to send the person to so they can allow access.\n\nThe link is RETURNED, not followed as a redirect: a person has to click it, deliberately and seeing where it leads.\n\nThe link contains a signed one-time `state` that expires in five minutes. Without it, anyone able to open the URL could attach their own account to your agent.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     },
     {
      "name": "name",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Connection name: the same one the agent's actions use for it."
     }
    ],
    "responses": {
     "200": {
      "description": "The link",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "url": {
           "type": "string"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "The connection is missing URLs or the application ID"
     },
     "401": {
      "description": "Sign-in required"
     },
     "403": {
      "description": "No access to this agent"
     },
     "404": {
      "description": "Access to connected accounts isn't included in this build"
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/connections/setup": {
   "post": {
    "tags": [
     "Dashboard · Connected accounts"
    ],
    "summary": "Connect a service by its address",
    "description": "The platform asks the service itself how to work with it, and registers an application in it on its own.\n\nUntil now, only someone who could read RFCs could set up a connection: register an application in a third-party service, get the client_id and secret, find the consent and exchange URLs in the docs, enter our redirect URL. In other words, the capability existed, but there was no way in for a person.\n\nServices describe themselves: RFC 8414 / OpenID Discovery for URLs and scopes; RFC 7591 for registering an application with a single request. A service that supports both connects with a single address, and the application secret goes into the agent's keys without ever being shown to the person.\n\nA service without self-registration isn't a dead end: the `registered: false` response returns the URLs and scopes already discovered and the `redirect_uri` the person enters in the service's dashboard. Two of the seven fields are left.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "required": [
         "site"
        ],
        "properties": {
         "site": {
          "type": "string",
          "description": "The service address as the person gave it: rombik.app. The scheme and path can be omitted; https is required."
         },
         "name": {
          "type": "string",
          "description": "Connection name. Empty: derived from the address (rombik.app → rombik)."
         }
        }
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Discovery succeeded. registered=true: the connection is ready and `url` leads to the consent page; registered=false: the service doesn't allow self-registration, and the body has what the person will enter by hand.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "registered": {
           "type": "boolean"
          },
          "name": {
           "type": "string"
          },
          "secret_name": {
           "type": "string",
           "description": "Name of the key the application secret is stored under. The value is never returned to anyone."
          },
          "auth_url": {
           "type": "string"
          },
          "token_url": {
           "type": "string"
          },
          "scopes": {
           "type": "array",
           "items": {
            "type": "string"
           }
          },
          "redirect_uri": {
           "type": "string",
           "description": "Only when registered=false: the redirect URL for the service's dashboard."
          },
          "why": {
           "type": "string",
           "description": "Only when registered=false: why the automatic setup didn't work."
          },
          "url": {
           "type": "string",
           "description": "Consent link. It must be opened by THE person whose account is being connected."
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "No service address given"
     },
     "401": {
      "description": "Sign-in required"
     },
     "403": {
      "description": "Admin rights required"
     },
     "404": {
      "description": "Access to connected accounts isn't included in this build"
     },
     "422": {
      "description": "The service doesn't describe itself automatically; the URLs will have to be provided"
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/connections/{name}": {
   "put": {
    "tags": [
     "Dashboard · Connected accounts"
    ],
    "summary": "Configure a connection",
    "description": "Creates or updates a connection to an external service: where to send the person for consent, where to exchange the code for a token, and with which application.\n\nThe platform doesn't keep a list of ready-made services: the owner provides the URLs, just like the URL of any action.\n\nThe application secret is NOT passed here: the `secret_name` field holds the name of the key in the agent's key store. A value that never passes through this endpoint has nowhere to leak.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     },
     {
      "name": "name",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Connection name: the same one the agent's actions use for it."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "auth_url": {
          "type": "string",
          "description": "Where to send the person for consent."
         },
         "token_url": {
          "type": "string",
          "description": "Where to exchange the code for a token and refresh it."
         },
         "client_id": {
          "type": "string",
          "description": "The application ID in the third-party service. Not a secret."
         },
         "secret_name": {
          "type": "string",
          "description": "Name of the key in the agent's key store that holds the application secret."
         },
         "scopes": {
          "type": "array",
          "items": {
           "type": "string"
          },
          "description": "Which scopes to request."
         },
         "extra": {
          "type": "object",
          "additionalProperties": {
           "type": "string"
          },
          "description": "Extra parameters for the consent link. Two are known: \"access_type=offline\" (without it, some services don't issue a refresh token at all) and \"pkce=off\" (for services that reject unfamiliar parameters; PKCE is on by default). redirect_uri and state can't be overridden; otherwise the consent code would go somewhere other than us."
         }
        },
        "required": [
         "auth_url",
         "token_url",
         "client_id"
        ]
       }
      }
     }
    },
    "responses": {
     "204": {
      "description": "Saved"
     },
     "400": {
      "description": "URLs or the application ID are missing"
     },
     "401": {
      "description": "Sign-in required"
     },
     "403": {
      "description": "Configured by the workspace admin"
     },
     "404": {
      "description": "Access to connected accounts isn't included in this build"
     },
     "409": {
      "description": "Too many connections already"
     }
    }
   },
   "delete": {
    "tags": [
     "Dashboard · Connected accounts"
    ],
    "summary": "Remove access",
    "description": "Removes the connection TOGETHER with the access that was granted: a connection without access looks like it works in the dashboard, and the owner would learn the truth from a customer's first action.\n\nAfter this, all actions that worked on behalf of the connected account stop working, which is why the event is recorded in the change log.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     },
     {
      "name": "name",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Connection name: the same one the agent's actions use for it."
     }
    ],
    "responses": {
     "204": {
      "description": "Removed"
     },
     "401": {
      "description": "Sign-in required"
     },
     "403": {
      "description": "No access to this agent"
     },
     "404": {
      "description": "Access to connected accounts isn't included in this build"
     }
    }
   }
  },
  "/v1/oauth/callback": {
   "get": {
    "tags": [
     "Dashboard · Connected accounts"
    ],
    "summary": "Return after consent",
    "description": "This is where a third-party service sends the person back after they allowed (or didn't allow) access.\n\n**No authorization**, and that's not an oversight: the person arrives here in a browser from another website, with no session and no key. Instead of authentication, the request is guarded by the signed `state`: it holds the agent and an expiry, and it's checked first.\n\nResponds with a redirect to the dashboard: people arrive here in a browser, and seeing JSON here would be a dead end.",
    "security": [],
    "parameters": [
     {
      "name": "state",
      "in": "query",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "The signed state issued in the consent link."
     },
     {
      "name": "code",
      "in": "query",
      "required": false,
      "schema": {
       "type": "string"
      },
      "description": "The consent code from the service."
     },
     {
      "name": "error",
      "in": "query",
      "required": false,
      "schema": {
       "type": "string"
      },
      "description": "The reason for refusal, if the person didn't allow access."
     }
    ],
    "responses": {
     "302": {
      "description": "Redirect to the dashboard with `oauth_ok` or `oauth_error` in the query"
     },
     "404": {
      "description": "Access to connected accounts isn't included in this build"
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/tasks": {
   "get": {
    "tags": [
     "Dashboard · Long tasks"
    ],
    "summary": "Agent long tasks",
    "description": "Work bigger than a single run: going through hundreds of sources, building a database. The agent creates a task in the conversation with whoever asks, and the platform continues it pass after pass until the agent says \"done\", a person stops it, or the platform sees there's no point in going on.\n\nThese are **not triggers** and **not deferred work**. A trigger wakes the agent every time on a schedule and doesn't know the word \"done\"; a deferral is a single return to a single subject. A task keeps going until it's finished, and the whole time it's visible here, with progress in numbers.\n\nNewest first.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     },
     {
      "name": "cursor",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "Continuation of the previous page."
     }
    ],
    "responses": {
     "200": {
      "description": "The list",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "tasks": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/LongTask"
           }
          },
          "next": {
           "type": "string",
           "description": "Cursor for the next page. Empty means that's everything."
          },
          "open": {
           "type": "integer",
           "description": "How many tasks haven't finished yet (running or stopped). The number for the panel, not the page length."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "Sign-in required"
     },
     "403": {
      "description": "No access to this agent"
     },
     "404": {
      "description": "There are no long tasks in this build, or there's no such task"
     }
    }
   },
   "post": {
    "tags": [
     "Dashboard · Long tasks"
    ],
    "summary": "Create a task",
    "description": "Creates a task on behalf of the owner; the first pass starts immediately. A task like this has no conversation, so the summary goes to the owner as a notification and stays in the task itself.\n\nA task **spends credits on its own**: a pass every half minute until it finishes. An agent runs no more than three at a time.\n\nThe agent must have the `long_task` capability together with a notebook: without them, a pass has nowhere to put what it found and no way to say \"done\".",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "required": [
         "title",
         "brief"
        ],
        "properties": {
         "title": {
          "type": "string",
          "description": "Title in a few words."
         },
         "brief": {
          "type": "string",
          "description": "What to do and by what criteria, complete and self-contained."
         },
         "sets": {
          "type": "array",
          "items": {
           "type": "string"
          },
          "description": "Notebook card sets the task will keep. Optional: the agent will name them itself."
         }
        }
       }
      }
     }
    },
    "responses": {
     "201": {
      "description": "Created",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "task": {
           "$ref": "#/components/schemas/LongTask"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "No title or description"
     },
     "401": {
      "description": "Sign-in required"
     },
     "403": {
      "description": "Admin role required"
     },
     "404": {
      "description": "There are no long tasks in this build, or there's no such task"
     },
     "409": {
      "description": "As many tasks as allowed at once are already running"
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/tasks/{tid}": {
   "get": {
    "tags": [
     "Dashboard · Long tasks"
    ],
    "summary": "A single task",
    "description": "The task with its progress from the notebook.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     },
     {
      "name": "tid",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Task ID."
     }
    ],
    "responses": {
     "200": {
      "description": "The task",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "task": {
           "$ref": "#/components/schemas/LongTask"
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "Sign-in required"
     },
     "403": {
      "description": "No access to this agent"
     },
     "404": {
      "description": "There are no long tasks in this build, or there's no such task"
     }
    }
   },
   "put": {
    "tags": [
     "Dashboard · Long tasks"
    ],
    "summary": "Change a task's criteria",
    "description": "Replaces the task description. The next pass learns about the change in a separate line: it will review what's already been collected against the new criteria, not just use them to search further.\n\nThe task's state doesn't change: a paused task stays paused, and resuming it is a separate action.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     },
     {
      "name": "tid",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Task ID."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "required": [
         "brief"
        ],
        "properties": {
         "brief": {
          "type": "string",
          "description": "The new description in full, not just what changed: the pass reads only this."
         }
        }
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Criteria changed",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "task": {
           "$ref": "#/components/schemas/LongTask"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "Empty description"
     },
     "401": {
      "description": "Sign-in required"
     },
     "403": {
      "description": "Admin role required"
     },
     "404": {
      "description": "There are no long tasks in this build, or there's no such task"
     },
     "409": {
      "description": "The task has already finished"
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/tasks/{tid}/pause": {
   "post": {
    "tags": [
     "Dashboard · Long tasks"
    ],
    "summary": "Pause a task",
    "description": "A pass that's already running will finish, but there won't be a next one: cutting it off mid-write would leave the work half-done. What's been collected stays.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     },
     {
      "name": "tid",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Task ID."
     }
    ],
    "responses": {
     "200": {
      "description": "Paused",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "task": {
           "$ref": "#/components/schemas/LongTask"
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "Sign-in required"
     },
     "403": {
      "description": "Admin role required"
     },
     "404": {
      "description": "There are no long tasks in this build, or there's no such task"
     },
     "409": {
      "description": "The task isn't running right now or has already finished"
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/tasks/{tid}/resume": {
   "post": {
    "tags": [
     "Dashboard · Long tasks"
    ],
    "summary": "Resume a paused task",
    "description": "A pass starts immediately. The failure counters and the pass ceiling start over: a person has looked and said \"go on\". The \"task stopped\" incident is closed.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     },
     {
      "name": "tid",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Task ID."
     }
    ],
    "responses": {
     "200": {
      "description": "Resumed",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "task": {
           "$ref": "#/components/schemas/LongTask"
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "Sign-in required"
     },
     "403": {
      "description": "Admin role required"
     },
     "404": {
      "description": "There are no long tasks in this build, or there's no such task"
     },
     "409": {
      "description": "The task isn't paused, has already finished, or as many tasks as allowed at once are already running"
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/tasks/{tid}/cancel": {
   "post": {
    "tags": [
     "Dashboard · Long tasks"
    ],
    "summary": "Cancel a task",
    "description": "Final: a cancelled task can't be resumed, only a new one created. Everything the task collected stays in the notebook: cancelling applies to the work, not its results. If you only need to hold it, there's pause.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     },
     {
      "name": "tid",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Task ID."
     }
    ],
    "responses": {
     "200": {
      "description": "Cancelled",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "task": {
           "$ref": "#/components/schemas/LongTask"
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "Sign-in required"
     },
     "403": {
      "description": "Admin role required"
     },
     "404": {
      "description": "There are no long tasks in this build, or there's no such task"
     },
     "409": {
      "description": "The task has already finished"
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/records/export": {
   "get": {
    "tags": [
     "Dashboard · Agent cards"
    ],
    "summary": "Cards as a spreadsheet: Excel or CSV",
    "description": "The same filters as the list: exactly what the person is looking at is exported, and ALL cards in the selection, not one page.\n\nColumns are built from the cards: key, state, then the fields of all cards in order of first appearance, and at the end, when it was updated. A card set column is added only when no set is specified. A number in a field stays a number.\n\nIn CSV, a cell that starts with a formula character gets an apostrophe: the agent collects cards from other people's pages, and a listing title must not turn into a formula the moment the owner opens the file.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     },
     {
      "name": "format",
      "in": "query",
      "schema": {
       "type": "string",
       "enum": [
        "xlsx",
        "csv"
       ],
       "default": "xlsx"
      },
      "description": "File type. Excel workbook by default."
     },
     {
      "name": "kind",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "Only this card set."
     },
     {
      "name": "status",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "Only this state."
     },
     {
      "name": "task",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "Only this long task's cards, with their states in it."
     },
     {
      "name": "q",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "A substring in the card's fields."
     },
     {
      "name": "since",
      "in": "query",
      "schema": {
       "type": "string",
       "format": "date-time"
      },
      "description": "Only cards updated after this timestamp."
     },
     {
      "name": "where",
      "in": "query",
      "schema": {
       "type": "array",
       "items": {
        "type": "string"
       }
      },
      "style": "form",
      "explode": true,
      "description": "A condition on a card field; the parameter can be repeated. `price<=450000`, `plot>=2000`, `district~chamberí` (contains), `phone has` (the field exists), `phone none` (the field is missing); operators: <=, >=, <, >, =, !=, ~. `_.rating=fits` is a field in the service part. This is a comparison in the database: it works even without semantic search. A card that lacks the field STAYS in the results by default, below the confirmed ones (see explain): \"we don't know\" isn't the same as \"doesn't fit\"."
     },
     {
      "name": "strict",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "true: only cards where every where condition is confirmed."
     },
     {
      "name": "sort",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "The field to sort by; a leading \"-\" means descending. Numbers are compared as numbers; cards without the field go last."
     },
     {
      "name": "collapse",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "true: a group of duplicates as a single card (the best of those that passed the filter), with a copies count."
     },
     {
      "name": "created_since",
      "in": "query",
      "schema": {
       "type": "string",
       "format": "date-time"
      },
      "description": "Only cards that appeared after this timestamp. Not the same as since: a sweep also updates old cards, while \"new since last time\" means cards that didn't exist then."
     }
    ],
    "responses": {
     "200": {
      "description": "The file",
      "headers": {
       "X-Records-Count": {
        "schema": {
         "type": "integer"
        },
        "description": "How many cards are in the file."
       }
      },
      "content": {
       "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": {
        "schema": {
         "type": "string",
         "format": "binary"
        }
       },
       "text/csv": {
        "schema": {
         "type": "string",
         "format": "binary"
        }
       }
      }
     },
     "400": {
      "description": "Unknown file type"
     },
     "401": {
      "description": "Sign-in required"
     },
     "403": {
      "description": "No access to this agent"
     },
     "404": {
      "description": "Cards aren't available in this build"
     },
     "413": {
      "description": "The selection has more cards than one file can hold (50,000). The file isn't truncated: narrow the selection by card set, state or date.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/widget": {
   "get": {
    "tags": [
     "Dashboard · Agents"
    ],
    "summary": "Chat window appearance on the website",
    "description": "The same thing the chat window gets from `GET /v1/widget/config`, for previewing in the dashboard. It's built by the same code, so what the preview shows can't diverge from what a visitor will see.\n\nA separate endpoint rather than the publishable key: the key is bound to allowed domains, and the dashboard's address doesn't have to be among them.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     }
    ],
    "responses": {
     "200": {
      "description": "Chat window settings.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/WidgetConfig"
        }
       }
      }
     },
     "401": {
      "description": "No valid session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The role doesn't allow this action.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Agent not found, or it belongs to another workspace.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/catalog": {
   "get": {
    "tags": [
     "Dashboard · Product catalog"
    ],
    "summary": "Product catalog",
    "description": "Shop products the agent knows from the **feed**, a file with the whole product range that the shop provides to marketplaces. When a catalog is connected, the agent searches it on its own during conversations: no separate capability needs to be turned on.\n\nThis isn't knowledge: knowledge is page text searched by meaning; here there are rows with price and availability, which can number in the thousands and cost no credits.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     }
    ],
    "responses": {
     "200": {
      "description": "Catalog status.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "required": [
          "catalog"
         ],
         "properties": {
          "catalog": {
           "$ref": "#/components/schemas/Catalog"
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "Sign-in required"
     },
     "403": {
      "description": "No access to this agent"
     },
     "404": {
      "description": "There's no product catalog in this build."
     }
    }
   },
   "put": {
    "tags": [
     "Dashboard · Product catalog"
    ],
    "summary": "Connect a product feed",
    "description": "Saves the feed link and **reads it right away**. Understands YML price lists (Rozetka, Prom, Hotline) and Google Merchant feeds (RSS or Atom).\n\nAfter that the feed is re-read automatically, daily by default: reading costs no credits, but an outdated price does, because it gets quoted to the buyer. The same link with a different `every_hours` only changes the schedule.\n\nA link that didn't open or turned out not to be a feed **isn't saved**: otherwise the catalog would \"exist\" but be empty. Role: admin.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     }
    ],
    "responses": {
     "200": {
      "description": "Feed read.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "required": [
          "catalog",
          "report"
         ],
         "properties": {
          "catalog": {
           "$ref": "#/components/schemas/Catalog"
          },
          "report": {
           "$ref": "#/components/schemas/CatalogReport"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "The link is unusable, or it doesn't point to a product feed.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "description": "Sign-in required"
     },
     "403": {
      "description": "No access to this agent"
     },
     "404": {
      "description": "There's no product catalog in this build."
     },
     "502": {
      "description": "Couldn't download the file from the shop.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "required": [
         "url"
        ],
        "properties": {
         "url": {
          "type": "string",
          "description": "The full feed link, with `https://`."
         },
         "every_hours": {
          "type": "integer",
          "minimum": 1,
          "maximum": 720,
          "description": "How often to re-read, in hours. Without the field, the existing schedule stays; for the first connection, 24."
         }
        }
       }
      }
     }
    }
   },
   "delete": {
    "tags": [
     "Dashboard · Product catalog"
    ],
    "summary": "Remove the product catalog",
    "description": "Removes the feed link together with the products: the agent stops searching the product range. Role: admin.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     }
    ],
    "responses": {
     "200": {
      "description": "Catalog removed.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "required": [
          "catalog"
         ],
         "properties": {
          "catalog": {
           "$ref": "#/components/schemas/Catalog"
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "Sign-in required"
     },
     "403": {
      "description": "No access to this agent"
     },
     "404": {
      "description": "There's no product catalog in this build."
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/catalog/sync": {
   "post": {
    "tags": [
     "Dashboard · Product catalog"
    ],
    "summary": "Re-read the feed now",
    "description": "Reads the feed without waiting for the schedule. If reading fails, the products from the previous read **stay**, and the agent gets a `catalog_stale` incident; a successful read clears it. Role: admin.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     }
    ],
    "responses": {
     "200": {
      "description": "Feed re-read.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "required": [
          "catalog",
          "report"
         ],
         "properties": {
          "catalog": {
           "$ref": "#/components/schemas/Catalog"
          },
          "report": {
           "$ref": "#/components/schemas/CatalogReport"
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "Sign-in required"
     },
     "403": {
      "description": "No access to this agent"
     },
     "404": {
      "description": "There's no product catalog in this build, or no feed is connected to the agent yet."
     },
     "409": {
      "description": "The feed link was changed while the feed was being read: products have already been read from the new link, and what was read from the old one wasn't saved.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "502": {
      "description": "Couldn't download the file; the catalog keeps the previous prices.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/catalog/discover": {
   "post": {
    "tags": [
     "Dashboard · Product catalog"
    ],
    "summary": "Find a feed on the shop's website",
    "description": "Looks for the product file on its own, so you don't have to hunt for the feed link in the shop's admin panel. It checks links on the home page, the platform's typical URLs (where the feed URL is the same for every shop) and the sitemap. **Every candidate is verified**: only a file that products were read from makes it into the response.\n\nConnects nothing: the link found is passed to `PUT /v1/dashboard/bots/{id}/catalog`. If no feed is found, `steps` says where to get the link by hand, for a recognized platform or in general.\n\n`site` can be omitted: the search then covers the websites allowed for this agent's chat window.\n\nNo more than 12 requests go to the website, through the same fence as feed reading: private addresses are unreachable. Role: admin.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "site": {
          "type": "string",
          "description": "The shop's website address: `shop.ua` or `https://shop.ua`. The path is dropped. Empty means the websites where the agent's chat window is installed."
         }
        }
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Search finished. An empty `candidates` isn't an error: no feed is visible on the website.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "required": [
          "discovery"
         ],
         "properties": {
          "discovery": {
           "$ref": "#/components/schemas/CatalogDiscovery"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "The website address is unusable, or none was given and the agent has no websites yet.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "description": "Sign-in required"
     },
     "403": {
      "description": "No access to this agent"
     },
     "404": {
      "description": "There's no product catalog in this build."
     },
     "502": {
      "description": "The search couldn't be run.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/catalog/products": {
   "get": {
    "tags": [
     "Dashboard · Product catalog"
    ],
    "summary": "Search products",
    "description": "The same search the agent uses in a conversation — so you can check \"would it find this?\". Words are reduced to their stems (\"mice\" finds \"Mouse\"), and a match in the name weighs more than a match in the attributes; among equal matches, in-stock items come first, then cheaper ones. Returns up to eight products.\n\nWhen the words find fewer than three products and the build also searches by meaning (the `meaning` field in the catalog state), the response is topped up with products similar in meaning to the query; these carry `by_meaning: true`, and `total` counts them. The price, availability and category filters apply to both parts.\n\nVariants of one product (size, color) that the feed itself grouped are ONE product in the response, with a `variants` list: it takes one of the eight slots and is counted in `total` once. The `in_stock` filter lets a group through when at least one variant is in stock; price bounds apply to the lowest price among the in-stock variants.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     },
     {
      "name": "q",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "What to search for: type, brand, model."
     },
     {
      "name": "category",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "Part of the category name."
     },
     {
      "name": "price_from",
      "in": "query",
      "schema": {
       "type": "number"
      },
      "description": "Minimum price."
     },
     {
      "name": "price_to",
      "in": "query",
      "schema": {
       "type": "number"
      },
      "description": "Maximum price."
     },
     {
      "name": "in_stock",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "`true` — only items in stock."
     }
    ],
    "responses": {
     "200": {
      "description": "Products found.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "required": [
          "products",
          "total"
         ],
         "properties": {
          "products": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/CatalogProduct"
           }
          },
          "total": {
           "type": "integer",
           "description": "How many products match in total; a variant group counts as one product."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "Sign-in required"
     },
     "403": {
      "description": "No access to this agent"
     },
     "404": {
      "description": "There's no product catalog in this build."
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/shop/recognize": {
   "post": {
    "tags": [
     "Dashboard · Actions"
    ],
    "summary": "Detect the shop platform for \"where is my order\"",
    "description": "Opens the shop's home page (a single request, through the same guard as the feed search: private addresses are unreachable) and detects the shop platform. If a ready-made order connection exists for it, returns its `preset_id` and numbered steps showing where in the shop admin to get the key; you install it with the regular `POST /v1/dashboard/bots/{id}/skills/presets`. For platforms without a connection (OpenCart, Shopify), `note` explains why there isn't one.\n\nInstalls nothing and writes nothing to the change log. `site` is optional: if omitted, we look at the sites allowed to host this agent's chat window. Role: administrator.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "site": {
          "type": "string",
          "description": "The shop's site address: `shop.ua` or `https://shop.ua`. Empty — the sites where the agent's chat window is installed."
         }
        }
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Checked. An empty `engine` means the platform wasn't recognized (explanation in `note`).",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "required": [
          "shop"
         ],
         "properties": {
          "shop": {
           "$ref": "#/components/schemas/ShopLook"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "The website address is unusable, or none was given and the agent has no websites yet.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "description": "Sign-in required"
     },
     "403": {
      "description": "No access to this agent"
     },
     "404": {
      "description": "Shop detection isn't available in this build"
     },
     "502": {
      "description": "The site couldn't be opened.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/widget/thread": {
   "post": {
    "tags": [
     "Widget"
    ],
    "summary": "Conversation from another device",
    "description": "The latest conversation of a visitor **signed by the site** (the `user_auth` envelope, see \"Signed envelope\") — so someone who started on their phone can continue on their computer.\n\nSigned envelope only: an unsigned `user_token` or a name is not proof, and no conversation is recorded or returned under them. The server checks the signature with this agent's visitor signing key, the agent named in the envelope, and the expiry. If the envelope is missing, invalid, expired, or issued to another agent, or there is no conversation, the response is the same: 204.\n\nThe conversation is the one this person wrote in last, if no more than a day has passed since then (the chat window itself keeps it just as long). A conversation that already belongs to another signed visitor can't be taken over.\n\nPOST rather than GET: an envelope in the URL would end up in logs.",
    "security": [
     {
      "widgetKey": []
     }
    ],
    "parameters": [
     {
      "name": "X-Bot-Key",
      "in": "header",
      "required": true,
      "schema": {
       "type": "string",
       "example": "pk_…"
      },
      "description": "The agent's publishable key."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "required": [
         "user_auth"
        ],
        "properties": {
         "user_auth": {
          "type": "string",
          "description": "The visitor's signed envelope — the same one sent with messages."
         }
        }
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "The conversation.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "required": [
          "session_id",
          "messages",
          "status",
          "cursor",
          "updated_at"
         ],
         "properties": {
          "session_id": {
           "type": "string",
           "description": "The conversation to continue: subsequent messages are sent with this `session_id`."
          },
          "messages": {
           "type": "array",
           "description": "The latest messages (up to 60), oldest first.",
           "items": {
            "$ref": "#/components/schemas/Message"
           }
          },
          "status": {
           "$ref": "#/components/schemas/HandoffStatus"
          },
          "cursor": {
           "type": "string",
           "description": "Where to poll operator messages from (`GET /v1/widget/messages`) so you don't get what's shown here a second time."
          },
          "updated_at": {
           "type": "integer",
           "format": "int64",
           "description": "Time of the last message (Unix ms)."
          }
         }
        }
       }
      }
     },
     "204": {
      "description": "Nothing to continue: the envelope is missing or failed verification, or there is no conversation."
     },
     "400": {
      "description": "The body isn't JSON.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "description": "The agent key is unknown or revoked.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "Wrong key type, or the domain is not on the agent's allowed list.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "429": {
      "description": "Too many requests from this address.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "503": {
      "$ref": "#/components/responses/Unavailable"
     }
    }
   }
  },
  "/v1/widget/event": {
   "post": {
    "tags": [
     "Widget"
    ],
    "summary": "Funnel step",
    "description": "The chat window reports what **happened** in the conversation: it was opened, a question was asked, \"add to cart\" was clicked, the visitor went to a product, to a messenger, left a contact, called a human. The body is just the step name from a closed list: no conversation or visitor ID, no text, no page URL. The server adds one to the hourly counter.\n\nThe window sends each step once per conversation and sends nothing in preview mode or when the owner turned counting off (`widget_design.funnel: false`) — then the server also responds 204 without counting anything.\n\nThe key is publishable, so anyone can inflate a step: the endpoint has its own rate limit per key and address, and the dashboard shows the numbers as approximate.",
    "security": [
     {
      "widgetKey": []
     }
    ],
    "parameters": [
     {
      "name": "X-Bot-Key",
      "in": "header",
      "required": true,
      "schema": {
       "type": "string",
       "example": "pk_…"
      },
      "description": "The agent's publishable key."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "additionalProperties": false,
        "required": [
         "step"
        ],
        "properties": {
         "step": {
          "type": "string",
          "enum": [
           "opened",
           "asked",
           "cart",
           "product",
           "messenger",
           "continued",
           "lead",
           "human"
          ]
         }
        }
       }
      }
     }
    },
    "responses": {
     "204": {
      "description": "Counted (or there's nowhere to count it — the window doesn't care either way)."
     },
     "400": {
      "description": "Unknown step.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "description": "The agent key is unknown or revoked.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "Wrong key type, or the domain is not on the agent's allowed list.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "429": {
      "description": "Too many steps from this address.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/funnel": {
   "get": {
    "tags": [
     "Dashboard · Shop"
    ],
    "summary": "Chat window funnel",
    "description": "Whether the consultant sells: how many conversations in the chat window on the site reached each step over the period — opened, asked, \"add to cart\", went to a product, messenger, contact, human.\n\nPercentages are shown only when there are at least `needed` opened windows: \"2 of 3\" isn't 67 %, it's two people. The numbers are approximate: a step blocked by the visitor's browser is lost, and the publishable key allows inflation within the rate limit.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     },
     {
      "name": "period",
      "in": "query",
      "schema": {
       "type": "string",
       "enum": [
        "day",
        "week",
        "month"
       ]
      },
      "description": "The last day, 7 days (default) or 30 days."
     }
    ],
    "responses": {
     "200": {
      "description": "The funnel.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "required": [
          "funnel"
         ],
         "properties": {
          "funnel": {
           "$ref": "#/components/schemas/Funnel"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "Unknown period.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "description": "No valid session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The role doesn't allow this action.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Agent not found, or this build has no funnel.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/catalog/missed": {
   "get": {
    "tags": [
     "Dashboard · Product catalog"
    ],
    "summary": "Searched and not found",
    "description": "Queries the agent used to search the product catalog that **found no product by name** (similar in meaning doesn't count as found) — most frequent first. A direct hint about what to add to the range, or how to name a product the way people search for it.\n\nThe unit is the agent's query, not the shopper's message; no conversation text and no visitor data. Queries with price or availability bounds aren't included: they might have come up empty because of the bounds. The owner's rehearsals don't count. A row nobody has asked about for two months disappears on its own.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     }
    ],
    "responses": {
     "200": {
      "description": "The list.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "required": [
          "missed"
         ],
         "properties": {
          "missed": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/CatalogMiss"
           }
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "No valid session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The role doesn't allow this action.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Agent not found.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/catalog/missed/{missID}": {
   "delete": {
    "tags": [
     "Dashboard · Product catalog"
    ],
    "summary": "Remove a query from the list",
    "description": "Admin only: the product has already been added to the range, or the query isn't about a product. Only the next shopper who again finds nothing can bring the row back.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     },
     {
      "name": "missID",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "The row ID from the list."
     }
    ],
    "responses": {
     "204": {
      "description": "Removed."
     },
     "401": {
      "description": "Sign-in required.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "Admin rights required.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "There’s no such request in the list.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/widget/continue": {
   "post": {
    "tags": [
     "Widget"
    ],
    "summary": "Continue the conversation in a messenger",
    "description": "Returns a link to the agent's Telegram bot that opens THIS VERY conversation: the bot knows what was said in the chat window and carries on without greeting again. The link contains a one-time ticket valid for 10 minutes, not the `session_id`: whoever sees the link can't read the conversation. The conversation moves only to the private chat that opens the link first; opening it again, a different bot, or an expired ticket give the usual greeting. Call it when the button is pressed, not in advance: each call cancels the previous ticket for this conversation.",
    "security": [
     {
      "widgetKey": []
     }
    ],
    "parameters": [
     {
      "name": "X-Bot-Key",
      "in": "header",
      "required": true,
      "schema": {
       "type": "string",
       "example": "pk_…"
      },
      "description": "The agent's publishable key."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "session_id": {
          "type": "string",
          "description": "The chat window conversation to continue."
         }
        },
        "required": [
         "session_id"
        ]
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "The link.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/ContinueLink"
        }
       }
      }
     },
     "400": {
      "description": "`session_id` is missing or too long.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "description": "The agent key is unknown or revoked.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "Wrong key type, or the domain is not on the agent's allowed list.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "The agent has no messenger bot to continue in (`continue_in` in the chat window settings is empty).",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     },
     "503": {
      "$ref": "#/components/responses/Unavailable"
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/channels/{cid}/people": {
   "get": {
    "tags": [
     "Dashboard · Channels"
    ],
    "summary": "Who can write to the channel",
    "description": "People linked to the channel, and whether the channel replies only to them. The role is determined by the channel from the link, not by the message text: \"I'm the owner\" in a message counts for nothing.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     },
     {
      "name": "cid",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Channel ID."
     }
    ],
    "responses": {
     "200": {
      "description": "The list.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "people": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/ChannelPerson"
           }
          },
          "private": {
           "type": "boolean"
          },
          "pairable": {
           "type": "boolean"
          },
          "pairing_blocked": {
           "type": "string",
           "description": "The messenger can verify the sender, but this channel is missing a setting — in plain words for a person (for example, a WhatsApp channel without an App secret). The field is absent if linking is possible or the channel type doesn't verify senders at all."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "No valid session — log in again.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The current user's role doesn't allow this action.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Agent or channel not found.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/channels/{cid}/pairing": {
   "post": {
    "tags": [
     "Dashboard · Channels"
    ],
    "summary": "Issue a chat linking code",
    "description": "A one-time code valid for 10 minutes with which a person links THEIR OWN private chat to the bot themselves: they send it to the bot as text or open the `link` (Telegram). It works only in this channel; a new code cancels the previous one. The code doesn't work from a group. `private: true` — as soon as the code works, the channel will reply only to linked people. The code is shown only here; the database stores only its digest.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     },
     {
      "name": "cid",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Channel ID."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "role": {
          "type": "string",
          "enum": [
           "owner",
           "trusted"
          ],
          "description": "Defaults to owner."
         },
         "name": {
          "type": "string",
          "description": "What to call the person in the list; empty — the name from the messenger."
         },
         "private": {
          "type": "boolean",
          "description": "Close the channel to everyone else as soon as the code works."
         }
        }
       }
      }
     }
    },
    "responses": {
     "201": {
      "description": "Code issued.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "code": {
           "type": "string",
           "description": "The code in groups of digits; the bot accepts it with spaces, hyphens or without them."
          },
          "link": {
           "type": "string",
           "description": "A link that opens the bot with the code already filled in. Absent if the messenger can't do this."
          },
          "send": {
           "type": "string",
           "description": "Exactly what to send to the bot when the code alone isn't enough: in Discord the bot sees only commands, so this is `/ask <code>`. Absent — just send the code."
          },
          "expires_at": {
           "type": "string",
           "format": "date-time"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "Unknown role, or chats can't be linked in this channel (email).",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "description": "No valid session — log in again.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The current user's role doesn't allow this action.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Agent or channel not found.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "502": {
      "description": "Before issuing a code, the platform re-registers with the messenger (so deliveries carry the secret that verifies them), and the messenger didn't accept it. No code was issued — try again.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/channels/{cid}/people/{key}": {
   "delete": {
    "tags": [
     "Dashboard · Channels"
    ],
    "summary": "Unlink a person",
    "description": "Takes effect from their next message: the role is read on every incoming one. It can be restored only with a new code, which the person sends themselves.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     },
     {
      "name": "cid",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Channel ID."
     },
     {
      "name": "key",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "The person's key from the `people` list."
     }
    ],
    "responses": {
     "200": {
      "description": "Unlinked.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "status": {
           "type": "string",
           "enum": [
            "removed"
           ]
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "No valid session — log in again.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The current user's role doesn't allow this action.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Agent, channel, or person in it not found.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/channels/{cid}/private": {
   "put": {
    "tags": [
     "Dashboard · Channels"
    ],
    "summary": "Reply only to linked people",
    "description": "`true` — strangers get a one-sentence refusal, no agent run starts and no credits are spent; in a group — silence. It can be turned on only where the owner is already linked, otherwise the bot would reply to no one. `false` — everyone again.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     },
     {
      "name": "cid",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Channel ID."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "required": [
         "private"
        ],
        "properties": {
         "private": {
          "type": "boolean"
         }
        }
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Changed.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "channel": {
           "$ref": "#/components/schemas/Channel"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "The owner isn't linked yet, or this isn't possible in this channel (email).",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "description": "No valid session — log in again.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The current user's role doesn't allow this action.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Agent or channel not found.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/channels/{cid}/mailbox": {
   "put": {
    "tags": [
     "Dashboard · Channels"
    ],
    "summary": "Mailbox modes: reply or read only, send on its own or with permission",
    "description": "`replies: false` — the mailbox only reads: emails don't wake the agent to reply and aren't marked as read; the owner's agent searches and reads them with the `mailbox` capability in the owner's runs, and the `mail.received` event announces a new email (watching starts from this minute). `replies: true` — replies to every new email on its own. `sends_itself: true` — the owner's agent sends emails without an approval card; `false` — every email first waits for permission. After reading someone else's email in the same run, everything it writes goes through permission anyway. One of the two fields is enough.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     },
     {
      "name": "cid",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Channel ID."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "replies": {
          "type": "boolean"
         },
         "sends_itself": {
          "type": "boolean"
         }
        }
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Changed.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "channel": {
           "$ref": "#/components/schemas/Channel"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "Nothing to change was named, or this isn't possible: only email can read only and send on its own, and only a mailbox with an incoming mail server can read only.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "description": "No valid session — log in again.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The current user's role doesn't allow this action.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Agent or channel not found.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/channels/{cid}/away": {
   "put": {
    "tags": [
     "Dashboard · Channels"
    ],
    "summary": "What a person hears in a turned-off channel: custom words, the default, or nothing",
    "description": "A person who writes to a turned-off channel hears one sentence — no model and no credits, at most once every 30 minutes. `text` — a custom sentence (up to 300 characters); an empty string restores the default. `silent: true` — say nothing. If only `text` is passed, silence is turned off. One of the two fields is enough. Applies only to a turned-off channel: when the agent has run out of credits, the sentence is always the default. The sentence isn't sent in reply to auto-replies and mailings (email).",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     },
     {
      "name": "cid",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Channel ID."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "text": {
          "type": "string",
          "maxLength": 300,
          "description": "An empty string — the default sentence."
         },
         "silent": {
          "type": "boolean"
         }
        }
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Changed.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "channel": {
           "$ref": "#/components/schemas/Channel"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "Nothing to change was named, or this isn't possible: only email can read only and send on its own, and only a mailbox with an incoming mail server can read only.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "description": "No valid session — log in again.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The current user's role doesn't allow this action.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Agent or channel not found.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/owner-notes": {
   "get": {
    "tags": [
     "Dashboard · Owner memory"
    ],
    "summary": "What the agent remembers about the owner",
    "description": "Notes, oldest first, and how much space is used. The agent writes them only in a run where the platform knows the owner is writing: a linked messenger chat or a run signed by the dashboard. 502 means \"couldn't read\", not \"remembers nothing\".",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     }
    ],
    "responses": {
     "200": {
      "description": "The list.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/OwnerNotes"
        }
       }
      }
     },
     "401": {
      "description": "No valid session — log in again.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The current user's role doesn't allow this action: only an administrator can see and edit the notes.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Agent not found, or notes aren't available in this build.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "502": {
      "description": "The notes couldn't be read — try again.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   },
   "post": {
    "tags": [
     "Dashboard · Owner memory"
    ],
    "summary": "Write a note",
    "description": "A note from the owner themselves, so without the `after` mark.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "text": {
          "type": "string",
          "description": "The note itself, briefly (up to 500 characters)."
         }
        },
        "required": [
         "text"
        ]
       }
      }
     }
    },
    "responses": {
     "201": {
      "description": "Saved.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/OwnerNote"
        }
       }
      }
     },
     "400": {
      "description": "Empty or too long (one note is up to 500 characters).",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "description": "No valid session — log in again.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The current user's role doesn't allow this action: only an administrator can see and edit the notes.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Agent not found, or notes aren't available in this build.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "409": {
      "description": "The notes are full (2,000 characters in total): shorten or remove one — old ones aren't pushed out automatically.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "502": {
      "description": "Couldn’t save — try again.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   },
   "delete": {
    "tags": [
     "Dashboard · Owner memory"
    ],
    "summary": "Forget everything about the owner",
    "description": "Erases all of the agent's notes about the owner. This can't be undone.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     }
    ],
    "responses": {
     "200": {
      "description": "Erased.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "status": {
           "type": "string",
           "enum": [
            "cleared"
           ]
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "No valid session — log in again.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The current user's role doesn't allow this action: only an administrator can see and edit the notes.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Agent not found, or notes aren't available in this build.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "502": {
      "description": "Couldn't erase — try again.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/owner-notes/{noteID}": {
   "put": {
    "tags": [
     "Dashboard · Owner memory"
    ],
    "summary": "Rewrite a note",
    "description": "The new text replaces the old; the `after` mark is removed — the owner has vouched for the text themselves.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     },
     {
      "name": "noteID",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "The note ID from the list."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "text": {
          "type": "string",
          "description": "The note itself, briefly (up to 500 characters)."
         }
        },
        "required": [
         "text"
        ]
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Rewritten.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/OwnerNote"
        }
       }
      }
     },
     "400": {
      "description": "Empty or too long (one note is up to 500 characters).",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "description": "No valid session — log in again.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The current user's role doesn't allow this action: only an administrator can see and edit the notes.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Agent or note not found.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "409": {
      "description": "The new text doesn't fit within the limit for all notes.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "502": {
      "description": "Couldn’t save — try again.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   },
   "delete": {
    "tags": [
     "Dashboard · Owner memory"
    ],
    "summary": "Remove a note",
    "description": "\"Forget about my old job\" — one note.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     },
     {
      "name": "noteID",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "The note ID from the list."
     }
    ],
    "responses": {
     "200": {
      "description": "Removed.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "status": {
           "type": "string",
           "enum": [
            "removed"
           ]
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "No valid session — log in again.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The current user's role doesn't allow this action: only an administrator can see and edit the notes.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Agent or note not found.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "502": {
      "description": "Couldn't remove — try again.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/agent-files": {
   "get": {
    "tags": [
     "Dashboard · Agent files"
    ],
    "summary": "What's in the agent's persistent folder",
    "description": "Files the agent saved between runs (the `/agent` folder in the `run_code` environment), and how much space is used. The folder exists only in the owner's own runs — their conversation with the agent and background work on their behalf; it's not there in a conversation with a visitor. `available: false` — this agent has no persistent folder at all (the execution environment isn't connected or doesn't support folders yet): this isn't \"empty\". `exists: false` — a folder is possible, but the agent hasn't saved anything yet. 502 means \"couldn't read\", not \"empty\".",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     }
    ],
    "responses": {
     "200": {
      "description": "The list.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/AgentFiles"
        }
       }
      }
     },
     "401": {
      "description": "No valid session — log in again.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The current user's role doesn't allow this action: only an administrator can see and delete the agent's files.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Agent not found.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "502": {
      "description": "The files couldn't be read — try again.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   },
   "delete": {
    "tags": [
     "Dashboard · Agent files"
    ],
    "summary": "Erase the agent's entire folder",
    "description": "Deletes all files in the folder permanently — they can't be restored. If the agent is working with the folder right now, the response is 409: try again in a minute.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     }
    ],
    "responses": {
     "200": {
      "description": "Folder erased.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "status": {
           "type": "string",
           "enum": [
            "cleared"
           ]
          }
         },
         "required": [
          "status"
         ]
        }
       }
      }
     },
     "401": {
      "description": "No valid session — log in again.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The current user's role doesn't allow this action: only an administrator can see and delete the agent's files.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Agent not found, or it has no persistent folder.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "409": {
      "description": "The agent is working with the folder right now.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "502": {
      "description": "Couldn't erase — try again.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/agent-files/download": {
   "get": {
    "tags": [
     "Dashboard · Agent files"
    ],
    "summary": "Download a file from the agent's folder",
    "description": "Returns the file as an attachment (`Content-Disposition: attachment`) — always as `application/octet-stream`: the file was written by the agent's code and must not open in the browser. A symbolic link (`link: true` in the list) can't be downloaded.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     },
     {
      "name": "path",
      "in": "query",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "The file path relative to the folder root, as in the list (for example `journal/ideas.md`)."
     }
    ],
    "responses": {
     "200": {
      "description": "The file.",
      "content": {
       "application/octet-stream": {
        "schema": {
         "type": "string",
         "format": "binary"
        }
       }
      }
     },
     "400": {
      "description": "No path given, or it leads outside the folder, through a link, or it's a folder.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "description": "No valid session — log in again.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The current user's role doesn't allow this action: only an administrator can see and delete the agent's files.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Agent or file not found, or the agent has no persistent folder.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "502": {
      "description": "The file couldn't be read — try again.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/agent-files/file": {
   "delete": {
    "tags": [
     "Dashboard · Agent files"
    ],
    "summary": "Delete a file from the agent's folder",
    "description": "Deletes one file permanently. This is how you free up space when the folder is full: until then the agent gets it read-only.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     },
     {
      "name": "path",
      "in": "query",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "The file path relative to the folder root, as in the list (for example `journal/ideas.md`)."
     }
    ],
    "responses": {
     "200": {
      "description": "Deleted.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "status": {
           "type": "string",
           "enum": [
            "removed"
           ]
          }
         },
         "required": [
          "status"
         ]
        }
       }
      }
     },
     "400": {
      "description": "No path given, or it leads outside the folder.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "description": "No valid session — log in again.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The current user's role doesn't allow this action: only an administrator can see and delete the agent's files.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Agent or file not found, or the agent has no persistent folder.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "502": {
      "description": "Couldn't delete — try again.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/calendar": {
   "get": {
    "tags": [
     "Dashboard · Calendar"
    ],
    "summary": "Agent calendar",
    "description": "Which calendar is connected, whether it can be read, and with what settings. The link or password is never returned. Role: administrator — calendar events are personal.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     }
    ],
    "responses": {
     "200": {
      "description": "Calendar state.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "required": [
          "calendar"
         ],
         "properties": {
          "calendar": {
           "$ref": "#/components/schemas/Calendar"
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "Sign-in required"
     },
     "403": {
      "description": "No access to this agent, or the administrator role is required"
     },
     "404": {
      "description": "This build has no calendar."
     }
    }
   },
   "put": {
    "tags": [
     "Dashboard · Calendar"
    ],
    "summary": "Connect a calendar",
    "description": "Connects the owner's calendar and **reads it first**: if it can't be read, it isn't connected.\n\nTwo ways. `url` without `password` — a secret address in iCal format (`https://…` or `webcal://…`) from Google, iCloud or Outlook: read only. `username` and `password` (an app password) — CalDAV: read and write. For iCloud and Fastmail the platform knows the server address from the email; for Nextcloud, pass its address in `url`. Google and Outlook can't be connected with a password.\n\nReplacing the link keeps the working hours and the approval settings. Role: administrator.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     }
    ],
    "responses": {
     "200": {
      "description": "Calendar read and connected.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "required": [
          "calendar",
          "events",
          "others"
         ],
         "properties": {
          "calendar": {
           "$ref": "#/components/schemas/Calendar"
          },
          "events": {
           "type": "integer",
           "description": "How many events of the coming week were read."
          },
          "others": {
           "type": "array",
           "items": {
            "type": "string"
           },
           "description": "Other calendars in the CalDAV account that weren't selected."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "Sign-in required"
     },
     "403": {
      "description": "No access to this agent, or the administrator role is required"
     },
     "404": {
      "description": "This build has no calendar."
     },
     "400": {
      "description": "The link or login won't do (including Google or Outlook with a password), or there is no calendar with that name.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "502": {
      "description": "The calendar couldn't be read: the server is unreachable, didn't accept the password, or the link isn't a calendar. Nothing was connected.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "url": {
          "type": "string",
          "description": "A secret iCal address or, with a password, a Nextcloud server address."
         },
         "username": {
          "type": "string",
          "description": "CalDAV login — usually the account's email."
         },
         "password": {
          "type": "string",
          "description": "App password for CalDAV. Never returned."
         },
         "calendar": {
          "type": "string",
          "description": "The calendar name when the account has several. Empty — the first one."
         }
        }
       }
      }
     }
    }
   },
   "delete": {
    "tags": [
     "Dashboard · Calendar"
    ],
    "summary": "Disconnect the calendar",
    "description": "Disconnects the calendar and erases the link or password. From then on the agent says it can't see a calendar. Role: administrator.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     }
    ],
    "responses": {
     "200": {
      "description": "Unlinked.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "required": [
          "calendar"
         ],
         "properties": {
          "calendar": {
           "$ref": "#/components/schemas/Calendar"
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "Sign-in required"
     },
     "403": {
      "description": "No access to this agent, or the administrator role is required"
     },
     "404": {
      "description": "This build has no calendar."
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/calendar/check": {
   "post": {
    "tags": [
     "Dashboard · Calendar"
    ],
    "summary": "Check the calendar",
    "description": "Reads the coming week now. An unreadable calendar isn't a request error: the response is 200 with the reason in `calendar.problem` (and a `calendar_unreadable` incident). Role: administrator.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     }
    ],
    "responses": {
     "200": {
      "description": "The result of the read.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "required": [
          "calendar",
          "events"
         ],
         "properties": {
          "calendar": {
           "$ref": "#/components/schemas/Calendar"
          },
          "events": {
           "type": "integer"
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "Sign-in required"
     },
     "403": {
      "description": "No access to this agent, or the administrator role is required"
     },
     "404": {
      "description": "No calendar is connected, or this build has no calendar."
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/calendar/events": {
   "get": {
    "tags": [
     "Dashboard · Calendar"
    ],
    "summary": "Calendar events",
    "description": "Events for the period as the agent sees them (recurrences expanded). Role: administrator.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     },
     {
      "name": "from",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "Start: a date (2026-10-08) or RFC 3339. Default — the start of today, Kyiv time."
     },
     {
      "name": "to",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "End: a date (inclusive) or RFC 3339. Default — a week from the start."
     }
    ],
    "responses": {
     "200": {
      "description": "Events.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "required": [
          "events",
          "calendar"
         ],
         "properties": {
          "events": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/CalendarEvent"
           }
          },
          "calendar": {
           "$ref": "#/components/schemas/Calendar"
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "Sign-in required"
     },
     "403": {
      "description": "No access to this agent, or the administrator role is required"
     },
     "404": {
      "description": "This build has no calendar."
     },
     "400": {
      "description": "The period can't be parsed or is longer than two months.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "502": {
      "description": "The calendar couldn't be read — this isn't \"no events\".",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/calendar/settings": {
   "put": {
    "tags": [
     "Dashboard · Calendar"
    ],
    "summary": "Calendar settings",
    "description": "Working hours (the agent looks for free slots within them; empty `days` — remove them) and whether to ask the owner before every calendar entry (yes by default; `false` — the agent writes on its own). Role: administrator.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     }
    ],
    "responses": {
     "200": {
      "description": "The new settings.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "required": [
          "calendar"
         ],
         "properties": {
          "calendar": {
           "$ref": "#/components/schemas/Calendar"
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "Sign-in required"
     },
     "403": {
      "description": "No access to this agent, or the administrator role is required"
     },
     "404": {
      "description": "This build has no calendar."
     },
     "400": {
      "description": "The hours can't be parsed, or nothing was given.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "hours": {
          "$ref": "#/components/schemas/CalendarHours"
         },
         "ask_before_writing": {
          "type": "boolean"
         }
        }
       }
      }
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/playbooks": {
   "get": {
    "tags": [
     "Dashboard · Skills"
    ],
    "summary": "Agent skills",
    "description": "Skills and drafts, oldest first, without their texts, and how much space is used. Any workspace member can read them. 502 means \"couldn't read\", not \"no skills\".",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     }
    ],
    "responses": {
     "200": {
      "description": "The list.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "playbooks": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/PlaybookItem"
           }
          },
          "max_active": {
           "type": "integer",
           "description": "How many skills can exist at once."
          },
          "max_drafts": {
           "type": "integer",
           "description": "How many drafts can wait for approval."
          },
          "index_used": {
           "type": "integer",
           "description": "How many characters the names and \"when to use\" of all skills take — that much goes into the prompt every run."
          },
          "index_limit": {
           "type": "integer",
           "description": "The limit for this list."
          }
         },
         "required": [
          "playbooks",
          "max_active",
          "max_drafts",
          "index_used",
          "index_limit"
         ]
        }
       }
      }
     },
     "401": {
      "description": "No valid session — log in again.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "Wrong kind of key for the dashboard.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Agent or skill not found, or skills aren't available in this build.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "502": {
      "description": "The skills couldn't be read — try again.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   },
   "post": {
    "tags": [
     "Dashboard · Skills"
    ],
    "summary": "Write a skill",
    "description": "A skill in the owner's own words — takes effect immediately. It goes into the change log; \"undo\" removes it.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "name": {
          "type": "string",
          "description": "Name: lowercase letters, digits, hyphens (weekly-report)."
         },
         "when": {
          "type": "string",
          "description": "What it does and when to use it."
         },
         "body": {
          "type": "string",
          "description": "The instruction itself: steps, pitfalls, verification."
         }
        },
        "required": [
         "name",
         "when",
         "body"
        ]
       }
      }
     }
    },
    "responses": {
     "201": {
      "description": "Saved.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Playbook"
        }
       }
      }
     },
     "400": {
      "description": "The name doesn't follow the format (lowercase letters, digits, hyphens), or it's empty or too long.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "description": "No valid session — log in again.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The current user's role doesn't allow this action: only an administrator can change skills.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Agent or skill not found, or skills aren't available in this build.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "409": {
      "description": "No room left (for skills, drafts, or characters in the prompt list), or a skill with this name already exists.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "502": {
      "description": "That didn't work. Try again.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/playbooks/preview": {
   "post": {
    "tags": [
     "Dashboard · Skills"
    ],
    "summary": "Read a skill from a link",
    "description": "Reads SKILL.md (a GitHub folder or file page is rewritten to the raw file) and returns the text, risky lines and a digest. Saves NOTHING: import saves it after approval. Files next to it (scripts/, references/) are neither read nor executed.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "url": {
          "type": "string",
          "description": "Link to the skill: a folder or SKILL.md on GitHub, or a raw file."
         }
        },
        "required": [
         "url"
        ]
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Read.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/FetchedPlaybook"
        }
       }
      }
     },
     "400": {
      "description": "No link.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "description": "No valid session — log in again.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The current user's role doesn't allow this action: only an administrator can change skills.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Agent or skill not found, or skills aren't available in this build.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "422": {
      "description": "The link isn't a SKILL.md: no frontmatter, the name doesn't follow the format, and so on.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "502": {
      "description": "The link couldn't be read: 404, a web page instead of a file, the file is too large, the address didn't respond.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/playbooks/import": {
   "post": {
    "tags": [
     "Dashboard · Skills"
    ],
    "summary": "Add a skill that was read",
    "description": "Re-reads the link and saves the skill only if the text is the same as what was shown (digest). It goes into the change log as third-party text; \"undo\" removes it.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "url": {
          "type": "string",
          "description": "The same link as in preview."
         },
         "digest": {
          "type": "string",
          "description": "The digest from preview."
         }
        },
        "required": [
         "url",
         "digest"
        ]
       }
      }
     }
    },
    "responses": {
     "201": {
      "description": "Added.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Playbook"
        }
       }
      }
     },
     "400": {
      "description": "No link or digest.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "description": "No valid session — log in again.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The current user's role doesn't allow this action: only an administrator can change skills.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Agent or skill not found, or skills aren't available in this build.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "409": {
      "description": "The text at the link changed after it was shown, a skill with this name already exists, or there's no room.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "422": {
      "description": "The link isn't a SKILL.md.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "502": {
      "description": "The link couldn't be read.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/playbooks/{pid}": {
   "get": {
    "tags": [
     "Dashboard · Skills"
    ],
    "summary": "One skill",
    "description": "A skill or draft with its text and risky lines — so it can be read before \"Save\".",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     },
     {
      "name": "pid",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "The skill or draft ID from the list."
     }
    ],
    "responses": {
     "200": {
      "description": "The skill.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "playbook": {
           "$ref": "#/components/schemas/Playbook"
          },
          "draft": {
           "type": "boolean"
          },
          "risks": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/PlaybookRisk"
           }
          },
          "digest": {
           "type": "string",
           "description": "Digest of the text: send it to approve to save exactly what was shown."
          }
         },
         "required": [
          "playbook",
          "draft",
          "risks",
          "digest"
         ]
        }
       }
      }
     },
     "401": {
      "description": "No valid session — log in again.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "Wrong kind of key for the dashboard.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Agent or skill not found, or skills aren't available in this build.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "502": {
      "description": "That didn't work. Try again.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   },
   "put": {
    "tags": [
     "Dashboard · Skills"
    ],
    "summary": "Rewrite a skill",
    "description": "A new \"when to use\" or text; the name doesn't change. The `after` mark is removed — the owner has vouched for the text. Editing a skill goes into the change log and can be undone.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     },
     {
      "name": "pid",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "The skill or draft ID from the list."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "when": {
          "type": "string",
          "description": "New \"when to use\"; empty — unchanged."
         },
         "body": {
          "type": "string",
          "description": "New text; empty — unchanged."
         }
        }
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Rewritten.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Playbook"
        }
       }
      }
     },
     "400": {
      "description": "The name doesn't follow the format (lowercase letters, digits, hyphens), or it's empty or too long.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "description": "No valid session — log in again.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The current user's role doesn't allow this action: only an administrator can change skills.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Agent or skill not found, or skills aren't available in this build.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "409": {
      "description": "No room left (for skills, drafts, or characters in the prompt list), or a skill with this name already exists.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "502": {
      "description": "That didn't work. Try again.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   },
   "delete": {
    "tags": [
     "Dashboard · Skills"
    ],
    "summary": "Remove a skill",
    "description": "\"Forget the skill about reports\". The skill goes into the change log and comes back with \"undo\"; a removed draft doesn't (it never took effect).",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     },
     {
      "name": "pid",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "The skill or draft ID from the list."
     }
    ],
    "responses": {
     "200": {
      "description": "Removed.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "status": {
           "type": "string",
           "enum": [
            "removed"
           ]
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "No valid session — log in again.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The current user's role doesn't allow this action: only an administrator can change skills.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Agent or skill not found, or skills aren't available in this build.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "502": {
      "description": "That didn't work. Try again.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/playbooks/{pid}/approve": {
   "post": {
    "tags": [
     "Dashboard · Skills"
    ],
    "summary": "Save a draft",
    "description": "A draft proposed by the agent becomes a skill; a skill with the same name, if there was one, is replaced. A draft with the \"after reading\" mark (after) is saved only with the digest of the text shown (digest from GET of a single skill) — this is approval on the server, not just a second tap in the dashboard. It goes into the change log; \"undo\" restores both the draft and the replaced skill.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     },
     {
      "name": "pid",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "The skill or draft ID from the list."
     }
    ],
    "responses": {
     "200": {
      "description": "Saved.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Playbook"
        }
       }
      }
     },
     "401": {
      "description": "No valid session — log in again.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The current user's role doesn't allow this action: only an administrator can change skills.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Agent or skill not found, or skills aren't available in this build.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "409": {
      "description": "This is already a skill, not a draft; there's no room; a draft written after reading third-party content is being saved without the digest of the text shown; or the text changed after it was shown.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "502": {
      "description": "That didn't work. Try again.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "requestBody": {
     "required": false,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "digest": {
          "type": "string",
          "description": "Digest of the text the person saw (digest from GET of a single skill). Required for a draft with the after mark; if sent, it's always checked."
         }
        }
       }
      }
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/playbooks/{pid}/reject": {
   "post": {
    "tags": [
     "Dashboard · Skills"
    ],
    "summary": "Reject a draft",
    "description": "\"No\" to the agent's proposal: the draft is removed. Nothing is written to the change log — the draft never took effect.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     },
     {
      "name": "pid",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "The skill or draft ID from the list."
     }
    ],
    "responses": {
     "200": {
      "description": "Rejected.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "status": {
           "type": "string",
           "enum": [
            "rejected"
           ]
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "No valid session — log in again.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The current user's role doesn't allow this action: only an administrator can change skills.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Agent or skill not found, or skills aren't available in this build.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "409": {
      "description": "This is a skill, not a draft.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "502": {
      "description": "That didn't work. Try again.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/payments": {
   "get": {
    "tags": [
     "Dashboard · Payments"
    ],
    "summary": "Agent payments",
    "description": "Whether a payment provider is connected, the cap for a single link, the service price list and recent payments.\n\nOnce payments are connected, the agent hands out the link in the conversation itself: no separate capability needs to be turned on. The platform doesn't issue refunds — only the payment provider's dashboard does.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     }
    ],
    "responses": {
     "200": {
      "description": "Agent payments.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "required": [
          "payments"
         ],
         "properties": {
          "payments": {
           "$ref": "#/components/schemas/Payments"
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "Sign-in required"
     },
     "403": {
      "description": "No access to this agent"
     },
     "404": {
      "description": "This build has no in-conversation payments."
     },
     "500": {
      "description": "Agent payments couldn't be read.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   },
   "put": {
    "tags": [
     "Dashboard · Payments"
    ],
    "summary": "Payment settings",
    "description": "The cap for a single link per currency, how many unpaid links one conversation can get per day, and the service price list (complete, replaces the previous one). A field missing from the request stays as it was. Role: administrator.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "limits": {
          "type": "object",
          "additionalProperties": {
           "type": "integer",
           "format": "int64"
          },
          "description": "Cap per currency (UAH, USD, EUR), in minor units."
         },
         "prices": {
          "type": "array",
          "items": {
           "$ref": "#/components/schemas/PaymentPrice"
          },
          "description": "The complete service price list; an empty array removes it."
         },
         "links_per_conversation": {
          "type": "integer",
          "minimum": 0,
          "maximum": 50,
          "description": "How many unpaid links one conversation can get per day; 0 — the default (5). Paid links don't count."
         }
        }
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Agent payments.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "required": [
          "payments"
         ],
         "properties": {
          "payments": {
           "$ref": "#/components/schemas/Payments"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "The settings make no sense (zero cap, a service without a name, an unknown currency, a link limit outside 0–50).",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "description": "Sign-in required"
     },
     "403": {
      "description": "No access to this agent"
     },
     "404": {
      "description": "This build has no in-conversation payments."
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/payments/connect": {
   "post": {
    "tags": [
     "Dashboard · Payments"
    ],
    "summary": "Connect a payment provider",
    "description": "Verifies the keys with the payment provider itself and only then puts them into the agent's keys under fixed names: `LIQPAY_PUBLIC_KEY` and `LIQPAY_PRIVATE_KEY`. Rejected keys aren't stored. There is one payment provider — LiqPay; naming another gives `400`. Role: administrator.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "required": [
         "provider",
         "keys"
        ],
        "properties": {
         "provider": {
          "type": "string",
          "enum": [
           "liqpay"
          ]
         },
         "keys": {
          "type": "object",
          "additionalProperties": {
           "type": "string"
          },
          "description": "Keys by name: `LIQPAY_PUBLIC_KEY` and `LIQPAY_PRIVATE_KEY`."
         }
        }
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Agent payments.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "required": [
          "payments"
         ],
         "properties": {
          "payments": {
           "$ref": "#/components/schemas/Payments"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "A key is missing, or the provider didn't accept it.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "description": "Sign-in required"
     },
     "403": {
      "description": "No access to this agent"
     },
     "404": {
      "description": "This build has no in-conversation payments."
     },
     "502": {
      "description": "The payment provider didn't respond — the key was neither verified nor stored.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/payments/{provider}": {
   "delete": {
    "tags": [
     "Dashboard · Payments"
    ],
    "summary": "Disconnect a payment provider",
    "description": "Erases the provider's keys from the agent's keys: the agent stops handing out links, and the status of links already issued is no longer checked. Role: administrator.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     },
     {
      "name": "provider",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "enum": [
        "liqpay"
       ]
      }
     }
    ],
    "responses": {
     "200": {
      "description": "Agent payments.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "required": [
          "payments"
         ],
         "properties": {
          "payments": {
           "$ref": "#/components/schemas/Payments"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "Unknown provider.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "description": "Sign-in required"
     },
     "403": {
      "description": "No access to this agent"
     },
     "404": {
      "description": "This build has no in-conversation payments."
     }
    }
   }
  },
  "/v1/payments/hook/{provider}/{bot}/{pay}": {
   "post": {
    "tags": [
     "Dashboard · Payments"
    ],
    "summary": "Payment provider notification",
    "operationId": "paymentWebhook",
    "security": [],
    "description": "The payment provider sends payment status changes here; the platform gives it this address itself when it creates a link. The owner doesn't need to configure anything.\n\nThe notification is authenticated by **the provider's signature**: LiqPay sends a form with the `data` and `signature` fields (signed with the shop's private key). Without a genuine signature, for someone else's payment, or without the agent's keys, nothing changes (`401`/`404`). When a payment is received, the owner gets a notification, the shopper gets a message in the same conversation, and triggers get the `payment.received` event.",
    "parameters": [
     {
      "name": "provider",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "enum": [
        "liqpay"
       ]
      }
     },
     {
      "name": "bot",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      }
     },
     {
      "name": "pay",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      }
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/x-www-form-urlencoded": {
       "schema": {
        "type": "object",
        "properties": {
         "data": {
          "type": "string"
         },
         "signature": {
          "type": "string"
         }
        }
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Accepted."
     },
     "400": {
      "description": "The body can't be parsed."
     },
     "401": {
      "description": "The signature isn't genuine, or the notification is about a different payment."
     },
     "404": {
      "description": "There is no such payment."
     },
     "413": {
      "description": "Body too large."
     },
     "500": {
      "description": "A platform failure — the provider will retry."
     }
    }
   }
  },
  "/v1/pay/{pay}": {
   "get": {
    "tags": [
     "Dashboard · Payments"
    ],
    "summary": "Payment page",
    "operationId": "paymentPage",
    "security": [],
    "description": "The page the shopper opens from the agent's link when the payment provider's form is submitted via POST (LiqPay): it shows the amount and purpose and submits the form right away. A paid or expired payment shows its status. The payment number is random — someone else's can't be guessed.",
    "parameters": [
     {
      "name": "pay",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      }
     }
    ],
    "responses": {
     "200": {
      "description": "HTML page.",
      "content": {
       "text/html": {
        "schema": {
         "type": "string"
        }
       }
      }
     },
     "404": {
      "description": "There is no such payment."
     },
     "502": {
      "description": "The page is unavailable right now."
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/agent-access": {
   "get": {
    "tags": [
     "Dashboard · Access for other agents"
    ],
    "summary": "Which other agents have access",
    "description": "Issued keys (name, first characters, when last used — no values), the agent card, and the addresses it is called at. Any workspace member can read this. 502 means \"couldn't read\", not \"no keys\".",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     }
    ],
    "responses": {
     "200": {
      "description": "Access state for other agents.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/AgentAccess"
        }
       }
      }
     },
     "401": {
      "description": "No valid session — log in again.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "Wrong kind of key: a publishable key (`pk_`) doesn't open the dashboard.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Agent not found, or access for other agents isn't available in this build.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "502": {
      "description": "The keys couldn't be read — try again.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/agent-access/keys": {
   "post": {
    "tags": [
     "Dashboard · Access for other agents"
    ],
    "summary": "Issue an access key",
    "description": "A new key for someone else's agent or program. The key value (`secret`) and the ready-made setup (`setup`) are only in this response: they can't be read later, and the key can only be revoked. Names don't repeat within an agent. Role: administrator.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "required": [
         "name"
        ],
        "properties": {
         "name": {
          "type": "string",
          "description": "Who the key is for: \"Claude on my laptop\", \"Cursor\". Up to 60 characters."
         }
        }
       }
      }
     }
    },
    "responses": {
     "201": {
      "description": "Key issued.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "required": [
          "key",
          "secret",
          "mcp_url",
          "setup"
         ],
         "properties": {
          "key": {
           "$ref": "#/components/schemas/AgentAccessKey"
          },
          "secret": {
           "type": "string",
           "description": "The key itself (`ak_…`). Shown once."
          },
          "mcp_url": {
           "type": "string",
           "description": "The agent's MCP server address."
          },
          "setup": {
           "$ref": "#/components/schemas/AgentAccessSetup"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "The name is missing or too long.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "description": "No valid session — log in again.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The current user's role doesn't allow this action: only an administrator can issue or revoke a key and show the agent to others.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Agent not found, or access for other agents isn't available in this build.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "409": {
      "description": "A key with this name already exists, or there are already twenty keys.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "502": {
      "description": "Couldn’t issue the key — try again.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/agent-access/keys/{keyID}": {
   "delete": {
    "tags": [
     "Dashboard · Access for other agents"
    ],
    "summary": "Revoke an access key",
    "description": "The key stops working immediately; the agent's other keys aren't affected. The same key can't be restored. Role: administrator.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     },
     {
      "name": "keyID",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "The key ID from the list."
     }
    ],
    "responses": {
     "200": {
      "description": "Revoked.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "status": {
           "type": "string",
           "enum": [
            "revoked"
           ]
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "No valid session — log in again.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The current user's role doesn't allow this action: only an administrator can issue or revoke a key and show the agent to others.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Agent or key not found.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "502": {
      "description": "Couldn't revoke — try again.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/agent-access/card": {
   "put": {
    "tags": [
     "Dashboard · Access for other agents"
    ],
    "summary": "Show the agent to other agents and describe it",
    "description": "Writes both fields together. `visible: true` publishes the agent card (A2A Agent Card) at `card_url` — without a key, for anyone; it doesn't let anyone talk to the agent. By default the agent isn't visible. `description` goes to the other party's model and into the card. Role: administrator.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "required": [
         "visible",
         "description"
        ],
        "properties": {
         "visible": {
          "type": "boolean"
         },
         "description": {
          "type": "string",
          "description": "Up to 600 characters; empty — no description."
         }
        }
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Access state for other agents.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/AgentAccess"
        }
       }
      }
     },
     "400": {
      "description": "The description is too long.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "description": "No valid session — log in again.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The current user's role doesn't allow this action: only an administrator can issue or revoke a key and show the agent to others.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Agent not found, or access for other agents isn't available in this build.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "502": {
      "description": "Couldn’t save — try again.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/agents/{id}/mcp": {
   "post": {
    "tags": [
     "Agent for other agents"
    ],
    "summary": "Agent MCP server (JSON-RPC 2.0, Streamable HTTP)",
    "description": "Another agent calls THIS agent as a tool. Tools: `ask` (message → reply; `conversation_id` continues a conversation), and, for an agent with the long-task capability, also `task_start` and `task_status`. The `agent://{id}/about` resource is the agent's description. The caller is always a visitor; every `ask` and `task_start` call spends the owner's credits, and the agent's spending cap applies. Exhausted credits, the rate limit and a run failure come back as a tool result with `isError: true` and a text, not as a protocol error.\n\nThe server understands two eras of the MCP specification. Current (`2026-07-28`): there is no handshake; every request carries `params._meta` with `io.modelcontextprotocol/protocolVersion` and `io.modelcontextprotocol/clientCapabilities` and duplicates the version, method, and tool name or resource URI in the `MCP-Protocol-Version`, `Mcp-Method`, `Mcp-Name` headers — a mismatch with the body gives `400` with code `-32020`; an unknown version gives `400` with code `-32022` and a list of supported ones; an unknown method gives `404` with code `-32601`; `server/discover` is available. Previous (`2025-03-26`, `2025-06-18`, `2025-11-25`): `initialize`, then requests without `_meta`. The response is always `application/json`; the server doesn't open a stream.\n\nNot to be confused with `POST /v1/api/mcp`: that is the BUILDER's MCP (a `ck_` key), used to build agents.",
    "security": [
     {
      "agentKey": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     },
     {
      "name": "MCP-Protocol-Version",
      "in": "header",
      "required": false,
      "schema": {
       "type": "string"
      },
      "description": "Protocol version. Required in the current version; without it, a request without `_meta` is served as `2025-03-26`."
     },
     {
      "name": "Mcp-Method",
      "in": "header",
      "required": false,
      "schema": {
       "type": "string"
      },
      "description": "Current version: the same method as in the body."
     },
     {
      "name": "Mcp-Name",
      "in": "header",
      "required": false,
      "schema": {
       "type": "string"
      },
      "description": "Current version, for `tools/call` and `resources/read`: the tool name or resource URI from the body; non-ASCII in the form `=?base64?…?=`."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "required": [
         "jsonrpc",
         "method"
        ],
        "properties": {
         "jsonrpc": {
          "type": "string",
          "enum": [
           "2.0"
          ]
         },
         "id": {
          "description": "A number or a string; the response returns it as is. Without `id` it's a notification."
         },
         "method": {
          "type": "string"
         },
         "params": {
          "type": "object"
         }
        }
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "JSON-RPC response: `result` or `error`.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object"
        }
       }
      }
     },
     "202": {
      "description": "Notification accepted (no response)."
     },
     "400": {
      "description": "Current version: the headers don't match the body (`-32020`), the version isn't supported (`-32022`), or the required `_meta` field is missing (`-32602`). The body is a JSON-RPC error.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object"
        }
       }
      }
     },
     "401": {
      "description": "The key is missing, invalid or revoked, or the agent no longer exists.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The key was issued for a different agent, or the request came from a page on someone else's site (the `Origin` header).",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Current version: no such method (`-32601`, the body is a JSON-RPC error). Or access for other agents isn't available in this build.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object"
        }
       }
      }
     },
     "413": {
      "description": "Body too large.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "429": {
      "description": "Too many requests with this key.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "503": {
      "description": "Couldn't verify the key — retry in a moment.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   },
   "get": {
    "tags": [
     "Agent for other agents"
    ],
    "summary": "Agent MCP: the server doesn't keep a stream",
    "description": "The server responds only to POST; GET honestly returns 405.",
    "security": [],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     }
    ],
    "responses": {
     "405": {
      "description": "Method Not Allowed; header `Allow: POST`."
     }
    }
   },
   "delete": {
    "tags": [
     "Agent for other agents"
    ],
    "summary": "Agent MCP: the server doesn't keep sessions",
    "description": "There are no protocol sessions, so there's nothing to close: 405.",
    "security": [],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     }
    ],
    "responses": {
     "405": {
      "description": "Method Not Allowed; header `Allow: POST`."
     }
    }
   }
  },
  "/v1/agents/{id}/a2a": {
   "post": {
    "tags": [
     "Agent for other agents"
    ],
    "summary": "A2A entry point (JSON-RPC 2.0)",
    "description": "A minimal entry point per the A2A 1.0 specification: the `SendMessage` method — one message (text parts only) and one reply, returned immediately as a message (`result.message`, role `ROLE_AGENT`), on top of the same run as `ask` in MCP. `contextId` continues the conversation. There are no A2A tasks, streaming or push notifications: `GetTask` and `CancelTask` respond with `-32001`, other methods with `-32004`. The `A2A-Version: 1.0` header is required (or a query parameter of the same name); without it or with a different version — `-32009`. A run refusal (exhausted credits, rate limit, failure) is a `-32603` error with the reason as text. Protocol errors come with status 200 in the JSON-RPC body.",
    "security": [
     {
      "agentKey": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     },
     {
      "name": "A2A-Version",
      "in": "header",
      "required": false,
      "schema": {
       "type": "string",
       "enum": [
        "1.0"
       ]
      },
      "description": "A2A protocol version."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "required": [
         "jsonrpc",
         "method"
        ],
        "properties": {
         "jsonrpc": {
          "type": "string",
          "enum": [
           "2.0"
          ]
         },
         "id": {
          "description": "A number or a string; the response returns it as is. Without `id` it's a notification."
         },
         "method": {
          "type": "string"
         },
         "params": {
          "type": "object"
         }
        }
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "JSON-RPC response: `result` or `error`.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object"
        }
       }
      }
     },
     "401": {
      "description": "The key is missing, invalid or revoked, or the agent no longer exists.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The key was issued for a different agent, or the request came from a page on someone else's site (the `Origin` header).",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Access for other agents isn’t available in this build.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "413": {
      "description": "Body too large.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "429": {
      "description": "Too many requests with this key.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "503": {
      "description": "Couldn't verify the key — retry in a moment.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/agents/{id}/.well-known/agent-card.json": {
   "get": {
    "tags": [
     "Agent for other agents"
    ],
    "summary": "Agent card (A2A Agent Card)",
    "description": "The agent's description per the A2A 1.0 specification: name, description, entry point address, authentication method, what it can do. No key needed — and so only when the owner has published the card themselves (\"visible to other agents\"); by default there is none. An invisible, nonexistent and deleted agent all respond the same way — 404. The card doesn't let anyone talk to the agent. The response carries an `ETag` and `Cache-Control: max-age=300`; a conditional request with `If-None-Match` gives 304.",
    "security": [],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     }
    ],
    "responses": {
     "200": {
      "description": "The card.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "required": [
          "name",
          "description",
          "version",
          "supportedInterfaces",
          "capabilities",
          "defaultInputModes",
          "defaultOutputModes",
          "skills"
         ],
         "properties": {
          "name": {
           "type": "string"
          },
          "description": {
           "type": "string"
          },
          "version": {
           "type": "string"
          },
          "supportedInterfaces": {
           "type": "array",
           "items": {
            "type": "object",
            "required": [
             "url",
             "protocolBinding",
             "protocolVersion"
            ],
            "properties": {
             "url": {
              "type": "string"
             },
             "protocolBinding": {
              "type": "string"
             },
             "protocolVersion": {
              "type": "string"
             }
            }
           }
          },
          "provider": {
           "type": "object"
          },
          "documentationUrl": {
           "type": "string"
          },
          "capabilities": {
           "type": "object"
          },
          "securitySchemes": {
           "type": "object"
          },
          "securityRequirements": {
           "type": "array",
           "items": {
            "type": "object"
           }
          },
          "defaultInputModes": {
           "type": "array",
           "items": {
            "type": "string"
           }
          },
          "defaultOutputModes": {
           "type": "array",
           "items": {
            "type": "string"
           }
          },
          "skills": {
           "type": "array",
           "items": {
            "type": "object"
           }
          }
         }
        }
       }
      }
     },
     "304": {
      "description": "The card hasn't changed."
     },
     "404": {
      "description": "There's no card at this address.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "429": {
      "description": "Too many requests.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "503": {
      "description": "The card couldn't be read — retry in a moment.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/dashboard/workspace": {
   "post": {
    "tags": [
     "Dashboard · Team"
    ],
    "summary": "Switch workspace",
    "description": "Remembers in the account which workspace the person works in from now on — on all their devices and in every browser at once. You can only switch to a workspace the person is already in. Until the person has chosen anything (or no longer belongs to the chosen workspace), a request lands in their own workspace.\n\nThere is one selection per account, but there can be several tabs and devices. So that a stale tab (in this browser, another one or on a phone) doesn't perform an action in a different workspace than the one it shows, the dashboard sends the `X-Workspace` header with the ID of the workspace it shows in every request to `/v1/dashboard/*` and `/v1/billing/*`. If the request would land in a different workspace, the response is 409 with code `workspace_changed`, and the action isn't performed: re-read `GET /v1/dashboard` (it always responds) and show the actual workspace. The header doesn't select anything and is optional: without it the request goes to the chosen workspace.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "id": {
          "type": "string",
          "description": "The workspace ID from the overview's `workspaces`."
         }
        },
        "required": [
         "id"
        ]
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Switched.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "status": {
           "type": "string",
           "enum": [
            "switched"
           ]
          },
          "workspace": {
           "type": "string"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "The request can't be parsed.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "description": "No valid session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The role doesn't allow this action.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "There's no such workspace among the person's workspaces.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/dashboard/workspaces": {
   "post": {
    "tags": [
     "Dashboard · Team"
    ],
    "summary": "Create your own workspace",
    "description": "For a person who works only in someone else's team and wants agents of their own too, and for a person with a pending invitation (the overview tells them `invitation_pending`): the link may have been lost, and they shouldn't have to sit without a dashboard until it expires. The workspace appears with the first agent; the invitation stays valid. A person has only one workspace of their own.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "responses": {
     "201": {
      "description": "The workspace was created, and the person is working in it.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "status": {
           "type": "string",
           "enum": [
            "created"
           ]
          },
          "workspace": {
           "type": "string"
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "No valid session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The role doesn't allow this action.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "409": {
      "description": "The person already has their own workspace.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/dashboard/leave": {
   "post": {
    "tags": [
     "Dashboard · Team"
    ],
    "summary": "Leave the team",
    "description": "Removes the person from the workspace they are currently working in — by their own decision. The owner can't leave their own workspace.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "responses": {
     "200": {
      "description": "The person is no longer in this workspace.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "status": {
           "type": "string",
           "enum": [
            "left"
           ]
          },
          "workspace": {
           "type": "string",
           "description": "The workspace that was left."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "No valid session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The role doesn't allow this action.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "No workspace.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "409": {
      "description": "The owner can’t leave their workspace.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/invites/{token}": {
   "get": {
    "tags": [
     "Dashboard · Team"
    ],
    "summary": "What invitation is behind the link",
    "description": "A public endpoint: the invitation page shows who is inviting and with what role even before sign-in — and a person without an account learns that the invitation has expired before signing up. The invitation address is returned **masked**: sign-up doesn't verify the email, so the full address would let an outsider with someone else's link sign up with it.",
    "parameters": [
     {
      "name": "token",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      }
     }
    ],
    "responses": {
     "200": {
      "description": "The invitation is valid.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "email": {
           "type": "string",
           "description": "The address the invitation was issued to — masked: `i•••@example.com`."
          },
          "role": {
           "$ref": "#/components/schemas/Role"
          },
          "expires_at": {
           "type": "string",
           "format": "date-time"
          },
          "invited_by": {
           "type": "string",
           "description": "The inviter's email. Absent when it couldn't be read."
          },
          "for_you": {
           "type": "boolean",
           "description": "With a session only: whether the invitation is issued to the account the person signed in with."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "The invitation is invalid or revoked.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "409": {
      "description": "The invitation has already been used.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "410": {
      "description": "The invitation has expired.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "security": []
   }
  },
  "/v1/dashboard/bots/{id}/transfer": {
   "get": {
    "tags": [
     "Dashboard · Agent transfer"
    ],
    "summary": "Whether this agent is being transferred",
    "description": "The current agent transfer request — pending or already in progress. Any workspace member can read it.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     }
    ],
    "responses": {
     "200": {
      "description": "The current request, or `null` when the agent isn't being transferred.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "transfer": {
           "oneOf": [
            {
             "$ref": "#/components/schemas/Transfer"
            },
            {
             "type": "null"
            }
           ]
          }
         },
         "required": [
          "transfer"
         ]
        }
       }
      }
     },
     "401": {
      "description": "No valid session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The role doesn't allow this action.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Agent not found, or it belongs to another workspace.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   },
   "post": {
    "tags": [
     "Dashboard · Agent transfer"
    ],
    "summary": "Transfer the agent to another person",
    "description": "Creates a transfer request. Workspace owner only. The recipient is named by email, and an account with that email must already exist: the request is bound to the account (sign-up doesn't verify the email, so a request to a bare address would go to whoever signs up with it first). Until it's accepted, the agent keeps working for the sender as usual. The request is valid for 7 days; while it's pending, a second one can't be created for the same agent.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "email": {
          "type": "string",
          "format": "email",
          "description": "Email of the account the agent is being transferred to."
         }
        },
        "required": [
         "email"
        ]
       }
      }
     }
    },
    "responses": {
     "201": {
      "description": "Request created.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "transfer": {
           "$ref": "#/components/schemas/Transfer"
          },
          "message": {
           "type": "string",
           "description": "What happens next — in plain words for a person."
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "Not an email, or it's the sender's own address.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "description": "No valid session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "Only the workspace owner can transfer an agent.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Agent not found, or there's no account with this email yet.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "409": {
      "description": "This agent is already being transferred.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   },
   "delete": {
    "tags": [
     "Dashboard · Agent transfer"
    ],
    "summary": "Cancel the transfer",
    "description": "The sender changed their mind. A pending request is cancelled; an accepted agent can't be taken back. Workspace owner only.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     }
    ],
    "responses": {
     "200": {
      "description": "Request cancelled.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "status": {
           "type": "string",
           "enum": [
            "cancelled"
           ]
          },
          "transfer": {
           "$ref": "#/components/schemas/Transfer"
          },
          "message": {
           "type": "string",
           "description": "Only when a stuck move was cancelled: what stayed erased and what to check. In plain words for a person."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "No valid session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "Only the workspace owner can cancel a transfer.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Agent not found, or it isn't being transferred right now.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "409": {
      "description": "The request has already been accepted and the agent is moving — only a stuck move can be cancelled.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/dashboard/transfers": {
   "get": {
    "tags": [
     "Dashboard · Agent transfer"
    ],
    "summary": "Transfers: incoming and outgoing",
    "description": "`incoming` — requests addressed to the person's account (whichever workspace they're currently working in) that are still pending or in progress. `outgoing` — requests from the workspace the person is currently in: current and recently resolved; returned only to the workspace owner, everyone else gets an empty list. This is the sender's record of the transfer: after it, they no longer have the agent or its change log.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "responses": {
     "200": {
      "description": "Transfers.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "incoming": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/Transfer"
           }
          },
          "outgoing": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/Transfer"
           }
          },
          "keeps": {
           "type": "string",
           "description": "What moves together with the agent — in plain words for a person."
          },
          "drops": {
           "type": "string",
           "description": "What doesn't move and is erased — in plain words for a person."
          }
         },
         "required": [
          "incoming",
          "outgoing"
         ]
        }
       }
      }
     },
     "401": {
      "description": "No valid session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The role doesn't allow this action.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/dashboard/transfers/{tid}/accept": {
   "post": {
    "tags": [
     "Dashboard · Agent transfer"
    ],
    "summary": "Accept an agent",
    "description": "The recipient accepts the agent into their **own** workspace (if they don't have one yet, it appears empty). No role is needed: the request is addressed to the account. It can't be accepted with a key. Once accepted, it can't be undone: the previous owner's personal data (keys, connections, notes, personal conversations, linked people) is erased, the rest moves, and the agent's secret key (`sk_`) is replaced. The agent runs on the recipient's plan; if there's no room for another agent — `409`, and the request stays valid. From then on the recipient works in their own workspace — this is remembered in the account, on all their devices.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "tid",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "The transfer request ID."
     }
    ],
    "responses": {
     "200": {
      "description": "Accepted: the agent is already in the recipient's workspace. The move is a single action: either the agent moved entirely, or nothing changed (then the response is a refusal with a reason).",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "status": {
           "type": "string",
           "enum": [
            "accepted"
           ]
          },
          "transfer": {
           "$ref": "#/components/schemas/Transfer"
          },
          "workspace": {
           "type": "string",
           "description": "The recipient's workspace the agent landed in."
          },
          "message": {
           "type": "string"
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "No valid session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "It can't be accepted with a key: a person must be signed in.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "There's no such request among those addressed to this person.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "409": {
      "description": "The request has already been resolved, the recipient has no room for another agent, or the agent was in the middle of replying to someone and didn't finish — in that case nothing changed, and you can accept again in a minute.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "410": {
      "description": "The request has expired, or the agent no longer exists.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/dashboard/transfers/{tid}/decline": {
   "post": {
    "tags": [
     "Dashboard · Agent transfer"
    ],
    "summary": "Decline a transfer",
    "description": "The recipient declines. The agent stays with the sender, which is why they are told about it.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "tid",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "The transfer request ID."
     }
    ],
    "responses": {
     "200": {
      "description": "Declined.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "status": {
           "type": "string",
           "enum": [
            "declined"
           ]
          },
          "transfer": {
           "$ref": "#/components/schemas/Transfer"
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "No valid session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The role doesn't allow this action.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "There's no such request among those addressed to this person.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "409": {
      "description": "The request has already been resolved.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "410": {
      "description": "The request has expired.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/training": {
   "get": {
    "tags": [
     "Dashboard · Training"
    ],
    "summary": "Training mode status",
    "description": "Whether the mode is on, what it does without an operator, how many drafts are waiting, the readiness counter, and suggestions drawn from corrections.\n\nThe mode itself is turned on by changing the agent's settings: `PATCH …/config` with `training`, `training_idle`, `training_idle_min`.\n\n`share` — the share of a human's decisions that went out without edits, as a percentage; `-1` — there have been no decisions yet (this isn't zero: there's nothing to judge by).",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     }
    ],
    "responses": {
     "200": {
      "description": "Mode status.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "required": [
          "on",
          "idle",
          "idle_min",
          "waiting",
          "stats",
          "share",
          "suggestions"
         ],
         "properties": {
          "on": {
           "type": "boolean",
           "description": "The mode is on."
          },
          "idle": {
           "type": "string",
           "enum": [
            "wait",
            "send",
            "later"
           ],
           "description": "What to do when the operator hasn't replied."
          },
          "idle_min": {
           "type": "integer",
           "description": "After how many minutes the operator is considered not to have replied."
          },
          "waiting": {
           "type": "integer",
           "description": "How many drafts are waiting right now."
          },
          "stats": {
           "$ref": "#/components/schemas/TrainingStats"
          },
          "share": {
           "type": "integer",
           "description": "Share sent without edits, percent; `-1` — no decisions yet."
          },
          "suggestions": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/TrainingSuggestion"
           }
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "Sign-in required.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The role or key type doesn't allow this action.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Agent not found, or training mode isn't available in this build.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/training/drafts": {
   "get": {
    "tags": [
     "Dashboard · Training"
    ],
    "summary": "Draft queue",
    "description": "Drafts being composed, waiting for a person, and being sent — starting with the one whose customer has waited longest. Every workspace member can see them: this is the work of whoever answers in conversations.\n\nConversations with drafts are handled by the assistant, so they don't appear among active requests (`GET …/threads`); changes to the queue are signaled by the `training_waiting` field of the `GET …/events` stream.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     },
     {
      "name": "session",
      "in": "query",
      "required": false,
      "schema": {
       "type": "string"
      },
      "description": "Only drafts from this conversation."
     }
    ],
    "responses": {
     "200": {
      "description": "The queue.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "required": [
          "drafts"
         ],
         "properties": {
          "drafts": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/TrainingDraft"
           }
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "Sign-in required.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The role or key type doesn't allow this action.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Agent not found, or training mode isn't available in this build.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/training/drafts/{did}/hold": {
   "post": {
    "tags": [
     "Dashboard · Training"
    ],
    "summary": "Mark a draft as being edited",
    "description": "A soft \"is already editing …\" mark — as in an operator's conversation: a colleague sees who has taken it on, but there's no lock. Whoever's decision arrives first decides; the second gets `draft_decided`. The mark fades on its own after two minutes, so the dashboard repeats the call while the person is typing. `release: true` removes it.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     },
     {
      "name": "did",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "The draft ID (also the ID of the decision behind it)."
     }
    ],
    "requestBody": {
     "required": false,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "release": {
          "type": "boolean",
          "description": "`true` — remove the mark."
         }
        }
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "The draft with the mark.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "required": [
          "draft"
         ],
         "properties": {
          "draft": {
           "$ref": "#/components/schemas/TrainingDraft"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "The request can't be parsed.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "description": "Sign-in required.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The role or key type doesn't allow this action.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "There’s no such draft.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "409": {
      "description": "The draft has already been decided (`draft_decided`), replaced by a new one (`draft_stale`), or is still being composed (`draft_composing`).",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/training/drafts/{did}/decide": {
   "post": {
    "tags": [
     "Dashboard · Training"
    ],
    "summary": "Decide on a draft",
    "description": "Three ways: `send` — send as is; `edit` — send your own `text` instead of the draft (unchanged text counts as \"as is\"); `own` — reply yourself, the draft is discarded.\n\n**Actions.** Together with `send` and `edit`, the draft's actions that can be run (`runnable`) and that the person didn't remove are executed (`drop` — indexes of the removed ones, from zero). They run the same way as in an agent run with visitor rights: an action the owner marked \"only with permission\" becomes a card in the approvals queue rather than being executed on the operator's say-so. The request doesn't accept action arguments — what the agent composed is executed. `own` removes all actions.\n\nIf an action fails, the reply **is not sent** (`502`, `draft_action_failed`), and the draft returns to the queue with the reason in `note`. If the reply didn't reach the customer in the messenger — `502`, `draft_undelivered`, and the draft is also back in the queue; actions that already ran aren't run a second time.\n\n**The decision is atomic:** of two simultaneous decisions one goes through, the other gets `409 draft_decided`. If the customer wrote more while the draft was waiting — `409 draft_stale`: the assistant composes a new one taking both messages into account.\n\n`comment` — an optional \"what was wrong\": words for training, not sent to the customer.\n\nReplying to the customer doesn't switch the conversation to \"Handled by a person\": their next message will become a draft again.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     },
     {
      "name": "did",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "The draft ID (also the ID of the decision behind it)."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "required": [
         "action"
        ],
        "properties": {
         "action": {
          "type": "string",
          "enum": [
           "send",
           "edit",
           "own"
          ]
         },
         "text": {
          "type": "string",
          "maxLength": 8000,
          "description": "The reply text for the customer — for `edit` and `own`."
         },
         "comment": {
          "type": "string",
          "description": "What was wrong with the draft (up to 1,000 characters, longer is truncated). Not sent to the customer."
         },
         "drop": {
          "type": "array",
          "items": {
           "type": "integer"
          },
          "description": "Indexes of the draft's actions (from zero) that shouldn't be run."
         }
        }
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "The decision is recorded, and the reply went to the customer.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "required": [
          "draft"
         ],
         "properties": {
          "draft": {
           "$ref": "#/components/schemas/TrainingDraft"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "No reply text, the text is too long, or the decision isn't from the list.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "description": "Sign-in required.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The role or key type doesn't allow this action.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "There’s no such draft.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "409": {
      "description": "The decision has already been made (`draft_decided`), the customer wrote more (`draft_stale`), the draft is still being composed (`draft_composing`), or the agent is in the middle of moving to a new owner.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "422": {
      "description": "The agent didn't compose a draft — `send` isn't possible here; you can only reply yourself.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "502": {
      "description": "A draft action failed (`draft_action_failed`) or the reply didn't reach the customer (`draft_undelivered`). The draft stayed in the queue.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/training/decisions": {
   "get": {
    "tags": [
     "Dashboard · Training"
    ],
    "summary": "Decisions on drafts",
    "description": "What was asked, what the agent composed, what was sent, who decided, how big the edit was and what was wrong — newest first. This also includes drafts that went out on their own (`auto`). Replaced ones (`stale`) aren't here: they didn't answer anyone.\n\nThe readiness counter is calculated and suggestions are composed from these same rows — there are no separate counters.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     },
     {
      "name": "limit",
      "in": "query",
      "required": false,
      "schema": {
       "type": "integer"
      },
      "description": "How many decisions to return (default 50, maximum 200)."
     }
    ],
    "responses": {
     "200": {
      "description": "Decisions.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "required": [
          "decisions"
         ],
         "properties": {
          "decisions": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/TrainingDraft"
           }
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "Sign-in required.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The role or key type doesn't allow this action.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Agent not found, or training mode isn't available in this build.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/training/decisions/{did}/comment": {
   "post": {
    "tags": [
     "Dashboard · Training"
    ],
    "summary": "Add \"what was wrong\"",
    "description": "A remark on a decision already made: it often comes to mind after the reply has gone out. A draft sent as is with a remark becomes an example for the agent just like a correction.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     },
     {
      "name": "did",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "The draft ID (also the ID of the decision behind it)."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "required": [
         "comment"
        ],
        "properties": {
         "comment": {
          "type": "string",
          "description": "What was wrong (up to 1,000 characters, longer is truncated)."
         }
        }
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "The decision with the remark.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "required": [
          "decision"
         ],
         "properties": {
          "decision": {
           "$ref": "#/components/schemas/TrainingDraft"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "The remark is empty.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "description": "Sign-in required.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The role or key type doesn't allow this action.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "There’s no such decision.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/training/decisions/{did}": {
   "delete": {
    "tags": [
     "Dashboard · Training"
    ],
    "summary": "Remove a decision",
    "description": "Admin only: the decision disappears completely — the agent no longer uses it as an example, and it doesn't count toward the readiness counter. For a correction that was itself a mistake.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     },
     {
      "name": "did",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "The draft ID (also the ID of the decision behind it)."
     }
    ],
    "responses": {
     "204": {
      "description": "Removed."
     },
     "401": {
      "description": "Sign-in required.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "Admin rights required.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "There’s no such decision.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/training/suggestions/{sid}/apply": {
   "post": {
    "tags": [
     "Dashboard · Training"
    ],
    "summary": "Apply a suggestion",
    "description": "Admin only: a suggestion drawn from corrections becomes a change to the agent through existing paths.\n\n- `knowledge` — a \"question — answer\" pair goes into the knowledge base (just like answering a question from \"What the agent doesn't know\"): an entry in the change log, can be undone. `answer` — the answer, if the owner refined it; otherwise the latest human answer from the suggestion is used.\n- `playbook` — a **draft** skill: it doesn't go into the prompt until it's approved in \"Skills\". It's composed from operators' words and customers' questions, so it carries the mark, like a draft written after reading third-party content.\n- `dismiss` — don't suggest it again.\n\nThe platform takes the question (and, for a skill, the answer too) **from its own records**, not from the request. After this, corrections from the suggestion no longer produce suggestions, but they remain examples for the agent.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     },
     {
      "name": "sid",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "The suggestion ID from `GET …/training`."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "required": [
         "to"
        ],
        "properties": {
         "to": {
          "type": "string",
          "enum": [
           "knowledge",
           "playbook",
           "dismiss"
          ]
         },
         "answer": {
          "type": "string",
          "description": "Only for `knowledge`: the answer in the owner's words."
         }
        }
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Applied.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "required": [
          "applied"
         ],
         "properties": {
          "applied": {
           "type": "string",
           "enum": [
            "knowledge",
            "playbook",
            "dismissed"
           ]
          },
          "source_id": {
           "type": "string",
           "description": "For `knowledge`: the ID of the added knowledge source."
          },
          "playbook_id": {
           "type": "string",
           "description": "For `playbook`: the ID of the skill draft."
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "`to` isn't from the list, or the skill failed validation.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "description": "Sign-in required.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "Admin rights required.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "That suggestion no longer exists.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "409": {
      "description": "Too many skill drafts, or this name already exists.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "422": {
      "description": "The suggestion has no answer that can be added to knowledge.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "502": {
      "description": "The knowledge or draft couldn't be saved.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "503": {
      "description": "The knowledge base is temporarily unavailable.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/base/summary": {
   "get": {
    "tags": [
     "Dashboard · Search base"
    ],
    "summary": "Source registry and search quality in numbers",
    "description": "Registry counters (\"found / active / on topic\", access states) and search quality metrics. Everything is calculated from the notebook cards and the spending log at the moment of the request — this isn't the agent's words.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     }
    ],
    "responses": {
     "200": {
      "description": "Counters",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "sources": {
           "$ref": "#/components/schemas/BaseSources"
          },
          "quality": {
           "$ref": "#/components/schemas/BaseQuality"
          },
          "meaning": {
           "type": "boolean",
           "description": "Whether the notebook searches by meaning. false — search goes by words and fields, and like is rejected."
          }
         },
         "required": [
          "sources",
          "quality",
          "meaning"
         ]
        }
       }
      }
     },
     "401": {
      "description": "Sign-in required"
     },
     "403": {
      "description": "Wrong key type for this endpoint"
     },
     "404": {
      "description": "This build has no search base, or the agent isn't yours"
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/base/import": {
   "post": {
    "tags": [
     "Dashboard · Search base"
    ],
    "summary": "Add your own list of sources",
    "description": "Admin only. A list of links as text (JSON) or as a CSV or XLSX table (multipart, field file). Columns with known names — «назва» (\"name\"), \"country\", «мова» (\"language\"), «тип» (\"type\") — become card fields. The same site written in different ways is one source. as=control puts the list not into the registry but into the CONTROL list: what the agent finds is compared against it (coverage).",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "text": {
          "type": "string",
          "description": "Links separated by spaces, commas or new lines."
         },
         "as": {
          "type": "string",
          "enum": [
           "sources",
           "control"
          ],
          "description": "Where to: into the source registry (default) or into the control list."
         }
        },
        "required": [
         "text"
        ]
       }
      },
      "multipart/form-data": {
       "schema": {
        "type": "object",
        "properties": {
         "file": {
          "type": "string",
          "format": "binary",
          "description": "CSV or XLSX, up to 5 MB."
         },
         "as": {
          "type": "string",
          "enum": [
           "sources",
           "control"
          ]
         }
        },
        "required": [
         "file"
        ]
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "What was added",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "added": {
           "type": "integer",
           "description": "How many new sources."
          },
          "existed": {
           "type": "integer",
           "description": "How many already existed."
          },
          "skipped": {
           "type": "array",
           "items": {
            "type": "string"
           },
           "description": "Rows without an address, as they were (up to twenty)."
          },
          "truncated": {
           "type": "boolean",
           "description": "The list is longer than two thousand — the tail wasn't taken."
          },
          "failed": {
           "type": "array",
           "items": {
            "type": "string"
           },
           "description": "Sources that weren't added, with the reason."
          }
         },
         "required": [
          "added",
          "existed",
          "skipped",
          "truncated",
          "failed"
         ]
        }
       }
      }
     },
     "400": {
      "description": "The request couldn't be parsed — the text says what's missing"
     },
     "401": {
      "description": "Sign-in required"
     },
     "403": {
      "description": "Admin rights required"
     },
     "404": {
      "description": "This build has no search base, or the agent isn't yours"
     },
     "413": {
      "description": "The file is larger than 5 MB"
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/base/sources/check": {
   "post": {
    "tags": [
     "Dashboard · Search base"
    ],
    "summary": "Check access to sources",
    "description": "Admin only. The platform itself opens the address of each source (up to 25 at a time) and records the access state and the check date in the card — no model and no credits. It bypasses nothing: a page with an \"I'm not a robot\" check or a sign-in gives the state «потрібен вхід» (\"sign-in required\"); if robots.txt forbids it, no request is made at all; closed platforms (Facebook, Instagram, TikTok, YouTube, WeChat, Weibo) aren't requested at all and have the state «потрібен API» (\"API required\").",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "keys": {
          "type": "array",
          "items": {
           "type": "string"
          },
          "description": "Card keys."
         }
        },
        "required": [
         "keys"
        ]
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Results",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "checked": {
           "type": "array",
           "items": {
            "type": "object",
            "properties": {
             "key": {
              "type": "string"
             },
             "access": {
              "type": "string",
              "description": "Access state."
             },
             "why": {
              "type": "string",
              "description": "Why it's unavailable; absent — readable."
             },
             "feed": {
              "type": "string",
              "description": "The RSS or Atom feed address, if the page names one."
             }
            },
            "required": [
             "key",
             "access"
            ]
           }
          }
         },
         "required": [
          "checked"
         ]
        }
       }
      }
     },
     "400": {
      "description": "The request couldn't be parsed — the text says what's missing"
     },
     "401": {
      "description": "Sign-in required"
     },
     "403": {
      "description": "Admin rights required"
     },
     "404": {
      "description": "This build has no search base, or the agent isn't yours"
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/base/sources/switch": {
   "post": {
    "tags": [
     "Dashboard · Search base"
    ],
    "summary": "Turn sources off or on",
    "description": "Admin only. A turned-off source stays in the registry, but the agent doesn't visit it; an agent's write doesn't turn a turned-off source back on.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "keys": {
          "type": "array",
          "items": {
           "type": "string"
          },
          "description": "Card keys."
         },
         "off": {
          "type": "boolean",
          "description": "true — turn off, false — turn on."
         }
        },
        "required": [
         "keys",
         "off"
        ]
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Changed",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "changed": {
           "type": "integer",
           "description": "How many sources were changed."
          }
         },
         "required": [
          "changed"
         ]
        }
       }
      }
     },
     "400": {
      "description": "The request couldn't be parsed — the text says what's missing"
     },
     "401": {
      "description": "Sign-in required"
     },
     "403": {
      "description": "Admin rights required"
     },
     "404": {
      "description": "This build has no search base, or the agent isn't yours"
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/base/results/card": {
   "get": {
    "tags": [
     "Dashboard · Search base"
    ],
    "summary": "Result card with provenance",
    "description": "One result card, the other cards for the same object (a group of duplicates — \"listed on three platforms\", each with its own price), and the trust in each known field: whether it's confirmed by a page fragment, whether it matched across sources, or whether it was recorded without confirmation.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     },
     {
      "name": "key",
      "in": "query",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Card key."
     }
    ],
    "responses": {
     "200": {
      "description": "The card",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "record": {
           "$ref": "#/components/schemas/RecordCard"
          },
          "copies": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/RecordCard"
           },
           "description": "Other cards for the same object."
          },
          "trust": {
           "type": "object",
           "description": "Field → trust.",
           "additionalProperties": {
            "type": "object",
            "properties": {
             "level": {
              "type": "string",
              "description": "«підтверджено» (\"confirmed\"), «збігається між джерелами» (\"matches across sources\"), «підтверджено й збігається між джерелами» (\"confirmed and matches across sources\") or «без підтвердження» (\"unconfirmed\")."
             },
             "score": {
              "type": "number",
              "description": "The same as a number, from 0 to 1."
             },
             "snippet": {
              "type": "string",
              "description": "The page fragment the value was taken from."
             },
             "from": {
              "type": "string",
              "description": "The page where this fragment is."
             }
            },
            "required": [
             "level",
             "score"
            ]
           }
          }
         },
         "required": [
          "record",
          "copies",
          "trust"
         ]
        }
       }
      }
     },
     "400": {
      "description": "The request couldn't be parsed — the text says what's missing"
     },
     "401": {
      "description": "Sign-in required"
     },
     "403": {
      "description": "Wrong key type for this endpoint"
     },
     "404": {
      "description": "This build has no search base, or the agent isn't yours"
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/base/results/rate": {
   "post": {
    "tags": [
     "Dashboard · Search base"
    ],
    "summary": "Rate results",
    "description": "Admin only. A person's rating: «підходить» (\"fits\"), «не підходить» (\"doesn't fit\") or an empty string (remove). Search precision is calculated from it; the agent rewriting a card doesn't erase the rating.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "keys": {
          "type": "array",
          "items": {
           "type": "string"
          },
          "description": "Card keys."
         },
         "verdict": {
          "type": "string",
          "enum": [
           "підходить",
           "не підходить",
           ""
          ],
          "description": "The rating; empty — remove."
         }
        },
        "required": [
         "keys",
         "verdict"
        ]
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Marked",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "changed": {
           "type": "integer"
          }
         },
         "required": [
          "changed"
         ]
        }
       }
      }
     },
     "400": {
      "description": "The request couldn't be parsed — the text says what's missing"
     },
     "401": {
      "description": "Sign-in required"
     },
     "403": {
      "description": "Admin rights required"
     },
     "404": {
      "description": "This build has no search base, or the agent isn't yours"
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/base/results/dupes": {
   "post": {
    "tags": [
     "Dashboard · Search base"
    ],
    "summary": "Merge, split, or reject a duplicate",
    "description": "Admin only. glue — key and other are the same object (the groups merge); split — take key out of its group; different — key and other aren't the same. After split and different, the platform no longer merges or suggests this pair.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "action": {
          "type": "string",
          "enum": [
           "glue",
           "split",
           "different"
          ]
         },
         "key": {
          "type": "string"
         },
         "other": {
          "type": "string",
          "description": "The second card — for glue and different."
         }
        },
        "required": [
         "action",
         "key"
        ]
       }
      }
     }
    },
    "responses": {
     "204": {
      "description": "Done"
     },
     "400": {
      "description": "The request couldn't be parsed — the text says what's missing"
     },
     "401": {
      "description": "Sign-in required"
     },
     "403": {
      "description": "Admin rights required"
     },
     "404": {
      "description": "This build has no search base, or the agent isn't yours"
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/base/results/send": {
   "post": {
    "tags": [
     "Dashboard · Search base"
    ],
    "summary": "Send results to the webhook",
    "description": "Admin only. Sends the named results (up to 200) as a POST request to the URL from the base settings. preview: true sends nothing and returns the body that would have been sent, so a person sees it before sending. The platform has no ready-made CRM integrations: a webhook is the common language for all of them.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "keys": {
          "type": "array",
          "items": {
           "type": "string"
          },
          "description": "Card keys."
         },
         "preview": {
          "type": "boolean",
          "description": "true — only show the body."
         }
        },
        "required": [
         "keys"
        ]
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Sent, or the body was shown",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "sent": {
           "type": "integer",
           "description": "How many results were sent."
          },
          "status": {
           "type": "integer",
           "description": "The receiver's response."
          },
          "url": {
           "type": "string",
           "description": "Where it was sent."
          },
          "body": {
           "type": "object",
           "additionalProperties": true,
           "description": "The request body — only with preview."
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "The request couldn't be parsed — the text says what's missing"
     },
     "401": {
      "description": "Sign-in required"
     },
     "403": {
      "description": "Admin rights required"
     },
     "404": {
      "description": "This build has no search base, or the agent isn't yours"
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/base/settings": {
   "get": {
    "tags": [
     "Dashboard · Search base"
    ],
    "summary": "Search base settings",
    "description": "The webhook URL, how long contacts are kept, and whether to publish without approval.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     }
    ],
    "responses": {
     "200": {
      "description": "Settings",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/BaseSettings"
        }
       }
      }
     },
     "401": {
      "description": "Sign-in required"
     },
     "403": {
      "description": "Wrong key type for this endpoint"
     },
     "404": {
      "description": "This build has no search base, or the agent isn't yours"
     }
    }
   },
   "put": {
    "tags": [
     "Dashboard · Search base"
    ],
    "summary": "Change search base settings",
    "description": "Admin only. Changes only the named fields. The webhook URL must be https.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "crm_url": {
          "type": "string",
          "description": "An empty string removes it."
         },
         "contact_days": {
          "type": "integer",
          "minimum": 1,
          "maximum": 3650
         },
         "auto_publish": {
          "type": "boolean"
         }
        }
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Settings",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/BaseSettings"
        }
       }
      }
     },
     "400": {
      "description": "The request couldn't be parsed — the text says what's missing"
     },
     "401": {
      "description": "Sign-in required"
     },
     "403": {
      "description": "Admin rights required"
     },
     "404": {
      "description": "This build has no search base, or the agent isn't yours"
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/base/contacts/erase": {
   "post": {
    "tags": [
     "Dashboard · Search base"
    ],
    "summary": "Erase contacts",
    "description": "Admin only. One of two: key — erase a single contact card; source — erase all contacts from a source: the contact cards from that site, plus the phone and contact in results from it.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "key": {
          "type": "string",
          "description": "The contact card key."
         },
         "source": {
          "type": "string",
          "description": "The source URL."
         }
        }
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Erased",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "contacts": {
           "type": "integer",
           "description": "How many contact cards were removed."
          },
          "results": {
           "type": "integer",
           "description": "In how many results the phone and contact were erased."
          }
         },
         "required": [
          "contacts",
          "results"
         ]
        }
       }
      }
     },
     "400": {
      "description": "The request couldn't be parsed — the text says what's missing"
     },
     "401": {
      "description": "Sign-in required"
     },
     "403": {
      "description": "Admin rights required"
     },
     "404": {
      "description": "This build has no search base, or the agent isn't yours"
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/base/searches": {
   "get": {
    "tags": [
     "Dashboard · Search base"
    ],
    "summary": "Saved searches",
    "description": "The agent's searches with their latest pass: when it ran, how many objects match, and how many are new since the previous time.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     }
    ],
    "responses": {
     "200": {
      "description": "The list",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "searches": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/SavedSearch"
           }
          }
         },
         "required": [
          "searches"
         ]
        }
       }
      }
     },
     "401": {
      "description": "Sign-in required"
     },
     "403": {
      "description": "Wrong key type for this endpoint"
     },
     "404": {
      "description": "This build has no search base, or the agent isn't yours"
     }
    }
   },
   "post": {
    "tags": [
     "Dashboard · Search base"
    ],
    "summary": "Save a search",
    "description": "Admin only. Saves a query with its conditions and runs it right away. A search only looks through what has already been collected and costs nothing; new cards come from the agent's work.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "name": {
          "type": "string"
         },
         "kind": {
          "type": "string"
         },
         "text": {
          "type": "string"
         },
         "like": {
          "type": "string"
         },
         "where": {
          "type": "array",
          "items": {
           "type": "string"
          }
         },
         "strict": {
          "type": "boolean"
         },
         "every_hours": {
          "type": "integer",
          "minimum": 0,
          "maximum": 720
         }
        },
        "required": [
         "name"
        ]
       }
      }
     }
    },
    "responses": {
     "201": {
      "description": "Saved",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "search": {
           "$ref": "#/components/schemas/SavedSearch"
          }
         },
         "required": [
          "search"
         ]
        }
       }
      }
     },
     "400": {
      "description": "The request couldn't be parsed — the text says what's missing"
     },
     "401": {
      "description": "Sign-in required"
     },
     "403": {
      "description": "Admin rights required"
     },
     "404": {
      "description": "This build has no search base, or the agent isn't yours"
     },
     "409": {
      "description": "There are already twenty saved searches"
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/base/searches/{sid}": {
   "patch": {
    "tags": [
     "Dashboard · Search base"
    ],
    "summary": "Change a saved search",
    "description": "Admin only. Changes the named fields: name, conditions, schedule, pause. Changing the conditions resets the \"new since last time\" count.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     },
     {
      "name": "sid",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "The saved search number."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "name": {
          "type": "string"
         },
         "text": {
          "type": "string"
         },
         "like": {
          "type": "string"
         },
         "where": {
          "type": "array",
          "items": {
           "type": "string"
          }
         },
         "strict": {
          "type": "boolean"
         },
         "every_hours": {
          "type": "integer"
         },
         "paused": {
          "type": "boolean"
         }
        }
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Changed",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "search": {
           "$ref": "#/components/schemas/SavedSearch"
          }
         },
         "required": [
          "search"
         ]
        }
       }
      }
     },
     "400": {
      "description": "The request couldn't be parsed — the text says what's missing"
     },
     "401": {
      "description": "Sign-in required"
     },
     "403": {
      "description": "Admin rights required"
     },
     "404": {
      "description": "This build has no search base, or the agent isn't yours"
     }
    }
   },
   "delete": {
    "tags": [
     "Dashboard · Search base"
    ],
    "summary": "Remove a saved search",
    "description": "Admin only.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     },
     {
      "name": "sid",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "The saved search number."
     }
    ],
    "responses": {
     "204": {
      "description": "Removed"
     },
     "401": {
      "description": "Sign-in required"
     },
     "403": {
      "description": "Admin rights required"
     },
     "404": {
      "description": "This build has no search base, or the agent isn't yours"
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/base/searches/{sid}/run": {
   "post": {
    "tags": [
     "Dashboard · Search base"
    ],
    "summary": "Run a saved search now",
    "description": "Admin only. Counts how many objects match the search and how many have appeared since the last pass. No model, no credits.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     },
     {
      "name": "sid",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "The saved search number."
     }
    ],
    "responses": {
     "200": {
      "description": "The search was run",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "search": {
           "$ref": "#/components/schemas/SavedSearch"
          }
         },
         "required": [
          "search"
         ]
        }
       }
      }
     },
     "401": {
      "description": "Sign-in required"
     },
     "403": {
      "description": "Admin rights required"
     },
     "404": {
      "description": "This build has no search base, or the agent isn't yours"
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/base/publications/submit": {
   "post": {
    "tags": [
     "Dashboard · Search base"
    ],
    "summary": "Submit a publication for approval",
    "description": "Admin only. For a publication that names an owner action: the card goes into the approval queue, and the action runs only after a \"yes\" (or right away if publishing without approval is turned on in the base settings). Before that, the platform checks for a repeat (the same text to the same venue), the stop list and the rate limit.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "key": {
          "type": "string",
          "description": "The publication key."
         }
        },
        "required": [
         "key"
        ]
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Log card",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "record": {
           "$ref": "#/components/schemas/RecordCard"
          }
         },
         "required": [
          "record"
         ]
        }
       }
      }
     },
     "400": {
      "description": "The request couldn't be parsed — the text says what's missing"
     },
     "401": {
      "description": "Sign-in required"
     },
     "403": {
      "description": "Admin rights required"
     },
     "404": {
      "description": "This build has no search base, or the agent isn't yours"
     },
     "409": {
      "description": "This text has already been published to this venue, or the publication is already awaiting approval"
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/base/publications/done": {
   "post": {
    "tags": [
     "Dashboard · Search base"
    ],
    "summary": "Record a publication made by hand",
    "description": "Admin only. A person posted the listing themselves: the log entry gets the \"published\" state, the time and a link (optional).",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "key": {
          "type": "string"
         },
         "link": {
          "type": "string",
          "description": "A link to the published listing."
         }
        },
        "required": [
         "key"
        ]
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Log card",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "record": {
           "$ref": "#/components/schemas/RecordCard"
          }
         },
         "required": [
          "record"
         ]
        }
       }
      }
     },
     "400": {
      "description": "The request couldn't be parsed — the text says what's missing"
     },
     "401": {
      "description": "Sign-in required"
     },
     "403": {
      "description": "Admin rights required"
     },
     "404": {
      "description": "This build has no search base, or the agent isn't yours"
     }
    }
   }
  },
  "/v1/auth/email/verify": {
   "post": {
    "tags": [
     "Authentication"
    ],
    "summary": "Send an email address confirmation email",
    "description": "Sends an email with a ONE-TIME link to the dashboard's `/confirm` page to the account's address. The link is valid for 24 hours. At least a minute must pass between two emails (`429` with `Retry-After`).\n\nWhen the build has no mail, the response is `503` with code `mail_not_configured`, not \"email sent\"; if mail is configured but the email didn't go out, it's `502` with `mail_send_failed`.",
    "security": [
     {
      "sessionCookie": []
     }
    ],
    "responses": {
     "200": {
      "description": "The email was sent.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "status": {
           "type": "string",
           "description": "",
           "enum": [
            "sent"
           ]
          },
          "email": {
           "type": "string",
           "description": "Which address."
          },
          "expires_in_hours": {
           "type": "integer",
           "description": "How many hours the link is valid."
          },
          "retry_in_seconds": {
           "type": "integer",
           "description": "In how many seconds another email can be requested."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "Session missing or expired.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "A request from another site. Roles don't matter here — these endpoints don't check them; see `sessionCookie` for how writes are protected by origin. Also: an action with a key (`forbidden`), and the account is being deleted (`account_closing`): the dashboard is locked until the account is restored (`POST /v1/auth/account/restore`).",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "409": {
      "description": "The address is already confirmed, or the account has no mailbox.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "429": {
      "description": "An email was just sent. `Retry-After` says how long to wait.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "502": {
      "description": "Mail is configured, but the email didn't go out (`mail_send_failed`).",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "503": {
      "description": "This build has no email (`mail_not_configured`), or storage is unavailable (`service_unavailable`).",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/auth/email": {
   "post": {
    "tags": [
     "Authentication"
    ],
    "summary": "Change the account email address",
    "description": "Requires the current password — a session alone isn't enough: the address is where password recovery goes.\n\nIf the current address is confirmed (or the account is an old one), it does NOT change right away. An email with a link (valid for 24 hours) goes to the new address; a notification with a \"this wasn't me\" link goes to the old one — it is valid for 7 days and cancels the change, or brings the old address back if the change was already confirmed. Until the new address is confirmed, the change is visible in `GET /v1/auth/me` (`pending_email`) and can be cancelled (`DELETE`). Once it is confirmed, the account's other sessions are ended.\n\nIf the current address is NOT confirmed (`email_state: pending`), the account switches to the new one right away — nobody ever confirmed the old one, and most often it's a typo at sign-up — and a confirmation email goes to the new address.\n\nTeam invitations issued to the old address can't be accepted after the change (they are checked against the account address) — `invitation_waiting` says so. Agent transfer requests are tied to the account and stay valid.",
    "security": [
     {
      "sessionCookie": []
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "new_email": {
          "type": "string",
          "format": "email"
         },
         "current_password": {
          "type": "string"
         }
        },
        "required": [
         "new_email",
         "current_password"
        ]
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "The change has started (`pending`), or the address was changed right away (`changed`).",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "status": {
           "type": "string",
           "description": "`pending` — waiting for confirmation by the email at the new address; `changed` — the account is already on the new address (the current one was unconfirmed).",
           "enum": [
            "pending",
            "changed"
           ]
          },
          "pending_email": {
           "type": "string",
           "description": "The new address (for `pending`)."
          },
          "email": {
           "type": "string",
           "description": "The account address (for `changed`)."
          },
          "expires_in_hours": {
           "type": "integer",
           "description": "How many hours the link at the new address is valid (for `pending`)."
          },
          "old_notified": {
           "type": "boolean",
           "description": "Whether the notification went out to the old address (for `pending`)."
          },
          "invitation_waiting": {
           "type": "boolean",
           "description": "A team invitation is waiting at the old address: after the change it can't be accepted (for `pending`)."
          },
          "letter_sent": {
           "type": "boolean",
           "description": "Whether the confirmation email went out to the new address (for `changed`)."
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "The new address doesn't look like an email address, or a field is missing.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "description": "Session missing or expired.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "Wrong password (`wrong_password`). A request from another site. Roles don't matter here — these endpoints don't check them; see `sessionCookie` for how writes are protected by origin. The account is being deleted (`account_closing`): the dashboard is locked until the account is restored (`POST /v1/auth/account/restore`).",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "409": {
      "description": "The address is already taken by another account, matches the current one, or the account has no password (sign-in with a shared account).",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "429": {
      "description": "Too many password attempts. `Retry-After` says how long to wait.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "502": {
      "description": "The email to the new address didn't go out (`mail_send_failed`) — the address was not changed.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "503": {
      "description": "This build has no email (`mail_not_configured`): the address can't be changed.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   },
   "delete": {
    "tags": [
     "Authentication"
    ],
    "summary": "Cancel an unfinished address change",
    "description": "The link from the email at the new address stops working; the account address stays as it is. If there's nothing to cancel, the response is the same with `cancelled: false`.",
    "security": [
     {
      "sessionCookie": []
     }
    ],
    "responses": {
     "200": {
      "description": "The change was cancelled (or there wasn't one).",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "status": {
           "type": "string",
           "description": "",
           "enum": [
            "cancelled"
           ]
          },
          "cancelled": {
           "type": "boolean",
           "description": "Whether there was anything to cancel."
          },
          "email": {
           "type": "string",
           "description": "The account address."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "Session missing or expired.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "A request from another site. Roles don't matter here — these endpoints don't check them; see `sessionCookie` for how writes are protected by origin. Also: an action with a key (`forbidden`), and the account is being deleted (`account_closing`): the dashboard is locked until the account is restored (`POST /v1/auth/account/restore`).",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "503": {
      "description": "This build has no email (`mail_not_configured`), or storage is unavailable.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/auth/email/confirm": {
   "post": {
    "tags": [
     "Authentication"
    ],
    "summary": "Follow a link from an email",
    "description": "Accepts the token from a link in an email to the account's address. No session needed: these links get opened where nobody has signed in to the dashboard.\n\n`action: confirm` (the default) — confirm the account address or the new address; `action: undo` — \"this wasn't me\" from the notification to the old address: the change is cancelled (or the old address is brought back), and all of the account's sessions are ended. The token is single-use and knows its purpose: opened with the wrong action, it doesn't work.",
    "security": [],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "token": {
          "type": "string"
         },
         "action": {
          "type": "string",
          "enum": [
           "confirm",
           "undo"
          ]
         }
        },
        "required": [
         "token"
        ]
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "The link was followed.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "status": {
           "type": "string",
           "description": "`verified` — the address is confirmed; `changed` — the account moved to the new address, other sessions were ended; `stopped` — the change was stopped before confirmation; `reverted` — the old address was brought back. After `stopped` and `reverted`, ALL sessions are ended.",
           "enum": [
            "verified",
            "changed",
            "stopped",
            "reverted"
           ]
          },
          "email": {
           "type": "string",
           "description": "The account address after the action."
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "The token is missing, or the action is unknown.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "409": {
      "description": "Another account has taken the new address in the meantime.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "410": {
      "description": "The link doesn't work (`email_ticket_invalid`): it expired, was already used, or isn't for this action.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "429": {
      "description": "Too many attempts from this caller address.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "503": {
      "description": "This build has no email (`mail_not_configured`), or storage is unavailable.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/auth/account": {
   "get": {
    "tags": [
     "Authentication"
    ],
    "summary": "What deleting the account will affect",
    "description": "A list of what will happen if the account is deleted — to show the person BEFORE the confirmation word. Changes nothing. Also responds for an account that is already being deleted (the `closing` field).",
    "security": [
     {
      "sessionCookie": []
     }
    ],
    "responses": {
     "200": {
      "description": "The list of consequences.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "agents": {
           "type": "array",
           "items": {
            "type": "object",
            "properties": {
             "id": {
              "type": "string"
             },
             "name": {
              "type": "string"
             },
             "sites": {
              "type": "array",
              "items": {
               "type": "string"
              },
              "description": "Sites where this agent's chat window is installed."
             },
             "channels": {
              "type": "array",
              "items": {
               "type": "string"
              },
              "description": "Connected channels (types)."
             }
            }
           },
           "description": "Agents in the person's own workspace: they will stop answering right away — in chat windows on sites and in channels."
          },
          "members": {
           "type": "array",
           "items": {
            "type": "string"
           },
           "description": "Addresses of people in the person's own workspace: they will lose access right away."
          },
          "invitations": {
           "type": "integer",
           "description": "How many unused invitations will be revoked."
          },
          "teams": {
           "type": "integer",
           "description": "In how many other people's teams the person is a member: their place in them disappears along with the account."
          },
          "subscription": {
           "type": "object",
           "description": "The current subscription; absent — there's no subscription.",
           "properties": {
            "plan": {
             "type": "string"
            },
            "paid_until": {
             "type": "string",
             "description": "Paid until.",
             "format": "date-time"
            },
            "renews": {
             "type": "boolean",
             "description": "The subscription still renews automatically: deletion will cancel the renewal with the payment service."
            }
           }
          },
          "grace_hours": {
           "type": "integer",
           "description": "For how many hours after deletion the account can be restored."
          },
          "word": {
           "type": "string",
           "description": "The word to type to confirm."
          },
          "needs_password": {
           "type": "boolean",
           "description": "Whether the password is asked again (not for an account without a password)."
          },
          "closing": {
           "type": "object",
           "description": "Present if deletion is already in progress.",
           "properties": {
            "deleted_at": {
             "type": "string",
             "description": "",
             "format": "date-time"
            },
            "erase_at": {
             "type": "string",
             "description": "",
             "format": "date-time"
            }
           }
          },
          "open_payments": {
           "type": "integer",
           "description": "How many payments were started and not finished: deletion will cancel them."
          }
         },
         "required": [
          "agents",
          "members",
          "invitations",
          "teams",
          "grace_hours",
          "word",
          "needs_password",
          "open_payments"
         ]
        }
       }
      }
     },
     "401": {
      "description": "Session missing or expired.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "An action with a key: a person needs to sign in.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "500": {
      "description": "The list could not be read.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/auth/account/delete": {
   "post": {
    "tags": [
     "Authentication"
    ],
    "summary": "Delete the account",
    "description": "Requires the current password and the confirmation word (`word` from `GET /v1/auth/account`; case doesn't matter).\n\nRight away: unfinished payments are cancelled (a cancelled invoice can't be credited); the subscription renewal is cancelled with the payment service (if it doesn't confirm — `502`, and the account is NOT deleted: otherwise charges would continue); agents in the person's own workspace are removed from it by the same step as an ordinary agent deletion — chat windows on sites and channels stop answering; the team is disbanded; agent transfer requests are cancelled; the other sessions are ended. An email with the erase date goes to the address.\n\nThen comes the `grace_hours` window: the person can sign in and restore the account (`POST /v1/auth/account/restore`). After the window, the data is erased for good: the agents with everything in them, the workspace, counters, conversations with the Builder, and the account itself. Payment records stay in the platform's accounting.\n\nAn account can't be deleted with a key.",
    "security": [
     {
      "sessionCookie": []
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "current_password": {
          "type": "string",
          "description": "The current password. An account without a password sends an empty string."
         },
         "confirm": {
          "type": "string",
          "description": "The confirmation word."
         }
        },
        "required": [
         "confirm"
        ]
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "The account is being deleted.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "status": {
           "type": "string",
           "description": "",
           "enum": [
            "closing"
           ]
          },
          "deleted_at": {
           "type": "string",
           "description": "",
           "format": "date-time"
          },
          "erase_at": {
           "type": "string",
           "description": "When the data will be erased; until then the account can be restored.",
           "format": "date-time"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "The confirmation word is missing or wrong.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "description": "Session missing or expired.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "Wrong password (`wrong_password`). A request from another site. Roles don't matter here — these endpoints don't check them; see `sessionCookie` for how writes are protected by origin. The account is being deleted (`account_closing`): the dashboard is locked until the account is restored (`POST /v1/auth/account/restore`).",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "409": {
      "description": "The account is already being deleted (`account_closing`), or one of the agents is being transferred to another person right now — wait a little.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "429": {
      "description": "Too many password attempts.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "500": {
      "description": "The workspace could not be read — the account was not deleted.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "501": {
      "description": "Account deletion isn’t available in this build.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "502": {
      "description": "The payment service didn't confirm cancelling the subscription or an unfinished payment — the account was not deleted.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "503": {
      "description": "The intent was not recorded — the account was not deleted (the subscription renewal has already been cancelled).",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/auth/account/restore": {
   "post": {
    "tags": [
     "Authentication"
    ],
    "summary": "Restore an account that is being deleted",
    "description": "\"I changed my mind.\" Works until `erase_at` has passed. Restores the account and the agents that deletion removed (with the same keys — the chat window code on sites keeps working). Does NOT restore the team (people have to be invited again) or the subscription renewal (the paid period remains; after it, the plan has to be set up again).",
    "security": [
     {
      "sessionCookie": []
     }
    ],
    "responses": {
     "200": {
      "description": "The account was restored.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "status": {
           "type": "string",
           "description": "",
           "enum": [
            "restored"
           ]
          },
          "agents_restored": {
           "type": "integer",
           "description": "How many agents were restored."
          },
          "agents_incomplete": {
           "type": "boolean",
           "description": "Not all agents were restored automatically: the rest are in the dashboard's list of deleted agents, with a \"Restore\" button."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "Session missing or expired.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "An action with a key: a person needs to sign in. A request from another site. Roles don't matter here — these endpoints don't check them; see `sessionCookie` for how writes are protected by origin.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "409": {
      "description": "The account isn’t being deleted — there’s nothing to restore.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "503": {
      "description": "Could not restore — try again in a moment.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/dashboard/exports": {
   "get": {
    "tags": [
     "Dashboard · Agents"
    ],
    "summary": "Workspace export archives",
    "description": "The workspace's archives, newest first, and whether a new one can be started now. While an archive is being built, its progress (`step`, `done`, `total`) is shown here — re-read every few seconds.\n\nA finished archive lives for 24 hours and is erased automatically; its row stays in the list for another week with the `expired` state.",
    "security": [
     {
      "sessionCookie": []
     }
    ],
    "responses": {
     "200": {
      "description": "Archives and whether a new one is allowed.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "exports": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/AccountExport"
           }
          },
          "can_start": {
           "type": "boolean",
           "description": "Whether a new archive can be started now: none is being built, and the daily count isn't used up."
          },
          "wait_seconds": {
           "type": "integer",
           "description": "In how many seconds a new one can be started. Only when the reason is the daily count."
          }
         },
         "required": [
          "exports",
          "can_start"
         ]
        }
       }
      }
     },
     "401": {
      "description": "No valid session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "Your role doesn't allow this action: export is for the workspace owner only, and only with a session (not with a key).",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Archive export isn’t available in this build.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "500": {
      "description": "The list could not be read.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   },
   "post": {
    "tags": [
     "Dashboard · Agents"
    ],
    "summary": "Build a workspace data archive",
    "description": "Starts building a FULL export of the workspace as a ZIP archive and returns its row right away; the build itself runs in the background.\n\nThe archive holds everything the owner sees in the dashboard: agents with their settings and flow, knowledge (source texts), actions, channels, schedules, conversations with the Builder, customer conversations, requests, contacts, training, the notebook and the search base, tasks, permissions, skills, notes, agent files, payments and credit spending, the team, the change log. Tables are CSV (they open in any spreadsheet program), the rest is JSON; the first file in the archive, `Read me.txt` («Прочитайте.txt» in a Ukrainian archive), says what is where.\n\nThere are no secrets in the archive: keys, tokens and passwords are named, but their values are not included. It does, however, contain the personal data of the workspace's customers — their messages and contacts.\n\nOnly one archive per workspace is built at a time (`409 export_busy`), and no more than three a day (`429`, `Retry-After`). If even one section fails to build, there is no archive at all (`failed`): an incomplete file that looks complete is worse than a refusal.",
    "security": [
     {
      "sessionCookie": []
     }
    ],
    "parameters": [
     {
      "$ref": "#/components/parameters/IdempotencyKey"
     }
    ],
    "responses": {
     "202": {
      "description": "The build has started.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "export": {
           "$ref": "#/components/schemas/AccountExport"
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "No valid session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "Your role doesn't allow this action: export is for the workspace owner only, and only with a session (not with a key).",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Archive export isn’t available in this build.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "409": {
      "description": "An archive for this workspace is already being built (`export_busy`).",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "429": {
      "description": "An archive has already been built three times today. `Retry-After` says how long to wait.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "500": {
      "description": "The build did not start.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/dashboard/exports/{eid}": {
   "delete": {
    "tags": [
     "Dashboard · Agents"
    ],
    "summary": "Erase an archive",
    "description": "Erases an archive before it expires — or removes the row for a failed or expired one from the list. An archive that is being built can't be erased (409): wait until the build finishes. An erased archive disappears from the list but still counts toward the \"three archives a day\" limit.",
    "security": [
     {
      "sessionCookie": []
     }
    ],
    "parameters": [
     {
      "name": "eid",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "The archive ID."
     },
     {
      "$ref": "#/components/parameters/IdempotencyKey"
     }
    ],
    "responses": {
     "200": {
      "description": "Erased.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "status": {
           "type": "string",
           "description": "",
           "enum": [
            "deleted"
           ]
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "No valid session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "Your role doesn't allow this action: export is for the workspace owner only, and only with a session (not with a key).",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "There is no such archive in this workspace, or export isn't available in this build.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "409": {
      "description": "The archive is still being built (`export_busy`) — it can be erased once the build finishes.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "500": {
      "description": "Not erased.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/dashboard/exports/{eid}/download": {
   "get": {
    "tags": [
     "Dashboard · Agents"
    ],
    "summary": "Download an archive",
    "description": "Returns the finished archive as a ZIP file (`Content-Disposition: attachment`). Access is by the owner's session cookie, so the URL can be given to the browser as an ordinary link.",
    "security": [
     {
      "sessionCookie": []
     }
    ],
    "parameters": [
     {
      "name": "eid",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "The archive ID."
     }
    ],
    "responses": {
     "200": {
      "description": "The archive file.",
      "content": {
       "application/zip": {
        "schema": {
         "type": "string",
         "format": "binary"
        }
       }
      }
     },
     "401": {
      "description": "No valid session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "Your role doesn't allow this action: export is for the workspace owner only, and only with a session (not with a key).",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "There is no such archive in this workspace, or export isn't available in this build.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "409": {
      "description": "The archive is still being built.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "410": {
      "description": "The file is gone (`export_gone`): it expired, or the archive failed to build.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "500": {
      "description": "The archive could not be read.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/billing/open": {
   "get": {
    "tags": [
     "Billing"
    ],
    "summary": "Open payments",
    "description": "Payments the owner started and didn't finish: an invoice for a plan (at most one) and invoices for credit packs (at most one per pack). While a payment is here, the \"Buy\" button leads to the same checkout.",
    "security": [
     {
      "sessionCookie": []
     }
    ],
    "responses": {
     "200": {
      "description": "Open payments; an empty list means nothing is open.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "required": [
          "orders"
         ],
         "properties": {
          "orders": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/OpenPayment"
           }
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "No valid session — log in again.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The current user's role doesn't allow this action.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/billing/checkout/cancel": {
   "post": {
    "tags": [
     "Billing"
    ],
    "summary": "Cancel a payment attempt",
    "description": "Closes an unfinished invoice: it can no longer be credited. The payment gateway page can't be closed, so if someone still pays on it, the money is refunded automatically. Before cancelling, the platform asks the gateway: an invoice that has already been paid is not cancelled but credited (`canceled: false`, `state: active`).",
    "security": [
     {
      "sessionCookie": []
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "order_id": {
          "type": "string"
         }
        },
        "required": [
         "order_id"
        ]
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "The invoice state after the action.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "required": [
          "canceled",
          "state"
         ],
         "properties": {
          "canceled": {
           "type": "boolean",
           "description": "`true` — the attempt was cancelled. `false` — the invoice was no longer open."
          },
          "state": {
           "type": "string",
           "description": "Invoice state: canceled, active, failed, expired, refunding, refunded, refund_failed."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "You have no such invoice.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "description": "No valid session — log in again.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The current user's role doesn't allow this action.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/pages/reread": {
   "post": {
    "tags": [
     "Dashboard · Knowledge"
    ],
    "summary": "Re-read knowledge from URLs now",
    "description": "Without waiting for the schedule. With `source_id` — a single page, and the response comes right away: what happened to it. Without a body (or without `source_id`) — everything the agent took from websites: sites read in full are crawled again, and pages added one by one are fetched exactly as they are; this takes minutes, so the response is `202`, and the summary is read via `GET …/scrape`. Unchanged content isn't re-read. Re-reading doesn't overwrite a person's edit — only with `take_site`.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     }
    ],
    "requestBody": {
     "required": false,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "source_id": {
          "type": "string",
          "description": "The page — the source ID from the knowledge list (its URL). Without it, everything is re-read."
         },
         "take_site": {
          "type": "boolean",
          "description": "Discard the person's edit and take the text from the website. Only together with `source_id`."
         }
        }
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "The page was re-read (`status: done`).",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/RereadResult"
        }
       }
      }
     },
     "202": {
      "description": "Re-reading everything has started (`status: scanning`); the state is at `GET …/scrape`.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/RereadResult"
        }
       }
      }
     },
     "400": {
      "description": "The body couldn't be parsed, or `take_site` was sent without `source_id`.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "description": "No valid session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The role doesn't allow this action.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Agent not found, or the source wasn't read from a URL — there's nowhere to re-read it from.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "409": {
      "description": "A site read for this agent is already in progress.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "502": {
      "description": "The page couldn't be read; the reason is in `error`.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/pages": {
   "put": {
    "tags": [
     "Dashboard · Knowledge"
    ],
    "summary": "Decide about a single page",
    "description": "Whether to keep re-reading the page on schedule (`refresh`) and whether to keep your own edit when the page on the website has changed (`keep_mine`). Requires the admin role: this is about what the platform will do on its own from now on. To turn off re-reading of a whole site — `PUT …/site-plans` with `every_days: 0`.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "required": [
         "source_id"
        ],
        "properties": {
         "source_id": {
          "type": "string",
          "description": "The page — the source ID from the knowledge list (its URL)."
         },
         "refresh": {
          "type": "boolean",
          "description": "`false` — stop re-reading this page; `true` — turn it back on. Not set — don't change."
         },
         "keep_mine": {
          "type": "boolean",
          "description": "`true` — keep the person's edit and clear the \"Changed on the website\" flag."
         }
        }
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Saved.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "page": {
           "$ref": "#/components/schemas/SourcePage"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "No page named, or nothing said about what to change. Nothing was changed.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "description": "No valid session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The role doesn't allow this action.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Agent not found, or the source wasn't read from a URL.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/notices": {
   "get": {
    "tags": [
     "Dashboard · Notifications"
    ],
    "summary": "Where requests and digests are delivered",
    "operationId": "getNotices",
    "description": "Where a customer's request for a human (other than the dashboard's \"Conversations\") and the owner's digest will be delivered — **computed by the same code that sends them**: a \"where\" answer built separately from delivery would promise routes that don't exist.\n\nAn empty `calls.where` means nobody will learn about a request outside the dashboard — and that's exactly what the dashboard tells the person, plainly, with a suggestion to link a messenger chat or give an email.\n\n`calls.mail` is about the caller: the owner gets emails at the account address by default; a team member turns them on for themselves (`PUT …/notices/mail`).",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     }
    ],
    "responses": {
     "200": {
      "description": "Notification routes.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Notices"
        }
       }
      }
     },
     "401": {
      "description": "No valid session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The role doesn't allow this action.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Agent not found.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "500": {
      "description": "Could not read where notifications are delivered.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/notices/mail": {
   "put": {
    "tags": [
     "Dashboard · Notifications"
    ],
    "summary": "Request emails for yourself",
    "operationId": "setCallMail",
    "description": "The caller turns emails about customers' requests for a human on or off **for themselves** — to their own account address. Available to every team member: it's their mail, and answering requests is their job.\n\nFor the workspace owner, this is the same switch as `handoff_mail` in the agent settings.\n\nThe email carries the latest messages of the conversation, a link to it in the dashboard, and a \"stop sending\" link. If the agent has a mailbox it reads itself, a reply to the email goes to the customer on behalf of the operator.",
    "security": [
     {
      "sessionCookie": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "required": [
         "on"
        ],
        "properties": {
         "on": {
          "type": "boolean",
          "description": "`true` — send, `false` — don't."
         }
        }
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Saved.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "required": [
          "address",
          "on"
         ],
         "properties": {
          "address": {
           "type": "string",
           "description": "The address the emails will go to."
          },
          "on": {
           "type": "boolean"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "Not said whether to send or not, or the request has an unknown field.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "description": "No valid session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The role doesn't allow this action.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Agent not found, or this build has no email.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "409": {
      "description": "There's nowhere to send the emails: platform mail isn't configured, or the account address is unknown.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "500": {
      "description": "Could not save.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/dashboard/bots/{id}/digest/send": {
   "post": {
    "tags": [
     "Dashboard · Notifications"
    ],
    "summary": "Send the digest now",
    "operationId": "sendDigest",
    "description": "Sends the owner the digest without waiting for the schedule: the customers' most frequent questions that the agent's knowledge has no answer to, and everything waiting for a person (requests, permission requests, agent questions, drafts under review, incidents). This doesn't shift the schedule.\n\nThe digest is put together by the platform with rules, from the same records the dashboard shows: **it is not a model run and costs no credits**.\n\n`409 digest_empty` — there's nothing to say (there's no such thing as an empty digest); `409 digest_nowhere` — there's nowhere to send it: there's neither a linked messenger chat nor email.",
    "security": [
     {
      "sessionCookie": []
     },
     {
      "apiKeyAuth": []
     }
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Agent ID."
     }
    ],
    "responses": {
     "200": {
      "description": "Sent.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "required": [
          "sent"
         ],
         "properties": {
          "sent": {
           "type": "array",
           "items": {
            "type": "string"
           },
           "description": "Where the digest went, in words."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "No valid session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "Admin rights required.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Agent not found, or this build has no digest.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "409": {
      "description": "Nothing to say (`digest_empty`) or nowhere to send it (`digest_nowhere`).",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "500": {
      "description": "Could not send.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/notices/off": {
   "get": {
    "tags": [
     "Dashboard · Notifications"
    ],
    "summary": "The \"turn off emails\" page",
    "operationId": "noticeOffPage",
    "security": [],
    "description": "The page opened by the \"stop sending\" link in an email (a digest or a request email): it says what exactly will be turned off and has a single button. Opening it turns nothing off by itself — mail scanners open links on their own.",
    "parameters": [
     {
      "name": "t",
      "in": "query",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "A signed token from the link in the email: it tells what exactly is being turned off, and for whom."
     }
    ],
    "responses": {
     "200": {
      "description": "HTML page.",
      "content": {
       "text/html": {
        "schema": {
         "type": "string"
        }
       }
      }
     },
     "404": {
      "description": "The link is outdated or broken."
     }
    }
   },
   "post": {
    "tags": [
     "Dashboard · Notifications"
    ],
    "summary": "Turn off emails via the link from an email",
    "operationId": "noticeOff",
    "security": [],
    "description": "Turns off the emails named by the token: the owner's digest, request emails to the owner or to a team member. The mail client's \"Unsubscribe\" button sends the same request (the `List-Unsubscribe` header, RFC 8058) — without any page. To turn them back on — in the dashboard.",
    "parameters": [
     {
      "name": "t",
      "in": "query",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "A signed token from the link in the email: it tells what exactly is being turned off, and for whom."
     }
    ],
    "responses": {
     "200": {
      "description": "HTML page.",
      "content": {
       "text/html": {
        "schema": {
         "type": "string"
        }
       }
      }
     },
     "404": {
      "description": "The link is outdated or broken."
     },
     "500": {
      "description": "Could not turn off."
     }
    }
   }
  },
  "/v1/files/{token}": {
   "get": {
    "tags": [
     "Widget"
    ],
    "summary": "A conversation file via a temporary link",
    "description": "Returns a file that the other party attached in the conversation, via a temporary signed link. The platform passes such links to the owner's system: to actions with an `in: files` parameter and `files_as: link`, and to a connected service's tool (MCP). The link is valid for a day and can be opened any number of times; no key is needed — the link itself is the pass. The file is served as a download (`Content-Disposition: attachment`) with its own type.",
    "security": [],
    "parameters": [
     {
      "name": "token",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "The signed token from the link."
     }
    ],
    "responses": {
     "200": {
      "description": "The file contents.",
      "content": {
       "application/octet-stream": {
        "schema": {
         "type": "string",
         "format": "binary"
        }
       }
      }
     },
     "404": {
      "description": "The link is invalid, or the file has already been erased.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "410": {
      "description": "The link has expired.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   },
   "head": {
    "tags": [
     "Widget"
    ],
    "summary": "Whether the file is still available via the link",
    "description": "The same as `GET`, without a body: headers with the file type and name. Systems that fetch files often ask this way first.",
    "security": [],
    "parameters": [
     {
      "name": "token",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "The signed token from the link."
     }
    ],
    "responses": {
     "200": {
      "description": "The file is available."
     },
     "404": {
      "description": "The link is invalid, or the file has already been erased."
     },
     "410": {
      "description": "The link has expired."
     }
    }
   }
  },
  "/v1/platform/spend": {
   "get": {
    "tags": [
     "Platform"
    ],
    "summary": "Model spending across all workspaces",
    "description": "A summary for the platform owner: how many model tokens each workspace, each agent and each kind of run consumed, what that costs at the model's rates, and the most expensive runs. The totals come from the run log; they include Builder runs, for which no credits are charged, erased conversations (as totals only), service model calls and test accounts.\n\nOnly a person whose confirmed address is listed in the `PLATFORM_ADMINS` server setting can see it. For everyone else this URL doesn't exist (404).",
    "security": [
     {
      "sessionCookie": []
     }
    ],
    "parameters": [
     {
      "name": "days",
      "in": "query",
      "required": false,
      "schema": {
       "type": "integer",
       "minimum": 1,
       "maximum": 180,
       "default": 30
      },
      "description": "How many days to show, including today."
     }
    ],
    "responses": {
     "200": {
      "description": "The summary.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/SpendReport"
        }
       }
      }
     },
     "400": {
      "description": "`days` is out of range.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "description": "No valid session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "The person isn't on the platform list.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "503": {
      "description": "The run log could not be read.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "Request made with a key, not a human session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/widget/tool-result": {
   "post": {
    "tags": [
     "Widget"
    ],
    "summary": "Page tool result",
    "description": "The page returns what its handler returned for a `client_tool` stream frame. `result` is any JSON value (the model sees a string as is, anything else as JSON; up to 64 KB); `error` is what went wrong (the model will hear that nothing was done). The call belongs to the conversation and the agent in whose stream it arrived; a different or already closed one — 404.",
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "required": [
         "call_id",
         "session_id"
        ],
        "properties": {
         "call_id": {
          "type": "string"
         },
         "session_id": {
          "type": "string"
         },
         "result": {
          "description": "What the handler returned."
         },
         "error": {
          "type": "string",
          "description": "Why the handler didn't run (up to 300 characters)."
         }
        }
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Accepted.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "required": [
          "status"
         ],
         "properties": {
          "status": {
           "type": "string"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "The body can't be read.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "description": "No key.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "Wrong key type, or another site's page.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "There’s no such call, or it’s no longer being waited for.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "429": {
      "description": "Too many requests.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "503": {
      "$ref": "#/components/responses/Unavailable"
     }
    },
    "security": [
     {
      "widgetKey": []
     }
    ],
    "parameters": [
     {
      "name": "X-Bot-Key",
      "in": "header",
      "required": true,
      "schema": {
       "type": "string",
       "example": "pk_…"
      },
      "description": "The agent's publishable key."
     }
    ]
   }
  },
  "/v1/platform/users": {
   "get": {
    "tags": [
     "Platform"
    ],
    "summary": "All platform accounts",
    "description": "The list of accounts for a platform person, with search by address, a filter and a sort order. Only a person whose confirmed address is listed in `PLATFORM_ADMINS` can see it; for everyone else this URL doesn't exist (404).",
    "security": [
     {
      "sessionCookie": []
     }
    ],
    "parameters": [
     {
      "name": "q",
      "in": "query",
      "required": false,
      "schema": {
       "type": "string"
      },
      "description": "Part of an email address, case-insensitive."
     },
     {
      "name": "offset",
      "in": "query",
      "required": false,
      "schema": {
       "type": "integer",
       "minimum": 0
      },
      "description": "How many to skip (a page is 50)."
     },
     {
      "name": "filter",
      "in": "query",
      "required": false,
      "schema": {
       "type": "string",
       "enum": [
        "all",
        "paying",
        "granted",
        "testers",
        "test",
        "blocked",
        "closing",
        "unconfirmed"
       ],
       "default": "all"
      },
      "description": "paying — has a current paid subscription; granted — a current plan granted without payment; testers — testers; test — test accounts; blocked — blocked; closing — being deleted; unconfirmed — email not confirmed."
     },
     {
      "name": "sort",
      "in": "query",
      "required": false,
      "schema": {
       "type": "string",
       "enum": [
        "registered",
        "last_active",
        "paid",
        "spend",
        "agents"
       ],
       "default": "registered"
      },
      "description": "registered — newest sign-ups first; the rest — larger values first."
     }
    ],
    "responses": {
     "200": {
      "description": "A page of the list.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/PlatformUsers"
        }
       }
      }
     },
     "401": {
      "description": "No valid session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "The person isn't on the platform list.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "503": {
      "description": "The list could not be read.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "Request made with a key, not a human session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "400": {
      "description": "Unknown filter or sort order.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/platform/activity": {
   "get": {
    "tags": [
     "Platform"
    ],
    "summary": "Activity: all runs in all workspaces",
    "description": "Visitor conversations, Builder runs, background runs and rehearsals in all workspaces, newest first, 30 per page: what woke the run, what the agent answered, how many tools it called and how many of them failed. Only a person whose confirmed address is listed in `PLATFORM_ADMINS` can see it; for everyone else this URL doesn't exist (404).",
    "security": [
     {
      "sessionCookie": []
     }
    ],
    "parameters": [
     {
      "name": "kind",
      "in": "query",
      "required": false,
      "schema": {
       "type": "string",
       "enum": [
        "all",
        "visitor",
        "builder",
        "background",
        "rehearsal"
       ],
       "default": "all"
      },
      "description": "Run kind."
     },
     {
      "name": "q",
      "in": "query",
      "required": false,
      "schema": {
       "type": "string"
      },
      "description": "Part of the workspace owner's email, case-insensitive."
     },
     {
      "name": "agent",
      "in": "query",
      "required": false,
      "schema": {
       "type": "string"
      },
      "description": "Only this agent's runs."
     },
     {
      "name": "errors",
      "in": "query",
      "required": false,
      "schema": {
       "type": "string",
       "enum": [
        "1"
       ]
      },
      "description": "`1` — only runs that failed, or that have at least one failed tool."
     },
     {
      "name": "before",
      "in": "query",
      "required": false,
      "schema": {
       "type": "string"
      },
      "description": "Cursor: `next` from the previous page."
     }
    ],
    "responses": {
     "200": {
      "description": "A page of the list.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/PlatformActivity"
        }
       }
      }
     },
     "400": {
      "description": "Unknown kind of flows.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "description": "No valid session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "Request made with a key, not a human session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "The person isn't on the platform list.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "503": {
      "description": "The run log or the email search could not be read.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/platform/activity/{runID}": {
   "get": {
    "tags": [
     "Platform"
    ],
    "summary": "Activity: one run in full",
    "description": "The log row, the trace (every step, and for tool calls — what the model called them with and what they returned, with keys hidden), and the whole conversation of this run's thread, each message with the run it belongs to. Every opening goes into the server log: which platform person opened which run.",
    "security": [
     {
      "sessionCookie": []
     }
    ],
    "parameters": [
     {
      "name": "runID",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "The run ID (run_…)."
     }
    ],
    "responses": {
     "200": {
      "description": "The run in full.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/ActivityDetail"
        }
       }
      }
     },
     "401": {
      "description": "No valid session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "Request made with a key, not a human session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "There's no such run, or the person isn't on the platform list.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "503": {
      "description": "The run log could not be read.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/platform/users/{uid}/entry": {
   "post": {
    "tags": [
     "Platform"
    ],
    "summary": "One-time sign-in link to an account",
    "description": "A platform person gets a link that opens a session in account `uid`: it is valid for 10 minutes and once, the session behind it lasts an hour, and in it you can't change the password or email, delete the account, or sign out on all devices. Not into your own account and not into another platform person's. Every issue and every sign-in goes into the server log.",
    "security": [
     {
      "sessionCookie": []
     }
    ],
    "parameters": [
     {
      "name": "uid",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      }
     }
    ],
    "responses": {
     "200": {
      "description": "The link.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/AdminEntryLink"
        }
       }
      }
     },
     "400": {
      "description": "This is your own account.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "description": "No valid session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "Another platform person's account.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "The person isn't on the platform list, or there's no such user.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "409": {
      "description": "The account is being deleted.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "503": {
      "description": "Could not issue the link.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/auth/admin-entry": {
   "post": {
    "tags": [
     "Authentication"
    ],
    "summary": "Sign in via a platform person's link",
    "description": "Uses up the one-time link and sets the session cookie of the account it led to. No session is needed for this: the link is the permission.",
    "security": [],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "required": [
         "token"
        ],
        "properties": {
         "token": {
          "type": "string",
          "description": "The part of the link after \"#\"."
         }
        }
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Signed in; the session cookie is set.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "status": {
           "type": "string",
           "enum": [
            "ok"
           ]
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "The link is incomplete.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "This build has no admin sign-in.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "410": {
      "description": "The link has already been used, or it has expired.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "503": {
      "description": "Could not sign in.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/platform/users/{uid}/plan": {
   "post": {
    "tags": [
     "Platform"
    ],
    "summary": "Grant an account a plan without payment",
    "description": "A platform person grants account `uid` a plan for `days` days without payment; `free` revokes the grant. The grant doesn't renew and doesn't touch paid subscriptions: the best limits among the current ones apply. Every change goes into the server log.",
    "security": [
     {
      "sessionCookie": []
     }
    ],
    "parameters": [
     {
      "name": "uid",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      }
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "required": [
         "plan"
        ],
        "properties": {
         "plan": {
          "type": "string",
          "description": "The plan ID (`starter`, `pro`, `business`) or `free` — revoke the granted one."
         },
         "days": {
          "type": "integer",
          "minimum": 0,
          "maximum": 3660,
          "description": "For how many days; 0 — 30."
         }
        }
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "The plan after the change.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/PlanGrant"
        }
       }
      }
     },
     "400": {
      "description": "There's no such plan, the term is negative or longer than 3660 days, or the body can't be parsed.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "description": "No valid session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "Request made with a key, not a human session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "The person isn't on the platform list, or there's no such user.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "503": {
      "description": "Could not change the plan.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/platform/users/{uid}/tester": {
   "post": {
    "tags": [
     "Platform"
    ],
    "summary": "Mark an account as a tester",
    "description": "A tester picks any plan for themselves without payment (`POST /v1/billing/tester/plan`). Removing the mark revokes the granted plan.",
    "security": [
     {
      "sessionCookie": []
     }
    ],
    "parameters": [
     {
      "name": "uid",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      }
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "required": [
         "tester"
        ],
        "properties": {
         "tester": {
          "type": "boolean"
         }
        }
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Saved.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "tester": {
           "type": "boolean"
          },
          "user": {
           "$ref": "#/components/schemas/PlatformUser",
           "description": "The updated list row (absent — it couldn't be re-read)."
          }
         },
         "required": [
          "tester"
         ]
        }
       }
      }
     },
     "400": {
      "description": "The body can't be parsed.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "description": "No valid session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "Request made with a key, not a human session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "The person isn't on the platform list, or there's no such user.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "503": {
      "description": "Could not save.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/platform/testers": {
   "post": {
    "tags": [
     "Platform"
    ],
    "summary": "Create a tester account",
    "description": "A new account, marked as a tester right away. Without `password`, a password is generated and returned once — in this response. `plan` — grant a plan right away.",
    "security": [
     {
      "sessionCookie": []
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "required": [
         "email"
        ],
        "properties": {
         "email": {
          "type": "string"
         },
         "password": {
          "type": "string"
         },
         "plan": {
          "type": "string"
         }
        }
       }
      }
     }
    },
    "responses": {
     "201": {
      "description": "The account was created.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "required": [
          "id",
          "email",
          "tester"
         ],
         "properties": {
          "id": {
           "type": "string"
          },
          "email": {
           "type": "string"
          },
          "tester": {
           "type": "boolean"
          },
          "password": {
           "type": "string",
           "description": "The generated password — only here and only once."
          },
          "plan": {
           "type": "string"
          },
          "until": {
           "type": "string",
           "format": "date-time"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "No email, a malformed email, or the password is too short.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "description": "No valid session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "Request made with a key, not a human session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "The person isn't on the platform list.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "409": {
      "description": "An account with this email already exists.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "503": {
      "description": "Could not create.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/billing/tester": {
   "get": {
    "tags": [
     "Billing"
    ],
    "summary": "Whether the person is a tester",
    "description": "A tester picks any plan for themselves without payment.",
    "security": [
     {
      "sessionCookie": []
     }
    ],
    "responses": {
     "200": {
      "description": "Status.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "required": [
          "tester"
         ],
         "properties": {
          "tester": {
           "type": "boolean"
          },
          "plan": {
           "type": "string"
          },
          "days": {
           "type": "integer",
           "description": "For how many days the plan is granted if no term is given."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "No valid session — log in again.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "The current user's role doesn't allow this action.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "503": {
      "description": "Could not read.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/billing/tester/plan": {
   "post": {
    "tags": [
     "Billing"
    ],
    "summary": "A tester picks a plan for themselves",
    "description": "Testers only: a plan without payment for `days` days (0 — 30); `free` revokes it.",
    "security": [
     {
      "sessionCookie": []
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "required": [
         "plan"
        ],
        "properties": {
         "plan": {
          "type": "string",
          "description": "The plan ID (`starter`, `pro`, `business`) or `free` — revoke the granted one."
         },
         "days": {
          "type": "integer",
          "minimum": 0,
          "maximum": 3660,
          "description": "For how many days; 0 — 30."
         }
        }
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "The plan after the change.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/PlanGrant"
        }
       }
      }
     },
     "400": {
      "description": "There's no such plan, the term is negative or longer than 3660 days, or the body can't be parsed.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "description": "No valid session — log in again.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "Not a tester, or the role doesn't allow it.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "503": {
      "description": "Could not change the plan.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/platform/users/{uid}/block": {
   "post": {
    "tags": [
     "Platform"
    ],
    "summary": "Block an account or lift the block",
    "description": "A block shuts sign-in (password and shared sign-in say the account is blocked), ends all sessions, recovery emails and an unfinished email change. Agent keys stay: the agents keep answering customers, but neither a session nor a key can manage the dashboard. A platform person can't be blocked (403). The action goes into the platform people's action log.",
    "security": [
     {
      "sessionCookie": []
     }
    ],
    "parameters": [
     {
      "name": "uid",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      }
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "blocked": {
          "type": "boolean"
         },
         "reason": {
          "type": "string",
          "description": "Why — up to 500 characters; only platform people see it."
         }
        },
        "required": [
         "blocked"
        ]
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Done.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/PlatformUserChange"
        }
       }
      }
     },
     "401": {
      "description": "No valid session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "Request made with a key, not a human session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "The person isn't on the platform list, or there's no such user.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "503": {
      "description": "Storage didn't respond — the action wasn't performed or couldn't be read back.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "400": {
      "description": "Not specified whether to block or not.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/platform/users/{uid}/test": {
   "post": {
    "tags": [
     "Platform"
    ],
    "summary": "Mark an account as a test account",
    "description": "A test account isn't counted in the spending summary or the platform overview. The mark changes nothing else. The action goes into the platform people's action log.",
    "security": [
     {
      "sessionCookie": []
     }
    ],
    "parameters": [
     {
      "name": "uid",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      }
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "test": {
          "type": "boolean"
         }
        },
        "required": [
         "test"
        ]
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Done.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/PlatformUserChange"
        }
       }
      }
     },
     "401": {
      "description": "No valid session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "Request made with a key, not a human session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "The person isn't on the platform list, or there's no such user.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "503": {
      "description": "Storage didn't respond — the action wasn't performed or couldn't be read back.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "400": {
      "description": "Not specified whether it's a test account or not.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/platform/users/{uid}/credits": {
   "post": {
    "tags": [
     "Platform"
    ],
    "summary": "Add or take away credits",
    "description": "Credits go onto the same prepaid balance of the person's own workspace as purchased packs. A negative number takes credits away — not below zero (`applied` says how many were taken). The action goes into the platform people's action log.",
    "security": [
     {
      "sessionCookie": []
     }
    ],
    "parameters": [
     {
      "name": "uid",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      }
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "credits": {
          "type": "integer",
          "description": "Positive — add, negative — take away; not 0, absolute value up to 10,000,000."
         },
         "note": {
          "type": "string",
          "description": "Why — goes into the action log."
         }
        },
        "required": [
         "credits"
        ]
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Done.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/PlatformUserChange"
        }
       }
      }
     },
     "401": {
      "description": "No valid session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "Request made with a key, not a human session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "The person isn't on the platform list, or there's no such user.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "503": {
      "description": "Storage didn't respond — the action wasn't performed or couldn't be read back.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "400": {
      "description": "The amount is missing, zero or too large.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "409": {
      "description": "There's no own workspace yet.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/platform/users/{uid}/confirm-email": {
   "post": {
    "tags": [
     "Platform"
    ],
    "summary": "Mark the email as confirmed",
    "description": "Without an email: when the build has no mail, there's no other way to confirm the address. Already confirmed isn't an error. The action goes into the platform people's action log.",
    "security": [
     {
      "sessionCookie": []
     }
    ],
    "parameters": [
     {
      "name": "uid",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      }
     }
    ],
    "responses": {
     "200": {
      "description": "Done.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/PlatformUserChange"
        }
       }
      }
     },
     "401": {
      "description": "No valid session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "Request made with a key, not a human session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "The person isn't on the platform list, or there's no such user.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "503": {
      "description": "Storage didn't respond — the action wasn't performed or couldn't be read back.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/platform/users/{uid}/password-link": {
   "post": {
    "tags": [
     "Platform"
    ],
    "summary": "Password setup link",
    "description": "A one-time link — the same permission as in a recovery email (valid for the same time, and it ends all sessions once the password is set), but handed to the platform person: there may be no mail. Shown once. The action goes into the platform people's action log.",
    "security": [
     {
      "sessionCookie": []
     }
    ],
    "parameters": [
     {
      "name": "uid",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      }
     }
    ],
    "responses": {
     "200": {
      "description": "Done.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/PlatformUserChange"
        }
       }
      }
     },
     "401": {
      "description": "No valid session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "Request made with a key, not a human session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "The person isn't on the platform list, or there's no such user.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "503": {
      "description": "Storage didn't respond — the action wasn't performed or couldn't be read back.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "409": {
      "description": "The account is being deleted.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/platform/users/{uid}/logout": {
   "post": {
    "tags": [
     "Platform"
    ],
    "summary": "End all sessions",
    "description": "\"Sign out everywhere\" on the person's behalf: all their sessions end, sign-in remains possible. The action goes into the platform people's action log.",
    "security": [
     {
      "sessionCookie": []
     }
    ],
    "parameters": [
     {
      "name": "uid",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      }
     }
    ],
    "responses": {
     "200": {
      "description": "Done.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/PlatformUserChange"
        }
       }
      }
     },
     "401": {
      "description": "No valid session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "Request made with a key, not a human session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "The person isn't on the platform list, or there's no such user.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "503": {
      "description": "Storage didn't respond — the action wasn't performed or couldn't be read back.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/platform/users/{uid}/note": {
   "post": {
    "tags": [
     "Platform"
    ],
    "summary": "Account note",
    "description": "A platform person's note (up to 4,000 characters); only platform people see it. Empty — erase it. Only its length goes into the action log. The action goes into the platform people's action log.",
    "security": [
     {
      "sessionCookie": []
     }
    ],
    "parameters": [
     {
      "name": "uid",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      }
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "note": {
          "type": "string"
         }
        },
        "required": [
         "note"
        ]
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Done.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/PlatformUserChange"
        }
       }
      }
     },
     "401": {
      "description": "No valid session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "Request made with a key, not a human session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "The person isn't on the platform list, or there's no such user.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "503": {
      "description": "Storage didn't respond — the action wasn't performed or couldn't be read back.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "400": {
      "description": "The body has no note.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/platform/users/{uid}/delete": {
   "post": {
    "tags": [
     "Platform"
    ],
    "summary": "Start account deletion",
    "description": "The same path as when the person does it themselves: unfinished payments and subscription renewal are cancelled, the workspace is stopped, the \"change your mind\" window is the same. The confirmation is the account's email. A platform person can't be deleted from here (403). The action goes into the platform people's action log.",
    "security": [
     {
      "sessionCookie": []
     }
    ],
    "parameters": [
     {
      "name": "uid",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      }
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "confirm": {
          "type": "string",
          "description": "The account's email."
         }
        },
        "required": [
         "confirm"
        ]
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Done.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/PlatformUserChange"
        }
       }
      }
     },
     "401": {
      "description": "No valid session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "Request made with a key, not a human session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "The person isn't on the platform list, or there's no such user.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "503": {
      "description": "Storage didn't respond — the action wasn't performed or couldn't be read back.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "400": {
      "description": "The email wasn't entered or doesn't match.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "409": {
      "description": "The account is already being deleted.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "502": {
      "description": "The payment service didn't cancel the payment — the account was not deleted.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/platform/users/{uid}/restore": {
   "post": {
    "tags": [
     "Platform"
    ],
    "summary": "Cancel account deletion",
    "description": "Restores the account and agents while the \"change your mind\" window hasn't passed. The action goes into the platform people's action log.",
    "security": [
     {
      "sessionCookie": []
     }
    ],
    "parameters": [
     {
      "name": "uid",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      }
     }
    ],
    "responses": {
     "200": {
      "description": "Done.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/PlatformUserChange"
        }
       }
      }
     },
     "401": {
      "description": "No valid session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "Request made with a key, not a human session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "The person isn't on the platform list, or there's no such user.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "503": {
      "description": "Storage didn't respond — the action wasn't performed or couldn't be read back.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "409": {
      "description": "The account isn't being deleted.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/platform/audit": {
   "get": {
    "tags": [
     "Platform"
    ],
    "summary": "Platform people's action log",
    "description": "Every action a platform person takes on someone else's account — sign-in, plan, tester, block, credits, email, password, sessions, note, deletion, opening someone else's conversation or run, a database query. Newest first, 50 per page. The log outlives account erasure, but doesn't keep addresses.",
    "security": [
     {
      "sessionCookie": []
     }
    ],
    "parameters": [
     {
      "name": "admin",
      "in": "query",
      "required": false,
      "schema": {
       "type": "string"
      },
      "description": "A platform person's ID or address."
     },
     {
      "name": "target",
      "in": "query",
      "required": false,
      "schema": {
       "type": "string"
      },
      "description": "On whom: a person, a workspace or an agent."
     },
     {
      "name": "action",
      "in": "query",
      "required": false,
      "schema": {
       "type": "string"
      },
      "description": "One action (`all` — all)."
     },
     {
      "name": "before",
      "in": "query",
      "required": false,
      "schema": {
       "type": "string"
      },
      "description": "Cursor: `next` from the previous page."
     }
    ],
    "responses": {
     "200": {
      "description": "A page of the log.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/PlatformAudit"
        }
       }
      }
     },
     "401": {
      "description": "No valid session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "Request made with a key, not a human session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "The person isn't on the platform list.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "503": {
      "description": "Storage didn't respond — the action wasn't performed or couldn't be read back.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/platform/users/{uid}/dossier": {
   "get": {
    "tags": [
     "Platform"
    ],
    "summary": "Account dossier",
    "description": "How the person uses this particular service: the plan and all invoices, credits by day, workspaces with teams, agents (channels, knowledge, actions, triggers, runs, incidents), up to 100 latest conversations, keys (prefix only), live sessions, platform people's actions on them, and related accounts. What storage doesn't keep is in `unknown`, not made up.",
    "security": [
     {
      "sessionCookie": []
     }
    ],
    "parameters": [
     {
      "name": "uid",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      }
     }
    ],
    "responses": {
     "200": {
      "description": "The dossier.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/PlatformDossier"
        }
       }
      }
     },
     "401": {
      "description": "No valid session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "Request made with a key, not a human session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "The person isn't on the platform list, or there's no such user.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "503": {
      "description": "Storage didn't respond — the action wasn't performed or couldn't be read back.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/platform/conversations/{agent}/{session}": {
   "get": {
    "tags": [
     "Platform"
    ],
    "summary": "One conversation in full",
    "description": "The transcript (up to the 500 latest messages), this thread's runs and the handoff-to-a-human state. Opening is recorded in the action log BEFORE showing: not recorded — not shown (503).",
    "security": [
     {
      "sessionCookie": []
     }
    ],
    "parameters": [
     {
      "name": "agent",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "The agent; for a conversation with the Builder without an agent — `-`."
     },
     {
      "name": "session",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      }
     },
     {
      "name": "kind",
      "in": "query",
      "required": false,
      "schema": {
       "type": "string",
       "enum": [
        "visitor",
        "builder"
       ],
       "default": "visitor"
      }
     }
    ],
    "responses": {
     "200": {
      "description": "The conversation.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/PlatformConversation"
        }
       }
      }
     },
     "401": {
      "description": "No valid session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "Request made with a key, not a human session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "The person isn't on the platform list, or there's no such conversation.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "503": {
      "description": "Storage didn't respond — the action wasn't performed or couldn't be read back.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "400": {
      "description": "Unknown conversation kind.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/platform/overview": {
   "get": {
    "tags": [
     "Platform"
    ],
    "summary": "Platform overview",
    "description": "The command center: accounts (total, new and active over 7 days), agents, runs over the day and week (and how many failed), credits, payments over 30 days, open incidents by kind, runs in progress; health (like /readyz, plus database connections, background loops and the commit) and 30-day series. Test accounts are filtered out everywhere.",
    "security": [
     {
      "sessionCookie": []
     }
    ],
    "responses": {
     "200": {
      "description": "The overview.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/PlatformOverview"
        }
       }
      }
     },
     "401": {
      "description": "No valid session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "Request made with a key, not a human session.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "The person isn't on the platform list.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "503": {
      "description": "Storage didn't respond — the action wasn't performed or couldn't be read back.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  }
 },
 "components": {
  "securitySchemes": {
   "apiKeyAuth": {
    "type": "apiKey",
    "in": "header",
    "name": "X-Bot-Key",
    "description": "The bot's secret key (`sk_…`) from the YouSelfBot dashboard. Keep it on your backend — never expose it in the browser. The publishable key `pk_…` from the widget snippet doesn't work here: you'll get `403` `wrong_key_type`."
   },
   "sessionCookie": {
    "type": "apiKey",
    "in": "cookie",
    "name": "session",
    "description": "The dashboard's session cookie. Set on `POST /v1/auth/login` and valid on all of the product's subdomains. There is NO CSRF token header — and there's no need to look for an endpoint that issues one. A write from a browser is let through by origin: `Origin` must be one of the allowed frontends (or the request must be same-site — this is visible from `Sec-Fetch-Site`, which the browser sets itself). A call without `Origin` and without `Sec-Fetch-*` — that is, not from a browser — goes through: it has no ambient cookie. Another site gets `403`.\n\nThe same routes also accept the bot's secret key (`X-Bot-Key: sk_…`) — this is how the dashboard is used from code rather than from a browser. The key acts on behalf of the workspace owner, but with two limits: it works ONLY with its own agent (another agent's id returns `404`) and has no owner rights — money, team membership and agent deletion stay with the person who signed in. The publishable key `pk_…` doesn't work here at all."
   },
   "widgetKey": {
    "type": "apiKey",
    "in": "header",
    "name": "X-Bot-Key",
    "description": "The agent's publishable key (`pk_…`). Meant for the browser: on its own it only allows the conversation and reading the widget settings."
   },
   "agentKey": {
    "type": "http",
    "scheme": "bearer",
    "description": "An agent access key (`ak_…`) in the `Authorization: Bearer ak_…` header. Issued by the agent's owner — in the dashboard (agent panel → \"Access by other agents\") or in words in the Builder. The key works only for its own agent and grants visitor rights; `pk_`, `sk_` and `ck_` keys don't work here."
   },
   "constructorKey": {
    "type": "http",
    "scheme": "bearer",
    "description": "A builder key (`ck_…`) in the `Authorization: Bearer ck_…` header (or `X-Bot-Key: ck_…`). Created in the dashboard (Account → MCP) or via the browser sign-in at `/v1/mcp-pair`; it works for the whole workspace and manages agents through the Builder. `sk_`, `pk_` and `ak_` keys don't work here: you'll get `403` `wrong_key_type` or `401`."
   }
  },
  "schemas": {
   "PlatformLogEntry": {
    "type": "object",
    "required": [
     "seq",
     "at",
     "level",
     "msg"
    ],
    "properties": {
     "seq": {
      "type": "integer",
      "description": "The sequence number since the instance started."
     },
     "at": {
      "type": "string",
      "format": "date-time"
     },
     "level": {
      "type": "string",
      "enum": [
       "debug",
       "info",
       "warn",
       "error"
      ]
     },
     "msg": {
      "type": "string"
     },
     "attrs": {
      "type": "string",
      "description": "The entry's fields as a single \"key=value\" line; secrets are hidden."
     }
    }
   },
   "PlatformLog": {
    "type": "object",
    "required": [
     "entries",
     "last",
     "counts",
     "capacity",
     "started_at",
     "instance"
    ],
    "properties": {
     "entries": {
      "type": "array",
      "items": {
       "$ref": "#/components/schemas/PlatformLogEntry"
      }
     },
     "last": {
      "type": "integer",
      "description": "The number of the newest entry in the buffer — the cursor for the next `after`."
     },
     "counts": {
      "type": "object",
      "required": [
       "debug",
       "info",
       "warn",
       "error"
      ],
      "properties": {
       "debug": {
        "type": "integer"
       },
       "info": {
        "type": "integer"
       },
       "warn": {
        "type": "integer"
       },
       "error": {
        "type": "integer"
       }
      },
      "description": "How many entries of each level are in the buffer now."
     },
     "capacity": {
      "type": "integer"
     },
     "started_at": {
      "type": "string",
      "format": "date-time",
      "description": "When this instance started writing the log."
     },
     "instance": {
      "type": "string",
      "description": "The instance label: if it differs, the cursor belongs to another instance and the log is read from the start."
     }
    }
   },
   "DBTable": {
    "type": "object",
    "required": [
     "name",
     "rows_estimate",
     "bytes",
     "columns"
    ],
    "properties": {
     "name": {
      "type": "string"
     },
     "rows_estimate": {
      "type": "integer",
      "description": "The planner's estimate; -1 — the database hasn't counted yet."
     },
     "bytes": {
      "type": "integer",
      "description": "Including indexes and TOAST."
     },
     "columns": {
      "type": "integer"
     }
    }
   },
   "DBTables": {
    "type": "object",
    "required": [
     "tables"
    ],
    "properties": {
     "tables": {
      "type": "array",
      "items": {
       "$ref": "#/components/schemas/DBTable"
      }
     }
    }
   },
   "DBColumn": {
    "type": "object",
    "required": [
     "name",
     "type",
     "nullable",
     "pk",
     "masked"
    ],
    "properties": {
     "name": {
      "type": "string"
     },
     "type": {
      "type": "string"
     },
     "nullable": {
      "type": "boolean"
     },
     "default": {
      "type": "string"
     },
     "pk": {
      "type": "boolean",
      "description": "Part of the primary key."
     },
     "masked": {
      "type": "boolean",
      "description": "A column with a secret: the value is shown as `***`."
     }
    }
   },
   "DBPage": {
    "type": "object",
    "required": [
     "table",
     "columns",
     "rows",
     "total",
     "offset",
     "limit",
     "editable",
     "clipped",
     "hidden",
     "ms"
    ],
    "properties": {
     "table": {
      "type": "string"
     },
     "columns": {
      "type": "array",
      "items": {
       "$ref": "#/components/schemas/DBColumn"
      }
     },
     "rows": {
      "type": "array",
      "items": {
       "type": "array",
       "items": {
        "oneOf": [
         {
          "type": "string"
         },
         {
          "type": "null"
         }
        ]
       }
      }
     },
     "total": {
      "type": "integer",
      "description": "The exact row count; -1 — it couldn't be counted within 3 s."
     },
     "offset": {
      "type": "integer"
     },
     "limit": {
      "type": "integer"
     },
     "sort": {
      "type": "string"
     },
     "editable": {
      "type": "boolean",
      "description": "Cells can be edited from the viewer: there's a primary key, and it isn't hidden."
     },
     "clipped": {
      "type": "array",
      "items": {
       "type": "array",
       "description": "The cell position: [row, column], zero-based.",
       "items": {
        "type": "integer"
       },
       "minItems": 2,
       "maxItems": 2
      },
      "description": "Cells shown truncated."
     },
     "hidden": {
      "type": "array",
      "items": {
       "type": "array",
       "description": "The cell position: [row, column], zero-based.",
       "items": {
        "type": "integer"
       },
       "minItems": 2,
       "maxItems": 2
      },
      "description": "Cells whose text has a secret hidden in it."
     },
     "ms": {
      "type": "integer"
     }
    }
   },
   "DBQueryResult": {
    "type": "object",
    "required": [
     "write",
     "columns",
     "rows",
     "truncated",
     "affected",
     "clipped",
     "hidden",
     "ms"
    ],
    "properties": {
     "write": {
      "type": "boolean"
     },
     "columns": {
      "type": "array",
      "items": {
       "type": "object",
       "required": [
        "name",
        "type",
        "masked"
       ],
       "properties": {
        "name": {
         "type": "string"
        },
        "type": {
         "type": "string"
        },
        "masked": {
         "type": "boolean"
        }
       }
      }
     },
     "rows": {
      "type": "array",
      "items": {
       "type": "array",
       "items": {
        "oneOf": [
         {
          "type": "string"
         },
         {
          "type": "null"
         }
        ]
       }
      }
     },
     "truncated": {
      "type": "boolean",
      "description": "There were more than 500 rows."
     },
     "affected": {
      "type": "integer",
      "description": "How many rows the statement affected."
     },
     "command": {
      "type": "string",
      "description": "The Postgres command tag (\"SELECT 3\", \"UPDATE 1\")."
     },
     "clipped": {
      "type": "array",
      "items": {
       "type": "array",
       "description": "The cell position: [row, column], zero-based.",
       "items": {
        "type": "integer"
       },
       "minItems": 2,
       "maxItems": 2
      }
     },
     "hidden": {
      "type": "array",
      "items": {
       "type": "array",
       "description": "The cell position: [row, column], zero-based.",
       "items": {
        "type": "integer"
       },
       "minItems": 2,
       "maxItems": 2
      }
     },
     "ms": {
      "type": "integer"
     },
     "error": {
      "type": "string",
      "description": "The database's response to the query, if it failed."
     },
     "sqlstate": {
      "type": "string",
      "description": "The Postgres code for `error` (25006 — a write in READ ONLY)."
     }
    }
   },
   "DBCellResult": {
    "type": "object",
    "required": [
     "value",
     "statement"
    ],
    "properties": {
     "value": {
      "oneOf": [
       {
        "type": "string"
       },
       {
        "type": "null"
       }
      ]
     },
     "statement": {
      "type": "string",
      "description": "The executed statement (with $n parameters)."
     }
    }
   },
   "SessionID": {
    "type": "string",
    "description": "The conversation ID. Must be **unpredictable** and unique within the bot — UUIDv4 is recommended. Don't use a user id, email, order number or counters: predictable ids collide between your own users. Maximum 128 characters.",
    "examples": [
     "3f6c1b9e-7f42-4d2a-9a6f-0d5b1f0b21c7"
    ],
    "maxLength": 128
   },
   "ChatRequest": {
    "type": "object",
    "required": [
     "message"
    ],
    "properties": {
     "session_id": {
      "allOf": [
       {
        "$ref": "#/components/schemas/SessionID"
       }
      ],
      "description": "The conversation ID: the same throughout one dialog — that's how the bot remembers context. If you don't pass it, the server generates a random one and returns it in the response. Must be unpredictable (UUIDv4), not a user id."
     },
     "message": {
      "type": "string",
      "minLength": 1,
      "description": "The user's message. Empty → 400. Maximum 8,000 characters (characters are counted, not bytes) → 400.",
      "maxLength": 8000
     },
     "user_token": {
      "type": "string",
      "description": "The end user's identifier on your side — this is the place for your internal id (unlike `session_id`). Used for memory about the user and for substitution into skill calls; never sent to the LLM.\n\nThis field is NOT verified: it's simply passed to your own API, which authenticates it. So it grants no extra rights. If you need to give someone actions that regular visitors can't use, use `user_auth` below."
     },
     "user_auth": {
      "type": "string",
      "description": "Proof of the visitor's identity, produced by your server (see the \"Verifying visitor identity\" section in the API description). The only way to give a visitor actions marked \"admin only\".\n\nAn empty, expired, issued-for-another-bot or unverified value isn't an error: the visitor stays a regular one, and the conversation answers as usual."
     },
     "page_context": {
      "type": "string",
      "description": "A short description of the page/context the user is on right now (URL, product, price, specs). Gives the bot specific, contextual answers. At most 4,000 characters reach the model."
     },
     "escalate": {
      "type": "boolean",
      "description": "An explicit request for a live operator (the \"operator\" button). `true` → immediately queues a handoff; the response will have `handoff: true`."
     },
     "visitor_name": {
      "type": "string",
      "maxLength": 200,
      "description": "How to address the visitor, if your site knows it (the name from their personal account). Shown to the model as one short line — letters, space, hyphen, apostrophe, up to 40 characters; the rest is dropped.\n\nThis is a word for the greeting, not proof of identity: it grants no rights and isn't substituted into actions. That's what `user_token` and `user_auth` are for."
     },
     "about_products": {
      "type": "array",
      "maxItems": 3,
      "items": {
       "type": "string",
       "maxLength": 120
      },
      "description": "IDs of catalog products (`products[].id` from a previous response) this message is about: the visitor clicked \"Similar\" or \"Cheaper\" on a card, or marked two or three products and asked to compare them. Still write the product name in `message` — that's what the person will see in the conversation; by the ID, the server fetches the product itself from the agent's catalog and gives the assistant its price, availability and specs, so it doesn't guess by the name or compare from memory.\n\nThis is a hint, not the truth: an ID that isn't in this agent's catalog adds nothing. The first three are taken into account."
     },
     "context_values": {
      "type": "object",
      "description": "Values the site passed to `YouSelfBot.setContext({...})`: flat \"key — string, number or yes/no\" pairs (up to 20; key — Latin letters, digits, `_`, `-`). An owner action substitutes them into its request at `{{context.key}}` (URL, header, fixed body value); they aren't shown to the model. A header that expects a value the page didn't pass isn't sent.",
      "additionalProperties": {
       "oneOf": [
        {
         "type": "string"
        },
        {
         "type": "number"
        },
        {
         "type": "boolean"
        }
       ]
      }
     },
     "client_tools": {
      "type": "array",
      "maxItems": 20,
      "items": {
       "type": "string"
      },
      "description": "Names of the handlers the page has registered (`YouSelfBot.registerTool`). Only in a streaming request: the model gets a page tool when its name is here, and the call arrives as a `client_tool` frame."
     }
    }
   },
   "ChatResponse": {
    "type": "object",
    "required": [
     "answer",
     "session_id"
    ],
    "properties": {
     "answer": {
      "type": "string",
      "description": "The bot's answer. With `handoff: true`, it's the escalation confirmation or an **empty string** (an operator is already on the line — nothing to show). With `quota_exceeded: true`, it's placeholder text."
     },
     "session_id": {
      "allOf": [
       {
        "$ref": "#/components/schemas/SessionID"
       }
      ],
      "description": "The conversation ID (generated if you didn't pass one). Use it in subsequent requests."
     },
     "handoff": {
      "type": "boolean",
      "description": "Present and `true` → a live operator is handling the conversation or is awaited, and the bot is deliberately silent. Poll `GET /v1/api/messages`. Absent in a regular response."
     },
     "quota_exceeded": {
      "type": "boolean",
      "description": "Present and `true` → the monthly conversation limit is used up, and no new conversation was started. This is a `200`, not an error. Conversations already started keep working. Absent in a regular response."
     },
     "notice": {
      "type": "string",
      "enum": [
       "outage",
       "service",
       "review"
      ],
      "description": "Present and `\"outage\"` → this is NOT a bot message but a service message about a failure or an exhausted limit. Show it separately from answers (without 👍/👎 ratings) — otherwise the customer rates a malfunction. Absent in a regular response. Values may be added: treat an unknown one as a service message. `\"service\"` — a platform service message, not a failure (for example, \"This code was issued for a different bot, so it doesn't work here — and no longer works anywhere\"). `\"review\"` — the answer to this message is being prepared by the assistant and checked by a person (training mode): the text is a line for the customer, and the answer itself will arrive as a message via `GET /v1/api/messages`."
     },
     "suggestions": {
      "type": "array",
      "maxItems": 3,
      "items": {
       "type": "string"
      },
      "description": "Options for the next message that the assistant suggested under this answer: short phrases in the visitor's voice (\"For the office\", \"Show me others\"). Show them as buttons and send the tapped one as a regular `message`. The field is absent when there are no options or the owner turned them off."
     },
     "contacts": {
      "type": "boolean",
      "description": "`true` → the assistant can't help on its own and asks to show buttons for contacting the company's people (`contacts` from `GET /v1/widget/config`). The field is absent when no buttons need to be shown."
     },
     "products": {
      "type": "array",
      "maxItems": 6,
      "items": {
       "$ref": "#/components/schemas/ProductCard"
      },
      "description": "Catalog products the assistant recommends in this answer — show them as cards below it (photo, name as a link, price, availability). Only a product the assistant fetched from the agent's catalog in this run and linked to in the answer gets here; the server takes the card data from the catalog. The field is absent when the answer recommends no products, the agent has no catalog, or the owner kept recommendations as text (`widget_design.catalog_cards: false`)."
     },
     "review": {
      "type": "boolean",
      "description": "Present and `true` → training mode: a person checks the agent's answer first. `answer` is a line for the customer (\"the answer is prepared by the assistant and checked by a person\") or empty if the customer just heard it. The answer itself will arrive later as a message: poll `GET /v1/api/messages` while its `review` stays `true`. Absent in a regular response."
     },
     "actions": {
      "type": "array",
      "description": "What this run's actions show the person themselves (buttons, files) and hand to the page (the raw result). Absent if no action ran.",
      "items": {
       "$ref": "#/components/schemas/ActionOutcome"
      }
     }
    }
   },
   "StreamFrame": {
    "description": "One SSE frame — JSON in the `data:` field. Tell frames apart by which field is present (`delta` / `action` / `error` / `done`). The set of frame kinds may grow: **skip** a frame without any of the known fields rather than crashing.",
    "oneOf": [
     {
      "$ref": "#/components/schemas/StreamDelta"
     },
     {
      "$ref": "#/components/schemas/StreamAction"
     },
     {
      "$ref": "#/components/schemas/StreamError"
     },
     {
      "$ref": "#/components/schemas/StreamDone"
     },
     {
      "$ref": "#/components/schemas/StreamClientTool"
     }
    ]
   },
   "StreamDelta": {
    "type": "object",
    "title": "Answer fragment",
    "required": [
     "delta"
    ],
    "properties": {
     "delta": {
      "type": "string",
      "description": "The next chunk of text — append it to what you've already received."
     },
     "notice": {
      "type": "string",
      "enum": [
       "outage",
       "service",
       "review"
      ],
      "description": "Present and `\"outage\"` → the text in `delta` is a service message about a failure or a limit, not a bot message. Show it separately, without ratings. `\"service\"` — a platform service message, not a failure (for example, \"This code was issued for a different bot, so it doesn't work here — and no longer works anywhere\"). `\"review\"` — the answer to this message is being prepared by the assistant and checked by a person (training mode): the text is a line for the customer, and the answer itself will arrive as a message via `GET /v1/api/messages`."
     }
    },
    "examples": [
     {
      "delta": "We're open "
     },
     {
      "delta": "The assistant is temporarily unavailable. Please try again later.",
      "notice": "outage"
     }
    ]
   },
   "StreamError": {
    "type": "object",
    "title": "Stream error",
    "required": [
     "error"
    ],
    "properties": {
     "error": {
      "type": "string",
      "description": "The error text for a person."
     },
     "code": {
      "type": "string",
      "enum": [
       "llm_unavailable",
       "llm_overloaded",
       "internal_error"
      ],
      "description": "A stable error code. `llm_unavailable` — the key or funds; the owner needs to act; `llm_overloaded` — overload or the run's time ran out; retrying makes sense; `internal_error` — a failure on our side. The list may grow — handle an unknown code as a generic error."
     },
     "retry_after": {
      "type": "integer",
      "description": "How many seconds to wait before retrying. Comes only with `llm_overloaded` (there are no more headers in a stream, so `Retry-After` travels in the frame)."
     }
    },
    "examples": [
     {
      "error": "The assistant is temporarily unavailable. We already know about it — please try again a little later.",
      "code": "llm_unavailable"
     },
     {
      "error": "There are too many requests right now, and the answer did not arrive in time. Please send your message again.",
      "code": "llm_overloaded",
      "retry_after": 20
     },
     {
      "error": "Something went wrong. Try again."
     }
    ]
   },
   "StreamDone": {
    "type": "object",
    "title": "End of stream",
    "required": [
     "done",
     "session_id"
    ],
    "properties": {
     "done": {
      "type": "boolean",
      "const": true
     },
     "session_id": {
      "allOf": [
       {
        "$ref": "#/components/schemas/SessionID"
       }
      ],
      "description": "The conversation ID — generated if you didn't pass one."
     },
     "handoff": {
      "type": "boolean",
      "description": "`true` → a live operator is handling the conversation or is awaited (the same as `handoff` in `POST /v1/api/chat`)."
     },
     "quota_exceeded": {
      "type": "boolean",
      "description": "`true` → the monthly conversation limit is used up; the placeholder text has already arrived in a `delta` frame."
     },
     "notice": {
      "type": "string",
      "enum": [
       "outage",
       "service",
       "review"
      ],
      "description": "Present and `\"outage\"` → the text of this run was a service message about a failure, not a bot message. It also comes in the final frame, because some of these messages can only be recognized after the run finishes — reclassify what you've already shown. `\"service\"` — a platform service message, not a failure (for example, \"This code was issued for a different bot, so it doesn't work here — and no longer works anywhere\"). `\"review\"` — the answer to this message is being prepared by the assistant and checked by a person (training mode): the text is a line for the customer, and the answer itself will arrive as a message via `GET /v1/api/messages`."
     },
     "suggestions": {
      "type": "array",
      "maxItems": 3,
      "items": {
       "type": "string"
      },
      "description": "Options for the next message that the assistant suggested under this answer: short phrases in the visitor's voice (\"For the office\", \"Show me others\"). Show them as buttons and send the tapped one as a regular `message`. The field is absent when there are no options or the owner turned them off."
     },
     "contacts": {
      "type": "boolean",
      "description": "`true` → the assistant can't help on its own and asks to show buttons for contacting the company's people (`contacts` from `GET /v1/widget/config`). The field is absent when no buttons need to be shown."
     },
     "products": {
      "type": "array",
      "maxItems": 6,
      "items": {
       "$ref": "#/components/schemas/ProductCard"
      },
      "description": "Catalog products the assistant recommends in this answer — show them as cards below it (photo, name as a link, price, availability). Only a product the assistant fetched from the agent's catalog in this run and linked to in the answer gets here; the server takes the card data from the catalog. The field is absent when the answer recommends no products, the agent has no catalog, or the owner kept recommendations as text (`widget_design.catalog_cards: false`)."
     },
     "review": {
      "type": "boolean",
      "description": "`true` → training mode: there's no answer in this stream (only a line for the customer in a `delta` frame, unless they just heard it) — it will arrive as a message after a person checks it. The same as `review` in `POST /v1/api/chat`. Absent in a regular stream."
     },
     "actions": {
      "type": "array",
      "description": "What this run's actions show the person themselves (buttons, files) and hand to the page (the raw result). Absent if no action ran.",
      "items": {
       "$ref": "#/components/schemas/ActionOutcome"
      }
     }
    },
    "examples": [
     {
      "done": true,
      "session_id": "3f6c1b9e-7f42-4d2a-9a6f-0d5b1f0b21c7"
     }
    ]
   },
   "Message": {
    "type": "object",
    "required": [
     "id",
     "author",
     "text",
     "at"
    ],
    "properties": {
     "id": {
      "type": "string",
      "description": "The message ID."
     },
     "author": {
      "type": "string",
      "enum": [
       "visitor",
       "bot",
       "operator",
       "event"
      ],
      "description": "Who wrote the message. `event` — not a message but a conversation event the platform recorded (the customer left a contact, rated an answer): its data is in the `event` field. Events aren't sent to the customer's window."
     },
     "text": {
      "type": "string"
     },
     "at": {
      "type": "integer",
      "format": "int64",
      "description": "Time (Unix ms). Pass this value (from the last message) as `after` in the next `GET /v1/api/messages` request."
     },
     "operator_id": {
      "type": "string",
      "description": "Which operator wrote it. Only for `author: \"operator\"`."
     },
     "operator_name": {
      "type": "string",
      "description": "The operator's display name for the visitor (\"Olena from support\"). Only for `author: \"operator\"`, and only if it's filled in."
     },
     "event": {
      "$ref": "#/components/schemas/ThreadEvent"
     }
    }
   },
   "HandoffStatus": {
    "type": "string",
    "enum": [
     "bot",
     "waiting",
     "operator",
     "resolved"
    ],
    "description": "bot — the bot is answering; waiting — queued for an operator; operator — an operator is on the line; resolved — finished. The list may grow — treat an unknown value as `bot`."
   },
   "Thread": {
    "type": "object",
    "required": [
     "session_id",
     "bot_id",
     "status",
     "last_text",
     "updated_at",
     "activity_at"
    ],
    "properties": {
     "session_id": {
      "allOf": [
       {
        "$ref": "#/components/schemas/SessionID"
       }
      ],
      "description": "Conversation ID."
     },
     "bot_id": {
      "type": "string",
      "description": "The bot the conversation belongs to (always your key's bot)."
     },
     "status": {
      "$ref": "#/components/schemas/HandoffStatus"
     },
     "last_text": {
      "type": "string",
      "description": "The last message in the conversation. An event (the customer left a contact, rated an answer) also becomes the last line and moves `updated_at`."
     },
     "updated_at": {
      "type": "integer",
      "format": "int64",
      "description": "Time of last activity (Unix ms)."
     },
     "assignee_id": {
      "type": "string",
      "description": "The operator who took the request. Absent while it isn't assigned to anyone."
     },
     "assignee_name": {
      "type": "string",
      "description": "That operator's display name."
     },
     "assigned_at": {
      "type": "integer",
      "format": "int64",
      "description": "When the request was assigned (Unix ms)."
     },
     "activity_at": {
      "type": "integer",
      "format": "int64",
      "description": "Time of the last activity by either side (Unix ms) — always present. Unlike `updated_at`, it also moves on \"typing\" signals."
     },
     "personal": {
      "type": "boolean",
      "description": "The owner's personal conversation with the assistant in a linked messenger chat: the run had admin rights, and it may contain results of \"admin only\" actions. A member without those rights gets such a conversation as a row without `last_text`, it's absent from search (`q`), and the transcript, reply, take, close and its runs' trace return `403`. The mark can't be removed."
     },
     "contact": {
      "type": "string",
      "description": "The last contact the customer left in this conversation (phone or email, as typed). Absent if they left none."
     },
     "contact_name": {
      "type": "string",
      "description": "The name the customer gave when leaving this contact."
     },
     "unhappy": {
      "type": "boolean",
      "description": "`true` → the customer's latest rating in this conversation is \"not helpful\". A later \"helpful\" clears the flag."
     }
    }
   },
   "Source": {
    "type": "object",
    "required": [
     "id",
     "title",
     "chunks"
    ],
    "properties": {
     "id": {
      "type": "string",
      "description": "Source ID — the one you passed as `source_id`, or a generated one."
     },
     "title": {
      "type": "string"
     },
     "chunks": {
      "type": "integer",
      "description": "How many chunks the source was split into."
     },
     "page": {
      "$ref": "#/components/schemas/SourcePage"
     }
    }
   },
   "Error": {
    "type": "object",
    "required": [
     "error",
     "code"
    ],
    "properties": {
     "error": {
      "type": "string",
      "description": "Human-readable error text. It may change at any time — don't parse it or build logic on it."
     },
     "code": {
      "type": "string",
      "description": "Stable machine-readable error code — branch on this. Present in EVERY JSON error from this API, including error frames in the stream. The list may grow: treat an unknown code as a generic error for its HTTP status rather than crashing.",
      "enum": [
       "bad_request",
       "missing_key",
       "invalid_key",
       "unauthorized",
       "forbidden",
       "wrong_key_type",
       "not_found",
       "conflict",
       "rate_limited",
       "internal_error",
       "llm_unavailable",
       "llm_overloaded",
       "service_unavailable",
       "payload_too_large",
       "idempotency_in_progress",
       "idempotency_key_reused",
       "workspace_changed",
       "telegram_token_taken",
       "telegram_unreachable",
       "sso_identity_unusable",
       "sso_storage_unavailable",
       "sso_password_account",
       "sso_address_unavailable",
       "signup_refused",
       "unprocessable",
       "origin_not_allowed",
       "quota_exceeded",
       "session_taken",
       "recovery_not_configured",
       "mail_send_failed",
       "reset_token_invalid",
       "gone",
       "draft_stale",
       "draft_decided",
       "draft_composing",
       "draft_action_failed",
       "draft_undelivered",
       "agent_moving",
       "chat_limit",
       "chat_deleted",
       "checkout_open",
       "confirm_another",
       "email_unconfirmed",
       "mail_not_configured",
       "email_ticket_invalid",
       "wrong_password",
       "account_closing",
       "export_busy",
       "export_gone",
       "knowledge_store_busy",
       "knowledge_too_large",
       "digest_empty",
       "digest_nowhere"
      ]
     },
     "session_id": {
      "type": "string",
      "description": "ID of the conversation in which the error occurred. Present in `/v1/api/chat` errors (503) so you can tie the failure to a specific dialog."
     },
     "retry_after": {
      "type": "integer",
      "description": "How many seconds to wait before retrying. Comes with `llm_overloaded`; duplicates the `Retry-After` header."
     },
     "open": {
      "$ref": "#/components/schemas/OpenPayment",
      "description": "Comes with `checkout_open`: which payment is already open."
     },
     "bought_at": {
      "type": "string",
      "format": "date-time",
      "description": "Comes with `confirm_another`: when the same pack was paid for."
     }
    },
    "examples": [
     {
      "error": "Wrong key type: secret key (sk_) is required here",
      "code": "wrong_key_type"
     }
    ]
   },
   "HandoffEvent": {
    "type": "object",
    "description": "Body of the outgoing webhook. One shape for all three events — which fields are filled depends on `event`.",
    "required": [
     "event",
     "bot_id",
     "session_id",
     "at"
    ],
    "properties": {
     "event": {
      "type": "string",
      "enum": [
       "escalated",
       "visitor_message",
       "resolved"
      ],
      "description": "What happened:\n\n* `escalated` — the conversation was handed off to a human; the agent went silent and is waiting for an operator.\n* `visitor_message` — the visitor wrote in a conversation that has already been handed off.\n* `resolved` — the request was closed; the agent takes the conversation over again.\n\nThe list may grow: ignore an unknown event rather than failing on it."
     },
     "bot_id": {
      "type": "string",
      "description": "ID of the agent whose conversation was handed off."
     },
     "session_id": {
      "type": "string",
      "description": "Conversation ID. This is the same `session_id` the operator API works with afterwards: `GET /v1/api/operator/threads/{sid}`, `POST /v1/api/operator/threads/{sid}/reply`."
     },
     "text": {
      "type": "string",
      "description": "The visitor's message. Filled only for `visitor_message`; absent in other events."
     },
     "transcript": {
      "type": "string",
      "description": "Recent conversation context as a single text — so the operator sees right away how it all started. Filled only for `escalated`."
     },
     "at": {
      "type": "integer",
      "format": "int64",
      "description": "Event time, Unix milliseconds."
     }
    }
   },
   "StreamAction": {
    "type": "object",
    "title": "Action progress in the stream",
    "description": "The agent is running an action (a call to your API, a long job) and hasn't started replying yet. The frame exists so the chat has no silent pause: show it as a status line and replace it once `delta` frames start arriving.\n\nThe frame is **optional** — it comes only when the run actually calls actions. A client that doesn't understand it should simply skip the frame, not crash.",
    "required": [
     "action"
    ],
    "properties": {
     "action": {
      "type": "string",
      "description": "Machine-readable action state — suitable for display as \"working…\"."
     },
     "action_count": {
      "type": "integer",
      "description": "How many actions have been executed in this run. Not always present."
     },
     "action_label": {
      "type": "string",
      "description": "Label for the state of the running action (provided by the action's owner). Absent — the window shows its own generic one."
     }
    }
   },
   "Task": {
    "type": "object",
    "required": [
     "id",
     "title",
     "status",
     "started_at",
     "updated_at"
    ],
    "description": "Card for a long-running agent action.",
    "properties": {
     "id": {
      "type": "string",
      "description": "Job ID."
     },
     "title": {
      "type": "string",
      "description": "What is being done — text for display."
     },
     "status": {
      "type": "string",
      "description": "Job state."
     },
     "detail": {
      "type": "string",
      "description": "Clarification of the state, if any."
     },
     "note": {
      "type": "string",
      "description": "Note for the visitor, if any."
     },
     "started_at": {
      "type": "integer",
      "format": "int64",
      "description": "Start (Unix ms)."
     },
     "updated_at": {
      "type": "integer",
      "format": "int64",
      "description": "Last update (Unix ms)."
     },
     "files": {
      "type": "array",
      "items": {
       "$ref": "#/components/schemas/TaskFile"
      },
      "description": "A list rather than inside detail: the widget must render real links without parsing a sentence written by a third-party service."
     }
    }
   },
   "AgentVersion": {
    "type": "object",
    "required": [
     "number",
     "state",
     "graph",
     "created_at"
    ],
    "description": "An immutable snapshot of the agent's graph. Every apply creates a version — this is what undoing a change set returns to.",
    "properties": {
     "number": {
      "type": "integer"
     },
     "state": {
      "type": "string",
      "enum": [
       "live",
       "archived"
      ],
      "description": "`live` — running now; `archived` — history."
     },
     "graph": {
      "$ref": "#/components/schemas/Graph"
     },
     "created_at": {
      "type": "string",
      "format": "date-time"
     },
     "published_at": {
      "type": "string",
      "format": "date-time"
     }
    }
   },
   "Trigger": {
    "type": "object",
    "required": [
     "id",
     "type",
     "name",
     "enabled",
     "input",
     "fail_streak",
     "created_at"
    ],
    "properties": {
     "id": {
      "type": "string"
     },
     "type": {
      "type": "string",
      "enum": [
       "schedule",
       "webhook",
       "poll",
       "manual",
       "event"
      ],
      "description": "What wakes the agent. `schedule` — the clock. `webhook` — an external call. `poll` — its own check at a set rhythm (what exactly to check is defined by the graph steps, not the trigger). `manual` — a button. `event` — an event of the platform itself."
     },
     "event": {
      "type": "string",
      "enum": [
       "run.failed",
       "handoff.request",
       "lead.captured",
       "credits.low",
       "mail.received",
       "payment.received"
      ],
      "description": "Only for `type: event`: the platform event the agent is subscribed to. The list is closed — a made-up name would be a trigger that simply never fires. `mail.received` — an email arrived in a read-only mailbox (`replies: false`); the run's answer goes to the owner."
     },
     "from": {
      "type": "string",
      "description": "Only for `event: mail.received`: the trigger fires when the sender (address or name) contains this string, case-insensitively. Empty — any email. The filter runs on the platform side: an email \"from the wrong sender\" doesn't cost a run."
     },
     "name": {
      "type": "string"
     },
     "enabled": {
      "type": "boolean"
     },
     "input": {
      "type": "string",
      "description": "The task the agent wakes up with."
     },
     "cron": {
      "type": "string",
      "description": "Only for `schedule`. Runs in the agent's time zone, not in UTC."
     },
     "timezone": {
      "type": "string",
      "example": "Europe/Kyiv"
     },
     "sync": {
      "type": "boolean",
      "description": "Only for `webhook`: wait for the agent's answer instead of 202."
     },
     "interval_sec": {
      "type": "integer",
      "description": "Only for `poll`, from 30."
     },
     "fail_streak": {
      "type": "integer",
      "description": "How many runs in a row have failed. At five, the trigger is paused and the owner is notified."
     },
     "created_at": {
      "type": "string",
      "format": "date-time"
     },
     "hook_url": {
      "type": "string",
      "description": "Only for `webhook`: the URL to send the event to."
     }
    },
    "description": "Declares one way to wake the agent. One schema for reading and writing: on creation the server fills in `id`, `fail_streak`, `created_at` and `hook_url` — values you send are ignored. The webhook signing secret is returned ONCE, in the create response."
   },
   "Run": {
    "type": "object",
    "properties": {
     "id": {
      "type": "string",
      "example": "run_01927d3f"
     },
     "trigger": {
      "type": "string"
     },
     "status": {
      "type": "string",
      "enum": [
       "running",
       "done",
       "failed"
      ]
     },
     "error": {
      "type": "string"
     },
     "credits": {
      "type": "number"
     },
     "input_tokens": {
      "type": "integer"
     },
     "output_tokens": {
      "type": "integer"
     },
     "started_at": {
      "type": "string",
      "format": "date-time"
     },
     "finished_at": {
      "type": "string",
      "format": "date-time"
     },
     "trace_steps": {
      "type": "integer",
      "description": "How many entries the trace of this run has. The trace itself is a separate request: in a list it would weigh megabytes."
     }
    }
   },
   "AgentState": {
    "type": "object",
    "required": [
     "values",
     "version"
    ],
    "properties": {
     "values": {
      "type": "object",
      "additionalProperties": {
       "type": "string"
      }
     },
     "version": {
      "type": "integer",
      "description": "Version for CAS. Pass it back in `PUT`; a mismatch = 409."
     }
    }
   },
   "Member": {
    "type": "object",
    "required": [
     "user_id",
     "email",
     "role"
    ],
    "properties": {
     "user_id": {
      "type": "string"
     },
     "email": {
      "type": "string",
      "format": "email"
     },
     "role": {
      "$ref": "#/components/schemas/Role"
     },
     "you": {
      "type": "boolean"
     }
    }
   },
   "Invite": {
    "type": "object",
    "required": [
     "id",
     "email",
     "role",
     "expires_at"
    ],
    "properties": {
     "id": {
      "type": "string"
     },
     "email": {
      "type": "string",
      "format": "email"
     },
     "role": {
      "$ref": "#/components/schemas/Role"
     },
     "expires_at": {
      "type": "string",
      "format": "date-time"
     }
    }
   },
   "Skill": {
    "type": "object",
    "required": [
     "id",
     "bot_id",
     "name",
     "description",
     "method",
     "url",
     "params",
     "admin_only",
     "disabled",
     "known_only",
     "expose_result",
     "client"
    ],
    "description": "An agent action as the dashboard returns it. Headers with access keys NEVER end up here — they can't be read back.",
    "properties": {
     "id": {
      "type": "string"
     },
     "bot_id": {
      "type": "string"
     },
     "name": {
      "type": "string",
      "description": "The name the model calls the action by. Unique within the agent."
     },
     "description": {
      "type": "string",
      "description": "Written for the MODEL: when exactly to call this action."
     },
     "method": {
      "type": "string",
      "enum": [
       "GET",
       "POST"
      ]
     },
     "url": {
      "type": "string"
     },
     "params": {
      "type": "array",
      "items": {
       "$ref": "#/components/schemas/SkillParam"
      }
     },
     "admin_only": {
      "type": "boolean",
      "description": "The action is available only to the site's authorized owner, not to an anonymous visitor."
     },
     "disabled": {
      "type": "boolean",
      "description": "The owner has temporarily disabled the action: the model doesn't see it; keys and settings are kept. Re-enable it with a PATCH with enabled: true."
     },
     "needs_approval": {
      "type": "boolean",
      "description": "A HUMAN performs the action, not the agent: the call becomes a card in the approval queue, and nothing happens in the world until the owner clicks \"Send\". For actions that reach someone outside — an email to a customer, a post, a payment."
     },
     "outreach": {
      "type": "object",
      "nullable": true,
      "description": "The action is OUTREACH to a person: the platform checks the stop list and rate limits before every call, and a refusal here stops the call rather than asking the model to be careful. Absent field = the action is not outreach.",
      "properties": {
       "param": {
        "type": "string",
        "description": "Name of the parameter that holds the recipient (to, phone, client_id — as in your API). The platform doesn't guess it: a guess would break silently, and the stop list would stop working while still showing as enabled."
       },
       "per_day": {
        "type": "integer",
        "description": "How many outreach contacts through this action are allowed per day. 0 = no limit."
       },
       "every_hours": {
        "type": "integer",
        "description": "Minimum interval between outreach contacts to ONE recipient, in hours. 0 = no limit."
       },
       "quota_param": {
        "type": "string",
        "description": "Name of the parameter that holds WHO the outreach comes FROM: an account, a page, a sender number. Then per_day is counted for each of them SEPARATELY.\n\nThis is needed because accounts get banned, not actions: one \"post to group\" action and three accounts means three separate limits. A single limit shared by all three either stops work three times too early or exceeds the safe rate on each account threefold, and no action setting can fix that.\n\nEmpty = the limit is counted for the action as a whole."
       }
      }
     },
     "connection": {
      "type": "string",
      "description": "Name of the connection this action acts on behalf of (see \"Dashboard · Connected accounts\"). Empty = the action works with its own headers, i.e. on behalf of the agent's OWNER; set = on behalf of whoever gave consent in the service. The token isn't copied here — it lives for a few minutes and refreshes itself."
     },
     "connection_header": {
      "type": "string",
      "description": "Where to put the token. Empty = Authorization."
     },
     "connection_prefix": {
      "type": "string",
      "description": "Value prefix. Empty for Authorization = \"Bearer \"."
     },
     "timeout_sec": {
      "type": "integer",
      "minimum": 0,
      "maximum": 300,
      "description": "How long to wait for a response from this particular action. 0 (field absent) — the platform default, 30 s. It belongs to the action because a balance check and building a quarterly report differ by an order of magnitude. More than 60 s works only in a background run (trigger, schedule, webhook): a conversational run is cut off earlier."
     },
     "async": {
      "$ref": "#/components/schemas/SkillAsync"
     },
     "token_auth": {
      "$ref": "#/components/schemas/SkillTokenAuth"
     },
     "order": {
      "type": "string",
      "enum": [
       "woocommerce",
       "prom",
       "horoshop"
      ],
      "description": "The shop engine whose orders this action reads (\"where is my order\"). In that case the shop API response does NOT go to the model: the platform matches the phone or email the buyer gave against the order and returns only the status, date, delivery and tracking number (TTN). The model calls such an action with `order_number` and `contact`. Set only by a ready-made connection (`POST …/skills/presets`); absent field — a regular action."
     },
     "known_only": {
      "type": "boolean",
      "description": "The action is only for visitors the site has identified (passed an identifier — the `{{user_token}}` substitution). For a guest it isn't in the set at all: the assistant doesn't see it and won't call it. This is not proof of identity — the identifier is written by the page."
     },
     "status_label": {
      "type": "string",
      "description": "What the person sees in the window while the action is running (\"Building the diagram…\"). Up to 80 characters, one line; empty — the window's generic line."
     },
     "expose_result": {
      "type": "boolean",
      "description": "The action's raw result and its arguments are passed to the page code (`actions[].args`, `actions[].result`, the window event `action_result`). Off by default."
     },
     "client": {
      "type": "boolean",
      "description": "A page tool: the site itself executes it (a `YouSelfBot.registerTool` handler), not the server. It has no URL and no keys; the model gets it only in a conversation where the page has registered a handler with this name."
     }
    }
   },
   "Lead": {
    "type": "object",
    "required": [
     "id",
     "name",
     "contact",
     "message",
     "created_at"
    ],
    "properties": {
     "id": {
      "type": "integer",
      "format": "int64"
     },
     "name": {
      "type": "string"
     },
     "contact": {
      "type": "string"
     },
     "message": {
      "type": "string"
     },
     "created_at": {
      "type": "string",
      "format": "date-time"
     }
    }
   },
   "Channel": {
    "type": "object",
    "properties": {
     "id": {
      "type": "string"
     },
     "type": {
      "type": "string",
      "enum": [
       "telegram",
       "viber",
       "whatsapp",
       "discord",
       "slack",
       "api",
       "email"
      ]
     },
     "name": {
      "type": "string"
     },
     "enabled": {
      "type": "boolean"
     },
     "created_at": {
      "type": "string",
      "format": "date-time"
     },
     "configured": {
      "type": "boolean",
      "description": "The channel has enough settings to work. The settings themselves (the token) are never returned — once they're in the database, showing them again only adds a leak path."
     },
     "private": {
      "type": "boolean",
      "description": "The channel replies only to linked people (the owner and trusted ones). A stranger gets a one-sentence refusal; no agent run starts for them and no credits are spent."
     },
     "pairable": {
      "type": "boolean",
      "description": "You can link your chat in this channel: the messenger itself vouches for who is writing (Telegram, Viber, WhatsApp). Email can't: a sender address is easy to forge."
     },
     "pairing_blocked": {
      "type": "string",
      "description": "The messenger can verify the sender, but this channel is missing a setting — in plain words for a person (for example, a WhatsApp channel without an App secret). The field is absent if linking is possible or the channel type doesn't verify senders at all."
     },
     "invite_url": {
      "type": "string",
      "description": "Where the owner goes to add the bot before anyone writes to it (a Discord server). The field is absent if the messenger has no such step."
     },
     "replies": {
      "type": "boolean",
      "description": "Whether the channel replies to messages itself. `false` — the mailbox is read-only: emails don't wake the agent to reply and aren't marked as read; the owner's agent searches and reads them with the `mailbox` capability, and the `mail.received` event announces a new email. Messengers are always `true`."
     },
     "reads": {
      "type": "boolean",
      "description": "The platform reads this mailbox itself (an email channel with an incoming mail server). Only then does the owner's agent have anything to search with the `mailbox` capability, and only then is `replies: false` allowed."
     },
     "sends_itself": {
      "type": "boolean",
      "description": "The owner's agent sends emails from this mailbox without an approval card. Default `false`: every email on the owner's behalf first waits for their permission. After reading someone else's email in the same run, permission is always required — regardless of this field."
     },
     "away": {
      "type": "object",
      "description": "What a person who writes to a DISABLED channel receives: one sentence, without the model or credits, no more than once every 30 minutes per person. Changed via `PUT …/channels/{cid}/away`.",
      "properties": {
       "text": {
        "type": "string",
        "description": "The owner's own sentence. Empty — the standard one (`default`)."
       },
       "silent": {
        "type": "boolean",
        "description": "`true` — the disabled channel says nothing."
       },
       "default": {
        "type": "string",
        "description": "The platform's standard sentence."
       }
      }
     },
     "waits": {
      "type": "boolean",
      "description": "`true` — this is a mailbox the platform reads itself (IMAP) and that replies: while the channel is disabled, emails wait in the mailbox unread, and the agent will reply to them once the channel is enabled. The \"not replying right now\" sentence isn't sent for such emails."
     },
     "missed": {
      "type": "object",
      "description": "How many people wrote to the channel while it wasn't replying (disabled or out of credits). The field is absent if the counter couldn't be read. The count restarts with each disabling and disappears 14 days after the last message. The messages themselves are in the agent's conversations; the agent doesn't reply to them on its own later.",
      "properties": {
       "people": {
        "type": "integer"
       },
       "messages": {
        "type": "integer"
       },
       "since": {
        "type": "string",
        "format": "date-time",
        "description": "When they first wrote."
       },
       "last": {
        "type": "string",
        "format": "date-time",
        "description": "When they last wrote."
       }
      }
     }
    }
   },
   "RunStep": {
    "type": "object",
    "required": [
     "name",
     "type",
     "outcome",
     "duration_ms"
    ],
    "description": "One trace entry: a step of the run or a tool call.",
    "properties": {
     "name": {
      "type": "string",
      "description": "Name of the step in the run (or the tool name)."
     },
     "type": {
      "type": "string",
      "description": "Step type; tool_call — a tool call by the model."
     },
     "outcome": {
      "type": "string",
      "enum": [
       "ran",
       "skipped",
       "halted",
       "failed",
       "tool"
      ],
      "description": "ran — executed; skipped — the condition didn't match; halted — ended the run; failed — failed; tool — a tool call."
     },
     "condition": {
      "type": "string",
      "description": "The step's condition, if it had one. Together with skipped, it explains the skip."
     },
     "detail": {
      "type": "string",
      "description": "The halt reason, the number of chunks found, the error text — whatever this step considers worth showing."
     },
     "duration_ms": {
      "type": "integer",
      "format": "int64"
     },
     "ref": {
      "type": "string",
      "description": "ID of the request to the model provider. The only thing you can take to them to trace a case where there is a response — and it's the wrong one. Present only on `model` steps; a node with a tool loop makes several requests, and the LAST one is kept here — the one that produced the response."
     },
     "args": {
      "type": "string",
      "description": "Only on tool_call steps: the arguments the model called the tool with (JSON as a string), up to 4 KB. Keys are redacted."
     },
     "result": {
      "type": "string",
      "description": "Only on tool_call steps: what the tool returned to the model, up to 4 KB. Keys are redacted."
     }
    }
   },
   "SecretList": {
    "type": "object",
    "properties": {
     "secrets": {
      "type": "array",
      "items": {
       "$ref": "#/components/schemas/Secret"
      }
     }
    }
   },
   "Secret": {
    "type": "object",
    "required": [
     "name",
     "updated_at"
    ],
    "description": "A secret as seen from outside: its name and modification time. No layer of the product returns the value.",
    "properties": {
     "name": {
      "type": "string",
      "example": "STRIPE_KEY"
     },
     "updated_at": {
      "type": "string",
      "format": "date-time"
     }
    }
   },
   "SecretWrite": {
    "type": "object",
    "required": [
     "value"
    ],
    "properties": {
     "value": {
      "type": "string",
      "description": "Key value. Spaces and line breaks at the edges are trimmed: a key copied from a service's console arrives with them — and silently doesn't work."
     }
    }
   },
   "IncidentList": {
    "type": "object",
    "properties": {
     "incidents": {
      "type": "array",
      "items": {
       "$ref": "#/components/schemas/Incident"
      }
     },
     "open": {
      "type": "integer",
      "description": "How many of them are still not fixed."
     },
     "truncated": {
      "type": "boolean",
      "description": "The list is truncated: there are more rows than a page holds (50). Say so explicitly — otherwise the owner reads the slice as the whole list. There's no cursor pagination here yet; older history is available only from storage."
     }
    }
   },
   "Incident": {
    "type": "object",
    "properties": {
     "id": {
      "type": "string"
     },
     "kind": {
      "type": "string",
      "enum": [
       "credits_low",
       "credits_exhausted",
       "cost_cap",
       "agent_cap",
       "action_unauthorized",
       "action_failing",
       "actions_unavailable",
       "run_failed",
       "turn_too_long",
       "loop_exhausted",
       "trigger_paused",
       "handoff_failed",
       "work_unfinished",
       "secret_missing",
       "memory_unproven",
       "history_lost",
       "mailbox_unreadable",
       "reply_undelivered",
       "reply_partial",
       "reply_refused",
       "records_full",
       "task_stalled",
       "catalog_stale",
       "voice_unheard",
       "calendar_unreadable",
       "image_unmade",
       "speech_unmade",
       "page_unreadable",
       "payment_unauthorized",
       "payment_unavailable",
       "site_pages_changed"
      ],
      "description": "Incident kind. `action_unauthorized` and `action_failing` are kept apart on purpose: the owner fixes the first (with a new key); nobody here can fix the second — it broke on the other side."
     },
     "subject": {
      "type": "string",
      "description": "What exactly: action name, key name, trigger name. Empty when it concerns the agent as a whole."
     },
     "detail": {
      "type": "string",
      "description": "Detail: response code, error text."
     },
     "count": {
      "type": "integer",
      "description": "How many times it has repeated. Distinguishes a one-off glitch from \"down for the third day\"."
     },
     "first_at": {
      "type": "string",
      "format": "date-time"
     },
     "last_at": {
      "type": "string",
      "format": "date-time"
     },
     "resolved_at": {
      "type": "string",
      "format": "date-time",
      "nullable": true,
      "description": "null = still open."
     },
     "open": {
      "type": "boolean"
     },
     "message": {
      "type": "string",
      "description": "Ready-made text for a human — the same one that came in the notification."
     }
    }
   },
   "BotConfigPatch": {
    "type": "object",
    "description": "All fields are optional. Empty = leave unchanged.",
    "properties": {
     "purpose": {
      "type": "string",
      "enum": [
       "assistant",
       "worker"
      ],
      "description": "Who the agent is for. This selects the prompt framework, not a shade of wording."
     },
     "role": {
      "type": "string"
     },
     "tone": {
      "type": "string",
      "enum": [
       "friendly",
       "professional",
       "playful",
       "concise"
      ]
     },
     "language": {
      "type": "string",
      "enum": [
       "auto",
       "uk",
       "en"
      ]
     },
     "greeting": {
      "type": "string"
     },
     "starters": {
      "type": "array",
      "items": {
       "type": "string"
      }
     },
     "refusal_text": {
      "type": "string"
     },
     "system_prompt": {
      "type": "string",
      "description": "A raw instruction instead of one assembled from the fields. DISABLES the managed fields: role, tone and language stop taking effect."
     },
     "widget_title": {
      "type": "string"
     },
     "widget_accent": {
      "type": "string",
      "description": "#rrggbb."
     },
     "widget_position": {
      "type": "string",
      "enum": [
       "bottom-right",
       "bottom-left",
       "top-right",
       "top-left"
      ],
      "description": "The screen corner where the chat button and window sit."
     },
     "widget_theme": {
      "type": "string"
     },
     "widget_light": {
      "$ref": "#/components/schemas/WidgetColors"
     },
     "widget_dark": {
      "$ref": "#/components/schemas/WidgetColors"
     },
     "collect_leads": {
      "type": "boolean",
      "description": "A pointer in the domain model: `false` here is meaningful and doesn't get lost among unset fields."
     },
     "page_aware": {
      "type": "boolean",
      "description": "Whether the chat window on the site may read the page it's on (URL, title, product name and price from the markup) and send it along with the message. Off by default: this is reading someone else's site, and the owner turns it on. A pointer in the domain model: `false` here is meaningful."
     },
     "off_topic": {
      "type": "string",
      "description": "Instruction to the model on what to do with an off-topic question. Not the same as refusal_text (a ready-made sentence for the visitor)."
     },
     "fit_site": {
      "type": "boolean",
      "description": "Whether the window adopts the site's palette. Yes by default; false locks in the built-in palette. A pointer in the domain model."
     },
     "operator": {
      "type": "boolean",
      "description": "Whether a live human can be called in — in the chat window on the site and in the agent's messengers (Telegram, Viber, WhatsApp). Yes by default. A pointer in the domain model."
     },
     "draft_preview": {
      "type": "boolean",
      "description": "Whether the operator sees what the customer is typing. Yes by default; applies only during a conversation with a human. A pointer in the domain model."
     },
     "auto_translate": {
      "type": "boolean",
      "description": "Translate the operator's replies into the visitor's language. Off by default: it's a model call for every operator reply."
     },
     "visitor_memory": {
      "type": "boolean",
      "description": "Whether to remember a recognized visitor between conversations. Yes by default; false turns off profile recording (what has been collected stays, and is erased at the person's request). A pointer in the domain model."
     },
     "semantic_cache": {
      "type": "boolean",
      "description": "Whether to reuse ready answers for identical questions. Yes by default — it saves credits; false = every run goes to the model and costs the full price. A pointer in the domain model."
     },
     "handoff_webhook_url": {
      "type": "string",
      "description": "Where to send a POST about a conversation being handed off to a human — for the owner's own operator system."
     },
     "clear": {
      "type": "array",
      "items": {
       "type": "string",
       "enum": [
        "refusal",
        "greeting",
        "starters",
        "role",
        "language",
        "widget_colors",
        "system_prompt",
        "peers",
        "mcp",
        "alert_email",
        "alert_webhook",
        "handoff_webhook",
        "widget_note",
        "contacts",
        "launcher_label",
        "launcher_image",
        "widget_logo",
        "teaser",
        "teaser_product",
        "widget_design",
        "widget_css",
        "widget_texts",
        "launcher_svg",
        "teaser_rules",
        "teaser_returning",
        "teaser_buttons",
        "teaser_image",
        "widget_items",
        "widget_layout",
        "widget_icons",
        "widget_all",
        "widget_accent",
        "quiet_hours",
        "digest_when",
        "digest_lang",
        "widget_title",
        "widget_langs",
        "widget_lang",
        "widget_hide_on",
        "launcher_emoji",
        "starter_rules",
        "identity_verify_url"
       ]
      },
      "description": "What to CLEAR. An empty string in a regular field means \"leave unchanged\", so this is the only way to remove something.\n\nThe names here are their own and don't always match the field names:\n\n| value | what it clears |\n|---|---|\n| `refusal` | `refusal_text` |\n| `alert_webhook` | `alert_webhook_url` |\n| `handoff_webhook` | `handoff_webhook_url` |\n| `digest_lang` | the digest language — back to the owner's dashboard language |\n| `widget_colors` | `widget_light` AND `widget_dark` at once |\n| `launcher_label`, `launcher_image` | the `widget_design` field of the same name |\n| `teaser` | the whole invitation banner: text, product-page text, rules for site sections, invitation for returning visitors, buttons and image |\n| `teaser_product` | `widget_design.teaser_product` — the product page shows the general text again |\n| `launcher_svg` | `widget_design.launcher_svg` |\n| `widget_logo` | `widget_design.logo` |\n| `widget_design` | the whole look of the window — back to default |\n| `teaser_rules`, `teaser_returning`, `teaser_buttons`, `teaser_image` | the `widget_design` field of the same name (`teaser` clears them too) |\n| `widget_items` | all custom elements in the window |\n| `widget_layout` | the arrangement of parts — back to the usual one |\n| `widget_icons` | all custom icons, together with `widget_design.launcher_svg` |\n| `widget_all` | the entire LOOK of the window in one go: `widget_design`, `widget_css`, `widget_texts`, `widget_icons`, `widget_items`, `widget_layout`, colors, accent, theme and corner. The title, greeting, starters, note and contact buttons stay |\n| `widget_accent` | the accent color — back to default |\n| `widget_note` | the note under the input field — there will be no line at all, not the \"default\" one |\n| anything else | the field of the same name |\n\nAn unknown name isn't ignored: it comes back in `refused` together with the list of allowed names. Silently skipping it would mean a \"Reset\" button that doesn't work while the response says \"done\"."
     },
     "peers": {
      "type": "array",
      "items": {
       "type": "string"
      },
      "description": "Other agents in this workspace that this one may delegate work to (the `agent_call` tool). Replaces the list ENTIRELY: \"add one\" and \"keep only one\" are different intents, and guessing which one was meant is worse than either.\n\nAn allowlist rather than \"anyone nearby\": the called agent spends the owner's credits and acts on their behalf."
     },
     "mcp": {
      "type": "array",
      "items": {
       "$ref": "#/components/schemas/MCPServer"
      },
      "description": "Connected Model Context Protocol servers: the agent gets their tools without each one being described by hand. Replaces the list entirely."
     },
     "alert_email": {
      "type": "string",
      "description": "Where to send emails about this agent's incidents: an action returned 401, a trigger was auto-paused, credits ran out. Often this is a shared support mailbox rather than the owner's address."
     },
     "alert_webhook_url": {
      "type": "string",
      "description": "Where to POST the same notifications. Delivery is signed: headers X-YouSelfBot-Timestamp and X-YouSelfBot-Signature, HMAC-SHA256 over \"timestamp.body\" with the alert_webhook_secret key. Body: {event:\"owner_alert\", agent, name, text, at}."
     },
     "alert_telegram": {
      "type": "boolean",
      "description": "Whether to send incidents to the agent's Telegram support. Yes by default. A pointer in the domain model: `false` here is meaningful and doesn't get lost among unset fields."
     },
     "monthly_credit_cap": {
      "type": "integer",
      "minimum": 0,
      "description": "How many credits THIS PARTICULAR agent may spend in a calendar month. 0 (default) = no cap.\n\nNot the same as the plan limit: that one applies to the workspace and stops everyone equally. This one stops just one agent — the one doing the spending — while the other agents keep working. It's needed where an agent works on its own at night: if it falls into a loop, it would otherwise drain the whole workspace's allowance, and in the morning the bot that answers customers goes silent.\n\nSpending is counted from the run log — the same numbers shown on the run card. The minimum is 1000: below that the agent stops before its first reply."
     },
     "suggestions": {
      "type": "boolean",
      "description": "Whether the assistant offers up to three options for the next message under its reply (\"For the office\", \"Show others\"), which the window shows as buttons. On by default."
     },
     "voice": {
      "type": "boolean",
      "description": "Whether voice messages in messengers (Telegram, WhatsApp, Viber, email) are transcribed: the platform turns a recording of up to 10 minutes into text before the agent's run; credits are charged per minute of audio. On by default."
     },
     "voice_reply": {
      "type": "string",
      "enum": [
       "off",
       "owner",
       "all"
      ],
      "description": "Who the agent replies to by voice in messengers: `owner` — only the owner in their linked chat, `all` — everyone, `off` — in text (default). Voice replies work in Telegram and WhatsApp; the site, Viber and email stay text. Credits are charged per thousand characters spoken; a reply containing a link is also sent as text. Empty = leave unchanged."
     },
     "widget_note": {
      "type": "string",
      "description": "A small-print note under the window's input field — one line, up to 160 characters. Empty = leave unchanged; to remove the line entirely — `clear: [\"widget_note\"]`."
     },
     "contacts": {
      "type": "array",
      "maxItems": 4,
      "items": {
       "$ref": "#/components/schemas/ContactButton"
      },
      "description": "Buttons for contacting the company's people: Telegram, Viber, WhatsApp, phone, email, link. Replaces the list ENTIRELY — pass all the buttons that should stay; to remove all of them — `clear: [\"contacts\"]`.\n\nAll or nothing: if a link can't be built from even one button (a number without a country code, a link not starting with `https://`), the list doesn't change, and the reason comes back in `refused`.\n\nA click in the window opens the messenger with the visitor's question and the page URL already filled in — support sees what it was about."
     },
     "widget_design": {
      "allOf": [
       {
        "$ref": "#/components/schemas/WidgetDesignPatch"
       }
      ],
      "description": "The chat window's look: shape, size, font, button, logo, offsets from the edge, invitation banner. The set is closed — there's deliberately no arbitrary CSS here: this runs on the owner's site in front of their customers.\n\nThe code snippet on the site doesn't change: the window reads its look from `GET /v1/widget/config`."
     },
     "widget_css": {
      "type": "string",
      "maxLength": 20000,
      "description": "A custom window style — plain CSS, written however you like, on top of the closed `widget_design` set. It applies only inside the window (which lives in its own Shadow DOM), so it doesn't affect the owner's pages.\n\nTwo limits. No code: scripts in any form, `@import`, rules about `:host` and images not from `https://` are rejected — the reason comes back in `refused`. And the window checks itself: if, while collapsed, the style covered the page, the window removes it and reports this in the browser console.\n\nThe platform no longer guarantees text readability with a custom style.\n\nReplaces the previous style ENTIRELY. Empty string = leave unchanged; to remove — `clear: [\"widget_css\"]`.\n\nThe \"Made with youselfbot.com\" label at the bottom of the window can't be removed: it can't be hidden, covered or replaced. The server rejects a style that names its class (`.madeby`) or hides the whole window, and the window itself checks after every change that the label is visible, and removes any custom style or custom elements that touched it."
     },
     "widget_texts": {
      "type": "object",
      "additionalProperties": {
       "type": "string",
       "maxLength": 120
      },
      "description": "Custom labels in the window: key — which label, value — the new text. Merged with those already set; an empty value restores the default label. Keys: `placeholder`, `send`, `attach`, `open`, `close`, `fresh`, `fresh_ask`, `fresh_yes`, `fresh_no` (the question before erasing the conversation, and its buttons), `attach_photo`, `attach_file` (the choice on a phone: photo or file), `attach_drop` (the hint while a file is held over the window), `move_back` (the \"Move the window back\" button), `human`, `lead`, `thinking`, `working`, `op_typing`, `viewing`, `buy`, `similar`, `cheaper`, `variants`, `compare`, `lead_name`, `lead_contact`, `lead_note`, `lead_send`, `lead_done`, `called`, `joined`, `thanks`, `continue` (the \"Continue in Telegram\" button), `state_bot`, `state_waiting`, `state_operator`, `state_resolved`. The window's refusals and errors are labels too (a site in another language should show them in its own language): `attach_sending`, `attach_too_big`, `attach_image_big`, `attach_type`, `attach_many`, `attach_full`, `attach_failed`, `compare_more`, `gone`, `lead_need`, `rate_failed`, `continue_gone`, `continue_later`, `closed`, `err_rate_limited`, `err_quota_exceeded`, `err_llm_unavailable`, `err_llm_overloaded`, `err_service_unavailable`, `err_internal_error`, `err_payload_too_large`, `err_session_taken`, `err_not_found`, `err_bad_request`, `err_offline`, `err_network`, `err_stream_broken`, `grow`, `shrink`, `teaser_close`, `unread`, `rate_up`, `rate_down`, `who_you`, `who_bot`, `who_operator`, `again`. The rest of the window's strings: `log_label`, `card_title`, `card_running`, `card_done`, `card_failed`, `card_unknown`, `human_ask`, `reach_hello`, `reach_question`, `reach_page`, `reach_subject`, `reach_label`, `say_similar`, `say_cheaper`, `say_compare`, `say_and`, `file_name`, `copied`, `compare_drop`, `goods`, `attach_remove`, `attached` (the message feed's name for screen readers, the long-action card, the offer to call a human, the draft for a messenger, the messages sent by buttons on product cards, small captions). Installation errors (key, domain) and \"no connection\" at startup stay default: they're shown before the settings have arrived.\n\nTwo labels deliberately can't be replaced: \"The owner of this site will see your contact\" and \"The operator can see what you are typing\" — this is what the visitor must know before typing anything."
     },
     "training": {
      "type": "boolean",
      "description": "Turn the training mode on (`true`) or off (`false`): a human sees the agent's replies to customers first. Not sent — leave unchanged."
     },
     "training_idle": {
      "type": "string",
      "enum": [
       "wait",
       "send",
       "later"
      ],
      "description": "Training mode: what to do when the operator hasn't replied: `wait` — wait (default), `send` — send the draft on its own, `later` — tell the customer we'll reply later. Empty = leave unchanged."
     },
     "training_idle_min": {
      "type": "integer",
      "minimum": 1,
      "maximum": 1440,
      "description": "Training mode: after how many minutes to consider that the operator hasn't replied. Not sent — leave unchanged."
     },
     "widget_items": {
      "type": "array",
      "maxItems": 24,
      "items": {
       "$ref": "#/components/schemas/WidgetItemPatch"
      },
      "description": "Custom elements in the window. The list is MERGED by `id`: pass only the ones you're adding or changing; `remove: true` removes one, `clear: [\"widget_items\"]` removes all. All or nothing: if even one element fails validation, none is applied, and the reason comes back in `refused`. Caps: 24 elements in total and a few per slot.\n\nThe \"Made with youselfbot.com\" label at the bottom of the window can't be removed: it can't be hidden, covered or replaced. The server rejects a style that names its class (`.madeby`) or hides the whole window, and the window itself checks after every change that the label is visible, and removes any custom style or custom elements that touched it. A custom element can't be named like this label or look like it."
     },
     "widget_layout": {
      "allOf": [
       {
        "$ref": "#/components/schemas/WidgetLayoutPatch"
       }
      ],
      "description": "Arrangement and composition of the window's built-in parts: the order of the header buttons and of the buttons under the message feed, hidden parts, a centered title, the input field at the top, starters above the field."
     },
     "widget_icons": {
      "type": "object",
      "additionalProperties": {
       "type": "string",
       "maxLength": 4000
      },
      "description": "Custom icons instead of the built-in ones: key — which icon, value — a single SVG, shapes only (`path`, `circle`, `rect`, `line`, `polyline`, `polygon`, `ellipse`, `g`), no scripts, links, embedded styles or external images. Keys: `launcher`, `launcher_close`, `teaser`, `teaser_close`, `close`, `fresh`, `grow`, `shrink`, `chat_more`, `chats`, `move_back`, `send`, `attach`, `attached`, `remove`, `human`, `lead`, `continue`, `rate_up`, `rate_down`, `typing`, `note`, `buy`, `photo`, `check`, `contact_telegram`, `contact_viber`, `contact_whatsapp`, `contact_phone`, `contact_email`, `contact_link`. The chat button icon (`launcher`) is stored in `widget_design.launcher_svg`. Merged by key; an empty value restores the built-in icon, `clear: [\"widget_icons\"]` — all of them."
     },
     "handoff_notify": {
      "type": "boolean",
      "description": "Whether to notify people outside the dashboard about a customer asking for a human (the owner's linked chat, Telegram support, email). Yes by default."
     },
     "handoff_mail": {
      "type": "boolean",
      "description": "Whether to email the owner about requests at their account address. Yes by default."
     },
     "handoff_remind_min": {
      "type": "integer",
      "description": "After how many minutes to send a reminder about a request nobody has taken (and how long after the previous one to send the next, if `handoff_remind_times` is more than one): 1…720; `-1` — no reminders; `0` — restore the default 10."
     },
     "handoff_remind_times": {
      "type": "integer",
      "minimum": 0,
      "maximum": 5,
      "description": "How many times to remind about a request nobody has taken: 1…5 (default 1). Each next reminder comes `handoff_remind_min` after the previous one; once the request is taken, answered or closed — no more; no reminders during quiet hours. `0` — no reminders (same as `handoff_remind_min: -1`); a number from 1 up, when reminders were off, turns them back on."
     },
     "quiet_hours": {
      "type": "string",
      "description": "Quiet hours for request notifications: `22:00-08:00` (a different time zone — as a third word). To remove — `clear: [\"quiet_hours\"]`."
     },
     "digest": {
      "type": "boolean",
      "description": "Whether to send the owner a digest (unanswered questions and everything waiting for a human). Yes by default."
     },
     "digest_when": {
      "type": "string",
      "description": "When to send the digest: `mon 09:00`, several days separated by commas — `mon,thu 18:00`, `weekdays 08:30` or `daily 18:30`; the time can be any minute; a different time zone — as a third word. To restore the default — `clear: [\"digest_when\"]`."
     },
     "digest_to": {
      "type": "string",
      "enum": [
       "chat",
       "mail",
       "all"
      ],
      "description": "Where to send the digest: only to the linked chat, only to email, or everywhere a route exists (`all`, default)."
     },
     "digest_lang": {
      "type": "string",
      "enum": [
       "uk",
       "en"
      ],
      "description": "Digest language."
     },
     "digest_size": {
      "type": "integer",
      "minimum": 1,
      "maximum": 50,
      "description": "How many of the most frequent questions to name in the digest: 1…50 (default 5); the rest — as a link to the sheet."
     },
     "widget_lang": {
      "type": "string",
      "description": "The window's primary language — a two-letter code (`uk`, `en`, `pl`…). To reset — `clear: [\"widget_lang\"]`."
     },
     "widget_lang_auto": {
      "type": "boolean",
      "description": "Whether the window picks the language from the page and the visitor's browser (yes by default). `false` — always the primary language."
     },
     "widget_langs": {
      "type": "object",
      "additionalProperties": {
       "$ref": "#/components/schemas/WidgetLangSetPatch"
      },
      "description": "Window texts in other languages: language code → a change to its set. Sets are merged by language and by field. To remove all — `clear: [\"widget_langs\"]`."
     },
     "widget_hide_on": {
      "type": "array",
      "maxItems": 20,
      "items": {
       "type": "string"
      },
      "description": "URL patterns of pages where the window isn't shown. Replaces the list entirely; to show it everywhere — `clear: [\"widget_hide_on\"]`."
     },
     "identity_verify_url": {
      "type": "string",
      "description": "The owner's server that verifies the visitor's token (`data-user-token`, `identify()`): the platform sends a POST `{\"token\", \"agent\"}` signed with `X-YouSelfBot-Signature: sha256=…` (an HMAC of the body with the agent's signing key) and expects 200 with `{\"valid\": true, \"user_id\": \"…\"}`. When set, only a verified token makes the person identified (`{{user_token}}` in actions, `known_only` actions, memory); an unverified or rejected token, or a server failure, means a guest. The response is cached: \"yes\" for 5 minutes, \"no\" for one minute. `https://` only."
     }
    }
   },
   "WidgetColors": {
    "type": "object",
    "properties": {
     "bg": {
      "type": "string",
      "description": "Background of the panel and footer (hex)."
     },
     "surface": {
      "type": "string",
      "description": "Background of the bubbles and the input field (hex)."
     },
     "text": {
      "type": "string",
      "description": "Main text (hex)."
     }
    }
   },
   "BotConfigPatchResult": {
    "type": "object",
    "properties": {
     "changed": {
      "type": "array",
      "items": {
       "type": "string"
      },
      "description": "What exactly changed, in plain language. Empty = the request added nothing. These are sentences for showing to a human; fields aren't named here, since what changed is visible anyway — in `config` of the same response."
     },
     "refused": {
      "type": "array",
      "items": {
       "$ref": "#/components/schemas/Refusal"
      },
      "description": "What was NOT accepted and why. Each entry names the field, so there's no need — and no point — in parsing the text to find where the error is."
     },
     "config": {
      "$ref": "#/components/schemas/BotConfig",
      "description": "The config after the write — already normalized."
     },
     "mcp": {
      "type": "array",
      "items": {
       "type": "object",
       "properties": {
        "alias": {
         "type": "string"
        },
        "url": {
         "type": "string"
        }
       }
      },
      "description": "Connected servers WITHOUT tokens. A separate field, because they don't appear in `config` itself at all, and the owner should see that a connection exists."
     }
    }
   },
   "ChangeList": {
    "type": "object",
    "properties": {
     "changes": {
      "type": "array",
      "items": {
       "$ref": "#/components/schemas/ChangeSet"
      }
     },
     "truncated": {
      "type": "boolean",
      "description": "The list is truncated: there are more rows than a page holds (50). Say so explicitly — otherwise the owner reads the slice as the whole list. There's no cursor pagination here yet; older history is available only from storage."
     }
    }
   },
   "ChangeSet": {
    "type": "object",
    "required": [
     "id",
     "at",
     "what",
     "undoable"
    ],
    "properties": {
     "id": {
      "type": "string"
     },
     "actor": {
      "type": "string",
      "description": "Who made it."
     },
     "at": {
      "type": "string",
      "format": "date-time"
     },
     "what": {
      "type": "array",
      "items": {
       "type": "string"
      },
      "description": "What changed, in plain language and in the order it was done."
     },
     "undoable": {
      "type": "boolean",
      "description": "Whether the whole set can be reverted."
     },
     "undone_at": {
      "type": "string",
      "format": "date-time",
      "description": "When it was undone. An undone set stays in the log: both events must be visible in it."
     },
     "session": {
      "type": "string",
      "description": "The conversation with the Builder in which the changes were made. Absent for changes made outside a conversation."
     },
     "blocking": {
      "type": "array",
      "items": {
       "type": "string"
      },
      "description": "Why the set can't be undone as a whole — in words for a human. Absent when `undoable`."
     }
    }
   },
   "Graph": {
    "type": "object",
    "description": "The agent as a graph of nodes. Nodes without shared dependencies run IN PARALLEL — this follows from the graph's shape, not from a setting.",
    "properties": {
     "nodes": {
      "type": "array",
      "items": {
       "$ref": "#/components/schemas/GraphNode"
      }
     },
     "edges": {
      "type": "array",
      "items": {
       "$ref": "#/components/schemas/GraphEdge"
      },
      "description": "Data flow: the output of node `from` goes into node `to`."
     }
    }
   },
   "GraphNode": {
    "type": "object",
    "required": [
     "id",
     "type"
    ],
    "properties": {
     "id": {
      "type": "string",
      "description": "Node name: lowercase Latin letters, digits and underscores. Edges, conditions and the trace refer to it, so a rename is a change that shows up in the diff.",
      "example": "draft"
     },
     "type": {
      "type": "string",
      "enum": [
       "model",
       "fetch",
       "code"
      ],
      "description": "`model` — a model call with its own prompt; `fetch` — an HTTP request WITHOUT a model; `code` — a script WITHOUT a model. The list is closed: a new capability is added as a model tool or a channel property, not as a fourth node type."
     },
     "config": {
      "description": "The shape depends on `type`. Parse by it, not by which fields are present.",
      "oneOf": [
       {
        "$ref": "#/components/schemas/ModelNodeConfig"
       },
       {
        "$ref": "#/components/schemas/FetchNodeConfig"
       },
       {
        "$ref": "#/components/schemas/CodeNodeConfig"
       }
      ]
     },
     "condition": {
      "type": "string",
      "example": "nodes.fetch.output != \"0\"",
      "description": "When the node runs; empty = always.\n\n**What you can read:** `nodes.NAME.output`, `nodes.NAME.error`, `state.KEY`, `input`, `trigger`.\n\n**Operators:** `==` `!=` `<` `<=` `>` `>=`, `contains`, `starts_with`, `ends_with`, `is empty`, `is not empty`, `and` / `or` / `not` and parentheses. Strings go in double quotes.\n\n**A condition is a dependency.** A node named in a condition runs EARLIER, even if there's no edge between them: otherwise \"do B if A failed\" would read an empty value, because A is still running in the same layer."
     },
     "on_error": {
      "type": "string",
      "enum": [
       "fail",
       "continue"
      ],
      "description": "`fail` (default) fails the run. `continue` lets it proceed, and the error becomes DATA: the next node branches on it with a condition. It's try/catch without nested blocks."
     },
     "for_each": {
      "type": "string",
      "example": "nodes.plan.output",
      "description": "The node runs ONCE PER ELEMENT of the list (a JSON array) at this path — written in the same language as conditions; `records:SET` — the notebook's cards in that set. Empty — once. Elements are processed a few at a time (a code node — one at a time); an element is visible as `{{item}}` and `{{item.field}}`."
     },
     "keep": {
      "type": "boolean",
      "description": "In a long-task pass, the node's output (when iterating — each element's output) is saved in the task's notebook (the «кроки завдань» (\"task steps\") set), and the next pass takes it from there instead of redoing it: research that didn't fit into one pass continues from what has already been found. Outside a task pass it does nothing."
     }
    }
   },
   "GraphEdge": {
    "type": "object",
    "required": [
     "from",
     "to"
    ],
    "properties": {
     "from": {
      "type": "string"
     },
     "to": {
      "type": "string"
     },
     "as": {
      "type": "string",
      "description": "The name under which the input is visible to the receiving node; empty = the source node's name. Needed when a node takes two inputs of the same kind: the prompt should refer to them by role, not by whatever the neighbor happened to be called."
     }
    }
   },
   "GraphDiff": {
    "type": "object",
    "required": [
     "added",
     "removed",
     "moved",
     "changed"
    ],
    "description": "What changed for customers. `moved` — changed connections: the same node, but its output now goes somewhere else. `changed` — the node stayed in place but now behaves differently: prompt, tool list, condition, error handling. The comparison uses the config's normal form, so a rewrite with a different field order doesn't count as a change.",
    "properties": {
     "added": {
      "type": "array",
      "items": {
       "type": "string"
      }
     },
     "removed": {
      "type": "array",
      "items": {
       "type": "string"
      }
     },
     "moved": {
      "type": "array",
      "items": {
       "type": "string"
      }
     },
     "changed": {
      "type": "array",
      "items": {
       "type": "string"
      },
      "description": "Nodes changed internally. The most important of the four fields: the graph's skeleton doesn't move, yet the behavior changes."
     },
     "text_only": {
      "type": "boolean",
      "description": "Only the prompts' wording changed, nothing else. Such a change falls on this side of the consent threshold: it's a change of wording, not of structure, and asking about it on a par with reshaping the flow would teach people to click \"yes\" without reading."
     }
    }
   },
   "MCPServer": {
    "type": "object",
    "required": [
     "alias",
     "url"
    ],
    "properties": {
     "alias": {
      "type": "string",
      "description": "Short name the model uses to call the server (\"jira\", \"github\").",
      "example": "jira"
     },
     "url": {
      "type": "string"
     },
     "header": {
      "type": "string",
      "description": "Name of the authorization header, if the server requires one."
     },
     "token": {
      "type": "string",
      "writeOnly": true,
      "description": "Header value. Accepted but NEVER RETURNED — the same rule as for agent keys: you can see that the server is connected, not with what."
     }
    }
   },
   "GraphEstimate": {
    "type": "object",
    "required": [
     "model_calls",
     "seconds",
     "parallel",
     "nodes"
    ],
    "description": "Worst case based on the graph's SHAPE. Only what has already run can be measured, and the warning is needed beforehand — so the estimate is deliberately high: one that underestimates is worse than none.",
    "properties": {
     "model_calls": {
      "type": "integer",
      "description": "How many model calls the graph allows: the sum of the iteration caps across model nodes. This is what turns \"I'll add one more check\" into a visible decision about money."
     },
     "seconds": {
      "type": "integer",
      "description": "The longest chain. Independent branches are NOT added up: three models fed from one input take the time of the slowest one, not three times as long."
     },
     "parallel": {
      "type": "integer",
      "description": "The widest layer: how many nodes run at once. Multiplies peak load, not time."
     },
     "nodes": {
      "type": "integer"
     }
    }
   },
   "AgentSnapshot": {
    "type": "object",
    "required": [
     "number",
     "at",
     "parts"
    ],
    "properties": {
     "number": {
      "type": "integer"
     },
     "at": {
      "type": "string",
      "format": "date-time"
     },
     "reason": {
      "type": "string",
      "description": "Why the snapshot was taken: «перед розмовою» (\"before the conversation\"), «вручну» (\"manually\")."
     },
     "missing": {
      "type": "array",
      "items": {
       "type": "string"
      },
      "description": "Parts that could NOT be captured. A snapshot with a gap is still useful, but a restore won't touch those parts."
     },
     "set": {
      "type": "string",
      "description": "The change set BEFORE which the point was taken. Empty for manual snapshots. This is what makes \"restore it to how it was before this conversation\" a precise question."
     },
     "parts": {
      "type": [
       "object",
       "null"
      ],
      "additionalProperties": true,
      "description": "The state of each captured part, keyed by its name. A part's content is an internal format — don't parse it. In the snapshot list it's `null`: part bodies aren't returned there."
     }
    }
   },
   "SnapshotRestored": {
    "type": "object",
    "description": "Three separate answers instead of a single \"done\": restored, failed, and what wasn't in the snapshot.",
    "properties": {
     "number": {
      "type": "integer"
     },
     "at": {
      "type": "string",
      "format": "date-time"
     },
     "done": {
      "type": "array",
      "items": {
       "type": "string"
      },
      "description": "Restored parts."
     },
     "failed": {
      "type": "array",
      "items": {
       "type": "string"
      },
      "description": "Couldn't be restored, with the reason. Worth retrying."
     },
     "missing": {
      "type": "array",
      "items": {
       "type": "string"
      },
      "description": "This wasn't in the snapshot — left as it is now. Retrying is pointless."
     },
     "notes": {
      "type": "array",
      "items": {
       "type": "string"
      },
      "description": "What the snapshot REMEMBERS but doesn't restore, and what's left to a human. Today that's actions: the list can be remembered but not restored — an action's access key disappears together with the action, and it isn't stored in the clear anywhere. So a restore names the actions added after this point (they remain) and the actions that no longer exist (they'll have to be added again). Empty when nothing diverged."
     },
     "not_covered": {
      "type": "array",
      "items": {
       "type": "string"
      },
      "description": "What the snapshot doesn't cover by design: access keys, connected channels, knowledge."
     }
    }
   },
   "SkillParam": {
    "type": "object",
    "required": [
     "name",
     "in",
     "type",
     "description",
     "required"
    ],
    "description": "One argument the model fills in when making the call.",
    "properties": {
     "name": {
      "type": "string"
     },
     "in": {
      "type": "string",
      "enum": [
       "",
       "body",
       "query",
       "path",
       "header",
       "files"
      ],
      "description": "Where the value goes in the request. Empty — by method: POST→body, GET→query."
     },
     "type": {
      "type": "string",
      "enum": [
       "string",
       "number",
       "integer",
       "boolean"
      ]
     },
     "description": {
      "type": "string"
     },
     "required": {
      "type": "boolean"
     },
     "schema": {
      "type": "object",
      "additionalProperties": true,
      "description": "The parameter's own JSON Schema, INSTEAD of the one derived from type. For lists and nested objects that type can't describe."
     },
     "always": {
      "type": "string",
      "description": "What the parameter carries on EVERY call, whatever the model wrote. Body only."
     },
     "files_as": {
      "type": "string",
      "enum": [
       "content",
       "link"
      ],
      "description": "Only for a parameter with `in: files` — how the conversation's files are sent in the request. `content` (default) — as content: a list of `{name, content (base64), content_type}`. `link` — as temporary signed links: a list of `{name, url, content_type, size, expires_at}`; `url` is valid for a day and opens without a key (`GET /v1/files/{token}`)."
     }
    }
   },
   "SkillParamInput": {
    "type": "object",
    "description": "An action parameter in the request body: only the name is required; the server fills in the rest.",
    "properties": {
     "name": {
      "type": "string"
     },
     "in": {
      "type": "string",
      "enum": [
       "",
       "body",
       "query",
       "path",
       "header",
       "files"
      ],
      "description": "Where the value goes in the request. Empty — by method: POST→body, GET→query."
     },
     "type": {
      "type": "string",
      "enum": [
       "string",
       "number",
       "integer",
       "boolean"
      ]
     },
     "description": {
      "type": "string"
     },
     "required": {
      "type": "boolean"
     },
     "schema": {
      "type": "object",
      "additionalProperties": true,
      "description": "The parameter's own JSON Schema, INSTEAD of the one derived from type. For lists and nested objects that type can't describe."
     },
     "always": {
      "type": "string",
      "description": "What the parameter carries on EVERY call, whatever the model wrote. Body only."
     },
     "files_as": {
      "type": "string",
      "enum": [
       "content",
       "link"
      ],
      "description": "Only for a parameter with `in: files` — how the conversation's files are sent in the request. `content` (default) — as content: a list of `{name, content (base64), content_type}`. `link` — as temporary signed links: a list of `{name, url, content_type, size, expires_at}`; `url` is valid for a day and opens without a key (`GET /v1/files/{token}`)."
     }
    },
    "required": [
     "name"
    ]
   },
   "NewSkill": {
    "type": "object",
    "description": "An action you're asking to create. Differs from Skill in that it has headers (access keys) and no IDs.",
    "properties": {
     "name": {
      "type": "string",
      "description": "Latin letters, digits, _ and -, up to 64 characters."
     },
     "description": {
      "type": "string"
     },
     "method": {
      "type": "string",
      "enum": [
       "GET",
       "POST"
      ],
      "default": "POST"
     },
     "url": {
      "type": "string",
      "description": "http(s). May contain {name} — parameters with in=path are substituted there."
     },
     "headers": {
      "type": "object",
      "additionalProperties": {
       "type": "string"
      },
      "description": "Headers, including authorization. A {{secrets.NAME}} value is substituted from the agent's key store. Nobody can read back what's stored."
     },
     "params": {
      "type": "array",
      "items": {
       "$ref": "#/components/schemas/SkillParamInput"
      }
     },
     "admin_only": {
      "type": "boolean"
     },
     "timeout_sec": {
      "type": "integer",
      "minimum": 0,
      "maximum": 300
     },
     "async": {
      "$ref": "#/components/schemas/SkillAsync"
     },
     "token_auth": {
      "$ref": "#/components/schemas/SkillTokenAuth"
     },
     "known_only": {
      "type": "boolean",
      "description": "The action is only for visitors the site has identified (passed an identifier — the `{{user_token}}` substitution). For a guest it isn't in the set at all: the assistant doesn't see it and won't call it. This is not proof of identity — the identifier is written by the page."
     },
     "status_label": {
      "type": "string",
      "description": "What the person sees in the window while the action is running (\"Building the diagram…\"). Up to 80 characters, one line; empty — the window's generic line."
     },
     "expose_result": {
      "type": "boolean",
      "description": "The action's raw result and its arguments are passed to the page code (`actions[].args`, `actions[].result`, the window event `action_result`). Off by default."
     },
     "client": {
      "type": "boolean",
      "description": "A page tool: the site itself executes it (a `YouSelfBot.registerTool` handler), not the server. It has no URL and no keys; the model gets it only in a conversation where the page has registered a handler with this name."
     }
    },
    "required": [
     "name",
     "url"
    ]
   },
   "SkillCandidate": {
    "type": "object",
    "required": [
     "name",
     "description",
     "method",
     "url",
     "params",
     "admin_only",
     "known_only",
     "expose_result",
     "client"
    ],
    "description": "An action the server found (in an API description, in a file, on a site) and suggests adding. Same shape as the `POST /skills` body: you can send the candidate there as is.",
    "properties": {
     "name": {
      "type": "string",
      "description": "Latin letters, digits, _ and -, up to 64 characters."
     },
     "description": {
      "type": "string"
     },
     "method": {
      "type": "string",
      "enum": [
       "GET",
       "POST"
      ],
      "default": "POST"
     },
     "url": {
      "type": "string",
      "description": "http(s). May contain {name} — parameters with in=path are substituted there."
     },
     "params": {
      "type": "array",
      "items": {
       "$ref": "#/components/schemas/SkillParam"
      }
     },
     "admin_only": {
      "type": "boolean"
     },
     "timeout_sec": {
      "type": "integer",
      "minimum": 0,
      "maximum": 300
     },
     "async": {
      "$ref": "#/components/schemas/SkillAsync"
     },
     "token_auth": {
      "$ref": "#/components/schemas/SkillTokenAuth"
     },
     "needs_approval": {
      "type": "boolean",
      "description": "A HUMAN performs the action, not the agent: the call becomes a card in the approval queue, and nothing happens in the world until the owner clicks \"Send\". For actions that reach someone outside — an email to a customer, a post, a payment."
     },
     "outreach": {
      "type": "object",
      "nullable": true,
      "description": "The action is OUTREACH to a person: the platform checks the stop list and rate limits before every call, and a refusal here stops the call rather than asking the model to be careful. Absent field = the action is not outreach.",
      "properties": {
       "param": {
        "type": "string",
        "description": "Name of the parameter that holds the recipient (to, phone, client_id — as in your API). The platform doesn't guess it: a guess would break silently, and the stop list would stop working while still showing as enabled."
       },
       "per_day": {
        "type": "integer",
        "description": "How many outreach contacts through this action are allowed per day. 0 = no limit."
       },
       "every_hours": {
        "type": "integer",
        "description": "Minimum interval between outreach contacts to ONE recipient, in hours. 0 = no limit."
       },
       "quota_param": {
        "type": "string",
        "description": "Name of the parameter that holds WHO the outreach comes FROM: an account, a page, a sender number. Then per_day is counted for each of them SEPARATELY.\n\nThis is needed because accounts get banned, not actions: one \"post to group\" action and three accounts means three separate limits. A single limit shared by all three either stops work three times too early or exceeds the safe rate on each account threefold, and no action setting can fix that.\n\nEmpty = the limit is counted for the action as a whole."
       }
      }
     },
     "connection": {
      "type": "string",
      "description": "Name of the connection this action acts on behalf of (see \"Dashboard · Connected accounts\"). Empty = the action works with its own headers, i.e. on behalf of the agent's OWNER; set = on behalf of whoever gave consent in the service. The token isn't copied here — it lives for a few minutes and refreshes itself."
     },
     "connection_header": {
      "type": "string",
      "description": "Where to put the token. Empty = Authorization."
     },
     "connection_prefix": {
      "type": "string",
      "description": "Value prefix. Empty for Authorization = \"Bearer \"."
     },
     "order": {
      "type": "string",
      "enum": [
       "woocommerce",
       "prom",
       "horoshop"
      ],
      "description": "The shop engine whose orders this action reads (\"where is my order\"). In that case the shop API response does NOT go to the model: the platform matches the phone or email the buyer gave against the order and returns only the status, date, delivery and tracking number (TTN). The model calls such an action with `order_number` and `contact`. Set only by a ready-made connection (`POST …/skills/presets`); absent field — a regular action."
     },
     "known_only": {
      "type": "boolean",
      "description": "The action is only for visitors the site has identified (passed an identifier — the `{{user_token}}` substitution). For a guest it isn't in the set at all: the assistant doesn't see it and won't call it. This is not proof of identity — the identifier is written by the page."
     },
     "status_label": {
      "type": "string",
      "description": "What the person sees in the window while the action is running (\"Building the diagram…\"). Up to 80 characters, one line; empty — the window's generic line."
     },
     "expose_result": {
      "type": "boolean",
      "description": "The action's raw result and its arguments are passed to the page code (`actions[].args`, `actions[].result`, the window event `action_result`). Off by default."
     },
     "client": {
      "type": "boolean",
      "description": "A page tool: the site itself executes it (a `YouSelfBot.registerTool` handler), not the server. It has no URL and no keys; the model gets it only in a conversation where the page has registered a handler with this name."
     }
    }
   },
   "SkillTest": {
    "type": "object",
    "required": [
     "status",
     "reached",
     "duration_ms",
     "response",
     "bot_sees",
     "failed",
     "timed_out",
     "timeout_sec",
     "truncated",
     "bytes"
    ],
    "description": "One real call of an action outside a conversation. Separates the raw exchange from what the model will take from it: an API may respond 200 with a body the bot can do nothing with.",
    "properties": {
     "status": {
      "type": "integer",
      "description": "0 — there was no response at all."
     },
     "reached": {
      "type": "boolean",
      "description": "false — the service wasn't reached (DNS, TLS, timeout), as opposed to \"the service refused\"."
     },
     "duration_ms": {
      "type": "integer"
     },
     "response": {
      "type": "string",
      "description": "The body as the service returned it, truncated to the limit."
     },
     "bot_sees": {
      "type": "string",
      "description": "What goes into the model's context. Exactly that — not a paraphrase."
     },
     "failed": {
      "type": "boolean",
      "description": "The bot will treat this call as failed."
     },
     "timed_out": {
      "type": "boolean",
      "description": "The service didn't respond within the time allotted to THIS action. Kept separate from reached=false on purpose: the URL is right, the key is right, and the advice \"check the URL\" would send the owner off to rewrite something that works."
     },
     "timeout_sec": {
      "type": "integer",
      "description": "How much time the action actually had — not 0, but the number the owner can change."
     },
     "truncated": {
      "type": "boolean",
      "description": "The service returned more than fits into the model in one pass. A first page shown as the whole response reads as the whole response."
     },
     "bytes": {
      "type": "integer",
      "description": "How many bytes the service actually returned."
     }
    }
   },
   "TaskFile": {
    "type": "object",
    "required": [
     "name"
    ],
    "description": "A file produced by a long job. Already stored on our side and available to the visitor — a third-party service's URLs can only be read with the owner's key, so they can't be handed to the browser.",
    "properties": {
     "name": {
      "type": "string"
     },
     "url": {
      "type": "string",
      "description": "Empty when the file couldn't be fetched. The card then names it without a link — the job really did produce it."
     }
    }
   },
   "AgentPreset": {
    "type": "object",
    "required": [
     "id",
     "title",
     "description",
     "shape",
     "next_steps"
    ],
    "description": "An agent preset: personality and flow shape. The shape is what sets presets apart from one another — the Builder fills in the industry during the conversation.",
    "properties": {
     "id": {
      "type": "string"
     },
     "title": {
      "type": "string"
     },
     "description": {
      "type": "string"
     },
     "shape": {
      "type": "string",
      "description": "The flow shape in plain language: \"a single node\", \"doer and critic\"."
     },
     "next_steps": {
      "type": "array",
      "items": {
       "type": "string"
      },
      "description": "What the preset doesn't provide and what will have to be added."
     }
    }
   },
   "WorkspaceBot": {
    "type": "object",
    "properties": {
     "id": {
      "type": "string"
     },
     "name": {
      "type": "string"
     },
     "publishable_key": {
      "type": "string",
      "description": "Publishable key `pk_…` — the one that goes into the widget. Read it here; there's no separate endpoint for a single agent."
     },
     "secret_key": {
      "type": "string",
      "description": "Secret key, MASKED (`sk_••••1234`). It's returned in full only once — when the agent is created and when the key is reissued."
     },
     "allowed_origins": {
      "type": "array",
      "items": {
       "type": "string"
      },
      "description": "Domains the widget is allowed on. Empty = allowed everywhere."
     }
    },
    "required": [
     "id",
     "name",
     "publishable_key",
     "secret_key",
     "allowed_origins"
    ]
   },
   "Usage": {
    "type": "object",
    "properties": {
     "conversations": {
      "type": "integer",
      "description": "Conversations in the current period — a counter for display, not a limit."
     },
     "credits_used": {
      "type": "integer",
      "description": "Everything spent in the period, including what has already been deducted from a purchased pack."
     },
     "credits_limit": {
      "type": "integer",
      "description": "-1 = unlimited."
     },
     "credits_warn_at": {
      "type": "integer",
      "description": "0 = no warning (unlimited plan)."
     },
     "credits": {
      "type": "integer",
      "description": "Prepaid allowance on top of the plan — the balance AFTER deductions. Left before a stop: max(0, credits_limit − credits_used) + credits."
     },
     "input_tokens": {
      "type": "integer"
     },
     "output_tokens": {
      "type": "integer"
     },
     "cache_read_tokens": {
      "type": "integer"
     },
     "cost_usd": {
      "type": "number"
     },
     "cost_cap_usd": {
      "type": "number",
      "description": "0 = no cap."
     },
     "cost_warn_usd": {
      "type": "number"
     }
    },
    "description": "Spent in the current period. Both limits — conversations and money — are deliberately here together: either one can stop the bot.\n\n**The period here is a CALENDAR MONTH (UTC), not your subscription month.** Counters reset on the first of the month, regardless of the payment date; `subscription.current_period_end` runs on its own clock — from the day of payment. So a subscription bought on the 20th gets a full monthly allowance for the rest of the month and a new full allowance on the first. This deliberately favors the owner, but the two numbers on screen are counted by different clocks, and showing them side by side without this explanation is a bad idea."
   },
   "Role": {
    "type": "string",
    "description": "Role in the workspace. `owner` — money, team membership and deleting agents. `admin` — everything about agents except what's reserved for the owner. `member` — conversations and replies to customers.",
    "enum": [
     "owner",
     "admin",
     "member"
    ]
   },
   "BotConfig": {
    "type": "object",
    "properties": {
     "purpose": {
      "type": "string",
      "description": "What this agent is for. Sets the defaults for the rest of its personality."
     },
     "role": {
      "type": "string",
      "description": "Who it is (\"assistant for the Smak restaurant\")."
     },
     "tone": {
      "type": "string"
     },
     "language": {
      "type": "string",
      "description": "`auto` = mirror the language of the person it's talking to."
     },
     "off_topic": {
      "type": "string",
      "description": "What to do with questions outside the business's topic."
     },
     "refusal_text": {
      "type": "string",
      "description": "What to reply when there's no answer."
     },
     "system_prompt": {
      "type": "string",
      "description": "A direct replacement for the instructions. Takes precedence over the other personality fields."
     },
     "greeting": {
      "type": "string"
     },
     "starters": {
      "type": "array",
      "items": {
       "type": "string"
      },
      "description": "Suggested first questions."
     },
     "collect_leads_off": {
      "type": "boolean",
      "description": "DISABLES the \"Leave your contact\" form in the window. The form is on by default: collecting contacts is the most common reason a site assistant is installed."
     },
     "widget_title": {
      "type": "string"
     },
     "widget_accent": {
      "type": "string",
      "description": "Accent color (hex)."
     },
     "widget_position": {
      "type": "string",
      "enum": [
       "",
       "bottom-right",
       "bottom-left",
       "top-right",
       "top-left"
      ],
      "description": "The screen corner where the chat button and window sit. Empty — not chosen: bottom right."
     },
     "widget_theme": {
      "type": "string",
      "enum": [
       "",
       "auto",
       "light",
       "dark"
      ],
      "description": "Empty — not chosen: `auto` applies."
     },
     "widget_light": {
      "$ref": "#/components/schemas/WidgetColors"
     },
     "widget_dark": {
      "$ref": "#/components/schemas/WidgetColors"
     },
     "fit_site_off": {
      "type": "boolean"
     },
     "page_context_off": {
      "type": "boolean",
      "description": "DISABLES reading the page the window is on (URL without the query string, title, and on a product card — name, price, availability). By default the window sees the page."
     },
     "visitor_memory_off": {
      "type": "boolean",
      "description": "DISABLES memory of a recognized visitor. Memory is on by default (only where the owner's site has signed who the visitor is)."
     },
     "semantic_cache_off": {
      "type": "boolean",
      "description": "DISABLES answer reuse. By default the cache is on and saves credits."
     },
     "disabled_sources": {
      "type": "array",
      "items": {
       "type": "string"
      },
      "description": "Knowledge topics temporarily removed from search. The topics' text is kept; the agent filters them out after the search."
     },
     "operator_disabled": {
      "type": "boolean",
      "description": "Escalation to a human is disabled."
     },
     "draft_preview_off": {
      "type": "boolean"
     },
     "auto_translate": {
      "type": "boolean"
     },
     "handoff_webhook_url": {
      "type": "string",
      "description": "Where to send escalations. This is the URL the section on delivery signatures refers to."
     },
     "handoff_webhook_secret": {
      "type": "string",
      "description": "The key our deliveries to `handoff_webhook_url` are signed with. Issued automatically on first read."
     },
     "alert_email": {
      "type": "string"
     },
     "alert_webhook_url": {
      "type": "string"
     },
     "alert_webhook_secret": {
      "type": "string",
      "description": "Signing key for incident notifications."
     },
     "alert_telegram_off": {
      "type": "boolean"
     },
     "visitor_identity_secret": {
      "type": "string",
      "description": "The key that signs visitor identity confirmations. MASKED (`idsec_…`): returned in full only when reissued."
     },
     "peers": {
      "type": "array",
      "items": {
       "type": "string"
      },
      "description": "Agents in the same workspace this one can delegate work to. Absent if there's nobody to delegate to."
     },
     "monthly_credit_cap": {
      "type": "integer",
      "minimum": 0,
      "description": "How many credits THIS PARTICULAR agent may spend in a calendar month. 0 (default) = no cap.\n\nNot the same as the plan limit: that one applies to the workspace and stops everyone equally. This one stops just one agent — the one doing the spending — while the other agents keep working. It's needed where an agent works on its own at night: if it falls into a loop, it would otherwise drain the whole workspace's allowance, and in the morning the bot that answers customers goes silent.\n\nSpending is counted from the run log — the same numbers shown on the run card. The minimum is 1000: below that the agent stops before its first reply."
     },
     "suggestions_off": {
      "type": "boolean",
      "description": "`true` → the assistant does NOT offer options for the next message under its reply. Default `false`: the options are shown."
     },
     "voice_off": {
      "type": "boolean",
      "description": "`true` → voice messages in messengers are NOT transcribed: a person who sends a voice message is asked \"Please type your message.\" Default `false`: the platform turns voice messages up to 10 minutes long into text before the agent's run (credits per minute of audio)."
     },
     "voice_reply": {
      "type": "string",
      "enum": [
       "",
       "owner",
       "all"
      ],
      "description": "Who the agent replies to by voice in messengers: `owner` — only the owner, `all` — everyone; empty — in text (default)."
     },
     "widget_note": {
      "type": "string",
      "description": "A custom note under the window's input field. Empty = the default one (\"The assistant can make mistakes. Double-check what matters.\"), unless `widget_note_off` is `true`."
     },
     "widget_note_off": {
      "type": "boolean",
      "description": "`true` → there's no note under the input field at all."
     },
     "contacts": {
      "type": "array",
      "maxItems": 4,
      "items": {
       "$ref": "#/components/schemas/ContactButton"
      },
      "description": "Buttons for contacting the company's people. The window shows them under a reply when the assistant can't help on its own, and after a \"not helpful\" rating."
     },
     "widget_design": {
      "$ref": "#/components/schemas/WidgetDesign"
     },
     "widget_css": {
      "type": "string",
      "maxLength": 20000,
      "description": "A custom window style — plain CSS, written however you like, on top of the closed `widget_design` set. It applies only inside the window (which lives in its own Shadow DOM), so it doesn't affect the owner's pages.\n\nTwo limits. No code: scripts in any form, `@import`, rules about `:host` and images not from `https://` are rejected — the reason comes back in `refused`. And the window checks itself: if, while collapsed, the style covered the page, the window removes it and reports this in the browser console.\n\nThe platform no longer guarantees text readability with a custom style.\n\nThe \"Made with youselfbot.com\" label at the bottom of the window can't be removed: it can't be hidden, covered or replaced. The server rejects a style that names its class (`.madeby`) or hides the whole window, and the window itself checks after every change that the label is visible, and removes any custom style or custom elements that touched it."
     },
     "widget_texts": {
      "type": "object",
      "additionalProperties": {
       "type": "string"
      },
      "description": "Custom labels in the window instead of the default ones. Keys: `placeholder`, `send`, `attach`, `open`, `close`, `fresh`, `fresh_ask`, `fresh_yes`, `fresh_no` (the question before erasing the conversation, and its buttons), `attach_photo`, `attach_file` (the choice on a phone: photo or file), `attach_drop` (the hint while a file is held over the window), `move_back` (the \"Move the window back\" button), `human`, `lead`, `thinking`, `working`, `op_typing`, `viewing`, `buy`, `similar`, `cheaper`, `variants`, `compare`, `lead_name`, `lead_contact`, `lead_note`, `lead_send`, `lead_done`, `called`, `joined`, `thanks`, `continue` (the \"Continue in Telegram\" button), `state_bot`, `state_waiting`, `state_operator`, `state_resolved`. The window's refusals and errors are labels too (a site in another language should show them in its own language): `attach_sending`, `attach_too_big`, `attach_image_big`, `attach_type`, `attach_many`, `attach_full`, `attach_failed`, `compare_more`, `gone`, `lead_need`, `rate_failed`, `continue_gone`, `continue_later`, `closed`, `err_rate_limited`, `err_quota_exceeded`, `err_llm_unavailable`, `err_llm_overloaded`, `err_service_unavailable`, `err_internal_error`, `err_payload_too_large`, `err_session_taken`, `err_not_found`, `err_bad_request`, `err_offline`, `err_network`, `err_stream_broken`, `grow`, `shrink`, `teaser_close`, `unread`, `rate_up`, `rate_down`, `who_you`, `who_bot`, `who_operator`, `again`. The rest of the window's strings: `log_label`, `card_title`, `card_running`, `card_done`, `card_failed`, `card_unknown`, `human_ask`, `reach_hello`, `reach_question`, `reach_page`, `reach_subject`, `reach_label`, `say_similar`, `say_cheaper`, `say_compare`, `say_and`, `file_name`, `copied`, `compare_drop`, `goods`, `attach_remove`, `attached` (the message feed's name for screen readers, the long-action card, the offer to call a human, the draft for a messenger, the messages sent by buttons on product cards, small captions). Installation errors (key, domain) and \"no connection\" at startup stay default: they're shown before the settings have arrived."
     },
     "training": {
      "type": "boolean",
      "description": "Training mode: `true` → a human sees every agent reply to a customer first (`GET …/training/drafts`), and actions with external consequences wait together with the reply. Default `false` (field absent): the mode changes who answers customers. The owner's own conversations with the assistant aren't covered by the mode."
     },
     "training_idle": {
      "type": "string",
      "enum": [
       "",
       "send",
       "later"
      ],
      "description": "Training mode: what to do when the operator hasn't replied within `training_idle_min` minutes. Empty (field absent) — wait; `send` — send the draft on its own (only a draft without actions); `later` — tell the customer we'll reply later."
     },
     "training_idle_min": {
      "type": "integer",
      "description": "Training mode: after how many minutes to consider that the operator hasn't replied (1…1440). `0` or absent — the default 5."
     },
     "widget_items": {
      "type": "array",
      "maxItems": 24,
      "items": {
       "$ref": "#/components/schemas/WidgetItem"
      },
      "description": "Custom elements in the window: buttons, links, lines of text and images in named slots. The \"Made with youselfbot.com\" label at the bottom of the window can't be removed: it can't be hidden, covered or replaced. The server rejects a style that names its class (`.madeby`) or hides the whole window, and after every change the window itself checks that the label is visible and drops any custom style or custom elements that affected it."
     },
     "widget_layout": {
      "$ref": "#/components/schemas/WidgetLayout"
     },
     "widget_icons": {
      "type": "object",
      "additionalProperties": {
       "type": "string",
       "maxLength": 4000
      },
      "description": "Custom icons instead of the built-in ones: the key is which icon, the value is a single SVG with shapes only (`path`, `circle`, `rect`, `line`, `polyline`, `polygon`, `ellipse`, `g`), no scripts, links, embedded styles or external images. Keys: `launcher`, `launcher_close`, `teaser`, `teaser_close`, `close`, `fresh`, `grow`, `shrink`, `chat_more`, `chats`, `move_back`, `send`, `attach`, `attached`, `remove`, `human`, `lead`, `continue`, `rate_up`, `rate_down`, `typing`, `note`, `buy`, `photo`, `check`, `contact_telegram`, `contact_viber`, `contact_whatsapp`, `contact_phone`, `contact_email`, `contact_link`. The chat button icon (`launcher`) is stored in `widget_design.launcher_svg`."
     },
     "handoff_notify_off": {
      "type": "boolean",
      "description": "`true` — don't notify anyone outside the dashboard when a customer asks for a human (Conversations and the operator webhook still get it). Default `false`: notifications go everywhere there is a route to — see `GET …/notices`."
     },
     "handoff_mail_off": {
      "type": "boolean",
      "description": "`true` — don't email the owner about requests at their account address. Default `false`."
     },
     "handoff_remind_min": {
      "type": "integer",
      "description": "After how many minutes to send a reminder about a request nobody has taken (and how long after the previous reminder to send the next one). `0` or absent — the default of 10; `-1` — no reminders; maximum 720."
     },
     "handoff_remind_times": {
      "type": "integer",
      "description": "How many times to send a reminder about a request nobody has taken. `0` or absent — the default of one; maximum 5. To turn reminders off, use `handoff_remind_min: -1`."
     },
     "quiet_hours": {
      "type": "string",
      "description": "Quiet hours for request notifications: `22:00-08:00` (Kyiv time; for another time zone, add it as a third word: `22:00-08:00 Europe/Warsaw`). Empty or absent — no quiet hours."
     },
     "digest_off": {
      "type": "boolean",
      "description": "`true` — don't send the owner the digest. Default `false`: it's sent on schedule whenever, since the previous one, customers asked things that have no answer."
     },
     "digest_when": {
      "type": "string",
      "description": "When to send the digest: `mon 09:00` (day of the week: mon…sun), several days separated by commas — `mon,thu 18:00`, or `daily 18:30`; another time zone as a third word. Empty or absent — the default `mon 09:00`."
     },
     "digest_to": {
      "type": "string",
      "enum": [
       "",
       "chat",
       "mail"
      ],
      "description": "Where to send the digest: `chat` — only to the owner's linked chat, `mail` — only by email; empty or absent — everywhere there is a route to."
     },
     "digest_lang": {
      "type": "string",
      "enum": [
       "",
       "uk",
       "en"
      ],
      "description": "Digest language: `uk` or `en`; empty or absent — not chosen, and the digest is sent in the language of the owner's account."
     },
     "digest_size": {
      "type": "integer",
      "description": "How many of the most frequent questions to list in the digest. `0` or absent — the default of 5; maximum 50."
     },
     "widget_lang": {
      "type": "string",
      "description": "The window's primary language: the language `greeting`, `starters`, `widget_texts` and the other primary texts are written in. Empty — not specified.",
      "example": "uk"
     },
     "widget_lang_fixed": {
      "type": "boolean",
      "description": "`true` — the window doesn't pick a language based on the visitor's page and browser."
     },
     "widget_langs": {
      "type": "object",
      "additionalProperties": {
       "$ref": "#/components/schemas/WidgetLangSet"
      },
      "description": "Window texts in other languages: language code → text set."
     },
     "widget_hide_on": {
      "type": "array",
      "items": {
       "type": "string"
      },
      "description": "URL patterns of pages where the window doesn't appear (`/app`, `/docs/*`)."
     },
     "identity_verify_url": {
      "type": "string",
      "description": "The owner's server that verifies the visitor's token (`data-user-token`, `identify()`): the platform sends a POST `{\"token\", \"agent\"}` signed with `X-YouSelfBot-Signature: sha256=…` (an HMAC of the body with the agent's signing key) and expects 200 with `{\"valid\": true, \"user_id\": \"…\"}`. When set, only a verified token makes the person identified (`{{user_token}}` in actions, `known_only` actions, memory); an unverified or rejected token, or a server failure, means a guest. The response is cached: \"yes\" for 5 minutes, \"no\" for one minute. `https://` only."
     }
    },
    "description": "The agent's character and the window's appearance — the same settings `PATCH /config` edits. Field names match `BotConfigPatch`, except `clear` (see its description)."
   },
   "DevConnection": {
    "type": "object",
    "properties": {
     "connected": {
      "type": "boolean",
      "description": "The connection is configured and enabled."
     },
     "key_hint": {
      "type": "string",
      "description": "The tail of the account key (`bvk_…f8a2`) — just enough to tell which key was entered. The key itself is never returned. Absent until a key is set."
     },
     "max_concurrent": {
      "type": "integer",
      "description": "How many developer tasks can run at the same time."
     },
     "max_per_day": {
      "type": "integer"
     },
     "last_error": {
      "type": "string",
      "description": "The most recent failure. Absent if there have been no failures."
     },
     "last_error_at": {
      "type": "string",
      "format": "date-time",
      "description": "When it happened. Absent together with `last_error`."
     }
    },
    "required": [
     "connected",
     "max_concurrent",
     "max_per_day"
    ]
   },
   "InboxFrame": {
    "type": "object",
    "properties": {
     "threads": {
      "type": "array",
      "items": {
       "$ref": "#/components/schemas/Thread"
      },
      "description": "The FIRST PAGE of requests, newest first — the same amount as `GET /threads` without a cursor. Not present in every frame: a frame that only reports \"customer is typing\" doesn't carry it, and the previous list stays valid. For further pages, use the same pagination as in REST."
     },
     "typing": {
      "type": "array",
      "items": {
       "type": "string"
      },
      "description": "session_id of the conversations where the customer is typing RIGHT NOW. Present in EVERY frame."
     },
     "drafts": {
      "type": "object",
      "additionalProperties": {
       "type": "string"
      },
      "description": "session_id → what the customer is typing but hasn't sent yet. Present in every frame; empty if draft preview is turned off."
     },
     "training_waiting": {
      "type": "integer",
      "description": "How many training-mode drafts are waiting for a human. Sent in frames that carry `threads`. Conversations with drafts are handled by the assistant, so they aren't among the requests: when this number changes, re-read `GET …/training/drafts`. The field is absent when the build has no training mode or the queue couldn't be read."
     }
    }
   },
   "Refusal": {
    "type": "object",
    "properties": {
     "field": {
      "type": "string",
      "description": "The field name exactly as the client sends it — so the form can highlight that specific row. Empty only where the refusal isn't about a particular field."
     },
     "reason": {
      "type": "string",
      "description": "A ready-made sentence for a human. Show it as is — it was written to be shown."
     }
    },
    "required": [
     "field",
     "reason"
    ]
   },
   "Attachment": {
    "type": "object",
    "properties": {
     "id": {
      "type": "string"
     },
     "name": {
      "type": "string",
      "description": "The file name as the visitor named it."
     },
     "content_type": {
      "type": "string"
     },
     "size": {
      "type": "integer",
      "description": "Size in bytes."
     },
     "at": {
      "type": "string",
      "format": "date-time",
      "description": "When it was sent — use this to place it in the timeline."
     },
     "url": {
      "type": "string",
      "description": "File URL."
     }
    },
    "required": [
     "id",
     "name",
     "content_type",
     "size",
     "at",
     "url"
    ]
   },
   "ModelNodeConfig": {
    "type": "object",
    "properties": {
     "system": {
      "type": "string",
      "description": "The system prompt of THIS PARTICULAR node — what makes a \"critic\" different from an \"executor\". Text fields support substitutions: `{{input}}` — the run's input, `{{trigger}}` — what woke it up, `{{nodes.NAME.output}}` and `{{nodes.NAME.error}}` — the result of a neighboring node, `{{state.KEY}}` — the agent's memory, `{{secrets.NAME}}` — a key from the key store (masked in the trace and in the diff)."
     },
     "model": {
      "type": "string",
      "description": "Model identifier; empty = the platform default. A cheaper model is often enough for a critic."
     },
     "tools": {
      "type": "array",
      "items": {
       "type": "string"
      },
      "description": "Which actions the node is allowed to call. `\"*\"` — all of the agent's actions. EMPTY MEANS NONE, not all: a critic node that silently got permission to write to someone else's system is damage nobody will find out about, while a node that lacks a tool will say so in its very first reply."
     },
     "max_loops": {
      "type": "integer",
      "description": "Cap on iterations of this node's \"model ↔ actions\" loop."
     }
    },
    "required": [
     "system"
    ],
    "description": "Config of the `model` node."
   },
   "FetchNodeConfig": {
    "type": "object",
    "properties": {
     "method": {
      "type": "string",
      "description": "Defaults to GET."
     },
     "url": {
      "type": "string",
      "description": "URL. Text fields support substitutions: `{{input}}` — the run's input, `{{trigger}}` — what woke it up, `{{nodes.NAME.output}}` and `{{nodes.NAME.error}}` — the result of a neighboring node, `{{state.KEY}}` — the agent's memory, `{{secrets.NAME}}` — a key from the key store (masked in the trace and in the diff). In watch mode (`watch`) the URL can be left empty — then it and the settings are taken from the run's task: «Стеж за сторінкою: https://…», «Блок: CSS-селектор», «Не зважати: слово; слово» (\"Watch the page: …\", \"Block: CSS selector\", \"Ignore: word; word\")."
     },
     "header": {
      "type": "object",
      "additionalProperties": {
       "type": "string"
      },
      "description": "Request headers. This is where `{{secrets.NAME}}` goes for authorization."
     },
     "body": {
      "type": "string",
      "description": "Request body."
     },
     "timeout_sec": {
      "type": "integer"
     },
     "watch": {
      "$ref": "#/components/schemas/WatchNodeConfig"
     }
    },
    "required": [
     "url"
    ],
    "description": "Config of the `fetch` node — an HTTP request without a model. With `watch` it watches a page: the output is the \"before → after\" diff against the previous check, or empty when nothing has changed."
   },
   "CodeNodeConfig": {
    "type": "object",
    "properties": {
     "runtime": {
      "type": "string",
      "description": "Runtime.",
      "enum": [
       "shell",
       "python"
      ]
     },
     "code": {
      "type": "string",
      "description": "Script. Text fields support substitutions: `{{input}}` — the run's input, `{{trigger}}` — what woke it up, `{{nodes.NAME.output}}` and `{{nodes.NAME.error}}` — the result of a neighboring node, `{{state.KEY}}` — the agent's memory, `{{secrets.NAME}}` — a key from the key store (masked in the trace and in the diff)."
     },
     "secrets": {
      "type": "array",
      "items": {
       "type": "string"
      },
      "description": "Names of the agent's keys that THIS node can see. Permissions in the graph are always per node, not per agent: a script doesn't get the whole key store just because the agent has one. Empty does not mean \"all\"."
     },
     "repo": {
      "type": "string",
      "description": "URL of the repository checked out into /workspace before the script runs. The platform clones it with ITS OWN credentials — no git token ever reaches the sandbox, so the code that runs there has nothing to steal. Empty = an empty working directory."
     },
     "branch": {
      "type": "string",
      "description": "Branch to clone. Empty = the repository's default branch."
     },
     "push_to": {
      "type": "string",
      "description": "Branch to publish the work to after a SUCCESSFUL run. Empty = nothing is published: reading someone else's repository and writing to it have very different consequences. Publishing happens only after a zero exit code, because the output of a script that failed is half the work passed off as finished."
     },
     "deliver": {
      "type": "array",
      "items": {
       "type": "string"
      },
      "description": "Files from the working directory to HAND OVER to a person: a report, a spreadsheet, an image. Paths are relative to the working directory. Each one becomes a link appended to the node's output; the bytes are never put into the model's context. Without this field, a node that builds a file has no way to pass it on — only stdout goes out, and the environment shuts down together with the run."
     },
     "timeout_sec": {
      "type": "integer"
     }
    },
    "required": [
     "code"
    ],
    "description": "Config of the `code` node — a script without a model."
   },
   "SkillAsync": {
    "type": "object",
    "properties": {
     "title": {
      "type": "string",
      "description": "What to show the person while the work is in progress (\"Processing the order\"). Empty — the widget picks a neutral phrase."
     },
     "task_id_field": {
      "type": "string",
      "description": "Where the task ID is in the FIRST response. A dotted path goes deeper: `id`, `data.task_id`, `result.job.id`."
     },
     "status_url": {
      "type": "string",
      "description": "What to poll for this task. Must contain `{id}`. The action's own headers (that is, the owner's keys) are applied here — the visitor's browser never sees them."
     },
     "state_field": {
      "type": "string",
      "description": "Where the status itself is in the status response (\"status\")."
     },
     "done_values": {
      "type": "array",
      "items": {
       "type": "string"
      },
      "description": "Status values that mean \"done\". Compared case-insensitively."
     },
     "fail_values": {
      "type": "array",
      "items": {
       "type": "string"
      },
      "description": "Values that mean \"failed\". A status that isn't in either list is treated as \"still working\" — an unknown status must not turn into a result."
     },
     "result_field": {
      "type": "string",
      "description": "Where the result text is. Optional: without it, the card simply says the work has finished — still better than a chat that went silent."
     },
     "error_field": {
      "type": "string",
      "description": "Where the error text is."
     },
     "progress_field": {
      "type": "string",
      "description": "Where the service says what it's doing RIGHT NOW, in human-readable words."
     },
     "files_field": {
      "type": "string",
      "description": "Where the list of result files is."
     },
     "file_name_field": {
      "type": "string",
      "description": "File name inside a list item."
     },
     "file_url_field": {
      "type": "string",
      "description": "File URL inside a list item."
     }
    },
    "required": [
     "task_id_field",
     "status_url",
     "state_field",
     "done_values",
     "fail_values"
    ],
    "description": "The \"accepting the job now, answering later\" protocol. Field names differ from service to service, but the protocol is the same — so it's described with DATA rather than with code for each integration. Block absent = a regular action."
   },
   "SkillTokenAuth": {
    "type": "object",
    "properties": {
     "url": {
      "type": "string",
      "description": "Where to get the token. Requested with the action's own headers — that's where the owner's account key lives."
     },
     "method": {
      "type": "string",
      "description": "Defaults to POST."
     },
     "token_field": {
      "type": "string",
      "description": "Where the token is in the response: `token`, `data.jwt`."
     },
     "header": {
      "type": "string",
      "description": "Where to put the token in the actual call. Defaults to `Authorization`."
     },
     "prefix": {
      "type": "string",
      "description": "What to put before the token. Defaults to `Bearer `."
     },
     "scope_field": {
      "type": "string",
      "description": "Where to put the ID of THIS conversation during the exchange. That's what keeps one visitor's token from reading another visitor's data: a token without a scope is usually valid for the whole account. We can't force a third-party service to respect it, but failing to pass it where the service accepts it is a far more common mistake."
     },
     "ttl_seconds": {
      "type": "integer",
      "description": "How many seconds to reuse an issued token. Deliberately OUR number, not the token's lifetime: a token that expires mid-call breaks the visitor's request, so this is set lower than the real one."
     },
     "body": {
      "type": "object",
      "additionalProperties": {
       "type": "string"
      },
      "description": "Fixed fields of the token request body. Values may contain `{{secrets.NAME}}` — that way the password for an API that issues a token by login and password (Horoshop) lives in the agent's keys, not in the action description."
     },
     "in": {
      "type": "string",
      "enum": [
       "header",
       "body"
      ],
      "description": "Where to put the token in the actual call: `header` (default) — the `header` header; `body` — the `field` body field."
     },
     "field": {
      "type": "string",
      "description": "Body field name for the token when `in` = `body`. Required in that case."
     }
    },
    "required": [
     "url",
     "token_field"
    ],
    "description": "Exchanges the owner's key for a short-lived token before the call. Block absent = the action authenticates with its headers alone."
   },
   "ApprovalCard": {
    "type": "object",
    "properties": {
     "id": {
      "type": "string"
     },
     "action": {
      "type": "string",
      "description": "The action name as the owner sees it in the list of actions."
     },
     "summary": {
      "type": "string",
      "description": "What exactly will happen if approved. Written by the model; it's the only thing the decision is based on."
     },
     "args": {
      "type": "object",
      "additionalProperties": true,
      "description": "Call arguments. They can be corrected when approving."
     },
     "status": {
      "type": "string",
      "enum": [
       "чекає",
       "виконується",
       "виконано",
       "відхилено",
       "протерміновано",
       "не вдалося"
      ],
      "description": "«виконується» (\"running\") — approved, the action is still in progress (or the process crashed midway: then the outcome is unknown). «виконано» (\"done\") — only after the action has actually returned. «протерміновано» (\"expired\") — the deadline passed before a decision was made (this is the absence of a decision, not a rejection). «не вдалося» (\"failed\") — approved, but the action didn't complete."
     },
     "session_id": {
      "type": "string",
      "description": "The conversation where the action came up; empty in a background run."
     },
     "created_at": {
      "type": "string"
     },
     "expires_at": {
      "type": "string",
      "description": "After this moment the card won't be executed."
     },
     "decided_at": {
      "type": "string"
     },
     "decided_by": {
      "type": "string"
     },
     "result": {
      "type": "string",
      "description": "The outcome: the third-party service's response, the reason for the failure, or the reason for the rejection."
     },
     "personal": {
      "type": "boolean",
      "description": "A card from a run that read the owner's mail, or an email from their mailbox. A member without admin rights sees it without the content: `summary` is an explanation, `args` are empty, `result` is empty."
     }
    }
   },
   "BlockedContact": {
    "type": "object",
    "properties": {
     "contact": {
      "type": "string",
      "description": "The contact as it was written. Show exactly this: the canonical form \"380671110000\" reads like a database error, not a person's phone number."
     },
     "key": {
      "type": "string",
      "description": "The canonical form — what the contact is removed by. It's the same for \"+38 (067) 111-00-00\", \"0671110000\" and \"+380671110000\": otherwise the stop list wouldn't work."
     },
     "why": {
      "type": "string",
      "description": "Why we don't message them."
     },
     "by": {
      "type": "string",
      "description": "Who added it: the agent from a conversation or a person from the dashboard."
     },
     "created_at": {
      "type": "string",
      "description": "Since when we don't message them. Adding it again doesn't change this date."
     },
     "appeal": {
      "type": "string",
      "description": "The person changed their mind and asks to be messaged again — in their own words. Empty = didn't ask. Only the owner can restore them (by removing the contact from the list), not the agent."
     },
     "appealed_at": {
      "type": "string",
      "description": "When they asked. Empty = didn't ask."
     }
    }
   },
   "PlannedWork": {
    "type": "object",
    "properties": {
     "id": {
      "type": "string"
     },
     "about": {
      "type": "string",
      "description": "What it's about, in the agent's words: \"the September 5 post\", \"Petrenko\"."
     },
     "task": {
      "type": "string",
      "description": "The task of that run — what the agent will get as input when it wakes up."
     },
     "status": {
      "type": "string",
      "enum": [
       "чекає",
       "виконується",
       "виконано",
       "проґавлено",
       "скасовано",
       "не вдалося"
      ],
      "description": "«проґавлено» (\"missed\") — the moment passed while the platform wasn't waking up: this is OUR failure, not a person's decision or the agent's work. «виконується» (\"running\") — the agent is doing this work right now. «не вдалося» (\"failed\") — started but didn't finish: retries are exhausted."
     },
     "run_at": {
      "type": "string",
      "format": "date-time",
      "description": "When the agent will come back to this."
     },
     "created_at": {
      "type": "string",
      "format": "date-time"
     },
     "session_id": {
      "type": "string",
      "description": "The conversation where the deferral came up; empty in a background run."
     },
     "personal": {
      "type": "boolean",
      "description": "Composed after reading the owner's email or calendar. For a member without admin rights, the content is replaced with the sentence «Особисте власника: …» (\"The owner's personal: …\"); only the workspace admins see what exactly it says."
     }
    }
   },
   "Connection": {
    "type": "object",
    "properties": {
     "name": {
      "type": "string",
      "description": "Connection name: \"instagram\", \"google\". Actions refer to it by this name."
     },
     "account": {
      "type": "string",
      "description": "Whose account is linked, if the service said so. Empty is more honest than made up."
     },
     "scopes": {
      "type": "array",
      "items": {
       "type": "string"
      },
      "description": "Which scopes to request."
     },
     "granted": {
      "type": "boolean",
      "description": "Whether consent has been GRANTED. The key field of the list: a connection without consent looks configured but doesn't work, and without this field the owner would learn the truth from a customer's first action."
     },
     "expires_at": {
      "type": "string",
      "format": "date-time",
      "description": "How long the current token is valid. It's refreshed automatically as long as there is a refresh token."
     }
    }
   },
   "GapList": {
    "type": "object",
    "required": [
     "gaps"
    ],
    "properties": {
     "gaps": {
      "type": "array",
      "items": {
       "$ref": "#/components/schemas/Gap"
      }
     }
    }
   },
   "Gap": {
    "type": "object",
    "required": [
     "id",
     "question",
     "count",
     "first_at",
     "last_at",
     "named"
    ],
    "properties": {
     "id": {
      "type": "string",
      "description": "The row's address: use it to answer the question or dismiss it."
     },
     "question": {
      "type": "string",
      "description": "The query the agent searched the knowledge with and found nothing."
     },
     "count": {
      "type": "integer",
      "description": "How many times this was asked — counting questions merged by meaning."
     },
     "first_at": {
      "type": "string",
      "format": "date-time",
      "description": "When it was first asked."
     },
     "last_at": {
      "type": "string",
      "format": "date-time",
      "description": "When it was last asked."
     },
     "named": {
      "type": "string",
      "description": "A name from the agent's knowledge that it searched for and didn't find. Empty for a regular gap.\n\nNon-empty means a different kind of row: material about this name **exists**, but the search missed it. Adding knowledge won't help here — if people call the thing something other than what the materials say, link the spellings (`POST …/knowledge/names/link`)."
     }
    }
   },
   "StatusCount": {
    "type": "object",
    "required": [
     "status",
     "count"
    ],
    "properties": {
     "status": {
      "type": "string",
      "description": "Status. An empty string — cards without a status."
     },
     "count": {
      "type": "integer"
     }
    }
   },
   "TaskProgress": {
    "type": "object",
    "required": [
     "kind",
     "total",
     "statuses"
    ],
    "description": "Progress on one card set of the notebook: how many cards are in each status.",
    "properties": {
     "kind": {
      "type": "string",
      "description": "The set name — as given by the agent or the owner."
     },
     "total": {
      "type": "integer",
      "description": "How many cards of this set the task has marked."
     },
     "statuses": {
      "type": "array",
      "items": {
       "$ref": "#/components/schemas/StatusCount"
      }
     }
    }
   },
   "LongTask": {
    "type": "object",
    "required": [
     "id",
     "title",
     "brief",
     "status",
     "in_flight",
     "passes",
     "created_at",
     "updated_at",
     "progress"
    ],
    "description": "A long task: work bigger than one run, which the platform continues in passes.",
    "properties": {
     "id": {
      "type": "string"
     },
     "title": {
      "type": "string",
      "description": "Human-readable title: \"plots in Madrid from one hectare\"."
     },
     "brief": {
      "type": "string",
      "description": "What to do and by what criteria. A pass doesn't remember the conversation, so everything it needs is here."
     },
     "status": {
      "type": "string",
      "enum": [
       "виконується",
       "на паузі",
       "завершено",
       "скасовано"
      ],
      "description": "«виконується» (\"running\") — the platform keeps working on the task in passes; «на паузі» (\"paused\") — no passes until someone says to continue (`why` says who stopped it and why); «завершено» (\"completed\") — the agent said \"done\"; «скасовано» (\"cancelled\") — the task was abandoned, what was collected remains."
     },
     "why": {
      "type": "string",
      "description": "Why the task is stopped or cancelled. The platform stops it on its own after three consecutive passes with an error, three consecutive passes without progress, or at the pass cap — and writes the reason here."
     },
     "note": {
      "type": "string",
      "description": "The agent's note to itself: where it stopped and what's next."
     },
     "summary": {
      "type": "string",
      "description": "The summary the agent gave when completing the task."
     },
     "in_flight": {
      "type": "boolean",
      "description": "A pass is running right now."
     },
     "passes": {
      "type": "integer",
      "description": "How many passes there have been."
     },
     "session_id": {
      "type": "string",
      "description": "The conversation where the task was set; the summary will go there. Absent — the task was created from the dashboard or via the API, and the summary will go to the owner as a notification."
     },
     "created_at": {
      "type": "string",
      "format": "date-time"
     },
     "updated_at": {
      "type": "string",
      "format": "date-time"
     },
     "ended_at": {
      "type": "string",
      "format": "date-time",
      "description": "When it was completed or cancelled."
     },
     "next_run_at": {
      "type": "string",
      "format": "date-time",
      "description": "When the next pass is; only for a running task."
     },
     "progress": {
      "type": "array",
      "items": {
       "$ref": "#/components/schemas/TaskProgress"
      },
      "description": "Progress computed by the platform from the notebook, not reported by the agent: set → status → how many cards IN THIS TASK."
     }
    }
   },
   "ContactButton": {
    "type": "object",
    "title": "Contact button",
    "required": [
     "kind",
     "value"
    ],
    "properties": {
     "kind": {
      "type": "string",
      "enum": [
       "telegram",
       "viber",
       "whatsapp",
       "phone",
       "email",
       "link"
      ],
      "description": "Where the button leads."
     },
     "value": {
      "type": "string",
      "description": "`telegram` — username (without `@`) or phone number; `viber`, `whatsapp`, `phone` — number with country code (`+380671234567`); `email` — address; `link` — full URL with `https://`."
     },
     "label": {
      "type": "string",
      "description": "Button label. Empty = the default for the kind (\"Telegram\", \"Viber\", \"WhatsApp\", \"Call us\", \"Email us\"). Required for `link`."
     }
    }
   },
   "WidgetDesign": {
    "type": "object",
    "title": "Window appearance (as saved)",
    "description": "Only what the owner changed: an absent field means the default value.",
    "properties": {
     "shape": {
      "type": "string",
      "enum": [
       "round",
       "soft",
       "square"
      ],
      "description": "Corners of the window, buttons and messages: `round` — rounded (default), `soft` — slightly rounded, `square` — square."
     },
     "size": {
      "type": "string",
      "enum": [
       "regular",
       "compact",
       "large"
      ],
      "description": "Size of the window and its text. Default `regular`."
     },
     "font": {
      "type": "string",
      "enum": [
       "system",
       "site"
      ],
      "description": "`system` — the built-in font (default); `site` — the font of the page the window is on."
     },
     "header": {
      "type": "string",
      "enum": [
       "plain",
       "accent"
      ],
      "description": "Window header: `plain` — same as the background (default), `accent` — filled with the accent color."
     },
     "bubbles": {
      "type": "string",
      "enum": [
       "tint",
       "solid"
      ],
      "description": "Visitor's messages: `tint` — light accent fill (default), `solid` — solid accent."
     },
     "launcher_icon": {
      "type": "string",
      "enum": [
       "chat",
       "question",
       "sparkle",
       "bag",
       "headset",
       "none"
      ],
      "description": "Icon on the button that opens the chat. Default `chat`."
     },
     "launcher_label": {
      "type": "string",
      "maxLength": 24,
      "description": "Label on the button next to the icon (\"Need help?\"). Empty = a round button without a label."
     },
     "launcher_image": {
      "type": "string",
      "description": "Custom image on the button instead of the icon — full URL with `https://`."
     },
     "logo": {
      "type": "string",
      "description": "Image in the window header to the left of the title — full URL with `https://`."
     },
     "offset_x": {
      "type": "integer",
      "minimum": 0,
      "maximum": 200,
      "description": "How many pixels the button and window are offset from the side edge beyond the usual margin."
     },
     "offset_y": {
      "type": "integer",
      "minimum": 0,
      "maximum": 200,
      "description": "How many pixels the button and window are raised above the bottom edge beyond the usual margin."
     },
     "teaser": {
      "type": "string",
      "maxLength": 120,
      "description": "Invitation teaser next to the closed button (\"Need help choosing?\"). Empty = no teaser."
     },
     "teaser_delay": {
      "type": "integer",
      "minimum": 0,
      "maximum": 120,
      "description": "How many seconds on the page (only while the tab is visible): for `teaser_when` = `time` — the teaser appears after this long; for `read` and `leave` — it won't appear earlier than this. `0` = the default of 5."
     },
     "teaser_when": {
      "type": "string",
      "enum": [
       "time",
       "read",
       "leave",
       "scroll"
      ],
      "description": "When the teaser appears: `time` — after `teaser_delay` seconds on the page (default); `read` — the person scrolled to the end of the page; `leave` — the cursor left through the top edge of the browser window (only on devices with a mouse; phones have no such signal, and a teaser with `leave` doesn't appear there). `scroll` — the person scrolled `teaser_scroll` percent of the page. The window can't see the shop's cart — there's no \"added but didn't buy\" event. Absent = `time`."
     },
     "teaser_product": {
      "type": "string",
      "maxLength": 120,
      "description": "Invitation text for a product page; the window replaces {product} (or «{товар}») with the product's short name. Empty = the same as `teaser`."
     },
     "teaser_pages": {
      "type": "string",
      "enum": [
       "all",
       "products"
      ],
      "description": "Where to invite: `all` — on all pages (default), `products` — only on single-product pages (the window recognizes them from schema.org or OpenGraph markup)."
     },
     "teaser_phone": {
      "type": "boolean",
      "description": "Show the teaser on phones too (≤560px). Default no."
     },
     "sound": {
      "type": "boolean",
      "description": "A quiet, short sound (Web Audio, no file fetched from the network) when a new message arrives in a collapsed window or an inactive tab. Off by default; the browser won't play sound anyway until the visitor has interacted with the page."
     },
     "unread_title": {
      "type": "boolean",
      "description": "\"(1) …\" before the tab title while the tab is inactive and a new message has arrived; the title is restored exactly as it was. Off by default."
     },
     "phone": {
      "type": "string",
      "enum": [
       "sheet",
       "full"
      ],
      "description": "Window on phones: `sheet` — a bottom sheet at ~85% of the height, closed by swiping down (default); `full` — full screen."
     },
     "product_card_off": {
      "type": "boolean",
      "description": "`true` → no product card above the conversation (the window still reads the page — that's `page_context_off`)."
     },
     "buy_button_off": {
      "type": "boolean",
      "description": "`true` → no \"add to cart\" button on the product card."
     },
     "launcher_svg": {
      "type": "string",
      "maxLength": 4000,
      "description": "Custom icon on the button — a single SVG with shapes only (`path`, `circle`, `rect`, `line`, `polyline`, `polygon`, `ellipse`, `g`). Overrides `launcher_icon`; overridden by `launcher_image`. No scripts, links, embedded styles or external images."
     },
     "catalog_cards_off": {
      "type": "boolean",
      "description": "`true` → the window doesn't render the catalog products the assistant recommends as cards under the reply: links and prices stay in the text."
     },
     "funnel_off": {
      "type": "boolean",
      "description": "`true` → the window doesn't send buyer steps for the funnel (`GET /v1/dashboard/bots/{id}/funnel`). Counted by default."
     },
     "draggable_off": {
      "type": "boolean",
      "description": "`true` → the visitor can't move the window and the chat button around the page. Allowed by default."
     },
     "width": {
      "type": "integer",
      "minimum": 300,
      "maximum": 960,
      "description": "Custom window width on desktop, in pixels. No field — based on `size`."
     },
     "height": {
      "type": "integer",
      "minimum": 360,
      "maximum": 1200,
      "description": "Custom window height on desktop, in pixels. No field — based on `size`."
     },
     "expanded": {
      "type": "boolean",
      "description": "`true` → on desktop the window opens already expanded to full screen."
     },
     "resizable_off": {
      "type": "boolean",
      "description": "`true` → the visitor can't resize the window by dragging its edges and corners. Allowed by default."
     },
     "conversations_off": {
      "type": "boolean",
      "description": "`true` → the visitor has a single conversation: a new one erases the previous one. By default there can be several conversations, as several chat windows side by side."
     },
     "conversations_max": {
      "type": "integer",
      "minimum": 2,
      "maximum": 20,
      "description": "Maximum number of chat windows at once. No field — only the window's technical cap (twenty conversations)."
     },
     "teaser_rules": {
      "type": "array",
      "maxItems": 8,
      "items": {
       "$ref": "#/components/schemas/TeaserRule"
      },
      "description": "Custom invitations for parts of the site by URL pattern. The first match overrides `teaser` and `teaser_product`; a rule with `off` (\"don't invite here\") overrides everything."
     },
     "teaser_returning": {
      "type": "string",
      "maxLength": 120,
      "description": "Invitation for someone who has already chatted in this window. Empty — the same as for everyone."
     },
     "teaser_scroll": {
      "type": "integer",
      "minimum": 0,
      "maximum": 100,
      "description": "For `teaser_when: scroll` — what percentage of the page needs to be scrolled. Default 50."
     },
     "teaser_repeat": {
      "type": "string",
      "enum": [
       "visit",
       "page",
       "day",
       "once"
      ],
      "description": "How often to invite the same person: `visit` — once per visit (default); `page` — on every page, until they close the teaser themselves or open the window; `day` — once a day; `once` — once and never again. A teaser closed with the X is not brought back within the visit, whatever the value."
     },
     "teaser_hold": {
      "type": "integer",
      "minimum": 0,
      "maximum": 120,
      "description": "How many seconds the teaser stays before disappearing on its own. 0 — until closed."
     },
     "teaser_buttons": {
      "type": "array",
      "maxItems": 3,
      "items": {
       "type": "string",
       "maxLength": 40
      },
      "description": "Option buttons on the teaser: clicking one opens the window and sends that phrase to the assistant."
     },
     "teaser_place": {
      "type": "string",
      "enum": [
       "above",
       "side"
      ],
      "description": "Where the teaser sits relative to the chat button: `above` — above it (default), `side` — beside it."
     },
     "teaser_image": {
      "type": "string",
      "description": "Image on the teaser before the text — full URL with `https://`. For a custom icon instead, use `widget_icons.teaser`."
     },
     "conversations_layout": {
      "type": "string",
      "enum": [
       "tile"
      ],
      "description": "`tile` → several chat windows are tiled across the full screen. No field — in a row from the corner."
     },
     "snap_off": {
      "type": "boolean",
      "description": "`true` → the window doesn't snap to the screen edges. Snaps by default."
     },
     "mode": {
      "type": "string",
      "enum": [
       "window",
       "side"
      ],
      "description": "How the chat sits on the page: `window` — a window in the corner (default), `side` — a full-height side panel at the edge of the screen (width — `width`, default 400; on screens up to 720 pixels — the regular phone window)."
     },
     "launcher_emoji": {
      "type": "string",
      "description": "Chat button icon as a character or emoji (`✦`, `🤖`), up to 8 characters. Overrides `launcher_icon`; overridden by `launcher_svg` and `launcher_image`."
     },
     "side_push_off": {
      "type": "boolean",
      "description": "`true` — the side panel overlays the page (without dimming). By default the panel pushes the page content aside."
     },
     "starter_rules": {
      "type": "array",
      "maxItems": 8,
      "description": "Custom suggestions under the greeting for parts of the site: the first rule whose pattern matches the page replaces the regular `starters`.",
      "items": {
       "$ref": "#/components/schemas/StarterRule"
      }
     }
    }
   },
   "WidgetDesignView": {
    "type": "object",
    "title": "Window appearance (for the window)",
    "description": "The same set with defaults filled in: every field is always present.",
    "required": [
     "shape",
     "size",
     "font",
     "header",
     "bubbles",
     "launcher_icon",
     "launcher_label",
     "launcher_image",
     "logo",
     "offset_x",
     "offset_y",
     "teaser",
     "teaser_delay",
     "teaser_when",
     "teaser_product",
     "teaser_pages",
     "teaser_phone",
     "sound",
     "unread_title",
     "phone",
     "product_card",
     "buy_button",
     "launcher_svg",
     "catalog_cards",
     "funnel",
     "draggable",
     "teaser_rules",
     "teaser_returning",
     "teaser_scroll",
     "teaser_repeat",
     "teaser_hold",
     "teaser_buttons",
     "teaser_place",
     "teaser_image",
     "width",
     "height",
     "expanded",
     "resizable",
     "conversations",
     "conversations_max",
     "conversations_layout",
     "snap",
     "mode",
     "side_push",
     "launcher_emoji",
     "starter_rules"
    ],
    "properties": {
     "shape": {
      "type": "string",
      "enum": [
       "round",
       "soft",
       "square"
      ],
      "description": "Corners of the window, buttons and messages: `round` — rounded (default), `soft` — slightly rounded, `square` — square."
     },
     "size": {
      "type": "string",
      "enum": [
       "regular",
       "compact",
       "large"
      ],
      "description": "Size of the window and its text. Default `regular`."
     },
     "font": {
      "type": "string",
      "enum": [
       "system",
       "site"
      ],
      "description": "`system` — the built-in font (default); `site` — the font of the page the window is on."
     },
     "header": {
      "type": "string",
      "enum": [
       "plain",
       "accent"
      ],
      "description": "Window header: `plain` — same as the background (default), `accent` — filled with the accent color."
     },
     "bubbles": {
      "type": "string",
      "enum": [
       "tint",
       "solid"
      ],
      "description": "Visitor's messages: `tint` — light accent fill (default), `solid` — solid accent."
     },
     "launcher_icon": {
      "type": "string",
      "enum": [
       "chat",
       "question",
       "sparkle",
       "bag",
       "headset",
       "none"
      ],
      "description": "Icon on the button that opens the chat. Default `chat`."
     },
     "launcher_label": {
      "type": "string",
      "maxLength": 24,
      "description": "Label on the button next to the icon (\"Need help?\"). Empty = a round button without a label."
     },
     "launcher_image": {
      "type": "string",
      "description": "Custom image on the button instead of the icon — full URL with `https://`."
     },
     "logo": {
      "type": "string",
      "description": "Image in the window header to the left of the title — full URL with `https://`."
     },
     "offset_x": {
      "type": "integer",
      "minimum": 0,
      "maximum": 200,
      "description": "How many pixels the button and window are offset from the side edge beyond the usual margin."
     },
     "offset_y": {
      "type": "integer",
      "minimum": 0,
      "maximum": 200,
      "description": "How many pixels the button and window are raised above the bottom edge beyond the usual margin."
     },
     "teaser": {
      "type": "string",
      "maxLength": 120,
      "description": "Invitation teaser next to the closed button (\"Need help choosing?\"). Empty = no teaser."
     },
     "teaser_delay": {
      "type": "integer",
      "minimum": 0,
      "maximum": 120,
      "description": "How many seconds on the page (only while the tab is visible): for `teaser_when` = `time` — the teaser appears after this long; for `read` and `leave` — it won't appear earlier than this."
     },
     "teaser_when": {
      "type": "string",
      "enum": [
       "time",
       "read",
       "leave",
       "scroll"
      ],
      "description": "When the teaser appears: `time` — after `teaser_delay` seconds on the page (default); `read` — the person scrolled to the end of the page; `leave` — the cursor left through the top edge of the browser window (only on devices with a mouse; phones have no such signal, and a teaser with `leave` doesn't appear there). `scroll` — the person scrolled `teaser_scroll` percent of the page. The window can't see the shop's cart — there's no \"added but didn't buy\" event."
     },
     "teaser_product": {
      "type": "string",
      "maxLength": 120,
      "description": "Invitation text for a product page; the window replaces {product} (or «{товар}») with the product's short name. Empty = the same as `teaser`."
     },
     "teaser_pages": {
      "type": "string",
      "enum": [
       "all",
       "products"
      ],
      "description": "Where to invite: `all` — on all pages (default), `products` — only on single-product pages (the window recognizes them from schema.org or OpenGraph markup)."
     },
     "teaser_phone": {
      "type": "boolean",
      "description": "Show the teaser on phones too (≤560px). Default no."
     },
     "sound": {
      "type": "boolean",
      "description": "A quiet, short sound (Web Audio, no file fetched from the network) when a new message arrives in a collapsed window or an inactive tab. Off by default; the browser won't play sound anyway until the visitor has interacted with the page."
     },
     "unread_title": {
      "type": "boolean",
      "description": "\"(1) …\" before the tab title while the tab is inactive and a new message has arrived; the title is restored exactly as it was. Off by default."
     },
     "phone": {
      "type": "string",
      "enum": [
       "sheet",
       "full"
      ],
      "description": "Window on phones: `sheet` — a bottom sheet at ~85% of the height, closed by swiping down (default); `full` — full screen."
     },
     "product_card": {
      "type": "boolean",
      "description": "Whether to show the card of the product the visitor is viewing above the conversation."
     },
     "buy_button": {
      "type": "boolean",
      "description": "Whether the product card has an \"add to cart\" button."
     },
     "launcher_svg": {
      "type": "string",
      "maxLength": 4000,
      "description": "Custom icon on the button — a single SVG with shapes only (`path`, `circle`, `rect`, `line`, `polyline`, `polygon`, `ellipse`, `g`). Overrides `launcher_icon`; overridden by `launcher_image`. No scripts, links, embedded styles or external images."
     },
     "catalog_cards": {
      "type": "boolean",
      "description": "Whether the window renders the catalog products the assistant recommends in the reply as cards (`products`)."
     },
     "funnel": {
      "type": "boolean",
      "description": "Whether the window sends conversation steps for the funnel (`POST /v1/widget/event`): opened, asked, \"add to cart\", went to a product, messenger, contact, human. Only the step name — no conversation ID, text or URL."
     },
     "draggable": {
      "type": "boolean",
      "description": "Whether the visitor can move the window (by its header, on desktop) and the chat button around the page. The position is remembered in their browser for this site; double-clicking the header puts it back."
     },
     "width": {
      "type": "integer",
      "minimum": 0,
      "maximum": 960,
      "description": "Custom window width on desktop, in pixels; `0` — based on `size`. A size the visitor set themselves takes precedence in their browser."
     },
     "height": {
      "type": "integer",
      "minimum": 0,
      "maximum": 1200,
      "description": "Custom window height on desktop, in pixels; `0` — based on `size`."
     },
     "expanded": {
      "type": "boolean",
      "description": "Whether the window opens on desktop already expanded to full screen. The visitor's own choice (expanded or collapsed) is remembered in their browser and takes precedence."
     },
     "resizable": {
      "type": "boolean",
      "description": "Whether the visitor can resize the window by dragging its edges and corners (from the keyboard — with the arrow keys on the corner handle). The size is remembered in their browser; double-clicking an edge restores the owner's size."
     },
     "conversations": {
      "type": "boolean",
      "description": "Whether the visitor can keep several conversations at once, as several chat windows side by side (on phones — via a switcher in the header of a single window). `false` — one conversation; a new one erases the previous one."
     },
     "conversations_max": {
      "type": "integer",
      "minimum": 2,
      "maximum": 20,
      "description": "How many conversations (chat windows) the visitor can keep at once. Twenty is the window's own technical cap."
     },
     "teaser_rules": {
      "type": "array",
      "maxItems": 8,
      "items": {
       "$ref": "#/components/schemas/TeaserRule"
      },
      "description": "Custom invitations for parts of the site by URL pattern. The first match overrides `teaser` and `teaser_product`; a rule with `off` (\"don't invite here\") overrides everything."
     },
     "teaser_returning": {
      "type": "string",
      "maxLength": 120,
      "description": "Invitation for someone who has already chatted in this window. Empty — the same as for everyone."
     },
     "teaser_scroll": {
      "type": "integer",
      "minimum": 0,
      "maximum": 100,
      "description": "For `teaser_when: scroll` — what percentage of the page needs to be scrolled. Default 50."
     },
     "teaser_repeat": {
      "type": "string",
      "enum": [
       "visit",
       "page",
       "day",
       "once"
      ],
      "description": "How often to invite the same person: `visit` — once per visit (default); `page` — on every page, until they close the teaser themselves or open the window; `day` — once a day; `once` — once and never again. A teaser closed with the X is not brought back within the visit, whatever the value."
     },
     "teaser_hold": {
      "type": "integer",
      "minimum": 0,
      "maximum": 120,
      "description": "How many seconds the teaser stays before disappearing on its own. 0 — until closed."
     },
     "teaser_buttons": {
      "type": "array",
      "maxItems": 3,
      "items": {
       "type": "string",
       "maxLength": 40
      },
      "description": "Option buttons on the teaser: clicking one opens the window and sends that phrase to the assistant."
     },
     "teaser_place": {
      "type": "string",
      "enum": [
       "above",
       "side"
      ],
      "description": "Where the teaser sits relative to the chat button: `above` — above it (default), `side` — beside it."
     },
     "teaser_image": {
      "type": "string",
      "description": "Image on the teaser before the text — full URL with `https://`. For a custom icon instead, use `widget_icons.teaser`."
     },
     "conversations_layout": {
      "type": "string",
      "enum": [
       "corner",
       "tile"
      ],
      "description": "How windows are arranged when there are several: `corner` — in a row from the corner; `tile` — tiled across the full screen (two split it in half, more form a grid). A layout the visitor chose themselves takes precedence."
     },
     "snap": {
      "type": "boolean",
      "description": "Whether the window snaps to the screen edges when dragged there: an edge gives half the screen, a corner a quarter, the top the full screen."
     },
     "mode": {
      "type": "string",
      "enum": [
       "window",
       "side"
      ],
      "description": "How the chat sits on the page: `window` — a window in the corner (default), `side` — a full-height side panel at the edge of the screen (width — `width`, default 400; on screens up to 720 pixels — the regular phone window)."
     },
     "launcher_emoji": {
      "type": "string",
      "description": "Chat button icon as a character or emoji (`✦`, `🤖`), up to 8 characters. Overrides `launcher_icon`; overridden by `launcher_svg` and `launcher_image`."
     },
     "side_push": {
      "type": "boolean",
      "description": "Whether the side panel pushes the page content aside (default yes); `false` — it overlays the page, without dimming."
     },
     "starter_rules": {
      "type": "array",
      "maxItems": 8,
      "description": "Custom suggestions under the greeting for parts of the site: the first rule whose pattern matches the page replaces the regular `starters`.",
      "items": {
       "$ref": "#/components/schemas/StarterRule"
      }
     }
    }
   },
   "WidgetDesignPatch": {
    "type": "object",
    "title": "Window appearance change",
    "additionalProperties": false,
    "description": "Send only the fields you're changing. An empty string = leave unchanged; to remove a label, image, logo or teaser, use `clear`.",
    "properties": {
     "shape": {
      "type": "string",
      "enum": [
       "round",
       "soft",
       "square"
      ],
      "description": "Corners of the window, buttons and messages: `round` — rounded (default), `soft` — slightly rounded, `square` — square."
     },
     "size": {
      "type": "string",
      "enum": [
       "regular",
       "compact",
       "large"
      ],
      "description": "Size of the window and its text. Default `regular`."
     },
     "font": {
      "type": "string",
      "enum": [
       "system",
       "site"
      ],
      "description": "`system` — the built-in font (default); `site` — the font of the page the window is on."
     },
     "header": {
      "type": "string",
      "enum": [
       "plain",
       "accent"
      ],
      "description": "Window header: `plain` — same as the background (default), `accent` — filled with the accent color."
     },
     "bubbles": {
      "type": "string",
      "enum": [
       "tint",
       "solid"
      ],
      "description": "Visitor's messages: `tint` — light accent fill (default), `solid` — solid accent."
     },
     "launcher_icon": {
      "type": "string",
      "enum": [
       "chat",
       "question",
       "sparkle",
       "bag",
       "headset",
       "none"
      ],
      "description": "Icon on the button that opens the chat. Default `chat`."
     },
     "launcher_label": {
      "type": "string",
      "maxLength": 24,
      "description": "Label on the button next to the icon (\"Need help?\"). Empty = a round button without a label."
     },
     "launcher_image": {
      "type": "string",
      "description": "Custom image on the button instead of the icon — full URL with `https://`."
     },
     "logo": {
      "type": "string",
      "description": "Image in the window header to the left of the title — full URL with `https://`."
     },
     "offset_x": {
      "type": "integer",
      "minimum": 0,
      "maximum": 200,
      "description": "How many pixels the button and window are offset from the side edge beyond the usual margin."
     },
     "offset_y": {
      "type": "integer",
      "minimum": 0,
      "maximum": 200,
      "description": "How many pixels the button and window are raised above the bottom edge beyond the usual margin."
     },
     "teaser": {
      "type": "string",
      "maxLength": 120,
      "description": "Invitation teaser next to the closed button (\"Need help choosing?\"). Empty = no teaser."
     },
     "teaser_delay": {
      "type": "integer",
      "minimum": 0,
      "maximum": 120,
      "description": "How many seconds on the page (only while the tab is visible): for `teaser_when` = `time` — the teaser appears after this long; for `read` and `leave` — it won't appear earlier than this. Default 5."
     },
     "teaser_when": {
      "type": "string",
      "enum": [
       "time",
       "read",
       "leave",
       "scroll"
      ],
      "description": "When the teaser appears: `time` — after `teaser_delay` seconds on the page (default); `read` — the person scrolled to the end of the page; `leave` — the cursor left through the top edge of the browser window (only on devices with a mouse; phones have no such signal, and a teaser with `leave` doesn't appear there). `scroll` — the person scrolled `teaser_scroll` percent of the page. The window can't see the shop's cart — there's no \"added but didn't buy\" event."
     },
     "teaser_product": {
      "type": "string",
      "maxLength": 120,
      "description": "Invitation text for a product page; the window replaces {product} (or «{товар}») with the product's short name. Empty = the same as `teaser`."
     },
     "teaser_pages": {
      "type": "string",
      "enum": [
       "all",
       "products"
      ],
      "description": "Where to invite: `all` — on all pages (default), `products` — only on single-product pages (the window recognizes them from schema.org or OpenGraph markup)."
     },
     "teaser_phone": {
      "type": "boolean",
      "description": "Show the teaser on phones too (≤560px). Default no."
     },
     "sound": {
      "type": "boolean",
      "description": "A quiet, short sound (Web Audio, no file fetched from the network) when a new message arrives in a collapsed window or an inactive tab. Off by default; the browser won't play sound anyway until the visitor has interacted with the page."
     },
     "unread_title": {
      "type": "boolean",
      "description": "\"(1) …\" before the tab title while the tab is inactive and a new message has arrived; the title is restored exactly as it was. Off by default."
     },
     "phone": {
      "type": "string",
      "enum": [
       "sheet",
       "full"
      ],
      "description": "Window on phones: `sheet` — a bottom sheet at ~85% of the height, closed by swiping down (default); `full` — full screen."
     },
     "product_card": {
      "type": "boolean",
      "description": "Whether to show the product card above the conversation. Default yes."
     },
     "buy_button": {
      "type": "boolean",
      "description": "Whether the product card has an \"add to cart\" button (it clicks the shop's own button). Default yes."
     },
     "launcher_svg": {
      "type": "string",
      "maxLength": 4000,
      "description": "Custom icon on the button — a single SVG with shapes only (`path`, `circle`, `rect`, `line`, `polyline`, `polygon`, `ellipse`, `g`). Overrides `launcher_icon`; overridden by `launcher_image`. No scripts, links, embedded styles or external images."
     },
     "catalog_cards": {
      "type": "boolean",
      "description": "Whether the window shows the catalog products the assistant recommends in the reply as cards: photo, price, availability, and \"Similar\", \"Cheaper\", \"Compare\" buttons. Default yes; `false` keeps recommendations as text."
     },
     "funnel": {
      "type": "boolean",
      "description": "Whether the window counts buyer steps for the funnel. Default yes; `false` — the window sends nothing, and the funnel keeps what was counted so far."
     },
     "draggable": {
      "type": "boolean",
      "description": "Whether the visitor can move the window and the chat button around the page. Default yes; `false` pins them in place."
     },
     "width": {
      "type": "integer",
      "minimum": 0,
      "maximum": 960,
      "description": "Custom window width on desktop: 300 to 960 pixels; `0` restores the default (based on `size`)."
     },
     "height": {
      "type": "integer",
      "minimum": 0,
      "maximum": 1200,
      "description": "Custom window height on desktop: 360 to 1,200 pixels; `0` restores the default (based on `size`)."
     },
     "expanded": {
      "type": "boolean",
      "description": "Open the window on desktop already expanded to full screen. Default no."
     },
     "resizable": {
      "type": "boolean",
      "description": "Whether the visitor can resize the window. Default yes; `false` fixes the size."
     },
     "conversations": {
      "type": "boolean",
      "description": "Whether the visitor can keep several conversations at once (several chat windows). Default yes; `false` — one conversation; a new one erases the previous one."
     },
     "conversations_max": {
      "type": "integer",
      "minimum": 0,
      "maximum": 20,
      "description": "Maximum number of chat windows at once: 2 to 20; `0` — no custom cap."
     },
     "teaser_rules": {
      "type": "array",
      "maxItems": 8,
      "items": {
       "$ref": "#/components/schemas/TeaserRule"
      },
      "description": "Custom invitations for parts of the site by URL pattern. The first match overrides `teaser` and `teaser_product`; a rule with `off` (\"don't invite here\") overrides everything. Replaces the list ENTIRELY; to remove it, use `clear`."
     },
     "teaser_returning": {
      "type": "string",
      "maxLength": 120,
      "description": "Invitation for someone who has already chatted in this window. Empty — the same as for everyone."
     },
     "teaser_scroll": {
      "type": "integer",
      "minimum": 1,
      "maximum": 100,
      "description": "For `teaser_when: scroll` — what percentage of the page needs to be scrolled. Default 50."
     },
     "teaser_repeat": {
      "type": "string",
      "enum": [
       "visit",
       "page",
       "day",
       "once"
      ],
      "description": "How often to invite the same person: `visit` — once per visit (default); `page` — on every page, until they close the teaser themselves or open the window; `day` — once a day; `once` — once and never again. A teaser closed with the X is not brought back within the visit, whatever the value."
     },
     "teaser_hold": {
      "type": "integer",
      "minimum": 0,
      "maximum": 120,
      "description": "How many seconds the teaser stays before disappearing on its own. 0 — until closed."
     },
     "teaser_buttons": {
      "type": "array",
      "maxItems": 3,
      "items": {
       "type": "string",
       "maxLength": 40
      },
      "description": "Option buttons on the teaser: clicking one opens the window and sends that phrase to the assistant. Replaces the list ENTIRELY; to remove it, use `clear`."
     },
     "teaser_place": {
      "type": "string",
      "enum": [
       "above",
       "side"
      ],
      "description": "Where the teaser sits relative to the chat button: `above` — above it (default), `side` — beside it."
     },
     "teaser_image": {
      "type": "string",
      "description": "Image on the teaser before the text — full URL with `https://`. For a custom icon instead, use `widget_icons.teaser`."
     },
     "conversations_layout": {
      "type": "string",
      "enum": [
       "corner",
       "tile"
      ],
      "description": "How several chat windows are arranged: in a row from the corner (default) or tiled across the full screen."
     },
     "snap": {
      "type": "boolean",
      "description": "Whether the window snaps to the screen edges. Default yes."
     },
     "mode": {
      "type": "string",
      "enum": [
       "window",
       "side"
      ],
      "description": "How the chat sits on the page: `window` — a window in the corner (default), `side` — a full-height side panel at the edge of the screen (width — `width`, default 400; on screens up to 720 pixels — the regular phone window)."
     },
     "launcher_emoji": {
      "type": "string",
      "description": "Chat button icon as a character or emoji (`✦`, `🤖`), up to 8 characters. Overrides `launcher_icon`; overridden by `launcher_svg` and `launcher_image`."
     },
     "side_push": {
      "type": "boolean",
      "description": "Whether the side panel pushes the page content aside (default yes); `false` — it overlays the page, without dimming."
     },
     "starter_rules": {
      "type": "array",
      "maxItems": 8,
      "description": "Custom suggestions under the greeting for parts of the site: the first rule whose pattern matches the page replaces the regular `starters`.",
      "items": {
       "$ref": "#/components/schemas/StarterRule"
      }
     }
    }
   },
   "WidgetConfig": {
    "type": "object",
    "properties": {
     "title": {
      "type": "string",
      "description": "Window title. Empty = default."
     },
     "greeting": {
      "type": "string",
      "description": "The first message in the window."
     },
     "starters": {
      "type": [
       "array",
       "null"
      ],
      "items": {
       "type": "string"
      },
      "description": "Suggested questions under the greeting."
     },
     "collect_leads": {
      "type": "boolean",
      "description": "Whether to show the \"Leave your contact\" button."
     },
     "accent": {
      "type": "string",
      "description": "Accent color in hex. Empty = default."
     },
     "position": {
      "type": "string",
      "description": "Screen corner: `bottom-right`, `bottom-left`, `top-right` or `top-left`. Empty = bottom right."
     },
     "theme": {
      "type": "string",
      "description": "`auto`, `light` or `dark`. Empty = `auto`."
     },
     "light": {
      "type": "object",
      "properties": {
       "bg": {
        "type": "string"
       },
       "surface": {
        "type": "string"
       },
       "text": {
        "type": "string"
       }
      },
      "description": "Custom theme colors in hex; an empty field = the built-in palette."
     },
     "dark": {
      "type": "object",
      "properties": {
       "bg": {
        "type": "string"
       },
       "surface": {
        "type": "string"
       },
       "text": {
        "type": "string"
       }
      },
      "description": "Custom theme colors in hex; an empty field = the built-in palette."
     },
     "operator_enabled": {
      "type": "boolean",
      "description": "Whether a live person can be called in — in the chat window on the site and in the agent's messengers (Telegram, Viber, WhatsApp)."
     },
     "page_aware": {
      "type": "boolean",
      "description": "Whether the window reads the page it's on."
     },
     "fit_site": {
      "type": "boolean",
      "description": "Whether the window adopts the site's palette."
     },
     "draft_preview": {
      "type": "boolean",
      "description": "Whether the operator sees what the visitor is typing before it's sent."
     },
     "note": {
      "type": "string",
      "description": "Note under the input field. An empty string = no line."
     },
     "contacts": {
      "type": "array",
      "items": {
       "$ref": "#/components/schemas/WidgetContactButton"
      },
      "description": "Buttons for contacting company staff, with ready-made labels. An empty list = no buttons."
     },
     "design": {
      "$ref": "#/components/schemas/WidgetDesignView"
     },
     "suggestions": {
      "type": "boolean",
      "description": "Whether the assistant suggests options for the next message. The options themselves come with the reply (`suggestions`)."
     },
     "css": {
      "type": "string",
      "description": "Custom window style. An empty string = none."
     },
     "texts": {
      "type": "object",
      "additionalProperties": {
       "type": "string"
      },
      "description": "Custom labels instead of the default ones. An empty object = all default."
     },
     "continue_in": {
      "type": "string",
      "enum": [
       "",
       "telegram"
      ],
      "description": "The messenger where THIS SAME conversation with the assistant can be continued: `telegram` — the agent has a Telegram bot connected, and the window can show a \"Continue in Telegram\" button (the link is issued by `POST /v1/widget/continue`); empty — nowhere. These aren't contact buttons (`contacts`): those lead to company staff."
     },
     "items": {
      "type": "array",
      "items": {
       "$ref": "#/components/schemas/WidgetItem"
      },
      "description": "The owner's custom elements in the window. An empty list = none. The window builds its elements solely from these descriptions."
     },
     "layout": {
      "$ref": "#/components/schemas/WidgetLayoutView"
     },
     "icons": {
      "type": "object",
      "additionalProperties": {
       "type": "string"
      },
      "description": "Custom icons instead of the built-in ones, including the chat button icon (`launcher`). An empty object = all built-in."
     },
     "lang": {
      "type": "string",
      "description": "Language of the window's primary texts (`greeting`, `starters`, `texts`…): a two-letter code. Empty — the owner hasn't specified it: their texts are shown for any language, and the window uses its built-in labels in the visitor's language.",
      "example": "uk"
     },
     "lang_fixed": {
      "type": "boolean",
      "description": "`true` — the window doesn't pick a language based on the page and browser: it always uses the primary one (the `data-lang` attribute works the same way)."
     },
     "langs": {
      "type": "object",
      "additionalProperties": {
       "$ref": "#/components/schemas/WidgetLangSet"
      },
      "description": "The same texts in other languages: language code → set. The window picks the language in this order: `data-lang` on the script tag (or `YouSelfBot.setLang`) → the page's `<html lang>` → the browser language → the primary language; it takes the first one for which the owner has a set or the window has a built-in dictionary (Ukrainian, English). An empty object — no sets."
     },
     "note_own": {
      "type": "boolean",
      "description": "Whether the `note` was written by the owner. The window says the default note in other languages using its own dictionary."
     },
     "hide_on": {
      "type": "array",
      "items": {
       "type": "string"
      },
      "description": "URL patterns of pages without the window: `/app` — the page and everything under it, `/` — only the home page, `*` — anything (`/docs/*`). The `data-hide-on` attribute does the same. Empty — the window appears everywhere."
     },
     "lang_report": {
      "type": "array",
      "description": "Only in the dashboard response (`GET /v1/dashboard/bots/{id}/widget`): for each language other than the primary one — what is set in that language and what is left untranslated (along with what the window shows instead). An empty list — no other languages.",
      "items": {
       "type": "object",
       "required": [
        "lang",
        "name",
        "has",
        "missing"
       ],
       "properties": {
        "lang": {
         "type": "string",
         "description": "Language code.",
         "example": "en"
        },
        "name": {
         "type": "string",
         "description": "Language name in words.",
         "example": "English"
        },
        "has": {
         "type": "array",
         "items": {
          "type": "string"
         },
         "description": "What is set in this language."
        },
        "missing": {
         "type": "array",
         "items": {
          "type": "string"
         },
         "description": "What the owner set in the primary language but not in this one — and what the window shows instead."
        }
       }
      }
     }
    },
    "title": "Window settings",
    "required": [
     "collect_leads",
     "operator_enabled",
     "page_aware",
     "fit_site",
     "draft_preview",
     "note",
     "suggestions",
     "contacts",
     "design",
     "css",
     "texts",
     "continue_in",
     "items",
     "layout",
     "icons",
     "lang",
     "lang_fixed",
     "langs",
     "note_own",
     "hide_on"
    ]
   },
   "CatalogProduct": {
    "type": "object",
    "title": "Product",
    "required": [
     "id",
     "name",
     "url",
     "price",
     "available"
    ],
    "properties": {
     "id": {
      "type": "string",
      "description": "Product ID in the feed."
     },
     "name": {
      "type": "string"
     },
     "url": {
      "type": "string",
      "description": "Product page in the shop."
     },
     "image": {
      "type": "string",
      "description": "URL of the first photo."
     },
     "category": {
      "type": "string",
      "description": "Category with its parents: \"Peripherals / Mice\"."
     },
     "vendor": {
      "type": "string"
     },
     "price": {
      "type": "number"
     },
     "old_price": {
      "type": "number",
      "description": "Price before the discount. Absent when there's no discount."
     },
     "currency": {
      "type": "string"
     },
     "available": {
      "type": "boolean"
     },
     "description": {
      "type": "string",
      "description": "Description without markup, up to 600 characters."
     },
     "params": {
      "type": "array",
      "items": {
       "type": "object",
       "required": [
        "name",
        "value"
       ],
       "properties": {
        "name": {
         "type": "string"
        },
        "value": {
         "type": "string"
        }
       }
      },
      "description": "Specifications."
     },
     "by_meaning": {
      "type": "boolean",
      "description": "The product was found by the meaning of the query, not by the words in its name: it's a \"might fit\", not an exact match. Absent for products found by words."
     },
     "group": {
      "type": "string",
      "description": "Variant group in the feed (`group_id` / `g:item_group_id`). Absent for a product without variants."
     },
     "variants": {
      "type": "array",
      "items": {
       "$ref": "#/components/schemas/CatalogProduct"
      },
      "description": "Product variants (size, color…), when the search collapsed a group into one product: in feed order, each with its ID, name, URL, price, availability and only the attributes in which the variants differ (shared ones are in the product's own `params`). The product's price is then the lowest among in-stock variants (price filters use it too), and `available` tells whether at least one is in stock. Absent for a product without variants."
     }
    }
   },
   "Catalog": {
    "type": "object",
    "title": "Product catalog",
    "required": [
     "connected",
     "count",
     "seen",
     "stale",
     "groups",
     "variants"
    ],
    "properties": {
     "connected": {
      "type": "boolean",
      "description": "Whether a feed is connected. `false` — the other fields are zero values."
     },
     "url": {
      "type": "string",
      "description": "Feed URL. Absent when the products were taken from a spreadsheet (`file`)."
     },
     "file": {
      "type": "string",
      "description": "Name of the spreadsheet (CSV or XLSX) the products were taken from: a spreadsheet uploaded to knowledge becomes the catalog automatically. Such a catalog isn't re-read on schedule — a new upload updates it."
     },
     "every_hours": {
      "type": "integer",
      "description": "How often the feed is re-read, in hours."
     },
     "count": {
      "type": "integer",
      "description": "How many products are in the catalog."
     },
     "seen": {
      "type": "integer",
      "description": "How many products were in the feed. Greater than `count` when the feed was truncated at the cap (20,000) or some products were discarded."
     },
     "updated_at": {
      "type": "string",
      "format": "date-time",
      "description": "When prices were last checked against the shop. Absent until the feed has been read at least once."
     },
     "problem": {
      "type": "string",
      "description": "Why the last read failed, in words. Absent when it succeeded. Products from the previous read stay in place."
     },
     "stale": {
      "type": "boolean",
      "description": "Reading has been failing for longer than two intervals in a row: prices and availability may have changed."
     },
     "meaning": {
      "type": "object",
      "required": [
       "ready",
       "total"
      ],
      "description": "Product search by the meaning of the query (\"something for a gamer as a gift\"): when the words in product names give few matches, the catalog adds products similar in meaning to the answer. Product vectors are computed in the background after the feed is read, once per product (variants of one group are one product and one vector): a re-read feed only computes new products and those whose name, category, brand or description changed. **The field is absent entirely** when the build doesn't search by meaning.",
      "properties": {
       "ready": {
        "type": "integer",
        "description": "How many products already have a vector — meaning search covers exactly these."
       },
       "total": {
        "type": "integer",
        "description": "How many products are in the catalog; a variant group counts as one product."
       }
      }
     },
     "groups": {
      "type": "integer",
      "description": "How many products have variants (size, color, etc.) — groups of two or more offers that the feed itself marked as one group (`group_id` in YML, `g:item_group_id` in Google Merchant). Search and the assistant show each such group as one product with a list of variants. Identical names without a group are not merged."
     },
     "variants": {
      "type": "integer",
      "description": "How many feed offers (rows in `count`) are variants in these groups. Distinct products for the buyer: `count − variants + groups`."
     }
    }
   },
   "CatalogReport": {
    "type": "object",
    "title": "Feed read summary",
    "required": [
     "count",
     "seen",
     "skipped",
     "truncated"
    ],
    "properties": {
     "count": {
      "type": "integer",
      "description": "How many products are in the catalog now."
     },
     "seen": {
      "type": "integer",
      "description": "How many were in the feed."
     },
     "skipped": {
      "type": "integer",
      "description": "How many were discarded: missing a name, link or price, or with a duplicate ID."
     },
     "truncated": {
      "type": "boolean",
      "description": "The feed exceeds the cap, and the remaining products weren't included."
     },
     "format": {
      "type": "string",
      "enum": [
       "yml",
       "google"
      ],
      "description": "Detected feed format."
     }
    }
   },
   "CatalogDiscovery": {
    "type": "object",
    "title": "Feed discovery summary",
    "required": [
     "site",
     "candidates",
     "unreachable",
     "steps"
    ],
    "properties": {
     "site": {
      "type": "string",
      "description": "The site URL that was searched."
     },
     "engine": {
      "type": "string",
      "description": "The shop engine, if it could be recognized (OpenCart, Horoshop, Prom, WooCommerce, Shopify). Absent when not recognized."
     },
     "candidates": {
      "type": "array",
      "description": "Feeds found — each one already checked: products were read from it. The one with more products comes first. An empty list — no feed visible on the site.",
      "items": {
       "type": "object",
       "required": [
        "url",
        "format",
        "count",
        "partial"
       ],
       "properties": {
        "url": {
         "type": "string",
         "description": "Feed URL — this is what you pass to `PUT …/catalog`."
        },
        "format": {
         "type": "string",
         "enum": [
          "yml",
          "google"
         ],
         "description": "Detected format."
        },
        "count": {
         "type": "integer",
         "description": "How many products were read during the check."
        },
        "partial": {
         "type": "boolean",
         "description": "The file is larger than the probe (2 MB): there are at least `count` products; connecting it will give the exact number."
        }
       }
      }
     },
     "unreachable": {
      "type": "boolean",
      "description": "The site's home page didn't open: \"not found\" then refers to the site, not to the feed."
     },
     "steps": {
      "type": "array",
      "items": {
       "type": "string"
      },
      "description": "Where to get the link manually: steps for the recognized engine, or generic ones. An empty list when a feed was found."
     }
    }
   },
   "ProductCard": {
    "type": "object",
    "title": "Product card",
    "description": "A catalog product the assistant recommends in the reply — exactly what's on the card. All fields come from the agent's catalog (the shop's feed), not from the model's text: a made-up price or a wrong URL can't appear here.",
    "required": [
     "id",
     "name",
     "url",
     "price",
     "available"
    ],
    "properties": {
     "id": {
      "type": "string",
      "description": "Product ID in the agent's catalog. Pass it in `about_products` when the next message is about this product."
     },
     "name": {
      "type": "string"
     },
     "url": {
      "type": "string",
      "description": "Product page in the shop."
     },
     "image": {
      "type": "string",
      "description": "Photo URL. Absent when the feed had no photo."
     },
     "price": {
      "type": "number"
     },
     "old_price": {
      "type": "number",
      "description": "Price before the discount — always greater than `price`. Absent when there's no discount."
     },
     "currency": {
      "type": "string",
      "description": "Currency code from the feed: `UAH`."
     },
     "available": {
      "type": "boolean",
      "description": "`false` → the product is out of stock."
     },
     "variants": {
      "type": "integer",
      "description": "How many variants (size, color…) the product on this card has; the card shows the variant the assistant referred to (its price and availability), and the window may add \"6 variants\". Variants of one group produce one card. Absent when there are no variants."
     }
    }
   },
   "ShopLook": {
    "type": "object",
    "required": [
     "site",
     "engine",
     "unreachable"
    ],
    "properties": {
     "site": {
      "type": "string",
      "description": "The site URL that was checked."
     },
     "engine": {
      "type": "string",
      "description": "The shop engine (`WooCommerce`, Horoshop, `Prom`, `OpenCart`, `Shopify`), or empty if not recognized."
     },
     "unreachable": {
      "type": "boolean",
      "description": "The home page didn't open: \"not recognized\" then refers to the site, not to the engine."
     },
     "preset_id": {
      "type": "string",
      "description": "Ready-made order connection for this engine (`woocommerce_orders`, `prom_orders`, `horoshop_orders`)."
     },
     "preset_title": {
      "type": "string",
      "description": "Its human-readable name."
     },
     "steps": {
      "type": "array",
      "items": {
       "type": "string"
      },
      "description": "Where to get the key in the admin panel — numbered steps for a person."
     },
     "note": {
      "type": "string",
      "description": "Why there's no connection (OpenCart, Shopify), or what to do when the engine isn't recognized."
     }
    },
    "description": "What the platform recognized about the shop for \"where is my order\"."
   },
   "FunnelStep": {
    "type": "object",
    "required": [
     "step",
     "label",
     "count"
    ],
    "properties": {
     "step": {
      "type": "string",
      "enum": [
       "opened",
       "asked",
       "cart",
       "product",
       "messenger",
       "continued",
       "lead",
       "human"
      ],
      "description": "Step: `opened` — the window was expanded; `asked` — the visitor wrote and the server accepted the message; `cart` — \"add to cart\" was clicked on the product card for the page's product; `product` — went to a product from a card under a reply or from a link to a product shown as a card; `messenger` — a messenger or phone button (to company staff); `continued` — \"Continue in Telegram\": the conversation with the assistant moved to its bot; `lead` — left a contact in the form; `human` — asked for a human (with the button, or the assistant handed off on its own)."
     },
     "label": {
      "type": "string",
      "description": "The step in human-readable words."
     },
     "count": {
      "type": "integer",
      "description": "How many conversations reached the step: the window counts each step once per conversation."
     },
     "percent": {
      "type": "integer",
      "description": "Percentage: for `asked` — of `opened`, for the rest — of `asked`. Absent when there are fewer conversations than `needed` or the base is zero."
     }
    }
   },
   "Funnel": {
    "type": "object",
    "required": [
     "period",
     "from",
     "enough",
     "needed",
     "off",
     "steps"
    ],
    "properties": {
     "period": {
      "type": "string",
      "enum": [
       "day",
       "week",
       "month"
      ],
      "description": "The period: the last day, 7 or 30 days — rolling, counted back from this moment."
     },
     "from": {
      "type": "string",
      "format": "date-time",
      "description": "The hour counting starts from (start of the hour, UTC)."
     },
     "enough": {
      "type": "boolean",
      "description": "There are enough conversations for the percentages to mean something. `false` — the numbers are there but the percentages aren't: \"not enough data\"."
     },
     "needed": {
      "type": "integer",
      "description": "How many opened windows are needed for percentages."
     },
     "off": {
      "type": "boolean",
      "description": "The owner turned off step counting (`widget_design.funnel: false`): new steps aren't counted; the numbers are what was counted before."
     },
     "steps": {
      "type": "array",
      "items": {
       "$ref": "#/components/schemas/FunnelStep"
      },
      "description": "Steps in funnel order."
     }
    }
   },
   "CatalogMiss": {
    "type": "object",
    "required": [
     "id",
     "query",
     "count",
     "first_at",
     "last_at"
    ],
    "properties": {
     "id": {
      "type": "string",
      "description": "The row's address: use it to dismiss the row."
     },
     "query": {
      "type": "string",
      "description": "The query the agent searched the catalog with, in lowercase. Queries with the same meaning are merged into one row."
     },
     "count": {
      "type": "integer",
      "description": "How many times it was searched for and not found."
     },
     "first_at": {
      "type": "string",
      "format": "date-time",
      "description": "When first."
     },
     "last_at": {
      "type": "string",
      "format": "date-time",
      "description": "When last."
     }
    }
   },
   "ContinueLink": {
    "type": "object",
    "title": "Continuation link",
    "required": [
     "url",
     "messenger",
     "carried"
    ],
    "properties": {
     "url": {
      "type": "string",
      "description": "What to open: a link of the form `https://t.me/<agent bot>?start=<ticket>`. The ticket is single-use and valid for 10 minutes — don't store or display the link; open it right away."
     },
     "messenger": {
      "type": "string",
      "enum": [
       "telegram"
      ],
      "description": "The messenger where the conversation will open."
     },
     "carried": {
      "type": "boolean",
      "description": "Whether the link carries the conversation over. `false` — there's no conversation yet: the link just opens the bot."
     }
    }
   },
   "ChannelPerson": {
    "type": "object",
    "required": [
     "key",
     "name",
     "role",
     "added_at"
    ],
    "properties": {
     "key": {
      "type": "string",
      "description": "The person's ID in the messenger; use it to unlink them."
     },
     "name": {
      "type": "string",
      "description": "The name given at linking, or the name from the messenger."
     },
     "role": {
      "type": "string",
      "enum": [
       "owner",
       "trusted"
      ],
      "description": "owner — the owner: a conversation with admin rights; the agent can see \"admin only\" actions. trusted — a trusted person: can write to the private channel, but doesn't have the owner's rights."
     },
     "added_at": {
      "type": "string",
      "format": "date-time"
     }
    }
   },
   "OwnerNote": {
    "type": "object",
    "properties": {
     "id": {
      "type": "string"
     },
     "text": {
      "type": "string"
     },
     "after": {
      "type": "string",
      "description": "What the agent read in the run it wrote the note from (a page, a search result, an action response). Empty or absent — nothing third-party was read, or the owner edited the note themselves. Such an entry may have come from someone else's text rather than the owner's words."
     },
     "created_at": {
      "type": "string",
      "format": "date-time"
     },
     "updated_at": {
      "type": "string",
      "format": "date-time"
     }
    },
    "required": [
     "id",
     "text",
     "created_at",
     "updated_at"
    ]
   },
   "OwnerNotes": {
    "type": "object",
    "properties": {
     "notes": {
      "type": "array",
      "items": {
       "$ref": "#/components/schemas/OwnerNote"
      }
     },
     "used": {
      "type": "integer",
      "description": "How many characters the notes take up in total."
     },
     "limit": {
      "type": "integer",
      "description": "The limit for all notes together, in characters. Exceeding it is an error; old notes aren't pushed out."
     },
     "note_limit": {
      "type": "integer",
      "description": "The limit for a single note, in characters."
     }
    },
    "required": [
     "notes",
     "used",
     "limit",
     "note_limit"
    ]
   },
   "AgentFile": {
    "type": "object",
    "properties": {
     "path": {
      "type": "string",
      "description": "Path relative to the folder root."
     },
     "size": {
      "type": "integer",
      "description": "Size in bytes."
     },
     "modified": {
      "type": "string",
      "format": "date-time",
      "description": "When the file was last modified."
     },
     "link": {
      "type": "boolean",
      "description": "A symbolic link: visible, but can't be downloaded."
     }
    },
    "required": [
     "path",
     "size",
     "modified"
    ]
   },
   "AgentFiles": {
    "type": "object",
    "properties": {
     "available": {
      "type": "boolean",
      "description": "Whether the agent has a persistent folder at all. false — the runtime isn't connected or doesn't support folders yet; the other fields are empty then."
     },
     "path": {
      "type": "string",
      "description": "Where the folder is visible to the agent's code (`/agent`)."
     },
     "exists": {
      "type": "boolean",
      "description": "Whether the agent has saved anything yet. false — the folder hasn't been created yet."
     },
     "files": {
      "type": "array",
      "items": {
       "$ref": "#/components/schemas/AgentFile"
      }
     },
     "truncated": {
      "type": "boolean",
      "description": "There are more files than shown; the used space counts all of them."
     },
     "used": {
      "type": "integer",
      "description": "How many bytes are used."
     },
     "quota": {
      "type": "integer",
      "description": "How many bytes are allowed."
     },
     "full": {
      "type": "boolean",
      "description": "Out of space: the agent gets the folder read-only until something is deleted."
     }
    },
    "required": [
     "available",
     "path",
     "exists",
     "files",
     "truncated",
     "used",
     "quota",
     "full"
    ]
   },
   "CalendarHours": {
    "type": "object",
    "description": "The owner's working hours in their time zone.",
    "properties": {
     "days": {
      "type": "array",
      "items": {
       "type": "integer",
       "minimum": 1,
       "maximum": 7
      },
      "description": "1 — Monday … 7 — Sunday."
     },
     "from": {
      "type": "string",
      "example": "09:00"
     },
     "to": {
      "type": "string",
      "example": "18:00"
     }
    }
   },
   "Calendar": {
    "type": "object",
    "description": "A connected calendar, without the secret.",
    "required": [
     "connected",
     "writable",
     "ask_before_writing"
    ],
    "properties": {
     "connected": {
      "type": "boolean"
     },
     "kind": {
      "type": "string",
      "enum": [
       "ics",
       "caldav"
      ],
      "description": "`ics` — a secret address, read-only; `caldav` — read and write."
     },
     "label": {
      "type": "string",
      "description": "Human-readable name: \"Google Calendar · Work\"."
     },
     "host": {
      "type": "string"
     },
     "username": {
      "type": "string"
     },
     "zone": {
      "type": "string",
      "description": "The owner's time zone, Europe/Kyiv by default."
     },
     "writable": {
      "type": "boolean"
     },
     "ask_before_writing": {
      "type": "boolean",
      "description": "Every write becomes an approval card for the owner."
     },
     "hours": {
      "$ref": "#/components/schemas/CalendarHours"
     },
     "hours_text": {
      "type": "string",
      "description": "Hours in words: \"Mon–Fri 09:00–18:00\"."
     },
     "connected_at": {
      "type": "string",
      "format": "date-time"
     },
     "checked_at": {
      "type": "string",
      "format": "date-time"
     },
     "last_ok": {
      "type": "string",
      "format": "date-time",
      "description": "When it was last read successfully."
     },
     "problem": {
      "type": "string",
      "description": "Why the last read attempt failed. Empty — it succeeded."
     }
    }
   },
   "CalendarEvent": {
    "type": "object",
    "required": [
     "title",
     "start",
     "end",
     "all_day",
     "recurring",
     "free",
     "tentative"
    ],
    "properties": {
     "title": {
      "type": "string"
     },
     "location": {
      "type": "string"
     },
     "description": {
      "type": "string"
     },
     "start": {
      "type": "string",
      "format": "date-time"
     },
     "end": {
      "type": "string",
      "format": "date-time"
     },
     "all_day": {
      "type": "boolean"
     },
     "recurring": {
      "type": "boolean"
     },
     "free": {
      "type": "boolean",
      "description": "Marked \"free\": doesn't block the time."
     },
     "tentative": {
      "type": "boolean"
     },
     "zone": {
      "type": "string",
      "description": "The event's own time zone."
     }
    }
   },
   "Playbook": {
    "type": "object",
    "description": "An agent skill — instructions for a specific task in the SKILL.md format of the open Agent Skills standard (agentskills.io). The agent sees only the name and \"when to use\", and loads the text itself when a task fits.",
    "properties": {
     "id": {
      "type": "string"
     },
     "name": {
      "type": "string",
      "description": "Name per the standard: lowercase letters of any alphabet, digits and hyphens, up to 64 characters."
     },
     "when": {
      "type": "string",
      "description": "When to use it (description in SKILL.md): what the skill does and for which tasks."
     },
     "body": {
      "type": "string",
      "description": "The instructions themselves (Markdown). Not returned in the list — only in a GET of a single skill."
     },
     "origin": {
      "type": "string",
      "enum": [
       "owner",
       "agent",
       "import"
      ],
      "description": "owner — written by the owner; agent — proposed by the agent in a conversation with the owner; import — taken from a link (source)."
     },
     "source": {
      "type": "string",
      "description": "The link it was imported from."
     },
     "after": {
      "type": "string",
      "description": "What third-party content the agent read in the run it proposed the draft from (a page, an email, a search). Such instructions may have come from someone else's text rather than from the owner."
     },
     "created_at": {
      "type": "string",
      "format": "date-time"
     },
     "updated_at": {
      "type": "string",
      "format": "date-time"
     },
     "approved_at": {
      "type": "string",
      "format": "date-time",
      "description": "When the owner approved it. Absent — a draft: it doesn't go into the prompt and isn't loaded."
     }
    },
    "required": [
     "id",
     "name",
     "when",
     "origin",
     "created_at",
     "updated_at"
    ]
   },
   "PlaybookItem": {
    "type": "object",
    "description": "A skill or draft in the list — without the text, with its size.",
    "properties": {
     "id": {
      "type": "string"
     },
     "name": {
      "type": "string",
      "description": "Name per the standard: lowercase letters of any alphabet, digits and hyphens, up to 64 characters."
     },
     "when": {
      "type": "string",
      "description": "When to use it (description in SKILL.md): what the skill does and for which tasks."
     },
     "body": {
      "type": "string",
      "description": "The instructions themselves (Markdown). Not returned in the list — only in a GET of a single skill."
     },
     "origin": {
      "type": "string",
      "enum": [
       "owner",
       "agent",
       "import"
      ],
      "description": "owner — written by the owner; agent — proposed by the agent in a conversation with the owner; import — taken from a link (source)."
     },
     "source": {
      "type": "string",
      "description": "The link it was imported from."
     },
     "after": {
      "type": "string",
      "description": "What third-party content the agent read in the run it proposed the draft from (a page, an email, a search). Such instructions may have come from someone else's text rather than from the owner."
     },
     "created_at": {
      "type": "string",
      "format": "date-time"
     },
     "updated_at": {
      "type": "string",
      "format": "date-time"
     },
     "approved_at": {
      "type": "string",
      "format": "date-time",
      "description": "When the owner approved it. Absent — a draft: it doesn't go into the prompt and isn't loaded."
     },
     "draft": {
      "type": "boolean",
      "description": "A draft awaiting the owner's approval."
     },
     "size": {
      "type": "integer",
      "description": "How many characters the text has."
     }
    },
    "required": [
     "id",
     "name",
     "when",
     "origin",
     "created_at",
     "updated_at",
     "draft",
     "size"
    ]
   },
   "PlaybookRisk": {
    "type": "object",
    "description": "A line of the skill worth pausing on before approving: where it sends something, URLs, keys, money, scripts, an attempt to override other instructions. A hint, not a filter: an empty list doesn't mean \"safe\".",
    "properties": {
     "line": {
      "type": "integer"
     },
     "text": {
      "type": "string"
     },
     "why": {
      "type": "string"
     }
    },
    "required": [
     "line",
     "text",
     "why"
    ]
   },
   "FetchedPlaybook": {
    "type": "object",
    "description": "A skill read from a link, before approval. Nothing is saved.",
    "properties": {
     "name": {
      "type": "string"
     },
     "when": {
      "type": "string"
     },
     "body": {
      "type": "string"
     },
     "license": {
      "type": "string"
     },
     "link": {
      "type": "string",
      "description": "The link as it was given."
     },
     "raw": {
      "type": "string",
      "description": "What was actually read: a GitHub page is rewritten to the raw SKILL.md."
     },
     "digest": {
      "type": "string",
      "description": "A fingerprint of the text shown. Saving is only possible with it: if the file at the link has changed, import will refuse."
     },
     "risks": {
      "type": "array",
      "items": {
       "$ref": "#/components/schemas/PlaybookRisk"
      }
     },
     "ignored": {
      "type": "array",
      "items": {
       "type": "string"
      },
      "description": "Standard fields the platform doesn't enforce (allowed-tools, compatibility), in words."
     }
    },
    "required": [
     "name",
     "when",
     "body",
     "link",
     "raw",
     "digest",
     "risks",
     "ignored"
    ]
   },
   "WatchNodeConfig": {
    "type": "object",
    "properties": {
     "select": {
      "type": "string",
      "description": "CSS selector for part of the page (\"the block with the price\"): tag, #id, .class, [attribute], [attribute=value], nesting with a space, alternatives separated by commas. Empty — the whole page."
     },
     "ignore": {
      "type": "array",
      "items": {
       "type": "string"
      },
      "description": "Words whose lines don't count as a change (a view counter, etc.). Time of day and \"N minutes ago\" never count."
     },
     "browser": {
      "type": "boolean",
      "description": "Read with a real browser on every check (costs sandbox seconds). Without this, a browser is used automatically when a plain request sees no text on the page."
     }
    },
    "description": "Page watching. A read failure doesn't fail the run: several checks in a row without a successful read become a `page_unreadable` incident."
   },
   "Payment": {
    "type": "object",
    "description": "One payment: a link issued by the agent and its status.",
    "required": [
     "id",
     "amount",
     "currency",
     "money",
     "purpose",
     "source",
     "status",
     "status_words",
     "provider",
     "test",
     "created_at",
     "updated_at"
    ],
    "properties": {
     "id": {
      "type": "string",
      "description": "Payment number (pay_…); also the order number in the payment service."
     },
     "amount": {
      "type": "integer",
      "format": "int64",
      "description": "Amount in minor units (kopiykas)."
     },
     "currency": {
      "type": "string",
      "enum": [
       "UAH",
       "USD",
       "EUR"
      ]
     },
     "money": {
      "type": "string",
      "description": "Amount in words for a person: \"1,250 UAH\"."
     },
     "refunded": {
      "type": "integer",
      "format": "int64",
      "description": "How much of the paid amount has been refunded, in minor units; absent until anything has been refunded."
     },
     "purpose": {
      "type": "string",
      "description": "The payment purpose the buyer saw."
     },
     "order": {
      "type": "string",
      "description": "The shop's order number, if the payment was for an order."
     },
     "source": {
      "type": "string",
      "enum": [
       "catalog",
       "order",
       "service",
       "owner"
      ],
      "description": "Where the amount came from: catalog prices, a verified order, the services price list, or named by the owner."
     },
     "status": {
      "type": "string",
      "enum": [
       "awaiting_owner",
       "declined",
       "not_issued",
       "created",
       "processing",
       "accepted",
       "paid",
       "failed",
       "expired",
       "unverified",
       "reversed_partly",
       "reversed"
      ],
      "description": "Status. `awaiting_owner` — the amount is over the cap and awaits the owner's permission; there's no link yet; `declined` — permission wasn't given (the owner declined or the card expired); `not_issued` — the owner allowed it, but the link couldn't be created (the payment service keys were disconnected while the amount was awaiting permission); `accepted` — the money was charged to the buyer, but the payment service hasn't credited it to the shop yet (LiqPay: the shop hasn't passed verification) — this isn't a payment yet; `reversed_partly` — paid, and part of the money was refunded in the payment service's dashboard (how much — `refunded`); `expired` — the link expired without payment (as reported by the payment service); `unverified` — the link expired, and asking the service whether a payment was made failed (keys disconnected or the service didn't respond)."
     },
     "status_words": {
      "type": "string",
      "description": "Status in words for a person."
     },
     "provider": {
      "type": "string",
      "enum": [
       "liqpay"
      ]
     },
     "url": {
      "type": "string",
      "description": "Link for the buyer; absent while the amount awaits permission."
     },
     "test": {
      "type": "boolean",
      "description": "A test payment in the payment service — no real money involved."
     },
     "created_at": {
      "type": "string",
      "format": "date-time"
     },
     "updated_at": {
      "type": "string",
      "format": "date-time"
     }
    }
   },
   "Payments": {
    "type": "object",
    "description": "The agent's payments. `recent` is always a list: empty means there have been no payments yet; if it couldn't be read, the whole response is a 500, not an empty list.",
    "required": [
     "connected",
     "provider",
     "providers",
     "limits",
     "links_per_conversation",
     "prices",
     "recent"
    ],
    "properties": {
     "connected": {
      "type": "boolean",
      "description": "Whether the agent issues payment links."
     },
     "provider": {
      "type": "string",
      "description": "Who currently accepts the money: `liqpay`, or empty — payments aren't connected."
     },
     "providers": {
      "type": "array",
      "items": {
       "type": "object",
       "required": [
        "id",
        "title",
        "ready",
        "keys"
       ],
       "properties": {
        "id": {
         "type": "string",
         "enum": [
          "liqpay"
         ]
        },
        "title": {
         "type": "string"
        },
        "ready": {
         "type": "boolean",
         "description": "All of this service's keys are present in the agent's keys."
        },
        "keys": {
         "type": "array",
         "items": {
          "type": "string"
         },
         "description": "Names of the agent's keys under which the service keys are stored."
        }
       }
      }
     },
     "limits": {
      "type": "object",
      "additionalProperties": {
       "type": "integer",
       "format": "int64"
      },
      "description": "Cap on a single link, per currency, in minor units. A larger amount awaits the owner's permission."
     },
     "links_per_conversation": {
      "type": "integer",
      "description": "How many unpaid links one conversation can get per day: the effective value — set by the owner or the default (5). Beyond that the agent doesn't issue new links; paid ones don't count."
     },
     "prices": {
      "type": "array",
      "items": {
       "$ref": "#/components/schemas/PaymentPrice"
      }
     },
     "recent": {
      "type": "array",
      "items": {
       "$ref": "#/components/schemas/Payment"
      },
      "description": "Recent payments, newest first (up to 20)."
     }
    }
   },
   "PaymentPrice": {
    "type": "object",
    "required": [
     "name",
     "amount",
     "currency"
    ],
    "properties": {
     "name": {
      "type": "string"
     },
     "amount": {
      "type": "integer",
      "format": "int64",
      "description": "Price in minor units."
     },
     "currency": {
      "type": "string",
      "enum": [
       "UAH",
       "USD",
       "EUR"
      ]
     }
    }
   },
   "Plan": {
    "type": "object",
    "required": [
     "id",
     "name",
     "amount",
     "currency",
     "period",
     "max_bots",
     "monthly_credits",
     "max_site_pages"
    ],
    "properties": {
     "id": {
      "type": "string"
     },
     "name": {
      "type": "string",
      "description": "Human-readable plan name."
     },
     "amount": {
      "type": "number",
      "description": "Price per period in `currency`."
     },
     "currency": {
      "type": "string",
      "example": "UAH"
     },
     "period": {
      "type": "string",
      "enum": [
       "month",
       "year"
      ]
     },
     "max_bots": {
      "type": "integer",
      "description": "How many agents the plan allows. `-1` — unlimited."
     },
     "monthly_credits": {
      "type": "integer",
      "description": "Credits per month. `-1` — unlimited."
     },
     "max_site_pages": {
      "type": "integer",
      "description": "How many pages of ONE site the agent keeps in knowledge on this plan. One cap for all entry points: the conversation with the Builder, the dashboard, the API (`max_pages` above it is truncated) and scheduled re-reads."
     },
     "purchasable": {
      "type": "boolean",
      "description": "Whether this plan can be paid for. The free one is shown in the list but can't be bought — don't infer this from the price."
     }
    },
    "description": "Plan."
   },
   "CreditPack": {
    "type": "object",
    "required": [
     "id",
     "name",
     "credits",
     "amount",
     "currency"
    ],
    "properties": {
     "id": {
      "type": "string"
     },
     "name": {
      "type": "string"
     },
     "credits": {
      "type": "integer",
      "description": "How many credits the pack adds."
     },
     "amount": {
      "type": "number",
      "description": "Price in `currency`."
     },
     "currency": {
      "type": "string"
     }
    },
    "description": "A credit pack on top of the plan."
   },
   "Checkout": {
    "type": "object",
    "required": [
     "data",
     "signature",
     "action_url",
     "order_id",
     "expires_at",
     "resumed"
    ],
    "properties": {
     "data": {
      "type": "string",
      "description": "The `data` field of the payment gateway form."
     },
     "signature": {
      "type": "string",
      "description": "The `signature` field of the same form."
     },
     "action_url": {
      "type": "string",
      "description": "The URL the form is submitted to (POST)."
     },
     "order_id": {
      "type": "string",
      "description": "The order this form pays for."
     },
     "expires_at": {
      "type": "string",
      "format": "date-time",
      "description": "Until when the payment gateway accepts payment for this order."
     },
     "resumed": {
      "type": "boolean",
      "description": "`true` means this is not a new order: a payment was already open, and the form leads to the same checkout."
     }
    },
    "description": "What you need to send the customer to payment: a form with `data` and `signature`, posted to `action_url`. Until the order is completed, a repeated request returns the form for THE SAME order (`resumed: true`) instead of creating a second one."
   },
   "Media": {
    "type": "object",
    "required": [
     "id",
     "bot_id",
     "kind",
     "origin",
     "name",
     "description",
     "content_type",
     "size",
     "url",
     "created_at"
    ],
    "properties": {
     "id": {
      "type": "string"
     },
     "bot_id": {
      "type": "string"
     },
     "kind": {
      "type": "string",
      "enum": [
       "image",
       "file"
      ],
      "description": "An image is shown inline in the conversation; a file is shown as a link."
     },
     "origin": {
      "type": "string",
      "enum": [
       "owner",
       "visitor",
       "skill",
       "generated"
      ],
      "description": "Who added the file: the owner, a visitor, an agent action, or the agent itself (generated)."
     },
     "name": {
      "type": "string"
     },
     "description": {
      "type": "string",
      "description": "What the file contains — the agent uses this to decide when to send it."
     },
     "content_type": {
      "type": "string"
     },
     "size": {
      "type": "integer",
      "description": "In bytes."
     },
     "url": {
      "type": "string",
      "description": "The full URL of the file."
     },
     "created_at": {
      "type": "string",
      "format": "date-time"
     }
    },
    "description": "A file the agent can send into a conversation."
   },
   "TelegramSupport": {
    "type": "object",
    "properties": {
     "has_token": {
      "type": "boolean",
      "description": "A token is saved. The token itself can't be read back."
     },
     "bot_username": {
      "type": "string",
      "description": "The bot's Telegram username, as reported by Telegram. Empty until the token has been checked."
     },
     "timezone": {
      "type": "string",
      "description": "The IANA time zone in which operator shifts are counted."
     },
     "agents": {
      "type": "array",
      "items": {
       "type": "object",
       "properties": {
        "chat_id": {
         "type": "string"
        },
        "name": {
         "type": "string"
        },
        "active": {
         "type": "boolean"
        },
        "shifts": {
         "type": "array",
         "items": {
          "type": "object",
          "properties": {
           "days": {
            "type": "array",
            "items": {
             "type": "integer"
            },
            "description": "0=Sunday … 6=Saturday."
           },
           "from": {
            "type": "integer",
            "description": "Minutes from midnight."
           },
           "to": {
            "type": "integer"
           }
          }
         }
        }
       }
      },
      "description": "Operators who receive escalations."
     },
     "known_chats": {
      "type": "array",
      "items": {
       "type": "object",
       "properties": {
        "chat_id": {
         "type": "string"
        },
        "name": {
         "type": "string"
        }
       }
      },
      "description": "Chats that sent `/start` to the bot themselves — operators are picked from these."
     },
     "last_error": {
      "type": "string",
      "description": "The last error returned by Telegram. Empty means everything is fine."
     },
     "last_error_at": {
      "type": "string",
      "description": "When it happened. Empty if there have been no errors."
     }
    },
    "required": [
     "has_token",
     "bot_username",
     "timezone",
     "agents",
     "known_chats",
     "last_error",
     "last_error_at"
    ]
   },
   "BuilderFrame": {
    "type": "object",
    "properties": {
     "delta": {
      "type": "string",
      "description": "The next piece of the reply text."
     },
     "step": {
      "type": "string",
      "description": "A change that was just applied, in the tool's own words."
     },
     "section": {
      "type": "string",
      "description": "The agent section the change touched. Arrives together with `step`."
     },
     "action": {
      "type": "string",
      "description": "The Builder is running an action and isn't replying yet — machine-readable state."
     },
     "action_count": {
      "type": "integer",
      "description": "How many actions have been run in this turn."
     },
     "error": {
      "type": "string",
      "description": "The turn failed — explained in human-readable words."
     },
     "code": {
      "type": "string",
      "description": "Machine-readable code for `error`."
     },
     "done": {
      "type": "boolean",
      "description": "The last frame of the turn."
     },
     "answer": {
      "type": "string",
      "description": "The full reply — in the `done` frame."
     },
     "changed": {
      "type": "array",
      "items": {
       "type": "string"
      },
      "description": "Sections the turn touched — in the `done` frame. A reconciliation point for a client that missed a `step` frame."
     },
     "choices": {
      "type": "array",
      "items": {
       "type": "string"
      },
      "description": "Answer options for the Builder's question, shown as buttons. Absent when it didn't ask anything."
     },
     "clean": {
      "type": "boolean",
      "description": "Only together with `error`: the turn changed nothing and started nothing — the same request can be sent again."
     },
     "switch_workspace": {
      "type": "string",
      "description": "Only in the `done` frame. The workspace the dashboard should switch to after this turn (the person asked to move to another workspace or create their own). The workspace cookie is held by the browser, so the browser does the switching — `POST /v1/dashboard/workspace`."
     },
     "reload": {
      "type": "boolean",
      "description": "Only in the `done` frame. The dashboard should reload completely: the person left the team, and the workspace under them has changed."
     },
     "signed_out": {
      "type": "boolean",
      "description": "Only in the `done` frame. The person was signed out on all devices, including this one: the dashboard ends the session (`POST /v1/auth/logout`) and goes to the sign-in page."
     },
     "place_file": {
      "type": "object",
      "description": "Only in the `done` frame. Where to put the file attached to this message. The dashboard does the placing: `learn` — `POST …/files`, `send` — `POST …/media`, `actions` — `POST …/skills/import-file` with `install=1`.",
      "properties": {
       "kind": {
        "type": "string",
        "enum": [
         "learn",
         "send",
         "actions"
        ]
       },
       "agent": {
        "type": "string",
        "description": "The agent the file belongs to."
       },
       "base_url": {
        "type": "string",
        "description": "For `actions`: the service address, if the person gave one."
       }
      }
     },
     "thread": {
      "type": "string",
      "description": "Only in the `done` frame. The chat this turn was recorded in. A dashboard with no chat named (or with another agent's chat) picks up this agent's chat and continues in it."
     },
     "created_agent": {
      "type": "string",
      "description": "Only in the `done` frame. The agent this turn created. The dashboard switches to it: the person's next messages are about that agent."
     },
     "created_thread": {
      "type": "string",
      "description": "Only in the `done` frame. The new agent's chat, where this request and the reply were moved so the conversation about it continues instead of starting over."
     },
     "action_label": {
      "type": "string",
      "description": "Label for the state of the running action (provided by the action's owner). Absent — the window shows its own generic one."
     }
    },
    "description": "One frame of the Builder stream — JSON in the `data:` field. Tell frames apart by which field is present (`delta` / `step` / `action` / `error` / `done`); skip a frame that has none of the known fields."
   },
   "AgentAccessKey": {
    "type": "object",
    "description": "An agent access key. The value itself isn't here: it exists only in the response that issued it.",
    "properties": {
     "id": {
      "type": "string",
      "description": "The key ID — used to revoke the key."
     },
     "name": {
      "type": "string",
      "description": "Who the key is for, in the owner's words."
     },
     "prefix": {
      "type": "string",
      "description": "The first characters of the key: use them to check which key is configured in a third-party app."
     },
     "created_at": {
      "type": "string",
      "format": "date-time"
     },
     "last_used_at": {
      "type": "string",
      "format": "date-time",
      "description": "When the key was last used (accurate to ten minutes). Absent means it has never been used."
     }
    },
    "required": [
     "id",
     "name",
     "prefix",
     "created_at"
    ]
   },
   "AgentAccess": {
    "type": "object",
    "properties": {
     "keys": {
      "type": "array",
      "items": {
       "$ref": "#/components/schemas/AgentAccessKey"
      }
     },
     "key_limit": {
      "type": "integer",
      "description": "How many keys one agent can have."
     },
     "visible": {
      "type": "boolean",
      "description": "Whether other agents can see this agent's card without a key. Off by default."
     },
     "description": {
      "type": "string",
      "description": "A description of the agent for other agents: what to ask it about. Public text."
     },
     "description_limit": {
      "type": "integer",
      "description": "The description length limit, in characters."
     },
     "mcp_url": {
      "type": "string",
      "description": "The URL of the agent's MCP server: paste it into a third-party app together with the key."
     },
     "a2a_url": {
      "type": "string",
      "description": "The A2A endpoint URL."
     },
     "card_url": {
      "type": "string",
      "description": "The A2A card URL. Responds only when `visible`."
     }
    },
    "required": [
     "keys",
     "key_limit",
     "visible",
     "description",
     "description_limit",
     "mcp_url",
     "a2a_url",
     "card_url"
    ]
   },
   "AgentAccessSetup": {
    "type": "object",
    "description": "A ready-made configuration for third-party apps — with the key inside, so it exists only in the response that issued the key.",
    "properties": {
     "header": {
      "type": "string",
      "description": "The value of the `Authorization` header."
     },
     "claude_code": {
      "type": "string",
      "description": "A terminal command (Claude Code)."
     },
     "cursor": {
      "type": "string",
      "description": "The contents of `mcp.json` for Cursor."
     },
     "mcp_json": {
      "type": "string",
      "description": "The contents of `.mcp.json` for clients that read `mcpServers` with a transport type."
     }
    },
    "required": [
     "header",
     "claude_code",
     "cursor",
     "mcp_json"
    ]
   },
   "Workspace": {
    "type": "object",
    "description": "A workspace the person works in: their own, or a team they were invited to.",
    "properties": {
     "id": {
      "type": "string"
     },
     "role": {
      "$ref": "#/components/schemas/Role"
     },
     "owner_email": {
      "type": "string",
      "description": "Whose workspace this is. Workspaces have no names — they are identified by their owner. Empty if the address couldn't be read."
     },
     "own": {
      "type": "boolean",
      "description": "The person's own workspace: they are its owner."
     },
     "current": {
      "type": "boolean",
      "description": "The workspace the person is working in right now."
     }
    }
   },
   "Transfer": {
    "type": "object",
    "description": "An agent transfer request.",
    "properties": {
     "id": {
      "type": "string"
     },
     "agent_id": {
      "type": "string"
     },
     "agent_name": {
      "type": "string"
     },
     "from_email": {
      "type": "string",
      "description": "Who is transferring."
     },
     "to_email": {
      "type": "string",
      "description": "To whom. The request is tied to the account with this email, not to the address itself."
     },
     "status": {
      "type": "string",
      "enum": [
       "pending",
       "accepted",
       "declined",
       "cancelled",
       "expired"
      ],
      "description": "`pending` — waiting for the recipient's decision. `accepted` — the agent now belongs to the recipient. `declined` — the recipient refused. `cancelled` — the sender cancelled or the agent was deleted. `expired` — the deadline passed without a decision."
     },
     "created_at": {
      "type": "string",
      "format": "date-time"
     },
     "expires_at": {
      "type": "string",
      "format": "date-time"
     },
     "decided_at": {
      "type": "string",
      "format": "date-time",
      "description": "When the request was accepted, declined or cancelled."
     },
     "can_accept": {
      "type": "boolean",
      "description": "Only in pending incoming requests: whether the recipient's own workspace has room for one more agent."
     },
     "blocked": {
      "type": "string",
      "description": "Only when `can_accept` is `false`: why there's nowhere to accept it, in human-readable words."
     }
    },
    "required": [
     "id",
     "agent_id",
     "agent_name",
     "from_email",
     "to_email",
     "status",
     "created_at",
     "expires_at"
    ]
   },
   "TrainingDraftAction": {
    "type": "object",
    "required": [
     "tool",
     "note",
     "runnable"
    ],
    "properties": {
     "tool": {
      "type": "string",
      "description": "The action name as the agent and the owner see it."
     },
     "note": {
      "type": "string",
      "description": "The same in words: what the agent would do and with which arguments (truncated). The arguments themselves aren't in the response: they stay on the server, and the decision doesn't accept them."
     },
     "runnable": {
      "type": "boolean",
      "description": "`true` → the action can run together with sending the reply: it's an owner action (an HTTP call). `false` → it isn't run from a draft (hand the conversation to a human, add to the calendar, send a payment link) — the person sees it and does it themselves."
     },
     "outcome": {
      "type": "string",
      "enum": [
       "done",
       "dropped",
       "failed",
       "skipped"
      ],
      "description": "How it ended after the decision: `done` — run, `dropped` — the person removed it, `failed` — didn't run (the reply is then not sent), `skipped` — not run from a draft. The field is absent until there's a decision."
     },
     "result": {
      "type": "string",
      "description": "The first line of the action's result, or the reason it didn't run."
     }
    }
   },
   "TrainingDraft": {
    "type": "object",
    "description": "A draft of the agent's reply waiting for a human — or the record of the decision made on it. One row in different states.",
    "required": [
     "id",
     "session_id",
     "status",
     "question",
     "draft",
     "sources",
     "actions",
     "revision",
     "created_at",
     "edit"
    ],
    "properties": {
     "id": {
      "type": "string"
     },
     "session_id": {
      "allOf": [
       {
        "$ref": "#/components/schemas/SessionID"
       }
      ],
      "description": "The conversation in which the customer asked: use it to open the transcript (`GET …/threads/{sid}`)."
     },
     "status": {
      "type": "string",
      "enum": [
       "composing",
       "pending",
       "sending",
       "sent",
       "edited",
       "own",
       "auto",
       "stale"
      ],
      "description": "`composing` — the agent is still writing the draft; `pending` — waiting for a human; `sending` — decided, the reply is on its way; `sent` — sent as is; `edited` — corrected and sent; `own` — the person replied themselves; `auto` — the draft went out on its own because the operator didn't reply within the time the owner set; `stale` — the customer wrote more, and the draft was rewritten."
     },
     "question": {
      "type": "string",
      "description": "The customer messages the draft replies to (several are separated by newlines). Third-party text."
     },
     "draft": {
      "type": "string",
      "description": "The agent's draft. Empty when the agent didn't write one (`note` says why) — then you can only reply yourself."
     },
     "sources": {
      "type": "array",
      "items": {
       "type": "string"
      },
      "description": "Which knowledge sources the agent relied on: the source name or its URL."
     },
     "actions": {
      "type": "array",
      "items": {
       "$ref": "#/components/schemas/TrainingDraftAction"
      },
      "description": "What the agent would do in this turn: actions with external effects are recorded, not run."
     },
     "note": {
      "type": "string",
      "description": "A service note for the operator: no draft, an action didn't run, the reply wasn't delivered."
     },
     "revision": {
      "type": "integer",
      "description": "Which draft in a row this is in the conversation. Greater than zero means the customer wrote more while the previous one was waiting, and this one was written taking all of their messages into account."
     },
     "created_at": {
      "type": "integer",
      "description": "When the customer's message arrived, Unix milliseconds."
     },
     "ready_at": {
      "type": "integer",
      "description": "When the draft became ready for a decision."
     },
     "on_idle": {
      "type": "string",
      "enum": [
       "send",
       "later"
      ],
      "description": "What happens if nobody replies by `due_at`: `send` — the draft goes out on its own (only without actions), `later` — the customer is told «відповімо пізніше» (\"we'll reply later\"). Field absent — the draft waits as long as needed."
     },
     "due_at": {
      "type": "integer",
      "description": "When `on_idle` fires, Unix milliseconds."
     },
     "later_at": {
      "type": "integer",
      "description": "When the customer was told «відповімо пізніше» (\"we'll reply later\")."
     },
     "holder_id": {
      "type": "string",
      "description": "Who is editing the draft right now (a soft marker that expires after two minutes). Field absent — nobody."
     },
     "holder_name": {
      "type": "string"
     },
     "final": {
      "type": "string",
      "description": "What was sent to the customer."
     },
     "comment": {
      "type": "string",
      "description": "\"What was wrong\" — the operator's words for training. Not sent to the customer."
     },
     "by_id": {
      "type": "string",
      "description": "Who decided. Empty — the draft went out on its own, or the decision was carried over from the agent's previous owner."
     },
     "by_name": {
      "type": "string"
     },
     "decided_at": {
      "type": "integer",
      "description": "When the decision was made, Unix milliseconds."
     },
     "edit": {
      "type": "number",
      "description": "How much what was sent differs from the draft: 0 — identical, 1 — not a single word in common."
     },
     "edit_words": {
      "type": "string",
      "description": "The same in words: \"no edits\", \"small edit\", \"noticeable edit\", \"rewritten\", \"answered yourself\", \"sent on its own\"."
     },
     "applied": {
      "type": "string",
      "enum": [
       "knowledge",
       "playbook",
       "dismissed"
      ],
      "description": "How the owner responded to the suggestion built from this correction. Field absent — not yet."
     }
    }
   },
   "TrainingStats": {
    "type": "object",
    "description": "The readiness counter. Computed from the same decisions that `GET …/training/decisions` returns.",
    "required": [
     "window",
     "decided",
     "clean",
     "edited",
     "own",
     "auto",
     "ready"
    ],
    "properties": {
     "window": {
      "type": "integer",
      "description": "Over how many of the most recent HUMAN decisions the counter is computed."
     },
     "decided": {
      "type": "integer",
      "description": "How many such decisions actually exist (no more than `window`)."
     },
     "clean": {
      "type": "integer",
      "description": "Of these, sent as is."
     },
     "edited": {
      "type": "integer",
      "description": "Corrected and sent."
     },
     "own": {
      "type": "integer",
      "description": "The person replied themselves."
     },
     "auto": {
      "type": "integer",
      "description": "How many drafts went out on their own over the same period. Nobody read them, so they aren't counted in the share."
     },
     "ready": {
      "type": "boolean",
      "description": "`true` → the window is full and the \"as is\" share is consistently high: the mode can be turned off or switched to \"Send it alone\"."
     }
    }
   },
   "TrainingSuggestion": {
    "type": "object",
    "description": "A suggestion to the owner built from several corrections whose questions are close in meaning. Built by rules, without a model.",
    "required": [
     "id",
     "count",
     "of",
     "questions",
     "answer",
     "comments",
     "ids"
    ],
    "properties": {
     "id": {
      "type": "string",
      "description": "The suggestion ID — used to apply or reject it."
     },
     "count": {
      "type": "integer",
      "description": "How many similar corrections are in the group."
     },
     "of": {
      "type": "integer",
      "description": "Out of how many corrections in total."
     },
     "questions": {
      "type": "array",
      "items": {
       "type": "string"
      },
      "description": "Up to three questions from the group, newest first. Third-party text."
     },
     "answer": {
      "type": "string",
      "description": "What the person replied most recently."
     },
     "comments": {
      "type": "array",
      "items": {
       "type": "string"
      },
      "description": "Up to three operator comments."
     },
     "ids": {
      "type": "array",
      "items": {
       "type": "string"
      },
      "description": "The decisions the suggestion was built from."
     }
    }
   },
   "BaseShare": {
    "type": "object",
    "properties": {
     "count": {
      "type": "integer",
      "description": "How many."
     },
     "of": {
      "type": "integer",
      "description": "Out of how many. 0 means there's nothing to count from, which isn't the same as zero percent."
     }
    },
    "required": [
     "count",
     "of"
    ]
   },
   "BaseSources": {
    "type": "object",
    "properties": {
     "found": {
      "type": "integer",
      "description": "How many sources are in the registry."
     },
     "active": {
      "type": "integer",
      "description": "Sources whose latest publication is no older than active_days days. Computed from the date in the card at the moment of the request, not from the agent's word."
     },
     "active_days": {
      "type": "integer",
      "description": "For how many days after its latest publication a source still counts as active."
     },
     "on_topic": {
      "type": "integer",
      "description": "Sources with relevance of at least relevance_from — \"on topic with high confidence\"."
     },
     "relevance_from": {
      "type": "integer",
      "description": "The score from which a source counts as on topic."
     },
     "off": {
      "type": "integer",
      "description": "Sources the owner turned off: they stay in the registry, but the agent doesn't visit them."
     },
     "access": {
      "type": "array",
      "items": {
       "type": "object",
       "properties": {
        "access": {
         "type": "string",
         "description": "Access state: «читається» (\"readable\"), «заборонено robots.txt» (\"blocked by robots.txt\"), «потрібен вхід» (\"login required\"), «не відповідає» (\"not responding\"), «потрібен API» (\"API required\"), «не перевірено» (\"not checked\")."
        },
        "count": {
         "type": "integer"
        }
       },
       "required": [
        "access",
        "count"
       ]
      },
      "description": "How many sources are in each access state; states with no sources are omitted."
     }
    },
    "required": [
     "found",
     "active",
     "active_days",
     "on_topic",
     "relevance_from",
     "off",
     "access"
    ],
    "description": "Source registry counters. Each number is a count of cards."
   },
   "BaseQuality": {
    "type": "object",
    "properties": {
     "coverage": {
      "$ref": "#/components/schemas/BaseShare",
      "description": "How many sources from the reference list the agent found on its own."
     },
     "precision": {
      "$ref": "#/components/schemas/BaseShare",
      "description": "How many of the results a person rated are a fit."
     },
     "results": {
      "type": "integer",
      "description": "How many objects are in the base; a group of duplicates counts as one."
     },
     "duplicates": {
      "$ref": "#/components/schemas/BaseShare",
      "description": "How many result cards are copies of an object already present, out of all result cards."
     },
     "maybe": {
      "type": "integer",
      "description": "How many cards are waiting for a \"same or not\" decision."
     },
     "traceable": {
      "$ref": "#/components/schemas/BaseShare",
      "description": "How many results link to the page they were taken from."
     },
     "fresh_hours": {
      "type": "number",
      "description": "How many hours after publication the agent finds a listing (median)."
     },
     "fresh_of": {
      "type": "integer",
      "description": "How many cards freshness was computed from. 0 means the cards have no publication dates."
     },
     "spent": {
      "type": "integer",
      "description": "Credits spent by the agent."
     },
     "spent_known": {
      "type": "boolean",
      "description": "false means this build has no spending log, and cost isn't computed."
     },
     "cost_per_fit": {
      "type": "number",
      "description": "Credits per result marked as a fit. 0 until any are marked."
     },
     "cards": {
      "type": "integer",
      "description": "How many cards are in the agent's notebook."
     },
     "max_cards": {
      "type": "integer",
      "description": "How many cards the notebook can hold: the ceiling after which new ones aren't added."
     }
    },
    "required": [
     "coverage",
     "precision",
     "results",
     "duplicates",
     "maybe",
     "traceable",
     "fresh_hours",
     "fresh_of",
     "spent",
     "spent_known",
     "cost_per_fit",
     "cards",
     "max_cards"
    ],
    "description": "Search quality metrics — from the cards and the spending log."
   },
   "SavedSearch": {
    "type": "object",
    "properties": {
     "id": {
      "type": "string"
     },
     "name": {
      "type": "string",
      "description": "Title in a few words."
     },
     "kind": {
      "type": "string",
      "description": "The notebook card set; empty means «результати» (\"results\")."
     },
     "text": {
      "type": "string",
      "description": "Words that must appear in the card."
     },
     "like": {
      "type": "string",
      "description": "A \"similar in meaning\" description; works only where the notebook searches by meaning."
     },
     "where": {
      "type": "array",
      "items": {
       "type": "string"
      },
      "description": "Field conditions as they're written: \"price<=450000\", \"plot>=2000\", \"district~chambery\", \"phone has\"."
     },
     "strict": {
      "type": "boolean",
      "description": "Only cards where every condition is confirmed."
     },
     "every_hours": {
      "type": "integer",
      "description": "How often the platform runs the search by itself, in hours; 0 means only on button press."
     },
     "paused": {
      "type": "boolean"
     },
     "created_at": {
      "type": "string"
     },
     "last_run_at": {
      "type": "string",
      "description": "When it last ran; absent means it hasn't run yet."
     },
     "prev_run_at": {
      "type": "string",
      "description": "The previous pass: \"new since last time\" means cards that appeared after it."
     },
     "last_new": {
      "type": "integer",
      "description": "How many new items the last pass found."
     },
     "last_total": {
      "type": "integer",
      "description": "How many objects match the search in total."
     },
     "last_error": {
      "type": "string",
      "description": "Why the last pass failed. Absent means it succeeded."
     },
     "next_at": {
      "type": "string",
      "description": "When the next scheduled pass is. Absent means there's no schedule or the search is paused."
     }
    },
    "required": [
     "id",
     "name",
     "kind",
     "where",
     "every_hours",
     "paused",
     "created_at",
     "last_new",
     "last_total"
    ],
    "description": "A saved search: a query and conditions that the platform runs over the collected base by itself — without a model and without credits."
   },
   "BaseSettings": {
    "type": "object",
    "properties": {
     "crm_url": {
      "type": "string",
      "description": "The webhook URL results are sent to. Empty means nowhere."
     },
     "contact_days": {
      "type": "integer",
      "description": "How many days a contact the agent hasn't touched is kept; after that the platform removes it."
     },
     "auto_publish": {
      "type": "boolean",
      "description": "Publish through an action without the owner's approval. Off by default."
     }
    },
    "required": [
     "crm_url",
     "contact_days",
     "auto_publish"
    ]
   },
   "RecordCard": {
    "type": "object",
    "properties": {
     "kind": {
      "type": "string"
     },
     "key": {
      "type": "string",
      "description": "The natural key. A second record with the same key UPDATES the first — that's the deduplication."
     },
     "status": {
      "type": "string",
      "description": "Where the card is in the workflow. Any string: the platform doesn't know which states someone else's process has."
     },
     "data": {
      "type": "object",
      "additionalProperties": true,
      "description": "The card's fields. JSON, because the owner names them."
     },
     "created_at": {
      "type": "string"
     },
     "updated_at": {
      "type": "string"
     },
     "meta": {
      "type": "object",
      "additionalProperties": true,
      "description": "The service part of the card — what the platform writes, not the agent: «оцінка» (\"rating\": a fit / not a fit), «група» (\"group\" of duplicates), «можливо» (\"maybe\": cards similar to this one), «не_те_саме» (\"not the same\"), «поля» (\"fields\": page fragments that confirm the values). Field absent — there's no service part."
     },
     "copies": {
      "type": "integer",
      "description": "How many cards are in the duplicate group (including this one). Present only when searching with collapse and there's more than one copy."
     },
     "activity": {
      "type": "string",
      "description": "Only in the «джерела» (\"sources\") set: «активне» (\"active\"), «неактивне» (\"inactive\") or «невідомо» (\"unknown\") — from the latest publication date at the moment of the request."
     },
     "explain": {
      "type": "object",
      "properties": {
       "met": {
        "type": "array",
        "items": {
         "type": "string"
        },
        "description": "Conditions the card meets."
       },
       "unconfirmed": {
        "type": "array",
        "items": {
         "type": "string"
        },
        "description": "Conditions the card says nothing about: the field is missing or can't be compared."
       }
      },
      "required": [
       "met",
       "unconfirmed"
      ],
      "description": "Why the card is in the results. Present only when searching with where."
     }
    }
   },
   "WidgetMenuItem": {
    "type": "object",
    "title": "Dropdown item",
    "required": [
     "label",
     "action"
    ],
    "properties": {
     "label": {
      "type": "string",
      "maxLength": 60,
      "description": "The item's label."
     },
     "icon": {
      "type": "string",
      "maxLength": 4000,
      "description": "A custom icon — a single SVG, shapes only (`path`, `circle`, `rect`, `line`, `polyline`, `polygon`, `ellipse`, `g`), with no scripts, links, embedded styles or external images."
     },
     "action": {
      "type": "string",
      "enum": [
       "link",
       "contact",
       "send",
       "insert",
       "new_chat",
       "human",
       "lead",
       "open",
       "close",
       "grow",
       "copy",
       "page"
      ],
      "description": "The item's action — any of its element's actions except `menu` and `toggle`."
     },
     "value": {
      "type": "string",
      "maxLength": 500,
      "description": "The action value (a URL, a contact, text, a page function name)."
     },
     "fallback": {
      "type": "string",
      "maxLength": 500,
      "description": "Only for `page`: a URL, following the `link` rules, to go to if the page has no function with that name (the site is still loading, a different page). Not set — such a button does nothing."
     },
     "new_tab": {
      "type": "boolean",
      "description": "For `link`: open in a new tab."
     }
    }
   },
   "WidgetItem": {
    "type": "object",
    "title": "Custom element in the window",
    "description": "A button, link, line of text or image that the owner added to the window in words. This is a DESCRIPTION, not markup: the window builds the nodes itself, and there's no custom script in it.",
    "required": [
     "id",
     "slot",
     "kind"
    ],
    "properties": {
     "id": {
      "type": "string",
      "pattern": "^[a-z][a-z0-9-]{0,23}$",
      "description": "A short name in Latin letters. It's used to change or remove the element, to list it in the header order (`widget_layout.head`) and to style it (`.own-<id>` in `widget_css`). Can't match the name of a window part."
     },
     "slot": {
      "type": "string",
      "enum": [
       "head_left",
       "head_right",
       "under_head",
       "list_top",
       "over_input",
       "tools",
       "bottom",
       "launcher",
       "teaser"
      ],
      "description": "Where in the window: `head_left` — the header, left of the title (up to 2); `head_right` — the header, right of the title, among its buttons (up to 3); `under_head` — the strip below the header (up to 4); `list_top` — the start of the conversation feed, above the greeting (scrolls with it) (up to 6); `over_input` — above the input field (up to 6); `tools` — next to the \"Talk to a person\" and \"Leave your contact\" buttons (up to 4); `bottom` — the bottom of the window, below the input field (up to 4); `launcher` — next to the button that opens the chat (visible while the window is minimised) (up to 3); `teaser` — on the invitation bubble (up to 3)."
     },
     "kind": {
      "type": "string",
      "enum": [
       "button",
       "link",
       "text",
       "image"
      ],
      "description": "What the element looks like: `button` — a button (default), `link` — a text link, `text` — a line of text (the action is optional), `image` — an image (`image` — the URL, `label` — a description for screen readers)."
     },
     "label": {
      "type": "string",
      "maxLength": 200,
      "description": "The label: up to 60 characters, up to 200 for `text`. Must not pass itself off as a platform label."
     },
     "icon": {
      "type": "string",
      "maxLength": 4000,
      "description": "A custom icon — a single SVG, shapes only (`path`, `circle`, `rect`, `line`, `polyline`, `polygon`, `ellipse`, `g`), with no scripts, links, embedded styles or external images."
     },
     "image": {
      "type": "string",
      "description": "The image URL, starting with `https://` (for `kind: image`)."
     },
     "class": {
      "type": "string",
      "pattern": "^[a-z][a-z0-9-]{0,31}$",
      "description": "A custom class for `widget_css`. The window's own classes can't be used."
     },
     "hint": {
      "type": "string",
      "maxLength": 80,
      "description": "The tooltip and the name for screen readers; required for an icon button without a label."
     },
     "action": {
      "type": "string",
      "enum": [
       "link",
       "contact",
       "send",
       "insert",
       "new_chat",
       "human",
       "lead",
       "open",
       "close",
       "grow",
       "copy",
       "page",
       "toggle",
       "menu"
      ],
      "description": "What a click does: `link` — open a URL: a page on the same site (\"/catalog\"), a full URL with https://, mailto: or tel:; new_tab: true — in a new tab (other sites open in a new tab anyway); `contact` — open a messenger, email or a call using the same rules as the contact buttons: \"telegram:@svitlo\", \"viber:+380671234567\", \"whatsapp:+380…\", \"phone:+380…\", \"email:hi@firma.com\" — the messenger will already contain the person's question and the page URL; `send` — send this phrase to the assistant on the visitor's behalf (the person sees it as their own message); the window opens if it was minimised; `insert` — put this text into the input field without sending it; `new_chat` — start a new conversation (asks for confirmation, like the bin in the header); `human` — call a live person into the conversation; `lead` — open the \"Leave your contact\" form; `open` — open the chat window; `close` — minimise the chat window; `grow` — expand the window to a larger size or restore the normal one; `copy` — copy this text to the clipboard (a promo code, an address, a number); `page` — call a site page function that the site's code registered via `YouSelfBot.registerTool(name, fn)`: value holds the function name (Latin letters, digits, `_` and `-`, up to 64 characters), `fallback` holds a URL for when the page has no such function; `toggle` — show or hide another custom element — value holds its id (give that element hidden: true so it starts out invisible); `menu` — a dropdown under the button — the items go in the menu field, each with its own label and action. The list is closed: there's no custom script here, and no action pays for anything or agrees to anything on the visitor's behalf."
     },
     "value": {
      "type": "string",
      "maxLength": 500,
      "description": "The action value: a URL for `link` (a page on this site `/catalog`, `https://…`, `mailto:`, `tel:`), `kind:value` for `contact` (`telegram:@svitlo`, `viber:+380…`), text for `send`, `insert`, `copy`, the `id` of another element for `toggle`, a page function name for `page`."
     },
     "fallback": {
      "type": "string",
      "maxLength": 500,
      "description": "Only for `page`: a URL, following the `link` rules, to go to if the page has no function with that name (the site is still loading, a different page). Not set — such a button does nothing."
     },
     "new_tab": {
      "type": "boolean",
      "description": "For `link`: open in a new tab. Other sites always open in a new tab."
     },
     "hidden": {
      "type": "boolean",
      "description": "Hidden at first; another element shows it with the `toggle` action."
     },
     "menu": {
      "type": "array",
      "maxItems": 8,
      "items": {
       "$ref": "#/components/schemas/WidgetMenuItem"
      },
      "description": "Dropdown items (for `action: menu`)."
     }
    }
   },
   "WidgetItemPatch": {
    "type": "object",
    "title": "Custom element change",
    "additionalProperties": false,
    "description": "A new element — in full; for an existing one (the same `id`) it's enough to name what changes. `remove: true` removes it.",
    "required": [
     "id"
    ],
    "properties": {
     "id": {
      "type": "string",
      "pattern": "^[a-z][a-z0-9-]{0,23}$",
      "description": "A short name in Latin letters. It's used to change or remove the element, to list it in the header order (`widget_layout.head`) and to style it (`.own-<id>` in `widget_css`). Can't match the name of a window part."
     },
     "slot": {
      "type": "string",
      "enum": [
       "head_left",
       "head_right",
       "under_head",
       "list_top",
       "over_input",
       "tools",
       "bottom",
       "launcher",
       "teaser"
      ],
      "description": "Where in the window: `head_left` — the header, left of the title (up to 2); `head_right` — the header, right of the title, among its buttons (up to 3); `under_head` — the strip below the header (up to 4); `list_top` — the start of the conversation feed, above the greeting (scrolls with it) (up to 6); `over_input` — above the input field (up to 6); `tools` — next to the \"Talk to a person\" and \"Leave your contact\" buttons (up to 4); `bottom` — the bottom of the window, below the input field (up to 4); `launcher` — next to the button that opens the chat (visible while the window is minimised) (up to 3); `teaser` — on the invitation bubble (up to 3)."
     },
     "kind": {
      "type": "string",
      "enum": [
       "button",
       "link",
       "text",
       "image"
      ],
      "description": "What the element looks like: `button` — a button (default), `link` — a text link, `text` — a line of text (the action is optional), `image` — an image (`image` — the URL, `label` — a description for screen readers)."
     },
     "label": {
      "type": "string",
      "maxLength": 200,
      "description": "The label: up to 60 characters, up to 200 for `text`. Must not pass itself off as a platform label."
     },
     "icon": {
      "type": "string",
      "maxLength": 4000,
      "description": "A custom icon — a single SVG, shapes only (`path`, `circle`, `rect`, `line`, `polyline`, `polygon`, `ellipse`, `g`), with no scripts, links, embedded styles or external images."
     },
     "image": {
      "type": "string",
      "description": "The image URL, starting with `https://` (for `kind: image`)."
     },
     "class": {
      "type": "string",
      "pattern": "^[a-z][a-z0-9-]{0,31}$",
      "description": "A custom class for `widget_css`. The window's own classes can't be used."
     },
     "hint": {
      "type": "string",
      "maxLength": 80,
      "description": "The tooltip and the name for screen readers; required for an icon button without a label."
     },
     "action": {
      "type": "string",
      "enum": [
       "link",
       "contact",
       "send",
       "insert",
       "new_chat",
       "human",
       "lead",
       "open",
       "close",
       "grow",
       "copy",
       "page",
       "toggle",
       "menu"
      ],
      "description": "What a click does: `link` — open a URL: a page on the same site (\"/catalog\"), a full URL with https://, mailto: or tel:; new_tab: true — in a new tab (other sites open in a new tab anyway); `contact` — open a messenger, email or a call using the same rules as the contact buttons: \"telegram:@svitlo\", \"viber:+380671234567\", \"whatsapp:+380…\", \"phone:+380…\", \"email:hi@firma.com\" — the messenger will already contain the person's question and the page URL; `send` — send this phrase to the assistant on the visitor's behalf (the person sees it as their own message); the window opens if it was minimised; `insert` — put this text into the input field without sending it; `new_chat` — start a new conversation (asks for confirmation, like the bin in the header); `human` — call a live person into the conversation; `lead` — open the \"Leave your contact\" form; `open` — open the chat window; `close` — minimise the chat window; `grow` — expand the window to a larger size or restore the normal one; `copy` — copy this text to the clipboard (a promo code, an address, a number); `page` — call a site page function that the site's code registered via `YouSelfBot.registerTool(name, fn)`: value holds the function name (Latin letters, digits, `_` and `-`, up to 64 characters), `fallback` holds a URL for when the page has no such function; `toggle` — show or hide another custom element — value holds its id (give that element hidden: true so it starts out invisible); `menu` — a dropdown under the button — the items go in the menu field, each with its own label and action. The list is closed: there's no custom script here, and no action pays for anything or agrees to anything on the visitor's behalf."
     },
     "value": {
      "type": "string",
      "maxLength": 500,
      "description": "The action value: a URL for `link` (a page on this site `/catalog`, `https://…`, `mailto:`, `tel:`), `kind:value` for `contact` (`telegram:@svitlo`, `viber:+380…`), text for `send`, `insert`, `copy`, the `id` of another element for `toggle`, a page function name for `page`."
     },
     "fallback": {
      "type": "string",
      "maxLength": 500,
      "description": "Only for `page`: a URL, following the `link` rules, to go to if the page has no function with that name (the site is still loading, a different page). Not set — such a button does nothing."
     },
     "new_tab": {
      "type": "boolean",
      "description": "For `link`: open in a new tab. Other sites always open in a new tab."
     },
     "hidden": {
      "type": "boolean",
      "description": "Hidden at first; another element shows it with the `toggle` action."
     },
     "menu": {
      "type": "array",
      "maxItems": 8,
      "items": {
       "$ref": "#/components/schemas/WidgetMenuItem"
      },
      "description": "Dropdown items (for `action: menu`)."
     },
     "remove": {
      "type": "boolean",
      "description": "`true` — remove the element with this `id`."
     }
    }
   },
   "WidgetLayout": {
    "type": "object",
    "title": "Window part layout (as saved)",
    "description": "Only what the owner changed: an empty object means everything is default.",
    "properties": {
     "head": {
      "type": "array",
      "items": {
       "type": "string"
      },
      "description": "The order of header parts from left to right: `logo`, `title`, `more`, `chats`, `fresh`, `home`, `grow`, `close` and the `id` of your custom header elements. Field absent — the default order."
     },
     "tools": {
      "type": "array",
      "items": {
       "type": "string"
      },
      "description": "The order of buttons under the feed: `human`, `lead`, `continue` and the `id` of your custom elements in the `tools` slot."
     },
     "hide": {
      "type": "array",
      "items": {
       "type": "string",
       "enum": [
        "logo",
        "title",
        "state",
        "more",
        "chats",
        "fresh",
        "home",
        "grow",
        "close",
        "human",
        "lead",
        "continue",
        "clip",
        "rate",
        "starters",
        "badge"
       ]
      },
      "description": "Hidden window parts. Parts: `logo` — the logo in the header; `title` — the window title; `state` — the status line under the title (\"Usually replies right away\"); `more` — the \"Another conversation\" button (the ability itself is widget_design conversations); `chats` — the conversation list button (present when there's more than one conversation); `fresh` — the \"Start a new conversation\" button (the bin); `home` — the \"Move the window back\" button; `grow` — the \"Expand\" button; `close` — the \"Minimise\" button in the header (always stays on phones: there it's the only visible way out of the window); `human` — the \"Talk to a person\" button; `lead` — the \"Leave your contact\" button; `continue` — the \"Continue in Telegram\" button; `clip` — the paperclip — removing it also makes the window stop accepting files entirely; `rate` — the rating under a reply; `starters` — the suggestions under the greeting; `badge` — the new-replies counter on the chat button."
     },
     "title": {
      "type": "string",
      "enum": [
       "center"
      ],
      "description": "`center` — the title in the middle of the header. Field absent — on the left."
     },
     "input": {
      "type": "string",
      "enum": [
       "top"
      ],
      "description": "`top` — the input field under the header, the conversation grows from top to bottom. Field absent — at the bottom."
     },
     "starters": {
      "type": "string",
      "enum": [
       "input"
      ],
      "description": "`input` — suggestions in a row above the input field. Field absent — in the feed under the greeting."
     },
     "acts": {
      "type": "object",
      "description": "Custom actions for the built-in buttons under the feed: the key is the button (`human`, `lead`, `continue`). A button with a custom action is always in the window, even when the operator or the contact form is turned off.",
      "additionalProperties": {
       "$ref": "#/components/schemas/WidgetPartAct"
      }
     }
    }
   },
   "WidgetLayoutView": {
    "type": "object",
    "title": "Window part layout (for the window)",
    "description": "The same with default values filled in: every field is always present.",
    "required": [
     "head",
     "tools",
     "hide",
     "title",
     "input",
     "starters",
     "acts"
    ],
    "properties": {
     "head": {
      "type": "array",
      "items": {
       "type": "string"
      },
      "description": "The order of header parts from left to right; empty means the default."
     },
     "tools": {
      "type": "array",
      "items": {
       "type": "string"
      },
      "description": "The order of buttons under the feed; empty means the default."
     },
     "hide": {
      "type": "array",
      "items": {
       "type": "string",
       "enum": [
        "logo",
        "title",
        "state",
        "more",
        "chats",
        "fresh",
        "home",
        "grow",
        "close",
        "human",
        "lead",
        "continue",
        "clip",
        "rate",
        "starters",
        "badge"
       ]
      },
      "description": "Hidden window parts."
     },
     "title": {
      "type": "string",
      "enum": [
       "start",
       "center"
      ],
      "description": "Where the title sits in the header."
     },
     "input": {
      "type": "string",
      "enum": [
       "bottom",
       "top"
      ],
      "description": "Where the input field is."
     },
     "starters": {
      "type": "string",
      "enum": [
       "list",
       "input"
      ],
      "description": "Where the suggestions are: in the feed or above the input field."
     },
     "acts": {
      "type": "object",
      "description": "Custom actions for the built-in buttons under the feed: the key is the button (`human`, `lead`, `continue`). A button with a custom action is always in the window, even when the operator or the contact form is turned off.",
      "additionalProperties": {
       "$ref": "#/components/schemas/WidgetPartAct"
      }
     }
    }
   },
   "WidgetLayoutPatch": {
    "type": "object",
    "title": "Window part layout change",
    "additionalProperties": false,
    "description": "Send only what you're changing. To restore all defaults — `clear: [\"widget_layout\"]`. Parts: `logo` — the logo in the header; `title` — the window title; `state` — the status line under the title (\"Usually replies right away\"); `more` — the \"Another conversation\" button (the ability itself is widget_design conversations); `chats` — the conversation list button (present when there's more than one conversation); `fresh` — the \"Start a new conversation\" button (the bin); `home` — the \"Move the window back\" button; `grow` — the \"Expand\" button; `close` — the \"Minimise\" button in the header (always stays on phones: there it's the only visible way out of the window); `human` — the \"Talk to a person\" button; `lead` — the \"Leave your contact\" button; `continue` — the \"Continue in Telegram\" button; `clip` — the paperclip — removing it also makes the window stop accepting files entirely; `rate` — the rating under a reply; `starters` — the suggestions under the greeting; `badge` — the new-replies counter on the chat button.",
    "properties": {
     "head": {
      "type": "array",
      "items": {
       "type": "string"
      },
      "description": "The order of header parts from left to right: `logo`, `title`, `more`, `chats`, `fresh`, `home`, `grow`, `close` and the `id` of your custom header elements. Anything not named goes after the named parts, in the default sequence."
     },
     "tools": {
      "type": "array",
      "items": {
       "type": "string"
      },
      "description": "The order of buttons under the feed: `human`, `lead`, `continue` and the `id` of your custom elements in the `tools` slot."
     },
     "hide": {
      "type": "array",
      "items": {
       "type": "string",
       "enum": [
        "logo",
        "title",
        "state",
        "more",
        "chats",
        "fresh",
        "home",
        "grow",
        "close",
        "human",
        "lead",
        "continue",
        "clip",
        "rate",
        "starters",
        "badge"
       ]
      },
      "description": "What to hide. Added to what's already hidden."
     },
     "show": {
      "type": "array",
      "items": {
       "type": "string",
       "enum": [
        "logo",
        "title",
        "state",
        "more",
        "chats",
        "fresh",
        "home",
        "grow",
        "close",
        "human",
        "lead",
        "continue",
        "clip",
        "rate",
        "starters",
        "badge"
       ]
      },
      "description": "What to bring back from the hidden parts."
     },
     "title": {
      "type": "string",
      "enum": [
       "start",
       "center"
      ],
      "description": "Title: `start` — on the left (default), `center` — in the middle."
     },
     "input": {
      "type": "string",
      "enum": [
       "bottom",
       "top"
      ],
      "description": "Input field: `bottom` — at the bottom (default), `top` — under the header."
     },
     "starters": {
      "type": "string",
      "enum": [
       "list",
       "input"
      ],
      "description": "Suggestions: `list` — in the feed (default), `input` — above the input field, always visible."
     },
     "acts": {
      "type": "array",
      "description": "Give a built-in button under the feed a custom action, or restore the default one (`action: default`).",
      "items": {
       "type": "object",
       "required": [
        "part",
        "action"
       ],
       "properties": {
        "part": {
         "type": "string",
         "enum": [
          "human",
          "lead",
          "continue"
         ]
        },
        "action": {
         "type": "string",
         "enum": [
          "link",
          "contact",
          "send",
          "insert",
          "new_chat",
          "human",
          "lead",
          "open",
          "close",
          "grow",
          "copy",
          "page",
          "default"
         ]
        },
        "value": {
         "type": "string"
        },
        "fallback": {
         "type": "string"
        },
        "new_tab": {
         "type": "boolean"
        }
       }
      }
     }
    }
   },
   "TeaserRule": {
    "type": "object",
    "title": "Invitation for part of the site",
    "required": [
     "pages"
    ],
    "properties": {
     "pages": {
      "type": "string",
      "maxLength": 120,
      "description": "The page path from the site root, an asterisk means anything: `/catalog/*`, `/blog/*`, `/` (the home page only)."
     },
     "text": {
      "type": "string",
      "maxLength": 120,
      "description": "What the bubble says there."
     },
     "off": {
      "type": "boolean",
      "description": "`true` — don't show an invitation on these pages at all."
     }
    }
   },
   "AccountExport": {
    "type": "object",
    "properties": {
     "id": {
      "type": "string",
      "description": "The archive ID."
     },
     "status": {
      "type": "string",
      "description": "`building` — being built; `ready` — ready, can be downloaded until `expires_at`; `failed` — couldn't be built (`error` says why); `expired` — the deadline passed, the file was deleted.",
      "enum": [
       "building",
       "ready",
       "failed",
       "expired"
      ]
     },
     "step": {
      "type": "string",
      "description": "What's being collected right now, in words. Only while `building`."
     },
     "done": {
      "type": "integer",
      "description": "How many steps have been collected."
     },
     "total": {
      "type": "integer",
      "description": "How many steps in total (0 — the list is still being prepared)."
     },
     "created_at": {
      "type": "string",
      "description": "When it was requested.",
      "format": "date-time"
     },
     "ready_at": {
      "type": "string",
      "description": "When it was built.",
      "format": "date-time"
     },
     "expires_at": {
      "type": "string",
      "description": "Until when it can be downloaded; after that the file is deleted.",
      "format": "date-time"
     },
     "size_bytes": {
      "type": "integer",
      "description": "The archive file size."
     },
     "error": {
      "type": "string",
      "description": "Why it couldn't be built — in human-readable words."
     }
    },
    "required": [
     "id",
     "status",
     "done",
     "total",
     "created_at"
    ]
   },
   "ThreadEvent": {
    "type": "object",
    "required": [
     "kind"
    ],
    "description": "A conversation event — something the customer did in the window other than writing. Only for `author: \"event\"`; the `text` of the same message says the same in one sentence (\"The customer left a contact: Olena, +380…\"). The operator sees it — in the dashboard transcript and in the operator API; responses to the window (`/v1/widget/messages`, the stream, `/v1/widget/thread`) contain no events.",
    "properties": {
     "kind": {
      "type": "string",
      "enum": [
       "contact",
       "rating"
      ],
      "description": "`contact` — the customer left a contact (`POST /v1/widget/lead`); `rating` — rated a reply (`POST /v1/widget/feedback`)."
     },
     "name": {
      "type": "string",
      "description": "The name the person gave. Only for `contact`."
     },
     "contact": {
      "type": "string",
      "description": "Phone or email — as entered. Only for `contact`."
     },
     "note": {
      "type": "string",
      "description": "What the person added to the contact. Only for `contact`."
     },
     "rating": {
      "type": "string",
      "enum": [
       "up",
       "down"
      ],
      "description": "The rating: `up` — helpful, `down` — not helpful. Only for `rating`."
     },
     "ref": {
      "type": "string",
      "description": "The `id` of the message the rating refers to. Absent if that reply wasn't found in the transcript — the event is then placed by time only."
     }
    }
   },
   "OpenPayment": {
    "type": "object",
    "required": [
     "order_id",
     "kind",
     "item_id",
     "name",
     "amount",
     "currency",
     "state",
     "created_at",
     "expires_at"
    ],
    "properties": {
     "order_id": {
      "type": "string"
     },
     "kind": {
      "type": "string",
      "enum": [
       "plan",
       "credits"
      ],
      "description": "plan — a subscription, credits — a one-time credit pack."
     },
     "item_id": {
      "type": "string",
      "description": "The plan or pack being paid for."
     },
     "name": {
      "type": "string",
      "description": "Its name."
     },
     "amount": {
      "type": "number"
     },
     "currency": {
      "type": "string"
     },
     "state": {
      "type": "string",
      "enum": [
       "open",
       "confirming",
       "lapsed"
      ],
      "description": "open — the payment page is open, the gateway hasn't seen any money yet; confirming — the gateway sees the payment and is waiting for the bank's confirmation; lapsed — the payment deadline passed, and how it ended hasn't been reconciled yet."
     },
     "created_at": {
      "type": "string",
      "format": "date-time"
     },
     "expires_at": {
      "type": "string",
      "format": "date-time",
      "description": "Until when the gateway accepts payment for this invoice."
     }
    },
    "description": "An unfinished payment: what the dashboard shows instead of a second \"Buy\" button."
   },
   "BuilderChat": {
    "type": "object",
    "description": "A chat with the Builder — one of the person's conversations about an agent.",
    "required": [
     "id",
     "title",
     "named",
     "pending"
    ],
    "properties": {
     "id": {
      "type": "string",
      "description": "The chat ID; it's also passed in the `thread` field to open the conversation or write to it."
     },
     "title": {
      "type": "string",
      "description": "The title: given by the person or taken from the first request. Empty means nothing has been said in the chat yet."
     },
     "named": {
      "type": "boolean",
      "description": "The person gave the title (later turns don't change it)."
     },
     "pending": {
      "type": "boolean",
      "description": "The Builder's last reply — a question with buttons that hasn't been answered yet."
     },
     "updated_at": {
      "type": "string",
      "format": "date-time",
      "description": "When the chat was last active. The field is absent for a conversation held before the chat list existed: the platform doesn't know its time."
     },
     "deleted_at": {
      "type": "string",
      "format": "date-time",
      "description": "When the chat was deleted. Only for deleted chats."
     },
     "purge_at": {
      "type": "string",
      "format": "date-time",
      "description": "When a deleted chat disappears for good. Until then it can be restored."
     }
    }
   },
   "KnowledgeDuplicates": {
    "type": "object",
    "description": "What the check of the agent's sources found: identical sources and sources whose text repeats. The check changes nothing.",
    "properties": {
     "twins": {
      "type": "array",
      "description": "Groups of sources with the same text, largest first. \"The same\" ignores line endings, trailing spaces and blank lines; different letter case is already different text.",
      "items": {
       "type": "object",
       "properties": {
        "sources": {
         "type": "array",
         "description": "The copies in knowledge list order, at least two.",
         "items": {
          "$ref": "#/components/schemas/Source"
         }
        },
        "chars": {
         "type": "integer",
         "description": "How many characters are in the text of one copy."
        }
       },
       "required": [
        "sources",
        "chars"
       ]
      }
     },
     "repeats": {
      "type": "array",
      "description": "Sources in which the same text appears more than once.",
      "items": {
       "type": "object",
       "properties": {
        "source": {
         "$ref": "#/components/schemas/Source"
        },
        "chars": {
         "type": "integer",
         "description": "Characters in the text right now."
        },
        "extra": {
         "type": "integer",
         "description": "How many of them are repetition."
        }
       },
       "required": [
        "source",
        "chars",
        "extra"
       ]
      }
     },
     "checked": {
      "type": "integer",
      "description": "How many sources were checked."
     },
     "unchecked": {
      "type": "integer",
      "description": "How many were NOT checked: beyond the check limit (500 sources) or the text couldn't be read. Empty `twins` and `repeats` are only true for the checked ones."
     }
    },
    "required": [
     "twins",
     "repeats",
     "checked",
     "unchecked"
    ]
   },
   "KnowledgeDuplicatesCleaned": {
    "type": "object",
    "description": "How the cleanup of copies and repeats ended.",
    "properties": {
     "removed": {
      "type": "array",
      "description": "Copies removed.",
      "items": {
       "type": "object",
       "properties": {
        "id": {
         "type": "string"
        },
        "title": {
         "type": "string"
        },
        "why": {
         "type": "string",
         "description": "Why it was left alone. Only in `skipped`."
        },
        "extra": {
         "type": "integer",
         "description": "How many characters of repetition were removed. Only in `folded`."
        }
       },
       "required": [
        "id",
        "title"
       ]
      }
     },
     "folded": {
      "type": "array",
      "description": "Sources whose text was kept only once.",
      "items": {
       "type": "object",
       "properties": {
        "id": {
         "type": "string"
        },
        "title": {
         "type": "string"
        },
        "why": {
         "type": "string",
         "description": "Why it was left alone. Only in `skipped`."
        },
        "extra": {
         "type": "integer",
         "description": "How many characters of repetition were removed. Only in `folded`."
        }
       },
       "required": [
        "id",
        "title"
       ]
      }
     },
     "skipped": {
      "type": "array",
      "description": "Named items that were left alone, with the reason: it's no longer a copy, it's the last copy of the text, there's no repetition anymore.",
      "items": {
       "type": "object",
       "properties": {
        "id": {
         "type": "string"
        },
        "title": {
         "type": "string"
        },
        "why": {
         "type": "string",
         "description": "Why it was left alone. Only in `skipped`."
        },
        "extra": {
         "type": "integer",
         "description": "How many characters of repetition were removed. Only in `folded`."
        }
       },
       "required": [
        "id",
        "title"
       ]
      }
     }
    },
    "required": [
     "removed",
     "folded",
     "skipped"
    ]
   },
   "SourcePage": {
    "type": "object",
    "description": "The state of a page read from a URL. Present only for sources the platform read from a site itself; text and files don't have it.",
    "required": [
     "state",
     "refresh"
    ],
    "properties": {
     "state": {
      "type": "string",
      "enum": [
       "ok",
       "gone",
       "failed",
       "blocked",
       "empty"
      ],
      "description": "`ok` — the page is on the site, its text is in the knowledge. `gone` — the site said the page doesn't exist: the agent no longer answers from it, but the text is NOT deleted — the owner decides whether to remove or keep it. `failed` — it didn't open last time; `blocked` — the site forbids automated reading (robots.txt); `empty` — it opened with no text. In the last three cases the previous text stays in the knowledge."
     },
     "reason": {
      "type": "string",
      "description": "Why it isn't `ok`, in human-readable words."
     },
     "read_at": {
      "type": "string",
      "format": "date-time",
      "description": "When text was last taken from the site. Absent until text has been taken from the site."
     },
     "checked_at": {
      "type": "string",
      "format": "date-time",
      "description": "When the page was last looked at — possibly finding that it hadn't changed."
     },
     "next_at": {
      "type": "string",
      "format": "date-time",
      "description": "When the page will be re-read next. Absent — it isn't re-read automatically."
     },
     "refresh": {
      "type": "boolean",
      "description": "Whether the page is re-read on a schedule. `false` — the site has no schedule, or re-reading this page is turned off."
     },
     "every_days": {
      "type": "integer",
      "description": "Every how many days. Present only together with `refresh: true`."
     },
     "edited": {
      "type": "boolean",
      "description": "A person edited the text in the knowledge. Re-reading doesn't overwrite it."
     },
     "site_changed": {
      "type": "boolean",
      "description": "The page on the site changed after the person's edit. The flag stays until the owner decides: take the text from the site (`POST …/pages/reread` with `take_site`) or keep their own (`PUT …/pages` with `keep_mine`)."
     },
     "whole_site": {
      "type": "boolean",
      "description": "The page was found by reading the whole site. Absent — it was added individually: only it is re-read, without crawling the site."
     }
    }
   },
   "RereadResult": {
    "type": "object",
    "required": [
     "status"
    ],
    "properties": {
     "status": {
      "type": "string",
      "enum": [
       "done",
       "scanning"
      ],
      "description": "`done` — one page was re-read, the summary is right here; `scanning` — re-reading everything went to the background, the summary is read via `GET …/scrape`."
     },
     "notice": {
      "type": "string",
      "description": "What happened to the page, in human-readable words: changed, didn't change, disappeared, the edit was kept. Only with `done`."
     },
     "page": {
      "$ref": "#/components/schemas/SourcePage"
     }
    }
   },
   "Notices": {
    "type": "object",
    "required": [
     "calls",
     "digest"
    ],
    "properties": {
     "calls": {
      "type": "object",
      "description": "Customer requests for a human: where you learn about them outside the dashboard's Conversations.",
      "required": [
       "operator",
       "on",
       "where",
       "remind_min",
       "remind_times",
       "quiet_hours",
       "quiet",
       "mail"
      ],
      "properties": {
       "operator": {
        "type": "boolean",
        "description": "Whether calling a live person is enabled at all. `false` — there are no requests."
       },
       "on": {
        "type": "boolean",
        "description": "Whether request notifications are on (`handoff_notify`)."
       },
       "where": {
        "type": "array",
        "items": {
         "type": "string"
        },
        "description": "Where a request will go right now, in human-readable words (\"to the chat “Bot” (telegram)\", \"to the email a@b.c\"). Empty means nowhere except the dashboard. Computed by the same code that sends it."
       },
       "remind_min": {
        "type": "integer",
        "description": "After how many minutes a reminder arrives if nobody has taken the request; `0` — reminders are off."
       },
       "remind_times": {
        "type": "integer",
        "description": "How many times we'll remind (each one `remind_min` after the previous) if nobody has taken the request; 1…5. Applies only when `remind_min` is greater than zero."
       },
       "quiet_hours": {
        "type": "string",
        "description": "Quiet hours; empty means none."
       },
       "quiet": {
        "type": "object",
        "description": "Quiet hours broken into parts — so the dashboard can show \"from … to …\" and write back a `quiet_hours` value without parsing it itself.",
        "required": [
         "on",
         "from",
         "to",
         "zone"
        ],
        "properties": {
         "on": {
          "type": "boolean",
          "description": "Whether quiet hours are set."
         },
         "from": {
          "type": "string",
          "description": "Start, `22:00`; empty means no quiet hours."
         },
         "to": {
          "type": "string",
          "description": "End, `08:00`; empty means no quiet hours."
         },
         "zone": {
          "type": "string",
          "description": "Time zone, `Europe/Kyiv` by default."
         }
        }
       },
       "mail": {
        "type": "object",
        "description": "Emails about requests to THE PERSON ASKING: the owner gets them at the account address (on by default), a team member gets them if they turned them on for themselves.",
        "required": [
         "address",
         "on",
         "ready"
        ],
        "properties": {
         "address": {
          "type": "string",
          "description": "The address the emails will go to. Empty — this build has no email (see `ready`), the account address isn't confirmed yet, or the request was made with a key."
         },
         "ready": {
          "type": "boolean",
          "description": "Whether the platform sends emails at all. `false` — this build has no email: confirming an address or turning on emails is impossible."
         },
         "on": {
          "type": "boolean",
          "description": "Whether emails are currently being sent to this person."
         }
        }
       }
      }
     },
     "digest": {
      "type": "object",
      "description": "Digest for the owner: unanswered questions and everything waiting for a human.",
      "required": [
       "available",
       "on",
       "when",
       "when_words",
       "daily",
       "days",
       "at",
       "zone",
       "size",
       "next",
       "to",
       "lang",
       "where",
       "chat",
       "mail"
      ],
      "properties": {
       "available": {
        "type": "boolean",
        "description": "Whether the digest is included in this build."
       },
       "on": {
        "type": "boolean",
        "description": "Whether the digest is sent on a schedule (`digest`)."
       },
       "when": {
        "type": "string",
        "description": "The schedule as written in settings (`mon 09:00`, `mon,thu 18:00`, `daily 18:30`); empty means the default."
       },
       "when_words": {
        "type": "string",
        "description": "The schedule in words: \"every Monday at 09:00\", \"every Monday and Thursday at 18:00\"."
       },
       "daily": {
        "type": "boolean",
        "description": "The schedule is daily."
       },
       "days": {
        "type": "array",
        "items": {
         "type": "string",
         "enum": [
          "mon",
          "tue",
          "wed",
          "thu",
          "fri",
          "sat",
          "sun"
         ]
        },
        "description": "The days of the schedule in effect (the default one when not set), starting from Monday."
       },
       "at": {
        "type": "string",
        "description": "The time of the schedule in effect: `09:00`."
       },
       "zone": {
        "type": "string",
        "description": "The schedule's time zone: `Europe/Kyiv` by default."
       },
       "size": {
        "type": "integer",
        "description": "How many of the most frequent questions are in the digest (1…50; 5 by default)."
       },
       "next": {
        "type": "string",
        "description": "The next moment on the schedule (RFC 3339, in the schedule's time zone) — computed by the same code that runs the schedule; the digest goes out then if anything was asked since last time. Empty — turned off, or this build has no digest."
       },
       "to": {
        "type": "string",
        "enum": [
         "",
         "chat",
         "mail"
        ],
        "description": "Where it was asked to be sent; empty means everywhere a route exists."
       },
       "lang": {
        "type": "string",
        "enum": [
         "",
         "uk",
         "en"
        ],
        "description": "The digest language; empty means not chosen, and the digest goes out in the owner's account language."
       },
       "where": {
        "type": "array",
        "items": {
         "type": "string"
        },
        "description": "Where the digest will go on schedule, in words. Empty means nowhere (turned off or no routes)."
       },
       "chat": {
        "type": "array",
        "items": {
         "type": "string"
        },
        "description": "The owner's linked chats the digest could go to, whatever is chosen."
       },
       "mail": {
        "type": "array",
        "items": {
         "type": "string"
        },
        "description": "Email addresses the digest could go to, whatever is chosen."
       }
      }
     }
    }
   },
   "WidgetContactButton": {
    "type": "object",
    "title": "Contact button in the window",
    "required": [
     "kind",
     "value",
     "label",
     "own"
    ],
    "properties": {
     "kind": {
      "type": "string",
      "enum": [
       "telegram",
       "viber",
       "whatsapp",
       "phone",
       "email",
       "link"
      ],
      "description": "Where the button leads."
     },
     "value": {
      "type": "string",
      "description": "`telegram` — username (without `@`) or phone number; `viber`, `whatsapp`, `phone` — number with country code (`+380671234567`); `email` — address; `link` — full URL with `https://`."
     },
     "label": {
      "type": "string",
      "description": "The final button label: custom or the default for its kind."
     },
     "own": {
      "type": "boolean",
      "description": "The owner set the label (rather than the default for this kind)."
     }
    }
   },
   "WidgetLangSet": {
    "type": "object",
    "description": "Window texts in one language. Missing fields aren't set in this language: the window takes them from its own dictionary in this language (it has Ukrainian and English), not from the main language.",
    "properties": {
     "title": {
      "type": "string",
      "description": "The window title in this language. Not set — the main one stays."
     },
     "greeting": {
      "type": "string",
      "description": "The greeting."
     },
     "starters": {
      "type": "array",
      "items": {
       "type": "string"
      },
      "description": "Suggested questions (up to 4)."
     },
     "note": {
      "type": "string",
      "description": "The note under the input field."
     },
     "refusal": {
      "type": "string",
      "description": "The refusal sentence in this language: the assistant says it to someone writing in this language."
     },
     "teaser": {
      "type": "string",
      "description": "The invitation bubble text."
     },
     "teaser_product": {
      "type": "string",
      "description": "The bubble text on a product page; `{product}` is replaced with the product name."
     },
     "teaser_returning": {
      "type": "string",
      "description": "The bubble text for someone who has chatted before."
     },
     "teaser_buttons": {
      "type": "array",
      "items": {
       "type": "string"
      },
      "description": "Buttons on the bubble (up to 3)."
     },
     "launcher_label": {
      "type": "string",
      "description": "The chat button label."
     },
     "texts": {
      "type": "object",
      "additionalProperties": {
       "type": "string"
      },
      "description": "Window labels in this language: the same keys as in `widget_texts`."
     },
     "items": {
      "type": "object",
      "additionalProperties": {
       "type": "string"
      },
      "description": "Labels of custom elements: element `id` → label."
     },
     "contacts": {
      "type": "object",
      "additionalProperties": {
       "type": "string"
      },
      "description": "Contact button labels: kind (`telegram`, `viber`, `whatsapp`, `phone`, `email`) → label."
     }
    }
   },
   "WidgetLangSetPatch": {
    "type": "object",
    "description": "A change to one language's text set: named fields are replaced, the rest stay. `texts`, `items`, `contacts` are merged by key (an empty value removes the key).",
    "properties": {
     "title": {
      "type": "string",
      "description": "The window title in this language. Not set — the main one stays."
     },
     "greeting": {
      "type": "string",
      "description": "The greeting."
     },
     "starters": {
      "type": "array",
      "items": {
       "type": "string"
      },
      "description": "Suggested questions (up to 4)."
     },
     "note": {
      "type": "string",
      "description": "The note under the input field."
     },
     "refusal": {
      "type": "string",
      "description": "The refusal sentence in this language: the assistant says it to someone writing in this language."
     },
     "teaser": {
      "type": "string",
      "description": "The invitation bubble text."
     },
     "teaser_product": {
      "type": "string",
      "description": "The bubble text on a product page; `{product}` is replaced with the product name."
     },
     "teaser_returning": {
      "type": "string",
      "description": "The bubble text for someone who has chatted before."
     },
     "teaser_buttons": {
      "type": "array",
      "items": {
       "type": "string"
      },
      "description": "Buttons on the bubble (up to 3)."
     },
     "launcher_label": {
      "type": "string",
      "description": "The chat button label."
     },
     "texts": {
      "type": "object",
      "additionalProperties": {
       "type": "string"
      },
      "description": "Window labels in this language: the same keys as in `widget_texts`."
     },
     "items": {
      "type": "object",
      "additionalProperties": {
       "type": "string"
      },
      "description": "Labels of custom elements: element `id` → label."
     },
     "contacts": {
      "type": "object",
      "additionalProperties": {
       "type": "string"
      },
      "description": "Contact button labels: kind (`telegram`, `viber`, `whatsapp`, `phone`, `email`) → label."
     },
     "clear": {
      "type": "array",
      "items": {
       "type": "string",
       "enum": [
        "title",
        "greeting",
        "starters",
        "note",
        "refusal",
        "teaser",
        "teaser_product",
        "teaser_returning",
        "teaser_buttons",
        "launcher_label",
        "texts",
        "items",
        "contacts"
       ]
      },
      "description": "What to remove from the set."
     },
     "remove": {
      "type": "boolean",
      "description": "`true` — remove this language entirely."
     }
    }
   },
   "WidgetPartAct": {
    "type": "object",
    "description": "What a built-in button under the feed does instead of its default.",
    "required": [
     "action"
    ],
    "properties": {
     "action": {
      "type": "string",
      "enum": [
       "link",
       "contact",
       "send",
       "insert",
       "new_chat",
       "human",
       "lead",
       "open",
       "close",
       "grow",
       "copy",
       "page"
      ],
      "description": "The action — the same as for custom window elements, except the dropdown and the toggle."
     },
     "value": {
      "type": "string",
      "description": "A URL, a contact (\"telegram:@svitlo\"), text or a page function name — whatever this action needs."
     },
     "fallback": {
      "type": "string",
      "maxLength": 500,
      "description": "Only for `page`: a URL, following the `link` rules, to go to if the page has no function with that name (the site is still loading, a different page). Not set — such a button does nothing."
     },
     "new_tab": {
      "type": "boolean",
      "description": "Open the URL in a new tab."
     }
    }
   },
   "SpendSum": {
    "type": "object",
    "description": "Totals for one slice of the spending summary.",
    "required": [
     "runs",
     "input_tokens",
     "output_tokens",
     "cache_read_tokens",
     "cache_write_tokens",
     "credits",
     "cost_usd"
    ],
    "properties": {
     "runs": {
      "type": "integer",
      "description": "How many runs."
     },
     "input_tokens": {
      "type": "integer",
      "description": "Input tokens at full price."
     },
     "output_tokens": {
      "type": "integer",
      "description": "Output tokens."
     },
     "cache_read_tokens": {
      "type": "integer",
      "description": "Input tokens read from the cache (ten times cheaper)."
     },
     "cache_write_tokens": {
      "type": "integer",
      "description": "Input tokens written to the cache (a quarter more expensive)."
     },
     "credits": {
      "type": "integer",
      "description": "How many credits were charged to the workspace for this. Zero for Builder runs."
     },
     "cost_usd": {
      "type": "number",
      "description": "The token cost at the model's rates, in dollars. This is the model provider's bill, not the cost basis of credits."
     }
    }
   },
   "SpendDay": {
    "type": "object",
    "description": "Usage for one day.",
    "required": [
     "day",
     "runs",
     "input_tokens",
     "output_tokens",
     "cache_read_tokens",
     "cache_write_tokens",
     "credits",
     "cost_usd"
    ],
    "properties": {
     "day": {
      "type": "string",
      "description": "The day (UTC), `2026-10-10`."
     },
     "runs": {
      "type": "integer",
      "description": "How many runs."
     },
     "input_tokens": {
      "type": "integer",
      "description": "Input tokens at full price."
     },
     "output_tokens": {
      "type": "integer",
      "description": "Output tokens."
     },
     "cache_read_tokens": {
      "type": "integer",
      "description": "Input tokens read from the cache (ten times cheaper)."
     },
     "cache_write_tokens": {
      "type": "integer",
      "description": "Input tokens written to the cache (a quarter more expensive)."
     },
     "credits": {
      "type": "integer",
      "description": "How many credits were charged to the workspace for this. Zero for Builder runs."
     },
     "cost_usd": {
      "type": "number",
      "description": "The token cost at the model's rates, in dollars. This is the model provider's bill, not the cost basis of credits."
     }
    }
   },
   "SpendTrigger": {
    "type": "object",
    "description": "Usage for one kind of run.",
    "required": [
     "trigger",
     "runs",
     "input_tokens",
     "output_tokens",
     "cache_read_tokens",
     "cache_write_tokens",
     "credits",
     "cost_usd"
    ],
    "properties": {
     "trigger": {
      "type": "string",
      "description": "What woke the run: `message` — a conversation, `constructor` — a Builder run, `rehearsal` — a rehearsal, `service` — service model calls outside a run; the rest — a schedule, an event, a webhook, a task pass."
     },
     "runs": {
      "type": "integer",
      "description": "How many runs."
     },
     "input_tokens": {
      "type": "integer",
      "description": "Input tokens at full price."
     },
     "output_tokens": {
      "type": "integer",
      "description": "Output tokens."
     },
     "cache_read_tokens": {
      "type": "integer",
      "description": "Input tokens read from the cache (ten times cheaper)."
     },
     "cache_write_tokens": {
      "type": "integer",
      "description": "Input tokens written to the cache (a quarter more expensive)."
     },
     "credits": {
      "type": "integer",
      "description": "How many credits were charged to the workspace for this. Zero for Builder runs."
     },
     "cost_usd": {
      "type": "number",
      "description": "The token cost at the model's rates, in dollars. This is the model provider's bill, not the cost basis of credits."
     }
    }
   },
   "SpendAgent": {
    "type": "object",
    "description": "Usage for one agent in the workspace.",
    "required": [
     "agent",
     "name",
     "runs",
     "input_tokens",
     "output_tokens",
     "cache_read_tokens",
     "cache_write_tokens",
     "credits",
     "cost_usd"
    ],
    "properties": {
     "agent": {
      "type": "string"
     },
     "name": {
      "type": "string",
      "description": "The agent name; empty if the agent no longer exists."
     },
     "runs": {
      "type": "integer",
      "description": "How many runs."
     },
     "input_tokens": {
      "type": "integer",
      "description": "Input tokens at full price."
     },
     "output_tokens": {
      "type": "integer",
      "description": "Output tokens."
     },
     "cache_read_tokens": {
      "type": "integer",
      "description": "Input tokens read from the cache (ten times cheaper)."
     },
     "cache_write_tokens": {
      "type": "integer",
      "description": "Input tokens written to the cache (a quarter more expensive)."
     },
     "credits": {
      "type": "integer",
      "description": "How many credits were charged to the workspace for this. Zero for Builder runs."
     },
     "cost_usd": {
      "type": "number",
      "description": "The token cost at the model's rates, in dollars. This is the model provider's bill, not the cost basis of credits."
     }
    }
   },
   "SpendWorkspace": {
    "type": "object",
    "description": "Usage for one workspace: the total, the Builder's part of it, and per agent.",
    "required": [
     "workspace",
     "owner_email",
     "test",
     "constructor",
     "agents",
     "runs",
     "input_tokens",
     "output_tokens",
     "cache_read_tokens",
     "cache_write_tokens",
     "credits",
     "cost_usd"
    ],
    "properties": {
     "workspace": {
      "type": "string",
      "description": "The workspace; empty for spend without a workspace: service model calls and the totals of deleted or transferred agents."
     },
     "owner_email": {
      "type": "string",
      "description": "The workspace owner's email; empty if the workspace no longer exists."
     },
     "test": {
      "type": "boolean",
      "description": "A test account's workspace. It is left out of the platform overview but included here: the provider charges for its tokens all the same."
     },
     "constructor": {
      "$ref": "#/components/schemas/SpendSum"
     },
     "agents": {
      "type": "array",
      "items": {
       "$ref": "#/components/schemas/SpendAgent"
      }
     },
     "runs": {
      "type": "integer",
      "description": "How many runs."
     },
     "input_tokens": {
      "type": "integer",
      "description": "Input tokens at full price."
     },
     "output_tokens": {
      "type": "integer",
      "description": "Output tokens."
     },
     "cache_read_tokens": {
      "type": "integer",
      "description": "Input tokens read from the cache (ten times cheaper)."
     },
     "cache_write_tokens": {
      "type": "integer",
      "description": "Input tokens written to the cache (a quarter more expensive)."
     },
     "credits": {
      "type": "integer",
      "description": "How many credits were charged to the workspace for this. Zero for Builder runs."
     },
     "cost_usd": {
      "type": "number",
      "description": "The token cost at the model's rates, in dollars. This is the model provider's bill, not the cost basis of credits."
     }
    }
   },
   "SpendRun": {
    "type": "object",
    "description": "One of the most expensive runs.",
    "required": [
     "id",
     "workspace",
     "owner_email",
     "agent",
     "agent_name",
     "trigger",
     "status",
     "started_at",
     "runs",
     "input_tokens",
     "output_tokens",
     "cache_read_tokens",
     "cache_write_tokens",
     "credits",
     "cost_usd"
    ],
    "properties": {
     "id": {
      "type": "string"
     },
     "workspace": {
      "type": "string"
     },
     "owner_email": {
      "type": "string"
     },
     "agent": {
      "type": "string",
      "description": "Empty for a Builder run."
     },
     "agent_name": {
      "type": "string"
     },
     "trigger": {
      "type": "string"
     },
     "status": {
      "type": "string"
     },
     "started_at": {
      "type": "string",
      "format": "date-time"
     },
     "runs": {
      "type": "integer",
      "description": "How many runs."
     },
     "input_tokens": {
      "type": "integer",
      "description": "Input tokens at full price."
     },
     "output_tokens": {
      "type": "integer",
      "description": "Output tokens."
     },
     "cache_read_tokens": {
      "type": "integer",
      "description": "Input tokens read from the cache (ten times cheaper)."
     },
     "cache_write_tokens": {
      "type": "integer",
      "description": "Input tokens written to the cache (a quarter more expensive)."
     },
     "credits": {
      "type": "integer",
      "description": "How many credits were charged to the workspace for this. Zero for Builder runs."
     },
     "cost_usd": {
      "type": "number",
      "description": "The token cost at the model's rates, in dollars. This is the model provider's bill, not the cost basis of credits."
     }
    }
   },
   "SpendReport": {
    "type": "object",
    "description": "A summary of model spending across all workspaces on the platform.",
    "required": [
     "model",
     "rates",
     "days",
     "since",
     "total",
     "by_day",
     "by_trigger",
     "workspaces",
     "costliest"
    ],
    "properties": {
     "model": {
      "type": "string",
      "description": "The model that agents and the Builder reply with."
     },
     "rates": {
      "type": "object",
      "description": "The rates the dollars are computed at: per million tokens.",
      "required": [
       "input_per_mtok",
       "output_per_mtok",
       "cache_read_per_mtok",
       "cache_write_per_mtok"
      ],
      "properties": {
       "input_per_mtok": {
        "type": "number"
       },
       "output_per_mtok": {
        "type": "number"
       },
       "cache_read_per_mtok": {
        "type": "number"
       },
       "cache_write_per_mtok": {
        "type": "number"
       }
      }
     },
     "days": {
      "type": "integer"
     },
     "since": {
      "type": "string",
      "description": "The first day of the window (UTC)."
     },
     "total": {
      "$ref": "#/components/schemas/SpendSum"
     },
     "by_day": {
      "type": "array",
      "description": "Newest day first.",
      "items": {
       "$ref": "#/components/schemas/SpendDay"
      }
     },
     "by_trigger": {
      "type": "array",
      "description": "Most expensive run kind first.",
      "items": {
       "$ref": "#/components/schemas/SpendTrigger"
      }
     },
     "workspaces": {
      "type": "array",
      "description": "Most expensive workspace first.",
      "items": {
       "$ref": "#/components/schemas/SpendWorkspace"
      }
     },
     "costliest": {
      "type": "array",
      "description": "Up to 50 of the most expensive runs in the window.",
      "items": {
       "$ref": "#/components/schemas/SpendRun"
      }
     }
    }
   },
   "ActionButton": {
    "type": "object",
    "description": "A link button from an action's response.",
    "required": [
     "label",
     "url",
     "style"
    ],
    "properties": {
     "label": {
      "type": "string"
     },
     "url": {
      "type": "string",
      "description": "`https://…`, `mailto:` or `tel:`."
     },
     "style": {
      "type": "string",
      "enum": [
       "primary",
       "secondary",
       "pay"
      ],
      "description": "`pay` — a payment button: the window renders it more prominently."
     }
    }
   },
   "ActionFile": {
    "type": "object",
    "description": "A file from an action's response that the person can download.",
    "required": [
     "name",
     "url"
    ],
    "properties": {
     "name": {
      "type": "string"
     },
     "url": {
      "type": "string",
      "description": "Only `https://…`."
     },
     "size": {
      "type": "integer",
      "description": "Bytes, if the service reported them."
     }
    }
   },
   "ActionOutcome": {
    "type": "object",
    "description": "How one action call in this run ended — for the window and the page code. Buttons and files come from the top-level `buttons` and `files` fields of the owner's service JSON response and are shown under the reply exactly as the service returned them (up to 4 buttons and 5 files). `args` and `result` are present only for an action with `expose_result: true`.",
    "required": [
     "name",
     "ok"
    ],
    "properties": {
     "name": {
      "type": "string",
      "description": "The action name."
     },
     "ok": {
      "type": "boolean",
      "description": "The service responded without an error."
     },
     "args": {
      "description": "The call arguments (only with `expose_result`)."
     },
     "result": {
      "description": "The raw action result: JSON as is, anything else as a string; up to 64 KB (only with `expose_result`)."
     },
     "buttons": {
      "type": "array",
      "items": {
       "$ref": "#/components/schemas/ActionButton"
      }
     },
     "files": {
      "type": "array",
      "items": {
       "$ref": "#/components/schemas/ActionFile"
      }
     }
    }
   },
   "StarterRule": {
    "type": "object",
    "required": [
     "pages",
     "starters"
    ],
    "properties": {
     "pages": {
      "type": "string",
      "description": "The page path from the site root, an asterisk means anything: `/app/*`, `/pricing`."
     },
     "starters": {
      "type": "array",
      "maxItems": 4,
      "items": {
       "type": "string"
      },
      "description": "Suggestions on these pages (up to 80 characters each); empty means no suggestions here."
     }
    }
   },
   "StreamClientTool": {
    "type": "object",
    "description": "The model is calling a page tool: run the `name` handler with the `args` arguments and return the result to `POST /v1/widget/tool-result` with this `id`. The run waits up to 30 seconds.",
    "required": [
     "client_tool"
    ],
    "properties": {
     "client_tool": {
      "type": "object",
      "required": [
       "id",
       "name",
       "args"
      ],
      "properties": {
       "id": {
        "type": "string"
       },
       "name": {
        "type": "string"
       },
       "args": {
        "type": "object"
       }
      }
     }
    }
   },
   "PlatformUser": {
    "type": "object",
    "required": [
     "id",
     "email",
     "email_confirmed",
     "agents",
     "can_enter",
     "tester",
     "plan_granted",
     "paid_total",
     "spend_30d_credits",
     "runs_30d",
     "conversations_30d",
     "blocked",
     "test"
    ],
    "properties": {
     "id": {
      "type": "string"
     },
     "email": {
      "type": "string"
     },
     "email_confirmed": {
      "type": "boolean"
     },
     "created_at": {
      "type": "string",
      "format": "date-time"
     },
     "closing": {
      "type": "boolean",
      "description": "The account is being deleted."
     },
     "agents": {
      "type": "integer",
      "description": "Agents in their own workspace; -1 means not read."
     },
     "plan": {
      "type": "string"
     },
     "can_enter": {
      "type": "boolean",
      "description": "Whether you can sign in as them: not as yourself, not as another platform staff member, not into an account that is being deleted or is blocked."
     },
     "tester": {
      "type": "boolean",
      "description": "Tester: picks any plan for themselves without paying."
     },
     "last_active_at": {
      "type": "string",
      "format": "date-time",
      "description": "The person's last agent run or their last sign-in, whichever is later; absent means neither has happened yet."
     },
     "plan_until": {
      "type": "string",
      "format": "date-time",
      "description": "Until when the current plan is valid (the end of the paid or granted period)."
     },
     "plan_granted": {
      "type": "boolean",
      "description": "The current plan was granted without payment."
     },
     "paid_total": {
      "type": "number",
      "description": "The total of paid orders (plans, excluding granted ones, and credit packs). Renewals of the same order count as one amount."
     },
     "spend_30d_credits": {
      "type": "integer",
      "description": "Credits used by their own workspace over 30 days."
     },
     "runs_30d": {
      "type": "integer",
      "description": "Agent and Builder runs in their own workspace over 30 days."
     },
     "conversations_30d": {
      "type": "integer",
      "description": "Distinct visitor conversations with agents over 30 days."
     },
     "blocked": {
      "type": "boolean",
      "description": "The account was blocked by platform staff."
     },
     "test": {
      "type": "boolean",
      "description": "Test account: platform summaries don't count it."
     },
     "note": {
      "type": "string",
      "description": "The first line of the platform staff note."
     }
    }
   },
   "PlatformUsers": {
    "type": "object",
    "required": [
     "users",
     "total",
     "offset",
     "page",
     "filter",
     "sort"
    ],
    "properties": {
     "users": {
      "type": "array",
      "items": {
       "$ref": "#/components/schemas/PlatformUser"
      }
     },
     "total": {
      "type": "integer",
      "description": "How many accounts match the search and filter."
     },
     "offset": {
      "type": "integer"
     },
     "page": {
      "type": "integer"
     },
     "filter": {
      "type": "string",
      "enum": [
       "all",
       "paying",
       "granted",
       "testers",
       "test",
       "blocked",
       "closing",
       "unconfirmed"
      ],
      "description": "The filter applied."
     },
     "sort": {
      "type": "string",
      "enum": [
       "registered",
       "last_active",
       "paid",
       "spend",
       "agents"
      ],
      "description": "The sort order applied."
     }
    }
   },
   "AdminEntryLink": {
    "type": "object",
    "required": [
     "url",
     "expires_at",
     "email"
    ],
    "properties": {
     "url": {
      "type": "string",
      "description": "The sign-in link; the token comes after \"#\"."
     },
     "expires_at": {
      "type": "string",
      "format": "date-time"
     },
     "email": {
      "type": "string"
     }
    }
   },
   "PlanGrant": {
    "type": "object",
    "properties": {
     "plan": {
      "type": "string",
      "description": "The current plan after the change."
     },
     "until": {
      "type": "string",
      "format": "date-time",
      "description": "Until when the granted plan is valid; absent means the plan isn't granted."
     },
     "user": {
      "$ref": "#/components/schemas/PlatformUser",
      "description": "The updated list row (absent if it couldn't be re-read; the plan was changed anyway)."
     }
    },
    "required": [
     "plan"
    ]
   },
   "TraceStep": {
    "allOf": [
     {
      "$ref": "#/components/schemas/RunStep"
     }
    ],
    "description": "A run trace step in the platform activity — the same RunStep, together with tool call arguments and results."
   },
   "ActivityRun": {
    "type": "object",
    "required": [
     "id",
     "at",
     "kind",
     "trigger",
     "status",
     "credits",
     "workspace",
     "owner_email",
     "agent",
     "agent_name",
     "tools",
     "failed_tools"
    ],
    "description": "One run in the platform activity list.",
    "properties": {
     "id": {
      "type": "string",
      "description": "The run ID (run_…)."
     },
     "at": {
      "type": "string",
      "format": "date-time",
      "description": "The start of the run."
     },
     "finished_at": {
      "type": "string",
      "format": "date-time",
      "description": "The end of the run; absent while the run is in progress."
     },
     "kind": {
      "type": "string",
      "enum": [
       "visitor",
       "builder",
       "background",
       "rehearsal"
      ],
      "description": "visitor — a conversation (window, messenger, another agent); builder — a Builder run; background — a schedule, webhook, polling, event; rehearsal — a rehearsal."
     },
     "trigger": {
      "type": "string",
      "description": "What woke the run — the raw trigger type from the log."
     },
     "status": {
      "type": "string",
      "enum": [
       "running",
       "done",
       "failed"
      ]
     },
     "error": {
      "type": "string",
      "description": "Why the run failed; only for failed."
     },
     "credits": {
      "type": "integer",
      "format": "int64"
     },
     "workspace": {
      "type": "string",
      "description": "The workspace that pays for the run."
     },
     "owner_email": {
      "type": "string",
      "description": "The workspace owner's email; empty if the workspace no longer exists."
     },
     "agent": {
      "type": "string",
      "description": "The agent; empty for Builder runs."
     },
     "agent_name": {
      "type": "string",
      "description": "The agent name; empty if there's no agent or it wasn't found."
     },
     "session_id": {
      "type": "string",
      "description": "The conversation thread, if the run happened in one."
     },
     "question": {
      "type": "string",
      "description": "The message that woke the run (up to 300 characters), if the run happened in a conversation."
     },
     "answer": {
      "type": "string",
      "description": "The agent's reply (up to 300 characters), if there is one."
     },
     "tools": {
      "type": "integer",
      "description": "How many times the model called tools."
     },
     "failed_tools": {
      "type": "integer",
      "description": "How many of those calls failed."
     }
    }
   },
   "PlatformActivity": {
    "type": "object",
    "required": [
     "runs"
    ],
    "properties": {
     "runs": {
      "type": "array",
      "items": {
       "$ref": "#/components/schemas/ActivityRun"
      }
     },
     "next": {
      "type": "string",
      "description": "The cursor for the next page (pass it as before); absent means there's nothing more."
     }
    }
   },
   "ActivityLine": {
    "type": "object",
    "required": [
     "role",
     "content",
     "at"
    ],
    "description": "A conversation message in the run details.",
    "properties": {
     "role": {
      "type": "string",
      "enum": [
       "user",
       "assistant"
      ]
     },
     "content": {
      "type": "string",
      "description": "The full message text."
     },
     "at": {
      "type": "string",
      "format": "date-time",
      "description": "When the message was recorded."
     },
     "run_id": {
      "type": "string",
      "description": "The run the message belongs to, if known."
     }
    }
   },
   "ActivityDetail": {
    "type": "object",
    "required": [
     "run",
     "trace",
     "transcript"
    ],
    "properties": {
     "run": {
      "$ref": "#/components/schemas/ActivityRun"
     },
     "trace": {
      "type": "array",
      "items": {
       "$ref": "#/components/schemas/TraceStep"
      }
     },
     "transcript": {
      "type": "array",
      "items": {
       "$ref": "#/components/schemas/ActivityLine"
      },
      "description": "The whole conversation of the run's thread (up to the last 200 messages) in chronological order: for the Builder — its conversation with the person, for an agent — with the visitor. A run without a thread (background, rehearsal) gives an empty list."
     }
    }
   },
   "PlatformUserChange": {
    "type": "object",
    "properties": {
     "user": {
      "$ref": "#/components/schemas/PlatformUser"
     },
     "applied": {
      "type": "integer",
      "description": "Credits actually added (+) or taken away (−): you can't take away more than there is."
     },
     "balance": {
      "type": "integer",
      "description": "The workspace's prepaid credit balance after the action."
     },
     "note": {
      "type": "string",
      "description": "The saved note in full."
     },
     "url": {
      "type": "string",
      "description": "The set-password link — shown once."
     },
     "expires_at": {
      "type": "string",
      "format": "date-time",
      "description": "Until when the link is valid."
     },
     "erase_at": {
      "type": "string",
      "format": "date-time",
      "description": "When the account data will be permanently erased (the \"change your mind\" window)."
     },
     "agents_restored": {
      "type": "integer",
      "description": "How many agents were restored together with the account."
     },
     "agents_incomplete": {
      "type": "boolean",
      "description": "Not all agents were restored: the rest are among the deleted ones, with a \"Restore\" button."
     }
    },
    "required": [
     "user"
    ],
    "description": "The account action was performed: the updated list row and whatever the action adds."
   },
   "PlatformAuditEntry": {
    "type": "object",
    "properties": {
     "id": {
      "type": "string"
     },
     "at": {
      "type": "string",
      "format": "date-time"
     },
     "admin_id": {
      "type": "string"
     },
     "admin_email": {
      "type": "string"
     },
     "action": {
      "type": "string",
      "description": "entry, plan, tester, create_tester, block, unblock, test, credits, confirm_email, password_link, logout, note, delete, restore, view_run, view_conversation, db_query, db_cell."
     },
     "target_user": {
      "type": "string"
     },
     "target_email": {
      "type": "string",
      "description": "The current email of the account the action was applied to; absent means the account was erased (the log doesn't keep addresses)."
     },
     "target_workspace": {
      "type": "string"
     },
     "target_agent": {
      "type": "string"
     },
     "target_agent_name": {
      "type": "string"
     },
     "detail": {
      "type": "object",
      "additionalProperties": {},
      "description": "Action details: plan and term, credits, block reason, run or conversation."
     }
    },
    "required": [
     "id",
     "at",
     "admin_id",
     "admin_email",
     "action",
     "detail"
    ]
   },
   "PlatformAudit": {
    "type": "object",
    "properties": {
     "entries": {
      "type": "array",
      "items": {
       "$ref": "#/components/schemas/PlatformAuditEntry"
      }
     },
     "next": {
      "type": "string",
      "description": "The cursor for the next page (`before`); empty means there's nothing more."
     },
     "actions": {
      "type": "array",
      "items": {
       "type": "string"
      },
      "description": "All known actions — for the filter."
     }
    },
    "required": [
     "entries",
     "next",
     "actions"
    ]
   },
   "PlatformDossier": {
    "type": "object",
    "properties": {
     "user": {
      "type": "object",
      "properties": {
       "id": {
        "type": "string"
       },
       "email": {
        "type": "string"
       },
       "email_confirmed": {
        "type": "boolean"
       },
       "created_at": {
        "type": "string",
        "format": "date-time"
       },
       "closing": {
        "type": "boolean"
       },
       "closing_at": {
        "type": "string",
        "format": "date-time",
        "description": "When deletion was requested."
       },
       "blocked": {
        "type": "boolean"
       },
       "blocked_at": {
        "type": "string",
        "format": "date-time"
       },
       "blocked_reason": {
        "type": "string"
       },
       "test": {
        "type": "boolean"
       },
       "tester": {
        "type": "boolean"
       },
       "platform_admin": {
        "type": "boolean"
       },
       "note": {
        "type": "string",
        "description": "The platform staff note in full."
       },
       "last_active_at": {
        "type": "string",
        "format": "date-time"
       },
       "login_methods": {
        "type": "array",
        "items": {
         "type": "string",
         "enum": [
          "password",
          "sso"
         ]
        },
        "description": "How the person signs in."
       },
       "lang": {
        "type": "string"
       }
      },
      "required": [
       "id",
       "email",
       "email_confirmed",
       "closing",
       "blocked",
       "test",
       "tester",
       "platform_admin",
       "note",
       "login_methods"
      ]
     },
     "plan": {
      "type": "object",
      "properties": {
       "plan": {
        "type": "string"
       },
       "until": {
        "type": "string",
        "format": "date-time"
       },
       "granted": {
        "type": "boolean"
       },
       "paid_total": {
        "type": "number"
       },
       "entitlement": {
        "type": "object",
        "properties": {
         "max_bots": {
          "type": "integer",
          "description": "-1 means unlimited."
         },
         "credits_month": {
          "type": "integer",
          "description": "-1 means unlimited."
         }
        },
        "required": [
         "max_bots",
         "credits_month"
        ]
       },
       "subscriptions": {
        "type": "array",
        "items": {
         "type": "object",
         "properties": {
          "order_id": {
           "type": "string"
          },
          "plan": {
           "type": "string"
          },
          "status": {
           "type": "string"
          },
          "amount": {
           "type": "number"
          },
          "period_end": {
           "type": "string",
           "format": "date-time"
          },
          "cancel_at_period_end": {
           "type": "boolean"
          },
          "created_at": {
           "type": "string",
           "format": "date-time"
          },
          "granted": {
           "type": "boolean",
           "description": "Granted without payment."
          }
         },
         "required": [
          "order_id",
          "plan",
          "status",
          "amount",
          "cancel_at_period_end",
          "granted"
         ]
        }
       },
       "charges": {
        "type": "array",
        "items": {
         "type": "object",
         "properties": {
          "order_id": {
           "type": "string"
          },
          "kind": {
           "type": "string",
           "enum": [
            "plan",
            "credits"
           ],
           "description": "plan — a subscription, credits — a one-time credit pack."
          },
          "name": {
           "type": "string",
           "description": "Name of the plan or pack at display time: the catalog is live, and a plan withdrawn from sale stays in the history under its id."
          },
          "amount": {
           "type": "number"
          },
          "currency": {
           "type": "string"
          },
          "status": {
           "type": "string",
           "description": "pending | active | failed | canceled | expired | refunding | refunded | refund_failed — as is, without smoothing. canceled — the owner canceled the payment attempt; expired — the payment deadline passed with no money received; refunding/refunded/refund_failed — the payment was unnecessary (a double payment, or one for a canceled attempt): it is being refunded, has been refunded, or couldn't be refunded automatically."
          },
          "at": {
           "type": "string",
           "format": "date-time"
          },
          "credits": {
           "type": "integer",
           "description": "How many credits the pack purchase added; absent for a subscription."
          },
          "note": {
           "type": "string",
           "description": "Why the invoice is in this state, in plain words: for example, \"refunded automatically: double payment\". Only for invoices whose payment is being refunded."
          }
         }
        },
        "description": "The same as GET /v1/billing/history."
       }
      },
      "required": [
       "plan",
       "granted",
       "paid_total",
       "entitlement",
       "subscriptions",
       "charges"
      ]
     },
     "credits": {
      "type": "object",
      "properties": {
       "balance": {
        "type": "integer",
        "description": "Prepaid credits of their own workspace."
       },
       "spent_30d": {
        "type": "integer"
       },
       "by_day": {
        "type": "array",
        "items": {
         "type": "object",
         "properties": {
          "day": {
           "type": "string",
           "description": "YYYY-MM-DD"
          },
          "credits": {
           "type": "integer"
          },
          "runs": {
           "type": "integer"
          }
         },
         "required": [
          "day",
          "credits",
          "runs"
         ]
        }
       }
      },
      "required": [
       "balance",
       "spent_30d",
       "by_day"
      ]
     },
     "workspaces": {
      "type": "array",
      "items": {
       "type": "object",
       "properties": {
        "id": {
         "type": "string"
        },
        "role": {
         "type": "string"
        },
        "owner_id": {
         "type": "string"
        },
        "owner_email": {
         "type": "string"
        },
        "members": {
         "type": "array",
         "items": {
          "type": "object",
          "properties": {
           "user_id": {
            "type": "string"
           },
           "email": {
            "type": "string"
           },
           "role": {
            "type": "string"
           }
          },
          "required": [
           "user_id",
           "email",
           "role"
          ]
         }
        }
       },
       "required": [
        "id",
        "role",
        "owner_id",
        "owner_email",
        "members"
       ]
      }
     },
     "agents": {
      "type": "array",
      "items": {
       "type": "object",
       "properties": {
        "id": {
         "type": "string"
        },
        "name": {
         "type": "string"
        },
        "workspace": {
         "type": "string"
        },
        "created_at": {
         "type": "string",
         "format": "date-time"
        },
        "deleted": {
         "type": "boolean"
        },
        "deleted_at": {
         "type": "string",
         "format": "date-time"
        },
        "frozen": {
         "type": "boolean",
         "description": "The agent is currently moving to another owner."
        },
        "channels": {
         "type": "array",
         "items": {
          "type": "string"
         },
         "description": "Enabled channels by kind."
        },
        "knowledge_sources": {
         "type": "integer"
        },
        "actions": {
         "type": "integer"
        },
        "triggers": {
         "type": "integer"
        },
        "runs_30d": {
         "type": "integer"
        },
        "credits_30d": {
         "type": "integer"
        },
        "open_incidents": {
         "type": "integer"
        },
        "last_run_at": {
         "type": "string",
         "format": "date-time"
        }
       },
       "required": [
        "id",
        "name",
        "workspace",
        "deleted",
        "frozen",
        "channels",
        "knowledge_sources",
        "actions",
        "triggers",
        "runs_30d",
        "credits_30d",
        "open_incidents"
       ]
      }
     },
     "conversations": {
      "type": "array",
      "items": {
       "type": "object",
       "properties": {
        "agent": {
         "type": "string"
        },
        "agent_name": {
         "type": "string"
        },
        "session_id": {
         "type": "string"
        },
        "kind": {
         "type": "string",
         "enum": [
          "visitor",
          "builder"
         ]
        },
        "messages": {
         "type": "integer",
         "description": "-1 means not read."
        },
        "first_at": {
         "type": "string",
         "format": "date-time"
        },
        "last_at": {
         "type": "string",
         "format": "date-time"
        },
        "last_message": {
         "type": "string"
        },
        "handoff": {
         "type": "string",
         "enum": [
          "none",
          "waiting",
          "taken",
          "closed"
         ]
        },
        "title": {
         "type": "string",
         "description": "The title of the chat with the Builder."
        }
       },
       "required": [
        "agent",
        "agent_name",
        "session_id",
        "kind",
        "messages",
        "last_message",
        "handoff"
       ]
      },
      "description": "Up to the last 100: visitors with the person's agents, and the person themselves with the Builder. Each one opens with GET /v1/platform/conversations/{agent}/{session}."
     },
     "incidents": {
      "type": "array",
      "items": {
       "type": "object",
       "properties": {
        "id": {
         "type": "string"
        },
        "agent": {
         "type": "string"
        },
        "kind": {
         "type": "string",
         "enum": [
          "credits_low",
          "credits_exhausted",
          "cost_cap",
          "agent_cap",
          "action_unauthorized",
          "action_failing",
          "actions_unavailable",
          "run_failed",
          "turn_too_long",
          "loop_exhausted",
          "trigger_paused",
          "handoff_failed",
          "work_unfinished",
          "secret_missing",
          "memory_unproven",
          "history_lost",
          "mailbox_unreadable",
          "reply_undelivered",
          "reply_partial",
          "reply_refused",
          "records_full",
          "task_stalled",
          "catalog_stale",
          "voice_unheard",
          "calendar_unreadable",
          "image_unmade",
          "speech_unmade",
          "page_unreadable",
          "payment_unauthorized",
          "payment_unavailable",
          "site_pages_changed"
         ],
         "description": "Incident kind — the same list as `Incident.kind`."
        },
        "subject": {
         "type": "string"
        },
        "count": {
         "type": "integer"
        },
        "opened_at": {
         "type": "string",
         "format": "date-time"
        },
        "last_at": {
         "type": "string",
         "format": "date-time"
        },
        "resolved_at": {
         "type": "string",
         "format": "date-time"
        }
       },
       "required": [
        "id",
        "agent",
        "kind",
        "count",
        "opened_at",
        "last_at"
       ]
      }
     },
     "keys": {
      "type": "array",
      "items": {
       "type": "object",
       "properties": {
        "kind": {
         "type": "string",
         "enum": [
          "sk",
          "ak"
         ]
        },
        "agent": {
         "type": "string"
        },
        "name": {
         "type": "string"
        },
        "prefix": {
         "type": "string",
         "description": "The start of the key — the key itself isn't shown."
        },
        "created_at": {
         "type": "string",
         "format": "date-time"
        },
        "last_used_at": {
         "type": "string",
         "format": "date-time"
        }
       },
       "required": [
        "kind",
        "agent",
        "prefix"
       ]
      }
     },
     "sessions": {
      "type": "array",
      "items": {
       "type": "object",
       "properties": {
        "created_at": {
         "type": "string",
         "format": "date-time"
        },
        "expires_at": {
         "type": "string",
         "format": "date-time"
        },
        "last_seen_at": {
         "type": "string",
         "format": "date-time"
        },
        "ip": {
         "type": "string",
         "description": "Storage doesn't keep it — empty."
        },
        "user_agent": {
         "type": "string",
         "description": "Storage doesn't keep it — empty."
        },
        "admin_entry": {
         "type": "boolean",
         "description": "The session was opened by a platform staff link."
        },
        "admin_email": {
         "type": "string"
        }
       },
       "required": [
        "ip",
        "user_agent",
        "admin_entry"
       ]
      }
     },
     "audit": {
      "type": "array",
      "items": {
       "$ref": "#/components/schemas/PlatformAuditEntry"
      },
      "description": "Up to the last 50 actions platform staff took on this account."
     },
     "related": {
      "type": "array",
      "items": {
       "type": "object",
       "properties": {
        "id": {
         "type": "string"
        },
        "email": {
         "type": "string"
        },
        "why": {
         "type": "string",
         "enum": [
          "same_workspace",
          "same_ip"
         ]
        }
       },
       "required": [
        "id",
        "email",
        "why"
       ]
      }
     },
     "unknown": {
      "type": "array",
      "items": {
       "type": "string"
      },
      "description": "Fields the storage doesn't keep: they're empty not because there's nothing there."
     },
     "unread": {
      "type": "array",
      "items": {
       "type": "string"
      },
      "description": "Parts that should have been read but weren't this time: they are incomplete."
     }
    },
    "required": [
     "user",
     "plan",
     "credits",
     "workspaces",
     "agents",
     "conversations",
     "incidents",
     "keys",
     "sessions",
     "audit",
     "related",
     "unknown",
     "unread"
    ]
   },
   "PlatformConversation": {
    "type": "object",
    "properties": {
     "kind": {
      "type": "string",
      "enum": [
       "visitor",
       "builder"
      ]
     },
     "agent": {
      "type": "string"
     },
     "agent_name": {
      "type": "string"
     },
     "session_id": {
      "type": "string"
     },
     "workspace": {
      "type": "string"
     },
     "owner_id": {
      "type": "string"
     },
     "owner_email": {
      "type": "string"
     },
     "title": {
      "type": "string"
     },
     "messages": {
      "type": "array",
      "items": {
       "type": "object",
       "properties": {
        "id": {
         "type": "string"
        },
        "author": {
         "type": "string",
         "description": "visitor | bot | operator | event — a conversation with a customer; owner | builder — with the Builder."
        },
        "text": {
         "type": "string"
        },
        "at": {
         "type": "string",
         "format": "date-time"
        },
        "operator_email": {
         "type": "string"
        },
        "event": {
         "type": "object",
         "additionalProperties": {},
         "description": "A conversation event (contact, rating)."
        }
       },
       "required": [
        "author",
        "text"
       ]
      }
     },
     "truncated": {
      "type": "boolean",
      "description": "More than 500 messages — the latest are shown."
     },
     "runs": {
      "type": "array",
      "items": {
       "type": "object",
       "properties": {
        "id": {
         "type": "string"
        },
        "started_at": {
         "type": "string",
         "format": "date-time"
        },
        "finished_at": {
         "type": "string",
         "format": "date-time"
        },
        "status": {
         "type": "string"
        },
        "trigger": {
         "type": "string"
        },
        "credits": {
         "type": "integer"
        },
        "error": {
         "type": "string"
        }
       },
       "required": [
        "id",
        "started_at",
        "status",
        "trigger",
        "credits"
       ]
      },
      "description": "Runs in this thread, newest first; the trace is at GET /v1/platform/activity/{runID}."
     },
     "handoff": {
      "type": "object",
      "properties": {
       "status": {
        "type": "string",
        "enum": [
         "none",
         "waiting",
         "taken",
         "closed"
        ]
       },
       "assignee_email": {
        "type": "string"
       },
       "assigned_at": {
        "type": "string",
        "format": "date-time"
       },
       "contact": {
        "type": "string"
       },
       "contact_name": {
        "type": "string"
       },
       "unhappy": {
        "type": "boolean"
       },
       "personal": {
        "type": "boolean"
       }
      },
      "required": [
       "status",
       "unhappy",
       "personal"
      ]
     }
    },
    "required": [
     "kind",
     "agent",
     "agent_name",
     "session_id",
     "workspace",
     "owner_id",
     "owner_email",
     "messages",
     "truncated",
     "runs",
     "handoff"
    ]
   },
   "PlatformOverview": {
    "type": "object",
    "properties": {
     "tiles": {
      "type": "object",
      "properties": {
       "accounts_total": {
        "type": "integer"
       },
       "accounts_new_7d": {
        "type": "integer"
       },
       "accounts_active_7d": {
        "type": "integer",
        "description": "At least one sign-in or agent run in 7 days."
       },
       "agents": {
        "type": "integer",
        "description": "Live agents."
       },
       "runs_24h": {
        "type": "integer"
       },
       "runs_24h_failed": {
        "type": "integer"
       },
       "runs_7d": {
        "type": "integer"
       },
       "runs_7d_failed": {
        "type": "integer"
       },
       "credits_7d": {
        "type": "integer"
       },
       "paid_orders_30d": {
        "type": "integer",
        "description": "Paid orders created in 30 days (plans, excluding granted ones, and packs)."
       },
       "paid_amount_30d": {
        "type": "number"
       },
       "open_incidents": {
        "type": "object",
        "additionalProperties": {
         "type": "integer"
        },
        "propertyNames": {
         "type": "string",
         "enum": [
          "credits_low",
          "credits_exhausted",
          "cost_cap",
          "agent_cap",
          "action_unauthorized",
          "action_failing",
          "actions_unavailable",
          "run_failed",
          "turn_too_long",
          "loop_exhausted",
          "trigger_paused",
          "handoff_failed",
          "work_unfinished",
          "secret_missing",
          "memory_unproven",
          "history_lost",
          "mailbox_unreadable",
          "reply_undelivered",
          "reply_partial",
          "reply_refused",
          "records_full",
          "task_stalled",
          "catalog_stale",
          "voice_unheard",
          "calendar_unreadable",
          "image_unmade",
          "speech_unmade",
          "page_unreadable",
          "payment_unauthorized",
          "payment_unavailable",
          "site_pages_changed"
         ]
        },
        "description": "Open incidents by kind: the key is the incident kind (the `Incident.kind` list), the value is how many are open."
       },
       "running_now": {
        "type": "integer",
        "description": "Runs in progress (started within the last day)."
       }
      },
      "required": [
       "accounts_total",
       "accounts_new_7d",
       "accounts_active_7d",
       "agents",
       "runs_24h",
       "runs_24h_failed",
       "runs_7d",
       "runs_7d_failed",
       "credits_7d",
       "paid_orders_30d",
       "paid_amount_30d",
       "open_incidents",
       "running_now"
      ]
     },
     "health": {
      "type": "object",
      "properties": {
       "status": {
        "type": "string",
        "enum": [
         "ok",
         "unavailable"
        ]
       },
       "failing": {
        "type": "object",
        "additionalProperties": {
         "type": "string"
        },
        "description": "Dependencies that aren't responding — as in /readyz."
       },
       "features": {
        "type": "object",
        "additionalProperties": {
         "type": "boolean"
        },
        "description": "What the build can do and what's working right now — as in /readyz."
       },
       "degraded": {
        "type": "object",
        "additionalProperties": {},
        "description": "Why a capability isn't working right now."
       },
       "db": {
        "type": [
         "object",
         "null"
        ],
        "properties": {
         "used": {
          "type": "integer",
          "description": "Open connections of the role."
         },
         "limit": {
          "type": "integer",
          "description": "The role's ceiling; -1 means no ceiling."
         },
         "server": {
          "type": "integer",
          "description": "The server's max_connections."
         },
         "pool": {
          "type": "integer",
          "description": "The pool ceiling of this instance."
         }
        },
        "required": [
         "used",
         "limit",
         "server",
         "pool"
        ],
        "description": "null means no database, or it couldn't be read."
       },
       "loops": {
        "type": "array",
        "items": {
         "type": "object",
         "properties": {
          "name": {
           "type": "string"
          },
          "every_sec": {
           "type": "integer"
          },
          "last_at": {
           "type": "string",
           "format": "date-time"
          },
          "took_ms": {
           "type": "integer"
          },
          "panicked": {
           "type": "boolean"
          }
         },
         "required": [
          "name",
          "every_sec",
          "last_at",
          "took_ms",
          "panicked"
         ]
        },
        "description": "The last pass of each background loop on THIS instance since it started; a loop that hasn't run yet is absent."
       },
       "version": {
        "type": "string",
        "description": "The build commit."
       }
      },
      "required": [
       "status",
       "failing",
       "features",
       "degraded",
       "db",
       "loops",
       "version"
      ]
     },
     "series": {
      "type": "object",
      "properties": {
       "accounts": {
        "type": "array",
        "items": {
         "type": "object",
         "properties": {
          "day": {
           "type": "string"
          },
          "count": {
           "type": "integer"
          }
         },
         "required": [
          "day",
          "count"
         ]
        },
        "description": "New accounts per day, 30 days."
       },
       "runs": {
        "type": "array",
        "items": {
         "type": "object",
         "properties": {
          "day": {
           "type": "string"
          },
          "visitor": {
           "type": "integer"
          },
          "builder": {
           "type": "integer"
          },
          "background": {
           "type": "integer"
          },
          "rehearsal": {
           "type": "integer"
          }
         },
         "required": [
          "day",
          "visitor",
          "builder",
          "background",
          "rehearsal"
         ]
        },
        "description": "Runs per day by kind."
       },
       "credits": {
        "type": "array",
        "items": {
         "type": "object",
         "properties": {
          "day": {
           "type": "string"
          },
          "credits": {
           "type": "integer"
          }
         },
         "required": [
          "day",
          "credits"
         ]
        },
        "description": "Credits per day."
       }
      },
      "required": [
       "accounts",
       "runs",
       "credits"
      ]
     },
     "test_accounts": {
      "type": "integer",
      "description": "How many test accounts were excluded from all the numbers."
     },
     "unread": {
      "type": "array",
      "items": {
       "type": "string"
      },
      "description": "Parts that couldn't be read: the numbers next to them are incomplete."
     }
    },
    "required": [
     "tiles",
     "health",
     "series",
     "test_accounts",
     "unread"
    ]
   }
  },
  "responses": {
   "BadRequest": {
    "description": "Bad request: a required field is missing or empty, or the body isn't valid JSON.",
    "content": {
     "application/json": {
      "schema": {
       "$ref": "#/components/schemas/Error"
      },
      "examples": {
       "default": {
        "value": {
         "error": "Write a message.",
         "code": "bad_request"
        }
       }
      }
     }
    }
   },
   "Unauthorized": {
    "description": "`X-Bot-Key` is missing or invalid. A secret key (`sk_…`) from the YouSelfBot dashboard is required.",
    "content": {
     "application/json": {
      "schema": {
       "$ref": "#/components/schemas/Error"
      },
      "examples": {
       "default": {
        "value": {
         "error": "The access key is missing: pass it in the X-Bot-Key header.",
         "code": "missing_key"
        }
       },
       "invalidKey": {
        "summary": "Unknown or revoked key",
        "value": {
         "error": "The access key is invalid or revoked.",
         "code": "invalid_key"
        }
       }
      }
     }
    }
   },
   "Forbidden": {
    "description": "The key is valid but of the wrong type: you passed the publishable key (`pk_…`) from the widget snippet where a secret key (`sk_…`) is required. Get the secret key in the YouSelfBot dashboard and call the API from your backend. This is the most common mistake when getting started — and it's a `403`, not a `401`.",
    "content": {
     "application/json": {
      "schema": {
       "$ref": "#/components/schemas/Error"
      },
      "examples": {
       "wrongKeyType": {
        "value": {
         "error": "Wrong key type: secret key (sk_) is required here",
         "code": "wrong_key_type"
        }
       }
      }
     }
    }
   },
   "RateLimited": {
    "description": "Rate limit exceeded: 60/min for conversation and writes, 240/min for reads and signals (1-minute window, counted separately per key+IP pair). The same `RateLimit-Limit` / `RateLimit-Remaining` / `RateLimit-Reset` headers are also set on **successful** responses — watch them instead of waiting for a 429. Duplicates with the `X-` prefix are present for compatibility with older clients. Retry in a few seconds with exponential backoff.",
    "content": {
     "application/json": {
      "schema": {
       "$ref": "#/components/schemas/Error"
      },
      "examples": {
       "limited": {
        "value": {
         "error": "Too many requests. Try again in 20 s",
         "code": "rate_limited"
        }
       }
      }
     }
    },
    "headers": {
     "Retry-After": {
      "schema": {
       "type": "integer"
      },
      "description": "How many seconds to wait before retrying."
     },
     "RateLimit-Limit": {
      "schema": {
       "type": "integer"
      },
      "description": "How many requests are allowed in the window."
     },
     "RateLimit-Remaining": {
      "schema": {
       "type": "integer"
      },
      "description": "How many are left in the current window."
     },
     "RateLimit-Reset": {
      "schema": {
       "type": "integer"
      },
      "description": "In how many seconds the window resets."
     }
    }
   },
   "InternalError": {
    "description": "Internal server error. The request can be safely retried.",
    "content": {
     "application/json": {
      "schema": {
       "$ref": "#/components/schemas/Error"
      },
      "examples": {
       "default": {
        "value": {
         "error": "Something went wrong. Try again.",
         "code": "internal_error"
        }
       }
      }
     }
    }
   },
   "LLMUnavailable": {
    "description": "The AI backend is temporarily unavailable — the bot can't generate a reply. We've already been notified. Show the customer a friendly message and retry later. The body also includes `session_id`, so the conversation can continue with the same ID.",
    "content": {
     "application/json": {
      "schema": {
       "type": "object",
       "required": [
        "error",
        "code",
        "session_id"
       ],
       "properties": {
        "error": {
         "type": "string"
        },
        "code": {
         "type": "string",
         "const": "llm_unavailable"
        },
        "session_id": {
         "$ref": "#/components/schemas/SessionID"
        }
       }
      },
      "examples": {
       "unavailable": {
        "value": {
         "error": "The assistant is temporarily unavailable. We already know about it — please try again a little later.",
         "code": "llm_unavailable",
         "session_id": "3f6c1b9e-7f42-4d2a-9a6f-0d5b1f0b21c7"
        }
       }
      }
     }
    }
   },
   "PayloadTooLarge": {
    "description": "The request body is too large (1 MiB for most endpoints, 5 MiB for `POST /v1/api/knowledge`).",
    "content": {
     "application/json": {
      "schema": {
       "$ref": "#/components/schemas/Error"
      },
      "examples": {
       "default": {
        "value": {
         "error": "Request too large (at most 1,024 KiB)",
         "code": "payload_too_large"
        }
       }
      }
     }
    }
   },
   "IdempotencyConflict": {
    "description": "`Idempotency-Key` conflict: either a request with this key is still in progress (`idempotency_in_progress` — retry in a second), or this key was already used for a DIFFERENT request (`idempotency_key_reused` — use a new key).",
    "content": {
     "application/json": {
      "schema": {
       "$ref": "#/components/schemas/Error"
      },
      "examples": {
       "inProgress": {
        "value": {
         "error": "A request with this Idempotency-Key is still in progress — wait for the response.",
         "code": "idempotency_in_progress"
        }
       },
       "reused": {
        "value": {
         "error": "This Idempotency-Key has already been used for a different request.",
         "code": "idempotency_key_reused"
        }
       }
      }
     }
    }
   },
   "Unavailable": {
    "description": "The service couldn't PERFORM the check — storage is unavailable. This isn't an access denial: retry the request in a moment with the same key or session. Never show a sign-in screen in response to this — the session is alive, and you'd force the person who sees it to sign in to a service that isn't responding right now.",
    "content": {
     "application/json": {
      "schema": {
       "$ref": "#/components/schemas/Error"
      }
     }
    }
   }
  },
  "parameters": {
   "PageLimit": {
    "name": "limit",
    "in": "query",
    "required": false,
    "schema": {
     "type": "integer",
     "minimum": 1,
     "maximum": 200,
     "default": 50
    },
    "description": "How many items to return (1–200, default 50). More than 200 is capped at 200, with no error.",
    "example": 50
   },
   "PageCursor": {
    "name": "cursor",
    "in": "query",
    "required": false,
    "schema": {
     "type": "string"
    },
    "description": "An opaque cursor for the next page: pass `next_cursor` from the previous response. Empty/absent means the first page. Don't parse its contents: the format may change."
   },
   "IdempotencyKey": {
    "name": "Idempotency-Key",
    "in": "header",
    "required": false,
    "schema": {
     "type": "string",
     "maxLength": 255
    },
    "description": "A unique key for this request (for example a UUIDv4). A retry with the same key does NOT perform the action again — the saved response of the first attempt is returned with the `Idempotency-Replayed: true` header. Stored for 24 hours.",
    "example": "3f6c1b9e-7f42-4d2a-9a6f-0d5b1f0b21c7"
   }
  }
 },
 "webhooks": {
  "escalated": {
   "post": {
    "summary": "Conversation handed off to a live operator",
    "description": "The agent handed the conversation to a human: the visitor clicked \"Talk to a person\", or the agent decided on its own that a human should take over.\n\n`transcript` holds the recent conversation context so the operator doesn't start from scratch. From there, your backend replies via `POST /v1/api/operator/threads/{sid}/reply` and closes the request via `.../resolve`.\n\nTogether with the `visitor_message` and `resolved` events, this gives you the full cycle **without polling** `GET /v1/api/operator/threads`.\n\nVerify the signature before parsing the body (see \"Outgoing webhooks: verifying the signature\" in the introduction). Delivery is retried on `5xx` and network errors — the handler must be idempotent.",
    "operationId": "webhookEscalated",
    "security": [],
    "parameters": [
     {
      "name": "X-YouSelfBot-Timestamp",
      "in": "header",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Delivery time, Unix seconds. Part of the signed string."
     },
     {
      "name": "X-YouSelfBot-Signature",
      "in": "header",
      "required": true,
      "schema": {
       "type": "string",
       "examples": [
        "sha256=6f1c…"
       ]
      },
      "description": "`sha256=` + hex of `HMAC-SHA256(secret, \"<timestamp>.<raw body>\")`."
     },
     {
      "name": "User-Agent",
      "in": "header",
      "required": false,
      "schema": {
       "type": "string",
       "examples": [
        "YouSelfBot-Handoff/1.0"
       ]
      },
      "description": "Always `YouSelfBot-Handoff/1.0`."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/HandoffEvent"
       },
       "examples": {
        "default": {
         "value": {
          "event": "escalated",
          "bot_id": "bot_7f3a1c",
          "session_id": "3f6c1b9e-7f42-4d2a-9a6f-0d5b1f0b21c7",
          "transcript": "Customer: Order #4417 still hasn't arrived\nBot: According to the carrier, the parcel is on its way, expected tomorrow.\nCustomer: I was told that a week ago. Get me a person.",
          "at": 1753600000123
         }
        }
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Accepted. Any `2xx`/`3xx` counts as success and isn't retried."
     },
     "400": {
      "description": "Any `4xx` is a final rejection: we do NOT retry delivery. If you want a retry, respond with `5xx`."
     },
     "500": {
      "description": "Temporary failure. We'll retry delivery three times — after 1 s, 5 s and 25 s."
     }
    }
   }
  },
  "visitor_message": {
   "post": {
    "summary": "Visitor wrote in a handed-off conversation",
    "description": "A new visitor message in a conversation a human is already handling. The text is in `text`.\n\nThis event arrives only while the handoff lasts: once the request is closed (`resolved`), the agent replies again and there are no more events.\n\nVerify the signature before parsing the body (see \"Outgoing webhooks: verifying the signature\" in the introduction). Delivery is retried on `5xx` and network errors — the handler must be idempotent.",
    "operationId": "webhookVisitorMessage",
    "security": [],
    "parameters": [
     {
      "name": "X-YouSelfBot-Timestamp",
      "in": "header",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Delivery time, Unix seconds. Part of the signed string."
     },
     {
      "name": "X-YouSelfBot-Signature",
      "in": "header",
      "required": true,
      "schema": {
       "type": "string",
       "examples": [
        "sha256=6f1c…"
       ]
      },
      "description": "`sha256=` + hex of `HMAC-SHA256(secret, \"<timestamp>.<raw body>\")`."
     },
     {
      "name": "User-Agent",
      "in": "header",
      "required": false,
      "schema": {
       "type": "string",
       "examples": [
        "YouSelfBot-Handoff/1.0"
       ]
      },
      "description": "Always `YouSelfBot-Handoff/1.0`."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/HandoffEvent"
       },
       "examples": {
        "default": {
         "value": {
          "event": "visitor_message",
          "bot_id": "bot_7f3a1c",
          "session_id": "3f6c1b9e-7f42-4d2a-9a6f-0d5b1f0b21c7",
          "text": "Waybill number 59000123456789, please check",
          "at": 1753600041880
         }
        }
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Accepted. Any `2xx`/`3xx` counts as success and isn't retried."
     },
     "400": {
      "description": "Any `4xx` is a final rejection: we do NOT retry delivery. If you want a retry, respond with `5xx`."
     },
     "500": {
      "description": "Temporary failure. We'll retry delivery three times — after 1 s, 5 s and 25 s."
     }
    }
   }
  },
  "resolved": {
   "post": {
    "summary": "Request closed",
    "description": "The conversation was returned to the agent — the operator clicked \"Finish\" in the dashboard, or your backend called `POST /v1/api/operator/threads/{sid}/resolve`.\n\nThe event also arrives when you initiated the closing yourself: this keeps two operator systems (our dashboard and yours) in sync.\n\nVerify the signature before parsing the body (see \"Outgoing webhooks: verifying the signature\" in the introduction). Delivery is retried on `5xx` and network errors — the handler must be idempotent.",
    "operationId": "webhookResolved",
    "security": [],
    "parameters": [
     {
      "name": "X-YouSelfBot-Timestamp",
      "in": "header",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Delivery time, Unix seconds. Part of the signed string."
     },
     {
      "name": "X-YouSelfBot-Signature",
      "in": "header",
      "required": true,
      "schema": {
       "type": "string",
       "examples": [
        "sha256=6f1c…"
       ]
      },
      "description": "`sha256=` + hex of `HMAC-SHA256(secret, \"<timestamp>.<raw body>\")`."
     },
     {
      "name": "User-Agent",
      "in": "header",
      "required": false,
      "schema": {
       "type": "string",
       "examples": [
        "YouSelfBot-Handoff/1.0"
       ]
      },
      "description": "Always `YouSelfBot-Handoff/1.0`."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/HandoffEvent"
       },
       "examples": {
        "default": {
         "value": {
          "event": "resolved",
          "bot_id": "bot_7f3a1c",
          "session_id": "3f6c1b9e-7f42-4d2a-9a6f-0d5b1f0b21c7",
          "at": 1753600512004
         }
        }
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Accepted. Any `2xx`/`3xx` counts as success and isn't retried."
     },
     "400": {
      "description": "Any `4xx` is a final rejection: we do NOT retry delivery. If you want a retry, respond with `5xx`."
     },
     "500": {
      "description": "Temporary failure. We'll retry delivery three times — after 1 s, 5 s and 25 s."
     }
    }
   }
  }
 }
}
