# ketec Device HTTP API — OpenAPI 3.1（ketec 设备 HTTP 接口规范）
# This YAML is the source of truth; openapi.json is generated from it.（本文件为唯一来源，openapi.json 由它生成）
# Examples: content.<type>.examples.<name>; x-outcome = success | failure; x-inferred: true = sample values reconstructed from the App source.
openapi: "3.1.0"
info:
  title: ketec Device HTTP API
  version: "330v235"
  description: |-
    Every phone running ketec hosts its own HTTP server. The address (phone IP and port) is shown on the App status page; the default port is 9800. Use phone-ip in examples as a placeholder for that address.

    ketec runs in one of two modes:
    - **Agent mode**: no extra hardware; touches, typing and UI-tree reading are injected through the iOS system testing/automation service.
    - **HID mode**: an ESP32-S3 USB HID device plugged into the phone performs touches and key presses.

    `/api/control/*` and `/api/source` are for Agent mode (in HID mode most `/api/control/*` calls are forwarded to the HID channel; `w3cActions` is Agent-only). `/api/hid/*` is for HID mode and needs the ESP32-S3 device for touch and key input. Each operation lists its modes in `x-modes`.

    Conventions:
    - Most endpoints are `GET` with query parameters; the server does not check the HTTP method. Endpoints documented as `POST` read a request body (JSON or binary).
    - Query values must be URL-encoded; `+` decodes to a space, so send a literal plus as `%2B`.
    - Coordinates are physical screen pixels, the same as the screenshot pixels.
    - Responses are JSON shaped like `{"success": bool, "data": ..., "message"?: string, "reason"?: string}` unless stated otherwise (images, streams, file downloads, the log endpoints). `message` / `reason` are human-readable (usually Chinese) and not stable; check `success` and documented fields.
    - Missing or invalid parameters return HTTP 400; unknown paths return 404 `{"success": false, "reason": "Not Found"}`. Many action failures still use HTTP 200 with `success: false`.
    - If the device license is not valid, most endpoints return `{"success": false, "error": "license", "message": ...}`.

    Security: there is no authentication. Anyone who can reach the port can control the phone, read the clipboard and files, and delete photos. Use it only on a trusted local network and never expose the port to the internet.

    The `/v1/heartbeat` operation (tag License Service) runs on the cloud license service `https://api.ketec.top`, not on the phone; it is listed for reference.
servers:
  - url: "http://{phoneIp}:{port}"
    description: The phone running ketec.
    variables:
      phoneIp:
        default: phone-ip
        description: LAN IP address of the phone, shown on the ketec App status page.
      port:
        default: "9800"
        description: HTTP port of the ketec server (default 9800).
tags:
  - name: Device
    description: Device status, screenshots, installed apps, lock state, brightness, volume and run-mode switching.
    x-zh-name: "设备"
    x-zh-description: "设备状态、截图、已安装应用、锁屏状态、亮度、音量与运行模式切换。"
  - name: "Scripts & Packages"
    description: Run JavaScript snippets, and upload, load, run and stop script packages.
    x-zh-name: "脚本与软件包"
    x-zh-description: "执行 JavaScript 片段；上传、加载、运行、停止脚本软件包。"
  - name: Agent Control
    description: "Touch, typing, keys, app control and UI-tree reading through the Agent channel (no hardware). Designed for Agent mode; in HID mode most /api/control/* calls are forwarded to the HID channel."
    x-zh-name: "Agent 控制"
    x-zh-description: "经 Agent 通道（无需硬件）进行点击、输入、按键、应用控制与读取界面树。面向 Agent 模式；HID 模式下大部分 /api/control/* 会转由 HID 通道执行。"
  - name: HID Control
    description: Touch, typing and buttons through the ESP32-S3 USB HID device. Use in HID mode with the device plugged in. Coordinates are physical pixels.
    x-zh-name: "HID 控制"
    x-zh-description: "经 ESP32-S3 USB HID 设备进行点击、输入与按键。在 HID 模式下、插着设备时使用。坐标为物理像素。"
  - name: Keyboard
    description: "Text input through the ketec keyboard extension (/api/ime/*). Most calls need the ketec keyboard enabled and a keyboard on screen."
    x-zh-name: "输入法（键盘）"
    x-zh-description: "经 ketec 键盘扩展输入文字（/api/ime/*）。大多数接口需要已启用 ketec 键盘且屏幕上有键盘弹出。"
  - name: "Clipboard & Config"
    description: System clipboard access from the main app, and the app key/value configuration.
    x-zh-name: "剪贴板与配置"
    x-zh-description: "主 App 读写系统剪贴板，以及 App 键值配置。"
  - name: Files
    description: Manage files in the app sandbox (Documents or temporary directory).
    x-zh-name: "文件"
    x-zh-description: "管理 App 沙盒（Documents 或临时目录）中的文件。"
  - name: Media
    description: Save images/videos to the Photos library and bulk-delete media.
    x-zh-name: "媒体"
    x-zh-description: "把图片/视频保存到系统相册，以及批量删除相册媒体。"
  - name: Logs
    description: Read and download the app logs.
    x-zh-name: "日志"
    x-zh-description: "读取与下载 App 日志。"
  - name: Screen Mirror
    description: Live screen streaming (MJPEG, H.264 FLV) and screen recording. Streaming needs the ketec screen broadcast to be running.
    x-zh-name: "屏幕镜像"
    x-zh-description: "实时屏幕流（MJPEG、H.264 FLV）与录屏。实时流需要 ketec 屏幕直播正在运行。"
  - name: "Account & License"
    description: "Sign a phone in or out from a computer (TokenKey / account key, or username + password) and read its license status. These endpoints answer even when the device is not licensed. The license itself is checked by the App against the cloud license service; there is no cloud API that signs a device in remotely, so call these on each phone over the LAN."
    x-zh-name: "账号与授权"
    x-zh-description: "从电脑给手机登录 / 退出（TokenKey、账号主 key 或账号密码），以及查询授权状态。设备未授权时这些接口也会应答。许可由 App 向云端授权服务校验；云端没有远程给设备登录的接口，要在局域网里逐台调用手机上的这些接口。"
  - name: License Service
    description: "The cloud license service the App talks to (api.ketec.top). The App sends this heartbeat by itself every 60 seconds; it is documented here for reference only — you normally do not call it."
    x-zh-name: "授权服务"
    x-zh-description: "App 与云端授权服务（api.ketec.top）之间的心跳。App 每 60 秒自动发送，这里仅供参考，一般不需要自己调用。"
paths:
  /api/status:
    get:
      operationId: getStatus
      summary: Get app and device status
      description: Returns device identity, screen geometry, battery, current run mode, Agent/HID availability, script and recording state. The object also contains extra diagnostic fields that are not part of the stable contract.
      tags: ["Device"]
      x-zh-summary: "获取软件与设备状态"
      x-zh-description: "返回设备标识、屏幕尺寸、电量、当前运行模式、Agent/HID 可用性、脚本与录屏状态。对象里还包含额外的诊断字段，不属于稳定契约。"
      x-modes: ["agent", "hid"]
      responses:
        "200":
          description: JSON result.
          content:
            application/json:
              schema:
                type: object
                required: ["success", "data"]
                properties:
                  success:
                    type: boolean
                  data:
                    $ref: "#/components/schemas/Status"
              examples:
                ok:
                  summary: Success
                  x-zh-summary: "成功"
                  x-outcome: success
                  value:
                    success: true
                    data:
                      apiVersion: "330v223"
                      appName: ketec
                      appBundleId: top.ketec.app
                      appVersion: "1.0.0"
                      appBuildNumber: 330.223
                      bundleVersion: "330.223"
                      appNo: ""
                      deviceName: iPhone
                      deviceModel: iPhone13,2
                      osVersion: "16.1.1"
                      deviceIp: phone-ip
                      deviceId: "<device-id>"
                      serverDeviceId: "<server-device-id>"
                      udid: "<udid>"
                      ecid: "<ecid>"
                      orientation: PORTRAIT
                      screenInfo:
                        width: 1170
                        height: 2532
                        scale: 3
                        logicWidth: 390
                        logicHeight: 844
                      batteryInfo:
                        level: 87
                        isCharging: true
                      volume: 0.5
                      brightness: 0.6
                      isLocked: false
                      selectedRunMode: agent
                      agentConnected: true
                      agentAvailable: true
                      isHidConnected: false
                      hidModel: ""
                      hidVersion: ""
                      isRun: false
                      isShowUI: false
                      isRecording: false
                      isBroadcastConnected: false
                      isMirrorLive: false
                      isAuth: true
                      isLogin: true
                      isDebugMode: false
                      isVolumeControlEnabled: false
                      uptime: 86400
                      scriptModules:
                        - appleOcr
                        - device
                        - action
                        - hid
                        - file
                        - http
                        - config
                        - system
                        - media
                        - ime
                        - app
                        - node
        "404":
          description: Unknown path.
          x-zh-description: "路径不存在。"
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
              examples:
                error:
                  summary: "Failure: wrong path (typo, or an older App without this endpoint)"
                  x-zh-summary: "失败：路径不存在（拼写错误或旧版 App 没有该接口）"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    reason: Not Found
  /api/apps:
    get:
      operationId: listApps
      summary: List installed apps
      description: Returns user-installed apps. Each item carries appName, bundleIdentifier and bundleVersion (plus the legacy aliases name and bundleId).
      tags: ["Device"]
      x-zh-summary: "获取已安装应用列表"
      x-zh-description: "返回用户安装的应用。每项包含 appName、bundleIdentifier、bundleVersion（以及兼容旧调用方的 name、bundleId）。"
      x-modes: ["agent", "hid"]
      responses:
        "200":
          description: JSON result.
          content:
            application/json:
              schema:
                type: object
                required: ["success"]
                properties:
                  success:
                    type: boolean
                  data:
                    type: array
                    items:
                      $ref: "#/components/schemas/AppInfo"
                  message:
                    type: string
              examples:
                ok:
                  summary: Success
                  x-zh-summary: "成功"
                  x-outcome: success
                  value:
                    success: true
                    data:
                      - appName: Settings
                        bundleIdentifier: com.apple.Preferences
                        bundleVersion: "1.0"
                        name: Settings
                        bundleId: com.apple.Preferences
                licenseDenied:
                  summary: "Failure: device license not valid (HTTP 200)"
                  x-zh-summary: "失败：设备许可无效（HTTP 200）"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    error: license
                    message: "授权已到期"
                    data:
                      enforced: true
                      valid: false
                      reason: expired
                      message: "授权已到期"
                      builtIn: false
                      hasKey: true
                      account: ""
                      isLogin: false
                      key: "1A2B3C4D…"
                      deviceId: "<device-id>"
                      expiresAt: 1796000000
                      maxDevices: 0
                      online: 0
                      lastOK: 1795990000
                      lastCheck: 1796000100
                      server: "https://api.ketec.top"
  /api/isLocked:
    get:
      operationId: isLocked
      summary: Check whether the screen is locked
      description: "Returns the lock state. Read `locked` together with `source` (which detection level produced the answer: notify, keybag, display or none); `data` carries the same boolean for compatibility."
      tags: ["Device"]
      x-zh-summary: "是否锁屏"
      x-zh-description: "返回锁屏状态。请结合 `locked` 与 `source`（结论来自哪一级判定：notify、keybag、display 或 none）一起读；`data` 是同值的兼容字段。"
      x-modes: ["agent", "hid"]
      responses:
        "200":
          description: JSON result.
          content:
            application/json:
              schema:
                type: object
                required: ["success", "data", "locked", "source"]
                properties:
                  success:
                    type: boolean
                  data:
                    type: boolean
                  locked:
                    type: boolean
                  source:
                    type: string
                    enum: ["notify", "keybag", "display", "none"]
                  diag:
                    type: object
                    description: "Raw value of each detection level, or \"unavailable\"."
                    additionalProperties: true
              examples:
                ok:
                  summary: Success
                  x-zh-summary: "成功"
                  x-outcome: success
                  value:
                    success: true
                    data: false
                    locked: false
                    source: notify
                    diag:
                      notify: 0
                      keybag: 1
                      displayPower: unavailable
                licenseDenied:
                  summary: "Failure: device license not valid (HTTP 200)"
                  x-zh-summary: "失败：设备许可无效（HTTP 200）"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    error: license
                    message: "授权已到期"
                    data:
                      enforced: true
                      valid: false
                      reason: expired
                      message: "授权已到期"
                      builtIn: false
                      hasKey: true
                      account: ""
                      isLogin: false
                      key: "1A2B3C4D…"
                      deviceId: "<device-id>"
                      expiresAt: 1796000000
                      maxDevices: 0
                      online: 0
                      lastOK: 1795990000
                      lastCheck: 1796000100
                      server: "https://api.ketec.top"
  /api/screenshot:
    get:
      operationId: getScreenshot
      summary: Take a screenshot (binary image)
      description: "Returns the current screen as JPEG or PNG (Content-Type tells which). Image pixels match the device's physical resolution, so coordinates measured on it can be passed to click endpoints directly."
      tags: ["Device"]
      x-zh-summary: "截图（二进制图片）"
      x-zh-description: "返回当前屏幕的 JPEG 或 PNG（以 Content-Type 为准）。图片像素与设备物理分辨率一致，在图上量得的坐标可直接用于点击接口。"
      x-modes: ["agent", "hid"]
      parameters:
        - name: method
          in: query
          required: false
          description: "Capture channel. auto tries xct, broadcast, replaykit, render in order. xct = system test service (Agent mode); broadcast = latest frame of the running screen broadcast; replaykit = in-process ReplayKit; render = ketec's own window only; shortcuts = helper Shortcut via the HID device (never chosen by auto). An explicitly chosen channel never falls back."
          x-zh-description: "截图通道。auto 依次尝试 xct、broadcast、replaykit、render。xct = 系统测试服务（Agent 模式）；broadcast = 正在运行的屏幕直播的最新帧；replaykit = 进程内 ReplayKit；render = 仅 ketec 自己的窗口；shortcuts = 经 HID 设备触发辅助快捷指令（auto 不会选）。显式指定的通道失败不回落。"
          schema:
            type: string
            enum: ["auto", "xct", "broadcast", "replaykit", "render", "shortcuts"]
            default: auto
          example: auto
        - name: meta
          in: query
          required: false
          description: When 1, return only a JSON receipt (method, size, dimensions) instead of the image.
          x-zh-description: "为 1 时只返回 JSON 回执（通道、字节数、尺寸），不返回图片。"
          schema:
            type: integer
            enum: [0, 1]
            default: 0
          example: 0
      responses:
        "200":
          description: "Screen image, or a JSON receipt when meta=1."
          content:
            image/jpeg:
              schema:
                type: string
                format: binary
            image/png:
              schema:
                type: string
                format: binary
            application/json:
              schema:
                $ref: "#/components/schemas/ScreenshotReceipt"
              examples:
                ok:
                  summary: Success
                  x-zh-summary: "成功"
                  x-outcome: success
                  value:
                    success: true
                    method: xct
                    bytes: 412345
                    w: 1170
                    h: 2532
                    format: jpeg
                    blank: false
                    elapsedMs: 180
                    needsUserAction: false
                licenseDenied:
                  summary: "Failure: device license not valid (HTTP 200)"
                  x-zh-summary: "失败：设备许可无效（HTTP 200）"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    error: license
                    message: "授权已到期"
                    data:
                      enforced: true
                      valid: false
                      reason: expired
                      message: "授权已到期"
                      builtIn: false
                      hasKey: true
                      account: ""
                      isLogin: false
                      key: "1A2B3C4D…"
                      deviceId: "<device-id>"
                      expiresAt: 1796000000
                      maxDevices: 0
                      online: 0
                      lastOK: 1795990000
                      lastCheck: 1796000100
                      server: "https://api.ketec.top"
        "500":
          description: All channels failed (503 for auto, 500 for an explicit method).
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ScreenshotError"
              examples:
                error:
                  summary: "Failure: action failed"
                  x-zh-summary: "失败：执行失败"
                  x-outcome: failure
                  value:
                    success: false
                    method: auto
                    error: "screenshot_method_failed:auto"
                    needsUserAction: true
                    message: capture failed
                    attempts:
                      - method: xct
                        ok: false
                        bytes: 0
                        error: "..."
                    elapsedMs: 2600
        "503":
          description: All channels failed (503 for auto, 500 for an explicit method).
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ScreenshotError"
              examples:
                error:
                  summary: "Failure: channel unavailable"
                  x-zh-summary: "失败：通道不可用"
                  x-outcome: failure
                  value:
                    success: false
                    method: auto
                    error: "screenshot_method_failed:auto"
                    needsUserAction: true
                    message: capture failed
                    attempts:
                      - method: xct
                        ok: false
                        bytes: 0
                        error: "..."
                    elapsedMs: 2600
  /api/screenshotBase64:
    get:
      operationId: getScreenshotBase64
      summary: Take a screenshot (Base64 JSON)
      description: "Same capture as /api/screenshot, returned as JSON with the image Base64-encoded in `data` and its MIME type in `contentType`."
      tags: ["Device"]
      x-zh-summary: "截图（Base64）"
      x-zh-description: "与 /api/screenshot 相同的截图，以 JSON 返回：`data` 为 Base64 图片，`contentType` 为图片类型。"
      x-modes: ["agent", "hid"]
      parameters:
        - name: method
          in: query
          required: false
          description: "Capture channel. auto tries xct, broadcast, replaykit, render in order. xct = system test service (Agent mode); broadcast = latest frame of the running screen broadcast; replaykit = in-process ReplayKit; render = ketec's own window only; shortcuts = helper Shortcut via the HID device (never chosen by auto). An explicitly chosen channel never falls back."
          x-zh-description: "截图通道。auto 依次尝试 xct、broadcast、replaykit、render。xct = 系统测试服务（Agent 模式）；broadcast = 正在运行的屏幕直播的最新帧；replaykit = 进程内 ReplayKit；render = 仅 ketec 自己的窗口；shortcuts = 经 HID 设备触发辅助快捷指令（auto 不会选）。显式指定的通道失败不回落。"
          schema:
            type: string
            enum: ["auto", "xct", "broadcast", "replaykit", "render", "shortcuts"]
            default: auto
          example: auto
        - name: meta
          in: query
          required: false
          description: When 1, return only a JSON receipt (method, size, dimensions) instead of the image.
          x-zh-description: "为 1 时只返回 JSON 回执（通道、字节数、尺寸），不返回图片。"
          schema:
            type: integer
            enum: [0, 1]
            default: 0
          example: 0
      responses:
        "200":
          description: JSON result.
          content:
            application/json:
              schema:
                allOf:
                  - $ref: "#/components/schemas/ScreenshotReceipt"
                  - type: object
                    properties:
                      data:
                        type: string
                        contentEncoding: base64
                      contentType:
                        type: string
                        enum: ["image/jpeg", "image/png"]
              examples:
                ok:
                  summary: Success
                  x-zh-summary: "成功"
                  x-outcome: success
                  value:
                    success: true
                    method: xct
                    bytes: 412345
                    w: 1170
                    h: 2532
                    format: jpeg
                    blank: false
                    elapsedMs: 180
                    needsUserAction: false
                    contentType: image/jpeg
                    data: /9j/4AAQSkZJRgABAQ...
                licenseDenied:
                  summary: "Failure: device license not valid (HTTP 200)"
                  x-zh-summary: "失败：设备许可无效（HTTP 200）"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    error: license
                    message: "授权已到期"
                    data:
                      enforced: true
                      valid: false
                      reason: expired
                      message: "授权已到期"
                      builtIn: false
                      hasKey: true
                      account: ""
                      isLogin: false
                      key: "1A2B3C4D…"
                      deviceId: "<device-id>"
                      expiresAt: 1796000000
                      maxDevices: 0
                      online: 0
                      lastOK: 1795990000
                      lastCheck: 1796000100
                      server: "https://api.ketec.top"
        "500":
          description: All channels failed (503 for auto, 500 for an explicit method).
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ScreenshotError"
              examples:
                error:
                  summary: "Failure: action failed"
                  x-zh-summary: "失败：执行失败"
                  x-outcome: failure
                  value:
                    success: false
                    method: auto
                    error: "screenshot_method_failed:auto"
                    needsUserAction: true
                    message: capture failed
                    attempts:
                      - method: xct
                        ok: false
                        bytes: 0
                        error: "..."
                    elapsedMs: 2600
        "503":
          description: All channels failed (503 for auto, 500 for an explicit method).
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ScreenshotError"
              examples:
                error:
                  summary: "Failure: channel unavailable"
                  x-zh-summary: "失败：通道不可用"
                  x-outcome: failure
                  value:
                    success: false
                    method: auto
                    error: "screenshot_method_failed:auto"
                    needsUserAction: true
                    message: capture failed
                    attempts:
                      - method: xct
                        ok: false
                        bytes: 0
                        error: "..."
                    elapsedMs: 2600
  /api/takeMeToFront:
    get:
      operationId: takeMeToFront
      summary: Bring ketec to the foreground
      description: "Switches the ketec app itself to the foreground. Returns alreadyFront=true if it already is."
      tags: ["Device"]
      x-zh-summary: "App 切到前台"
      x-zh-description: "把 ketec 自身切到前台；已在前台时返回 alreadyFront=true。"
      x-modes: ["agent", "hid"]
      responses:
        "200":
          description: JSON result.
          content:
            application/json:
              schema:
                type: object
                required: ["success"]
                properties:
                  success:
                    type: boolean
                  data:
                    type: object
                    additionalProperties: true
              examples:
                ok:
                  summary: Success
                  x-zh-summary: "成功"
                  x-outcome: success
                  value:
                    success: true
                    data:
                      bundleId: top.ketec.app
                      alreadyFront: true
                licenseDenied:
                  summary: "Failure: device license not valid (HTTP 200)"
                  x-zh-summary: "失败：设备许可无效（HTTP 200）"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    error: license
                    message: "授权已到期"
                    data:
                      enforced: true
                      valid: false
                      reason: expired
                      message: "授权已到期"
                      builtIn: false
                      hasKey: true
                      account: ""
                      isLogin: false
                      key: "1A2B3C4D…"
                      deviceId: "<device-id>"
                      expiresAt: 1796000000
                      maxDevices: 0
                      online: 0
                      lastOK: 1795990000
                      lastCheck: 1796000100
                      server: "https://api.ketec.top"
  /api/getScreenBrightness:
    get:
      operationId: getScreenBrightness
      summary: Get screen brightness
      description: Returns the screen brightness from 0 to 1 (two decimals).
      tags: ["Device"]
      x-zh-summary: "获取屏幕亮度"
      x-zh-description: "返回屏幕亮度，范围 0–1（保留两位小数）。"
      x-modes: ["agent", "hid"]
      responses:
        "200":
          description: JSON result.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/NumberDataResponse"
              examples:
                ok:
                  summary: Success
                  x-zh-summary: "成功"
                  x-outcome: success
                  value:
                    success: true
                    data: 0.6
                licenseDenied:
                  summary: "Failure: device license not valid (HTTP 200)"
                  x-zh-summary: "失败：设备许可无效（HTTP 200）"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    error: license
                    message: "授权已到期"
                    data:
                      enforced: true
                      valid: false
                      reason: expired
                      message: "授权已到期"
                      builtIn: false
                      hasKey: true
                      account: ""
                      isLogin: false
                      key: "1A2B3C4D…"
                      deviceId: "<device-id>"
                      expiresAt: 1796000000
                      maxDevices: 0
                      online: 0
                      lastOK: 1795990000
                      lastCheck: 1796000100
                      server: "https://api.ketec.top"
  /api/setScreenBrightness:
    get:
      operationId: setScreenBrightness
      summary: Set screen brightness
      description: "Sets the screen brightness. Pass `brightness` (or its alias `value`) from 0 to 1."
      tags: ["Device"]
      x-zh-summary: "设置屏幕亮度"
      x-zh-description: "设置屏幕亮度。传 `brightness`（或别名 `value`），范围 0–1。"
      x-modes: ["agent", "hid"]
      parameters:
        - name: brightness
          in: query
          required: true
          description: "Brightness from 0 to 1. Alias: value."
          x-zh-description: "亮度 0–1。别名：value。"
          schema:
            type: number
            minimum: 0
            maximum: 1
          example: 0.5
      responses:
        "200":
          description: JSON result.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/SuccessResponse"
              examples:
                ok:
                  summary: Success
                  x-zh-summary: "成功"
                  x-outcome: success
                  value:
                    success: true
                licenseDenied:
                  summary: "Failure: device license not valid (HTTP 200)"
                  x-zh-summary: "失败：设备许可无效（HTTP 200）"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    error: license
                    message: "授权已到期"
                    data:
                      enforced: true
                      valid: false
                      reason: expired
                      message: "授权已到期"
                      builtIn: false
                      hasKey: true
                      account: ""
                      isLogin: false
                      key: "1A2B3C4D…"
                      deviceId: "<device-id>"
                      expiresAt: 1796000000
                      maxDevices: 0
                      online: 0
                      lastOK: 1795990000
                      lastCheck: 1796000100
                      server: "https://api.ketec.top"
        "400":
          description: A required parameter is missing or invalid.
          x-zh-description: "必填参数缺失或无效。"
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
              examples:
                error:
                  summary: "Failure: missing or invalid parameter"
                  x-zh-summary: "失败：参数缺失或无效"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    message: "缺少有效的brightness参数"
  /api/getVolume:
    get:
      operationId: getVolume
      summary: Get media volume
      description: Returns the system output volume from 0 to 1 (two decimals).
      tags: ["Device"]
      x-zh-summary: "获取设备音量"
      x-zh-description: "返回系统输出音量，范围 0–1（保留两位小数）。"
      x-modes: ["agent", "hid"]
      responses:
        "200":
          description: JSON result.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/NumberDataResponse"
              examples:
                ok:
                  summary: Success
                  x-zh-summary: "成功"
                  x-outcome: success
                  value:
                    success: true
                    data: 0.5
                licenseDenied:
                  summary: "Failure: device license not valid (HTTP 200)"
                  x-zh-summary: "失败：设备许可无效（HTTP 200）"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    error: license
                    message: "授权已到期"
                    data:
                      enforced: true
                      valid: false
                      reason: expired
                      message: "授权已到期"
                      builtIn: false
                      hasKey: true
                      account: ""
                      isLogin: false
                      key: "1A2B3C4D…"
                      deviceId: "<device-id>"
                      expiresAt: 1796000000
                      maxDevices: 0
                      online: 0
                      lastOK: 1795990000
                      lastCheck: 1796000100
                      server: "https://api.ketec.top"
  /api/setVolume:
    get:
      operationId: setVolume
      summary: Set media volume
      description: "Sets the system output volume. Pass `volume` (or its alias `value`) from 0 to 1."
      tags: ["Device"]
      x-zh-summary: "设置设备音量"
      x-zh-description: "设置系统输出音量。传 `volume`（或别名 `value`），范围 0–1。"
      x-modes: ["agent", "hid"]
      parameters:
        - name: volume
          in: query
          required: true
          description: "Volume from 0 to 1. Alias: value."
          x-zh-description: "音量 0–1。别名：value。"
          schema:
            type: number
            minimum: 0
            maximum: 1
          example: 0.3
      responses:
        "200":
          description: JSON result.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/SuccessResponse"
              examples:
                ok:
                  summary: Success
                  x-zh-summary: "成功"
                  x-outcome: success
                  value:
                    success: true
                licenseDenied:
                  summary: "Failure: device license not valid (HTTP 200)"
                  x-zh-summary: "失败：设备许可无效（HTTP 200）"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    error: license
                    message: "授权已到期"
                    data:
                      enforced: true
                      valid: false
                      reason: expired
                      message: "授权已到期"
                      builtIn: false
                      hasKey: true
                      account: ""
                      isLogin: false
                      key: "1A2B3C4D…"
                      deviceId: "<device-id>"
                      expiresAt: 1796000000
                      maxDevices: 0
                      online: 0
                      lastOK: 1795990000
                      lastCheck: 1796000100
                      server: "https://api.ketec.top"
        "400":
          description: A required parameter is missing or invalid.
          x-zh-description: "必填参数缺失或无效。"
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
              examples:
                error:
                  summary: "Failure: missing or invalid parameter"
                  x-zh-summary: "失败：参数缺失或无效"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    message: "缺少有效的volume参数"
  /api/getRunMode:
    get:
      operationId: getRunMode
      summary: Get current run mode
      description: Returns the selected run mode (agent or hid) and whether each channel is currently usable. Also reachable as /api/control/getRunMode.
      tags: ["Device"]
      x-zh-summary: "获取当前运行模式"
      x-zh-description: "返回当前选择的运行模式（agent 或 hid）以及两个通道当前是否可用。也可通过 /api/control/getRunMode 访问。"
      x-modes: ["agent", "hid"]
      responses:
        "200":
          description: JSON result.
          content:
            application/json:
              schema:
                type: object
                required: ["success", "data"]
                properties:
                  success:
                    type: boolean
                  data:
                    $ref: "#/components/schemas/RunModeInfo"
              examples:
                ok:
                  summary: Success
                  x-zh-summary: "成功"
                  x-outcome: success
                  value:
                    success: true
                    data:
                      runMode: agent
                      agentAvailable: true
                      isHidConnected: false
                licenseDenied:
                  summary: "Failure: device license not valid (HTTP 200)"
                  x-zh-summary: "失败：设备许可无效（HTTP 200）"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    error: license
                    message: "授权已到期"
                    data:
                      enforced: true
                      valid: false
                      reason: expired
                      message: "授权已到期"
                      builtIn: false
                      hasKey: true
                      account: ""
                      isLogin: false
                      key: "1A2B3C4D…"
                      deviceId: "<device-id>"
                      expiresAt: 1796000000
                      maxDevices: 0
                      online: 0
                      lastOK: 1795990000
                      lastCheck: 1796000100
                      server: "https://api.ketec.top"
  /api/setRunMode:
    get:
      operationId: setRunMode
      summary: Switch run mode
      description: "Switches between Agent and HID mode. Switching to hid immediately closes the Agent automation session; switching to agent is refused with HTTP 409 when the Agent channel is not available. Also reachable as /api/control/setRunMode."
      tags: ["Device"]
      x-zh-summary: "切换运行模式"
      x-zh-description: "在 Agent 与 HID 模式之间切换。切到 hid 会立即断开 Agent 自动化会话；Agent 通道不可用时切到 agent 会被拒绝（HTTP 409）。也可通过 /api/control/setRunMode 访问。"
      x-modes: ["agent", "hid"]
      parameters:
        - name: mode
          in: query
          required: true
          description: Target run mode.
          x-zh-description: "目标运行模式。"
          schema:
            type: string
            enum: ["agent", "hid"]
          example: hid
      responses:
        "200":
          description: JSON result.
          content:
            application/json:
              schema:
                type: object
                required: ["success", "data"]
                properties:
                  success:
                    type: boolean
                  data:
                    allOf:
                      - $ref: "#/components/schemas/RunModeInfo"
                      - type: object
                        properties:
                          warning:
                            type: string
                            description: Present when the target channel is not ready yet.
              examples:
                ok:
                  summary: Success
                  x-zh-summary: "成功"
                  x-outcome: success
                  value:
                    success: true
                    data:
                      runMode: hid
                      agentAvailable: true
                      isHidConnected: true
                licenseDenied:
                  summary: "Failure: device license not valid (HTTP 200)"
                  x-zh-summary: "失败：设备许可无效（HTTP 200）"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    error: license
                    message: "授权已到期"
                    data:
                      enforced: true
                      valid: false
                      reason: expired
                      message: "授权已到期"
                      builtIn: false
                      hasKey: true
                      account: ""
                      isLogin: false
                      key: "1A2B3C4D…"
                      deviceId: "<device-id>"
                      expiresAt: 1796000000
                      maxDevices: 0
                      online: 0
                      lastOK: 1795990000
                      lastCheck: 1796000100
                      server: "https://api.ketec.top"
        "400":
          description: A required parameter is missing or invalid.
          x-zh-description: "必填参数缺失或无效。"
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
              examples:
                error:
                  summary: "Failure: missing or invalid parameter"
                  x-zh-summary: "失败：参数缺失或无效"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    message: "缺少有效的mode参数"
        "409":
          description: "Agent channel is not available; mode unchanged."
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
              examples:
                error:
                  summary: "Failure: conflict"
                  x-zh-summary: "失败：状态冲突"
                  x-outcome: failure
                  value:
                    success: false
                    reason: "Agent 通道不可用"
                    agentAvailable: false
                    runMode: hid
  /api/runScript:
    post:
      operationId: runScript
      summary: Run a JavaScript snippet
      description: "Runs JavaScript in the built-in engine and returns the value of the last expression (no `return` needed), e.g. `appleOcr.recognize('screen')`. Scripts are executed one at a time; after `timeout` seconds the call returns while the script may keep running."
      tags: ["Scripts & Packages"]
      x-zh-summary: "执行脚本（仅 JS）"
      x-zh-description: "在内置引擎中执行 JavaScript，返回最后一个表达式的值（无需写 return），例如 `appleOcr.recognize('screen')`。脚本串行执行；超过 `timeout` 秒接口先返回，脚本可能仍在继续运行。"
      x-modes: ["agent", "hid"]
      parameters:
        - name: timeout
          in: query
          required: false
          description: Seconds to wait for the result before returning.
          x-zh-description: "等待结果的秒数，超时先返回。"
          schema:
            type: number
            minimum: 0
            default: 15
          example: 15
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: ["script"]
              properties:
                script:
                  type: string
                  description: "JavaScript source. Can also be passed as the `script` or `code` query parameter."
                  x-zh-description: "JavaScript 源码。也可用查询参数 `script` 或 `code` 传入。"
            example:
              script: |-
                let a = 1;
                a + 1;
      responses:
        "200":
          description: JSON result.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/RunScriptResponse"
              examples:
                ok:
                  summary: Success
                  x-zh-summary: "成功"
                  x-outcome: success
                  value:
                    success: true
                    resultType: number
                    result: 2
                    data:
                      result: 2
                      logs: []
                      durationMs: 3
                licenseDenied:
                  summary: "Failure: device license not valid (HTTP 200)"
                  x-zh-summary: "失败：设备许可无效（HTTP 200）"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    error: license
                    message: "授权已到期"
                    data:
                      enforced: true
                      valid: false
                      reason: expired
                      message: "授权已到期"
                      builtIn: false
                      hasKey: true
                      account: ""
                      isLogin: false
                      key: "1A2B3C4D…"
                      deviceId: "<device-id>"
                      expiresAt: 1796000000
                      maxDevices: 0
                      online: 0
                      lastOK: 1795990000
                      lastCheck: 1796000100
                      server: "https://api.ketec.top"
        "400":
          description: A required parameter is missing or invalid.
          x-zh-description: "必填参数缺失或无效。"
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
              examples:
                error:
                  summary: "Failure: missing or invalid parameter"
                  x-zh-summary: "失败：参数缺失或无效"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    message: "请求体为空"
  /api/run:
    get:
      operationId: runPackage
      summary: Run the current script package
      description: "Starts the entry script of the currently loaded package (see /api/load and /api/sync). If a `script` or `code` parameter is supplied, it instead behaves like /api/runScript."
      tags: ["Scripts & Packages"]
      x-zh-summary: "运行脚本（当前软件包）"
      x-zh-description: "启动当前已加载软件包的入口脚本（见 /api/load、/api/sync）。若带 `script` 或 `code` 参数，则行为与 /api/runScript 相同。"
      x-modes: ["agent", "hid"]
      responses:
        "200":
          description: JSON result.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/MessageResponse"
              examples:
                ok:
                  summary: Success
                  x-zh-summary: "成功"
                  x-outcome: success
                  value:
                    success: true
                    message: "运行成功"
                licenseDenied:
                  summary: "Failure: device license not valid (HTTP 200)"
                  x-zh-summary: "失败：设备许可无效（HTTP 200）"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    error: license
                    message: "授权已到期"
                    data:
                      enforced: true
                      valid: false
                      reason: expired
                      message: "授权已到期"
                      builtIn: false
                      hasKey: true
                      account: ""
                      isLogin: false
                      key: "1A2B3C4D…"
                      deviceId: "<device-id>"
                      expiresAt: 1796000000
                      maxDevices: 0
                      online: 0
                      lastOK: 1795990000
                      lastCheck: 1796000100
                      server: "https://api.ketec.top"
        "400":
          description: Could not start.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/MessageResponse"
              examples:
                error:
                  summary: "Failure: missing or invalid parameter"
                  x-zh-summary: "失败：参数缺失或无效"
                  x-outcome: failure
                  value:
                    success: false
                    message: "入口脚本不存在"
  /api/runUI:
    get:
      operationId: runPackageUI
      summary: Show the UI of the current package
      description: "Shows the configuration UI of the currently loaded package in the app (sets isShowUI=true). Fails if the package has no entry script."
      tags: ["Scripts & Packages"]
      x-zh-summary: "运行 UI"
      x-zh-description: "在 App 内显示当前已加载软件包的配置界面（isShowUI 变为 true）。软件包没有入口脚本时失败。"
      x-modes: ["agent", "hid"]
      responses:
        "200":
          description: JSON result.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/MessageResponse"
              examples:
                ok:
                  summary: Success
                  x-zh-summary: "成功"
                  x-outcome: success
                  value:
                    success: true
                    message: "UI运行成功"
                licenseDenied:
                  summary: "Failure: device license not valid (HTTP 200)"
                  x-zh-summary: "失败：设备许可无效（HTTP 200）"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    error: license
                    message: "授权已到期"
                    data:
                      enforced: true
                      valid: false
                      reason: expired
                      message: "授权已到期"
                      builtIn: false
                      hasKey: true
                      account: ""
                      isLogin: false
                      key: "1A2B3C4D…"
                      deviceId: "<device-id>"
                      expiresAt: 1796000000
                      maxDevices: 0
                      online: 0
                      lastOK: 1795990000
                      lastCheck: 1796000100
                      server: "https://api.ketec.top"
        "400":
          description: Failed.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/MessageResponse"
              examples:
                error:
                  summary: "Failure: missing or invalid parameter"
                  x-zh-summary: "失败：参数缺失或无效"
                  x-outcome: failure
                  value:
                    success: false
                    message: "入口脚本不存在"
  /api/stop:
    get:
      operationId: stopScript
      summary: Stop the running script
      description: "Requests the running package script (or a running /api/runScript snippet) to stop. Returns success=false when nothing is running."
      tags: ["Scripts & Packages"]
      x-zh-summary: "停止脚本"
      x-zh-description: "请求停止正在运行的软件包脚本（或正在执行的 /api/runScript 脚本）。没有脚本在运行时返回 success=false。"
      x-modes: ["agent", "hid"]
      responses:
        "200":
          description: JSON result.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/MessageResponse"
              examples:
                ok:
                  summary: Success
                  x-zh-summary: "成功"
                  x-outcome: success
                  value:
                    success: true
                    message: "停止成功"
                licenseDenied:
                  summary: "Failure: device license not valid (HTTP 200)"
                  x-zh-summary: "失败：设备许可无效（HTTP 200）"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    error: license
                    message: "授权已到期"
                    data:
                      enforced: true
                      valid: false
                      reason: expired
                      message: "授权已到期"
                      builtIn: false
                      hasKey: true
                      account: ""
                      isLogin: false
                      key: "1A2B3C4D…"
                      deviceId: "<device-id>"
                      expiresAt: 1796000000
                      maxDevices: 0
                      online: 0
                      lastOK: 1795990000
                      lastCheck: 1796000100
                      server: "https://api.ketec.top"
        "400":
          description: Nothing running.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/MessageResponse"
              examples:
                error:
                  summary: "Failure: missing or invalid parameter"
                  x-zh-summary: "失败：参数缺失或无效"
                  x-outcome: failure
                  value:
                    success: false
                    message: "脚本未运行中"
  /api/load:
    get:
      operationId: loadPackage
      summary: Load a script package
      description: "Makes the package with the given appNo the current package; if it is not installed locally it is downloaded first. Refused while a script is running."
      tags: ["Scripts & Packages"]
      x-zh-summary: "加载指定软件包"
      x-zh-description: "把指定 appNo 的软件包设为当前包；本地没有时先下载。脚本运行中会被拒绝。"
      x-modes: ["agent", "hid"]
      parameters:
        - name: appNo
          in: query
          required: true
          description: Package number / identifier.
          x-zh-description: "软件包编号。"
          schema:
            type: string
          example: demo
      responses:
        "200":
          description: JSON result.
          content:
            application/json:
              schema:
                allOf:
                  - $ref: "#/components/schemas/MessageResponse"
                  - type: object
                    properties:
                      data:
                        type: object
                        properties:
                          softwareName:
                            type: string
                          downloaded:
                            type: boolean
                          appNo:
                            type: string
              examples:
                ok:
                  summary: Success
                  x-zh-summary: "成功"
                  x-outcome: success
                  value:
                    success: true
                    message: "加载成功"
                    data:
                      softwareName: demo
                      downloaded: false
                      appNo: demo
                licenseDenied:
                  summary: "Failure: device license not valid (HTTP 200)"
                  x-zh-summary: "失败：设备许可无效（HTTP 200）"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    error: license
                    message: "授权已到期"
                    data:
                      enforced: true
                      valid: false
                      reason: expired
                      message: "授权已到期"
                      builtIn: false
                      hasKey: true
                      account: ""
                      isLogin: false
                      key: "1A2B3C4D…"
                      deviceId: "<device-id>"
                      expiresAt: 1796000000
                      maxDevices: 0
                      online: 0
                      lastOK: 1795990000
                      lastCheck: 1796000100
                      server: "https://api.ketec.top"
        "400":
          description: Load failed.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/MessageResponse"
              examples:
                error:
                  summary: "Failure: missing or invalid parameter"
                  x-zh-summary: "失败：参数缺失或无效"
                  x-outcome: failure
                  value:
                    success: false
                    message: "引擎运行中，请先停止再加载"
  /api/sync:
    post:
      operationId: syncPackage
      summary: Upload (sync) a script package
      description: "Uploads a zipped script project as the raw request body and makes it the current package. The zip must contain a file named `appId` at its root; its content becomes the package appNo."
      tags: ["Scripts & Packages"]
      x-zh-summary: "同步脚本（上传软件包）"
      x-zh-description: "以原始请求体上传打包好的脚本工程（zip），并设为当前包。zip 根目录必须有名为 `appId` 的文件，其内容即软件包 appNo。"
      x-modes: ["agent", "hid"]
      parameters:
        - name: projectName
          in: query
          required: false
          description: Display name of the project (defaults to the appId).
          x-zh-description: "工程显示名（缺省为 appId）。"
          schema:
            type: string
          example: MyProject
      requestBody:
        required: true
        content:
          application/zip:
            schema:
              type: string
              format: binary
          application/octet-stream:
            schema:
              type: string
              format: binary
      responses:
        "200":
          description: JSON result.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/MessageResponse"
              examples:
                ok:
                  summary: Success
                  x-zh-summary: "成功"
                  x-outcome: success
                  value:
                    success: true
                    message: "同步成功"
                licenseDenied:
                  summary: "Failure: device license not valid (HTTP 200)"
                  x-zh-summary: "失败：设备许可无效（HTTP 200）"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    error: license
                    message: "授权已到期"
                    data:
                      enforced: true
                      valid: false
                      reason: expired
                      message: "授权已到期"
                      builtIn: false
                      hasKey: true
                      account: ""
                      isLogin: false
                      key: "1A2B3C4D…"
                      deviceId: "<device-id>"
                      expiresAt: 1796000000
                      maxDevices: 0
                      online: 0
                      lastOK: 1795990000
                      lastCheck: 1796000100
                      server: "https://api.ketec.top"
        "400":
          description: Empty body, invalid zip or missing appId file.
          content:
            application/json:
              schema:
                oneOf:
                  - $ref: "#/components/schemas/MessageResponse"
                  - $ref: "#/components/schemas/ErrorResponse"
              examples:
                error:
                  summary: "Failure: missing or invalid parameter"
                  x-zh-summary: "失败：参数缺失或无效"
                  x-outcome: failure
                  value:
                    success: false
                    message: "appId不存在"
  /api/source:
    get:
      operationId: getSource
      summary: Get the UI element tree (XML)
      description: "Returns the accessibility element tree of the foreground app as XML (XCUIElementType* elements with frame, label, value, etc.). Agent mode only. With meta=1 a JSON summary is returned instead of XML."
      tags: ["Agent Control"]
      x-zh-summary: "节点 XML（界面树）"
      x-zh-description: "以 XML 返回前台 App 的无障碍元素树（XCUIElementType* 节点，含 frame、label、value 等）。仅 Agent 模式。meta=1 时改为返回 JSON 摘要而不是 XML。"
      x-modes: ["agent"]
      parameters:
        - name: mode
          in: query
          required: false
          description: "Capture mode, the same three modes as createNodeSelector({mode}) in scripts. 1 = one snapshot of the whole tree (22 attributes per node, depth 50, unlimited children); the default, fastest and most stable. 2 = stitched capture: 2 levels per request with 13 attributes per node, then every cut-off node is requested again and its subtree attached in place; for long lists and very deep trees, slower (one request per container). 3 = stitched capture with 1 level per request (13 attributes, at most 256 children per level). Modes 2 and 3 attach subtrees in place, so they do not return duplicate nodes."
          x-zh-description: "抓取模式，与脚本 createNodeSelector({mode}) 的三种模式相同。1 = 一次取整棵树（每个节点 22 个属性、深度 50、子节点不限），默认值，最快最稳定。2 = 分段拼接：每次请求取 2 层、每个节点 13 个属性，再对每个被截断的节点单独请求、把子树挂回原位；适合长列表和很深的界面，较慢（每个容器一次请求）。3 = 分段拼接，每次只取 1 层（13 个属性，每层最多 256 个子节点）。模式 2 和 3 把子树挂回原位，不会返回重复节点。"
          schema:
            type: integer
            enum: [1, 2, 3]
            default: 1
          example: 1
        - name: pid
          in: query
          required: false
          description: Process id of the app to read. Omit to read the foreground app.
          x-zh-description: "要读取的 App 进程号；不传则读取前台 App。"
          schema:
            type: integer
          example: 0
        - name: meta
          in: query
          required: false
          description: When 1, return JSON metadata (target, node count, size, elapsed time) instead of XML.
          x-zh-description: "为 1 时返回 JSON 元信息（目标、节点数、字节数、耗时），不返回 XML。"
          schema:
            type: integer
            enum: [0, 1]
            default: 0
          example: 0
        - name: max_depth
          in: query
          required: false
          description: "Accepted for compatibility; ignored by the default capture engine."
          x-zh-description: "兼容参数；默认采集引擎忽略。"
          schema:
            type: integer
          example: 50
        - name: timeout
          in: query
          required: false
          description: "Accepted for compatibility; ignored by the default capture engine."
          x-zh-description: "兼容参数；默认采集引擎忽略。"
          schema:
            type: integer
          example: 120
      responses:
        "200":
          description: "XML tree, a JSON summary when meta=1, or a JSON error ({success:false, error})."
          content:
            text/xml:
              schema:
                type: string
              examples:
                ok:
                  summary: Success
                  x-zh-summary: "成功"
                  x-outcome: success
                  value: |-
                    <?xml version="1.0" encoding="UTF-8"?>
                    <XCUIElementTypeApplication type="XCUIElementTypeApplication" name="Settings" label="Settings" enabled="true" visible="true" x="0" y="0" width="390" height="844" ...>
            application/json:
              schema:
                oneOf:
                  - type: object
                    properties:
                      success:
                        type: boolean
                      data:
                        type: object
                        properties:
                          how:
                            type: string
                          targetPid:
                            type: integer
                          targetBundleId:
                            type: string
                          nodes:
                            type: integer
                          bytes:
                            type: integer
                          elapsedMs:
                            type: integer
                          mode:
                            type: integer
                          requestedPid:
                            type: integer
                        additionalProperties: true
                  - $ref: "#/components/schemas/ErrorResponse"
              examples:
                ok:
                  summary: Success
                  x-zh-summary: "成功"
                  x-outcome: success
                  value:
                    success: true
                    data:
                      how: "device->focused-app"
                      targetPid: 1234
                      targetBundleId: com.apple.Preferences
                      nodes: 294
                      bytes: 82637
                      elapsedMs: 313
                      mode: 1
                      requestedPid: 0
                licenseDenied:
                  summary: "Failure: device license not valid (HTTP 200)"
                  x-zh-summary: "失败：设备许可无效（HTTP 200）"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    error: license
                    message: "授权已到期"
                    data:
                      enforced: true
                      valid: false
                      reason: expired
                      message: "授权已到期"
                      builtIn: false
                      hasKey: true
                      account: ""
                      isLogin: false
                      key: "1A2B3C4D…"
                      deviceId: "<device-id>"
                      expiresAt: 1796000000
                      maxDevices: 0
                      online: 0
                      lastOK: 1795990000
                      lastCheck: 1796000100
                      server: "https://api.ketec.top"
  /api/activeAppInfo:
    get:
      operationId: getActiveAppInfo
      summary: Get the foreground app
      description: Returns name, bundleId and pid of the app currently in the foreground, read from the root of the UI tree. Agent mode only (in HID mode use /api/hid/currentAppInfo).
      tags: ["Agent Control"]
      x-zh-summary: "获取前台 App"
      x-zh-description: "返回当前前台 App 的名称、bundleId 与 pid（取自界面树根节点）。仅 Agent 模式（HID 模式请用 /api/hid/currentAppInfo）。"
      x-modes: ["agent"]
      responses:
        "200":
          description: JSON result.
          content:
            application/json:
              schema:
                type: object
                required: ["success", "data"]
                properties:
                  success:
                    type: boolean
                  data:
                    $ref: "#/components/schemas/ActiveAppInfo"
              examples:
                ok:
                  summary: Success
                  x-zh-summary: "成功"
                  x-outcome: success
                  value:
                    success: true
                    data:
                      name: Settings
                      bundleId: com.apple.Preferences
                      pid: 1234
                licenseDenied:
                  summary: "Failure: device license not valid (HTTP 200)"
                  x-zh-summary: "失败：设备许可无效（HTTP 200）"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    error: license
                    message: "授权已到期"
                    data:
                      enforced: true
                      valid: false
                      reason: expired
                      message: "授权已到期"
                      builtIn: false
                      hasKey: true
                      account: ""
                      isLogin: false
                      key: "1A2B3C4D…"
                      deviceId: "<device-id>"
                      expiresAt: 1796000000
                      maxDevices: 0
                      online: 0
                      lastOK: 1795990000
                      lastCheck: 1796000100
                      server: "https://api.ketec.top"
  /api/control/click:
    get:
      operationId: controlClick
      summary: Tap
      description: Taps at a point (physical pixels). In HID mode this request is executed by the HID channel instead.
      tags: ["Agent Control"]
      x-zh-summary: "点击"
      x-zh-description: "在指定坐标点击（物理像素）。处于 HID 模式时，该请求会改由 HID 通道执行。"
      x-modes: ["agent"]
      x-forwarded-in-hid-mode: true
      parameters:
        - name: x
          in: query
          required: true
          description: X coordinate in physical screen pixels.
          x-zh-description: "X 坐标（物理像素）。"
          schema:
            type: number
          example: 540
        - name: "y"
          in: query
          required: true
          description: Y coordinate in physical screen pixels.
          x-zh-description: "Y 坐标（物理像素）。"
          schema:
            type: number
          example: 1200
        - name: duration
          in: query
          required: false
          description: Press duration in milliseconds.
          x-zh-description: "按住时长（毫秒）。"
          schema:
            type: integer
            minimum: 0
            default: 0
          example: 20
        - name: jitter
          in: query
          required: false
          description: Add a small random offset to the touch point.
          x-zh-description: "对点击位置加少量随机偏移。"
          schema:
            type: boolean
            default: false
          example: false
      responses:
        "200":
          description: JSON result.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/SuccessResponse"
              examples:
                ok:
                  summary: Success
                  x-zh-summary: "成功"
                  x-outcome: success
                  value:
                    success: true
                licenseDenied:
                  summary: "Failure: device license not valid (HTTP 200)"
                  x-zh-summary: "失败：设备许可无效（HTTP 200）"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    error: license
                    message: "授权已到期"
                    data:
                      enforced: true
                      valid: false
                      reason: expired
                      message: "授权已到期"
                      builtIn: false
                      hasKey: true
                      account: ""
                      isLogin: false
                      key: "1A2B3C4D…"
                      deviceId: "<device-id>"
                      expiresAt: 1796000000
                      maxDevices: 0
                      online: 0
                      lastOK: 1795990000
                      lastCheck: 1796000100
                      server: "https://api.ketec.top"
        "400":
          description: A required parameter is missing or invalid.
          x-zh-description: "必填参数缺失或无效。"
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
              examples:
                error:
                  summary: "Failure: missing or invalid parameter"
                  x-zh-summary: "失败：参数缺失或无效"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    message: "缺少有效的x或y参数"
        "500":
          description: The event could not be delivered.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
              examples:
                error:
                  summary: "Failure: action failed"
                  x-zh-summary: "失败：执行失败"
                  x-outcome: failure
                  value:
                    success: false
                    action: click
                    message: "事件未送达（未收到成功回调）"
                    errorDomain: ""
                    errorCode: 0
                    agentAvailable: true
        "503":
          $ref: "#/components/responses/AgentUnavailable"
  /api/control/doubleClick:
    get:
      operationId: controlDoubleClick
      summary: Double tap
      description: Double-taps at a point (physical pixels). In HID mode this request is executed by the HID channel instead.
      tags: ["Agent Control"]
      x-zh-summary: "双击"
      x-zh-description: "在指定坐标双击（物理像素）。处于 HID 模式时，该请求会改由 HID 通道执行。"
      x-modes: ["agent"]
      x-forwarded-in-hid-mode: true
      parameters:
        - name: x
          in: query
          required: true
          description: X coordinate in physical screen pixels.
          x-zh-description: "X 坐标（物理像素）。"
          schema:
            type: number
          example: 540
        - name: "y"
          in: query
          required: true
          description: Y coordinate in physical screen pixels.
          x-zh-description: "Y 坐标（物理像素）。"
          schema:
            type: number
          example: 1200
        - name: duration
          in: query
          required: false
          description: Press duration of each tap in milliseconds.
          x-zh-description: "每次按下时长（毫秒）。"
          schema:
            type: integer
            minimum: 0
          example: 20
        - name: interval
          in: query
          required: false
          description: Pause between the two taps in milliseconds.
          x-zh-description: "两次点击的间隔（毫秒）。"
          schema:
            type: integer
            minimum: 0
          example: 100
        - name: jitter
          in: query
          required: false
          description: Add a small random offset.
          x-zh-description: "加少量随机偏移。"
          schema:
            type: boolean
            default: false
          example: false
      responses:
        "200":
          description: JSON result.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/SuccessResponse"
              examples:
                ok:
                  summary: Success
                  x-zh-summary: "成功"
                  x-outcome: success
                  value:
                    success: true
                licenseDenied:
                  summary: "Failure: device license not valid (HTTP 200)"
                  x-zh-summary: "失败：设备许可无效（HTTP 200）"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    error: license
                    message: "授权已到期"
                    data:
                      enforced: true
                      valid: false
                      reason: expired
                      message: "授权已到期"
                      builtIn: false
                      hasKey: true
                      account: ""
                      isLogin: false
                      key: "1A2B3C4D…"
                      deviceId: "<device-id>"
                      expiresAt: 1796000000
                      maxDevices: 0
                      online: 0
                      lastOK: 1795990000
                      lastCheck: 1796000100
                      server: "https://api.ketec.top"
        "400":
          description: A required parameter is missing or invalid.
          x-zh-description: "必填参数缺失或无效。"
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
              examples:
                error:
                  summary: "Failure: missing or invalid parameter"
                  x-zh-summary: "失败：参数缺失或无效"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    message: "缺少有效的x或y参数"
        "503":
          $ref: "#/components/responses/AgentUnavailable"
  /api/control/swipe:
    get:
      operationId: controlSwipe
      summary: Swipe
      description: Swipes from (startX,startY) to (endX,endY), in physical pixels. In HID mode this request is executed by the HID channel instead.
      tags: ["Agent Control"]
      x-zh-summary: "滑动"
      x-zh-description: "从 (startX,startY) 滑到 (endX,endY)，单位物理像素。处于 HID 模式时，该请求会改由 HID 通道执行。"
      x-modes: ["agent"]
      x-forwarded-in-hid-mode: true
      parameters:
        - name: startX
          in: query
          required: true
          description: Start X (pixels).
          x-zh-description: "起点 X（像素）。"
          schema:
            type: number
          example: 540
        - name: startY
          in: query
          required: true
          description: Start Y (pixels).
          x-zh-description: "起点 Y（像素）。"
          schema:
            type: number
          example: 1800
        - name: endX
          in: query
          required: true
          description: End X (pixels).
          x-zh-description: "终点 X（像素）。"
          schema:
            type: number
          example: 540
        - name: endY
          in: query
          required: true
          description: End Y (pixels).
          x-zh-description: "终点 Y（像素）。"
          schema:
            type: number
          example: 600
        - name: duration
          in: query
          required: false
          description: Swipe duration in milliseconds.
          x-zh-description: "滑动时长（毫秒）。"
          schema:
            type: integer
            minimum: 0
          example: 300
        - name: jitter
          in: query
          required: false
          description: Use a slightly irregular, human-like path.
          x-zh-description: "使用略带抖动的拟人轨迹。"
          schema:
            type: boolean
            default: false
          example: false
        - name: steps
          in: query
          required: false
          description: Number of intermediate points on the path.
          x-zh-description: "轨迹中间点数量。"
          schema:
            type: integer
            minimum: 0
          example: 10
      responses:
        "200":
          description: JSON result.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/SuccessResponse"
              examples:
                ok:
                  summary: Success
                  x-zh-summary: "成功"
                  x-outcome: success
                  value:
                    success: true
                licenseDenied:
                  summary: "Failure: device license not valid (HTTP 200)"
                  x-zh-summary: "失败：设备许可无效（HTTP 200）"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    error: license
                    message: "授权已到期"
                    data:
                      enforced: true
                      valid: false
                      reason: expired
                      message: "授权已到期"
                      builtIn: false
                      hasKey: true
                      account: ""
                      isLogin: false
                      key: "1A2B3C4D…"
                      deviceId: "<device-id>"
                      expiresAt: 1796000000
                      maxDevices: 0
                      online: 0
                      lastOK: 1795990000
                      lastCheck: 1796000100
                      server: "https://api.ketec.top"
        "400":
          description: A required parameter is missing or invalid.
          x-zh-description: "必填参数缺失或无效。"
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
              examples:
                error:
                  summary: "Failure: missing or invalid parameter"
                  x-zh-summary: "失败：参数缺失或无效"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    message: "缺少有效的startX/startY/endX/endY参数"
        "503":
          $ref: "#/components/responses/AgentUnavailable"
  /api/control/input:
    get:
      operationId: controlInput
      summary: Type text
      description: "Types text into the focused input field. Requires the keyboard to be up. Supports any Unicode text; when the ketec keyboard is on screen the text is inserted through it. In HID mode this request is executed by the HID channel instead."
      tags: ["Agent Control"]
      x-zh-summary: "输入文字"
      x-zh-description: "向当前焦点输入框输入文字，需键盘已弹出。支持任意 Unicode 文本；ketec 键盘在屏时经键盘扩展插入。处于 HID 模式时，该请求会改由 HID 通道执行。"
      x-modes: ["agent"]
      x-forwarded-in-hid-mode: true
      parameters:
        - name: text
          in: query
          required: true
          description: "Text to type. URL-encode it; a literal \"+\" must be sent as %2B because \"+\" decodes to a space."
          x-zh-description: "要输入的文字。需 URL 编码；\"+\" 会被解码成空格，加号本身请写 %2B。"
          schema:
            type: string
          example: "你好 ketec"
      responses:
        "200":
          description: JSON result.
          content:
            application/json:
              schema:
                type: object
                required: ["success"]
                properties:
                  success:
                    type: boolean
                  data:
                    type: string
                    description: Echo of the typed text.
                  elapsedMs:
                    type: integer
              examples:
                ok:
                  summary: Success
                  x-zh-summary: "成功"
                  x-outcome: success
                  value:
                    success: true
                    data: "你好 ketec"
                    elapsedMs: 120
                licenseDenied:
                  summary: "Failure: device license not valid (HTTP 200)"
                  x-zh-summary: "失败：设备许可无效（HTTP 200）"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    error: license
                    message: "授权已到期"
                    data:
                      enforced: true
                      valid: false
                      reason: expired
                      message: "授权已到期"
                      builtIn: false
                      hasKey: true
                      account: ""
                      isLogin: false
                      key: "1A2B3C4D…"
                      deviceId: "<device-id>"
                      expiresAt: 1796000000
                      maxDevices: 0
                      online: 0
                      lastOK: 1795990000
                      lastCheck: 1796000100
                      server: "https://api.ketec.top"
        "400":
          description: A required parameter is missing or invalid.
          x-zh-description: "必填参数缺失或无效。"
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
              examples:
                error:
                  summary: "Failure: missing or invalid parameter"
                  x-zh-summary: "失败：参数缺失或无效"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    message: "缺少有效的text参数"
        "503":
          $ref: "#/components/responses/AgentUnavailable"
  /api/control/inputSimple:
    get:
      operationId: controlInputSimple
      summary: Type text key by key
      description: Types text with key-by-key timing (about 15 characters per second), for fields that react to individual key events. Requires the keyboard to be up. In HID mode this request is executed by the HID channel instead.
      tags: ["Agent Control"]
      x-zh-summary: "输入字符（逐键）"
      x-zh-description: "按逐键节奏输入文字（约每秒 15 字），适用于需要逐个按键事件的输入框。需键盘已弹出。处于 HID 模式时，该请求会改由 HID 通道执行。"
      x-modes: ["agent"]
      x-forwarded-in-hid-mode: true
      parameters:
        - name: text
          in: query
          required: true
          description: "Text to type (URL-encoded; send \"+\" as %2B)."
          x-zh-description: "要输入的文字（URL 编码；加号写 %2B）。"
          schema:
            type: string
          example: abc123
      responses:
        "200":
          description: JSON result.
          content:
            application/json:
              schema:
                type: object
                required: ["success"]
                properties:
                  success:
                    type: boolean
                  data:
                    type: string
                  elapsedMs:
                    type: integer
              examples:
                ok:
                  summary: Success
                  x-zh-summary: "成功"
                  x-outcome: success
                  value:
                    success: true
                    data: abc123
                    elapsedMs: 420
                licenseDenied:
                  summary: "Failure: device license not valid (HTTP 200)"
                  x-zh-summary: "失败：设备许可无效（HTTP 200）"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    error: license
                    message: "授权已到期"
                    data:
                      enforced: true
                      valid: false
                      reason: expired
                      message: "授权已到期"
                      builtIn: false
                      hasKey: true
                      account: ""
                      isLogin: false
                      key: "1A2B3C4D…"
                      deviceId: "<device-id>"
                      expiresAt: 1796000000
                      maxDevices: 0
                      online: 0
                      lastOK: 1795990000
                      lastCheck: 1796000100
                      server: "https://api.ketec.top"
        "400":
          description: A required parameter is missing or invalid.
          x-zh-description: "必填参数缺失或无效。"
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
              examples:
                error:
                  summary: "Failure: missing or invalid parameter"
                  x-zh-summary: "失败：参数缺失或无效"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    message: "缺少有效的text参数"
        "503":
          $ref: "#/components/responses/AgentUnavailable"
  /api/control/backspace:
    get:
      operationId: controlBackspace
      summary: Backspace
      description: Deletes characters before the cursor. Requires the keyboard to be up. In HID mode this request is executed by the HID channel instead.
      tags: ["Agent Control"]
      x-zh-summary: "退格"
      x-zh-description: "删除光标前的字符，需键盘已弹出。处于 HID 模式时，该请求会改由 HID 通道执行。"
      x-modes: ["agent"]
      x-forwarded-in-hid-mode: true
      parameters:
        - name: count
          in: query
          required: false
          description: Number of characters to delete.
          x-zh-description: "删除字符数。"
          schema:
            type: integer
            minimum: 1
            default: 1
          example: 1
      responses:
        "200":
          description: JSON result.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/SuccessResponse"
              examples:
                ok:
                  summary: Success
                  x-zh-summary: "成功"
                  x-outcome: success
                  value:
                    success: true
                licenseDenied:
                  summary: "Failure: device license not valid (HTTP 200)"
                  x-zh-summary: "失败：设备许可无效（HTTP 200）"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    error: license
                    message: "授权已到期"
                    data:
                      enforced: true
                      valid: false
                      reason: expired
                      message: "授权已到期"
                      builtIn: false
                      hasKey: true
                      account: ""
                      isLogin: false
                      key: "1A2B3C4D…"
                      deviceId: "<device-id>"
                      expiresAt: 1796000000
                      maxDevices: 0
                      online: 0
                      lastOK: 1795990000
                      lastCheck: 1796000100
                      server: "https://api.ketec.top"
        "503":
          $ref: "#/components/responses/AgentUnavailable"
  /api/control/enter:
    get:
      operationId: controlEnter
      summary: Press Return
      description: Presses the Return key. Requires the keyboard to be up. In HID mode this request is executed by the HID channel instead.
      tags: ["Agent Control"]
      x-zh-summary: "回车"
      x-zh-description: "按回车键，需键盘已弹出。处于 HID 模式时，该请求会改由 HID 通道执行。"
      x-modes: ["agent"]
      x-forwarded-in-hid-mode: true
      responses:
        "200":
          description: JSON result.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/SuccessResponse"
              examples:
                ok:
                  summary: Success
                  x-zh-summary: "成功"
                  x-outcome: success
                  value:
                    success: true
                licenseDenied:
                  summary: "Failure: device license not valid (HTTP 200)"
                  x-zh-summary: "失败：设备许可无效（HTTP 200）"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    error: license
                    message: "授权已到期"
                    data:
                      enforced: true
                      valid: false
                      reason: expired
                      message: "授权已到期"
                      builtIn: false
                      hasKey: true
                      account: ""
                      isLogin: false
                      key: "1A2B3C4D…"
                      deviceId: "<device-id>"
                      expiresAt: 1796000000
                      maxDevices: 0
                      online: 0
                      lastOK: 1795990000
                      lastCheck: 1796000100
                      server: "https://api.ketec.top"
        "503":
          $ref: "#/components/responses/AgentUnavailable"
  /api/control/home:
    get:
      operationId: controlHome
      summary: Go to the Home screen
      description: "Returns to the Home screen. Hardware buttons have no Agent-side implementation: the request is relayed to the HID device, so it only works while an ESP32-S3 HID device is connected; otherwise success is false."
      tags: ["Agent Control"]
      x-zh-summary: "返回主页"
      x-zh-description: "回到主屏幕。Agent 通道没有硬件按键实现：请求会转交 HID 设备执行，只有连着 ESP32-S3 HID 设备时才有效，否则返回 success=false。"
      x-modes: ["agent"]
      x-forwarded-in-hid-mode: true
      responses:
        "200":
          description: JSON result.
          content:
            application/json:
              schema:
                type: object
                required: ["success"]
                properties:
                  success:
                    type: boolean
                  channel:
                    type: string
                  button:
                    type: string
                  message:
                    type: string
                  hint:
                    type: string
                additionalProperties: true
              examples:
                ok:
                  summary: Success
                  x-zh-summary: "成功"
                  x-outcome: success
                  value:
                    success: true
                    channel: hid
                    button: home
                licenseDenied:
                  summary: "Failure: device license not valid (HTTP 200)"
                  x-zh-summary: "失败：设备许可无效（HTTP 200）"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    error: license
                    message: "授权已到期"
                    data:
                      enforced: true
                      valid: false
                      reason: expired
                      message: "授权已到期"
                      builtIn: false
                      hasKey: true
                      account: ""
                      isLogin: false
                      key: "1A2B3C4D…"
                      deviceId: "<device-id>"
                      expiresAt: 1796000000
                      maxDevices: 0
                      online: 0
                      lastOK: 1795990000
                      lastCheck: 1796000100
                      server: "https://api.ketec.top"
        "503":
          $ref: "#/components/responses/AgentUnavailable"
  /api/control/recent:
    get:
      operationId: controlRecent
      summary: Open the app switcher
      description: Opens the app switcher. Like /api/control/home, this needs a connected HID device.
      tags: ["Agent Control"]
      x-zh-summary: "App 切换器"
      x-zh-description: "打开多任务切换器。与 /api/control/home 相同，需要连接 HID 设备。"
      x-modes: ["agent"]
      x-forwarded-in-hid-mode: true
      responses:
        "200":
          description: JSON result.
          content:
            application/json:
              schema:
                type: object
                required: ["success"]
                properties:
                  success:
                    type: boolean
                  channel:
                    type: string
                  button:
                    type: string
                  message:
                    type: string
                  hint:
                    type: string
                additionalProperties: true
              examples:
                ok:
                  summary: Success
                  x-zh-summary: "成功"
                  x-outcome: success
                  value:
                    success: true
                    channel: hid
                    button: recent
                licenseDenied:
                  summary: "Failure: device license not valid (HTTP 200)"
                  x-zh-summary: "失败：设备许可无效（HTTP 200）"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    error: license
                    message: "授权已到期"
                    data:
                      enforced: true
                      valid: false
                      reason: expired
                      message: "授权已到期"
                      builtIn: false
                      hasKey: true
                      account: ""
                      isLogin: false
                      key: "1A2B3C4D…"
                      deviceId: "<device-id>"
                      expiresAt: 1796000000
                      maxDevices: 0
                      online: 0
                      lastOK: 1795990000
                      lastCheck: 1796000100
                      server: "https://api.ketec.top"
        "503":
          $ref: "#/components/responses/AgentUnavailable"
  /api/control/pressButton:
    get:
      operationId: controlPressButton
      summary: Press a hardware/media button
      description: "Presses a button through the HID device (needs a connected HID device, see /api/control/home). eject shows/hides the on-screen keyboard; power sends Ctrl+Cmd+Q (the iOS lock-screen shortcut); snapshot sends Cmd+Shift+3 (system screenshot)."
      tags: ["Agent Control"]
      x-zh-summary: "按按钮"
      x-zh-description: "经 HID 设备按下按钮（需连接 HID 设备，见 /api/control/home）。eject 显示/隐藏屏幕键盘；power 发送 Ctrl+Cmd+Q（iOS 锁屏快捷键）；snapshot 发送 Cmd+Shift+3（系统截屏）。"
      x-modes: ["agent"]
      x-forwarded-in-hid-mode: true
      parameters:
        - name: button
          in: query
          required: true
          description: Button name (case-sensitive). appswitch is accepted as an alias of recent.
          x-zh-description: "按钮名（区分大小写）。appswitch 是 recent 的别名。"
          schema:
            type: string
            enum:
              - home
              - volumeup
              - volumedown
              - mute
              - playpause
              - next
              - prev
              - brightnessup
              - brightnessdown
              - eject
              - globe
              - recent
              - search
              - snapshot
              - power
          example: volumeup
      responses:
        "200":
          description: JSON result.
          content:
            application/json:
              schema:
                type: object
                required: ["success"]
                properties:
                  success:
                    type: boolean
                  channel:
                    type: string
                  button:
                    type: string
                  message:
                    type: string
                  hint:
                    type: string
                additionalProperties: true
              examples:
                ok:
                  summary: Success
                  x-zh-summary: "成功"
                  x-outcome: success
                  value:
                    success: true
                    channel: hid
                    button: volumeup
                licenseDenied:
                  summary: "Failure: device license not valid (HTTP 200)"
                  x-zh-summary: "失败：设备许可无效（HTTP 200）"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    error: license
                    message: "授权已到期"
                    data:
                      enforced: true
                      valid: false
                      reason: expired
                      message: "授权已到期"
                      builtIn: false
                      hasKey: true
                      account: ""
                      isLogin: false
                      key: "1A2B3C4D…"
                      deviceId: "<device-id>"
                      expiresAt: 1796000000
                      maxDevices: 0
                      online: 0
                      lastOK: 1795990000
                      lastCheck: 1796000100
                      server: "https://api.ketec.top"
        "400":
          description: A required parameter is missing or invalid.
          x-zh-description: "必填参数缺失或无效。"
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
              examples:
                error:
                  summary: "Failure: missing or invalid parameter"
                  x-zh-summary: "失败：参数缺失或无效"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    message: "缺少有效的button参数"
        "503":
          $ref: "#/components/responses/AgentUnavailable"
  /api/control/sendKey:
    post:
      operationId: controlSendKey
      summary: Send a key combination
      description: "Presses a key or key combination, e.g. [\"COMMAND\",\"a\"]. Keys are single characters or names such as COMMAND, LEFT_SHIFT, LEFT_CTRL, LEFT_ALT, RETURN, ESC, BACKSPACE, TAB, SPACE, DELETE, HOME, END, PAGE_UP, PAGE_DOWN, UP_ARROW, DOWN_ARROW, LEFT_ARROW, RIGHT_ARROW, F1–F12; numbers are taken as USB HID usage codes. A comma-separated `keys` query parameter is also accepted. In HID mode this request is executed by the HID channel instead."
      tags: ["Agent Control"]
      x-zh-summary: "发送组合键"
      x-zh-description: "按下单键或组合键，如 [\"COMMAND\",\"a\"]。键可以是单个字符或键名：COMMAND、LEFT_SHIFT、LEFT_CTRL、LEFT_ALT、RETURN、ESC、BACKSPACE、TAB、SPACE、DELETE、HOME、END、PAGE_UP、PAGE_DOWN、方向键 UP_ARROW 等、F1–F12；数字按 USB HID usage 码处理。也接受逗号分隔的查询参数 `keys`。处于 HID 模式时，该请求会改由 HID 通道执行。"
      x-modes: ["agent"]
      x-forwarded-in-hid-mode: true
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/KeysBody"
            example:
              keys: ["COMMAND", "a"]
      responses:
        "200":
          description: JSON result.
          content:
            application/json:
              schema:
                type: object
                required: ["success"]
                properties:
                  success:
                    type: boolean
                  message:
                    type: string
                  parseErrors:
                    type: array
                    items:
                      type: string
              examples:
                ok:
                  summary: Success
                  x-zh-summary: "成功"
                  x-outcome: success
                  value:
                    success: true
                licenseDenied:
                  summary: "Failure: device license not valid (HTTP 200)"
                  x-zh-summary: "失败：设备许可无效（HTTP 200）"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    error: license
                    message: "授权已到期"
                    data:
                      enforced: true
                      valid: false
                      reason: expired
                      message: "授权已到期"
                      builtIn: false
                      hasKey: true
                      account: ""
                      isLogin: false
                      key: "1A2B3C4D…"
                      deviceId: "<device-id>"
                      expiresAt: 1796000000
                      maxDevices: 0
                      online: 0
                      lastOK: 1795990000
                      lastCheck: 1796000100
                      server: "https://api.ketec.top"
        "400":
          description: A required parameter is missing or invalid.
          x-zh-description: "必填参数缺失或无效。"
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
              examples:
                error:
                  summary: "Failure: missing or invalid parameter"
                  x-zh-summary: "失败：参数缺失或无效"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    message: "请求体为空"
        "503":
          $ref: "#/components/responses/AgentUnavailable"
  /api/control/w3cActions:
    post:
      operationId: controlW3cActions
      summary: Perform W3C pointer actions
      description: "Executes a W3C WebDriver actions payload: pointer sources (touch or mouse) with pointerMove, pointerDown, pointerUp and pause steps; several pointer sources make a multi-touch gesture. Coordinates are physical pixels and durations are milliseconds. Unsupported types are rejected with an explicit message. Agent mode only (not forwarded in HID mode)."
      tags: ["Agent Control"]
      x-zh-summary: "W3C 动作序列"
      x-zh-description: "执行 W3C WebDriver actions：pointer 源（touch 或 mouse），步骤支持 pointerMove、pointerDown、pointerUp、pause；多个 pointer 源即多指手势。坐标为物理像素，时长单位毫秒。不支持的类型会明确报错。仅 Agent 模式（HID 模式下不转投）。"
      x-modes: ["agent"]
      x-forwarded-in-hid-mode: false
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/W3CActionsBody"
            example:
              actions:
                - type: pointer
                  id: finger1
                  parameters:
                    pointerType: touch
                  actions:
                    - type: pointerMove
                      duration: 0
                      x: 540
                      "y": 1800
                    - type: pointerDown
                      button: 0
                    - type: pointerMove
                      duration: 300
                      x: 540
                      "y": 600
                    - type: pointerUp
                      button: 0
      responses:
        "200":
          description: JSON result.
          content:
            application/json:
              schema:
                type: object
                required: ["success"]
                properties:
                  success:
                    type: boolean
                  message:
                    type: string
              examples:
                ok:
                  summary: Success
                  x-zh-summary: "成功"
                  x-outcome: success
                  value:
                    success: true
                licenseDenied:
                  summary: "Failure: device license not valid (HTTP 200)"
                  x-zh-summary: "失败：设备许可无效（HTTP 200）"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    error: license
                    message: "授权已到期"
                    data:
                      enforced: true
                      valid: false
                      reason: expired
                      message: "授权已到期"
                      builtIn: false
                      hasKey: true
                      account: ""
                      isLogin: false
                      key: "1A2B3C4D…"
                      deviceId: "<device-id>"
                      expiresAt: 1796000000
                      maxDevices: 0
                      online: 0
                      lastOK: 1795990000
                      lastCheck: 1796000100
                      server: "https://api.ketec.top"
        "400":
          description: A required parameter is missing or invalid.
          x-zh-description: "必填参数缺失或无效。"
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
              examples:
                error:
                  summary: "Failure: missing or invalid parameter"
                  x-zh-summary: "失败：参数缺失或无效"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    message: "请求体为空"
        "503":
          $ref: "#/components/responses/AgentUnavailable"
  /api/control/startApp:
    get:
      operationId: controlStartApp
      summary: Launch an app
      description: "Launches the app with the given bundle id. If the Agent call fails, ketec falls back to the system workspace API and marks the reply with deviation=true. In HID mode this request is executed by the HID channel instead."
      tags: ["Agent Control"]
      x-zh-summary: "打开 App"
      x-zh-description: "按 bundleId 启动 App。Agent 调用失败时会回落到系统 workspace 接口，并在回包中标记 deviation=true。处于 HID 模式时，该请求会改由 HID 通道执行。"
      x-modes: ["agent"]
      x-forwarded-in-hid-mode: true
      parameters:
        - name: bundleId
          in: query
          required: true
          description: Bundle identifier of the target app.
          x-zh-description: "目标 App 的 bundleId。"
          schema:
            type: string
          example: com.apple.Preferences
      responses:
        "200":
          description: JSON result.
          content:
            application/json:
              schema:
                type: object
                required: ["success"]
                properties:
                  success:
                    type: boolean
                  via:
                    type: string
                    description: Channel that performed the action.
                  bundleId:
                    type: string
                  action:
                    type: string
                  deviation:
                    type: boolean
                  agError:
                    type: string
                  note:
                    type: string
                additionalProperties: true
              examples:
                ok:
                  summary: Success
                  x-zh-summary: "成功"
                  x-outcome: success
                  value:
                    success: true
                    via: xct-ag
                    strict: false
                    bundleId: com.apple.Preferences
                    action: startApp
                licenseDenied:
                  summary: "Failure: device license not valid (HTTP 200)"
                  x-zh-summary: "失败：设备许可无效（HTTP 200）"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    error: license
                    message: "授权已到期"
                    data:
                      enforced: true
                      valid: false
                      reason: expired
                      message: "授权已到期"
                      builtIn: false
                      hasKey: true
                      account: ""
                      isLogin: false
                      key: "1A2B3C4D…"
                      deviceId: "<device-id>"
                      expiresAt: 1796000000
                      maxDevices: 0
                      online: 0
                      lastOK: 1795990000
                      lastCheck: 1796000100
                      server: "https://api.ketec.top"
        "400":
          description: A required parameter is missing or invalid.
          x-zh-description: "必填参数缺失或无效。"
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
              examples:
                error:
                  summary: "Failure: missing or invalid parameter"
                  x-zh-summary: "失败：参数缺失或无效"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    message: "缺少有效的bundleId参数"
        "503":
          $ref: "#/components/responses/AgentUnavailable"
  /api/control/activateApp:
    get:
      operationId: controlActivateApp
      summary: Bring an app to the foreground
      description: "Brings the app with the given bundle id to the foreground, launching it if needed. If the Agent call fails, ketec falls back to the system workspace API and marks the reply with deviation=true. In HID mode this request is executed by the HID channel instead."
      tags: ["Agent Control"]
      x-zh-summary: "激活 App（拉到前台）"
      x-zh-description: "把指定 bundleId 的 App 拉到前台，未运行时会启动。Agent 调用失败时会回落到系统 workspace 接口，并在回包中标记 deviation=true。处于 HID 模式时，该请求会改由 HID 通道执行。"
      x-modes: ["agent"]
      x-forwarded-in-hid-mode: true
      parameters:
        - name: bundleId
          in: query
          required: true
          description: Bundle identifier of the target app.
          x-zh-description: "目标 App 的 bundleId。"
          schema:
            type: string
          example: com.apple.Preferences
      responses:
        "200":
          description: JSON result.
          content:
            application/json:
              schema:
                type: object
                required: ["success"]
                properties:
                  success:
                    type: boolean
                  via:
                    type: string
                    description: Channel that performed the action.
                  bundleId:
                    type: string
                  action:
                    type: string
                  deviation:
                    type: boolean
                  agError:
                    type: string
                  note:
                    type: string
                additionalProperties: true
              examples:
                ok:
                  summary: Success
                  x-zh-summary: "成功"
                  x-outcome: success
                  value:
                    success: true
                    via: xct-ag
                    strict: false
                    bundleId: com.apple.Preferences
                    action: activateApp
                licenseDenied:
                  summary: "Failure: device license not valid (HTTP 200)"
                  x-zh-summary: "失败：设备许可无效（HTTP 200）"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    error: license
                    message: "授权已到期"
                    data:
                      enforced: true
                      valid: false
                      reason: expired
                      message: "授权已到期"
                      builtIn: false
                      hasKey: true
                      account: ""
                      isLogin: false
                      key: "1A2B3C4D…"
                      deviceId: "<device-id>"
                      expiresAt: 1796000000
                      maxDevices: 0
                      online: 0
                      lastOK: 1795990000
                      lastCheck: 1796000100
                      server: "https://api.ketec.top"
        "400":
          description: A required parameter is missing or invalid.
          x-zh-description: "必填参数缺失或无效。"
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
              examples:
                error:
                  summary: "Failure: missing or invalid parameter"
                  x-zh-summary: "失败：参数缺失或无效"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    message: "缺少有效的bundleId参数"
        "503":
          $ref: "#/components/responses/AgentUnavailable"
  /api/control/stopApp:
    get:
      operationId: controlStopApp
      summary: Terminate an app
      description: "Terminates the app with the given bundle id. If the Agent call fails, ketec falls back to the system workspace API and marks the reply with deviation=true. In HID mode this request is executed by the HID channel instead."
      tags: ["Agent Control"]
      x-zh-summary: "停止 App"
      x-zh-description: "结束指定 bundleId 的 App 进程。Agent 调用失败时会回落到系统 workspace 接口，并在回包中标记 deviation=true。处于 HID 模式时，该请求会改由 HID 通道执行。"
      x-modes: ["agent"]
      x-forwarded-in-hid-mode: true
      parameters:
        - name: bundleId
          in: query
          required: true
          description: Bundle identifier of the target app.
          x-zh-description: "目标 App 的 bundleId。"
          schema:
            type: string
          example: com.apple.Preferences
      responses:
        "200":
          description: JSON result.
          content:
            application/json:
              schema:
                type: object
                required: ["success"]
                properties:
                  success:
                    type: boolean
                  via:
                    type: string
                    description: Channel that performed the action.
                  bundleId:
                    type: string
                  action:
                    type: string
                  deviation:
                    type: boolean
                  agError:
                    type: string
                  note:
                    type: string
                additionalProperties: true
              examples:
                ok:
                  summary: Success
                  x-zh-summary: "成功"
                  x-outcome: success
                  value:
                    success: true
                    via: xct-ag
                    strict: false
                    bundleId: com.apple.Preferences
                    action: stopApp
                licenseDenied:
                  summary: "Failure: device license not valid (HTTP 200)"
                  x-zh-summary: "失败：设备许可无效（HTTP 200）"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    error: license
                    message: "授权已到期"
                    data:
                      enforced: true
                      valid: false
                      reason: expired
                      message: "授权已到期"
                      builtIn: false
                      hasKey: true
                      account: ""
                      isLogin: false
                      key: "1A2B3C4D…"
                      deviceId: "<device-id>"
                      expiresAt: 1796000000
                      maxDevices: 0
                      online: 0
                      lastOK: 1795990000
                      lastCheck: 1796000100
                      server: "https://api.ketec.top"
        "400":
          description: A required parameter is missing or invalid.
          x-zh-description: "必填参数缺失或无效。"
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
              examples:
                error:
                  summary: "Failure: missing or invalid parameter"
                  x-zh-summary: "失败：参数缺失或无效"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    message: "缺少有效的bundleId参数"
        "503":
          $ref: "#/components/responses/AgentUnavailable"
  /api/control/openURL:
    get:
      operationId: controlOpenUrl
      summary: Open a URL
      description: "Opens a URL or URL scheme (e.g. https://..., prefs:...) with the system. In HID mode this request is executed by the HID channel instead."
      tags: ["Agent Control"]
      x-zh-summary: "打开 URL"
      x-zh-description: "用系统打开 URL 或 URL scheme（如 https://…、prefs:…）。处于 HID 模式时，该请求会改由 HID 通道执行。"
      x-modes: ["agent"]
      x-forwarded-in-hid-mode: true
      parameters:
        - name: url
          in: query
          required: true
          description: URL to open (URL-encoded).
          x-zh-description: "要打开的 URL（需 URL 编码）。"
          schema:
            type: string
          example: "https://example.com"
      responses:
        "200":
          description: JSON result.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/SuccessResponse"
              examples:
                ok:
                  summary: Success
                  x-zh-summary: "成功"
                  x-outcome: success
                  value:
                    success: true
                licenseDenied:
                  summary: "Failure: device license not valid (HTTP 200)"
                  x-zh-summary: "失败：设备许可无效（HTTP 200）"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    error: license
                    message: "授权已到期"
                    data:
                      enforced: true
                      valid: false
                      reason: expired
                      message: "授权已到期"
                      builtIn: false
                      hasKey: true
                      account: ""
                      isLogin: false
                      key: "1A2B3C4D…"
                      deviceId: "<device-id>"
                      expiresAt: 1796000000
                      maxDevices: 0
                      online: 0
                      lastOK: 1795990000
                      lastCheck: 1796000100
                      server: "https://api.ketec.top"
        "400":
          description: A required parameter is missing or invalid.
          x-zh-description: "必填参数缺失或无效。"
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
              examples:
                error:
                  summary: "Failure: missing or invalid parameter"
                  x-zh-summary: "失败：参数缺失或无效"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    message: "缺少有效的url参数"
        "503":
          $ref: "#/components/responses/AgentUnavailable"
  /api/hid/click:
    get:
      operationId: hidClick
      summary: Tap (HID)
      description: "Taps at a point through the ESP32-S3 HID device. Coordinates are physical screen pixels (1:1 with the screenshot), not logical points. The reply reports requested vs. sent coordinates and whether the point was out of range."
      tags: ["HID Control"]
      x-zh-summary: "点击（HID）"
      x-zh-description: "经 ESP32-S3 HID 设备在指定坐标点击。坐标为物理像素（与截图 1:1），不是逻辑点。回包给出请求坐标、实际发送坐标以及是否越界。"
      x-modes: ["hid"]
      parameters:
        - name: x
          in: query
          required: true
          description: X coordinate in physical screen pixels.
          x-zh-description: "X 坐标（物理像素）。"
          schema:
            type: number
          example: 540
        - name: "y"
          in: query
          required: true
          description: Y coordinate in physical screen pixels.
          x-zh-description: "Y 坐标（物理像素）。"
          schema:
            type: number
          example: 1200
        - name: duration
          in: query
          required: false
          description: Press duration in milliseconds.
          x-zh-description: "按住时长（毫秒）。"
          schema:
            type: integer
            minimum: 0
          example: 20
        - name: mode
          in: query
          required: false
          description: "drag = press, move a few pixels, release; helps with some system alerts and menu buttons."
          x-zh-description: "drag = 按下、小幅移动、抬起；对部分系统弹框和菜单按钮更可靠。"
          schema:
            type: string
            enum: ["drag"]
          example: drag
      responses:
        "200":
          description: JSON result.
          content:
            application/json:
              schema:
                type: object
                required: ["success"]
                properties:
                  success:
                    type: boolean
                  data:
                    type: object
                    additionalProperties: true
                    properties:
                      requested:
                        $ref: "#/components/schemas/Point"
                      sent:
                        $ref: "#/components/schemas/Point"
                      screenPx:
                        type: object
                        properties:
                          width:
                            type: number
                          height:
                            type: number
                      outOfRange:
                        type: boolean
                      mode:
                        type: string
                      pointerMode:
                        type: string
                      hint:
                        type: string
              examples:
                ok:
                  summary: Success
                  x-zh-summary: "成功"
                  x-outcome: success
                  value:
                    success: true
                    data:
                      requested:
                        x: 540
                        "y": 1200
                      sent:
                        x: 540
                        "y": 1200
                      screenPx:
                        width: 1170
                        height: 2532
                      outOfRange: false
                      mode: absClick
                      pointerMode: absolute
                      hint: ok
                licenseDenied:
                  summary: "Failure: device license not valid (HTTP 200)"
                  x-zh-summary: "失败：设备许可无效（HTTP 200）"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    error: license
                    message: "授权已到期"
                    data:
                      enforced: true
                      valid: false
                      reason: expired
                      message: "授权已到期"
                      builtIn: false
                      hasKey: true
                      account: ""
                      isLogin: false
                      key: "1A2B3C4D…"
                      deviceId: "<device-id>"
                      expiresAt: 1796000000
                      maxDevices: 0
                      online: 0
                      lastOK: 1795990000
                      lastCheck: 1796000100
                      server: "https://api.ketec.top"
        "400":
          description: A required parameter is missing or invalid.
          x-zh-description: "必填参数缺失或无效。"
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
              examples:
                error:
                  summary: "Failure: missing or invalid parameter"
                  x-zh-summary: "失败：参数缺失或无效"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    message: "缺少有效的x或y参数"
  /api/hid/doubleClick:
    get:
      operationId: hidDoubleClick
      summary: Double tap (HID)
      description: "Double-taps through the HID device. Coordinates are physical screen pixels (1:1 with the screenshot), not logical points."
      tags: ["HID Control"]
      x-zh-summary: "双击（HID）"
      x-zh-description: "经 HID 设备双击。坐标为物理像素（与截图 1:1），不是逻辑点。"
      x-modes: ["hid"]
      parameters:
        - name: x
          in: query
          required: true
          description: X coordinate in physical screen pixels.
          x-zh-description: "X 坐标（物理像素）。"
          schema:
            type: number
          example: 540
        - name: "y"
          in: query
          required: true
          description: Y coordinate in physical screen pixels.
          x-zh-description: "Y 坐标（物理像素）。"
          schema:
            type: number
          example: 1200
        - name: duration
          in: query
          required: false
          description: Press duration of each tap in milliseconds.
          x-zh-description: "每次按下时长（毫秒）。"
          schema:
            type: integer
            minimum: 1
            default: 20
          example: 20
        - name: interval
          in: query
          required: false
          description: Pause between taps in milliseconds.
          x-zh-description: "两次点击间隔（毫秒）。"
          schema:
            type: integer
            minimum: 1
            default: 100
          example: 100
      responses:
        "200":
          description: JSON result.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/SuccessResponse"
              examples:
                ok:
                  summary: Success
                  x-zh-summary: "成功"
                  x-outcome: success
                  value:
                    success: true
                licenseDenied:
                  summary: "Failure: device license not valid (HTTP 200)"
                  x-zh-summary: "失败：设备许可无效（HTTP 200）"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    error: license
                    message: "授权已到期"
                    data:
                      enforced: true
                      valid: false
                      reason: expired
                      message: "授权已到期"
                      builtIn: false
                      hasKey: true
                      account: ""
                      isLogin: false
                      key: "1A2B3C4D…"
                      deviceId: "<device-id>"
                      expiresAt: 1796000000
                      maxDevices: 0
                      online: 0
                      lastOK: 1795990000
                      lastCheck: 1796000100
                      server: "https://api.ketec.top"
        "400":
          description: A required parameter is missing or invalid.
          x-zh-description: "必填参数缺失或无效。"
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
              examples:
                error:
                  summary: "Failure: missing or invalid parameter"
                  x-zh-summary: "失败：参数缺失或无效"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    message: "缺少有效的x或y参数"
  /api/hid/swipe:
    get:
      operationId: hidSwipe
      summary: Swipe (HID)
      description: "Swipes through the HID device along a multi-point path. Coordinates are physical screen pixels (1:1 with the screenshot), not logical points."
      tags: ["HID Control"]
      x-zh-summary: "滑动（HID）"
      x-zh-description: "经 HID 设备沿多点轨迹滑动。坐标为物理像素（与截图 1:1），不是逻辑点。"
      x-modes: ["hid"]
      parameters:
        - name: startX
          in: query
          required: true
          description: Start X (pixels).
          x-zh-description: "起点 X（像素）。"
          schema:
            type: number
          example: 540
        - name: startY
          in: query
          required: true
          description: Start Y (pixels).
          x-zh-description: "起点 Y（像素）。"
          schema:
            type: number
          example: 1800
        - name: endX
          in: query
          required: true
          description: End X (pixels).
          x-zh-description: "终点 X（像素）。"
          schema:
            type: number
          example: 540
        - name: endY
          in: query
          required: true
          description: End Y (pixels).
          x-zh-description: "终点 Y（像素）。"
          schema:
            type: number
          example: 600
        - name: jitter
          in: query
          required: false
          description: Add random deviation to intermediate points.
          x-zh-description: "中间点加随机偏移。"
          schema:
            type: boolean
            default: false
          example: true
        - name: steps
          in: query
          required: false
          description: Number of path segments.
          x-zh-description: "轨迹分段数。"
          schema:
            type: integer
            minimum: 1
            default: 10
          example: 10
        - name: duration
          in: query
          required: false
          description: "Approximate total duration in milliseconds (0 = firmware default speed)."
          x-zh-description: "大致总时长（毫秒，0 = 固件默认速度）。"
          schema:
            type: integer
            minimum: 0
            default: 0
          example: 300
      responses:
        "200":
          description: JSON result.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/SuccessResponse"
              examples:
                ok:
                  summary: Success
                  x-zh-summary: "成功"
                  x-outcome: success
                  value:
                    success: true
                licenseDenied:
                  summary: "Failure: device license not valid (HTTP 200)"
                  x-zh-summary: "失败：设备许可无效（HTTP 200）"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    error: license
                    message: "授权已到期"
                    data:
                      enforced: true
                      valid: false
                      reason: expired
                      message: "授权已到期"
                      builtIn: false
                      hasKey: true
                      account: ""
                      isLogin: false
                      key: "1A2B3C4D…"
                      deviceId: "<device-id>"
                      expiresAt: 1796000000
                      maxDevices: 0
                      online: 0
                      lastOK: 1795990000
                      lastCheck: 1796000100
                      server: "https://api.ketec.top"
        "400":
          description: A required parameter is missing or invalid.
          x-zh-description: "必填参数缺失或无效。"
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
              examples:
                error:
                  summary: "Failure: missing or invalid parameter"
                  x-zh-summary: "失败：参数缺失或无效"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    message: "缺少有效的startX/startY/endX/endY参数"
  /api/hid/move:
    get:
      operationId: hidMove
      summary: Move the pointer (HID)
      description: "Moves the HID pointer to a point without pressing. Combine with mouseDown / mouseUp for custom drags. Coordinates are physical screen pixels (1:1 with the screenshot), not logical points."
      tags: ["HID Control"]
      x-zh-summary: "移动坐标（HID）"
      x-zh-description: "把 HID 指针移动到指定位置（不按下）。配合 mouseDown / mouseUp 可组合自定义拖拽。坐标为物理像素（与截图 1:1），不是逻辑点。"
      x-modes: ["hid"]
      parameters:
        - name: x
          in: query
          required: true
          description: X coordinate in physical screen pixels.
          x-zh-description: "X 坐标（物理像素）。"
          schema:
            type: number
          example: 540
        - name: "y"
          in: query
          required: true
          description: Y coordinate in physical screen pixels.
          x-zh-description: "Y 坐标（物理像素）。"
          schema:
            type: number
          example: 1200
      responses:
        "200":
          description: JSON result.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/SuccessResponse"
              examples:
                ok:
                  summary: Success
                  x-zh-summary: "成功"
                  x-outcome: success
                  value:
                    success: true
                licenseDenied:
                  summary: "Failure: device license not valid (HTTP 200)"
                  x-zh-summary: "失败：设备许可无效（HTTP 200）"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    error: license
                    message: "授权已到期"
                    data:
                      enforced: true
                      valid: false
                      reason: expired
                      message: "授权已到期"
                      builtIn: false
                      hasKey: true
                      account: ""
                      isLogin: false
                      key: "1A2B3C4D…"
                      deviceId: "<device-id>"
                      expiresAt: 1796000000
                      maxDevices: 0
                      online: 0
                      lastOK: 1795990000
                      lastCheck: 1796000100
                      server: "https://api.ketec.top"
        "400":
          description: A required parameter is missing or invalid.
          x-zh-description: "必填参数缺失或无效。"
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
              examples:
                error:
                  summary: "Failure: missing or invalid parameter"
                  x-zh-summary: "失败：参数缺失或无效"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    message: "缺少有效的x或y参数"
  /api/hid/mouseDown:
    get:
      operationId: hidMouseDown
      summary: Press the pointer (HID)
      description: Presses at the current HID pointer position and keeps holding until /api/hid/mouseUp.
      tags: ["HID Control"]
      x-zh-summary: "鼠标按下（HID）"
      x-zh-description: "在当前 HID 指针位置按下并保持，直到调用 /api/hid/mouseUp。"
      x-modes: ["hid"]
      responses:
        "200":
          description: JSON result.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/SuccessResponse"
              examples:
                ok:
                  summary: Success
                  x-zh-summary: "成功"
                  x-outcome: success
                  value:
                    success: true
                licenseDenied:
                  summary: "Failure: device license not valid (HTTP 200)"
                  x-zh-summary: "失败：设备许可无效（HTTP 200）"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    error: license
                    message: "授权已到期"
                    data:
                      enforced: true
                      valid: false
                      reason: expired
                      message: "授权已到期"
                      builtIn: false
                      hasKey: true
                      account: ""
                      isLogin: false
                      key: "1A2B3C4D…"
                      deviceId: "<device-id>"
                      expiresAt: 1796000000
                      maxDevices: 0
                      online: 0
                      lastOK: 1795990000
                      lastCheck: 1796000100
                      server: "https://api.ketec.top"
  /api/hid/mouseUp:
    get:
      operationId: hidMouseUp
      summary: Release the pointer (HID)
      description: Releases the HID pointer.
      tags: ["HID Control"]
      x-zh-summary: "鼠标抬起（HID）"
      x-zh-description: "抬起 HID 指针。"
      x-modes: ["hid"]
      responses:
        "200":
          description: JSON result.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/SuccessResponse"
              examples:
                ok:
                  summary: Success
                  x-zh-summary: "成功"
                  x-outcome: success
                  value:
                    success: true
                licenseDenied:
                  summary: "Failure: device license not valid (HTTP 200)"
                  x-zh-summary: "失败：设备许可无效（HTTP 200）"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    error: license
                    message: "授权已到期"
                    data:
                      enforced: true
                      valid: false
                      reason: expired
                      message: "授权已到期"
                      builtIn: false
                      hasKey: true
                      account: ""
                      isLogin: false
                      key: "1A2B3C4D…"
                      deviceId: "<device-id>"
                      expiresAt: 1796000000
                      maxDevices: 0
                      online: 0
                      lastOK: 1795990000
                      lastCheck: 1796000100
                      server: "https://api.ketec.top"
  /api/hid/input:
    get:
      operationId: hidInput
      summary: Type text (HID)
      description: "Types text in HID mode (requires the keyboard to be up). Order: ketec keyboard extension if it is on screen, otherwise clipboard + Cmd+V through the HID device. `stage` tells which path was used; success on stage 3-custom1 cannot be confirmed."
      tags: ["HID Control"]
      x-zh-summary: "输入文字（HID）"
      x-zh-description: "HID 模式下输入文字（需键盘已弹出）。顺序：ketec 键盘在屏时走键盘扩展，否则经 HID 设备「剪贴板 + Cmd+V」。`stage` 表示实际走的路径；stage 为 3-custom1 时无法确认是否上屏。"
      x-modes: ["hid"]
      parameters:
        - name: text
          in: query
          required: true
          description: "Text to type (any Unicode; URL-encoded, send \"+\" as %2B). Also accepted as JSON body {\"text\": ...}."
          x-zh-description: "要输入的文字（任意 Unicode；URL 编码，加号写 %2B）。也可用 JSON 请求体 {\"text\": ...}。"
          schema:
            type: string
          example: "你好"
      responses:
        "200":
          description: JSON result.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/HidInputResult"
              examples:
                ok:
                  summary: Success
                  x-zh-summary: "成功"
                  x-outcome: success
                  value:
                    success: true
                    data: true
                    stage: "2-clipboard"
                licenseDenied:
                  summary: "Failure: device license not valid (HTTP 200)"
                  x-zh-summary: "失败：设备许可无效（HTTP 200）"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    error: license
                    message: "授权已到期"
                    data:
                      enforced: true
                      valid: false
                      reason: expired
                      message: "授权已到期"
                      builtIn: false
                      hasKey: true
                      account: ""
                      isLogin: false
                      key: "1A2B3C4D…"
                      deviceId: "<device-id>"
                      expiresAt: 1796000000
                      maxDevices: 0
                      online: 0
                      lastOK: 1795990000
                      lastCheck: 1796000100
                      server: "https://api.ketec.top"
        "400":
          description: A required parameter is missing or invalid.
          x-zh-description: "必填参数缺失或无效。"
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
              examples:
                error:
                  summary: "Failure: missing or invalid parameter"
                  x-zh-summary: "失败：参数缺失或无效"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    message: "缺少有效的text参数"
        "503":
          description: No usable input path.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/HidInputResult"
              examples:
                error:
                  summary: "Failure: channel unavailable"
                  x-zh-summary: "失败：通道不可用"
                  x-outcome: failure
                  value:
                    success: false
                    reason: "剪贴板粘贴失败"
                    channel: hid/input
                    stage: "2-clipboard"
  /api/hid/inputSimple:
    get:
      operationId: hidInputSimple
      summary: Type ASCII key by key (HID)
      description: "Types printable ASCII characters as individual key presses (requires the keyboard to be up). Non-ASCII text is rejected with 400; use /api/hid/input for Chinese and other text."
      tags: ["HID Control"]
      x-zh-summary: "输入字符（HID，仅 ASCII）"
      x-zh-description: "以逐个按键方式输入可打印 ASCII 字符（需键盘已弹出）。非 ASCII 文本返回 400；中文等请用 /api/hid/input。"
      x-modes: ["hid"]
      parameters:
        - name: text
          in: query
          required: true
          description: "ASCII text to type (URL-encoded; send \"+\" as %2B)."
          x-zh-description: "要输入的 ASCII 文本（URL 编码；加号写 %2B）。"
          schema:
            type: string
          example: abc123
      responses:
        "200":
          description: JSON result.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/HidInputResult"
              examples:
                ok:
                  summary: Success
                  x-zh-summary: "成功"
                  x-outcome: success
                  value:
                    success: true
                licenseDenied:
                  summary: "Failure: device license not valid (HTTP 200)"
                  x-zh-summary: "失败：设备许可无效（HTTP 200）"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    error: license
                    message: "授权已到期"
                    data:
                      enforced: true
                      valid: false
                      reason: expired
                      message: "授权已到期"
                      builtIn: false
                      hasKey: true
                      account: ""
                      isLogin: false
                      key: "1A2B3C4D…"
                      deviceId: "<device-id>"
                      expiresAt: 1796000000
                      maxDevices: 0
                      online: 0
                      lastOK: 1795990000
                      lastCheck: 1796000100
                      server: "https://api.ketec.top"
        "400":
          description: A required parameter is missing or invalid.
          x-zh-description: "必填参数缺失或无效。"
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
              examples:
                error:
                  summary: "Failure: missing or invalid parameter"
                  x-zh-summary: "失败：参数缺失或无效"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    message: "缺少有效的text参数"
        "503":
          description: No usable input path.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/HidInputResult"
              examples:
                error:
                  summary: "Failure: channel unavailable"
                  x-zh-summary: "失败：通道不可用"
                  x-outcome: failure
                  value:
                    success: false
                    reason: "键盘扩展不在位，且 HID 未连接；inputSimple 无法执行"
                    channel: hid/inputSimple
                    stage: "4-fail"
  /api/hid/backspace:
    get:
      operationId: hidBackspace
      summary: Backspace (HID)
      description: Sends Backspace key presses through the HID device (keyboard must be up).
      tags: ["HID Control"]
      x-zh-summary: "退格（HID）"
      x-zh-description: "经 HID 设备发送退格键（需键盘已弹出）。"
      x-modes: ["hid"]
      parameters:
        - name: count
          in: query
          required: false
          description: Number of presses.
          x-zh-description: "按键次数。"
          schema:
            type: integer
            minimum: 1
            default: 1
          example: 1
      responses:
        "200":
          description: JSON result.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/SuccessResponse"
              examples:
                ok:
                  summary: Success
                  x-zh-summary: "成功"
                  x-outcome: success
                  value:
                    success: true
                licenseDenied:
                  summary: "Failure: device license not valid (HTTP 200)"
                  x-zh-summary: "失败：设备许可无效（HTTP 200）"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    error: license
                    message: "授权已到期"
                    data:
                      enforced: true
                      valid: false
                      reason: expired
                      message: "授权已到期"
                      builtIn: false
                      hasKey: true
                      account: ""
                      isLogin: false
                      key: "1A2B3C4D…"
                      deviceId: "<device-id>"
                      expiresAt: 1796000000
                      maxDevices: 0
                      online: 0
                      lastOK: 1795990000
                      lastCheck: 1796000100
                      server: "https://api.ketec.top"
  /api/hid/enter:
    get:
      operationId: hidEnter
      summary: Press Return (HID)
      description: Sends the Return key through the HID device (keyboard must be up).
      tags: ["HID Control"]
      x-zh-summary: "回车（HID）"
      x-zh-description: "经 HID 设备发送回车键（需键盘已弹出）。"
      x-modes: ["hid"]
      responses:
        "200":
          description: JSON result.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/SuccessResponse"
              examples:
                ok:
                  summary: Success
                  x-zh-summary: "成功"
                  x-outcome: success
                  value:
                    success: true
                licenseDenied:
                  summary: "Failure: device license not valid (HTTP 200)"
                  x-zh-summary: "失败：设备许可无效（HTTP 200）"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    error: license
                    message: "授权已到期"
                    data:
                      enforced: true
                      valid: false
                      reason: expired
                      message: "授权已到期"
                      builtIn: false
                      hasKey: true
                      account: ""
                      isLogin: false
                      key: "1A2B3C4D…"
                      deviceId: "<device-id>"
                      expiresAt: 1796000000
                      maxDevices: 0
                      online: 0
                      lastOK: 1795990000
                      lastCheck: 1796000100
                      server: "https://api.ketec.top"
  /api/hid/home:
    get:
      operationId: hidHome
      summary: Go to the Home screen (HID)
      description: Sends the Home consumer key through the HID device.
      tags: ["HID Control"]
      x-zh-summary: "返回主页（HID）"
      x-zh-description: "经 HID 设备发送 Home 键。"
      x-modes: ["hid"]
      responses:
        "200":
          description: JSON result.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/SuccessResponse"
              examples:
                ok:
                  summary: Success
                  x-zh-summary: "成功"
                  x-outcome: success
                  value:
                    success: true
                licenseDenied:
                  summary: "Failure: device license not valid (HTTP 200)"
                  x-zh-summary: "失败：设备许可无效（HTTP 200）"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    error: license
                    message: "授权已到期"
                    data:
                      enforced: true
                      valid: false
                      reason: expired
                      message: "授权已到期"
                      builtIn: false
                      hasKey: true
                      account: ""
                      isLogin: false
                      key: "1A2B3C4D…"
                      deviceId: "<device-id>"
                      expiresAt: 1796000000
                      maxDevices: 0
                      online: 0
                      lastOK: 1795990000
                      lastCheck: 1796000100
                      server: "https://api.ketec.top"
  /api/hid/recent:
    get:
      operationId: hidRecent
      summary: Open the app switcher (HID)
      description: Presses Home twice through the HID device to open the app switcher.
      tags: ["HID Control"]
      x-zh-summary: "App 切换器（HID）"
      x-zh-description: "经 HID 设备连按两次 Home 打开多任务。"
      x-modes: ["hid"]
      responses:
        "200":
          description: JSON result.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/SuccessResponse"
              examples:
                ok:
                  summary: Success
                  x-zh-summary: "成功"
                  x-outcome: success
                  value:
                    success: true
                licenseDenied:
                  summary: "Failure: device license not valid (HTTP 200)"
                  x-zh-summary: "失败：设备许可无效（HTTP 200）"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    error: license
                    message: "授权已到期"
                    data:
                      enforced: true
                      valid: false
                      reason: expired
                      message: "授权已到期"
                      builtIn: false
                      hasKey: true
                      account: ""
                      isLogin: false
                      key: "1A2B3C4D…"
                      deviceId: "<device-id>"
                      expiresAt: 1796000000
                      maxDevices: 0
                      online: 0
                      lastOK: 1795990000
                      lastCheck: 1796000100
                      server: "https://api.ketec.top"
  /api/hid/pressButton:
    get:
      operationId: hidPressButton
      summary: Press a hardware/media button (HID)
      description: "Presses a button through the HID device. eject toggles the on-screen keyboard (optional state=show|hide) and returns extra detail in `data`; power sends Ctrl+Cmd+Q (the iOS lock-screen shortcut); snapshot sends Cmd+Shift+3 (system screenshot). Unknown names return success=false."
      tags: ["HID Control"]
      x-zh-summary: "按按钮（HID）"
      x-zh-description: "经 HID 设备按下按钮。eject 切换屏幕键盘显示（可选 state=show|hide），并在 `data` 中给出详情；power 发送 Ctrl+Cmd+Q（iOS 锁屏快捷键）；snapshot 发送 Cmd+Shift+3（系统截屏）。未知按钮名返回 success=false。"
      x-modes: ["hid"]
      parameters:
        - name: button
          in: query
          required: true
          description: Button name (case-sensitive).
          x-zh-description: "按钮名（区分大小写）。"
          schema:
            type: string
            enum:
              - home
              - volumeup
              - volumedown
              - mute
              - playpause
              - next
              - prev
              - brightnessup
              - brightnessdown
              - eject
              - globe
              - recent
              - search
              - snapshot
              - power
          example: home
        - name: state
          in: query
          required: false
          description: "Only for button=eject: force show or hide instead of toggling."
          x-zh-description: "仅 button=eject：强制显示或隐藏，而不是切换。"
          schema:
            type: string
            enum: ["show", "hide"]
          example: hide
      responses:
        "200":
          description: JSON result.
          content:
            application/json:
              schema:
                type: object
                required: ["success"]
                properties:
                  success:
                    type: boolean
                  button:
                    type: string
                  channel:
                    type: string
                  data:
                    type: object
                    additionalProperties: true
                  reason:
                    type: string
                  hint:
                    type: string
                additionalProperties: true
              examples:
                ok:
                  summary: Success
                  x-zh-summary: "成功"
                  x-outcome: success
                  value:
                    success: true
                licenseDenied:
                  summary: "Failure: device license not valid (HTTP 200)"
                  x-zh-summary: "失败：设备许可无效（HTTP 200）"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    error: license
                    message: "授权已到期"
                    data:
                      enforced: true
                      valid: false
                      reason: expired
                      message: "授权已到期"
                      builtIn: false
                      hasKey: true
                      account: ""
                      isLogin: false
                      key: "1A2B3C4D…"
                      deviceId: "<device-id>"
                      expiresAt: 1796000000
                      maxDevices: 0
                      online: 0
                      lastOK: 1795990000
                      lastCheck: 1796000100
                      server: "https://api.ketec.top"
        "400":
          description: A required parameter is missing or invalid.
          x-zh-description: "必填参数缺失或无效。"
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
              examples:
                error:
                  summary: "Failure: missing or invalid parameter"
                  x-zh-summary: "失败：参数缺失或无效"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    message: "缺少有效的button参数"
  /api/hid/sendKey:
    post:
      operationId: hidSendKey
      summary: Send a key combination (HID)
      description: "Presses a key combination through the HID device, e.g. [\"COMMAND\",\"v\"]. Keys are single characters or names: COMMAND, ENTER/RETURN, ESC, BACKSPACE, TAB, SPACE, CAPS_LOCK, INSERT, HOME, END, PAGE_UP, PAGE_DOWN, DELETE, UP_ARROW, DOWN_ARROW, LEFT_ARROW, RIGHT_ARROW; numbers are passed to the firmware as key codes. A comma-separated `keys` query parameter is also accepted."
      tags: ["HID Control"]
      x-zh-summary: "发送组合键（HID）"
      x-zh-description: "经 HID 设备按下组合键，如 [\"COMMAND\",\"v\"]。键可以是单个字符或键名：COMMAND、ENTER/RETURN、ESC、BACKSPACE、TAB、SPACE、CAPS_LOCK、INSERT、HOME、END、PAGE_UP、PAGE_DOWN、DELETE、方向键；数字按固件键码透传。也接受逗号分隔的查询参数 `keys`。"
      x-modes: ["hid"]
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/KeysBody"
            example:
              keys: ["COMMAND", "v"]
      responses:
        "200":
          description: JSON result.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/SuccessResponse"
              examples:
                ok:
                  summary: Success
                  x-zh-summary: "成功"
                  x-outcome: success
                  value:
                    success: true
                licenseDenied:
                  summary: "Failure: device license not valid (HTTP 200)"
                  x-zh-summary: "失败：设备许可无效（HTTP 200）"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    error: license
                    message: "授权已到期"
                    data:
                      enforced: true
                      valid: false
                      reason: expired
                      message: "授权已到期"
                      builtIn: false
                      hasKey: true
                      account: ""
                      isLogin: false
                      key: "1A2B3C4D…"
                      deviceId: "<device-id>"
                      expiresAt: 1796000000
                      maxDevices: 0
                      online: 0
                      lastOK: 1795990000
                      lastCheck: 1796000100
                      server: "https://api.ketec.top"
        "400":
          description: A required parameter is missing or invalid.
          x-zh-description: "必填参数缺失或无效。"
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
              examples:
                error:
                  summary: "Failure: missing or invalid parameter"
                  x-zh-summary: "失败：参数缺失或无效"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    message: "请求体为空"
  /api/hid/openApp:
    get:
      operationId: hidOpenApp
      summary: Open an app
      description: Launches an app by display name or bundle id. Does not need the HID hardware.
      tags: ["HID Control"]
      x-zh-summary: "打开 App"
      x-zh-description: "按 App 名称或 bundleId 启动 App，不依赖 HID 硬件。"
      x-modes: ["hid"]
      parameters:
        - name: name
          in: query
          required: true
          description: "App display name or bundle id (alias: bundleId)."
          x-zh-description: "App 名称或 bundleId（别名：bundleId）。"
          schema:
            type: string
          example: Settings
      responses:
        "200":
          description: JSON result.
          content:
            application/json:
              schema:
                type: object
                required: ["success"]
                properties:
                  success:
                    type: boolean
                  data:
                    type: object
                    properties:
                      bundleId:
                        type: string
              examples:
                ok:
                  summary: Success
                  x-zh-summary: "成功"
                  x-outcome: success
                  value:
                    success: true
                    data:
                      bundleId: com.apple.Preferences
                licenseDenied:
                  summary: "Failure: device license not valid (HTTP 200)"
                  x-zh-summary: "失败：设备许可无效（HTTP 200）"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    error: license
                    message: "授权已到期"
                    data:
                      enforced: true
                      valid: false
                      reason: expired
                      message: "授权已到期"
                      builtIn: false
                      hasKey: true
                      account: ""
                      isLogin: false
                      key: "1A2B3C4D…"
                      deviceId: "<device-id>"
                      expiresAt: 1796000000
                      maxDevices: 0
                      online: 0
                      lastOK: 1795990000
                      lastCheck: 1796000100
                      server: "https://api.ketec.top"
        "400":
          description: A required parameter is missing or invalid.
          x-zh-description: "必填参数缺失或无效。"
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
              examples:
                error:
                  summary: "Failure: missing or invalid parameter"
                  x-zh-summary: "失败：参数缺失或无效"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    message: "缺少有效的name参数"
  /api/hid/closeApp:
    get:
      operationId: hidCloseApp
      summary: Close an app
      description: "Terminates an app by display name or bundle id. If the system refuses, and a HID device is connected, ketec closes it with gestures (open app, Home, app switcher, swipe the card up), reported as via=hid-gesture."
      tags: ["HID Control"]
      x-zh-summary: "关闭 App"
      x-zh-description: "按 App 名称或 bundleId 结束 App。系统拒绝且连着 HID 设备时，ketec 用手势关闭（打开该 App → 回主屏 → 多任务 → 上划卡片），回包 via=hid-gesture。"
      x-modes: ["hid"]
      parameters:
        - name: name
          in: query
          required: true
          description: "App display name or bundle id (alias: bundleId)."
          x-zh-description: "App 名称或 bundleId（别名：bundleId）。"
          schema:
            type: string
          example: Settings
      responses:
        "200":
          description: JSON result.
          content:
            application/json:
              schema:
                type: object
                required: ["success"]
                properties:
                  success:
                    type: boolean
                  data:
                    type: object
                    properties:
                      bundleId:
                        type: string
                      via:
                        type: string
                        enum: ["terminate", "hid-gesture", ""]
              examples:
                ok:
                  summary: Success
                  x-zh-summary: "成功"
                  x-outcome: success
                  value:
                    success: true
                    data:
                      bundleId: com.apple.Preferences
                      via: terminate
                licenseDenied:
                  summary: "Failure: device license not valid (HTTP 200)"
                  x-zh-summary: "失败：设备许可无效（HTTP 200）"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    error: license
                    message: "授权已到期"
                    data:
                      enforced: true
                      valid: false
                      reason: expired
                      message: "授权已到期"
                      builtIn: false
                      hasKey: true
                      account: ""
                      isLogin: false
                      key: "1A2B3C4D…"
                      deviceId: "<device-id>"
                      expiresAt: 1796000000
                      maxDevices: 0
                      online: 0
                      lastOK: 1795990000
                      lastCheck: 1796000100
                      server: "https://api.ketec.top"
        "400":
          description: A required parameter is missing or invalid.
          x-zh-description: "必填参数缺失或无效。"
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
              examples:
                error:
                  summary: "Failure: missing or invalid parameter"
                  x-zh-summary: "失败：参数缺失或无效"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    message: "缺少有效的name参数"
  /api/hid/openURL:
    get:
      operationId: hidOpenUrl
      summary: Open a URL (HID mode)
      description: "Opens a URL. Uses the ketec helper Shortcut when available (works while ketec is in the background, accepts addresses without a scheme), otherwise opens it locally, adding https:// when no scheme is given."
      tags: ["HID Control"]
      x-zh-summary: "打开 URL（HID 模式）"
      x-zh-description: "打开 URL。优先经 ketec 辅助快捷指令打开（ketec 在后台也可用，可处理不带 scheme 的地址），否则本地打开，无 scheme 时自动补 https://。"
      x-modes: ["hid"]
      parameters:
        - name: url
          in: query
          required: true
          description: URL to open (URL-encoded).
          x-zh-description: "要打开的 URL（需 URL 编码）。"
          schema:
            type: string
          example: "https://example.com"
      responses:
        "200":
          description: JSON result.
          content:
            application/json:
              schema:
                type: object
                required: ["success"]
                properties:
                  success:
                    type: boolean
                  data:
                    type: object
                    properties:
                      url:
                        type: string
              examples:
                ok:
                  summary: Success
                  x-zh-summary: "成功"
                  x-outcome: success
                  value:
                    success: true
                    data:
                      url: "https://example.com"
                licenseDenied:
                  summary: "Failure: device license not valid (HTTP 200)"
                  x-zh-summary: "失败：设备许可无效（HTTP 200）"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    error: license
                    message: "授权已到期"
                    data:
                      enforced: true
                      valid: false
                      reason: expired
                      message: "授权已到期"
                      builtIn: false
                      hasKey: true
                      account: ""
                      isLogin: false
                      key: "1A2B3C4D…"
                      deviceId: "<device-id>"
                      expiresAt: 1796000000
                      maxDevices: 0
                      online: 0
                      lastOK: 1795990000
                      lastCheck: 1796000100
                      server: "https://api.ketec.top"
        "400":
          description: A required parameter is missing or invalid.
          x-zh-description: "必填参数缺失或无效。"
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
              examples:
                error:
                  summary: "Failure: missing or invalid parameter"
                  x-zh-summary: "失败：参数缺失或无效"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    message: "缺少有效的url参数"
  /api/hid/currentAppInfo:
    get:
      operationId: hidCurrentAppInfo
      summary: Get the foreground app (HID mode)
      description: Returns bundleId and name of the foreground app without using the Agent channel. Fails with message when it cannot be determined.
      tags: ["HID Control"]
      x-zh-summary: "获取前台 App（HID 模式）"
      x-zh-description: "不经 Agent 通道获取前台 App 的 bundleId 与名称。无法判断时返回失败与 message。"
      x-modes: ["hid"]
      responses:
        "200":
          description: JSON result.
          content:
            application/json:
              schema:
                type: object
                required: ["success"]
                properties:
                  success:
                    type: boolean
                  data:
                    type: object
                    properties:
                      bundleId:
                        type: string
                      name:
                        type: string
                  message:
                    type: string
              examples:
                ok:
                  summary: Success
                  x-zh-summary: "成功"
                  x-outcome: success
                  value:
                    success: true
                    data:
                      bundleId: com.apple.Preferences
                      name: Settings
                licenseDenied:
                  summary: "Failure: device license not valid (HTTP 200)"
                  x-zh-summary: "失败：设备许可无效（HTTP 200）"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    error: license
                    message: "授权已到期"
                    data:
                      enforced: true
                      valid: false
                      reason: expired
                      message: "授权已到期"
                      builtIn: false
                      hasKey: true
                      account: ""
                      isLogin: false
                      key: "1A2B3C4D…"
                      deviceId: "<device-id>"
                      expiresAt: 1796000000
                      maxDevices: 0
                      online: 0
                      lastOK: 1795990000
                      lastCheck: 1796000100
                      server: "https://api.ketec.top"
  /api/hid/deviceInfo:
    get:
      operationId: hidDeviceInfo
      summary: Get HID device info
      description: Returns whether the ESP32-S3 HID device is connected, plus its model, firmware version and MAC address as last reported. Also asks the device to refresh this information.
      tags: ["HID Control"]
      x-zh-summary: "获取 HID 设备信息"
      x-zh-description: "返回 ESP32-S3 HID 设备是否连接，以及最近一次上报的型号、固件版本、MAC 地址；同时请求设备刷新这些信息。"
      x-modes: ["hid"]
      responses:
        "200":
          description: JSON result.
          content:
            application/json:
              schema:
                type: object
                required: ["success", "data"]
                properties:
                  success:
                    type: boolean
                  data:
                    $ref: "#/components/schemas/HidDeviceInfo"
              examples:
                ok:
                  summary: Success
                  x-zh-summary: "成功"
                  x-outcome: success
                  value:
                    success: true
                    data:
                      connected: true
                      model: "<model>"
                      version: "<firmware-version>"
                      mac: "<mac>"
                      lastResponse: ""
                      transmitted: 128
                licenseDenied:
                  summary: "Failure: device license not valid (HTTP 200)"
                  x-zh-summary: "失败：设备许可无效（HTTP 200）"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    error: license
                    message: "授权已到期"
                    data:
                      enforced: true
                      valid: false
                      reason: expired
                      message: "授权已到期"
                      builtIn: false
                      hasKey: true
                      account: ""
                      isLogin: false
                      key: "1A2B3C4D…"
                      deviceId: "<device-id>"
                      expiresAt: 1796000000
                      maxDevices: 0
                      online: 0
                      lastOK: 1795990000
                      lastCheck: 1796000100
                      server: "https://api.ketec.top"
  /api/hid/restartDevice:
    get:
      operationId: hidRestartDevice
      summary: Restart the HID device
      description: Sends a restart command to the ESP32-S3 firmware (it does not restart the phone). The device re-enumerates over USB, so HID control is unavailable for a few seconds until it reconnects.
      tags: ["HID Control"]
      x-zh-summary: "重启 HID 设备"
      x-zh-description: "向 ESP32-S3 固件发送重启命令（不会重启手机）。设备会重新 USB 枚举，重连前的几秒内 HID 控制不可用。"
      x-modes: ["hid"]
      responses:
        "200":
          description: JSON result.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/SuccessResponse"
              examples:
                ok:
                  summary: Success
                  x-zh-summary: "成功"
                  x-outcome: success
                  value:
                    success: true
                licenseDenied:
                  summary: "Failure: device license not valid (HTTP 200)"
                  x-zh-summary: "失败：设备许可无效（HTTP 200）"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    error: license
                    message: "授权已到期"
                    data:
                      enforced: true
                      valid: false
                      reason: expired
                      message: "授权已到期"
                      builtIn: false
                      hasKey: true
                      account: ""
                      isLogin: false
                      key: "1A2B3C4D…"
                      deviceId: "<device-id>"
                      expiresAt: 1796000000
                      maxDevices: 0
                      online: 0
                      lastOK: 1795990000
                      lastCheck: 1796000100
                      server: "https://api.ketec.top"
  /api/hid/shortcutScreenshot:
    get:
      operationId: hidShortcutScreenshot
      summary: Screenshot via Shortcut (PNG)
      description: "Captures the screen through the ketec helper Shortcut, triggered by the HID device; requires the helper Shortcut to be installed and a connected HID device. Can take several seconds (timeout 20 s). Returns PNG."
      tags: ["HID Control"]
      x-zh-summary: "快捷指令截图"
      x-zh-description: "经 HID 设备触发 ketec 辅助快捷指令截屏；需已安装辅助快捷指令并连接 HID 设备。可能耗时数秒（超时 20 秒）。返回 PNG。"
      x-modes: ["hid"]
      responses:
        "200":
          description: "PNG image, or JSON {success:false, message} on failure."
          content:
            image/png:
              schema:
                type: string
                format: binary
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
              examples:
                ok:
                  summary: Success
                  x-zh-summary: "成功"
                  x-outcome: success
                  value:
                    success: false
                    message: "获取截图失败"
                licenseDenied:
                  summary: "Failure: device license not valid (HTTP 200)"
                  x-zh-summary: "失败：设备许可无效（HTTP 200）"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    error: license
                    message: "授权已到期"
                    data:
                      enforced: true
                      valid: false
                      reason: expired
                      message: "授权已到期"
                      builtIn: false
                      hasKey: true
                      account: ""
                      isLogin: false
                      key: "1A2B3C4D…"
                      deviceId: "<device-id>"
                      expiresAt: 1796000000
                      maxDevices: 0
                      online: 0
                      lastOK: 1795990000
                      lastCheck: 1796000100
                      server: "https://api.ketec.top"
  /api/hid/shortcutScreenshotBase64:
    get:
      operationId: hidShortcutScreenshotBase64
      summary: Screenshot via Shortcut (Base64)
      description: "Captures the screen through the ketec helper Shortcut, triggered by the HID device; requires the helper Shortcut to be installed and a connected HID device. Can take several seconds (timeout 20 s). Returns the PNG Base64-encoded in `data`."
      tags: ["HID Control"]
      x-zh-summary: "快捷指令截图 Base64"
      x-zh-description: "经 HID 设备触发 ketec 辅助快捷指令截屏；需已安装辅助快捷指令并连接 HID 设备。可能耗时数秒（超时 20 秒）。`data` 为 Base64 编码的 PNG。"
      x-modes: ["hid"]
      responses:
        "200":
          description: JSON result.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/StringDataResponse"
              examples:
                ok:
                  summary: Success
                  x-zh-summary: "成功"
                  x-outcome: success
                  value:
                    success: true
                    data: iVBORw0KGgoAAAANSUhEUgAA...
                licenseDenied:
                  summary: "Failure: device license not valid (HTTP 200)"
                  x-zh-summary: "失败：设备许可无效（HTTP 200）"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    error: license
                    message: "授权已到期"
                    data:
                      enforced: true
                      valid: false
                      reason: expired
                      message: "授权已到期"
                      builtIn: false
                      hasKey: true
                      account: ""
                      isLogin: false
                      key: "1A2B3C4D…"
                      deviceId: "<device-id>"
                      expiresAt: 1796000000
                      maxDevices: 0
                      online: 0
                      lastOK: 1795990000
                      lastCheck: 1796000100
                      server: "https://api.ketec.top"
  /api/ime/isOk:
    get:
      operationId: imeIsOk
      summary: Check whether the ketec keyboard is ready
      description: "success is true when the ketec keyboard is installed and currently visible. `data` explains the details (current input mode, whether it is ketec's keyboard, time since the extension last checked in)."
      tags: ["Keyboard"]
      x-zh-summary: "API 键盘是否可用"
      x-zh-description: "ketec 键盘已安装且当前可见时 success 为 true。`data` 给出详情（当前输入法、是否为 ketec 键盘、扩展最近一次心跳距今时长）。"
      x-modes: ["agent", "hid"]
      responses:
        "200":
          description: JSON result.
          content:
            application/json:
              schema:
                type: object
                required: ["success"]
                properties:
                  success:
                    type: boolean
                  superset:
                    type: boolean
                  data:
                    type: object
                    properties:
                      keyboardInstalled:
                        type: boolean
                      keyboardVisible:
                        type: boolean
                      currentInputModeIdentifier:
                        type: ["string", "null"]
                      targetInputModeIdentifier:
                        type: string
                      isOurKeyboard:
                        type: boolean
                      lastPollAgoMs:
                        type: ["integer", "null"]
                      neverPolled:
                        type: boolean
              examples:
                ok:
                  summary: Success
                  x-zh-summary: "成功"
                  x-outcome: success
                  value:
                    success: true
                    superset: true
                    data:
                      keyboardInstalled: true
                      keyboardVisible: true
                      currentInputModeIdentifier: "<input-mode-id>"
                      targetInputModeIdentifier: "<input-mode-id>"
                      isOurKeyboard: true
                      lastPollAgoMs: 120
                      neverPolled: false
                licenseDenied:
                  summary: "Failure: device license not valid (HTTP 200)"
                  x-zh-summary: "失败：设备许可无效（HTTP 200）"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    error: license
                    message: "授权已到期"
                    data:
                      enforced: true
                      valid: false
                      reason: expired
                      message: "授权已到期"
                      builtIn: false
                      hasKey: true
                      account: ""
                      isLogin: false
                      key: "1A2B3C4D…"
                      deviceId: "<device-id>"
                      expiresAt: 1796000000
                      maxDevices: 0
                      online: 0
                      lastOK: 1795990000
                      lastCheck: 1796000100
                      server: "https://api.ketec.top"
  /api/ime/input:
    get:
      operationId: imeInput
      summary: Insert text via the ketec keyboard
      description: "Requires the ketec keyboard to be added in iOS Settings (with Full Access) and a keyboard to be on screen. If another keyboard is showing, ketec switches to its own keyboard first, then inserts the text in one piece (any Unicode, including emoji). Fails with a `reason` when no keyboard is up."
      tags: ["Keyboard"]
      x-zh-summary: "输入文字（API 键盘）"
      x-zh-description: "需在 iOS 设置中添加 ketec 键盘（并开启完全访问），且屏幕上有键盘弹出。若当前是其他键盘，ketec 会先切换到自己的键盘，再整段插入文字（任意 Unicode，含表情）。没有键盘弹出时失败并给出 `reason`。"
      x-modes: ["agent", "hid"]
      parameters:
        - name: text
          in: query
          required: true
          description: "Text to insert (URL-encoded; send \"+\" as %2B). Also accepted as JSON body {\"text\": ...}."
          x-zh-description: "要插入的文字（URL 编码；加号写 %2B）。也可用 JSON 请求体 {\"text\": ...}。"
          schema:
            type: string
          example: "你好👋"
      responses:
        "200":
          description: JSON result.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ImeResult"
              examples:
                ok:
                  summary: Success
                  x-zh-summary: "成功"
                  x-outcome: success
                  value:
                    success: true
                    via: unix-socket
                    data: "你好👋"
                    readbackLen: 4
                    extKeyboardVisible: true
                licenseDenied:
                  summary: "Failure: device license not valid (HTTP 200)"
                  x-zh-summary: "失败：设备许可无效（HTTP 200）"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    error: license
                    message: "授权已到期"
                    data:
                      enforced: true
                      valid: false
                      reason: expired
                      message: "授权已到期"
                      builtIn: false
                      hasKey: true
                      account: ""
                      isLogin: false
                      key: "1A2B3C4D…"
                      deviceId: "<device-id>"
                      expiresAt: 1796000000
                      maxDevices: 0
                      online: 0
                      lastOK: 1795990000
                      lastCheck: 1796000100
                      server: "https://api.ketec.top"
  /api/ime/paste:
    get:
      operationId: imePaste
      summary: Paste via the ketec keyboard
      description: "Requires the ketec keyboard to be added in iOS Settings (with Full Access) and a keyboard to be on screen. Without `text` the keyboard extension pastes the current clipboard content; with `text` that text is inserted instead."
      tags: ["Keyboard"]
      x-zh-summary: "粘贴文本（API 键盘）"
      x-zh-description: "需在 iOS 设置中添加 ketec 键盘（并开启完全访问），且屏幕上有键盘弹出。不带 `text` 时由键盘扩展粘贴当前剪贴板内容；带 `text` 时插入该文本。"
      x-modes: ["agent", "hid"]
      parameters:
        - name: text
          in: query
          required: false
          description: Optional text to insert instead of the clipboard content.
          x-zh-description: "可选，代替剪贴板内容插入的文本。"
          schema:
            type: string
          example: ""
      responses:
        "200":
          description: JSON result.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ImeResult"
              examples:
                ok:
                  summary: Success
                  x-zh-summary: "成功"
                  x-outcome: success
                  value:
                    success: true
                    via: unix-socket
                    readbackLen: 12
                licenseDenied:
                  summary: "Failure: device license not valid (HTTP 200)"
                  x-zh-summary: "失败：设备许可无效（HTTP 200）"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    error: license
                    message: "授权已到期"
                    data:
                      enforced: true
                      valid: false
                      reason: expired
                      message: "授权已到期"
                      builtIn: false
                      hasKey: true
                      account: ""
                      isLogin: false
                      key: "1A2B3C4D…"
                      deviceId: "<device-id>"
                      expiresAt: 1796000000
                      maxDevices: 0
                      online: 0
                      lastOK: 1795990000
                      lastCheck: 1796000100
                      server: "https://api.ketec.top"
  /api/ime/getText:
    get:
      operationId: imeGetText
      summary: Read the text before the cursor
      description: "Requires the ketec keyboard to be added in iOS Settings (with Full Access) and a keyboard to be on screen. Returns the text before the cursor in the focused field as seen by the keyboard. iOS may truncate long content; returns an empty string when there is no input session."
      tags: ["Keyboard"]
      x-zh-summary: "获取已输入文本"
      x-zh-description: "需在 iOS 设置中添加 ketec 键盘（并开启完全访问），且屏幕上有键盘弹出。返回键盘看到的焦点输入框中光标前的文本。系统可能截断长文本；没有输入会话时返回空字符串。"
      x-modes: ["agent", "hid"]
      responses:
        "200":
          description: JSON result.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ImeResult"
              examples:
                ok:
                  summary: Success
                  x-zh-summary: "成功"
                  x-outcome: success
                  value:
                    success: true
                    via: unix-socket
                    data: hello
                    readbackLen: 5
                licenseDenied:
                  summary: "Failure: device license not valid (HTTP 200)"
                  x-zh-summary: "失败：设备许可无效（HTTP 200）"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    error: license
                    message: "授权已到期"
                    data:
                      enforced: true
                      valid: false
                      reason: expired
                      message: "授权已到期"
                      builtIn: false
                      hasKey: true
                      account: ""
                      isLogin: false
                      key: "1A2B3C4D…"
                      deviceId: "<device-id>"
                      expiresAt: 1796000000
                      maxDevices: 0
                      online: 0
                      lastOK: 1795990000
                      lastCheck: 1796000100
                      server: "https://api.ketec.top"
  /api/ime/clearText:
    get:
      operationId: imeClearText
      summary: Clear the focused field
      description: Requires the ketec keyboard to be added in iOS Settings (with Full Access) and a keyboard to be on screen. Deletes the text before the cursor until the field is empty (long text is deleted in rounds).
      tags: ["Keyboard"]
      x-zh-summary: "清空文本"
      x-zh-description: "需在 iOS 设置中添加 ketec 键盘（并开启完全访问），且屏幕上有键盘弹出。删除光标前的文字直到输入框为空（长文本分轮删除）。"
      x-modes: ["agent", "hid"]
      responses:
        "200":
          description: JSON result.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ImeResult"
              examples:
                ok:
                  summary: Success
                  x-zh-summary: "成功"
                  x-outcome: success
                  value:
                    success: true
                    via: unix-socket
                    readbackLen: 0
                    deletedCount: 5
                    superset: true
                licenseDenied:
                  summary: "Failure: device license not valid (HTTP 200)"
                  x-zh-summary: "失败：设备许可无效（HTTP 200）"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    error: license
                    message: "授权已到期"
                    data:
                      enforced: true
                      valid: false
                      reason: expired
                      message: "授权已到期"
                      builtIn: false
                      hasKey: true
                      account: ""
                      isLogin: false
                      key: "1A2B3C4D…"
                      deviceId: "<device-id>"
                      expiresAt: 1796000000
                      maxDevices: 0
                      online: 0
                      lastOK: 1795990000
                      lastCheck: 1796000100
                      server: "https://api.ketec.top"
  /api/ime/pressDel:
    get:
      operationId: imePressDel
      summary: Press Delete
      description: Requires the ketec keyboard to be added in iOS Settings (with Full Access) and a keyboard to be on screen. Deletes characters before the cursor.
      tags: ["Keyboard"]
      x-zh-summary: "按删除键"
      x-zh-description: "需在 iOS 设置中添加 ketec 键盘（并开启完全访问），且屏幕上有键盘弹出。删除光标前的字符。"
      x-modes: ["agent", "hid"]
      parameters:
        - name: count
          in: query
          required: false
          description: Number of characters to delete.
          x-zh-description: "删除字符数。"
          schema:
            type: integer
            minimum: 1
            default: 1
          example: 1
      responses:
        "200":
          description: JSON result.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ImeResult"
              examples:
                ok:
                  summary: Success
                  x-zh-summary: "成功"
                  x-outcome: success
                  value:
                    success: true
                    via: unix-socket
                    readbackLen: 4
                    deletedCount: 1
                    superset: true
                licenseDenied:
                  summary: "Failure: device license not valid (HTTP 200)"
                  x-zh-summary: "失败：设备许可无效（HTTP 200）"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    error: license
                    message: "授权已到期"
                    data:
                      enforced: true
                      valid: false
                      reason: expired
                      message: "授权已到期"
                      builtIn: false
                      hasKey: true
                      account: ""
                      isLogin: false
                      key: "1A2B3C4D…"
                      deviceId: "<device-id>"
                      expiresAt: 1796000000
                      maxDevices: 0
                      online: 0
                      lastOK: 1795990000
                      lastCheck: 1796000100
                      server: "https://api.ketec.top"
  /api/ime/pressEnter:
    get:
      operationId: imePressEnter
      summary: Press Return
      description: Requires the ketec keyboard to be added in iOS Settings (with Full Access) and a keyboard to be on screen. Inserts a Return (new line / submit, depending on the field).
      tags: ["Keyboard"]
      x-zh-summary: "按回车键"
      x-zh-description: "需在 iOS 设置中添加 ketec 键盘（并开启完全访问），且屏幕上有键盘弹出。插入回车（换行或提交，取决于输入框）。"
      x-modes: ["agent", "hid"]
      responses:
        "200":
          description: JSON result.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ImeResult"
              examples:
                ok:
                  summary: Success
                  x-zh-summary: "成功"
                  x-outcome: success
                  value:
                    success: true
                    via: unix-socket
                licenseDenied:
                  summary: "Failure: device license not valid (HTTP 200)"
                  x-zh-summary: "失败：设备许可无效（HTTP 200）"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    error: license
                    message: "授权已到期"
                    data:
                      enforced: true
                      valid: false
                      reason: expired
                      message: "授权已到期"
                      builtIn: false
                      hasKey: true
                      account: ""
                      isLogin: false
                      key: "1A2B3C4D…"
                      deviceId: "<device-id>"
                      expiresAt: 1796000000
                      maxDevices: 0
                      online: 0
                      lastOK: 1795990000
                      lastCheck: 1796000100
                      server: "https://api.ketec.top"
  /api/ime/dismiss:
    get:
      operationId: imeDismiss
      summary: Hide the keyboard
      description: "Requires the ketec keyboard to be added in iOS Settings (with Full Access) and a keyboard to be on screen. Dismisses the keyboard. If the extension cannot do it and a HID device is connected, ketec taps outside the keyboard; otherwise it fails with reason keyboard_still_visible."
      tags: ["Keyboard"]
      x-zh-summary: "隐藏键盘"
      x-zh-description: "需在 iOS 设置中添加 ketec 键盘（并开启完全访问），且屏幕上有键盘弹出。收起键盘。扩展无法收起且连着 HID 设备时，ketec 会点击键盘外区域；否则失败，reason 为 keyboard_still_visible。"
      x-modes: ["agent", "hid"]
      responses:
        "200":
          description: JSON result.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ImeResult"
              examples:
                ok:
                  summary: Success
                  x-zh-summary: "成功"
                  x-outcome: success
                  value:
                    success: true
                    via: unix-socket
                licenseDenied:
                  summary: "Failure: device license not valid (HTTP 200)"
                  x-zh-summary: "失败：设备许可无效（HTTP 200）"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    error: license
                    message: "授权已到期"
                    data:
                      enforced: true
                      valid: false
                      reason: expired
                      message: "授权已到期"
                      builtIn: false
                      hasKey: true
                      account: ""
                      isLogin: false
                      key: "1A2B3C4D…"
                      deviceId: "<device-id>"
                      expiresAt: 1796000000
                      maxDevices: 0
                      online: 0
                      lastOK: 1795990000
                      lastCheck: 1796000100
                      server: "https://api.ketec.top"
  /api/ime/getClipboard:
    get:
      operationId: imeGetClipboard
      summary: Read the clipboard via the keyboard
      description: Requires the ketec keyboard to be added in iOS Settings (with Full Access) and a keyboard to be on screen. Reads the clipboard through the keyboard extension, which avoids the iOS paste-permission prompt. Returns an empty string when the keyboard is not available.
      tags: ["Keyboard"]
      x-zh-summary: "获取剪贴板（API 键盘）"
      x-zh-description: "需在 iOS 设置中添加 ketec 键盘（并开启完全访问），且屏幕上有键盘弹出。经键盘扩展读取剪贴板，可避开 iOS 的「允许粘贴」弹窗。键盘不可用时返回空字符串。"
      x-modes: ["agent", "hid"]
      responses:
        "200":
          description: JSON result.
          content:
            application/json:
              schema:
                type: object
                required: ["success", "data"]
                properties:
                  success:
                    type: boolean
                  data:
                    type: string
                  length:
                    type: integer
                  chars:
                    type: integer
                  source:
                    type: string
                additionalProperties: true
              examples:
                ok:
                  summary: Success
                  x-zh-summary: "成功"
                  x-outcome: success
                  value:
                    success: true
                    data: copied text
                    length: 11
                    chars: 11
                    source: http-fallback
                licenseDenied:
                  summary: "Failure: device license not valid (HTTP 200)"
                  x-zh-summary: "失败：设备许可无效（HTTP 200）"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    error: license
                    message: "授权已到期"
                    data:
                      enforced: true
                      valid: false
                      reason: expired
                      message: "授权已到期"
                      builtIn: false
                      hasKey: true
                      account: ""
                      isLogin: false
                      key: "1A2B3C4D…"
                      deviceId: "<device-id>"
                      expiresAt: 1796000000
                      maxDevices: 0
                      online: 0
                      lastOK: 1795990000
                      lastCheck: 1796000100
                      server: "https://api.ketec.top"
  /api/ime/setClipboard:
    get:
      operationId: imeSetClipboard
      summary: Write the clipboard
      description: "Writes text to the system clipboard (does not need the keyboard). `verified` is \"true\" when it could be read back, \"unknown\" when reading back was blocked by iOS."
      tags: ["Keyboard"]
      x-zh-summary: "设置剪贴板"
      x-zh-description: "把文本写入系统剪贴板（不依赖键盘）。能读回一致时 `verified` 为 \"true\"，被 iOS 拦截读不到时为 \"unknown\"。"
      x-modes: ["agent", "hid"]
      parameters:
        - name: text
          in: query
          required: true
          description: "Text to write, kept verbatim (URL-encoded; send \"+\" as %2B). Also accepted as JSON body {\"text\": ...}."
          x-zh-description: "要写入的文本，原样保留（URL 编码；加号写 %2B）。也可用 JSON 请求体 {\"text\": ...}。"
          schema:
            type: string
          example: hello
      responses:
        "200":
          description: JSON result.
          content:
            application/json:
              schema:
                type: object
                required: ["success", "data"]
                properties:
                  success:
                    type: boolean
                  data:
                    type: object
                    properties:
                      via:
                        type: string
                      written:
                        type: boolean
                      verified:
                        type: string
                        enum: ["true", "false", "unknown"]
                      len:
                        type: integer
                      chars:
                        type: integer
                      note:
                        type: string
                    additionalProperties: true
              examples:
                ok:
                  summary: Success
                  x-zh-summary: "成功"
                  x-outcome: success
                  value:
                    success: true
                    data:
                      via: uipasteboard
                      written: true
                      verified: "true"
                      len: 5
                      encoding: 5
                      chars: 5
                licenseDenied:
                  summary: "Failure: device license not valid (HTTP 200)"
                  x-zh-summary: "失败：设备许可无效（HTTP 200）"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    error: license
                    message: "授权已到期"
                    data:
                      enforced: true
                      valid: false
                      reason: expired
                      message: "授权已到期"
                      builtIn: false
                      hasKey: true
                      account: ""
                      isLogin: false
                      key: "1A2B3C4D…"
                      deviceId: "<device-id>"
                      expiresAt: 1796000000
                      maxDevices: 0
                      online: 0
                      lastOK: 1795990000
                      lastCheck: 1796000100
                      server: "https://api.ketec.top"
  /api/getClipboard:
    get:
      operationId: getClipboard
      summary: Read the clipboard
      description: "Reads the system clipboard from the main app. iOS may block this read (paste permission); then needsUserPermission=true is returned and /api/ime/getClipboard is the better choice."
      tags: ["Clipboard & Config"]
      x-zh-summary: "获取剪贴板"
      x-zh-description: "由主 App 读取系统剪贴板。iOS 可能拦截该读取（粘贴权限），此时返回 needsUserPermission=true，建议改用 /api/ime/getClipboard。"
      x-modes: ["agent", "hid"]
      responses:
        "200":
          description: JSON result.
          content:
            application/json:
              schema:
                type: object
                required: ["success", "data"]
                properties:
                  success:
                    type: boolean
                  data:
                    type: string
                  meta:
                    type: object
                    properties:
                      data:
                        type: string
                      source:
                        type: string
                        description: "system = really read; shadow = cached value written by ketec; other values mean unavailable."
                      changeCount:
                        type: integer
                    additionalProperties: true
                  needsUserPermission:
                    type: boolean
                  hint:
                    type: string
              examples:
                ok:
                  summary: Success
                  x-zh-summary: "成功"
                  x-outcome: success
                  value:
                    success: true
                    data: copied text
                    meta:
                      data: copied text
                      source: system
                      changeCount: 42
                licenseDenied:
                  summary: "Failure: device license not valid (HTTP 200)"
                  x-zh-summary: "失败：设备许可无效（HTTP 200）"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    error: license
                    message: "授权已到期"
                    data:
                      enforced: true
                      valid: false
                      reason: expired
                      message: "授权已到期"
                      builtIn: false
                      hasKey: true
                      account: ""
                      isLogin: false
                      key: "1A2B3C4D…"
                      deviceId: "<device-id>"
                      expiresAt: 1796000000
                      maxDevices: 0
                      online: 0
                      lastOK: 1795990000
                      lastCheck: 1796000100
                      server: "https://api.ketec.top"
  /api/setClipboard:
    get:
      operationId: setClipboard
      summary: Write the clipboard
      description: Writes text to the system clipboard. The text is kept verbatim (leading/trailing spaces preserved).
      tags: ["Clipboard & Config"]
      x-zh-summary: "设置剪贴板"
      x-zh-description: "把文本写入系统剪贴板，原样保留（首尾空格不裁剪）。"
      x-modes: ["agent", "hid"]
      parameters:
        - name: text
          in: query
          required: true
          description: "Text to write (alias: value; URL-encoded, send \"+\" as %2B). Also accepted as JSON body {\"text\": ...}."
          x-zh-description: "要写入的文本（别名：value；URL 编码，加号写 %2B）。也可用 JSON 请求体 {\"text\": ...}。"
          schema:
            type: string
          example: hello
      responses:
        "200":
          description: JSON result.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/SuccessResponse"
              examples:
                ok:
                  summary: Success
                  x-zh-summary: "成功"
                  x-outcome: success
                  value:
                    success: true
                licenseDenied:
                  summary: "Failure: device license not valid (HTTP 200)"
                  x-zh-summary: "失败：设备许可无效（HTTP 200）"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    error: license
                    message: "授权已到期"
                    data:
                      enforced: true
                      valid: false
                      reason: expired
                      message: "授权已到期"
                      builtIn: false
                      hasKey: true
                      account: ""
                      isLogin: false
                      key: "1A2B3C4D…"
                      deviceId: "<device-id>"
                      expiresAt: 1796000000
                      maxDevices: 0
                      online: 0
                      lastOK: 1795990000
                      lastCheck: 1796000100
                      server: "https://api.ketec.top"
        "400":
          description: A required parameter is missing or invalid.
          x-zh-description: "必填参数缺失或无效。"
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
              examples:
                error:
                  summary: "Failure: missing or invalid parameter"
                  x-zh-summary: "失败：参数缺失或无效"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    message: "缺少有效的text参数"
  /api/getAllConfig:
    get:
      operationId: getAllConfig
      summary: Get all config values
      description: "Returns the app key/value configuration as an object in `data` and the same content as a JSON string in `json`. Values are strings."
      tags: ["Clipboard & Config"]
      x-zh-summary: "获取所有配置"
      x-zh-description: "返回 App 的键值配置：`data` 为对象，`json` 为同内容的 JSON 字符串。值均为字符串。"
      x-modes: ["agent", "hid"]
      responses:
        "200":
          description: JSON result.
          content:
            application/json:
              schema:
                type: object
                required: ["success", "data"]
                properties:
                  success:
                    type: boolean
                  data:
                    type: object
                    additionalProperties:
                      type: string
                  json:
                    type: string
              examples:
                ok:
                  summary: Success
                  x-zh-summary: "成功"
                  x-outcome: success
                  value:
                    success: true
                    data:
                      runMode: agent
                    json: "{\"runMode\":\"agent\"}"
                licenseDenied:
                  summary: "Failure: device license not valid (HTTP 200)"
                  x-zh-summary: "失败：设备许可无效（HTTP 200）"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    error: license
                    message: "授权已到期"
                    data:
                      enforced: true
                      valid: false
                      reason: expired
                      message: "授权已到期"
                      builtIn: false
                      hasKey: true
                      account: ""
                      isLogin: false
                      key: "1A2B3C4D…"
                      deviceId: "<device-id>"
                      expiresAt: 1796000000
                      maxDevices: 0
                      online: 0
                      lastOK: 1795990000
                      lastCheck: 1796000100
                      server: "https://api.ketec.top"
  /api/setConfig:
    get:
      operationId: setConfig
      summary: Set one config value
      description: "Sets one configuration value. key and value are read from the query string only (a JSON body is not read), so POST works too as long as the values are in the query. Setting key=runMode also switches the run mode."
      tags: ["Clipboard & Config"]
      x-zh-summary: "设置配置项"
      x-zh-description: "设置一个配置项。key 与 value 只从查询串读取（不读 JSON 请求体），因此用 POST 也可以，但参数必须放在查询串里。key=runMode 时会同时切换运行模式。"
      x-modes: ["agent", "hid"]
      parameters:
        - name: key
          in: query
          required: true
          description: Config key.
          x-zh-description: "配置键。"
          schema:
            type: string
          example: runMode
        - name: value
          in: query
          required: false
          description: Config value (empty string if omitted).
          x-zh-description: "配置值（不传则为空字符串）。"
          schema:
            type: string
          example: agent
      responses:
        "200":
          description: JSON result.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/SuccessResponse"
              examples:
                ok:
                  summary: Success
                  x-zh-summary: "成功"
                  x-outcome: success
                  value:
                    success: true
                licenseDenied:
                  summary: "Failure: device license not valid (HTTP 200)"
                  x-zh-summary: "失败：设备许可无效（HTTP 200）"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    error: license
                    message: "授权已到期"
                    data:
                      enforced: true
                      valid: false
                      reason: expired
                      message: "授权已到期"
                      builtIn: false
                      hasKey: true
                      account: ""
                      isLogin: false
                      key: "1A2B3C4D…"
                      deviceId: "<device-id>"
                      expiresAt: 1796000000
                      maxDevices: 0
                      online: 0
                      lastOK: 1795990000
                      lastCheck: 1796000100
                      server: "https://api.ketec.top"
        "400":
          description: A required parameter is missing or invalid.
          x-zh-description: "必填参数缺失或无效。"
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
              examples:
                error:
                  summary: "Failure: missing or invalid parameter"
                  x-zh-summary: "失败：参数缺失或无效"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    message: "缺少有效的key参数"
  /api/setAllConfig:
    post:
      operationId: setAllConfig
      summary: Set several config values
      description: "Merges the key/value pairs of the JSON body into the configuration. Non-string values are stored as their string form; existing keys not in the body are kept."
      tags: ["Clipboard & Config"]
      x-zh-summary: "设置所有配置"
      x-zh-description: "把 JSON 请求体中的键值合并进配置。非字符串值按字符串形式保存；请求体未包含的已有键保持不变。"
      x-modes: ["agent", "hid"]
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              additionalProperties: true
            example:
              theme: dark
              retry: "3"
      responses:
        "200":
          description: JSON result.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/SuccessResponse"
              examples:
                ok:
                  summary: Success
                  x-zh-summary: "成功"
                  x-outcome: success
                  value:
                    success: true
                licenseDenied:
                  summary: "Failure: device license not valid (HTTP 200)"
                  x-zh-summary: "失败：设备许可无效（HTTP 200）"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    error: license
                    message: "授权已到期"
                    data:
                      enforced: true
                      valid: false
                      reason: expired
                      message: "授权已到期"
                      builtIn: false
                      hasKey: true
                      account: ""
                      isLogin: false
                      key: "1A2B3C4D…"
                      deviceId: "<device-id>"
                      expiresAt: 1796000000
                      maxDevices: 0
                      online: 0
                      lastOK: 1795990000
                      lastCheck: 1796000100
                      server: "https://api.ketec.top"
  /api/file/list:
    get:
      operationId: fileList
      summary: List files
      description: "Recursively lists files and folders under the sandbox root (or under `path`). Up to 5000 entries, sorted by path; folders have size 0. Paths are relative to the chosen sandbox root; \"..\" is rejected."
      tags: ["Files"]
      x-zh-summary: "获取文件列表"
      x-zh-description: "递归列出沙盒根目录（或 `path` 子目录）下的文件与文件夹，最多 5000 项，按路径排序；文件夹 size 为 0。路径相对所选沙盒根目录；包含 \"..\" 会被拒绝。"
      x-modes: ["agent", "hid"]
      parameters:
        - name: dirType
          in: query
          required: false
          description: "Sandbox root: the App's Documents directory or its temporary directory."
          x-zh-description: "沙盒根目录：App 的 Documents 目录或临时目录。"
          schema:
            type: string
            enum: ["documents", "temp"]
            default: documents
          example: documents
        - name: path
          in: query
          required: false
          description: Optional sub-folder to list.
          x-zh-description: "可选，要列出的子目录。"
          schema:
            type: string
          example: records
      responses:
        "200":
          description: JSON result.
          content:
            application/json:
              schema:
                type: object
                required: ["success"]
                properties:
                  success:
                    type: boolean
                  data:
                    type: array
                    items:
                      $ref: "#/components/schemas/FileEntry"
                  reason:
                    type: string
              examples:
                ok:
                  summary: Success
                  x-zh-summary: "成功"
                  x-outcome: success
                  value:
                    success: true
                    data:
                      - name: records
                        path: records
                        isDirectory: true
                        size: 0
                        modified: 1764460800
                      - name: a.txt
                        path: a.txt
                        isDirectory: false
                        size: 12
                        modified: 1764460800
                licenseDenied:
                  summary: "Failure: device license not valid (HTTP 200)"
                  x-zh-summary: "失败：设备许可无效（HTTP 200）"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    error: license
                    message: "授权已到期"
                    data:
                      enforced: true
                      valid: false
                      reason: expired
                      message: "授权已到期"
                      builtIn: false
                      hasKey: true
                      account: ""
                      isLogin: false
                      key: "1A2B3C4D…"
                      deviceId: "<device-id>"
                      expiresAt: 1796000000
                      maxDevices: 0
                      online: 0
                      lastOK: 1795990000
                      lastCheck: 1796000100
                      server: "https://api.ketec.top"
        "400":
          $ref: "#/components/responses/BadRequest"
  /api/file/exists:
    get:
      operationId: fileExists
      summary: Check whether a path exists
      description: "Reports whether the path exists and whether it is a folder. Paths are relative to the chosen sandbox root; \"..\" is rejected."
      tags: ["Files"]
      x-zh-summary: "判断文件是否存在"
      x-zh-description: "返回路径是否存在以及是否为文件夹。路径相对所选沙盒根目录；包含 \"..\" 会被拒绝。"
      x-modes: ["agent", "hid"]
      parameters:
        - name: dirType
          in: query
          required: false
          description: "Sandbox root: the App's Documents directory or its temporary directory."
          x-zh-description: "沙盒根目录：App 的 Documents 目录或临时目录。"
          schema:
            type: string
            enum: ["documents", "temp"]
            default: documents
          example: documents
        - name: path
          in: query
          required: true
          description: Relative path.
          x-zh-description: "相对路径。"
          schema:
            type: string
          example: a.txt
      responses:
        "200":
          description: JSON result.
          content:
            application/json:
              schema:
                type: object
                required: ["success", "data"]
                properties:
                  success:
                    type: boolean
                  data:
                    type: object
                    properties:
                      exists:
                        type: boolean
                      isDirectory:
                        type: boolean
              examples:
                ok:
                  summary: Success
                  x-zh-summary: "成功"
                  x-outcome: success
                  value:
                    success: true
                    data:
                      exists: true
                      isDirectory: false
                licenseDenied:
                  summary: "Failure: device license not valid (HTTP 200)"
                  x-zh-summary: "失败：设备许可无效（HTTP 200）"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    error: license
                    message: "授权已到期"
                    data:
                      enforced: true
                      valid: false
                      reason: expired
                      message: "授权已到期"
                      builtIn: false
                      hasKey: true
                      account: ""
                      isLogin: false
                      key: "1A2B3C4D…"
                      deviceId: "<device-id>"
                      expiresAt: 1796000000
                      maxDevices: 0
                      online: 0
                      lastOK: 1795990000
                      lastCheck: 1796000100
                      server: "https://api.ketec.top"
        "400":
          description: A required parameter is missing or invalid.
          x-zh-description: "必填参数缺失或无效。"
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
              examples:
                error:
                  summary: "Failure: missing or invalid parameter"
                  x-zh-summary: "失败：参数缺失或无效"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    message: "缺少有效的path参数"
  /api/file/upload:
    post:
      operationId: fileUpload
      summary: Upload a file
      description: "Writes the raw request body to `path` (parent folders are created, existing files are overwritten). Maximum 200 MB. Paths are relative to the chosen sandbox root; \"..\" is rejected."
      tags: ["Files"]
      x-zh-summary: "上传文件"
      x-zh-description: "把原始请求体写入 `path`（自动创建上级目录，已存在则覆盖），上限 200 MB。路径相对所选沙盒根目录；包含 \"..\" 会被拒绝。"
      x-modes: ["agent", "hid"]
      parameters:
        - name: dirType
          in: query
          required: false
          description: "Sandbox root: the App's Documents directory or its temporary directory."
          x-zh-description: "沙盒根目录：App 的 Documents 目录或临时目录。"
          schema:
            type: string
            enum: ["documents", "temp"]
            default: documents
          example: documents
        - name: path
          in: query
          required: true
          description: Destination relative path including file name.
          x-zh-description: "目标相对路径（含文件名）。"
          schema:
            type: string
          example: scripts/main.js
      requestBody:
        required: true
        content:
          application/octet-stream:
            schema:
              type: string
              format: binary
      responses:
        "200":
          description: JSON result.
          content:
            application/json:
              schema:
                type: object
                required: ["success"]
                properties:
                  success:
                    type: boolean
                  data:
                    type: object
                    properties:
                      path:
                        type: string
                      bytes:
                        type: integer
                  reason:
                    type: string
              examples:
                ok:
                  summary: Success
                  x-zh-summary: "成功"
                  x-outcome: success
                  value:
                    success: true
                    data:
                      path: /scripts/main.js
                      bytes: 1024
                licenseDenied:
                  summary: "Failure: device license not valid (HTTP 200)"
                  x-zh-summary: "失败：设备许可无效（HTTP 200）"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    error: license
                    message: "授权已到期"
                    data:
                      enforced: true
                      valid: false
                      reason: expired
                      message: "授权已到期"
                      builtIn: false
                      hasKey: true
                      account: ""
                      isLogin: false
                      key: "1A2B3C4D…"
                      deviceId: "<device-id>"
                      expiresAt: 1796000000
                      maxDevices: 0
                      online: 0
                      lastOK: 1795990000
                      lastCheck: 1796000100
                      server: "https://api.ketec.top"
        "400":
          description: A required parameter is missing or invalid.
          x-zh-description: "必填参数缺失或无效。"
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
              examples:
                error:
                  summary: "Failure: missing or invalid parameter"
                  x-zh-summary: "失败：参数缺失或无效"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    message: "缺少有效的path参数"
        "413":
          description: Body larger than 200 MB.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
              examples:
                error:
                  summary: "Failure: body too large"
                  x-zh-summary: "失败：请求体过大"
                  x-outcome: failure
                  value:
                    success: false
                    reason: "文件过大（209715300 字节，上限 200MB）"
  /api/file/download:
    get:
      operationId: fileDownload
      summary: Download a file
      description: "Returns the file content as application/octet-stream. Screen recordings are stored under records/ in documents. Paths are relative to the chosen sandbox root; \"..\" is rejected."
      tags: ["Files"]
      x-zh-summary: "下载文件"
      x-zh-description: "以 application/octet-stream 返回文件内容。录屏文件保存在 documents 的 records/ 下。路径相对所选沙盒根目录；包含 \"..\" 会被拒绝。"
      x-modes: ["agent", "hid"]
      parameters:
        - name: dirType
          in: query
          required: false
          description: "Sandbox root: the App's Documents directory or its temporary directory."
          x-zh-description: "沙盒根目录：App 的 Documents 目录或临时目录。"
          schema:
            type: string
            enum: ["documents", "temp"]
            default: documents
          example: documents
        - name: path
          in: query
          required: true
          description: Relative path of the file.
          x-zh-description: "文件相对路径。"
          schema:
            type: string
          example: a.txt
      responses:
        "200":
          description: "File bytes, or JSON {success:false, reason} when the file is missing."
          content:
            application/octet-stream:
              schema:
                type: string
                format: binary
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
              examples:
                ok:
                  summary: Success
                  x-zh-summary: "成功"
                  x-outcome: success
                  value:
                    success: false
                    reason: "文件不存在或不可读"
        "400":
          description: A required parameter is missing or invalid.
          x-zh-description: "必填参数缺失或无效。"
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
              examples:
                error:
                  summary: "Failure: missing or invalid parameter"
                  x-zh-summary: "失败：参数缺失或无效"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    message: "缺少有效的path参数"
  /api/file/delete:
    get:
      operationId: fileDelete
      summary: Delete a file
      description: "Deletes the file (or folder) at `path`. Paths are relative to the chosen sandbox root; \"..\" is rejected."
      tags: ["Files"]
      x-zh-summary: "删除文件"
      x-zh-description: "删除 `path` 处的文件（或文件夹）。路径相对所选沙盒根目录；包含 \"..\" 会被拒绝。"
      x-modes: ["agent", "hid"]
      parameters:
        - name: dirType
          in: query
          required: false
          description: "Sandbox root: the App's Documents directory or its temporary directory."
          x-zh-description: "沙盒根目录：App 的 Documents 目录或临时目录。"
          schema:
            type: string
            enum: ["documents", "temp"]
            default: documents
          example: documents
        - name: path
          in: query
          required: true
          description: Relative path.
          x-zh-description: "相对路径。"
          schema:
            type: string
          example: a.txt
      responses:
        "200":
          description: JSON result.
          content:
            application/json:
              schema:
                oneOf:
                  - $ref: "#/components/schemas/SuccessResponse"
                  - $ref: "#/components/schemas/ErrorResponse"
              examples:
                ok:
                  summary: Success
                  x-zh-summary: "成功"
                  x-outcome: success
                  value:
                    success: true
                licenseDenied:
                  summary: "Failure: device license not valid (HTTP 200)"
                  x-zh-summary: "失败：设备许可无效（HTTP 200）"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    error: license
                    message: "授权已到期"
                    data:
                      enforced: true
                      valid: false
                      reason: expired
                      message: "授权已到期"
                      builtIn: false
                      hasKey: true
                      account: ""
                      isLogin: false
                      key: "1A2B3C4D…"
                      deviceId: "<device-id>"
                      expiresAt: 1796000000
                      maxDevices: 0
                      online: 0
                      lastOK: 1795990000
                      lastCheck: 1796000100
                      server: "https://api.ketec.top"
        "400":
          description: A required parameter is missing or invalid.
          x-zh-description: "必填参数缺失或无效。"
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
              examples:
                error:
                  summary: "Failure: missing or invalid parameter"
                  x-zh-summary: "失败：参数缺失或无效"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    message: "缺少有效的path参数"
  /api/file/deleteDir:
    get:
      operationId: fileDeleteDir
      summary: Delete a folder
      description: "Deletes the folder at `path` with all its content; fails if the path is not a folder. Paths are relative to the chosen sandbox root; \"..\" is rejected."
      tags: ["Files"]
      x-zh-summary: "删除目录"
      x-zh-description: "删除 `path` 处的文件夹及其全部内容；目标不是文件夹时失败。路径相对所选沙盒根目录；包含 \"..\" 会被拒绝。"
      x-modes: ["agent", "hid"]
      parameters:
        - name: dirType
          in: query
          required: false
          description: "Sandbox root: the App's Documents directory or its temporary directory."
          x-zh-description: "沙盒根目录：App 的 Documents 目录或临时目录。"
          schema:
            type: string
            enum: ["documents", "temp"]
            default: documents
          example: documents
        - name: path
          in: query
          required: true
          description: Relative folder path.
          x-zh-description: "文件夹相对路径。"
          schema:
            type: string
          example: tmp
      responses:
        "200":
          description: JSON result.
          content:
            application/json:
              schema:
                oneOf:
                  - $ref: "#/components/schemas/SuccessResponse"
                  - $ref: "#/components/schemas/ErrorResponse"
              examples:
                ok:
                  summary: Success
                  x-zh-summary: "成功"
                  x-outcome: success
                  value:
                    success: true
                licenseDenied:
                  summary: "Failure: device license not valid (HTTP 200)"
                  x-zh-summary: "失败：设备许可无效（HTTP 200）"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    error: license
                    message: "授权已到期"
                    data:
                      enforced: true
                      valid: false
                      reason: expired
                      message: "授权已到期"
                      builtIn: false
                      hasKey: true
                      account: ""
                      isLogin: false
                      key: "1A2B3C4D…"
                      deviceId: "<device-id>"
                      expiresAt: 1796000000
                      maxDevices: 0
                      online: 0
                      lastOK: 1795990000
                      lastCheck: 1796000100
                      server: "https://api.ketec.top"
        "400":
          description: A required parameter is missing or invalid.
          x-zh-description: "必填参数缺失或无效。"
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
              examples:
                error:
                  summary: "Failure: missing or invalid parameter"
                  x-zh-summary: "失败：参数缺失或无效"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    message: "缺少有效的path参数"
  /api/media/saveImageToAlbum:
    post:
      operationId: mediaSaveImageToAlbum
      summary: Save an image to the Photos album
      description: "Saves an image to the system Photos library. Accepts raw bytes, multipart/form-data (several files), JSON with Base64 `data`, or a `url` to download. The type is detected from the file header. Max 200 MB. The first call asks the user for photo-library permission on the phone."
      tags: ["Media"]
      x-zh-summary: "保存图片到相册"
      x-zh-description: "把图片保存到系统相册。支持原始二进制、multipart/form-data（可多文件）、带 Base64 `data` 的 JSON，或用 `url` 下载。按文件头识别类型，上限 200 MB。首次调用会在手机上弹出相册授权。"
      x-modes: ["agent", "hid"]
      parameters:
        - name: filename
          in: query
          required: false
          description: "File name; its extension helps detect the format."
          x-zh-description: "文件名；扩展名用于辅助识别格式。"
          schema:
            type: string
          example: photo.jpg
        - name: url
          in: query
          required: false
          description: http/https link to download and save instead of sending a body.
          x-zh-description: "改为下载该 http/https 链接并保存（无需请求体）。"
          schema:
            type: string
            format: uri
          example: "https://example.com/a.jpg"
      requestBody:
        required: false
        content:
          application/octet-stream:
            schema:
              type: string
              format: binary
              description: Raw file bytes.
          multipart/form-data:
            schema:
              type: object
              properties:
                file:
                  type: string
                  format: binary
              description: One or more file fields.
          application/json:
            schema:
              type: object
              properties:
                data:
                  type: string
                  description: "Base64 content (a data: URL prefix is allowed). Alias: base64."
                filename:
                  type: string
                url:
                  type: string
                  format: uri
            example:
              data: iVBORw0KGgo...
              filename: a.png
      responses:
        "200":
          description: JSON result.
          content:
            application/json:
              schema:
                type: object
                required: ["success"]
                properties:
                  success:
                    type: boolean
                  reason:
                    type: string
                  data:
                    oneOf:
                      - $ref: "#/components/schemas/MediaSaveItem"
                      - type: object
                        properties:
                          count:
                            type: integer
                          saved:
                            type: integer
                          items:
                            type: array
                            items:
                              $ref: "#/components/schemas/MediaSaveItem"
              examples:
                ok:
                  summary: Success
                  x-zh-summary: "成功"
                  x-outcome: success
                  value:
                    success: true
                    data:
                      filename: photo.jpg
                      bytes: 5364
                      kind: image
                      success: true
                      localIdentifier: "<asset-id>"
                licenseDenied:
                  summary: "Failure: device license not valid (HTTP 200)"
                  x-zh-summary: "失败：设备许可无效（HTTP 200）"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    error: license
                    message: "授权已到期"
                    data:
                      enforced: true
                      valid: false
                      reason: expired
                      message: "授权已到期"
                      builtIn: false
                      hasKey: true
                      account: ""
                      isLogin: false
                      key: "1A2B3C4D…"
                      deviceId: "<device-id>"
                      expiresAt: 1796000000
                      maxDevices: 0
                      online: 0
                      lastOK: 1795990000
                      lastCheck: 1796000100
                      server: "https://api.ketec.top"
        "400":
          description: A required parameter is missing or invalid.
          x-zh-description: "必填参数缺失或无效。"
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
              examples:
                error:
                  summary: "Failure: missing or invalid parameter"
                  x-zh-summary: "失败：参数缺失或无效"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    message: "请求体为空"
        "413":
          description: Body larger than 200 MB.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
              examples:
                error:
                  summary: "Failure: body too large"
                  x-zh-summary: "失败：请求体过大"
                  x-outcome: failure
                  value:
                    success: false
                    reason: "文件过大（…字节，上限 200MB）"
  /api/media/saveVideoToAlbumPath:
    post:
      operationId: mediaSaveVideoToAlbum
      summary: Save a video to the Photos album
      description: "Saves a video to the system Photos library (H.264 .mp4 / .mov recommended). Accepts raw bytes, multipart/form-data (several files), JSON with Base64 `data`, or a `url` to download. The type is detected from the file header. Max 200 MB. The first call asks the user for photo-library permission on the phone."
      tags: ["Media"]
      x-zh-summary: "保存视频到相册"
      x-zh-description: "把视频保存到系统相册（建议 H.264 的 .mp4 / .mov）。支持原始二进制、multipart/form-data（可多文件）、带 Base64 `data` 的 JSON，或用 `url` 下载。按文件头识别类型，上限 200 MB。首次调用会在手机上弹出相册授权。"
      x-modes: ["agent", "hid"]
      parameters:
        - name: filename
          in: query
          required: false
          description: "File name; its extension helps detect the format."
          x-zh-description: "文件名；扩展名用于辅助识别格式。"
          schema:
            type: string
          example: photo.jpg
        - name: url
          in: query
          required: false
          description: http/https link to download and save instead of sending a body.
          x-zh-description: "改为下载该 http/https 链接并保存（无需请求体）。"
          schema:
            type: string
            format: uri
          example: "https://example.com/a.jpg"
      requestBody:
        required: false
        content:
          application/octet-stream:
            schema:
              type: string
              format: binary
              description: Raw file bytes.
          multipart/form-data:
            schema:
              type: object
              properties:
                file:
                  type: string
                  format: binary
              description: One or more file fields.
          application/json:
            schema:
              type: object
              properties:
                data:
                  type: string
                  description: "Base64 content (a data: URL prefix is allowed). Alias: base64."
                filename:
                  type: string
                url:
                  type: string
                  format: uri
            example:
              data: iVBORw0KGgo...
              filename: a.png
      responses:
        "200":
          description: JSON result.
          content:
            application/json:
              schema:
                type: object
                required: ["success"]
                properties:
                  success:
                    type: boolean
                  reason:
                    type: string
                  data:
                    oneOf:
                      - $ref: "#/components/schemas/MediaSaveItem"
                      - type: object
                        properties:
                          count:
                            type: integer
                          saved:
                            type: integer
                          items:
                            type: array
                            items:
                              $ref: "#/components/schemas/MediaSaveItem"
              examples:
                ok:
                  summary: Success
                  x-zh-summary: "成功"
                  x-outcome: success
                  value:
                    success: true
                    data:
                      filename: photo.jpg
                      bytes: 5364
                      kind: image
                      success: true
                      localIdentifier: "<asset-id>"
                licenseDenied:
                  summary: "Failure: device license not valid (HTTP 200)"
                  x-zh-summary: "失败：设备许可无效（HTTP 200）"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    error: license
                    message: "授权已到期"
                    data:
                      enforced: true
                      valid: false
                      reason: expired
                      message: "授权已到期"
                      builtIn: false
                      hasKey: true
                      account: ""
                      isLogin: false
                      key: "1A2B3C4D…"
                      deviceId: "<device-id>"
                      expiresAt: 1796000000
                      maxDevices: 0
                      online: 0
                      lastOK: 1795990000
                      lastCheck: 1796000100
                      server: "https://api.ketec.top"
        "400":
          description: A required parameter is missing or invalid.
          x-zh-description: "必填参数缺失或无效。"
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
              examples:
                error:
                  summary: "Failure: missing or invalid parameter"
                  x-zh-summary: "失败：参数缺失或无效"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    message: "请求体为空"
        "413":
          description: Body larger than 200 MB.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
              examples:
                error:
                  summary: "Failure: body too large"
                  x-zh-summary: "失败：请求体过大"
                  x-outcome: failure
                  value:
                    success: false
                    reason: "文件过大（…字节，上限 200MB）"
  /api/media/save:
    post:
      operationId: mediaSave
      summary: Save images or videos to the album (auto-detect)
      description: "Unified upload: each file is saved as image or video according to its content. Accepts raw bytes, multipart/form-data (several files), JSON with Base64 `data`, or a `url` to download. The type is detected from the file header. Max 200 MB. The first call asks the user for photo-library permission on the phone. Also reachable as /api/media/upload."
      tags: ["Media"]
      x-zh-summary: "保存图片/视频到相册（自动识别）"
      x-zh-description: "统一入口：每个文件按内容自动识别为图片或视频后保存。支持原始二进制、multipart/form-data（可多文件）、带 Base64 `data` 的 JSON，或用 `url` 下载。按文件头识别类型，上限 200 MB。首次调用会在手机上弹出相册授权。也可通过 /api/media/upload 访问。"
      x-modes: ["agent", "hid"]
      parameters:
        - name: filename
          in: query
          required: false
          description: "File name; its extension helps detect the format."
          x-zh-description: "文件名；扩展名用于辅助识别格式。"
          schema:
            type: string
          example: photo.jpg
        - name: url
          in: query
          required: false
          description: http/https link to download and save instead of sending a body.
          x-zh-description: "改为下载该 http/https 链接并保存（无需请求体）。"
          schema:
            type: string
            format: uri
          example: "https://example.com/a.jpg"
      requestBody:
        required: false
        content:
          application/octet-stream:
            schema:
              type: string
              format: binary
              description: Raw file bytes.
          multipart/form-data:
            schema:
              type: object
              properties:
                file:
                  type: string
                  format: binary
              description: One or more file fields.
          application/json:
            schema:
              type: object
              properties:
                data:
                  type: string
                  description: "Base64 content (a data: URL prefix is allowed). Alias: base64."
                filename:
                  type: string
                url:
                  type: string
                  format: uri
            example:
              data: iVBORw0KGgo...
              filename: a.png
      responses:
        "200":
          description: JSON result.
          content:
            application/json:
              schema:
                type: object
                required: ["success"]
                properties:
                  success:
                    type: boolean
                  reason:
                    type: string
                  data:
                    oneOf:
                      - $ref: "#/components/schemas/MediaSaveItem"
                      - type: object
                        properties:
                          count:
                            type: integer
                          saved:
                            type: integer
                          items:
                            type: array
                            items:
                              $ref: "#/components/schemas/MediaSaveItem"
              examples:
                ok:
                  summary: Success
                  x-zh-summary: "成功"
                  x-outcome: success
                  value:
                    success: true
                    data:
                      filename: photo.jpg
                      bytes: 5364
                      kind: image
                      success: true
                      localIdentifier: "<asset-id>"
                licenseDenied:
                  summary: "Failure: device license not valid (HTTP 200)"
                  x-zh-summary: "失败：设备许可无效（HTTP 200）"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    error: license
                    message: "授权已到期"
                    data:
                      enforced: true
                      valid: false
                      reason: expired
                      message: "授权已到期"
                      builtIn: false
                      hasKey: true
                      account: ""
                      isLogin: false
                      key: "1A2B3C4D…"
                      deviceId: "<device-id>"
                      expiresAt: 1796000000
                      maxDevices: 0
                      online: 0
                      lastOK: 1795990000
                      lastCheck: 1796000100
                      server: "https://api.ketec.top"
        "400":
          description: A required parameter is missing or invalid.
          x-zh-description: "必填参数缺失或无效。"
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
              examples:
                error:
                  summary: "Failure: missing or invalid parameter"
                  x-zh-summary: "失败：参数缺失或无效"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    message: "请求体为空"
        "413":
          description: Body larger than 200 MB.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
              examples:
                error:
                  summary: "Failure: body too large"
                  x-zh-summary: "失败：请求体过大"
                  x-outcome: failure
                  value:
                    success: false
                    reason: "文件过大（…字节，上限 200MB）"
  /api/media/deleteAllPhotos:
    get:
      operationId: mediaDeleteAllPhotos
      summary: Delete all photos
      description: "Submits deletion of all photos (including screenshots) in the Photos library and returns immediately. iOS then shows a confirmation dialog; items are only deleted after the user confirms (deleted items go to Recently Deleted)."
      tags: ["Media"]
      x-zh-summary: "删除相册所有图片"
      x-zh-description: "提交删除相册中全部图片（含截屏）的请求并立即返回。随后 iOS 会弹出确认框，用户确认后才真正删除（进入「最近删除」）。"
      x-modes: ["agent", "hid"]
      responses:
        "200":
          description: JSON result.
          content:
            application/json:
              schema:
                type: object
                required: ["success"]
                properties:
                  success:
                    type: boolean
                  reason:
                    type: string
                  data:
                    type: object
                    properties:
                      submitted:
                        type: integer
                      kind:
                        type: string
                      note:
                        type: string
              examples:
                ok:
                  summary: Success
                  x-zh-summary: "成功"
                  x-outcome: success
                  value:
                    success: true
                    data:
                      submitted: 12
                      kind: "照片"
                      note: "已提交，系统会弹「允许删除」确认框，用户确认后才真正删除"
                licenseDenied:
                  summary: "Failure: device license not valid (HTTP 200)"
                  x-zh-summary: "失败：设备许可无效（HTTP 200）"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    error: license
                    message: "授权已到期"
                    data:
                      enforced: true
                      valid: false
                      reason: expired
                      message: "授权已到期"
                      builtIn: false
                      hasKey: true
                      account: ""
                      isLogin: false
                      key: "1A2B3C4D…"
                      deviceId: "<device-id>"
                      expiresAt: 1796000000
                      maxDevices: 0
                      online: 0
                      lastOK: 1795990000
                      lastCheck: 1796000100
                      server: "https://api.ketec.top"
  /api/media/deleteAllVideos:
    get:
      operationId: mediaDeleteAllVideos
      summary: Delete all videos
      description: "Submits deletion of all videos in the Photos library and returns immediately. iOS then shows a confirmation dialog; items are only deleted after the user confirms (deleted items go to Recently Deleted)."
      tags: ["Media"]
      x-zh-summary: "删除相册所有视频"
      x-zh-description: "提交删除相册中全部视频的请求并立即返回。随后 iOS 会弹出确认框，用户确认后才真正删除（进入「最近删除」）。"
      x-modes: ["agent", "hid"]
      responses:
        "200":
          description: JSON result.
          content:
            application/json:
              schema:
                type: object
                required: ["success"]
                properties:
                  success:
                    type: boolean
                  reason:
                    type: string
                  data:
                    type: object
                    properties:
                      submitted:
                        type: integer
                      kind:
                        type: string
                      note:
                        type: string
              examples:
                ok:
                  summary: Success
                  x-zh-summary: "成功"
                  x-outcome: success
                  value:
                    success: true
                    data:
                      submitted: 12
                      kind: "视频"
                      note: "已提交，系统会弹「允许删除」确认框，用户确认后才真正删除"
                licenseDenied:
                  summary: "Failure: device license not valid (HTTP 200)"
                  x-zh-summary: "失败：设备许可无效（HTTP 200）"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    error: license
                    message: "授权已到期"
                    data:
                      enforced: true
                      valid: false
                      reason: expired
                      message: "授权已到期"
                      builtIn: false
                      hasKey: true
                      account: ""
                      isLogin: false
                      key: "1A2B3C4D…"
                      deviceId: "<device-id>"
                      expiresAt: 1796000000
                      maxDevices: 0
                      online: 0
                      lastOK: 1795990000
                      lastCheck: 1796000100
                      server: "https://api.ketec.top"
  /api/media/deleteAllScreenshots:
    get:
      operationId: mediaDeleteAllScreenshots
      summary: Delete all screenshots
      description: "Submits deletion of all screenshots in the Photos library and returns immediately. iOS then shows a confirmation dialog; items are only deleted after the user confirms (deleted items go to Recently Deleted)."
      tags: ["Media"]
      x-zh-summary: "删除相册所有截屏"
      x-zh-description: "提交删除相册中全部截屏图片的请求并立即返回。随后 iOS 会弹出确认框，用户确认后才真正删除（进入「最近删除」）。"
      x-modes: ["agent", "hid"]
      responses:
        "200":
          description: JSON result.
          content:
            application/json:
              schema:
                type: object
                required: ["success"]
                properties:
                  success:
                    type: boolean
                  reason:
                    type: string
                  data:
                    type: object
                    properties:
                      submitted:
                        type: integer
                      kind:
                        type: string
                      note:
                        type: string
              examples:
                ok:
                  summary: Success
                  x-zh-summary: "成功"
                  x-outcome: success
                  value:
                    success: true
                    data:
                      submitted: 12
                      kind: "截图"
                      note: "已提交，系统会弹「允许删除」确认框，用户确认后才真正删除"
                licenseDenied:
                  summary: "Failure: device license not valid (HTTP 200)"
                  x-zh-summary: "失败：设备许可无效（HTTP 200）"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    error: license
                    message: "授权已到期"
                    data:
                      enforced: true
                      valid: false
                      reason: expired
                      message: "授权已到期"
                      builtIn: false
                      hasKey: true
                      account: ""
                      isLogin: false
                      key: "1A2B3C4D…"
                      deviceId: "<device-id>"
                      expiresAt: 1796000000
                      maxDevices: 0
                      online: 0
                      lastOK: 1795990000
                      lastCheck: 1796000100
                      server: "https://api.ketec.top"
  /logger/files:
    get:
      operationId: listLogFiles
      summary: List log files
      description: Returns the app log files, newest first. The response body is a JSON array (no success wrapper).
      tags: ["Logs"]
      x-zh-summary: "日志列表"
      x-zh-description: "返回 App 日志文件列表，按时间倒序。响应体是 JSON 数组（没有 success 外层）。"
      x-modes: ["agent", "hid"]
      responses:
        "200":
          description: JSON result.
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: "#/components/schemas/LogFileEntry"
              examples:
                ok:
                  summary: Success
                  x-zh-summary: "成功"
                  x-outcome: success
                  value:
                    - filePath: "<app-sandbox>/Documents/logs/ketec.log"
                      fileName: ketec.log
                      modificationDate: "2026-11-30T08:00:00Z"
                      fileSize: "120 KB"
                licenseDenied:
                  summary: "Failure: device license not valid (HTTP 200)"
                  x-zh-summary: "失败：设备许可无效（HTTP 200）"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    error: license
                    message: "授权已到期"
                    data:
                      enforced: true
                      valid: false
                      reason: expired
                      message: "授权已到期"
                      builtIn: false
                      hasKey: true
                      account: ""
                      isLogin: false
                      key: "1A2B3C4D…"
                      deviceId: "<device-id>"
                      expiresAt: 1796000000
                      maxDevices: 0
                      online: 0
                      lastOK: 1795990000
                      lastCheck: 1796000100
                      server: "https://api.ketec.top"
  /logger/download:
    get:
      operationId: downloadLogFile
      summary: Download a log file
      description: Returns the content of a log file as application/octet-stream. Without fileName the latest file (by name) is returned.
      tags: ["Logs"]
      x-zh-summary: "下载日志"
      x-zh-description: "以 application/octet-stream 返回日志文件内容。不传 fileName 时返回（按文件名排序的）最新一个。"
      x-modes: ["agent", "hid"]
      parameters:
        - name: fileName
          in: query
          required: false
          description: File name from /logger/files.
          x-zh-description: "来自 /logger/files 的文件名。"
          schema:
            type: string
          example: ketec.log
      responses:
        "200":
          description: Log file bytes. When the device license is not valid the reply is JSON instead (see the license example).
          content:
            application/octet-stream:
              schema:
                type: string
                format: binary
              examples:
                ok:
                  summary: Success (binary stream, abbreviated)
                  x-zh-summary: "成功（二进制流，节选示意）"
                  x-outcome: success
                  x-inferred: true
                  value: |-
                    [2026-12-03 10:00:00] [boot] ketec 330v223 …
                    [2026-12-03 10:00:01] [http] listening on :9800
                    …
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
              examples:
                licenseDenied:
                  summary: "Failure: device license not valid (HTTP 200)"
                  x-zh-summary: "失败：设备许可无效（HTTP 200）"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    error: license
                    message: "授权已到期"
                    data:
                      enforced: true
                      valid: false
                      reason: expired
                      message: "授权已到期"
                      builtIn: false
                      hasKey: true
                      account: ""
                      isLogin: false
                      key: "1A2B3C4D…"
                      deviceId: "<device-id>"
                      expiresAt: 1796000000
                      maxDevices: 0
                      online: 0
                      lastOK: 1795990000
                      lastCheck: 1796000100
                      server: "https://api.ketec.top"
        "400":
          $ref: "#/components/responses/BadRequest"
  /logger/current/lines:
    get:
      operationId: getCurrentLogLines
      summary: Get the latest log lines
      description: "Returns the last `count` non-empty lines of the current log. hasMore=true means older lines exist. The body has no success field."
      tags: ["Logs"]
      x-zh-summary: "获取当前实时日志"
      x-zh-description: "返回当前日志最后 `count` 行（去掉空行）。hasMore=true 表示前面还有更早的行。响应体没有 success 字段。"
      x-modes: ["agent", "hid"]
      parameters:
        - name: count
          in: query
          required: false
          description: Number of lines to return.
          x-zh-description: "返回行数。"
          schema:
            type: integer
            minimum: 1
            default: 200
          example: 100
      responses:
        "200":
          description: JSON result.
          content:
            application/json:
              schema:
                type: object
                required: ["lines", "hasMore"]
                properties:
                  lines:
                    type: array
                    items:
                      type: string
                  hasMore:
                    type: boolean
              examples:
                ok:
                  summary: Success
                  x-zh-summary: "成功"
                  x-outcome: success
                  value:
                    lines: ["[12:00:01] script started", "[12:00:02] click 540,1200"]
                    hasMore: true
                licenseDenied:
                  summary: "Failure: device license not valid (HTTP 200)"
                  x-zh-summary: "失败：设备许可无效（HTTP 200）"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    error: license
                    message: "授权已到期"
                    data:
                      enforced: true
                      valid: false
                      reason: expired
                      message: "授权已到期"
                      builtIn: false
                      hasKey: true
                      account: ""
                      isLogin: false
                      key: "1A2B3C4D…"
                      deviceId: "<device-id>"
                      expiresAt: 1796000000
                      maxDevices: 0
                      online: 0
                      lastOK: 1795990000
                      lastCheck: 1796000100
                      server: "https://api.ketec.top"
  /mirror/image:
    get:
      operationId: mirrorMjpeg
      summary: Live screen stream (MJPEG)
      description: "Requires the ketec screen broadcast to be running (iOS requires the user to start it once from the system broadcast picker / Control Center). Streams JPEG frames as multipart/x-mixed-replace (boundary kcframe) until the client disconnects; usable directly in an <img> tag. Also reachable as /api/mirror/image and /api/mirror/mjpeg."
      tags: ["Screen Mirror"]
      x-zh-summary: "实时屏幕流 MJPEG"
      x-zh-description: "需要 ketec 屏幕直播正在运行（iOS 要求用户在系统直播选择器 / 控制中心里手动开始一次）。以 multipart/x-mixed-replace（boundary 为 kcframe）持续推送 JPEG 帧，直到客户端断开；可直接放进 <img> 标签。也可通过 /api/mirror/image、/api/mirror/mjpeg 访问。"
      x-modes: ["agent", "hid"]
      parameters:
        - name: scalingFactor
          in: query
          required: false
          description: "Output size = device pixels × factor. Divide stream coordinates by this factor before sending clicks."
          x-zh-description: "输出尺寸 = 设备像素 × 系数。用画面坐标点击前请先除以该系数。"
          schema:
            type: number
            exclusiveMinimum: 0
            default: 1
          example: 0.5
      responses:
        "200":
          description: Endless multipart JPEG stream. When the device license is not valid the reply is JSON instead (see the license example).
          content:
            "multipart/x-mixed-replace; boundary=kcframe":
              schema:
                type: string
                format: binary
              examples:
                ok:
                  summary: Success (binary stream, abbreviated)
                  x-zh-summary: "成功（二进制流，节选示意）"
                  x-outcome: success
                  x-inferred: true
                  value: "--kcframe\r\nContent-Type: image/jpeg\r\nContent-Length: 48213\r\n\r\n<JPEG 帧二进制>\r\n--kcframe\r\n…"
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
              examples:
                licenseDenied:
                  summary: "Failure: device license not valid (HTTP 200)"
                  x-zh-summary: "失败：设备许可无效（HTTP 200）"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    error: license
                    message: "授权已到期"
                    data:
                      enforced: true
                      valid: false
                      reason: expired
                      message: "授权已到期"
                      builtIn: false
                      hasKey: true
                      account: ""
                      isLogin: false
                      key: "1A2B3C4D…"
                      deviceId: "<device-id>"
                      expiresAt: 1796000000
                      maxDevices: 0
                      online: 0
                      lastOK: 1795990000
                      lastCheck: 1796000100
                      server: "https://api.ketec.top"
  /mirror/flv:
    get:
      operationId: mirrorFlv
      summary: Live screen stream (H.264 HTTP-FLV)
      description: "Requires the ketec screen broadcast to be running (iOS requires the user to start it once from the system broadcast picker / Control Center). Streams H.264 video in an FLV container (video/x-flv) until the client disconnects; play it with an FLV player such as flv.js or ffplay. Also reachable as /api/mirror/flv."
      tags: ["Screen Mirror"]
      x-zh-summary: "实时屏幕流 H264 HTTP-FLV"
      x-zh-description: "需要 ketec 屏幕直播正在运行（iOS 要求用户在系统直播选择器 / 控制中心里手动开始一次）。以 FLV 封装（video/x-flv）持续推送 H.264 视频，直到客户端断开；可用 flv.js、ffplay 等播放。也可通过 /api/mirror/flv 访问。"
      x-modes: ["agent", "hid"]
      parameters:
        - name: fps
          in: query
          required: false
          description: Target frame rate.
          x-zh-description: "目标帧率。"
          schema:
            type: integer
            minimum: 1
            maximum: 60
            default: 10
          example: 15
        - name: scalingFactor
          in: query
          required: false
          description: "Output size = device pixels × factor."
          x-zh-description: "输出尺寸 = 设备像素 × 系数。"
          schema:
            type: number
            minimum: 0.1
            maximum: 1
            default: 1
          example: 0.5
        - name: bitrate
          in: query
          required: false
          description: Target bitrate in Mbit/s.
          x-zh-description: "目标码率（Mbit/s）。"
          schema:
            type: number
            minimum: 0.1
            maximum: 50
            default: 4
          example: 4
        - name: quality
          in: query
          required: false
          description: "Accepted for compatibility; has no visible effect (use scalingFactor)."
          x-zh-description: "兼容参数，无实际效果（请用 scalingFactor）。"
          schema:
            type: number
            minimum: 0.1
            maximum: 1
          example: 0.5
      responses:
        "200":
          description: Endless FLV stream. When the device license is not valid the reply is JSON instead (see the license example).
          content:
            video/x-flv:
              schema:
                type: string
                format: binary
              examples:
                ok:
                  summary: Success (binary stream, abbreviated)
                  x-zh-summary: "成功（二进制流，节选示意）"
                  x-outcome: success
                  x-inferred: true
                  value: "FLV <FLV 头 + H.264 视频 tag 持续推送，直到客户端断开>"
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
              examples:
                licenseDenied:
                  summary: "Failure: device license not valid (HTTP 200)"
                  x-zh-summary: "失败：设备许可无效（HTTP 200）"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    error: license
                    message: "授权已到期"
                    data:
                      enforced: true
                      valid: false
                      reason: expired
                      message: "授权已到期"
                      builtIn: false
                      hasKey: true
                      account: ""
                      isLogin: false
                      key: "1A2B3C4D…"
                      deviceId: "<device-id>"
                      expiresAt: 1796000000
                      maxDevices: 0
                      online: 0
                      lastOK: 1795990000
                      lastCheck: 1796000100
                      server: "https://api.ketec.top"
  /api/hid/openRecordScreen:
    get:
      operationId: startRecordScreen
      summary: Start screen recording
      description: "Starts recording to an MP4 file. If the screen broadcast is running, the whole screen is recorded; otherwise only ketec's own window. Files are saved under records/ in the documents sandbox (download with /api/file/download). Works in both modes; also reachable as /api/control/startRecordScreen."
      tags: ["Screen Mirror"]
      x-zh-summary: "开始录屏"
      x-zh-description: "开始录制 MP4。屏幕直播在运行时录整屏，否则只录 ketec 自己的窗口。文件保存在 documents 沙盒的 records/ 下（用 /api/file/download 下载）。两种模式均可用；也可通过 /api/control/startRecordScreen 访问。"
      x-modes: ["agent", "hid"]
      parameters:
        - name: fps
          in: query
          required: false
          description: "Recording frame rate (1–30)."
          x-zh-description: "录制帧率（1–30）。"
          schema:
            type: integer
            minimum: 1
            default: 10
            maximum: 30
          example: 10
        - name: source
          in: query
          required: false
          description: "Frame source. Default: broadcast when the screen broadcast is connected, otherwise internal (ketec window)."
          x-zh-description: "帧来源。缺省：屏幕直播已连接时为 broadcast，否则为 internal（ketec 窗口）。"
          schema:
            type: string
            enum: ["broadcast", "internal"]
          example: broadcast
      responses:
        "200":
          description: JSON result.
          content:
            application/json:
              schema:
                type: object
                required: ["success"]
                properties:
                  success:
                    type: boolean
                  message:
                    type: string
                  data:
                    $ref: "#/components/schemas/RecordState"
              examples:
                ok:
                  summary: Success
                  x-zh-summary: "成功"
                  x-outcome: success
                  value:
                    success: true
                    data:
                      isRecording: true
                      fps: 10
                      frames: 0
                      duration: 0
                      path: rec-20261130-120000.mp4
                      captureSource: broadcast
                      frameSource: broadcast
                      canCaptureFullScreen: true
                      broadcastSupported: true
                      lastBroadcastEvent: started
                      lastBroadcastAt: 1764504000
                licenseDenied:
                  summary: "Failure: device license not valid (HTTP 200)"
                  x-zh-summary: "失败：设备许可无效（HTTP 200）"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    error: license
                    message: "授权已到期"
                    data:
                      enforced: true
                      valid: false
                      reason: expired
                      message: "授权已到期"
                      builtIn: false
                      hasKey: true
                      account: ""
                      isLogin: false
                      key: "1A2B3C4D…"
                      deviceId: "<device-id>"
                      expiresAt: 1796000000
                      maxDevices: 0
                      online: 0
                      lastOK: 1795990000
                      lastCheck: 1796000100
                      server: "https://api.ketec.top"
  /api/hid/closeRecordScreen:
    get:
      operationId: stopRecordScreen
      summary: Stop screen recording
      description: "Stops the current recording; the file is finalized in the background (saving=true). Returns success=false when nothing is being recorded. Also reachable as /api/control/stopRecordScreen."
      tags: ["Screen Mirror"]
      x-zh-summary: "停止录屏"
      x-zh-description: "停止当前录制，文件在后台完成写入（saving=true）。未在录制时返回 success=false。也可通过 /api/control/stopRecordScreen 访问。"
      x-modes: ["agent", "hid"]
      responses:
        "200":
          description: JSON result.
          content:
            application/json:
              schema:
                type: object
                required: ["success"]
                properties:
                  success:
                    type: boolean
                  message:
                    type: string
                  data:
                    type: object
                    properties:
                      name:
                        type: string
                      saving:
                        type: boolean
              examples:
                ok:
                  summary: Success
                  x-zh-summary: "成功"
                  x-outcome: success
                  value:
                    success: true
                    data:
                      name: rec-20261130-120000.mp4
                      saving: true
                licenseDenied:
                  summary: "Failure: device license not valid (HTTP 200)"
                  x-zh-summary: "失败：设备许可无效（HTTP 200）"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    error: license
                    message: "授权已到期"
                    data:
                      enforced: true
                      valid: false
                      reason: expired
                      message: "授权已到期"
                      builtIn: false
                      hasKey: true
                      account: ""
                      isLogin: false
                      key: "1A2B3C4D…"
                      deviceId: "<device-id>"
                      expiresAt: 1796000000
                      maxDevices: 0
                      online: 0
                      lastOK: 1795990000
                      lastCheck: 1796000100
                      server: "https://api.ketec.top"
  /api/hid/isRecording:
    get:
      operationId: isRecording
      summary: Is the screen being recorded or broadcast
      description: Returns true while ketec is recording or while the screen broadcast is running (same meaning as isRecording in /api/status).
      tags: ["Screen Mirror"]
      x-zh-summary: "获取录屏状态"
      x-zh-description: "ketec 正在录制或屏幕直播正在运行时返回 true（与 /api/status 的 isRecording 同口径）。"
      x-modes: ["agent", "hid"]
      responses:
        "200":
          description: JSON result.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/BoolDataResponse"
              examples:
                ok:
                  summary: Success
                  x-zh-summary: "成功"
                  x-outcome: success
                  value:
                    success: true
                    data: false
                licenseDenied:
                  summary: "Failure: device license not valid (HTTP 200)"
                  x-zh-summary: "失败：设备许可无效（HTTP 200）"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    error: license
                    message: "授权已到期"
                    data:
                      enforced: true
                      valid: false
                      reason: expired
                      message: "授权已到期"
                      builtIn: false
                      hasKey: true
                      account: ""
                      isLogin: false
                      key: "1A2B3C4D…"
                      deviceId: "<device-id>"
                      expiresAt: 1796000000
                      maxDevices: 0
                      online: 0
                      lastOK: 1795990000
                      lastCheck: 1796000100
                      server: "https://api.ketec.top"
  /api/license:
    get:
      operationId: getLicense
      summary: Get the device license status
      description: "Returns the license state of this phone: whether it is licensed (valid / isLogin), the reason, the account name when signed in with an account, the first 8 characters of the key in use, the device limit, online count and expiry of the license. Always answered, even when the device is not licensed. After /api/login the license is verified in the background; poll this endpoint until reason is no longer checking."
      x-zh-description: "返回本机授权状态：是否已授权（valid / isLogin）、原因、用账号登录时的账号名、当前所用 key 的前 8 位、许可的设备上限、在线数和到期时间。未授权时也会正常应答。调用 /api/login 后许可在后台验证，轮询本接口直到 reason 不再是 checking。"
      x-zh-summary: "查询设备授权状态"
      tags: ["Account & License"]
      x-modes: ["agent", "hid"]
      responses:
        "200":
          description: JSON result.
          x-zh-description: "JSON 结果。"
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/LicenseResponse"
              examples:
                ok:
                  summary: "Success: licensed"
                  x-zh-summary: "成功：已授权"
                  x-outcome: success
                  x-inferred: true
                  value:
                    success: true
                    data:
                      enforced: true
                      valid: true
                      reason: "ok"
                      message: "已授权"
                      builtIn: false
                      hasKey: true
                      account: ""
                      isLogin: true
                      key: "4F0DCB53…"
                      deviceId: "<device-id>"
                      expiresAt: 1827851075
                      maxDevices: 1500
                      online: 12
                      lastOK: 1796000100
                      lastCheck: 1796000100
                      server: "https://api.ketec.top"
                noKey:
                  summary: "Not signed in (success is still true; check data.valid)"
                  x-zh-summary: "未登录（success 仍为 true，看 data.valid）"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: true
                    data:
                      enforced: true
                      valid: false
                      reason: "no_key"
                      message: "未登录：请登录账号或输入授权码"
                      builtIn: false
                      hasKey: false
                      account: ""
                      isLogin: false
                      key: ""
                      deviceId: "<device-id>"
                      expiresAt: 0
                      maxDevices: 0
                      online: 0
                      lastOK: 0
                      lastCheck: 1796000000
                      server: "https://api.ketec.top"
  /api/login:
    post:
      operationId: login
      summary: Sign this device in (TokenKey or username + password)
      description: "Signs the phone in so that it uses the license of an account. Send either a key (account key or TokenKey; aliases token / tokenKey) or username + password; when username is present the account sign-in is used. A key is saved at once and verified in the background (data.reason = checking). An account sign-in waits up to 20 seconds for the license service, then saves the account's key. Any previous key or account on the phone is replaced and its online seat released. Fields can be sent as a JSON body or as query parameters. This endpoint works before the device is licensed. Fails on builds with a built-in license key."
      x-zh-description: "给这台手机登录，让它使用某个账号的许可。二选一：传 key（账号主 key 或 TokenKey，别名 token / tokenKey），或传 username + password；带了 username 就按账号密码登录。传 key 时立即保存，并在后台验证（data.reason = checking）。账号密码登录会等授权服务回包（最多 20 秒），成功后保存该账号的 key。手机上原来的 key 或账号会被替换，并让出它占的在线席位。参数放 JSON 体或查询串都可以。设备未授权时也能调用。内置了授权码的安装包会返回失败。"
      x-zh-summary: "给设备登录（TokenKey 或账号密码）"
      tags: ["Account & License"]
      x-modes: ["agent", "hid"]
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                key:
                  type: string
                  description: "Account key or TokenKey (36-character uppercase UUID; 32 hex digits without dashes are also accepted). Aliases: token, tokenKey."
                  x-zh-description: "账号主 key 或 TokenKey（36 位大写 UUID；不带横线的 32 位十六进制也接受）。别名：token、tokenKey。"
                token:
                  type: string
                  description: Alias of key.
                  x-zh-description: "key 的别名。"
                tokenKey:
                  type: string
                  description: Alias of key.
                  x-zh-description: "key 的别名。"
                username:
                  type: string
                  description: "Account username (alias: account)."
                  x-zh-description: "账号用户名（别名 account）。"
                password:
                  type: string
                  description: Account password (6–64 characters).
                  x-zh-description: "账号密码（6–64 位）。"
            examples:
              tokenKey:
                summary: Sign in with a TokenKey or account key
                x-zh-summary: "用 TokenKey 或账号主 key 登录"
                value:
                  tokenKey: "4F0DCB53-478C-456A-AFA9-E682F56FE73A"
              account:
                summary: Sign in with username and password
                x-zh-summary: "用账号密码登录"
                value:
                  username: studio-a
                  password: "••••••••"
      responses:
        "200":
          description: "JSON result; data is always the license status after the call. Failures also use HTTP 200 with success false."
          x-zh-description: "JSON 结果；data 恒为调用后的授权状态。失败同样是 HTTP 200、success 为 false。"
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/LicenseResponse"
              examples:
                keySaved:
                  summary: "Success: key saved, verification running"
                  x-zh-summary: "成功：key 已保存，正在验证"
                  x-outcome: success
                  x-inferred: true
                  value:
                    success: true
                    data:
                      enforced: true
                      valid: false
                      reason: "checking"
                      message: "正在验证授权…"
                      builtIn: false
                      hasKey: true
                      account: ""
                      isLogin: false
                      key: "4F0DCB53…"
                      deviceId: "<device-id>"
                      expiresAt: 0
                      maxDevices: 0
                      online: 0
                      lastOK: 0
                      lastCheck: 1796000000
                      server: "https://api.ketec.top"
                accountOk:
                  summary: "Success: signed in with an account"
                  x-zh-summary: "成功：账号登录成功"
                  x-outcome: success
                  x-inferred: true
                  value:
                    success: true
                    data:
                      enforced: true
                      valid: false
                      reason: "checking"
                      message: "正在验证授权…"
                      builtIn: false
                      hasKey: true
                      account: "studio-a"
                      isLogin: false
                      key: "4F0DCB53…"
                      deviceId: "<device-id>"
                      expiresAt: 0
                      maxDevices: 0
                      online: 0
                      lastOK: 0
                      lastCheck: 1796000000
                      server: "https://api.ketec.top"
                badCredentials:
                  summary: "Failure: wrong username or password"
                  x-zh-summary: "失败：用户名或密码错误"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    error: "用户名或密码错误"
                    message: "用户名或密码错误"
                    data:
                      enforced: true
                      valid: false
                      reason: "no_key"
                      message: "未登录：请登录账号或输入授权码"
                      builtIn: false
                      hasKey: false
                      account: ""
                      isLogin: false
                      key: ""
                      deviceId: "<device-id>"
                      expiresAt: 0
                      maxDevices: 0
                      online: 0
                      lastOK: 0
                      lastCheck: 1796000000
                      server: "https://api.ketec.top"
                badKey:
                  summary: "Failure: malformed key"
                  x-zh-summary: "失败：授权码格式不对"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    error: "授权码格式不对：应为 36 位（含 4 个横线）的字母数字组合"
                    message: "授权码格式不对：应为 36 位（含 4 个横线）的字母数字组合"
                    data:
                      enforced: true
                      valid: false
                      reason: "no_key"
                      message: "未登录：请登录账号或输入授权码"
                      builtIn: false
                      hasKey: false
                      account: ""
                      isLogin: false
                      key: ""
                      deviceId: "<device-id>"
                      expiresAt: 0
                      maxDevices: 0
                      online: 0
                      lastOK: 0
                      lastCheck: 1796000000
                      server: "https://api.ketec.top"
                noServer:
                  summary: "Failure: license service unreachable"
                  x-zh-summary: "失败：连不上授权服务"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    error: "无法连接授权服务器"
                    message: "无法连接授权服务器"
                    data:
                      enforced: true
                      valid: false
                      reason: "no_key"
                      message: "未登录：请登录账号或输入授权码"
                      builtIn: false
                      hasKey: false
                      account: ""
                      isLogin: false
                      key: ""
                      deviceId: "<device-id>"
                      expiresAt: 0
                      maxDevices: 0
                      online: 0
                      lastOK: 0
                      lastCheck: 1796000000
                      server: "https://api.ketec.top"
                builtIn:
                  summary: "Failure: this build has a built-in license key"
                  x-zh-summary: "失败：安装包内置了授权码"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    error: "此安装包已内置授权，不能更换"
                    message: "此安装包已内置授权，不能更换"
                    data:
                      enforced: true
                      valid: true
                      reason: "ok"
                      message: "已授权"
                      builtIn: true
                      hasKey: true
                      account: ""
                      isLogin: true
                      key: "4F0DCB53…"
                      deviceId: "<device-id>"
                      expiresAt: 1827851075
                      maxDevices: 1500
                      online: 12
                      lastOK: 1796000100
                      lastCheck: 1796000100
                      server: "https://api.ketec.top"
  /api/license/activate:
    post:
      operationId: activateLicense
      summary: Set the license key (TokenKey or account key)
      description: "Same as /api/login with a key: saves the key and verifies it in the background. Poll /api/license for the result (reason unknown_key = the key does not exist, token_revoked = the TokenKey was revoked)."
      x-zh-description: "等同于用 key 调 /api/login：保存 key 并在后台验证。结果轮询 /api/license（reason 为 unknown_key = key 不存在，token_revoked = TokenKey 已作废）。"
      x-zh-summary: "写入授权码（TokenKey 或账号主 key）"
      tags: ["Account & License"]
      x-modes: ["agent", "hid"]
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                key:
                  type: string
                  description: "Account key or TokenKey (36-character uppercase UUID; 32 hex digits without dashes are also accepted). Aliases: token, tokenKey."
                  x-zh-description: "账号主 key 或 TokenKey（36 位大写 UUID；不带横线的 32 位十六进制也接受）。别名：token、tokenKey。"
                token:
                  type: string
                  description: Alias of key.
                  x-zh-description: "key 的别名。"
                tokenKey:
                  type: string
                  description: Alias of key.
                  x-zh-description: "key 的别名。"
            example:
              key: "4F0DCB53-478C-456A-AFA9-E682F56FE73A"
      responses:
        "200":
          description: "JSON result; data is always the license status after the call. Failures also use HTTP 200 with success false."
          x-zh-description: "JSON 结果；data 恒为调用后的授权状态。失败同样是 HTTP 200、success 为 false。"
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/LicenseResponse"
              examples:
                ok:
                  summary: "Success: key saved, verification running"
                  x-zh-summary: "成功：key 已保存，正在验证"
                  x-outcome: success
                  x-inferred: true
                  value:
                    success: true
                    data:
                      enforced: true
                      valid: false
                      reason: "checking"
                      message: "正在验证授权…"
                      builtIn: false
                      hasKey: true
                      account: ""
                      isLogin: false
                      key: "4F0DCB53…"
                      deviceId: "<device-id>"
                      expiresAt: 0
                      maxDevices: 0
                      online: 0
                      lastOK: 0
                      lastCheck: 1796000000
                      server: "https://api.ketec.top"
                badKey:
                  summary: "Failure: malformed key"
                  x-zh-summary: "失败：授权码格式不对"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    error: "授权码格式不对：应为 36 位（含 4 个横线）的字母数字组合"
                    message: "授权码格式不对：应为 36 位（含 4 个横线）的字母数字组合"
                    data:
                      enforced: true
                      valid: false
                      reason: "no_key"
                      message: "未登录：请登录账号或输入授权码"
                      builtIn: false
                      hasKey: false
                      account: ""
                      isLogin: false
                      key: ""
                      deviceId: "<device-id>"
                      expiresAt: 0
                      maxDevices: 0
                      online: 0
                      lastOK: 0
                      lastCheck: 1796000000
                      server: "https://api.ketec.top"
                unknownKeyLater:
                  summary: "Later, in /api/license: the key does not exist"
                  x-zh-summary: "随后在 /api/license 里看到：key 不存在"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: true
                    data:
                      enforced: true
                      valid: false
                      reason: "unknown_key"
                      message: "授权码无效，请检查后重新输入"
                      builtIn: false
                      hasKey: true
                      account: ""
                      isLogin: false
                      key: "4F0DCB53…"
                      deviceId: "<device-id>"
                      expiresAt: 0
                      maxDevices: 0
                      online: 0
                      lastOK: 0
                      lastCheck: 1796000000
                      server: "https://api.ketec.top"
  /api/register:
    post:
      operationId: registerAccount
      summary: Register an account and sign this device in
      description: "Creates a new account on the license service and signs the phone in with it (waits up to 20 seconds). A new account has no device license until one is bought, so data.reason becomes expired after verification. Username: 3–32 characters, starting with a letter or digit, letters, digits and _ . @ -; password: 6–64 characters."
      x-zh-description: "在授权服务上注册新账号，并用它给这台手机登录（最多等 20 秒）。新账号在购买前没有设备许可，所以验证后 data.reason 会是 expired。用户名 3–32 位，以字母或数字开头，可用字母、数字和 _ . @ -；密码 6–64 位。"
      x-zh-summary: "注册账号并给设备登录"
      tags: ["Account & License"]
      x-modes: ["agent", "hid"]
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: ["username", "password"]
              properties:
                username:
                  type: string
                  description: "Account username (alias: account)."
                  x-zh-description: "账号用户名（别名 account）。"
                password:
                  type: string
                  description: Account password (6–64 characters).
                  x-zh-description: "账号密码（6–64 位）。"
            example:
              username: studio-a
              password: "••••••••"
      responses:
        "200":
          description: "JSON result; data is always the license status after the call. Failures also use HTTP 200 with success false."
          x-zh-description: "JSON 结果；data 恒为调用后的授权状态。失败同样是 HTTP 200、success 为 false。"
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/LicenseResponse"
              examples:
                ok:
                  summary: "Success: registered and signed in"
                  x-zh-summary: "成功：已注册并登录"
                  x-outcome: success
                  x-inferred: true
                  value:
                    success: true
                    data:
                      enforced: true
                      valid: false
                      reason: "checking"
                      message: "正在验证授权…"
                      builtIn: false
                      hasKey: true
                      account: "studio-a"
                      isLogin: false
                      key: "4F0DCB53…"
                      deviceId: "<device-id>"
                      expiresAt: 0
                      maxDevices: 0
                      online: 0
                      lastOK: 0
                      lastCheck: 1796000000
                      server: "https://api.ketec.top"
                exists:
                  summary: "Failure: username taken"
                  x-zh-summary: "失败：用户名已被注册"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    error: "用户名已被注册"
                    message: "用户名已被注册"
                    data:
                      enforced: true
                      valid: false
                      reason: "no_key"
                      message: "未登录：请登录账号或输入授权码"
                      builtIn: false
                      hasKey: false
                      account: ""
                      isLogin: false
                      key: ""
                      deviceId: "<device-id>"
                      expiresAt: 0
                      maxDevices: 0
                      online: 0
                      lastOK: 0
                      lastCheck: 1796000000
                      server: "https://api.ketec.top"
                missing:
                  summary: "Failure: username or password missing"
                  x-zh-summary: "失败：缺少用户名或密码"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    error: "请提供 username 和 password（或 key）"
                    message: "请提供 username 和 password（或 key）"
                    data:
                      enforced: true
                      valid: false
                      reason: "no_key"
                      message: "未登录：请登录账号或输入授权码"
                      builtIn: false
                      hasKey: false
                      account: ""
                      isLogin: false
                      key: ""
                      deviceId: "<device-id>"
                      expiresAt: 0
                      maxDevices: 0
                      online: 0
                      lastOK: 0
                      lastCheck: 1796000000
                      server: "https://api.ketec.top"
  /api/logout:
    post:
      operationId: logout
      summary: Sign this device out
      description: "Removes the key / account from the phone and releases its online seat on the license service. Afterwards most endpoints return the license error until the device signs in again. Alias: /api/license/logout."
      x-zh-description: "清掉手机上的 key / 账号，并在授权服务上让出它的在线席位。之后大多数接口会返回授权错误，直到重新登录。别名：/api/license/logout。"
      x-zh-summary: "给设备退出登录"
      tags: ["Account & License"]
      x-modes: ["agent", "hid"]
      responses:
        "200":
          description: "JSON result; data is always the license status after the call. Failures also use HTTP 200 with success false."
          x-zh-description: "JSON 结果；data 恒为调用后的授权状态。失败同样是 HTTP 200、success 为 false。"
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/LicenseResponse"
              examples:
                ok:
                  summary: "Success: signed out"
                  x-zh-summary: "成功：已退出"
                  x-outcome: success
                  x-inferred: true
                  value:
                    success: true
                    data:
                      enforced: true
                      valid: false
                      reason: "no_key"
                      message: "未登录：请登录账号或输入授权码"
                      builtIn: false
                      hasKey: false
                      account: ""
                      isLogin: false
                      key: ""
                      deviceId: "<device-id>"
                      expiresAt: 0
                      maxDevices: 0
                      online: 0
                      lastOK: 0
                      lastCheck: 1796000000
                      server: "https://api.ketec.top"
                builtIn:
                  summary: "Failure: this build has a built-in license key"
                  x-zh-summary: "失败：安装包内置了授权码"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    success: false
                    error: "此安装包已内置授权，不能退出"
                    message: "此安装包已内置授权，不能更换"
                    data:
                      enforced: true
                      valid: true
                      reason: "ok"
                      message: "已授权"
                      builtIn: true
                      hasKey: true
                      account: ""
                      isLogin: true
                      key: "4F0DCB53…"
                      deviceId: "<device-id>"
                      expiresAt: 1827851075
                      maxDevices: 1500
                      online: 12
                      lastOK: 1796000100
                      lastCheck: 1796000100
                      server: "https://api.ketec.top"
  /v1/heartbeat:
    servers:
      - url: "https://api.ketec.top"
        description: ketec license service
    post:
      operationId: licenseHeartbeat
      summary: License heartbeat (reference)
      tags: ["License Service"]
      x-zh-summary: "授权心跳（参考）"
      description: "Sent by the App every 60 seconds with its license key (an account key or a TokenKey) and device ID. The reply is a signed envelope: `payload` is a JSON string and `sig` is an Ed25519 signature over that exact string, verified with the public key built into the App. The App also checks that `payload.key`, `payload.deviceId` and `payload.nonce` equal what it sent (`key` echoes the TokenKey when one was used). `ok: false` comes with a machine-readable `reason`: bad_request, unknown_key, token_revoked, disabled, expired, kicked or device_limit."
      x-zh-description: "App 每 60 秒带着授权码（账号密钥或 TokenKey）和设备标识发一次。回包是签名信封：`payload` 是 JSON 字符串，`sig` 是对该字符串的 Ed25519 签名，App 用内置公钥验签，并核对 `payload.key`、`deviceId`、`nonce` 与发出的一致（用 TokenKey 时 `key` 回显 TokenKey）。`ok: false` 时 `reason` 为机器可读原因：bad_request、unknown_key、token_revoked、disabled、expired、kicked、device_limit。"
      x-modes: ["agent", "hid"]
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: ["key", "deviceId", "nonce"]
              properties:
                key:
                  type: string
                  description: "License key: the account key or a TokenKey (uppercase UUID)."
                  x-zh-description: "授权码：账号密钥或 TokenKey（大写 UUID）。"
                deviceId:
                  type: string
                  description: Stable device identifier generated by the App.
                  x-zh-description: "App 生成的稳定设备标识。"
                nonce:
                  type: string
                  description: Random value echoed in the signed reply.
                  x-zh-description: "随机值，会在签名回包中回显。"
                model:
                  type: string
                  description: Device model.
                  x-zh-description: "机型。"
                ios:
                  type: string
                  description: iOS version.
                  x-zh-description: "iOS 版本。"
                appVersion:
                  type: string
                  description: App version.
                  x-zh-description: "App 版本。"
                name:
                  type: string
                  description: Device name.
                  x-zh-description: "设备名称。"
            example:
              key: "3F2A9C1E-7B4D-4E8A-9C21-5D6E7F809A1B"
              deviceId: "<device-id>"
              nonce: "6F1D2C3B-…"
              model: iPhone13,2
              ios: "26.5"
              appVersion: "330v240"
              name: iPhone
      responses:
        "200":
          description: Signed envelope.
          x-zh-description: "签名信封。"
          content:
            application/json:
              schema:
                type: object
                required: ["payload", "sig"]
                properties:
                  payload:
                    type: string
                    description: "JSON string; parse it after verifying sig."
                  sig:
                    type: string
                    description: Base64 Ed25519 signature of payload.
              examples:
                ok:
                  summary: "Success: licensed"
                  x-zh-summary: "成功：已授权"
                  x-outcome: success
                  x-inferred: true
                  value:
                    payload: "{\"key\":\"3F2A9C1E-7B4D-4E8A-9C21-5D6E7F809A1B\",\"deviceId\":\"<device-id>\",\"nonce\":\"6F1D2C3B-…\",\"serverTime\":1796300000,\"heartbeat\":60,\"ok\":true,\"reason\":\"ok\",\"message\":\"已授权\",\"maxDevices\":10,\"expiresAt\":1827843558,\"online\":3,\"customer\":\"studio-a\"}"
                    sig: "<base64 Ed25519 签名>"
                deviceLimit:
                  summary: "Failure: device limit reached"
                  x-zh-summary: "失败：在线设备已达上限"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    payload: "{\"key\":\"3F2A9C1E-7B4D-4E8A-9C21-5D6E7F809A1B\",\"deviceId\":\"<device-id>\",\"nonce\":\"6F1D2C3B-…\",\"serverTime\":1796300000,\"heartbeat\":60,\"ok\":false,\"reason\":\"device_limit\",\"message\":\"在线设备已达上限（10 台）\",\"maxDevices\":10,\"expiresAt\":1827843558,\"online\":10}"
                    sig: "<base64 Ed25519 签名>"
                expired:
                  summary: "Failure: license expired"
                  x-zh-summary: "失败：授权已到期"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    payload: "{\"key\":\"3F2A9C1E-7B4D-4E8A-9C21-5D6E7F809A1B\",\"deviceId\":\"<device-id>\",\"nonce\":\"6F1D2C3B-…\",\"serverTime\":1796300000,\"heartbeat\":60,\"ok\":false,\"reason\":\"expired\",\"message\":\"授权已到期\",\"expiresAt\":1793700000,\"maxDevices\":0}"
                    sig: "<base64 Ed25519 签名>"
                tokenRevoked:
                  summary: "Failure: TokenKey revoked"
                  x-zh-summary: "失败：TokenKey 已作废"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    payload: "{\"key\":\"3F2A9C1E-7B4D-4E8A-9C21-5D6E7F809A1B\",\"deviceId\":\"<device-id>\",\"nonce\":\"6F1D2C3B-…\",\"serverTime\":1796300000,\"heartbeat\":60,\"ok\":false,\"reason\":\"token_revoked\",\"message\":\"TokenKey 已作废\"}"
                    sig: "<base64 Ed25519 签名>"
                unknownKey:
                  summary: "Failure: unknown key"
                  x-zh-summary: "失败：授权码无效"
                  x-outcome: failure
                  x-inferred: true
                  value:
                    payload: "{\"key\":\"3F2A9C1E-7B4D-4E8A-9C21-5D6E7F809A1B\",\"deviceId\":\"<device-id>\",\"nonce\":\"6F1D2C3B-…\",\"serverTime\":1796300000,\"heartbeat\":60,\"ok\":false,\"reason\":\"unknown_key\",\"message\":\"授权 key 无效\"}"
                    sig: "<base64 Ed25519 签名>"
components:
  schemas:
    LicenseStatus:
      type: object
      description: "License state of the phone (KMLicense.status)."
      x-zh-description: "手机的授权状态（KMLicense.status）。"
      properties:
        enforced:
          type: boolean
          description: "false on development builds that do not check licenses."
          x-zh-description: "开发包不校验授权时为 false。"
        valid:
          type: boolean
          description: Licensed now (includes the offline grace period).
          x-zh-description: "当前是否已授权（含离线宽限期）。"
        reason:
          type: string
          description: "Machine-readable state: ok, offline, checking, no_key, unknown_key, token_revoked, disabled, expired, kicked, device_limit, network, bad_signature, not_enforced."
          x-zh-description: "机器可读状态：ok、offline、checking、no_key、unknown_key、token_revoked、disabled、expired、kicked、device_limit、network、bad_signature、not_enforced。"
        message:
          type: string
          description: Human-readable message (Chinese).
          x-zh-description: "给人看的提示。"
        builtIn:
          type: boolean
          description: The key is built into this build and cannot be changed.
          x-zh-description: "安装包内置了授权码，不能更换。"
        hasKey:
          type: boolean
        account:
          type: string
          description: Account username when signed in with an account; empty when a key was entered.
          x-zh-description: "用账号登录时为账号名；输入 key 时为空。"
        isLogin:
          type: boolean
          description: Has a key and it is valid.
          x-zh-description: "有 key 且有效。"
        key:
          type: string
          description: "First 8 characters of the key in use, followed by …"
          x-zh-description: "当前所用 key 的前 8 位加「…」。"
        deviceId:
          type: string
        expiresAt:
          type: number
          description: License expiry, Unix seconds (0 = none).
          x-zh-description: "许可到期时间，Unix 秒（0 = 无）。"
        maxDevices:
          type: integer
          description: Devices allowed online at once for this account.
          x-zh-description: "该账号可同时在线的设备数。"
        online:
          type: integer
          description: Devices of this account online now.
          x-zh-description: "该账号当前在线设备数。"
        lastOK:
          type: number
        lastCheck:
          type: number
        server:
          type: string
      additionalProperties: true
    LicenseResponse:
      type: object
      required: ["success", "data"]
      properties:
        success:
          type: boolean
        data:
          $ref: "#/components/schemas/LicenseStatus"
        error:
          type: string
          description: Failure reason (same text as message).
          x-zh-description: "失败原因（与 message 相同）。"
        message:
          type: string
    SuccessResponse:
      type: object
      description: Plain success flag.
      x-zh-description: "仅含成功标志。"
      required: ["success"]
      properties:
        success:
          type: boolean
    ErrorResponse:
      type: object
      description: "Failure body. success is false (absent in a few package-upload errors, which use error:true). message / reason carry human-readable text (usually Chinese, not stable); error carries a machine-readable code when available, e.g. \"license\" when the device license is not valid."
      x-zh-description: "失败响应。success 为 false（少数软件包上传错误不带 success，而是 error:true）。message / reason 为人类可读文本（多为中文，不保证稳定）；有机器可读错误码时放在 error，例如设备许可无效时为 \"license\"。"
      properties:
        success:
          type: boolean
          const: false
        message:
          type: string
        reason:
          type: string
        error:
          type: ["string", "boolean"]
        hint:
          type: string
      additionalProperties: true
    MessageResponse:
      type: object
      required: ["success", "message"]
      properties:
        success:
          type: boolean
        message:
          type: string
    BoolDataResponse:
      type: object
      required: ["success", "data"]
      properties:
        success:
          type: boolean
        data:
          type: boolean
    StringDataResponse:
      type: object
      required: ["success", "data"]
      properties:
        success:
          type: boolean
        data:
          type: string
    NumberDataResponse:
      type: object
      required: ["success", "data"]
      properties:
        success:
          type: boolean
        data:
          type: number
    Point:
      type: object
      properties:
        x:
          type: number
        "y":
          type: number
    ScreenInfo:
      type: object
      properties:
        width:
          type: integer
          description: Physical width in pixels.
        height:
          type: integer
          description: Physical height in pixels.
        scale:
          type: number
        logicWidth:
          type: integer
          description: Width in points.
        logicHeight:
          type: integer
          description: Height in points.
    BatteryInfo:
      type: object
      properties:
        level:
          type: integer
          minimum: 0
          maximum: 100
        isCharging:
          type: boolean
    Status:
      type: object
      description: "Stable fields are listed; the real object contains many additional diagnostic fields that may change between builds."
      x-zh-description: "此处列出稳定字段；实际对象还包含大量诊断字段，可能随版本变化。"
      additionalProperties: true
      properties:
        apiVersion:
          type: string
          description: Build id of the running app, e.g. 330v223.
        appName:
          type: string
        appBundleId:
          type: string
        appVersion:
          type: string
        appBuildNumber:
          type: number
          description: CFBundleVersion as a number.
        bundleVersion:
          type: string
          description: CFBundleVersion as a string.
        appNo:
          type: string
          description: Currently loaded script package.
        deviceName:
          type: string
        deviceModel:
          type: string
          description: Model identifier, e.g. iPhone13,2.
        osVersion:
          type: string
        deviceIp:
          type: string
          description: LAN address of the phone.
        deviceId:
          type: string
          description: "App-scoped device id; changes after reinstall."
        serverDeviceId:
          type: string
        udid:
          type: string
        ecid:
          type: string
        orientation:
          type: string
          enum: ["PORTRAIT", "UPSIDE_DOWN", "LANDSCAPE_LEFT", "LANDSCAPE_RIGHT", "UNKNOWN"]
        screenInfo:
          $ref: "#/components/schemas/ScreenInfo"
        batteryInfo:
          $ref: "#/components/schemas/BatteryInfo"
        volume:
          type: number
        brightness:
          type: number
        isLocked:
          type: boolean
          description: "Always false here; use /api/isLocked for the real lock state."
        selectedRunMode:
          type: string
          enum: ["agent", "hid"]
        agentConnected:
          type: boolean
          description: Agent channel usable and allowed (false in HID mode).
        agentAvailable:
          type: boolean
        isHidConnected:
          type: boolean
          description: ESP32-S3 HID device connected.
        hidModel:
          type: string
        hidVersion:
          type: string
        isRun:
          type: boolean
          description: A package script is running.
        isShowUI:
          type: boolean
        isRecording:
          type: boolean
          description: Recording or screen broadcast running.
        isBroadcastConnected:
          type: boolean
        isMirrorLive:
          type: boolean
        isAuth:
          type: boolean
          description: Device license valid.
        isLogin:
          type: boolean
        isDebugMode:
          type: boolean
        isVolumeControlEnabled:
          type: boolean
        memory:
          type: object
          additionalProperties: true
        storage:
          type: object
          additionalProperties: true
        uptime:
          type: number
          description: System uptime in seconds.
        scriptModules:
          type: array
          items:
            type: string
    AppInfo:
      type: object
      required: ["bundleIdentifier"]
      additionalProperties: true
      properties:
        appName:
          type: string
        bundleIdentifier:
          type: string
        bundleVersion:
          type: string
        name:
          type: string
          description: Legacy alias (localized name).
        bundleId:
          type: string
          description: Legacy alias of bundleIdentifier.
    ActiveAppInfo:
      type: object
      required: ["name", "bundleId", "pid"]
      properties:
        name:
          type: string
        bundleId:
          type: string
        pid:
          type: integer
    RunModeInfo:
      type: object
      required: ["runMode"]
      properties:
        runMode:
          type: string
          enum: ["agent", "hid"]
        agentAvailable:
          type: boolean
        isHidConnected:
          type: boolean
    RunScriptResponse:
      type: object
      required: ["success", "resultType", "data"]
      properties:
        success:
          type: boolean
        resultType:
          type: string
          enum: ["undefined", "string", "number", "boolean", "object"]
        result:
          description: Value of the last expression (omitted when undefined).
        data:
          type: object
          properties:
            result: {}
            logs:
              type: array
              items:
                type: string
            durationMs:
              type: number
        reason:
          type: string
          description: Error text when success is false.
    ScreenshotReceipt:
      type: object
      properties:
        success:
          type: boolean
        method:
          type: string
        bytes:
          type: integer
        w:
          type: integer
        h:
          type: integer
        format:
          type: string
          enum: ["jpeg", "png"]
        blank:
          type: boolean
        elapsedMs:
          type: number
        needsUserAction:
          type: boolean
        attempts:
          type: array
          items:
            type: object
            additionalProperties: true
      additionalProperties: true
    ScreenshotError:
      type: object
      properties:
        success:
          type: boolean
          const: false
        method:
          type: string
        error:
          type: string
        needsUserAction:
          type: boolean
        message:
          type: string
        attempts:
          type: array
          items:
            type: object
            additionalProperties: true
        elapsedMs:
          type: number
    KeysBody:
      type: object
      required: ["keys"]
      properties:
        keys:
          type: array
          minItems: 1
          items:
            type: ["string", "integer"]
          description: Keys pressed together, modifiers first.
    W3CActionsBody:
      type: object
      required: ["actions"]
      properties:
        actions:
          type: array
          minItems: 1
          items:
            type: object
            required: ["type", "actions"]
            properties:
              type:
                type: string
                const: pointer
              id:
                type: string
              parameters:
                type: object
                properties:
                  pointerType:
                    type: string
                    enum: ["touch", "mouse"]
              actions:
                type: array
                items:
                  type: object
                  required: ["type"]
                  properties:
                    type:
                      type: string
                      enum: ["pointerMove", "pointerDown", "pointerUp", "pause"]
                    x:
                      type: number
                    "y":
                      type: number
                    duration:
                      type: number
                      description: Milliseconds.
                    button:
                      type: integer
    HidInputResult:
      type: object
      required: ["success"]
      properties:
        success:
          type: boolean
        data:
          type: boolean
        stage:
          type: string
          enum: ["1-ime-socket", "1-ime", "2-clipboard", "3-custom1", "4-fail"]
        reason:
          type: string
        channel:
          type: string
      additionalProperties: true
    HidDeviceInfo:
      type: object
      properties:
        connected:
          type: boolean
        model:
          type: string
        version:
          type: string
          description: Firmware version.
        mac:
          type: string
        lastResponse:
          type: string
        transmitted:
          type: integer
    ImeResult:
      type: object
      required: ["success"]
      description: "Reply from the keyboard extension. On failure, `reason` explains why (e.g. ime_no_keyboard, ime_not_ready, global_switch_failed)."
      x-zh-description: "键盘扩展的回执。失败时 `reason` 说明原因（如 ime_no_keyboard、ime_not_ready、global_switch_failed）。"
      properties:
        success:
          type: boolean
        via:
          type: string
          description: Path used, e.g. unix-socket, unix-socket+switch, http-fallback.
        data: {}
        readbackLen:
          type: integer
          description: Length of the text before the cursor after the operation.
        deletedCount:
          type: integer
        extKeyboardVisible:
          type: ["boolean", "integer"]
        reason:
          type: string
        hint:
          type: string
      additionalProperties: true
    FileEntry:
      type: object
      properties:
        name:
          type: string
        path:
          type: string
          description: Relative to the dirType root.
        isDirectory:
          type: boolean
        size:
          type: integer
        modified:
          type: number
          description: Unix time in seconds.
    LogFileEntry:
      type: object
      required: ["filePath", "fileName", "modificationDate", "fileSize"]
      properties:
        filePath:
          type: string
        fileName:
          type: string
        modificationDate:
          type: string
          format: date-time
        fileSize:
          type: string
          description: "Human-readable size such as \"120 KB\"."
    MediaSaveItem:
      type: object
      properties:
        success:
          type: boolean
        filename:
          type: string
        bytes:
          type: integer
        kind:
          type: string
          enum: ["image", "video"]
        localIdentifier:
          type: string
        converted:
          type: boolean
        reason:
          type: string
    RecordState:
      type: object
      additionalProperties: true
      properties:
        isRecording:
          type: boolean
        fps:
          type: integer
        frames:
          type: integer
        duration:
          type: number
        path:
          type: string
          description: File name under records/.
        captureSource:
          type: string
        frameSource:
          type: string
        canCaptureFullScreen:
          type: boolean
        broadcastSupported:
          type: boolean
        lastBroadcastEvent:
          type: string
        lastBroadcastAt:
          type: number
  responses:
    BadRequest:
      description: A required parameter is missing or invalid.
      content:
        application/json:
          schema:
            $ref: "#/components/schemas/ErrorResponse"
          examples:
            error:
              summary: "Failure: missing or invalid parameter"
              x-zh-summary: "失败：参数缺失或无效"
              x-outcome: failure
              value:
                success: false
                message: "缺少有效的x或y参数"
    AgentUnavailable:
      description: The Agent channel is not available on this device, so the action was not executed.
      content:
        application/json:
          schema:
            $ref: "#/components/schemas/ErrorResponse"
          examples:
            error:
              summary: "Failure: channel unavailable"
              x-zh-summary: "失败：通道不可用"
              x-outcome: failure
              value:
                success: false
                reason: "Agent 通道不可用（XCTest 未注入），该操作无法执行"
                hint: "改用 HID：/api/hid/click 等；或 /api/control/setRunMode?mode=hid"
                agentAvailable: false
                action: click
