aixautobotaixautobot
写新云 aixautobot 文档

快速开始

添加依赖 · Feature 矩阵 · 二进制 · 最小示例

添加依赖

# Cargo.toml
[dependencies]
# 默认 full:开启全部 feature(vision/fleet/scriptlet-quickjs/license/screencast/hid/node/webrtc)
aixautosdk = { git = "https://github.com/aixautobot/aixautosdk", default-features = true }
tokio = { version = "1", features = ["full"] }

只取需要的能力(裁剪原生 / 重依赖):

# 例:只做 Android 驱动 + Flow,不要 vision/license/webrtc 等
aixautosdk = { git = "...", default-features = false, features = ["scriptlet"] }

Feature 矩阵

Feature说明额外依赖
full默认,开启下列全部
vision图像处理基础imageproc
vision-ocrOCR(含 vision)ort, ndarray
vision-yoloYOLO 目标检测(含 vision)ort
fleet集群调度数据结构dashmap
scriptlet脚本步骤(仅子进程 js/py/sh)
scriptlet-quickjs默认 full 已含;进程内 QuickJS,run_script 的 js 可直接驱动设备并读注入的 vars;裁剪后回退为 node -e 子进程、无设备访问rquickjs
license / license-online许可证(离线 / 在线校验)ed25519 等
screencast屏幕镜像
hid / hid-serialHID 输入 / 串口 HIDserialport
node节点 agent(/ws/node 客户端)tokio-tungstenite
webrtc节点 WebRTC 媒体(含 node+screencast)webrtc

aixautosdk::core(设备驱动 / Locator / Flow / 等核心)始终可用,不受 feature 影响。各子系统是顶层模块:aixautosdk::visionaixautosdk::fleetaixautosdk::node

二进制子命令

aixautosdk crate 提供单一可执行文件 aixautobot(子命令在对应 feature 关闭时自动消失):

子命令需要 feature作用
aixautobot nodenode执行节点 agent,注册到 backend 网关
aixautobot mcp serve(默认)MCP server(stdio)
aixautobot hid-bridgehidHID 输入桥
aixautobot skill(默认)打印内置 SDK skill,供 AI 阅读

最小示例:嵌入并驱动一台设备

use aixautosdk::core::prelude::*;

#[tokio::main]
async fn main() -> aixautosdk::core::Result<()> {
    let device = DeviceManager::connect("android", DeviceConfig {
        serial: Some("emulator-5554".into()),
        ..Default::default()
    }).await?;

    let png: Vec<u8> = device.screenshot().await?;
    std::fs::write("screen.png", &png)?;

    let btn: Element = device.find_element(&Locator::text("登录")).await?;
    device.tap(btn.rect.center_x(), btn.rect.center_y()).await?;
    Ok(())
}

完整的驱动/Flow 用法见 方式 A:嵌入 crate

最小示例:接入第一个节点

# 1) 在 backend 签发节点 token(需身份:项目 key/secret 或用户 JWT)
curl -sX POST http://<backend>/api/nodes \
  -H 'Content-Type: application/json' \
  -H 'X-Project-Key: <PROJECT_KEY>' -H 'X-Project-Secret: <PROJECT_SECRET>' \
  -d '{"name":"lab-node-1"}'
# → {"id":"...","token":"<NODE_TOKEN>"}   token 仅此一次返回

# 2) 运行节点(adb 设备自动枚举,无需指定平台)
AIXAUTOSDK_BACKEND_WS=ws://<backend>:3000 \
AIXAUTOSDK_NODE_TOKEN=<NODE_TOKEN> \
AIXAUTOSDK_NODE_NAME=lab-node-1 \
  ./aixautobot node

# 3) 通过网关代理一次截图
curl -sX POST http://<backend>/api/devices/<device_id>/op \
  -H 'Content-Type: application/json' \
  -H 'X-Project-Key: <PROJECT_KEY>' -H 'X-Project-Secret: <PROJECT_SECRET>' \
  -d '{"op":"screenshot"}'   # → { "png_base64": "..." }

生产走 HTTPS 时用 AIXAUTOSDK_BACKEND_WS=wss://aixautobot.com。节点接入细节见 方式 B:作为节点,更多 op 见 设备 API