openapi: 3.1.0
info:
  title: ButterIX 平台 API
  version: "1.0"
  description: |
    ButterIX 托管平台的 REST API：账户与组织、站点、部署、自定义域名、Git 集成、访问控制、Ask AI、分析与可视化编辑器。
    控制台与 `biti` CLI 都基于这套 API 构建。

    - 请求与响应均为 JSON（部署上传与文件上传除外）。
    - 时间戳是 Unix 毫秒数。
    - 错误统一返回 `{ "error": "人类可读的信息" }` 与对应的 HTTP 状态码。
    - 角色从高到低为 `owner > admin > editor > viewer`；组织 API Key 视为 `editor`。
  contact:
    name: ButterIX
    url: https://butterix.com

servers:
  - url: https://api.butterix.com/v1
    description: ButterIX 托管平台

security:
  - apiKey: []
  - session: []

tags:
  - name: Auth
    x-displayName: 认证与账户
    description: 注册、登录、当前用户，以及 API Key 身份查询。
  - name: Orgs
    x-displayName: 组织
    description: 组织是成员、站点与 API Key 的容器。每个用户注册时会自动获得一个个人组织。
  - name: Members
    x-displayName: 成员与邀请
    description: 管理组织成员与角色。邀请尚未注册的用户时会生成一次性邀请链接。
  - name: API Keys
    x-displayName: API Keys
    description: 组织级密钥，供 CLI 与 CI 使用（`Authorization Bearer biti_…`）。
  - name: Sites
    x-displayName: 站点
    description: 一个站点对应一个文档站，拥有自己的子域名、部署历史、域名与设置。
  - name: Deployments
    x-displayName: 部署
    description: 每次构建产生一个不可变的部署。生产部署可以随时切换（回滚）到任意成功的部署。
  - name: Domains
    x-displayName: 自定义域名
    description: 通过 TXT 记录验证所有权，再用 CNAME 把流量指向平台。
  - name: Git
    x-displayName: Git 集成
    description: 连接 GitHub 等 Git 仓库，推送自动部署、拉取请求自动生成预览。
  - name: AI
    x-displayName: Ask AI
    description: 站点 AI 问答的提供商、模型、密钥与指引，指定问答、内容来源与网页嵌入。
  - name: Analytics
    x-displayName: 分析
    description: 区分人类、AI 与爬虫的访问统计，AI 提问记录与页面反馈。
  - name: Automations
    x-displayName: 定时任务
    description: 按计划让 AI 检查文档与读者反馈并写出报告，需要时把修改放进草稿分支。
  - name: Editor
    x-displayName: 可视化编辑器
    description: 基于草稿分支的在线编辑：读写文件、实时渲染、校验、预览与发布。
  - name: Jobs
    x-displayName: 后台任务
    description: 耗时操作（如 AI 翻译）以后台任务运行，通过任务 id 查询进度。
  - name: Runtime
    x-displayName: 文档站运行时
    description: 每个托管文档站自带的动态端点，请求发往文档站自己的域名，无需认证。

paths:
  # ---------------------------------------------------------------- Auth
  /auth/signup:
    post:
      tags: [Auth]
      summary: 注册
      x-fern-sdk-method-name: signup
      description: 创建账户并自动登录（设置 `biti_session` Cookie），同时为新用户创建一个个人组织。平台关闭自助注册时返回 403；持有邀请链接的人仍然可以注册。
      security: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [name, email, password]
              properties:
                name: { type: string, description: 显示名称, example: 林晓 }
                email: { type: string, format: email, example: lin@example.com }
                password: { type: string, minLength: 8, description: 至少 8 个字符, example: correct-horse-battery }
      responses:
        "201":
          description: 注册成功
          content:
            application/json:
              schema:
                type: object
                properties:
                  user: { $ref: "#/components/schemas/User" }
        "400": { $ref: "#/components/responses/BadRequest" }
        "403": { $ref: "#/components/responses/Forbidden" }
        "409": { $ref: "#/components/responses/Conflict" }

  /auth/login:
    post:
      tags: [Auth]
      summary: 登录
      x-fern-sdk-method-name: login
      description: 用邮箱和密码登录，成功后设置 HttpOnly 会话 Cookie `biti_session`（有效期 30 天）。连续失败会被临时限流。
      security: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [email, password]
              properties:
                email: { type: string, format: email, example: lin@example.com }
                password: { type: string, example: correct-horse-battery }
      responses:
        "200":
          description: 登录成功
          headers:
            Set-Cookie:
              description: "`biti_session=…; HttpOnly; SameSite=Lax; Path=/`"
              schema: { type: string }
          content:
            application/json:
              schema:
                type: object
                properties:
                  user: { $ref: "#/components/schemas/User" }
        "401": { $ref: "#/components/responses/Unauthorized" }

  /auth/logout:
    post:
      tags: [Auth]
      summary: 退出登录
      x-fern-sdk-method-name: logout
      description: 销毁当前会话并清除 Cookie。
      security:
        - session: []
      responses:
        "200": { $ref: "#/components/responses/Ok" }

  /me:
    get:
      tags: [Auth]
      summary: 获取当前用户
      x-fern-sdk-method-name: get-me
      description: 返回当前登录用户及其所属的全部组织（含该用户在每个组织中的角色）。仅支持会话认证。
      security:
        - session: []
      responses:
        "200":
          description: 当前用户
          content:
            application/json:
              schema:
                type: object
                properties:
                  user: { $ref: "#/components/schemas/User" }
                  orgs:
                    type: array
                    items: { $ref: "#/components/schemas/Org" }
        "401": { $ref: "#/components/responses/Unauthorized" }
    patch:
      tags: [Auth]
      summary: 更新当前用户
      x-fern-sdk-method-name: update-me
      description: 修改显示名称或密码。修改密码时必须提供当前密码。
      security:
        - session: []
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                name: { type: string, example: 林晓 }
                currentPassword: { type: string }
                newPassword: { type: string, minLength: 8 }
      responses:
        "200":
          description: 更新后的用户
          content:
            application/json:
              schema:
                type: object
                properties:
                  user: { $ref: "#/components/schemas/User" }
        "400": { $ref: "#/components/responses/BadRequest" }

  /whoami:
    get:
      tags: [Auth]
      summary: 查询 API Key 所属组织
      x-fern-sdk-method-name: whoami
      description: 用 API Key 调用，返回该密钥所属的组织。`biti login` 用它校验密钥。
      security:
        - apiKey: []
      x-codeSamples:
        - lang: console
          label: biti CLI
          source: |
            $ biti login --token "$BITI_TOKEN"
      responses:
        "200":
          description: 所属组织
          content:
            application/json:
              schema:
                type: object
                properties:
                  org:
                    type: object
                    properties:
                      id: { type: string, example: org_8f2k1c }
                      slug: { type: string, example: acme }
                      name: { type: string, example: Acme }
        "401": { $ref: "#/components/responses/Unauthorized" }

  # ---------------------------------------------------------------- Orgs
  /orgs:
    post:
      tags: [Orgs]
      summary: 创建组织
      x-fern-sdk-method-name: create-org
      description: 创建一个新组织，调用者成为 `owner`。
      security:
        - session: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [name]
              properties:
                name: { type: string, example: Acme }
                slug: { type: string, description: 组织标识，默认由名称生成，创建后不可修改, example: acme }
      responses:
        "201":
          description: 新组织
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Org" }
        "409": { $ref: "#/components/responses/Conflict" }

  /orgs/{org}:
    parameters:
      - $ref: "#/components/parameters/Org"
    get:
      tags: [Orgs]
      summary: 获取组织
      x-fern-sdk-method-name: get-org
      responses:
        "200":
          description: 组织
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Org" }
        "404": { $ref: "#/components/responses/NotFound" }
    patch:
      tags: [Orgs]
      summary: 重命名组织
      x-fern-sdk-method-name: update-org
      description: 需要 `admin` 角色。
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                name: { type: string, example: Acme 中国 }
      responses:
        "200":
          description: 更新后的组织
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Org" }
        "403": { $ref: "#/components/responses/Forbidden" }

  /orgs/{org}/audit:
    parameters:
      - $ref: "#/components/parameters/Org"
    get:
      tags: [Orgs]
      summary: 审计日志
      x-fern-sdk-method-name: list-audit-log
      description: 最近 200 条重要操作（站点创建与删除、部署切换、域名、成员、密钥、Ask AI 设置等）。需要 `admin` 角色。
      responses:
        "200":
          description: 审计记录，按时间倒序
          content:
            application/json:
              schema:
                type: array
                items: { $ref: "#/components/schemas/AuditEntry" }

  # ---------------------------------------------------------------- Members
  /orgs/{org}/members:
    parameters:
      - $ref: "#/components/parameters/Org"
    get:
      tags: [Members]
      summary: 列出成员与邀请
      x-fern-sdk-method-name: list-members
      responses:
        "200":
          description: 成员与待接受的邀请
          content:
            application/json:
              schema:
                type: object
                properties:
                  members:
                    type: array
                    items: { $ref: "#/components/schemas/Member" }
                  invites:
                    type: array
                    items: { $ref: "#/components/schemas/Invite" }
    post:
      tags: [Members]
      summary: 添加或邀请成员
      x-fern-sdk-method-name: add-member
      description: |
        需要 `admin` 角色。邮箱已注册时直接加入组织，返回 `{ "added": true }`；
        否则生成一次性邀请链接，返回 `{ "invite": { "url" } }`，由你发给对方。
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [email]
              properties:
                email: { type: string, format: email, example: chen@example.com }
                role: { $ref: "#/components/schemas/Role" }
            example:
              email: chen@example.com
              role: editor
      responses:
        "201":
          description: 已加入或已生成邀请
          content:
            application/json:
              schema:
                oneOf:
                  - type: object
                    title: 已加入
                    properties:
                      added: { type: boolean, const: true }
                  - type: object
                    title: 已邀请
                    properties:
                      invite:
                        type: object
                        properties:
                          url: { type: string, format: uri }
              examples:
                invited:
                  summary: 生成邀请链接
                  value:
                    invite:
                      url: https://console.butterix.com/invite/q8Zt3vXc2bN0LmA4pR7sKd1e
                added:
                  summary: 直接加入
                  value:
                    added: true
        "409": { $ref: "#/components/responses/Conflict" }

  /orgs/{org}/members/{userId}:
    parameters:
      - $ref: "#/components/parameters/Org"
      - name: userId
        in: path
        required: true
        schema: { type: string, example: usr_3k9d2a }
    patch:
      tags: [Members]
      summary: 修改成员角色
      x-fern-sdk-method-name: update-member-role
      description: 需要 `admin` 角色。组织至少要保留一个 `owner`。
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [role]
              properties:
                role: { $ref: "#/components/schemas/Role" }
      responses:
        "200": { $ref: "#/components/responses/Ok" }
        "400": { $ref: "#/components/responses/BadRequest" }
    delete:
      tags: [Members]
      summary: 移除成员
      x-fern-sdk-method-name: remove-member
      description: 需要 `admin` 角色。不能移除最后一个 `owner`。
      responses:
        "200": { $ref: "#/components/responses/Ok" }
        "400": { $ref: "#/components/responses/BadRequest" }

  /orgs/{org}/invites/{inviteId}:
    parameters:
      - $ref: "#/components/parameters/Org"
      - name: inviteId
        in: path
        required: true
        schema: { type: string, example: inv_7cd2e1 }
    delete:
      tags: [Members]
      summary: 撤销邀请
      x-fern-sdk-method-name: revoke-invite
      responses:
        "200": { $ref: "#/components/responses/Ok" }

  /invites/{token}/accept:
    parameters:
      - name: token
        in: path
        required: true
        description: 邀请链接中的令牌
        schema: { type: string }
    post:
      tags: [Members]
      summary: 接受邀请
      x-fern-sdk-method-name: accept-invite
      description: 已登录用户接受邀请并以邀请时指定的角色加入组织。每个邀请只能使用一次。
      security:
        - session: []
      responses:
        "200":
          description: 加入的组织
          content:
            application/json:
              schema:
                type: object
                properties:
                  org: { $ref: "#/components/schemas/Org" }
        "404": { $ref: "#/components/responses/NotFound" }

  # ---------------------------------------------------------------- API keys
  /orgs/{org}/api-keys:
    parameters:
      - $ref: "#/components/parameters/Org"
    get:
      tags: [API Keys]
      summary: 列出 API Key
      x-fern-sdk-method-name: list-api-keys
      description: 需要 `admin` 角色（因此只能用会话认证调用）。只返回密钥的开头和末尾，不返回完整密钥。
      security:
        - session: []
      responses:
        "200":
          description: 密钥列表
          content:
            application/json:
              schema:
                type: array
                items: { $ref: "#/components/schemas/ApiKey" }
    post:
      tags: [API Keys]
      summary: 创建 API Key
      x-fern-sdk-method-name: create-api-key
      description: 需要 `admin` 角色。完整的 `token` **只在这次响应中返回一次**，请立即保存。
      security:
        - session: []
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                name: { type: string, example: GitHub Actions }
      responses:
        "201":
          description: 新密钥
          content:
            application/json:
              schema:
                type: object
                properties:
                  id: { type: string, example: key_5h2m8q }
                  token: { type: string, example: biti_Q2xhdWRlIGlzIGF3ZXNvbWUh9x }

  /orgs/{org}/api-keys/{keyId}:
    parameters:
      - $ref: "#/components/parameters/Org"
      - name: keyId
        in: path
        required: true
        schema: { type: string, example: key_5h2m8q }
    delete:
      tags: [API Keys]
      summary: 删除 API Key
      x-fern-sdk-method-name: delete-api-key
      description: 使用该密钥的 CLI 与 CI 立即失效。
      security:
        - session: []
      responses:
        "200": { $ref: "#/components/responses/Ok" }

  # ---------------------------------------------------------------- Sites
  /orgs/{org}/sites:
    parameters:
      - $ref: "#/components/parameters/Org"
    get:
      tags: [Sites]
      summary: 列出站点
      x-fern-sdk-method-name: list-sites
      responses:
        "200":
          description: 组织下的站点，按创建时间倒序
          content:
            application/json:
              schema:
                type: array
                items: { $ref: "#/components/schemas/SiteSummary" }
    post:
      tags: [Sites]
      summary: 创建站点
      x-fern-sdk-method-name: create-site
      description: |
        需要 `admin` 角色。平台会为站点创建托管 Git 仓库、写入模板内容并立即开始首次生产部署。

        - `starter`：简介、快速开始、写作指南三页。
        - `blank`：只有一个首页。
        - `openapi`：根据 `openapiText` 生成 API 参考，必须同时提供规范内容。

        `slug` 是站点子域名：5–40 个小写字母、数字或单个连字符，首尾不能是连字符，不能包含 `--`（预览地址使用 `--` 分隔），部分保留字（如 `console`、`managements`、`butterix`）不可用。站点地址为 `https://<slug>-sites.butterix.com`。
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [name]
              properties:
                name: { type: string, example: Acme 文档 }
                slug: { type: string, example: acme-payments, description: 默认由名称生成 }
                template:
                  type: string
                  enum: [starter, blank, openapi]
                  default: starter
                openapiText:
                  type: string
                  description: "`template` 为 `openapi` 时必填：OpenAPI 3.x 的 YAML 或 JSON 文本"
            examples:
              starter:
                summary: 入门模板
                value:
                  name: Acme 文档
                  slug: acme-payments
                  template: starter
              openapi:
                summary: 从 OpenAPI 生成
                value:
                  name: Acme API
                  slug: acme-api
                  template: openapi
                  openapiText: "openapi: 3.1.0\ninfo:\n  title: Acme API\n  version: '1'\npaths: {}\n"
      responses:
        "201":
          description: 新站点
          content:
            application/json:
              schema: { $ref: "#/components/schemas/SiteDetail" }
        "400": { $ref: "#/components/responses/BadRequest" }
        "409": { $ref: "#/components/responses/Conflict" }

  /sites/{site}:
    parameters:
      - $ref: "#/components/parameters/Site"
    get:
      tags: [Sites]
      summary: 获取站点
      x-fern-sdk-method-name: get-site
      responses:
        "200":
          description: 站点详情
          content:
            application/json:
              schema: { $ref: "#/components/schemas/SiteDetail" }
        "404": { $ref: "#/components/responses/NotFound" }
    patch:
      tags: [Sites]
      summary: 重命名站点
      x-fern-sdk-method-name: update-site
      description: 需要 `admin` 角色。子域名（slug）创建后不可修改。
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                name: { type: string, example: Acme 开发者文档 }
      responses:
        "200":
          description: 站点详情
          content:
            application/json:
              schema: { $ref: "#/components/schemas/SiteDetail" }
    delete:
      tags: [Sites]
      summary: 删除站点
      x-fern-sdk-method-name: delete-site
      description: 需要 `admin` 角色。永久删除站点、所有部署文件、托管仓库、域名映射与分析数据，**无法撤销**。
      responses:
        "200": { $ref: "#/components/responses/Ok" }

  /sites/{site}/access:
    parameters:
      - $ref: "#/components/parameters/Site"
    put:
      tags: [Sites]
      summary: 设置访问控制
      x-fern-sdk-method-name: update-access
      description: |
        需要 `admin` 角色。`password` 模式下访客首次访问会看到密码页，验证通过后获得 30 天有效的访问 Cookie。
        已设置过密码时，切换到 `password` 模式可以不传 `password`（沿用原密码）。修改密码会使所有访客的登录与 MCP 登录失效，访问令牌不受影响。
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [mode]
              properties:
                mode: { type: string, enum: [public, password] }
                password: { type: string, minLength: 6 }
            example:
              mode: password
              password: preview-2026
      responses:
        "200":
          description: 当前模式
          content:
            application/json:
              schema:
                type: object
                properties:
                  mode: { type: string, enum: [public, password] }
        "400": { $ref: "#/components/responses/BadRequest" }

  /sites/{site}/access-tokens:
    parameters:
      - $ref: "#/components/parameters/Site"
    get:
      tags: [Sites]
      summary: 列出访问令牌
      x-fern-sdk-method-name: list-access-tokens
      description: 需要 `admin` 角色。包含访问令牌与仍然有效的 MCP 登录，不返回令牌本身。
      responses:
        "200":
          description: 访问令牌
          content:
            application/json:
              schema:
                type: array
                items: { $ref: "#/components/schemas/AccessToken" }
    post:
      tags: [Sites]
      summary: 创建访问令牌
      x-fern-sdk-method-name: create-access-token
      description: 需要 `admin` 角色。用于以 `Authorization Bearer` 访问受密码保护站点的页面、`.md`、`llms.txt` 与 MCP 服务器。令牌只在创建时返回一次，每个站点最多 50 个。
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [name]
              properties:
                name: { type: string, maxLength: 100, example: 内部助手 }
                expiresInDays:
                  type: [integer, "null"]
                  minimum: 1
                  maximum: 3650
                  description: 有效天数；不传或 `null` 表示一直有效
      responses:
        "201":
          description: 新令牌
          content:
            application/json:
              schema:
                type: object
                properties:
                  id: { type: string, example: tok_01jd8x2k7q }
                  token: { type: string, example: bxt_xxxxxxxxxxxxxxxx, description: 完整令牌，只返回这一次 }
        "400": { $ref: "#/components/responses/BadRequest" }

  /sites/{site}/access-tokens/{id}:
    parameters:
      - $ref: "#/components/parameters/Site"
      - name: id
        in: path
        required: true
        description: 令牌 id
        schema: { type: string, example: tok_01jd8x2k7q }
    delete:
      tags: [Sites]
      summary: 吊销访问令牌
      x-fern-sdk-method-name: revoke-access-token
      description: 需要 `admin` 角色。
      responses:
        "200": { $ref: "#/components/responses/Ok" }
        "404": { $ref: "#/components/responses/NotFound" }

  /sites/{site}/redirects:
    parameters:
      - $ref: "#/components/parameters/Site"
    get:
      tags: [Sites]
      summary: 404 推荐重定向
      x-fern-sdk-method-name: list-redirects
      description: 最近 30 天读者访问过、但不存在的地址与推荐的页面，可以合并的整段搬家，以及已经加上的重定向。
      responses:
        "200":
          description: 推荐与已加上的重定向
          content:
            application/json:
              schema:
                type: object
                properties:
                  suggestions:
                    type: array
                    items:
                      type: object
                      properties:
                        path: { type: string, example: /gide }
                        count: { type: integer, example: 12 }
                        last: { type: integer, format: int64 }
                        target: { type: object, description: 地址最像的页面；没有把握时不给, properties: { path: { type: string, example: /guide }, title: { type: string }, score: { type: number } } }
                  groups:
                    type: array
                    items: { type: object, properties: { from: { type: string, example: /docs/old/* }, to: { type: string, example: "/docs/new/:splat" }, paths: { type: array, items: { type: string } }, count: { type: integer } } }
                  rules:
                    type: array
                    items: { type: object, properties: { from: { type: string }, to: { type: string }, status: { type: integer, enum: [301, 302] }, at: { type: integer, format: int64 }, active: { type: boolean, description: 原地址有了页面时为 false，不再跳转 } } }
    post:
      tags: [Sites]
      summary: 加上重定向
      x-fern-sdk-method-name: add-redirect
      description: 需要 `editor` 角色。立即生效，不用重新部署；只在原地址没有页面时跳转。来源以 `/` 开头，可以以 `/*` 结尾；目标必须是站内地址，可以用 `:splat`。最多 200 条。
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [from, to]
              properties:
                from: { type: string, example: /docs/old/* }
                to: { type: string, example: "/docs/new/:splat" }
                status: { type: integer, enum: [301, 302], default: 301 }
      responses:
        "201":
          description: 现在的全部重定向
    delete:
      tags: [Sites]
      summary: 去掉重定向
      x-fern-sdk-method-name: remove-redirect
      description: 需要 `editor` 角色。
      parameters:
        - name: from
          in: query
          required: true
          schema: { type: string, example: /gide }
      responses:
        "200":
          description: 现在的全部重定向

  /sites/{site}/export:
    parameters:
      - $ref: "#/components/parameters/Site"
    get:
      tags: [Sites]
      summary: 可导出的内容
      x-fern-sdk-method-name: list-exports
      description: 线上版本的语言、版本、标签页与分组，以及各有多少页。还没有可导出的内容时 `outline` 为 `null`。
      responses:
        "200":
          description: 可导出的内容
          content:
            application/json:
              schema:
                type: object
                properties:
                  outline:
                    type: [object, "null"]
                    properties:
                      title: { type: string, example: Acme }
                      variants:
                        type: array
                        items:
                          type: object
                          properties:
                            key: { type: string, example: "zh||v1" }
                            locale: { type: string, example: zh }
                            version: { type: string, example: v1 }
                            product: { type: string }
                            default: { type: boolean }
                            pages: { type: integer, example: 194 }
                            tabs:
                              type: array
                              items:
                                type: object
                                properties:
                                  id: { type: string, example: guides }
                                  title: { type: string, example: 指南 }
                                  pages: { type: integer, example: 44 }
                                  sections: { type: array, items: { type: object } }

  /sites/{site}/export/markdown:
    parameters:
      - $ref: "#/components/parameters/Site"
    get:
      tags: [Sites]
      summary: 导出 Markdown
      x-fern-sdk-method-name: export-markdown
      description: 线上版本的 Markdown 压缩包：每页一个文件，带图片（合计 50 MB 以内，超出的保留线上地址），页面之间是相对链接。每个成员同时导出一个，十分钟内最多 10 次，整个组织最多 30 次。下载太慢会断开。
      parameters:
        - name: variant
          in: query
          description: 语言与版本，取自可导出的内容里的 `key`，省略时用默认语言与默认版本
          schema: { type: string }
        - name: part
          in: query
          description: 标签页或分组的 `id`，省略时导出全部
          schema: { type: string }
      responses:
        "200":
          description: 压缩包
          content:
            application/zip:
              schema: { type: string, format: binary }

  # ---------------------------------------------------------------- Deployments
  /sites/{site}/deployments:
    parameters:
      - $ref: "#/components/parameters/Site"
    get:
      tags: [Deployments]
      summary: 列出部署
      x-fern-sdk-method-name: list-deployments
      parameters:
        - name: limit
          in: query
          description: 返回条数，最大 200
          schema: { type: integer, default: 50, maximum: 200 }
      responses:
        "200":
          description: 部署列表，按创建时间倒序
          content:
            application/json:
              schema:
                type: array
                items: { $ref: "#/components/schemas/Deployment" }
    post:
      tags: [Deployments]
      summary: 创建部署
      x-fern-sdk-method-name: create-deployment
      description: |
        需要 `editor` 角色。两种用法：

        1. **上传源码**（`biti deploy` 使用）：请求体是项目目录的 gzip tar 包（`Content-Type: application/gzip`，最大 200 MB）。
           请求头 `x-biti-preview: 1` 创建预览部署，`x-biti-message` 是 URL 编码的部署说明。
        2. **从仓库重新构建**：JSON `{ preview?, branch? }`，从托管仓库或已连接的 Git 仓库构建。通过 CLI 上传过的站点不支持这种方式。

        返回 202 与部署 id，用[获取部署](/api-reference/deployments/get-deployment)轮询状态。
      parameters:
        - name: x-biti-preview
          in: header
          description: 上传源码时：`1` 表示预览部署
          schema: { type: string, enum: ["0", "1"] }
        - name: x-biti-message
          in: header
          description: 上传源码时：URL 编码的部署说明
          schema: { type: string, example: "Release%20v1.2" }
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                preview: { type: boolean, default: false, description: 创建预览部署而不是生产部署 }
                branch: { type: string, description: 构建的分支，默认是站点的生产分支, example: main }
            example:
              preview: true
              branch: docs/new-quickstart
          application/gzip:
            schema:
              type: string
              format: binary
              description: 项目目录的 tar.gz（不含 node_modules、.git、.biti、dist）
      x-codeSamples:
        - lang: console
          label: biti CLI
          source: |
            $ biti deploy --site acme-payments --message "Release v1.2"
        - lang: shell
          label: cURL（上传 tar.gz）
          source: |
            tar --exclude=node_modules --exclude=.git --exclude=dist -czf site.tgz .
            curl -X POST https://api.butterix.com/v1/sites/acme-payments/deployments \
              -H "Authorization: Bearer $BITI_TOKEN" \
              -H "Content-Type: application/gzip" \
              -H "x-biti-preview: 1" \
              --data-binary @site.tgz
      responses:
        "202":
          description: 已排队
          content:
            application/json:
              schema:
                type: object
                properties:
                  id: { type: string, example: dpl_01jd8x2k7q }
        "400": { $ref: "#/components/responses/BadRequest" }
        "413":
          description: 上传超过 200 MB
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }

  /deployments/{id}:
    parameters:
      - $ref: "#/components/parameters/DeploymentId"
    get:
      tags: [Deployments]
      summary: 获取部署
      x-fern-sdk-method-name: get-deployment
      description: 部署详情与构建日志。构建进行中时 `log` 是实时日志。
      responses:
        "200":
          description: 部署
          content:
            application/json:
              schema:
                allOf:
                  - $ref: "#/components/schemas/Deployment"
                  - type: object
                    properties:
                      log: { type: string, description: 构建日志 }
        "404": { $ref: "#/components/responses/NotFound" }

  /deployments/{id}/promote:
    parameters:
      - $ref: "#/components/parameters/DeploymentId"
    post:
      tags: [Deployments]
      summary: 设为生产（回滚）
      x-fern-sdk-method-name: promote-deployment
      description: 需要 `editor` 角色。把任意一个状态为 `ready` 的部署（包括预览部署和更早的生产部署）设为生产。只是切换指针，即时生效，不会重新构建。
      responses:
        "200":
          description: 新的生产部署
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Deployment" }
        "400": { $ref: "#/components/responses/BadRequest" }

  /deployments/{id}/cancel:
    parameters:
      - $ref: "#/components/parameters/DeploymentId"
    post:
      tags: [Deployments]
      summary: 取消部署
      x-fern-sdk-method-name: cancel-deployment
      description: 只能取消仍在排队（`queued`）的部署。
      responses:
        "200": { $ref: "#/components/responses/Ok" }
        "400": { $ref: "#/components/responses/BadRequest" }

  # ---------------------------------------------------------------- Domains
  /sites/{site}/domains:
    parameters:
      - $ref: "#/components/parameters/Site"
    get:
      tags: [Domains]
      summary: 列出域名
      x-fern-sdk-method-name: list-domains
      responses:
        "200":
          description: 域名列表
          content:
            application/json:
              schema:
                type: array
                items: { $ref: "#/components/schemas/Domain" }
    post:
      tags: [Domains]
      summary: 添加域名
      x-fern-sdk-method-name: add-domain
      description: 需要 `admin` 角色。返回需要配置的 TXT 验证记录与 CNAME 目标。一个域名只能连接到一个站点。
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [domain]
              properties:
                domain: { type: string, example: docs.acme.com }
      responses:
        "201":
          description: 新域名（未验证）
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Domain" }
        "400": { $ref: "#/components/responses/BadRequest" }
        "409": { $ref: "#/components/responses/Conflict" }

  /sites/{site}/domains/{domain}/verify:
    parameters:
      - $ref: "#/components/parameters/Site"
      - $ref: "#/components/parameters/Domain"
    post:
      tags: [Domains]
      summary: 验证域名
      x-fern-sdk-method-name: verify-domain
      description: 查询 `_butterix.<domain>` 的 TXT 记录，匹配后标记为已验证，域名立即开始指向站点，平台随后自动通过 Let's Encrypt 签发 HTTPS 证书。
      responses:
        "200":
          description: 验证结果
          content:
            application/json:
              schema:
                allOf:
                  - $ref: "#/components/schemas/Domain"
                  - type: object
                    properties:
                      checked: { type: boolean, const: true }

  /sites/{site}/domains/{domain}/primary:
    parameters:
      - $ref: "#/components/parameters/Site"
      - $ref: "#/components/parameters/Domain"
    post:
      tags: [Domains]
      summary: 设为主域名
      x-fern-sdk-method-name: set-primary-domain
      description: 需要 `admin` 角色。canonical、站点地图、`llms.txt` 与 `.md` 里的绝对地址改用这个域名，并自动重新部署线上的版本。域名需要已验证，且 HTTPS 证书已生效。
      responses:
        "200":
          description: 主域名
          content:
            application/json:
              schema:
                allOf:
                  - $ref: "#/components/schemas/Domain"
                  - type: object
                    properties:
                      deployment: { type: string, description: 因此开始的部署；不需要或无法重新部署时没有 }
        "400": { $ref: "#/components/responses/BadRequest" }

  /sites/{site}/domains/{domain}:
    parameters:
      - $ref: "#/components/parameters/Site"
      - $ref: "#/components/parameters/Domain"
    delete:
      tags: [Domains]
      summary: 移除域名
      x-fern-sdk-method-name: remove-domain
      responses:
        "200": { $ref: "#/components/responses/Ok" }

  # ---------------------------------------------------------------- Git
  /sites/{site}/git:
    parameters:
      - $ref: "#/components/parameters/Site"
    put:
      tags: [Git]
      summary: 连接 Git 仓库
      x-fern-sdk-method-name: connect-git
      description: |
        需要 `admin` 角色。用远程仓库替换托管仓库，立即拉取并开始一次生产部署。
        私有仓库需要提供具有读取权限的访问令牌（加密存储）；使用可视化编辑器发布时还需要写权限。
        连接后请在仓库中配置 Webhook（地址与密钥见响应中的 `git`）。
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [url]
              properties:
                url: { type: string, description: https 地址, example: https://github.com/acme/docs.git }
                branch: { type: string, default: main }
                token: { type: string, description: 访问令牌；留空时保留已有令牌 }
      responses:
        "200":
          description: 站点详情
          content:
            application/json:
              schema: { $ref: "#/components/schemas/SiteDetail" }
        "400": { $ref: "#/components/responses/BadRequest" }
    delete:
      tags: [Git]
      summary: 断开 Git 仓库
      x-fern-sdk-method-name: disconnect-git
      description: 回到 ButterIX 托管仓库，之后的推送不再触发部署。
      responses:
        "200":
          description: 站点详情
          content:
            application/json:
              schema: { $ref: "#/components/schemas/SiteDetail" }

  /webhooks/github/{siteId}:
    parameters:
      - name: siteId
        in: path
        required: true
        description: 站点 id（不是 slug）
        schema: { type: string, example: site_2m4k8p }
    post:
      tags: [Git]
      summary: 接收 GitHub Webhook
      x-fern-sdk-method-name: github-webhook
      description: |
        由 GitHub（或兼容的 Git 服务）调用，无需 API 认证，但必须带正确的 `X-Hub-Signature-256` 签名（HMAC-SHA256，密钥为站点的 webhook secret）。

        - `push` 到生产分支 → 生产部署。
        - `pull_request` 的 `opened` / `synchronize` / `reopened` → 该分支的预览部署。
        - `ping` → `{ ok: true }`；其他事件 → `{ ignored: true }`。
      security: []
      parameters:
        - name: X-GitHub-Event
          in: header
          required: true
          schema: { type: string, enum: [push, pull_request, ping] }
        - name: X-Hub-Signature-256
          in: header
          required: true
          schema: { type: string, example: sha256=4f1c… }
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              description: GitHub 事件负载（只读取以下字段）
              properties:
                ref: { type: string, example: refs/heads/main }
                after: { type: string, example: 9fceb02d0ae598e95dc970b74767f19372d61af8 }
                head_commit:
                  type: object
                  properties:
                    message: { type: string, example: "docs: 更新快速开始" }
                action: { type: string, example: opened }
                pull_request:
                  type: object
                  properties:
                    number: { type: integer, example: 42 }
                    title: { type: string, example: 新增 Webhook 指南 }
                    head:
                      type: object
                      properties:
                        ref: { type: string, example: docs/webhooks }
                        sha: { type: string }
      responses:
        "202":
          description: 已创建部署
          content:
            application/json:
              schema:
                type: object
                properties:
                  deploymentId: { type: string, example: dpl_01jd8x2k7q }
        "200":
          description: ping 或被忽略的事件
          content:
            application/json:
              schema:
                type: object
                properties:
                  ok: { type: boolean }
                  ignored: { type: boolean }
        "401":
          description: 签名错误
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }

  # ---------------------------------------------------------------- AI
  /sites/{site}/ai:
    parameters:
      - $ref: "#/components/parameters/Site"
    get:
      tags: [AI]
      summary: 获取 Ask AI 设置
      x-fern-sdk-method-name: get-ai-settings
      responses:
        "200":
          description: 当前设置（密钥只返回掩码）
          content:
            application/json:
              schema: { $ref: "#/components/schemas/AiSettings" }
    put:
      tags: [AI]
      summary: 更新 Ask AI 设置
      x-fern-sdk-method-name: update-ai-settings
      description: |
        需要 `admin` 角色。只更新传入的字段。

        - 切换 `provider` 且未传 `model` 时，模型重置为该提供商的默认模型；未传 `apiKey` 时清除原密钥（密钥与提供商绑定）。
        - `apiKey: null` 清除站点密钥，回退到平台密钥（如有）。密钥以 AES-256-GCM 加密存储。
        - `effort` 的可选档位由模型决定（见 [模型列表](/api-reference/ai/list-models) 里的 `reasoning`）；不支持的档位使用时换成最接近的一档，`null` 表示使用模型的建议档位。
        - `dailyLimit` 是滚动 24 小时内调用模型的提问上限（1–1000000），`null` 表示不限；未设置时默认 200。
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                enabled: { type: boolean }
                provider: { $ref: "#/components/schemas/Provider" }
                model: { type: string, example: claude-opus-5-5 }
                apiKey:
                  type: [string, "null"]
                  description: 新密钥；`null` 表示清除
                guidance: { type: string, maxLength: 4000, description: 附加到系统提示的指引 }
                effort: { type: [string, "null"], enum: [none, minimal, low, medium, high, xhigh, max, null], description: 推理强度；`null` 表示使用模型的建议档位 }
                dailyLimit:
                  type: [integer, "null"]
                  minimum: 1
                  maximum: 1000000
                  description: 滚动 24 小时内调用模型的提问上限；`null` 表示不限
                agent: { type: boolean, description: 控制台 AI（Agent、定时任务、AI 翻译、文档缺口）的开关，与 Ask AI 互不影响 }
                gaps: { type: boolean, description: 每天自动整理文档缺口 }
                support:
                  type: object
                  description: 答不上时转人工。只更新传入的字段；开启时至少要有一种联系方式
                  properties:
                    enabled: { type: boolean, example: true }
                    url: { type: string, example: "https://acme.com/support", description: 支持页面：`https://` 地址或 `/` 开头的站内路径；空串表示清除 }
                    email: { type: string, example: support@acme.com, description: 支持邮箱；空串表示清除 }
            examples:
              deepseek:
                summary: 切换到 DeepSeek
                value:
                  provider: deepseek
                  model: deepseek-flash
                  apiKey: sk-xxxxxxxxxxxxxxxx
              guidance:
                summary: 只修改指引
                value:
                  guidance: 回答时优先给出 TypeScript 示例；不要讨论定价。
      responses:
        "200":
          description: 更新后的设置
          content:
            application/json:
              schema: { $ref: "#/components/schemas/AiSettings" }

  /sites/{site}/ai/test:
    parameters:
      - $ref: "#/components/parameters/Site"
    post:
      tags: [AI]
      summary: 测试提问
      x-fern-sdk-method-name: test-ai
      description: 需要 `editor` 角色。用当前保存的设置和生产部署的检索索引回答一个问题（非流式）。
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                question: { type: string, maxLength: 2000, example: 如何创建 API Key？ }
      responses:
        "200":
          description: 回答
          content:
            application/json:
              schema:
                type: object
                properties:
                  answer: { type: string, example: "在控制台的「组织设置 → API Keys」中创建密钥 [1]。" }
                  sources:
                    type: array
                    items:
                      type: object
                      properties:
                        title: { type: string, example: CLI 部署与 API Key }
                        url: { type: string, example: /guides/deploy/cli-deploy }
                  model: { type: string, example: claude-opus-5-5 }
                  provider: { $ref: "#/components/schemas/Provider" }
                  ms: { type: integer, example: 2380 }
        "400": { $ref: "#/components/responses/BadRequest" }
        "502":
          description: 模型提供商返回错误
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }

  /ai/models:
    get:
      tags: [AI]
      summary: 列出可用模型
      x-fern-sdk-method-name: list-models
      description: |
        实时从提供商拉取模型列表（缓存 10 分钟）。传 `site` 时优先使用该站点的密钥，否则使用平台密钥。
        无法拉取时返回内置列表，并设置 `live: false` 与 `error`。
      parameters:
        - name: provider
          in: query
          schema: { $ref: "#/components/schemas/Provider" }
        - name: site
          in: query
          description: 站点 slug 或 id
          schema: { type: string, example: acme-payments }
      responses:
        "200":
          description: 模型列表（推荐模型排在最前）
          content:
            application/json:
              schema:
                type: object
                properties:
                  models:
                    type: array
                    items: { $ref: "#/components/schemas/ModelInfo" }
                  live: { type: boolean }
                  error: { type: string }

  /sites/{site}/guidance:
    parameters:
      - $ref: "#/components/parameters/Site"
    get:
      tags: [AI]
      summary: 列出指定问答
      x-fern-sdk-method-name: list-guidance
      responses:
        "200":
          description: 指定问答，按创建时间倒序
          content:
            application/json:
              schema:
                type: array
                items: { $ref: "#/components/schemas/Guidance" }
    post:
      tags: [AI]
      summary: 创建指定问答
      x-fern-sdk-method-name: create-guidance
      description: 需要 `editor` 角色。读者的问题与任一示例问题相近时，Ask AI 优先按 `document` 回答。每个站点最多 200 条。
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [context, document]
              properties:
                context: { type: array, minItems: 1, maxItems: 20, items: { type: string, maxLength: 500 }, description: 示例问题 }
                document: { type: string, maxLength: 8000, description: 答案（Markdown） }
                enabled: { type: boolean, default: true }
            example:
              context: [怎么联系支持？, 有客服吗]
              document: 发邮件到 support@acme.com，工作日 4 小时内回复。
      responses:
        "201":
          description: 新的指定问答
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Guidance" }
        "400": { $ref: "#/components/responses/BadRequest" }

  /sites/{site}/guidance/{id}:
    parameters:
      - $ref: "#/components/parameters/Site"
      - name: id
        in: path
        required: true
        description: 指定问答 id
        schema: { type: string, example: gd_01jd8x2k7q }
    get:
      tags: [AI]
      summary: 获取指定问答
      x-fern-sdk-method-name: get-guidance
      responses:
        "200":
          description: 指定问答
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Guidance" }
        "404": { $ref: "#/components/responses/NotFound" }
    patch:
      tags: [AI]
      summary: 更新指定问答
      x-fern-sdk-method-name: update-guidance
      description: 需要 `editor` 角色。只更新传入的字段。
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                context: { type: array, minItems: 1, maxItems: 20, items: { type: string, maxLength: 500 } }
                document: { type: string, maxLength: 8000 }
                enabled: { type: boolean }
      responses:
        "200":
          description: 更新后的指定问答
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Guidance" }
        "400": { $ref: "#/components/responses/BadRequest" }
    delete:
      tags: [AI]
      summary: 删除指定问答
      x-fern-sdk-method-name: delete-guidance
      description: 需要 `editor` 角色。
      responses:
        "200": { $ref: "#/components/responses/Ok" }

  /sites/{site}/sources:
    parameters:
      - $ref: "#/components/parameters/Site"
    get:
      tags: [AI]
      summary: 列出内容来源
      x-fern-sdk-method-name: list-sources
      responses:
        "200":
          description: 内容来源，按创建时间倒序
          content:
            application/json:
              schema:
                type: array
                items: { $ref: "#/components/schemas/Source" }
    post:
      tags: [AI]
      summary: 添加内容来源
      x-fern-sdk-method-name: create-source
      description: 需要 `editor` 角色。`document` 是一份 Markdown，`website` 从 `url` 开始抓取一个公开网站（遵守 robots.txt）。每个站点最多 20 个来源。
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [kind, url]
              properties:
                kind: { type: string, enum: [document, website] }
                title: { type: string, maxLength: 200, description: 标题；`document` 必填，`website` 默认为主机名 }
                url: { type: string, description: 文档的引用地址，或抓取的起始地址 }
                document: { type: string, maxLength: 500000, description: Markdown 正文，仅 `document` }
                paths: { type: array, maxItems: 20, items: { type: string, example: /help/ }, description: 只抓取这些路径开头的页面，默认是起始地址所在的目录，仅 `website` }
                exclude: { type: array, maxItems: 20, items: { type: string, example: /help/archive/ }, description: 不抓取这些路径开头的页面，仅 `website` }
                maxPages: { type: integer, minimum: 1, maximum: 500, default: 100, description: 页数上限，仅 `website` }
                refresh: { type: string, enum: [never, daily, weekly, monthly], default: weekly, description: 重新抓取的周期，仅 `website` }
            examples:
              website:
                summary: 抓取网站
                value:
                  kind: website
                  url: https://help.acme.com/
                  maxPages: 200
                  refresh: weekly
              document:
                summary: Markdown 文档
                value:
                  kind: document
                  title: 服务条款
                  url: https://acme.com/terms
                  document: "# 服务条款\n……"
      responses:
        "201":
          description: 新的内容来源；网站在后台抓取
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Source" }
        "400": { $ref: "#/components/responses/BadRequest" }

  /sites/{site}/sources/{id}:
    parameters:
      - $ref: "#/components/parameters/Site"
      - name: id
        in: path
        required: true
        description: 内容来源 id
        schema: { type: string, example: src_01jd8x2k7q }
    get:
      tags: [AI]
      summary: 获取内容来源
      x-fern-sdk-method-name: get-source
      responses:
        "200":
          description: 内容来源及其页面
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Source" }
        "404": { $ref: "#/components/responses/NotFound" }
    patch:
      tags: [AI]
      summary: 更新内容来源
      x-fern-sdk-method-name: update-source
      description: 需要 `editor` 角色。只更新传入的字段；网站随后重新抓取。
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                title: { type: string, maxLength: 200 }
                url: { type: string }
                document: { type: string, maxLength: 500000 }
                paths: { type: array, maxItems: 20, items: { type: string } }
                exclude: { type: array, maxItems: 20, items: { type: string } }
                maxPages: { type: integer, minimum: 1, maximum: 500 }
                refresh: { type: string, enum: [never, daily, weekly, monthly] }
      responses:
        "200":
          description: 更新后的内容来源
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Source" }
        "400": { $ref: "#/components/responses/BadRequest" }
    delete:
      tags: [AI]
      summary: 删除内容来源
      x-fern-sdk-method-name: delete-source
      description: 需要 `editor` 角色。
      responses:
        "200": { $ref: "#/components/responses/Ok" }

  /sites/{site}/sources/{id}/refresh:
    parameters:
      - $ref: "#/components/parameters/Site"
      - name: id
        in: path
        required: true
        description: 内容来源 id
        schema: { type: string, example: src_01jd8x2k7q }
    post:
      tags: [AI]
      summary: 重新抓取网站
      x-fern-sdk-method-name: refresh-source
      description: 需要 `editor` 角色。只适用于 `website`，在后台进行。
      responses:
        "202":
          description: 已排队
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Source" }
        "400": { $ref: "#/components/responses/BadRequest" }

  /sites/{site}/embed:
    parameters:
      - $ref: "#/components/parameters/Site"
    get:
      tags: [AI]
      summary: 获取嵌入设置
      x-fern-sdk-method-name: get-embed
      responses:
        "200":
          description: 允许嵌入助手的网站、皮肤，以及文档站自己的两套强调色
          content:
            application/json:
              schema:
                allOf:
                  - $ref: "#/components/schemas/EmbedSettings"
                  - type: object
                    properties:
                      accent:
                        type: object
                        nullable: true
                        description: 文档站亮色与暗色模式的强调色，嵌入时不指定颜色就用它们；还没发布过时为 null
                        properties:
                          light: { type: string, example: "#a86200" }
                          dark: { type: string, example: "#ffc823" }
    put:
      tags: [AI]
      summary: 更新嵌入设置
      x-fern-sdk-method-name: update-embed
      description: 需要 `admin` 角色。只修改请求里给出的字段：`origins` 整体替换允许的来源（空列表表示关闭嵌入）；外观字段（`skin`、`trigger`、`theme`、`color`、`colorDark`）立即生效，写 `null` 恢复默认。
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: "#/components/schemas/EmbedSettings" }
      responses:
        "200":
          description: 更新后的设置
          content:
            application/json:
              schema: { $ref: "#/components/schemas/EmbedSettings" }
        "400": { $ref: "#/components/responses/BadRequest" }

  # ---------------------------------------------------------------- Automations
  /sites/{site}/automations:
    parameters:
      - $ref: "#/components/parameters/Site"
    get:
      tags: [Automations]
      summary: 列出定时任务
      x-fern-sdk-method-name: list-automations
      responses:
        "200":
          description: 定时任务，按创建时间倒序
          content:
            application/json:
              schema:
                type: array
                items: { $ref: "#/components/schemas/Automation" }
    post:
      tags: [Automations]
      summary: 创建定时任务
      x-fern-sdk-method-name: create-automation
      description: 需要 `editor` 角色。每个站点最多 20 个。
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [name, prompt, schedule]
              properties:
                name: { type: string, maxLength: 100 }
                prompt: { type: string, maxLength: 2000, description: 要做什么 }
                schedule: { $ref: "#/components/schemas/Schedule" }
                canEdit: { type: boolean, default: false, description: 允许修改文档；改动提交到新的草稿分支 }
                enabled: { type: boolean, default: true }
            example:
              name: 每周文档缺口
              prompt: 查看最近 7 天没有答上来的提问，列出最值得补写的 5 处。
              schedule:
                every: week
                weekday: 1
                hour: 9
                minute: 0
                timezone: Asia/Shanghai
      responses:
        "201":
          description: 新的定时任务
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Automation" }
        "400": { $ref: "#/components/responses/BadRequest" }

  /sites/{site}/automations/{id}:
    parameters:
      - $ref: "#/components/parameters/Site"
      - $ref: "#/components/parameters/AutomationId"
    get:
      tags: [Automations]
      summary: 获取定时任务
      x-fern-sdk-method-name: get-automation
      responses:
        "200":
          description: 定时任务
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Automation" }
        "404": { $ref: "#/components/responses/NotFound" }
    patch:
      tags: [Automations]
      summary: 更新定时任务
      x-fern-sdk-method-name: update-automation
      description: 需要 `editor` 角色。只更新传入的字段。
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                name: { type: string, maxLength: 100 }
                prompt: { type: string, maxLength: 2000 }
                schedule: { $ref: "#/components/schemas/Schedule" }
                canEdit: { type: boolean }
                enabled: { type: boolean }
      responses:
        "200":
          description: 更新后的定时任务
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Automation" }
        "400": { $ref: "#/components/responses/BadRequest" }
    delete:
      tags: [Automations]
      summary: 删除定时任务
      x-fern-sdk-method-name: delete-automation
      description: 需要 `editor` 角色。
      responses:
        "200": { $ref: "#/components/responses/Ok" }

  /sites/{site}/automations/{id}/run:
    parameters:
      - $ref: "#/components/parameters/Site"
      - $ref: "#/components/parameters/AutomationId"
    post:
      tags: [Automations]
      summary: 立即运行
      x-fern-sdk-method-name: run-automation
      description: 需要 `editor` 角色。在后台运行，不影响下一次计划。
      responses:
        "202":
          description: 已开始
          content:
            application/json:
              schema:
                type: object
                properties:
                  id: { type: string, example: run_01jd8x2k7q, description: 运行 id }
        "409":
          description: 正在运行
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }
        "429":
          description: 启动过于频繁，或有其他任务正在运行
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }

  /sites/{site}/automations/{id}/runs:
    parameters:
      - $ref: "#/components/parameters/Site"
      - $ref: "#/components/parameters/AutomationId"
    get:
      tags: [Automations]
      summary: 运行记录
      x-fern-sdk-method-name: list-automation-runs
      responses:
        "200":
          description: 最近 30 天的运行，最多 100 条，按开始时间倒序
          content:
            application/json:
              schema:
                type: array
                items: { $ref: "#/components/schemas/AutomationRun" }

  # ---------------------------------------------------------------- Analytics
  /sites/{site}/analytics:
    parameters:
      - $ref: "#/components/parameters/Site"
    get:
      tags: [Analytics]
      summary: 访问统计
      x-fern-sdk-method-name: get-analytics
      description: 按 User-Agent 把访问分为人类、AI（训练爬虫与 AI 助手）与其他爬虫。`.md` 请求、索引与规范文件的请求和 MCP 调用单独计数。
      parameters:
        - name: days
          in: query
          schema: { type: integer, default: 30, minimum: 1, maximum: 365 }
      responses:
        "200":
          description: 统计数据
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Analytics" }

  /sites/{site}/questions:
    parameters:
      - $ref: "#/components/parameters/Site"
    get:
      tags: [Analytics]
      summary: AI 提问记录
      x-fern-sdk-method-name: list-questions
      description: 按时间倒序。条件可以组合；翻页时把上一页最后一条的 `ts` 作为 `before`。
      parameters:
        - $ref: "#/components/parameters/QuestionDays"
        - $ref: "#/components/parameters/QuestionBefore"
        - $ref: "#/components/parameters/QuestionOutcome"
        - $ref: "#/components/parameters/QuestionRating"
        - $ref: "#/components/parameters/QuestionSources"
        - $ref: "#/components/parameters/QuestionPage"
        - name: limit
          in: query
          description: 返回条数，最大 500
          schema: { type: integer, default: 50, maximum: 500 }
      responses:
        "200":
          description: 读者在 Ask AI 中的提问与回答
          content:
            application/json:
              schema:
                type: array
                items:
                  type: object
                  properties:
                    id: { type: integer }
                    ts: { type: integer, format: int64 }
                    question: { type: string, example: 怎样配置自定义域名？ }
                    answer: { type: string }
                    model: { type: string, example: deepseek-flash }
                    provider: { $ref: "#/components/schemas/Provider" }
                    sources:
                      type: array
                      items: { type: string, example: /guides/deploy/custom-domains }
                    outcome:
                      type: string
                      enum: [answered, partial, missing, declined, stray, failed]
                      description: 有没有答上来：`answered` 已解决，`partial` 部分解决，`missing` 文档缺失，`declined` 与站点无关，`stray` 回答越出站点主题，`failed` 未完成
                    rating: { type: [string, "null"], enum: [up, down, null], description: 读者的评价 }
                    page: { type: [string, "null"], description: 提问时所在的页面, example: /guides/deploy/platform }
                    country: { type: [string, "null"], description: 国家代码（按 IP 识别）, example: CN }
                    net: { type: [string, "null"], description: 打码的网段（只保留 IP 前三段）, example: 203.0.113.* }
                    agent: { type: [string, "null"], description: 浏览器与系统, example: Chrome 158 · macOS }
                    visitor: { type: [string, "null"], description: 匿名访客编号（每天更换） }

  /sites/{site}/questions.csv:
    parameters:
      - $ref: "#/components/parameters/Site"
    get:
      tags: [Analytics]
      summary: 导出 AI 提问记录
      x-fern-sdk-method-name: export-questions
      description: 条件与提问记录相同，最多导出 10000 条。
      parameters:
        - $ref: "#/components/parameters/QuestionDays"
        - $ref: "#/components/parameters/QuestionBefore"
        - $ref: "#/components/parameters/QuestionOutcome"
        - $ref: "#/components/parameters/QuestionRating"
        - $ref: "#/components/parameters/QuestionSources"
        - $ref: "#/components/parameters/QuestionPage"
      responses:
        "200":
          description: CSV 文件
          content:
            text/csv:
              schema: { type: string }

  /sites/{site}/evals:
    parameters:
      - $ref: "#/components/parameters/Site"
    get:
      tags: [AI]
      summary: 文档考卷成绩
      x-fern-sdk-method-name: list-evals
      description: 最近 100 次[文档考卷](/guides/features/evals)的成绩，从新到旧。
      responses:
        "200":
          description: 成绩列表
          content:
            application/json:
              schema: { type: array, items: { $ref: "#/components/schemas/EvalRun" } }
    post:
      tags: [AI]
      summary: 上传文档考卷成绩
      x-fern-sdk-method-name: upload-eval
      description: 需要 `editor` 角色，一般由 `biti eval --site` 调用。得分由 `results` 算出。
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [results]
              properties:
                min: { type: integer, example: 80, description: 及格线（百分比） }
                model: { type: string, example: deepseek-flash, description: 作答的模型 }
                judge: { type: string, example: deepseek-flash, description: 评分的模型 }
                commit: { type: string, example: 0123abcd, description: 文档的提交号 }
                results: { type: array, minItems: 1, maxItems: 500, items: { $ref: "#/components/schemas/EvalResult" } }
      responses:
        "201":
          description: 已保存
          content:
            application/json:
              schema: { $ref: "#/components/schemas/EvalRun" }

  /sites/{site}/evals/{id}:
    parameters:
      - $ref: "#/components/parameters/Site"
      - { name: id, in: path, required: true, schema: { type: string, example: eval_k2m9 } }
    get:
      tags: [AI]
      summary: 文档考卷详情
      x-fern-sdk-method-name: get-eval
      description: 一次成绩与每道题的结果。
      responses:
        "200":
          description: 成绩与每道题的结果
          content:
            application/json:
              schema:
                allOf:
                  - $ref: "#/components/schemas/EvalRun"
                  - type: object
                    properties:
                      results: { type: array, items: { $ref: "#/components/schemas/EvalResult" } }
    delete:
      tags: [AI]
      summary: 删除文档考卷成绩
      x-fern-sdk-method-name: delete-eval
      description: 需要 `editor` 角色。
      responses:
        "200":
          description: 已删除
          content:
            application/json:
              schema: { type: object, properties: { ok: { type: boolean, example: true } } }

  /sites/{site}/page-reviews:
    parameters:
      - $ref: "#/components/parameters/Site"
    get:
      tags: [Analytics]
      summary: 页面核验
      x-fern-sdk-method-name: list-page-reviews
      description: 默认分支上每个页面的负责人、核验日期、复核日期与状态，可能过时与到期的在前。见[页面核验](/guides/features/page-review)。
      parameters:
        - name: today
          in: query
          description: 判断是否到期用的日期（YYYY-MM-DD），默认是 UTC 的今天
          schema: { type: string, format: date, example: "2026-11-26" }
      responses:
        "200":
          description: 页面列表
          content:
            application/json:
              schema:
                type: object
                properties:
                  pages:
                    type: [array, "null"]
                    description: 站点在平台上还没有内容时为 `null`
                    items:
                      type: object
                      properties:
                        path: { type: string, example: pages/quickstart.mdx }
                        title: { type: string, example: 快速开始 }
                        slug: { type: string, example: /guides/quickstart }
                        owners: { type: array, items: { type: string }, example: [alice] }
                        verified: { type: string, format: date, example: "2026-11-01" }
                        due: { type: string, format: date, example: "2027-01-30", description: 下次复核的日期 }
                        outdated: { type: boolean, example: false, description: 被标为可能过时 }
                        status: { type: string, enum: [verified, due, outdated, none] }

  /sites/{site}/questions/summary:
    parameters:
      - $ref: "#/components/parameters/Site"
    get:
      tags: [Analytics]
      summary: 解决率
      x-fern-sdk-method-name: question-summary
      description: 各结果的数量、解决率与读者评价。与站点无关和未完成的提问不计入解决率。
      parameters:
        - name: days
          in: query
          schema: { type: integer, default: 30, minimum: 1, maximum: 365 }
      responses:
        "200":
          description: 汇总
          content:
            application/json:
              schema:
                type: object
                properties:
                  days: { type: integer, example: 30 }
                  counts:
                    type: object
                    properties:
                      answered: { type: integer, example: 180 }
                      partial: { type: integer, example: 20 }
                      missing: { type: integer, example: 25 }
                      declined: { type: integer, example: 12 }
                      stray: { type: integer, example: 1 }
                      failed: { type: integer, example: 3 }
                  resolutionRate: { type: [number, "null"], example: 0.8, description: 0–1；没有可计入的提问时为 `null` }
                  rating:
                    type: object
                    properties:
                      up: { type: integer, example: 42 }
                      down: { type: integer, example: 5 }

  /sites/{site}/feedback:
    parameters:
      - $ref: "#/components/parameters/Site"
    get:
      tags: [Analytics]
      summary: 页面反馈
      x-fern-sdk-method-name: list-feedback
      parameters:
        - $ref: "#/components/parameters/Limit"
      responses:
        "200":
          description: 读者的「这页有帮助吗？」、代码块问题与 AI 工具提交的反馈
          content:
            application/json:
              schema:
                type: array
                items:
                  type: object
                  properties:
                    id: { type: integer }
                    ts: { type: integer, format: int64 }
                    path: { type: string, example: /guides/get-started/quickstart }
                    helpful: { type: boolean }
                    comment: { type: string, example: 希望补充 Windows 下的安装说明 }
                    source: { type: string, enum: [reader, agent], description: "`agent`：AI 工具经 MCP 或 Markdown 里的地址提交，内容由 AI 生成" }
                    code:
                      type: object
                      description: 针对的代码块（只有代码块问题有）
                      properties:
                        index: { type: integer, description: 页面上的第几个代码块，从 0 开始 }
                        lang: { type: string, example: bash }
                        line: { type: string, description: 第一行, example: npm install -g bitidocs }

  # ---------------------------------------------------------------- Editor
  /sites/{site}/editor/branches:
    parameters:
      - $ref: "#/components/parameters/Site"
    get:
      tags: [Editor]
      summary: 列出草稿分支
      x-fern-sdk-method-name: list-branches
      responses:
        "200":
          description: 分支列表
          content:
            application/json:
              schema:
                type: array
                items: { $ref: "#/components/schemas/Branch" }
    post:
      tags: [Editor]
      summary: 新建草稿
      x-fern-sdk-method-name: create-branch
      description: 从 `from`（默认生产分支）创建草稿分支 `draft/<用户 id 后 8 位>-<时间>`。
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                from: { type: string, example: main }
      responses:
        "201":
          description: 新分支名
          content:
            application/json:
              schema:
                type: object
                properties:
                  name: { type: string, example: draft/3k9d2a1b-mf2x8k }

  /sites/{site}/editor/branches/{name}:
    parameters:
      - $ref: "#/components/parameters/Site"
      - name: name
        in: path
        required: true
        schema: { type: string, example: draft/3k9d2a1b-mf2x8k }
    delete:
      tags: [Editor]
      summary: 丢弃草稿
      x-fern-sdk-method-name: delete-branch
      description: 不能删除生产分支。
      responses:
        "200": { $ref: "#/components/responses/Ok" }

  /sites/{site}/editor/tree:
    parameters:
      - $ref: "#/components/parameters/Site"
    get:
      tags: [Editor]
      summary: 文件树与导航
      x-fern-sdk-method-name: get-tree
      parameters:
        - $ref: "#/components/parameters/Branch"
      responses:
        "200":
          description: 分支上的文件、解析后的导航（默认语言与版本）与 docs.yml 原文
          content:
            application/json:
              schema:
                type: object
                properties:
                  branch: { type: string }
                  files:
                    type: array
                    items:
                      type: object
                      properties:
                        path: { type: string, example: pages/introduction.mdx }
                        size: { type: integer, example: 1834 }
                  nav:
                    type: array
                    items: { $ref: "#/components/schemas/NavNode" }
                  config: { type: string, description: 配置文件原文 }

  /sites/{site}/editor/file:
    parameters:
      - $ref: "#/components/parameters/Site"
    get:
      tags: [Editor]
      summary: 读取文件
      x-fern-sdk-method-name: read-file
      parameters:
        - $ref: "#/components/parameters/Branch"
        - $ref: "#/components/parameters/FilePath"
      responses:
        "200":
          description: 文件内容
          content:
            application/json:
              schema:
                type: object
                properties:
                  path: { type: string }
                  content: { type: string }
                  sha: { type: string, description: 用于乐观并发控制 }
        "404": { $ref: "#/components/responses/NotFound" }
    put:
      tags: [Editor]
      summary: 保存文件
      x-fern-sdk-method-name: write-file
      description: |
        把文件提交到草稿分支（一次保存 = 一次提交）。传入打开文件时的 `baseSha`，若文件已被他人修改，返回 409 与最新内容，便于合并。
        已连接 Git 的站点不能直接写生产分支。
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [branch, path, content]
              properties:
                branch: { type: string, example: draft/3k9d2a1b-mf2x8k }
                path: { type: string, example: pages/quickstart.mdx }
                content: { type: string, maxLength: 2000000 }
                message: { type: string, example: 更新快速开始 }
                baseSha: { type: string }
      responses:
        "200":
          description: 新的 sha
          content:
            application/json:
              schema:
                type: object
                properties:
                  sha: { type: string }
        "409":
          description: 文件已被修改
          content:
            application/json:
              schema:
                type: object
                properties:
                  error: { type: string, example: This file changed since you opened it. }
                  current:
                    type: object
                    properties:
                      content: { type: string }
                      sha: { type: string }
    delete:
      tags: [Editor]
      summary: 删除文件
      x-fern-sdk-method-name: delete-file
      parameters:
        - $ref: "#/components/parameters/Branch"
        - $ref: "#/components/parameters/FilePath"
      responses:
        "200": { $ref: "#/components/responses/Ok" }

  /sites/{site}/editor/move:
    parameters:
      - $ref: "#/components/parameters/Site"
    post:
      tags: [Editor]
      summary: 移动或重命名文件
      x-fern-sdk-method-name: move-file
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [branch, from, to]
              properties:
                branch: { type: string }
                from: { type: string, example: pages/old.mdx }
                to: { type: string, example: pages/guides/new.mdx }
      responses:
        "200": { $ref: "#/components/responses/Ok" }

  /sites/{site}/editor/upload:
    parameters:
      - $ref: "#/components/parameters/Site"
    post:
      tags: [Editor]
      summary: 上传图片、媒体或字体
      x-fern-sdk-method-name: upload-file
      description: 上传图片、视频、PDF 或字体（WOFF2、WOFF、TTF、OTF，最大 20 MB），保存到草稿分支的 `assets/` 下（字体在 `assets/fonts/`）并提交。返回可直接写进 Markdown 的地址。
      parameters:
        - name: branch
          in: query
          required: true
          schema: { type: string }
      requestBody:
        required: true
        content:
          multipart/form-data:
            schema:
              type: object
              required: [file]
              properties:
                file: { type: string, format: binary }
      responses:
        "201":
          description: 已保存
          content:
            application/json:
              schema:
                type: object
                properties:
                  path: { type: string, example: assets/mf2x8k-diagram.png }
                  url: { type: string, example: /assets/mf2x8k-diagram.png }
        "413":
          description: 超过 20 MB
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }

  /sites/{site}/editor/render:
    parameters:
      - $ref: "#/components/parameters/Site"
    post:
      tags: [Editor]
      summary: 实时渲染
      x-fern-sdk-method-name: render-preview
      description: 用未保存的内容渲染完整页面 HTML（含样式，适合放进 iframe 的 `srcdoc`），同时返回诊断。预览以安全模式渲染，不加载站点自定义脚本。
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: "#/components/schemas/RenderRequest" }
      responses:
        "200":
          description: 渲染结果
          content:
            application/json:
              schema:
                type: object
                properties:
                  html: { type: string }
                  diagnostics:
                    type: array
                    items: { $ref: "#/components/schemas/Diagnostic" }

  /sites/{site}/editor/check:
    parameters:
      - $ref: "#/components/parameters/Site"
    post:
      tags: [Editor]
      summary: 校验内容
      x-fern-sdk-method-name: check-file
      description: 与实时渲染相同，但只返回诊断（等价于对单个文件运行 `biti check`）。
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: "#/components/schemas/RenderRequest" }
      responses:
        "200":
          description: 诊断
          content:
            application/json:
              schema:
                type: object
                properties:
                  diagnostics:
                    type: array
                    items: { $ref: "#/components/schemas/Diagnostic" }

  /sites/{site}/editor/preview:
    parameters:
      - $ref: "#/components/parameters/Site"
    post:
      tags: [Editor]
      summary: 预览草稿
      x-fern-sdk-method-name: create-preview
      description: 为草稿分支创建预览部署，得到 `<site>--<短 id>` 形式的独立地址。
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                branch: { type: string }
      responses:
        "202":
          description: 已排队的预览部署
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Deployment" }

  /sites/{site}/editor/publish:
    parameters:
      - $ref: "#/components/parameters/Site"
    post:
      tags: [Editor]
      summary: 发布草稿
      x-fern-sdk-method-name: publish
      description: 把草稿分支合并到生产分支（已连接 Git 时同时推送到远程），并触发生产部署。合并冲突时返回 409。
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [branch]
              properties:
                branch: { type: string, example: draft/3k9d2a1b-mf2x8k }
                message: { type: string, example: 发布：新增 Webhook 指南 }
      responses:
        "202":
          description: 已触发生产部署
          content:
            application/json:
              schema:
                type: object
                properties:
                  deploymentId: { type: string }
        "409": { $ref: "#/components/responses/Conflict" }

  /sites/{site}/editor/translate:
    parameters:
      - $ref: "#/components/parameters/Site"
    post:
      tags: [Editor]
      summary: AI 翻译整站
      x-fern-sdk-method-name: translate
      x-fern-availability: beta
      description: |
        用站点的 Ask AI 配置把全部页面增量翻译到新分支 `translate/…`（包括导航标签、API 规范与翻译记忆），完成后可在编辑器中审阅再发布。
        以后台任务运行，返回任务 id。
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                to:
                  type: array
                  items: { type: string }
                  description: 目标语言，默认是 docs.yml 中原文以外的全部语言
                  example: [en, ja]
                from: { type: string, description: 基于哪个分支，默认生产分支 }
      responses:
        "202":
          description: 任务已开始
          content:
            application/json:
              schema:
                type: object
                properties:
                  id: { type: string, example: job_4n7q2w }
        "400": { $ref: "#/components/responses/BadRequest" }

  /jobs/{id}:
    parameters:
      - name: id
        in: path
        required: true
        schema: { type: string, example: job_4n7q2w }
    get:
      tags: [Jobs]
      summary: 查询任务
      x-fern-sdk-method-name: get-job
      responses:
        "200":
          description: 任务状态与最近 200 行日志
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Job" }
        "404": { $ref: "#/components/responses/NotFound" }

  /components:
    get:
      tags: [Editor]
      summary: 组件清单
      x-fern-sdk-method-name: list-components
      description: 全部 MDX 组件及其属性，与 `biti components --json` 的输出相同。可视化编辑器用它生成属性面板。
      responses:
        "200":
          description: 组件清单
          content:
            application/json:
              schema:
                type: array
                items: { $ref: "#/components/schemas/Component" }

  # ---------------------------------------------------------------- Organization MCP
  /mcp:
    post:
      tags: [Orgs]
      summary: 组织 MCP 服务器
      x-fern-sdk-method-name: org-mcp
      description: |
        组织的 MCP 服务器（Streamable HTTP 传输，JSON 响应），只读。只接受组织 API Key，工具见[托管平台](/guides/deploy/platform#组织-mcp-服务器)。
        `GET` 请求返回 405；每个 API Key 每分钟最多 120 次调用，超过返回 429。
      security:
        - apiKey: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [jsonrpc, method]
              properties:
                jsonrpc: { type: string, const: "2.0" }
                id: { type: [string, integer] }
                method: { type: string, enum: [initialize, ping, tools/list, tools/call] }
                params: { type: object }
            example:
              jsonrpc: "2.0"
              id: 1
              method: tools/call
              params:
                name: list_sites
                arguments: {}
      responses:
        "200":
          description: JSON-RPC 响应
          content:
            application/json:
              schema:
                type: object
                properties:
                  jsonrpc: { type: string }
                  id: { type: [string, integer] }
                  result: { type: object }
                  error:
                    type: object
                    properties:
                      code: { type: integer }
                      message: { type: string }
        "202":
          description: 通知类消息，无响应体
        "401": { $ref: "#/components/responses/Unauthorized" }

  # ---------------------------------------------------------------- Site runtime
  /_biti/ai/chat:
    servers:
      - url: "https://{site}-sites.butterix.com"
        description: ButterIX 托管文档站
        variables:
          site:
            default: butterix
            description: 站点子域名
    post:
      tags: [Runtime]
      summary: Ask AI 对话（SSE）
      x-fern-sdk-method-name: ask-ai
      description: |
        检索站点文档并流式生成带引用编号的回答，响应是 `text/event-stream`，事件依次为：

        | 事件 | 数据 |
        |---|---|
        | `sources` | `[{ n, title, heading?, url }]` 引用来源 |
        | `text` | `{ t }` 一段增量文本（多次） |
        | `done` | `{ model, sig?, notice? }` |
        | `error` | `{ message, code? }` |

        `done.sig` 是服务端对这一轮问答的签名，追问时把它放在对应的 `assistant` 消息里回传；没有有效签名的那一轮问答不会作为上下文交给模型。
        问题与文档明显无关时不生成回答，`text` 是一句固定说明，`done` 为 `{ model: null, notice: "offtopic" }`；
        站点达到每日上限时只返回相关文档，`done` 为 `{ model: null, notice: "budget" }`。

        托管平台上的调用要求：

        - 请求来自站点自身的页面（`Origin` 与站点一致，`Sec-Fetch-Site` 为 `same-origin`），否则返回 403；
        - 新版本构建的站点还需要在 `X-Biti-AI-Token` 头中携带 [会话令牌](/api-reference/runtime/ask-ai-token)，缺失或过期时返回 401（`code: "ai_token"`），重新获取后重试即可。

        限流：每个 IP（IPv6 按 /64）每分钟 12 次、每天 200 次；每个网段（IPv4 /24、IPv6 /48）每分钟 60 次、每天 1000 次；同一 IP 最多同时 2 个回答。
        站点关闭 Ask AI 时返回 404，未配置密钥或月度配额用完时返回 503。因为要求同源，API 参考页面中的「试调」无法调用这个端点。
      security: []
      parameters:
        - name: X-Biti-AI-Token
          in: header
          required: false
          description: 会话令牌（托管平台上新版本构建的站点必填）
          schema: { type: string }
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [messages]
              properties:
                messages:
                  type: array
                  description: 对话历史，最后一条必须是 `user`
                  items:
                    type: object
                    required: [role, content]
                    properties:
                      role: { type: string, enum: [user, assistant] }
                      content: { type: string, maxLength: 12000, description: "`user` 消息最多 512 字符" }
                      sig: { type: string, description: "`assistant` 消息：该轮 `done` 事件返回的签名" }
                locale: { type: string, description: 回答语言，默认站点第一种语言, example: zh }
            example:
              messages:
                - role: user
                  content: 如何给站点添加英文版？
              locale: zh
      responses:
        "200":
          description: 事件流
          content:
            text/event-stream:
              schema:
                type: string
              example: |
                event: sources
                data: [{"n":1,"title":"多语言","url":"/guides/features/i18n"}]

                event: text
                data: {"t":"在 docs.yml 的 languages 中加入 en [1]，"}

                event: text
                data: {"t":"然后把译文放到 translations/en/ 下。"}

                event: done
                data: {"model":"claude-opus-5-5","unanswered":true}
        "400":
          description: '最后一条不是问题，或问题超过 512 字符（`code: "too_long"`）'
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }
        "401":
          description: '缺少会话令牌或令牌已过期（`code: "ai_token"`）'
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }
        "403":
          description: '不是来自站点自身页面的请求（`code: "origin"`）'
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }
        "413":
          description: '请求体超过 256 KB（`code: "too_large"`）'
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }
        "429":
          description: '提问过于频繁（`code: "rate_limited"`）或同时进行的回答过多（`code: "busy"`）'
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }
        "503":
          description: 未配置 AI 提供商
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }

  /_biti/ai/token:
    servers:
      - url: "https://{site}-sites.butterix.com"
        description: ButterIX 托管文档站
        variables:
          site:
            default: butterix
            description: 站点子域名
    get:
      tags: [Runtime]
      summary: Ask AI 会话令牌
      x-fern-sdk-method-name: ask-ai-token
      description: |
        领取调用 [Ask AI 对话](/api-reference/runtime/ask-ai) 所需的会话令牌，30 分钟有效，绑定站点、客户端网段与浏览器标识（换了网络或浏览器需要重新领取）。
        跨站请求返回 403；每个 IP 每分钟最多 30 次。
      security: []
      responses:
        "200":
          description: 会话令牌
          content:
            application/json:
              schema:
                type: object
                required: [token, expiresAt]
                properties:
                  token: { type: string, example: 1795435200000.Zm9vYmFyYmF6cXV4cXV1eGNvcmdl }
                  expiresAt: { type: integer, format: int64, description: 过期时间（毫秒时间戳） }
        "403":
          description: 跨站请求
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }
        "429":
          description: 请求过于频繁
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }

  /_mcp/server:
    servers:
      - url: "https://{site}-sites.butterix.com"
        description: ButterIX 托管文档站
        variables:
          site:
            default: butterix
            description: 站点子域名
    post:
      tags: [Runtime]
      summary: MCP 服务器
      x-fern-sdk-method-name: mcp
      description: |
        站点 MCP 服务器（Streamable HTTP 传输，JSON 响应）。支持 `initialize`、`ping`、`tools/list`、`tools/call`，也接受批量消息。
        工具：`search_docs`（检索）、`get_page`（获取页面 Markdown）、`list_pages`（列出页面）。多语言站点的 `search_docs` 与 `list_pages` 可以传 `locale`。`GET` 请求返回 405；站点关闭 MCP 时返回 404。
        受密码保护的站点需要访问令牌或 OAuth 登录，未授权时返回 401。
      security: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [jsonrpc, method]
              properties:
                jsonrpc: { type: string, const: "2.0" }
                id: { type: [string, integer] }
                method: { type: string, enum: [initialize, ping, tools/list, tools/call] }
                params: { type: object }
            examples:
              search:
                summary: 调用 search_docs
                value:
                  jsonrpc: "2.0"
                  id: 1
                  method: tools/call
                  params:
                    name: search_docs
                    arguments:
                      query: 自定义域名
                      limit: 3
              list:
                summary: 列出工具
                value:
                  jsonrpc: "2.0"
                  id: 1
                  method: tools/list
      responses:
        "200":
          description: JSON-RPC 响应
          content:
            application/json:
              schema:
                type: object
                properties:
                  jsonrpc: { type: string }
                  id: { type: [string, integer] }
                  result: { type: object }
                  error:
                    type: object
                    properties:
                      code: { type: integer }
                      message: { type: string }
              example:
                jsonrpc: "2.0"
                id: 1
                result:
                  content:
                    - type: text
                      text: "## 1. 自定义域名 › 配置 DNS\nURL: https://docs.butterix.com/guides/deploy/custom-domains\n\n添加 TXT 记录……"
        "202":
          description: 通知类消息，无响应体

  /_biti/proxy:
    servers:
      - url: "https://{site}-sites.butterix.com"
        description: ButterIX 托管文档站
        variables:
          site:
            default: butterix
            description: 站点子域名
    post:
      tags: [Runtime]
      summary: API 试调代理
      x-fern-sdk-method-name: proxy
      description: |
        API 参考页的「试一试」通过它转发请求，避免浏览器跨域限制。为防止被滥用为开放代理：

        - 只允许站点 OpenAPI 规范中声明过的 `servers` 源站，其他地址返回 403；
        - 托管平台上拒绝解析到内网、回环地址的主机；
        - 剥离 `Cookie`、`Host` 等头，不跟随重定向，响应体最多 2 MB，30 秒超时；
        - 每个 IP 每分钟最多 60 次。
      security: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [url, method]
              properties:
                url: { type: string, example: https://api.butterix.com/v1/whoami }
                method: { type: string, example: GET }
                headers:
                  type: object
                  additionalProperties: { type: string }
                  example: { Authorization: Bearer biti_xxx }
                body: { type: string }
      responses:
        "200":
          description: 目标服务的响应（无论其状态码如何）
          content:
            application/json:
              schema:
                type: object
                properties:
                  status: { type: integer, example: 200 }
                  statusText: { type: string, example: OK }
                  headers:
                    type: object
                    additionalProperties: { type: string }
                  body: { type: string }
                  truncated: { type: boolean }
                  size: { type: integer }
                  timeMs: { type: integer, example: 84 }
        "403":
          description: 目标主机未在规范中声明，或解析到内网地址
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }

  /_biti/feedback:
    servers:
      - url: "https://{site}-sites.butterix.com"
        description: ButterIX 托管文档站
        variables:
          site:
            default: butterix
            description: 站点子域名
    post:
      tags: [Runtime]
      summary: 提交页面反馈
      x-fern-sdk-method-name: feedback
      description: 页面底部「这页有帮助吗？」使用的端点。评论最多 2000 字符。
      security: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [path, helpful]
              properties:
                path: { type: string, example: /guides/get-started/quickstart }
                helpful: { type: boolean, example: true }
                comment: { type: string, maxLength: 2000 }
      responses:
        "204":
          description: 已记录

components:
  securitySchemes:
    apiKey:
      type: http
      scheme: bearer
      bearerFormat: biti_…
      description: 组织 API Key，在控制台「组织设置 → API Keys」创建，格式 `biti_` 开头。以 `editor` 角色行事，不能执行需要 `admin` 的操作。
    session:
      type: apiKey
      in: cookie
      name: biti_session
      description: 登录后设置的 HttpOnly 会话 Cookie。修改类请求必须同源（校验 `Origin` 头），以防 CSRF。

  parameters:
    AutomationId:
      name: id
      in: path
      required: true
      description: 定时任务 id
      schema: { type: string, example: auto_01jd8x2k7q }
    QuestionDays:
      name: days
      in: query
      description: 最近多少天，默认不限
      schema: { type: integer, minimum: 1, maximum: 3650 }
    QuestionBefore:
      name: before
      in: query
      description: 只要早于这个时间（Unix 毫秒）的
      schema: { type: integer, format: int64 }
    QuestionOutcome:
      name: outcome
      in: query
      description: 结果，多个用逗号分隔
      schema: { type: string, example: "missing,partial" }
    QuestionRating:
      name: rating
      in: query
      description: 读者的评价；`none` 为没有评价的
      schema: { type: string, enum: [up, down, none] }
    QuestionSources:
      name: sources
      in: query
      description: "`none` 只返回没有引用任何来源的"
      schema: { type: string, enum: [none] }
    QuestionPage:
      name: page
      in: query
      description: 提问时所在的页面
      schema: { type: string, example: /guides/deploy/platform }
    Org:
      name: org
      in: path
      required: true
      description: 组织 slug 或 id
      schema: { type: string, example: acme }
    Site:
      name: site
      in: path
      required: true
      description: 站点 slug 或 id
      schema: { type: string, example: acme-payments }
    DeploymentId:
      name: id
      in: path
      required: true
      schema: { type: string, example: dpl_01jd8x2k7q }
    Domain:
      name: domain
      in: path
      required: true
      schema: { type: string, example: docs.acme.com }
    Branch:
      name: branch
      in: query
      description: 分支名，默认生产分支
      schema: { type: string, example: draft/3k9d2a1b-mf2x8k }
    FilePath:
      name: path
      in: query
      required: true
      description: 项目内路径
      schema: { type: string, example: pages/introduction.mdx }
    Limit:
      name: limit
      in: query
      schema: { type: integer, default: 50, maximum: 200 }

  responses:
    Ok:
      description: 成功
      content:
        application/json:
          schema:
            type: object
            properties:
              ok: { type: boolean, const: true }
    BadRequest:
      description: 请求参数无效
      content:
        application/json:
          schema: { $ref: "#/components/schemas/Error" }
          example: { error: "Use 5–40 lowercase letters, numbers and single hyphens." }
    Unauthorized:
      description: 未登录或凭据无效
      content:
        application/json:
          schema: { $ref: "#/components/schemas/Error" }
          example: { error: Sign in required }
    Forbidden:
      description: 角色不足，或 API Key 不允许此操作
      content:
        application/json:
          schema: { $ref: "#/components/schemas/Error" }
          example: { error: Requires admin role }
    NotFound:
      description: 资源不存在，或你没有访问权限
      content:
        application/json:
          schema: { $ref: "#/components/schemas/Error" }
          example: { error: Site not found }
    Conflict:
      description: 冲突（名称已被占用、重复添加或合并冲突）
      content:
        application/json:
          schema: { $ref: "#/components/schemas/Error" }
          example: { error: That subdomain is taken. }

  schemas:
    Error:
      type: object
      required: [error]
      properties:
        error: { type: string, description: 人类可读的错误信息 }
        code: { type: string, description: 机器可读的错误码（部分接口提供） }

    Role:
      type: string
      enum: [owner, admin, editor, viewer]
      description: 组织角色
      x-enum-descriptions:
        - 全部权限（组织至少保留一位）
        - 管理成员、站点、域名、密钥与设置
        - 编辑内容、部署与测试
        - 只读

    Provider:
      type: string
      enum: [anthropic, deepseek, openrouter]

    DeploymentStatus:
      type: string
      enum: [queued, building, ready, failed, canceled]

    User:
      type: object
      properties:
        id: { type: string, example: usr_3k9d2a }
        email: { type: string, format: email, example: lin@example.com }
        name: { type: string, example: 林晓 }
        avatarUrl: { type: string, format: uri }
        isAdmin: { type: boolean, description: 平台管理员, example: false }

    Org:
      type: object
      properties:
        id: { type: string, example: org_8f2k1c }
        slug: { type: string, example: acme }
        name: { type: string, example: Acme }
        plan: { type: string, example: free }
        planName: { type: string, example: Free }
        role: { $ref: "#/components/schemas/Role" }
        createdAt: { type: integer, format: int64, example: 1763596800000 }

    Member:
      type: object
      properties:
        user:
          type: object
          properties:
            id: { type: string }
            name: { type: string }
            email: { type: string }
            avatarUrl: { type: string }
        role: { $ref: "#/components/schemas/Role" }
        createdAt: { type: integer, format: int64 }

    Invite:
      type: object
      properties:
        id: { type: string, example: inv_7cd2e1 }
        email: { type: string, example: chen@example.com }
        role: { $ref: "#/components/schemas/Role" }
        createdAt: { type: integer, format: int64 }

    ApiKey:
      type: object
      properties:
        id: { type: string, example: key_5h2m8q }
        name: { type: string, example: GitHub Actions }
        prefix: { type: string, description: 密钥前 10 个字符, example: biti_Q2xha }
        suffix: { type: string, description: 密钥末尾 10 个字符, example: Kd82mQx0Zt }
        createdAt: { type: integer, format: int64 }
        lastUsedAt: { type: integer, format: int64 }

    AuditEntry:
      type: object
      properties:
        ts: { type: integer, format: int64 }
        action: { type: string, example: deployment.promote }
        target: { type: string, example: dpl_01jd8x2k7q }
        user:
          type: object
          properties:
            name: { type: string }
            email: { type: string }

    SiteSummary:
      type: object
      properties:
        id: { type: string, example: site_2m4k8p }
        slug: { type: string, example: acme-payments }
        name: { type: string, example: Acme 文档 }
        url: { type: string, format: uri, example: https://acme-payments-sites.butterix.com }
        sourceType:
          type: string
          enum: [hosted, git, upload]
          description: 内容来源：托管仓库、外部 Git 仓库或 CLI 上传
        status:
          description: 最近一次部署的状态，没有部署时为 `none`
          type: string
          enum: [queued, building, ready, failed, canceled, none]
        updatedAt: { type: integer, format: int64 }
        pageCount: { type: integer, description: 生产部署的页面数, example: 94 }

    SiteDetail:
      allOf:
        - $ref: "#/components/schemas/SiteSummary"
        - type: object
          properties:
            orgSlug: { type: string, example: acme }
            git:
              type: object
              description: 连接了 Git 仓库时存在
              properties:
                url: { type: string, example: https://github.com/acme/docs.git }
                branch: { type: string, example: main }
                hasToken: { type: boolean }
                webhookUrl: { type: string, example: https://api.butterix.com/v1/webhooks/github/site_2m4k8p }
                webhookSecret: { type: string }
            production: { $ref: "#/components/schemas/Deployment" }
            domains:
              type: array
              items: { $ref: "#/components/schemas/Domain" }
            access:
              type: object
              properties:
                mode: { type: string, enum: [public, password] }
            ai: { $ref: "#/components/schemas/AiSettings" }
            primaryUrl: { type: string, format: uri, description: 主域名的地址；没有自定义域名时与 `url` 相同, example: https://docs.acme.com }
            mcpUrl: { type: string, format: uri, example: https://docs.acme.com/_mcp/server }

    Deployment:
      type: object
      properties:
        id: { type: string, example: dpl_01jd8x2k7q }
        siteId: { type: string, example: site_2m4k8p }
        kind: { type: string, enum: [production, preview] }
        status: { $ref: "#/components/schemas/DeploymentStatus" }
        source:
          type: string
          description: "`cli`（上传）、`hosted`（托管仓库）或 `git`"
          example: git
        branch: { type: string, example: main }
        commitSha: { type: string, example: 9fceb02d0ae598e95dc970b74767f19372d61af8 }
        message: { type: string, example: "docs: 更新快速开始" }
        createdBy:
          type: object
          description: 触发者；用 API Key 触发时是创建密钥的人
          properties:
            id: { type: string }
            name: { type: string }
        apiKey:
          type: object
          description: 用 API Key（CLI / CI）触发时，密钥的名称与首尾
          properties:
            name: { type: string, example: GitHub Actions }
            prefix: { type: string, description: 密钥前 10 个字符, example: biti_a1B2c }
            suffix: { type: string, description: 密钥末尾 10 个字符, example: Kd82mQx0Zt }
        error: { type: string, description: 失败原因 }
        pageCount: { type: integer, example: 94 }
        sizeBytes: { type: integer, example: 5832110 }
        durationMs: { type: integer, example: 6120 }
        url:
          type: string
          format: uri
          description: 成功后才有。生产部署是站点地址，预览部署是 `<site>--<id 后 8 位>` 子域名
          example: https://acme-payments--8x2k7q-sites.butterix.com
        isCurrent: { type: boolean, description: 是否为当前生产部署 }
        createdAt: { type: integer, format: int64 }
        finishedAt: { type: integer, format: int64 }

    Domain:
      type: object
      properties:
        domain: { type: string, example: docs.acme.com }
        verified: { type: boolean, example: false }
        primary: { type: boolean, description: 是否为主域名, example: false }
        verifyRecord:
          type: object
          description: 需要添加的 TXT 记录
          properties:
            type: { type: string, const: TXT }
            name: { type: string, example: _butterix.docs.acme.com }
            value: { type: string, example: butterix-verify=a1b2c3d4e5f6 }
        cname: { type: string, description: CNAME 目标, example: sites.butterix.com }
        createdAt: { type: integer, format: int64 }

    AiSettings:
      type: object
      properties:
        enabled: { type: boolean, example: true }
        provider: { $ref: "#/components/schemas/Provider" }
        model: { type: string, example: claude-opus-5-5 }
        hasKey: { type: boolean, description: 是否设置了站点密钥 }
        keyMasked: { type: string, example: sk-a…9f2c }
        platformKeyAvailable: { type: boolean, description: 平台是否为当前提供商配置了默认密钥 }
        platformKeys:
          type: object
          description: 每个提供商是否有平台密钥
          additionalProperties: { type: boolean }
        guidance: { type: string }
        effort: { type: [string, "null"], enum: [none, minimal, low, medium, high, xhigh, max, null], description: 推理强度；`null` 表示使用模型的建议档位 }
        retentionDays: { type: [integer, "null"], description: 提问记录保留天数；`null` 表示一直保留 }
        dailyLimit: { type: [integer, "null"], example: 200, description: 滚动 24 小时内调用模型的提问上限；`null` 表示不限 }
        agent: { type: boolean, example: true, description: 控制台 AI 是否启用 }
        gaps: { type: boolean, example: false, description: 是否每天自动整理文档缺口 }
        support:
          type: object
          description: 答不上时转人工
          properties:
            enabled: { type: boolean, example: false }
            url: { type: string, example: "" }
            email: { type: string, example: "" }

    EvalRun:
      type: object
      properties:
        id: { type: string, example: eval_k2m9 }
        createdAt: { type: integer, example: 1764115200000 }
        score: { type: integer, example: 85, description: 答对的百分比 }
        passed: { type: integer, example: 17 }
        total: { type: integer, example: 20 }
        min: { type: integer, example: 80, description: 及格线 }
        ok: { type: boolean, example: true }
        model: { type: string, example: deepseek-flash }
        judge: { type: string, example: deepseek-flash }
        commit: { type: string, example: 0123abcd }

    EvalResult:
      type: object
      required: [question]
      properties:
        id: { type: string, example: refund-time }
        question: { type: string, example: 退款多久到账？ }
        pass: { type: boolean, example: true }
        met: { type: array, items: { type: boolean }, description: 每个要点是否说到 }
        missing: { type: array, items: { type: string }, description: 缺少的要点 }
        said: { type: array, items: { type: string }, description: 不该说却说了的内容 }
        unseen: { type: array, items: { type: string }, description: 没检索到的页面 }
        sources: { type: array, items: { type: string }, example: [/guides/refund] }
        answer: { type: string, example: 三个工作日内到账，原路退回。 }
        note: { type: string, description: 评分的说明 }
        error: { type: string, description: 无法作答或评分的原因 }

    ModelInfo:
      type: object
      properties:
        id: { type: string, example: claude-opus-5-5 }
        label: { type: string, example: Claude Opus 5.5 }
        contextWindow: { type: integer, example: 1000000 }
        pricing:
          type: object
          description: 每百万 tokens 的美元价格（提供商报告时）
          properties:
            input: { type: number, example: 4 }
            output: { type: number, example: 20 }
        recommended: { type: boolean }
        reasoning:
          type: object
          description: 模型支持的推理强度；没有时不返回
          properties:
            efforts:
              type: array
              description: 由低到高的档位，`none` 是关闭思考；为空表示会思考但没有档位可选
              items: { type: string, enum: [none, minimal, low, medium, high, xhigh, max] }
            suggested: { type: string, description: 没有设置时使用的档位, example: low }
            default: { type: string, description: 模型自己的默认档位, example: high }

    Analytics:
      type: object
      properties:
        totals:
          type: object
          properties:
            views: { type: integer, description: 页面与 .md 访问总数 }
            humanViews: { type: integer }
            visitors: { type: integer, description: 访客数，按天去重后累计，真人、AI 与爬虫都算 }
            aiViews: { type: integer, description: AI 爬虫与 AI 助手 }
            botViews: { type: integer, description: 搜索引擎与其他爬虫 }
            markdownRequests: { type: integer }
            agentFileRequests: { type: integer, description: 索引（llms.txt、llms-full.txt）与 API 规范文件的请求，不计入以上各项 }
            mcpCalls: { type: integer }
            searches: { type: integer }
            questions: { type: integer }
            feedbackUp: { type: integer }
            feedbackDown: { type: integer }
        daily:
          type: array
          items:
            type: object
            properties:
              date: { type: string, format: date, example: "2026-11-20" }
              human: { type: integer }
              ai: { type: integer }
              bot: { type: integer }
              visitors:
                type: object
                description: 当天按类型去重的访客
                properties:
                  human: { type: integer }
                  ai: { type: integer }
                  bot: { type: integer }
        topPages:
          type: array
          items:
            type: object
            properties:
              path: { type: string }
              views: { type: integer }
        aiAgents:
          type: array
          items:
            type: object
            properties:
              name: { type: string, example: ClaudeBot }
              count: { type: integer }
        referrers:
          type: array
          items:
            type: object
            properties:
              host: { type: string, example: github.com }
              count: { type: integer }
        countries:
          type: array
          items:
            type: object
            properties:
              code: { type: string, example: CN }
              count: { type: integer }
        notFound:
          type: array
          items:
            type: object
            properties:
              path: { type: string }
              count: { type: integer }
        agentFiles:
          type: array
          description: 请求最多的索引与规范文件
          items:
            type: object
            properties:
              path: { type: string, example: /llms.txt }
              type: { type: string, enum: [index, spec] }
              agents: { type: integer }
              humans: { type: integer }
              count: { type: integer }
        topSearches:
          type: array
          items:
            type: object
            properties:
              q: { type: string, example: 自定义域名 }
              count: { type: integer }

    AccessToken:
      type: object
      properties:
        id: { type: string, example: tok_01jd8x2k7q }
        kind: { type: string, enum: [token, oauth], description: "`token` 访问令牌，`oauth` MCP 登录" }
        name: { type: string, example: 内部助手 }
        prefix: { type: string, example: bxt_a1b2c3, description: 令牌开头 }
        expiresAt: { type: [integer, "null"], format: int64, description: 过期时间；`null` 表示一直有效 }
        createdAt: { type: integer, format: int64 }
        lastUsedAt: { type: [integer, "null"], format: int64 }

    Guidance:
      type: object
      properties:
        id: { type: string, example: gd_01jd8x2k7q }
        context: { type: array, items: { type: string }, description: 示例问题, example: [怎么联系支持？] }
        document: { type: string, description: 答案（Markdown） }
        enabled: { type: boolean }
        createdAt: { type: integer, format: int64 }
        updatedAt: { type: integer, format: int64 }

    Source:
      type: object
      properties:
        id: { type: string, example: src_01jd8x2k7q }
        kind: { type: string, enum: [document, website] }
        title: { type: string, example: help.acme.com }
        url: { type: string, example: "https://help.acme.com/" }
        config:
          type: object
          description: 抓取设置，仅 `website`
          properties:
            paths: { type: array, items: { type: string } }
            exclude: { type: array, items: { type: string } }
            maxPages: { type: integer }
            refresh: { type: string, enum: [never, daily, weekly, monthly] }
        status: { type: string, enum: [ready, queued, running, failed] }
        error: { type: string, description: 上次抓取失败的原因 }
        pageCount: { type: integer, example: 86 }
        createdAt: { type: integer, format: int64 }
        refreshedAt: { type: [integer, "null"], format: int64, description: 内容最近更新的时间 }
        nextAt: { type: [integer, "null"], format: int64, description: 下一次抓取的时间 }
        pages:
          type: array
          description: 页面，最多 500 个；列表中不返回
          items:
            type: object
            properties:
              url: { type: string }
              title: { type: string }
              size: { type: integer, description: 正文的字符数 }
        document: { type: string, description: Markdown 正文，仅 `document`；列表中不返回 }

    EmbedSettings:
      type: object
      properties:
        skin:
          type: string
          enum: [classic, aurora]
          default: classic
          description: 皮肤：`classic` 经典，`aurora` 极光（毛玻璃、边缘流光发光）。网页上的 `data-skin` 优先
        trigger:
          type: string
          enum: [button, bar]
          default: button
          description: 入口样式：`button` 悬浮按钮，`bar` 底部输入框。网页上的 `data-trigger` 优先
        theme:
          type: string
          enum: [dark, light, auto]
          default: dark
          description: 颜色模式，`auto` 跟随访客的系统设置。网页上的 `data-theme` 优先
        color:
          type: string
          nullable: true
          example: "#7c5cff"
          description: 亮色模式的强调色；null 表示用文档站自己的。网页上的 `data-color` 优先
        colorDark:
          type: string
          nullable: true
          example: "#9e8aff"
          description: 暗色模式的强调色；null 时由 `color` 推出，或用文档站自己的。网页上的 `data-color-dark` 优先
        origins:
          type: array
          maxItems: 20
          description: 允许的来源；`*.` 表示任意子域名，http 只允许 localhost
          items: { type: string }
          example: ["https://app.acme.com", "https://*.acme.com"]

    Schedule:
      type: object
      required: [every, hour]
      properties:
        every: { type: string, enum: [day, week] }
        weekday: { type: integer, minimum: 1, maximum: 7, description: 1（周一）到 7（周日），`every` 为 `week` 时必填 }
        hour: { type: integer, minimum: 0, maximum: 23 }
        minute: { type: integer, minimum: 0, maximum: 59, default: 0 }
        timezone: { type: string, default: UTC, example: Asia/Shanghai, description: IANA 时区 }

    Automation:
      type: object
      properties:
        id: { type: string, example: auto_01jd8x2k7q }
        name: { type: string, example: 每周文档缺口 }
        prompt: { type: string }
        schedule: { $ref: "#/components/schemas/Schedule" }
        canEdit: { type: boolean, description: 允许修改文档 }
        enabled: { type: boolean }
        createdBy:
          type: object
          properties:
            id: { type: string }
            name: { type: string }
        createdAt: { type: integer, format: int64 }
        nextAt: { type: [integer, "null"], format: int64, description: 下一次运行的时间 }
        lastRun:
          description: 最近一次运行（不含报告）；还没有运行过时为 `null`
          oneOf:
            - $ref: "#/components/schemas/AutomationRun"
            - type: "null"

    AutomationRun:
      type: object
      properties:
        id: { type: string, example: run_01jd8x2k7q }
        automationId: { type: string }
        cause: { type: string, enum: [schedule, manual] }
        status: { type: string, enum: [running, done, failed] }
        report: { type: string, description: 报告（Markdown） }
        branch: { type: string, description: 有改动时的草稿分支, example: automation/2k7q9x1a }
        files: { type: array, items: { type: string }, description: 修改的文件 }
        error: { type: string, description: 失败原因 }
        usage:
          type: object
          description: token 用量
          properties:
            input: { type: integer }
            output: { type: integer }
        startedAt: { type: integer, format: int64 }
        finishedAt: { type: [integer, "null"], format: int64 }

    Branch:
      type: object
      properties:
        name: { type: string, example: draft/3k9d2a1b-mf2x8k }
        isDefault: { type: boolean }
        updatedAt: { type: integer, format: int64 }
        author: { type: string, example: 林晓 }
        ahead: { type: integer, description: 领先生产分支的提交数 }

    NavNode:
      type: object
      properties:
        type: { type: string, enum: [tab, section, page, link, api] }
        title: { type: string }
        slug: { type: string }
        path: { type: string, description: 源文件 }
        children:
          type: array
          items: { $ref: "#/components/schemas/NavNode" }

    RenderRequest:
      type: object
      required: [branch, path, content]
      properties:
        branch: { type: string }
        path: { type: string, example: pages/quickstart.mdx }
        content: { type: string, description: 编辑器中当前（可能未保存）的内容 }

    Diagnostic:
      type: object
      properties:
        severity: { type: string, enum: [error, warning, info] }
        code: { type: string, example: mdx/unknown-component }
        message: { type: string }
        file: { type: string }
        line: { type: integer }
        column: { type: integer }
        hint: { type: string }

    Job:
      type: object
      properties:
        id: { type: string }
        kind: { type: string, example: translate }
        status: { type: string, enum: [running, done, failed] }
        log:
          type: array
          items: { type: string }
        result:
          type: object
          properties:
            branch: { type: string, example: translate/3k9d2a-mf2x8k }
            stats:
              type: object
              additionalProperties:
                type: object
                properties:
                  pages: { type: integer }
                  translated: { type: integer }
                  reused: { type: integer }
        error: { type: string }

    Component:
      type: object
      properties:
        name: { type: string, example: Callout }
        aliases:
          type: array
          items: { type: string }
          example: [Note, Info, Warning]
        category: { type: string, example: callout }
        description: { type: string }
        children: { type: string, enum: [none, inline, block] }
        parent: { type: string }
        props:
          type: array
          items:
            type: object
            properties:
              name: { type: string }
              type: { type: string }
              required: { type: boolean }
              options:
                type: array
                items: { type: string }
              default: {}
              description: { type: string }
