6 saasai工具
saasai 是 saastool 的 AI 友好衍生版本,与 saastool 并存(同一套后端 API,同一份 cfg.toml 配置),专为 AI Agent、CI 流水线与自动化脚本设计:
- stdout 只输出结构化 JSON(或 table);失败时 stdout 严格为空,便于
cmd > ok.json不被污染。 - stderr 承载结构化错误 JSON(以及进度、日志),失败时 JSON 格式与成功输出同构。
- 精细化退出码(usage/config/auth/not-found/invalid/network/server/timeout 等),AI Agent 可据此决定是否重试。
- 破坏性命令全部支持
--dry-run(delete / resetds / columnclear / create / bind / grant 等)。 --hash-file -、--lua -等参数支持从 stdin 读入。
提示
- saasai 与 saastool 完全独立,原 saastool 的命令、参数、输出字节级保持不变,现有脚本无需修改。
- 建议:人工操作继续用 saastool;Agent / 流水线 / 新脚本用 saasai。
源码:saasai
6.1 基础约定
6.1.1 输出格式
saasai 默认 --output json,成功时写入 stdout 的统一结构(envelope):
{
"schema_version": "v1",
"status": "success",
"code": 0,
"command": "task list",
"data": { /* ... 业务数据 ... */ }
}
失败时写入 stderr(stdout 为空):
{
"schema_version": "v1",
"status": "error",
"code": 30,
"command": "task info",
"error": {
"type": "NOT_FOUND",
"message": "任务不存在",
"retriable": false,
"details": { "sha256": "abc..." }
}
}
| 字段 | 说明 |
|---|---|
schema_version | envelope 版本,当前 v1 |
status | success / error |
code | 与进程退出码一致 |
command | 子命令路径(如 task list) |
data | 成功时的业务数据 |
error.type | 错误类型枚举 |
error.retriable | 是否可自动重试 |
error.details | 额外诊断信息(如入参 sha256) |
6.1.2 退出码与错误类型
| code | type | 含义 | retriable |
|---|---|---|---|
| 0 | SUCCESS | 成功 | — |
| 1 | GENERAL_ERROR | 兜底错误 | ❓ |
| 2 | USAGE_ERROR | 参数错误 | ❌ |
| 10 | CONFIG_ERROR | 配置文件错误 | ❌ |
| 20 | AUTH_ERROR | 认证失败( 账号/签名错误) | ❌ |
| 21 | PERMISSION_ERROR | 权限不足(账号被禁用) | ❌ |
| 30 | NOT_FOUND | 资源不存在(任务/数据空间等) | ❌ |
| 40 | INVALID_INPUT | 输入非法(文件解析失败、参数越界等) | ❌ |
| 50 | NETWORK_ERROR | 网络错误 | ✅ |
| 51 | SERVER_ERROR | 服务端 5xx / 未分类服务端错误 | ✅ |
| 60 | TIMEOUT | 超时 | ✅ |
Agent 使用约定
code ∈ {50, 51, 60}可退避后自动重试。code ∈ {2, 10, 20, 21, 40}不可盲目重试,必须先修正输入或配置。code = 30按业务语义处理(例如可视作"已不存在")。
6.1.3 全局参数
| 参数 | 默认 | 含义 |
|---|---|---|
-o / --output | json | 输出格式:json(默认)或 table |
-c / --config | cfg.toml | 配置文件路径(与 saastool 完全兼容) |
-q / --quiet | false | 抑制 stderr 的进度与 info 日志(错误仍保留) |
-v / --verbose | 0 | 计数:-v info,-vv debug(写入 stderr) |
--dry-run | false | 破坏性命令仅打印"将要执行"的内容,不实际调用后端 |
-h / --help | — | 任意层级均可附加 |
注意
--output json(默认)下,进度条与 info/debug 日志会自动抑制,确保 stderr 也是纯净 JSON。需要看进度请用 -o table 或显式加 -v。
6.1.4 cfg.toml 配置文件
与 saastool 完全兼容。默认名称 cfg.toml,置于 saasai 同目录;也可用 -c 或 --config 指定。
[auth]
account = "2000"
token = "test"
[apiurls]
baseurl = "https://api.rta.qq.com" # 正式环境
#baseurl = "https://srta.algo.com.cn" # 演示环境
6.1.5 参数命名对照(与 saastool)
saasai 采用 GNU 风格(双横线 kebab-case);saastool 沿用 Go flag 风格。差异表:
| saastool | saasai | 语义 |
|---|---|---|
-config | --config / -c | 配置文件 |
-hashfile | --hash-file | 任务哈希文件,saasai 额外支持 - 表示 stdin |
-userids | --user-ids | 用户 ID 列表 |
-beginday / -endday | --begin-day / --end-day | 日期区间 |
-bucketids | --bucket-ids | 桶 ID |
-accountid | --account-id | 账户 ID |
-hashtype / -idtype | --hash-type / --id-type | 哈希/ID 类型 |
-blocksize | --block-size | 块大小 |
-batchsize | --batch-size | 批大小 |
-extfields | --ext-fields | 扩展字段 |
-groupby | --group-by | 分组 |
-b(target list) | --list-binds | 是否列出绑定 |
6.2 命令总览
saasai --help
Available Commands:
admincode Manage admin codes
bind Manage target binds
columnclear Clear columns for a data space (destructive!)
convert Convert data to write format (local, no network)
exp Manage experiments and exp grants
grant Manage data grants
info Get SaaS server info
read Read users' bytes / uint32s / flags
resetds Reset data space (destructive!)
script Manage lua scripts
target Manage targets
task Manage tasks
write Write users' bytes / uint32s / flags from files
信息
saasai 不提供 daemon / web 子命令,这两类长驻服务仍由 saastool 承担。
6.3 info
读取 sRTA 服务的基础信息(数据空间、策略 ID 等)。
| 参数 | 必填 | 含义 | 样例 |
|---|---|---|---|
--config / -c | 否 | 配置文件路径 | cfg.toml(默认) |
saasai info
输出示例
{
"schema_version": "v1",
"status": "success",
"code": 0,
"command": "info",
"data": {
"dataspace": { "did": ["did", "20010101"], "wuid": ["wuid", "20010201"] },
"targetId": ["test44"]
}
}
6.4 read(读取用户数据)
读取指定用户在数据空间中的数据(bytes / uint32s / flags)。
| 参数 | 必填 | 含义 | 样例 |
|---|---|---|---|
--ds | 是 | 数据空间 ID | did、wuid、geo、geoip、geofac |
--user-ids | 是 | 用户 ID 列表(逗号分隔,最多 100 个) | cfcd208495d565ef66e7dff9f98764da |
--appid | 否 | 小程序 appid | wx1111111111111111 |
--account-id | 否 | 账户 ID,--ds=wuid 且 --appid 非空时必填 | 123 |
--id-type | 否 | 哈希类型:0=DEFAULT、1=PHONE_MD5、2=PHONE_SHA256 | 1 |
--config / -c | 否 | 配置文件路径 | cfg.toml(默认) |
wuid 数据空间的参数约束
--ds=wuid且--appid为空:--id-type必须为1或2。--ds=wuid且--appid非空:必须指定--account-id。
使用示例
# did 单用户
saasai read --ds did --user-ids cfcd208495d565ef66e7dff9f98764da
# did 多用户
saasai read --ds did --user-ids cfcd208495d565ef66e7dff9f98764da,a87ff679a2f3e71d9181a67b7542122c
# wuid + openid
saasai read --ds wuid --user-ids o_e3j4ggVPO2CP8iCPBLunzKL79n --appid wx1111111111111111 --account-id 123
# wuid + 手机号 MD5
saasai read --ds wuid --id-type 1 --user-ids 6b23320fcfc29304d73ce8090bce8e96
6.5 write(写入用户数据)
向指定数据空间批量写入,source 可以是单文件或目录(递归处理)。
| 参数 |
|---|