{
  "openapi": "3.0.3",
  "info": {
    "title": "FishHID Public Phone Control API",
    "version": "2.0.0",
    "description": "Single AI-facing control contract at /v1. Account management stays in the signed-in browser; APK transport uses separate device credentials and is not an AI API. Legacy /api/v1 endpoints are not accepted with AI keys. Unknown action outcomes must never be replayed."
  },
  "servers": [
    {
      "url": "https://control.208314.xyz",
      "description": "Public service origin; verify after deployment"
    }
  ],
  "security": [
    {
      "bearerAuth": []
    }
  ],
  "tags": [
    {
      "name": "control",
      "description": "Single versioned AI control and management entry."
    }
  ],
  "paths": {
    "/v1": {
      "get": {
        "tags": [
          "control"
        ],
        "operationId": "getPublicAIControlHub",
        "summary": "Read public usage and authenticated phone capabilities from one entry",
        "description": "GET /v1 returns self-description. Anonymous access has no device data; Bearer user keys add only readable owner-scoped device choices. command_id reads command status; request_status=1 with Idempotency-Key recovers the original invoke/group response.",
        "security": [
          {},
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "command_id",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "minLength": 1
            },
            "description": "Existing owned command for read-only status, requiring Bearer authentication."
          },
          {
            "name": "request_status",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "1"
              ]
            },
            "description": "With Idempotency-Key header, recovers the original invoke/group response for seven days."
          },
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "minLength": 1,
              "maxLength": 128,
              "pattern": "^[!-~]+$"
            },
            "description": "Use the original key with request_status=1 to recover an action or group request."
          }
        ],
        "responses": {
          "200": {
            "description": "Self-description manifest, or original command/request status.",
            "content": {
              "application/json": {
                "schema": {
                  "oneOf": [
                    {
                      "$ref": "#/components/schemas/HubManifest"
                    },
                    {
                      "$ref": "#/components/schemas/Command"
                    },
                    {
                      "$ref": "#/components/schemas/GroupResult"
                    }
                  ]
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      },
      "post": {
        "tags": [
          "control"
        ],
        "operationId": "dispatchPublicAIControl",
        "summary": "Dispatch one account-scoped action or management operation",
        "description": "All AI actions and management operations use this path. invoke and group require Idempotency-Key. Retries with the same key/body return the original command; a different body conflicts. Queued commands expire after 120 seconds; only queued commands can be cancelled. Group is asynchronous and rejects wait_ms. Scripts use lingping.script/1 and are never remotely run.",
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "minLength": 1,
              "maxLength": 128,
              "pattern": "^[!-~]+$"
            },
            "description": "Required for invoke and group; must be unique per intended command."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/HubPostRequest"
              },
              "examples": {
                "phoneInfo": {
                  "summary": "Read device info without a screenshot",
                  "value": {
                    "action": "info",
                    "device": "LYA-AL00"
                  }
                },
                "singlePhone": {
                  "summary": "Select the only bound phone automatically",
                  "value": {
                    "action": "key",
                    "key": "home"
                  }
                },
                "group": {
                  "value": {
                    "op": "group",
                    "devices": [
                      "LYA-AL00",
                      "客厅手机"
                    ],
                    "command": {
                      "action": "key",
                      "key": "back"
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Command/status, devices, group, script, release, or rename result.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HubPostResult"
                }
              }
            }
          },
          "201": {
            "description": "Script created with a one-time pickup code.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HubScriptResult"
                }
              }
            }
          },
          "202": {
            "description": "One action queued, not proof of physical effect.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HubCommandResult"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "description": "No owned target or command found.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HubSelectionError"
                }
              }
            }
          },
          "409": {
            "description": "Busy device, capability failure or ambiguous selector. No alternate phone is silently selected.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HubSelectionError"
                }
              }
            }
          },
          "502": {
            "$ref": "#/components/responses/CommandFailure"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "fhk_…",
        "description": "Create a user-scoped AI control key in the web console. Store it as a host secret, never in prompts, URLs or logs. Revoke it from the console when no longer needed."
      }
    },
    "schemas": {
      "GroupResult": {
        "type": "object",
        "required": [
          "mode",
          "results"
        ],
        "properties": {
          "mode": {
            "type": "string",
            "enum": [
              "all_accepted",
              "partial"
            ]
          },
          "idempotent": {
            "type": "boolean"
          },
          "results": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "device",
                "accepted"
              ],
              "properties": {
                "device": {
                  "$ref": "#/components/schemas/HubDeviceChoice"
                },
                "accepted": {
                  "type": "boolean"
                },
                "command": {
                  "$ref": "#/components/schemas/Command"
                },
                "error": {
                  "type": "string"
                }
              }
            }
          }
        }
      },
      "DeviceList": {
        "type": "object",
        "required": [
          "devices"
        ],
        "properties": {
          "devices": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/HubDeviceChoice"
            }
          }
        }
      },
      "Command": {
        "type": "object",
        "required": [
          "id",
          "kind",
          "status",
          "created_at",
          "updated_at"
        ],
        "properties": {
          "id": {
            "type": "string",
            "description": "Original command ID used internally for a later GET /v1?command_id=... status query; not a per-step user ticket."
          },
          "kind": {
            "type": "string",
            "enum": [
              "invoke"
            ]
          },
          "status": {
            "type": "string",
            "enum": [
              "queued",
              "running",
              "completed",
              "failed",
              "cancelled",
              "expired"
            ]
          },
          "result": {
            "type": "object",
            "description": "When completed, original device result. Inspect result.status, result.screen, result.submission and result.error; queued/submitted do not prove physical effects."
          },
          "created_at": {
            "type": "integer"
          },
          "updated_at": {
            "type": "integer"
          },
          "expires_at": {
            "type": "integer",
            "nullable": true,
            "description": "Queue deadline; commands not claimed before this time expire."
          },
          "device": {
            "$ref": "#/components/schemas/HubDeviceChoice"
          },
          "idempotent": {
            "type": "boolean"
          }
        }
      },
      "HubInvokeRequest": {
        "oneOf": [
          {
            "type": "object",
            "required": [
              "action"
            ],
            "additionalProperties": false,
            "properties": {
              "action": {
                "type": "string",
                "enum": [
                  "observe"
                ]
              },
              "format": {
                "type": "string",
                "enum": [
                  "ocr",
                  "image"
                ],
                "default": "ocr"
              },
              "wait_ms": {
                "type": "integer",
                "minimum": 0,
                "maximum": 22000,
                "description": "Optional relay wait budget; never forwarded as phone action data."
              },
              "device": {
                "type": "string",
                "minLength": 1,
                "maxLength": 128,
                "pattern": "\\S",
                "description": "Account-owned device name/model; ID resolved internally, never requested from the user."
              },
              "op": {
                "type": "string",
                "enum": [
                  "invoke"
                ],
                "default": "invoke"
              }
            }
          },
          {
            "type": "object",
            "required": [
              "action"
            ],
            "additionalProperties": false,
            "properties": {
              "action": {
                "type": "string",
                "enum": [
                  "info"
                ]
              },
              "wait_ms": {
                "type": "integer",
                "minimum": 0,
                "maximum": 22000,
                "description": "Optional relay wait budget; never forwarded as phone action data."
              },
              "device": {
                "type": "string",
                "minLength": 1,
                "maxLength": 128,
                "pattern": "\\S",
                "description": "Account-owned device name/model; ID resolved internally, never requested from the user."
              },
              "op": {
                "type": "string",
                "enum": [
                  "invoke"
                ],
                "default": "invoke"
              }
            }
          },
          {
            "type": "object",
            "required": [
              "action",
              "x",
              "y"
            ],
            "additionalProperties": false,
            "properties": {
              "action": {
                "type": "string",
                "enum": [
                  "tap"
                ]
              },
              "x": {
                "type": "integer",
                "minimum": 0
              },
              "y": {
                "type": "integer",
                "minimum": 0
              },
              "coordinate_space": {
                "type": "string",
                "enum": [
                  "image"
                ],
                "description": "Omit for source-frame pixels. Set image only when coordinates were measured in the returned PNG dimensions."
              },
              "wait_ms": {
                "type": "integer",
                "minimum": 0,
                "maximum": 22000,
                "description": "Optional relay wait budget; never forwarded as phone action data."
              },
              "device": {
                "type": "string",
                "minLength": 1,
                "maxLength": 128,
                "pattern": "\\S",
                "description": "Account-owned device name/model; ID resolved internally, never requested from the user."
              },
              "op": {
                "type": "string",
                "enum": [
                  "invoke"
                ],
                "default": "invoke"
              }
            }
          },
          {
            "type": "object",
            "required": [
              "action",
              "element_id"
            ],
            "additionalProperties": false,
            "properties": {
              "action": {
                "type": "string",
                "enum": [
                  "tap"
                ]
              },
              "element_id": {
                "type": "string",
                "maxLength": 128
              },
              "tap_offset_px": {
                "type": "integer",
                "minimum": 0,
                "maximum": 6
              },
              "wait_ms": {
                "type": "integer",
                "minimum": 0,
                "maximum": 22000,
                "description": "Optional relay wait budget; never forwarded as phone action data."
              },
              "device": {
                "type": "string",
                "minLength": 1,
                "maxLength": 128,
                "pattern": "\\S",
                "description": "Account-owned device name/model; ID resolved internally, never requested from the user."
              },
              "op": {
                "type": "string",
                "enum": [
                  "invoke"
                ],
                "default": "invoke"
              }
            }
          },
          {
            "type": "object",
            "required": [
              "action",
              "text"
            ],
            "additionalProperties": false,
            "properties": {
              "action": {
                "type": "string",
                "enum": [
                  "tap_text"
                ]
              },
              "text": {
                "type": "string",
                "minLength": 1,
                "maxLength": 512
              },
              "context": {
                "type": "string",
                "maxLength": 512
              },
              "tap_offset_px": {
                "type": "integer",
                "minimum": 0,
                "maximum": 6
              },
              "wait_ms": {
                "type": "integer",
                "minimum": 0,
                "maximum": 22000,
                "description": "Optional relay wait budget; never forwarded as phone action data."
              },
              "device": {
                "type": "string",
                "minLength": 1,
                "maxLength": 128,
                "pattern": "\\S",
                "description": "Account-owned device name/model; ID resolved internally, never requested from the user."
              },
              "op": {
                "type": "string",
                "enum": [
                  "invoke"
                ],
                "default": "invoke"
              }
            },
            "description": "Supported in structured OCR mode; may fail if text is missing or ambiguous."
          },
          {
            "type": "object",
            "required": [
              "action",
              "text",
              "state"
            ],
            "additionalProperties": false,
            "properties": {
              "action": {
                "type": "string",
                "enum": [
                  "set_switch"
                ]
              },
              "text": {
                "type": "string",
                "minLength": 1,
                "maxLength": 512
              },
              "state": {
                "type": "string",
                "enum": [
                  "on",
                  "off"
                ]
              },
              "context": {
                "type": "string",
                "maxLength": 512
              },
              "wait_ms": {
                "type": "integer",
                "minimum": 0,
                "maximum": 22000,
                "description": "Optional relay wait budget; never forwarded as phone action data."
              },
              "device": {
                "type": "string",
                "minLength": 1,
                "maxLength": 128,
                "pattern": "\\S",
                "description": "Account-owned device name/model; ID resolved internally, never requested from the user."
              },
              "op": {
                "type": "string",
                "enum": [
                  "invoke"
                ],
                "default": "invoke"
              }
            },
            "description": "Set a visually detected switch by its same-frame OCR label; state is a visual estimate, not system-state proof."
          },
          {
            "type": "object",
            "required": [
              "action",
              "x1",
              "y1",
              "x2",
              "y2"
            ],
            "additionalProperties": false,
            "properties": {
              "action": {
                "type": "string",
                "enum": [
                  "swipe"
                ]
              },
              "x1": {
                "type": "integer",
                "minimum": 0
              },
              "y1": {
                "type": "integer",
                "minimum": 0
              },
              "x2": {
                "type": "integer",
                "minimum": 0
              },
              "y2": {
                "type": "integer",
                "minimum": 0
              },
              "duration_ms": {
                "type": "integer",
                "minimum": 200,
                "maximum": 1200
              },
              "coordinate_space": {
                "type": "string",
                "enum": [
                  "image"
                ]
              },
              "wait_ms": {
                "type": "integer",
                "minimum": 0,
                "maximum": 22000,
                "description": "Optional relay wait budget; never forwarded as phone action data."
              },
              "device": {
                "type": "string",
                "minLength": 1,
                "maxLength": 128,
                "pattern": "\\S",
                "description": "Account-owned device name/model; ID resolved internally, never requested from the user."
              },
              "op": {
                "type": "string",
                "enum": [
                  "invoke"
                ],
                "default": "invoke"
              }
            }
          },
          {
            "type": "object",
            "required": [
              "action",
              "key"
            ],
            "additionalProperties": false,
            "properties": {
              "action": {
                "type": "string",
                "enum": [
                  "key"
                ]
              },
              "key": {
                "type": "string",
                "enum": [
                  "home",
                  "back",
                  "recents",
                  "key_enter",
                  "key_delete",
                  "key_select",
                  "key_copy",
                  "key_cut"
                ]
              },
              "wait_ms": {
                "type": "integer",
                "minimum": 0,
                "maximum": 22000,
                "description": "Optional relay wait budget; never forwarded as phone action data."
              },
              "device": {
                "type": "string",
                "minLength": 1,
                "maxLength": 128,
                "pattern": "\\S",
                "description": "Account-owned device name/model; ID resolved internally, never requested from the user."
              },
              "op": {
                "type": "string",
                "enum": [
                  "invoke"
                ],
                "default": "invoke"
              }
            }
          },
          {
            "type": "object",
            "required": [
              "action",
              "text"
            ],
            "additionalProperties": false,
            "properties": {
              "action": {
                "type": "string",
                "enum": [
                  "type"
                ]
              },
              "text": {
                "type": "string",
                "minLength": 1,
                "maxLength": 2048,
                "description": "APK uses/overwrites the system clipboard while entering this text. Do not send secrets without explicit user approval."
              },
              "wait_ms": {
                "type": "integer",
                "minimum": 0,
                "maximum": 22000,
                "description": "Optional relay wait budget; never forwarded as phone action data."
              },
              "device": {
                "type": "string",
                "minLength": 1,
                "maxLength": 128,
                "pattern": "\\S",
                "description": "Account-owned device name/model; ID resolved internally, never requested from the user."
              },
              "op": {
                "type": "string",
                "enum": [
                  "invoke"
                ],
                "default": "invoke"
              }
            }
          },
          {
            "oneOf": [
              {
                "type": "object",
                "required": [
                  "action",
                  "package"
                ],
                "additionalProperties": false,
                "properties": {
                  "action": {
                    "type": "string",
                    "enum": [
                      "launch"
                    ]
                  },
                  "package": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 200
                  },
                  "wait_ms": {
                    "type": "integer",
                    "minimum": 0,
                    "maximum": 22000,
                    "description": "Optional relay wait budget; never forwarded as phone action data."
                  },
                  "device": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 128,
                    "pattern": "\\S",
                    "description": "Account-owned device name/model; ID resolved internally, never requested from the user."
                  },
                  "op": {
                    "type": "string",
                    "enum": [
                      "invoke"
                    ],
                    "default": "invoke"
                  }
                }
              },
              {
                "type": "object",
                "required": [
                  "action",
                  "app"
                ],
                "additionalProperties": false,
                "properties": {
                  "action": {
                    "type": "string",
                    "enum": [
                      "launch"
                    ]
                  },
                  "app": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 100
                  },
                  "wait_ms": {
                    "type": "integer",
                    "minimum": 0,
                    "maximum": 22000,
                    "description": "Optional relay wait budget; never forwarded as phone action data."
                  },
                  "device": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 128,
                    "pattern": "\\S",
                    "description": "Account-owned device name/model; ID resolved internally, never requested from the user."
                  },
                  "op": {
                    "type": "string",
                    "enum": [
                      "invoke"
                    ],
                    "default": "invoke"
                  }
                }
              }
            ]
          }
        ],
        "description": "Flat one-action request. op defaults to invoke. A single bound phone is auto-selected; otherwise use a readable name/model."
      },
      "HubDeviceChoice": {
        "type": "object",
        "required": [
          "name",
          "alias",
          "model",
          "manufacturer",
          "status",
          "presence"
        ],
        "properties": {
          "name": {
            "type": "string"
          },
          "model": {
            "type": "string"
          },
          "manufacturer": {
            "type": "string"
          },
          "status": {
            "type": "string"
          },
          "alias": {
            "type": "string"
          },
          "presence": {
            "type": "object",
            "required": [
              "state",
              "heartbeat_age_seconds",
              "observed_at"
            ],
            "properties": {
              "state": {
                "type": "string",
                "enum": [
                  "online",
                  "stale",
                  "offline"
                ]
              },
              "heartbeat_age_seconds": {
                "type": "integer",
                "nullable": true
              },
              "observed_at": {
                "type": "integer",
                "nullable": true
              }
            }
          }
        }
      },
      "HubDeviceSummary": {
        "allOf": [
          {
            "$ref": "#/components/schemas/HubDeviceChoice"
          },
          {
            "type": "object",
            "properties": {
              "capabilities": {
                "type": "object",
                "properties": {
                  "actions": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  },
                  "relay_invoke": {
                    "type": "boolean"
                  },
                  "set_switch": {
                    "type": "boolean"
                  }
                }
              },
              "screen": {
                "type": "object",
                "properties": {
                  "width": {
                    "type": "integer",
                    "nullable": true
                  },
                  "height": {
                    "type": "integer",
                    "nullable": true
                  },
                  "source": {
                    "type": "string",
                    "enum": [
                      "heartbeat_snapshot; coordinates use latest observe frame"
                    ]
                  }
                }
              },
              "readiness": {
                "type": "object",
                "properties": {
                  "control_enabled": {
                    "type": "boolean",
                    "nullable": true
                  },
                  "bluetooth_ready": {
                    "type": "boolean",
                    "nullable": true
                  },
                  "heartbeat_at": {
                    "type": "integer",
                    "nullable": true
                  },
                  "heartbeat_age_seconds": {
                    "type": "integer",
                    "nullable": true
                  }
                }
              }
            }
          }
        ]
      },
      "HubManifest": {
        "type": "object",
        "required": [
          "protocol",
          "entry",
          "authenticated",
          "authentication",
          "devices",
          "instructions",
          "actions",
          "operations",
          "formats",
          "availability",
          "schema_url",
          "help_url"
        ],
        "properties": {
          "protocol": {
            "type": "string",
            "enum": [
              "lingping.public/1"
            ]
          },
          "entry": {
            "type": "string",
            "enum": [
              "/v1"
            ]
          },
          "authenticated": {
            "type": "boolean"
          },
          "authentication": {
            "type": "string"
          },
          "devices": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/HubDeviceSummary"
            },
            "description": "Authenticated account devices only; anonymous GET has an empty list. The manifest intentionally omits internal IDs."
          },
          "instructions": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "actions": {
            "type": "object",
            "additionalProperties": true
          },
          "operations": {
            "type": "object",
            "additionalProperties": true
          },
          "formats": {
            "type": "object",
            "additionalProperties": true
          },
          "key_values": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "availability": {
            "type": "object",
            "additionalProperties": true
          },
          "schema_url": {
            "type": "string"
          },
          "help_url": {
            "type": "string"
          }
        }
      },
      "HubDevicesRequest": {
        "type": "object",
        "required": [
          "op"
        ],
        "additionalProperties": false,
        "properties": {
          "op": {
            "type": "string",
            "enum": [
              "devices"
            ]
          }
        }
      },
      "HubGroupRequest": {
        "type": "object",
        "required": [
          "op",
          "devices",
          "command"
        ],
        "additionalProperties": false,
        "properties": {
          "op": {
            "type": "string",
            "enum": [
              "group"
            ]
          },
          "devices": {
            "type": "array",
            "minItems": 1,
            "maxItems": 32,
            "uniqueItems": true,
            "items": {
              "type": "string",
              "minLength": 1,
              "maxLength": 128,
              "pattern": "\\S",
              "description": "Exact owner-scoped device name, model or readable alias; internal IDs are not accepted."
            }
          },
          "command": {
            "$ref": "#/components/schemas/GroupCommand"
          }
        }
      },
      "HubScriptsRequest": {
        "type": "object",
        "required": [
          "op"
        ],
        "additionalProperties": false,
        "properties": {
          "op": {
            "type": "string",
            "enum": [
              "scripts"
            ]
          }
        }
      },
      "HubScriptGetRequest": {
        "type": "object",
        "required": [
          "op",
          "script_id"
        ],
        "additionalProperties": false,
        "properties": {
          "op": {
            "type": "string",
            "enum": [
              "script_get"
            ]
          },
          "script_id": {
            "type": "string",
            "minLength": 1
          }
        }
      },
      "HubScriptCreateRequest": {
        "type": "object",
        "required": [
          "op",
          "name",
          "payload"
        ],
        "additionalProperties": false,
        "properties": {
          "op": {
            "type": "string",
            "enum": [
              "script_create"
            ]
          },
          "name": {
            "type": "string",
            "maxLength": 80
          },
          "payload": {
            "$ref": "#/components/schemas/ScriptPayload"
          }
        }
      },
      "HubScriptUpdateRequest": {
        "type": "object",
        "required": [
          "op",
          "script_id",
          "name",
          "payload",
          "expected_updated_at"
        ],
        "additionalProperties": false,
        "properties": {
          "op": {
            "type": "string",
            "enum": [
              "script_update"
            ]
          },
          "script_id": {
            "type": "string",
            "minLength": 1
          },
          "name": {
            "type": "string",
            "maxLength": 80
          },
          "payload": {
            "$ref": "#/components/schemas/ScriptPayload"
          },
          "expected_updated_at": {
            "type": "integer"
          }
        }
      },
      "HubDeviceRenameRequest": {
        "type": "object",
        "required": [
          "op",
          "name"
        ],
        "additionalProperties": false,
        "properties": {
          "op": {
            "type": "string",
            "enum": [
              "device_rename"
            ]
          },
          "device": {
            "type": "string",
            "minLength": 1,
            "maxLength": 128,
            "pattern": "\\S",
            "description": "Account-owned device name/model; ID resolved internally, never requested from the user."
          },
          "name": {
            "type": "string",
            "minLength": 1,
            "maxLength": 80
          }
        }
      },
      "HubReleaseLatestRequest": {
        "type": "object",
        "required": [
          "op"
        ],
        "additionalProperties": false,
        "properties": {
          "op": {
            "type": "string",
            "enum": [
              "release_latest"
            ]
          },
          "platform": {
            "type": "string",
            "default": "android"
          },
          "channel": {
            "type": "string",
            "default": "stable"
          }
        }
      },
      "HubPostRequest": {
        "oneOf": [
          {
            "$ref": "#/components/schemas/HubInvokeRequest"
          },
          {
            "$ref": "#/components/schemas/HubDevicesRequest"
          },
          {
            "$ref": "#/components/schemas/HubGroupRequest"
          },
          {
            "$ref": "#/components/schemas/HubScriptsRequest"
          },
          {
            "$ref": "#/components/schemas/HubScriptGetRequest"
          },
          {
            "$ref": "#/components/schemas/HubScriptCreateRequest"
          },
          {
            "$ref": "#/components/schemas/HubScriptUpdateRequest"
          },
          {
            "$ref": "#/components/schemas/HubDeviceRenameRequest"
          },
          {
            "$ref": "#/components/schemas/HubReleaseLatestRequest"
          },
          {
            "$ref": "#/components/schemas/HubCancelRequest"
          }
        ],
        "description": "Exactly one enumerated operation. No arbitrary native capability or remote script execution. Unknown fields are rejected."
      },
      "HubCommandResult": {
        "allOf": [
          {
            "$ref": "#/components/schemas/Command"
          },
          {
            "type": "object",
            "properties": {
              "device": {
                "$ref": "#/components/schemas/HubDeviceChoice"
              }
            }
          }
        ]
      },
      "HubScriptList": {
        "type": "object",
        "required": [
          "scripts"
        ],
        "properties": {
          "scripts": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "id": {
                  "type": "string"
                },
                "name": {
                  "type": "string"
                },
                "pickup_expires_at": {
                  "type": "integer",
                  "nullable": true
                },
                "created_at": {
                  "type": "integer"
                },
                "updated_at": {
                  "type": "integer"
                }
              }
            }
          }
        }
      },
      "HubScriptResult": {
        "type": "object",
        "required": [
          "script"
        ],
        "properties": {
          "script": {
            "type": "object",
            "additionalProperties": true,
            "description": "Create returns a one-time pickup_code; update returns a newly rotated code plus updated_at; get returns stored metadata and payload without hashes or a stored cleartext code."
          }
        }
      },
      "HubReleaseResult": {
        "type": "object",
        "required": [
          "release"
        ],
        "properties": {
          "release": {
            "type": "object",
            "nullable": true,
            "additionalProperties": true
          }
        }
      },
      "HubRenameResult": {
        "type": "object",
        "required": [
          "ok"
        ],
        "properties": {
          "ok": {
            "type": "boolean"
          }
        }
      },
      "HubPostResult": {
        "anyOf": [
          {
            "$ref": "#/components/schemas/HubCommandResult"
          },
          {
            "$ref": "#/components/schemas/Command"
          },
          {
            "$ref": "#/components/schemas/DeviceList"
          },
          {
            "$ref": "#/components/schemas/GroupResult"
          },
          {
            "$ref": "#/components/schemas/HubScriptList"
          },
          {
            "$ref": "#/components/schemas/HubScriptResult"
          },
          {
            "$ref": "#/components/schemas/HubReleaseResult"
          },
          {
            "$ref": "#/components/schemas/HubRenameResult"
          },
          {
            "$ref": "#/components/schemas/HubCancelResult"
          }
        ]
      },
      "HubSelectionError": {
        "type": "object",
        "required": [
          "error",
          "message"
        ],
        "properties": {
          "error": {
            "type": "string"
          },
          "message": {
            "type": "string"
          },
          "devices": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/HubDeviceChoice"
            },
            "description": "Readable choices only, no internal IDs."
          },
          "command": {
            "$ref": "#/components/schemas/Command"
          }
        }
      },
      "GroupCommand": {
        "oneOf": [
          {
            "type": "object",
            "required": [
              "action"
            ],
            "additionalProperties": false,
            "properties": {
              "action": {
                "type": "string",
                "enum": [
                  "observe"
                ]
              },
              "format": {
                "type": "string",
                "enum": [
                  "ocr",
                  "image"
                ],
                "default": "ocr"
              }
            }
          },
          {
            "type": "object",
            "required": [
              "action"
            ],
            "additionalProperties": false,
            "properties": {
              "action": {
                "type": "string",
                "enum": [
                  "info"
                ]
              }
            }
          },
          {
            "type": "object",
            "required": [
              "action",
              "x",
              "y"
            ],
            "additionalProperties": false,
            "properties": {
              "action": {
                "type": "string",
                "enum": [
                  "tap"
                ]
              },
              "x": {
                "type": "integer",
                "minimum": 0
              },
              "y": {
                "type": "integer",
                "minimum": 0
              },
              "coordinate_space": {
                "type": "string",
                "enum": [
                  "image"
                ],
                "description": "Omit for source-frame pixels. Set image only when coordinates were measured in the returned PNG dimensions."
              }
            }
          },
          {
            "type": "object",
            "required": [
              "action",
              "element_id"
            ],
            "additionalProperties": false,
            "properties": {
              "action": {
                "type": "string",
                "enum": [
                  "tap"
                ]
              },
              "element_id": {
                "type": "string",
                "maxLength": 128
              },
              "tap_offset_px": {
                "type": "integer",
                "minimum": 0,
                "maximum": 6
              }
            }
          },
          {
            "type": "object",
            "required": [
              "action",
              "text"
            ],
            "additionalProperties": false,
            "properties": {
              "action": {
                "type": "string",
                "enum": [
                  "tap_text"
                ]
              },
              "text": {
                "type": "string",
                "minLength": 1,
                "maxLength": 512
              },
              "context": {
                "type": "string",
                "maxLength": 512
              },
              "tap_offset_px": {
                "type": "integer",
                "minimum": 0,
                "maximum": 6
              }
            },
            "description": "Supported in structured OCR mode; may fail if text is missing or ambiguous."
          },
          {
            "type": "object",
            "required": [
              "action",
              "text",
              "state"
            ],
            "additionalProperties": false,
            "properties": {
              "action": {
                "type": "string",
                "enum": [
                  "set_switch"
                ]
              },
              "text": {
                "type": "string",
                "minLength": 1,
                "maxLength": 512
              },
              "state": {
                "type": "string",
                "enum": [
                  "on",
                  "off"
                ]
              },
              "context": {
                "type": "string",
                "maxLength": 512
              }
            },
            "description": "Set a visually detected switch by its same-frame OCR label; state is a visual estimate, not system-state proof."
          },
          {
            "type": "object",
            "required": [
              "action",
              "x1",
              "y1",
              "x2",
              "y2"
            ],
            "additionalProperties": false,
            "properties": {
              "action": {
                "type": "string",
                "enum": [
                  "swipe"
                ]
              },
              "x1": {
                "type": "integer",
                "minimum": 0
              },
              "y1": {
                "type": "integer",
                "minimum": 0
              },
              "x2": {
                "type": "integer",
                "minimum": 0
              },
              "y2": {
                "type": "integer",
                "minimum": 0
              },
              "duration_ms": {
                "type": "integer",
                "minimum": 200,
                "maximum": 1200
              },
              "coordinate_space": {
                "type": "string",
                "enum": [
                  "image"
                ]
              }
            }
          },
          {
            "type": "object",
            "required": [
              "action",
              "key"
            ],
            "additionalProperties": false,
            "properties": {
              "action": {
                "type": "string",
                "enum": [
                  "key"
                ]
              },
              "key": {
                "type": "string",
                "enum": [
                  "home",
                  "back",
                  "recents",
                  "key_enter",
                  "key_delete",
                  "key_select",
                  "key_copy",
                  "key_cut"
                ]
              }
            }
          },
          {
            "type": "object",
            "required": [
              "action",
              "text"
            ],
            "additionalProperties": false,
            "properties": {
              "action": {
                "type": "string",
                "enum": [
                  "type"
                ]
              },
              "text": {
                "type": "string",
                "minLength": 1,
                "maxLength": 2048,
                "description": "APK uses/overwrites the system clipboard while entering this text. Do not send secrets without explicit user approval."
              }
            }
          },
          {
            "oneOf": [
              {
                "type": "object",
                "required": [
                  "action",
                  "package"
                ],
                "additionalProperties": false,
                "properties": {
                  "action": {
                    "type": "string",
                    "enum": [
                      "launch"
                    ]
                  },
                  "package": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 200
                  }
                }
              },
              {
                "type": "object",
                "required": [
                  "action",
                  "app"
                ],
                "additionalProperties": false,
                "properties": {
                  "action": {
                    "type": "string",
                    "enum": [
                      "launch"
                    ]
                  },
                  "app": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 100
                  }
                }
              }
            ]
          }
        ],
        "description": "One normalized phone command; wait_ms is not supported in group requests."
      },
      "HubCancelRequest": {
        "type": "object",
        "required": [
          "op",
          "command_id"
        ],
        "additionalProperties": false,
        "properties": {
          "op": {
            "type": "string",
            "enum": [
              "cancel"
            ]
          },
          "command_id": {
            "type": "string",
            "minLength": 1
          }
        }
      },
      "HubCancelResult": {
        "type": "object",
        "required": [
          "command",
          "cancel"
        ],
        "properties": {
          "command": {
            "$ref": "#/components/schemas/Command"
          },
          "cancel": {
            "type": "string",
            "enum": [
              "cancelled",
              "too_late",
              "expired"
            ]
          }
        }
      },
      "ScriptPayload": {
        "type": "object",
        "required": [
          "schema",
          "id",
          "name",
          "steps"
        ],
        "additionalProperties": false,
        "properties": {
          "schema": {
            "type": "string",
            "enum": [
              "lingping.script/1"
            ]
          },
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "name": {
            "type": "string",
            "minLength": 1,
            "maxLength": 80
          },
          "steps": {
            "$ref": "#/components/schemas/ScriptSteps"
          }
        },
        "description": "lingping.script/1 document. The server and APK additionally enforce a 16 KiB encoded-document limit, 128 total nodes, depth 8, 256 expanded operations, and 600000 ms expanded wait total. Text must be non-blank and contain no control characters."
      },
      "ScriptSteps": {
        "type": "array",
        "maxItems": 64,
        "items": {
          "$ref": "#/components/schemas/ScriptStep"
        }
      },
      "ScriptStep": {
        "oneOf": [
          {"$ref": "#/components/schemas/ScriptActionStep"},
          {"$ref": "#/components/schemas/ScriptWaitStep"},
          {"$ref": "#/components/schemas/ScriptIfTextStep"},
          {"$ref": "#/components/schemas/ScriptRepeatStep"}
        ]
      },
      "ScriptActionStep": {
        "type": "object",
        "required": ["kind", "action"],
        "additionalProperties": false,
        "properties": {
          "kind": {"type": "string", "enum": ["action"]},
          "action": {"$ref": "#/components/schemas/ScriptAction"}
        }
      },
      "ScriptWaitStep": {
        "type": "object",
        "required": ["kind", "ms"],
        "additionalProperties": false,
        "properties": {
          "kind": {"type": "string", "enum": ["wait"]},
          "ms": {"type": "integer", "minimum": 0, "maximum": 30000}
        }
      },
      "ScriptIfTextStep": {
        "type": "object",
        "required": ["kind", "text", "match", "then", "else"],
        "additionalProperties": false,
        "properties": {
          "kind": {"type": "string", "enum": ["if_text"]},
          "text": {"type": "string", "minLength": 1, "maxLength": 512},
          "match": {"type": "string", "enum": ["exact", "contains"]},
          "then": {"$ref": "#/components/schemas/ScriptSteps"},
          "else": {"$ref": "#/components/schemas/ScriptSteps"}
        }
      },
      "ScriptRepeatStep": {
        "type": "object",
        "required": ["kind", "count", "steps"],
        "additionalProperties": false,
        "properties": {
          "kind": {"type": "string", "enum": ["repeat"]},
          "count": {"type": "integer", "minimum": 1, "maximum": 20},
          "steps": {"$ref": "#/components/schemas/ScriptSteps"}
        }
      },
      "ScriptAction": {
        "oneOf": [
          {"$ref": "#/components/schemas/ScriptTapAction"},
          {"$ref": "#/components/schemas/ScriptTapTextAction"},
          {"$ref": "#/components/schemas/ScriptSwitchAction"},
          {"$ref": "#/components/schemas/ScriptSwipeAction"},
          {"$ref": "#/components/schemas/ScriptKeyAction"},
          {"$ref": "#/components/schemas/ScriptLaunchAction"},
          {"$ref": "#/components/schemas/ScriptTypeAction"}
        ]
      },
      "ScriptDisplay": {
        "type": "object",
        "required": ["width", "height", "rotation"],
        "additionalProperties": false,
        "properties": {
          "width": {"type": "integer", "minimum": 1, "maximum": 12000},
          "height": {"type": "integer", "minimum": 1, "maximum": 12000},
          "rotation": {"type": "integer", "minimum": 0, "maximum": 3}
        },
        "description": "width * height must not exceed 32000000; enforced by the shared application validator."
      },
      "ScriptTapAction": {
        "type": "object", "required": ["action", "x", "y"], "additionalProperties": false,
        "properties": {"action": {"type": "string", "enum": ["tap"]}, "x": {"type": "integer", "minimum": 0, "maximum": 2147483647}, "y": {"type": "integer", "minimum": 0, "maximum": 2147483647}, "display": {"$ref": "#/components/schemas/ScriptDisplay"}}
      },
      "ScriptTapTextAction": {
        "type": "object", "required": ["action", "text"], "additionalProperties": false,
        "properties": {"action": {"type": "string", "enum": ["tap_text"]}, "text": {"type": "string", "minLength": 1, "maxLength": 512}, "context": {"type": "string", "minLength": 1, "maxLength": 512}, "tap_offset_px": {"type": "integer", "minimum": 0, "maximum": 6}}
      },
      "ScriptSwitchAction": {
        "type": "object", "required": ["action", "text", "state"], "additionalProperties": false,
        "properties": {"action": {"type": "string", "enum": ["set_switch"]}, "text": {"type": "string", "minLength": 1, "maxLength": 512}, "state": {"type": "string", "enum": ["on", "off"]}, "context": {"type": "string", "minLength": 1, "maxLength": 512}}
      },
      "ScriptSwipeAction": {
        "type": "object", "required": ["action", "x1", "y1", "x2", "y2"], "additionalProperties": false,
        "properties": {"action": {"type": "string", "enum": ["swipe"]}, "x1": {"type": "integer", "minimum": 0}, "y1": {"type": "integer", "minimum": 0}, "x2": {"type": "integer", "minimum": 0}, "y2": {"type": "integer", "minimum": 0}, "display": {"$ref": "#/components/schemas/ScriptDisplay"}, "duration_ms": {"type": "integer", "minimum": 200, "maximum": 1200}}
      },
      "ScriptKeyAction": {
        "type": "object", "required": ["action", "key"], "additionalProperties": false,
        "properties": {"action": {"type": "string", "enum": ["key"]}, "key": {"type": "string", "enum": ["home", "back", "recents", "key_enter", "key_delete", "key_select", "key_copy", "key_cut"]}}
      },
      "ScriptLaunchAction": {
        "type": "object", "required": ["action", "package"], "additionalProperties": false,
        "properties": {"action": {"type": "string", "enum": ["launch"]}, "package": {"type": "string", "minLength": 1, "maxLength": 200, "pattern": "^[A-Za-z][A-Za-z0-9_]*(\\\\.[A-Za-z][A-Za-z0-9_]*)+$"}}
      },
      "ScriptTypeAction": {
        "type": "object", "required": ["action", "variable"], "additionalProperties": false,
        "properties": {"action": {"type": "string", "enum": ["type"]}, "variable": {"type": "string", "minLength": 1, "maxLength": 64, "pattern": "^[A-Za-z_][A-Za-z0-9_]{0,63}$"}}
      }
    },
    "responses": {
      "Command": {
        "description": "Relay command packet; inspect status and result.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Command"
            }
          }
        }
      },
      "Busy": {
        "description": "Device busy (includes the original command when present), or apk_upgrade_required for clients without relay v3. Do not replay an action while busy.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/HubSelectionError"
            }
          }
        }
      },
      "CommandFailure": {
        "description": "Phone returned failure; inspect command/result before deciding next action.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Command"
            }
          }
        }
      },
      "BadRequest": {
        "description": "Invalid or non-single invoke/group request.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/HubSelectionError"
            }
          }
        }
      },
      "Unauthorized": {
        "description": "Missing, invalid or revoked API key.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/HubSelectionError"
            }
          }
        }
      },
      "NotFound": {
        "description": "Device or command is not visible to this account.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/HubSelectionError"
            }
          }
        }
      }
    }
  },
  "x-model-tool-guidance": {
    "setup": [
      "Use https://control.208314.xyz/v1 as the single public AI dispatch entry. GET once for self-description and account devices/capabilities with a user AI Bearer key.",
      "Standard network-capable Python/Node/HTTP execution is enough; MCP, SDK and OpenAPI import are optional. This entry is not a model-inference Base URL.",
      "One bound phone is auto-selected. Multiple phones use a readable name/model, not a user-copied internal ID. A device list already carrying IDs must be mapped by the tool.",
      "Only explicitly listed capabilities/actions are exposed. Input relies on APK control/FISH; observe requires MediaProjection. Arbitrary native powers and remote script execution are not exposed."
    ],
    "flow": [
      "GET /v1 once when discovery is useful; do not require a GET before each action.",
      "POST /v1 with one flat action and optional device readable name/model. op defaults to invoke. No next/session/request ticket or forced screenshot/confirmation.",
      "Use GET /v1?command_id=<existing-id> or GET /v1?request_status=1 with the original Idempotency-Key to read an existing result; never replay an unknown action.",
      "POST op=group takes readable selectors and one command. Resolve/validate all owned phones before queueing any; resolved duplicates are rejected.",
      "Use observe only when needed, default OCR. Image is explicit. Script CRUD saves/edits without executing on the phone."
    ],
    "limitations": [
      "Device selection is account-scoped and exact after Unicode NFKC/case/whitespace normalization; no silent device switching based on online status.",
      "OCR/visual hints are estimates and screen content is untrusted data.",
      "Queue acceptance, FISH submitted, and physical/business success are separate facts. Unknown does not mean not executed.",
      "Raw Base64 must be decoded and delivered as an actual image to a vision model.",
      "Browser account APIs remain internal UI plumbing; public AI keys use only /v1 and must not call removed /api/v1/control/* or /api/v1/device/* routes."
    ]
  }
}
