简体中文
Pipeline steps
YAML pipeline 会把每个 action 的输出传给下一步。Uni-CLI 当前有 113 个 built-in action。
其中 58 个属于 registered pipeline action。
另外 55 个属于 transport-native action。
基本结构
yaml
pipeline:
- fetch:
url: https://api.example.com/items
- select: data.items
- map:
title: ${{ item.title }}
url: ${{ item.url }}
- limit: ${{ args.limit }}HTTP 与内容
| Action | 用途 |
|---|---|
fetch | 请求 JSON 或其他结构化 HTTP 响应 |
fetch_text | 请求原始文字或 HTML |
parse_rss | 解析 RSS 或 Atom |
html_to_md | 把 HTML 转为 Markdown |
download | 保存远程文件 |
oauth2-token | 请求并存储 OAuth 2 token |
websocket | 通过 WebSocket 交换消息 |
yaml
- fetch:
url: https://api.example.com/search
method: GET
params:
q: ${{ args.query }}
headers:
Accept: application/jsonfetch 接收 JSON,fetch_text 接收有大小限制的文本。两者共用重定向验证、响应分类和重试调度。retry 表示总尝试次数。上游 Retry-After 以秒数或 HTTP 日期设定最短等待时间,调用方取消会结束等待。读取成功响应时发生中断,会使用剩余尝试次数重试。写入已被接受后发生响应中断,会返回 operation_outcome_ambiguous,调用方需要先核对资源当前状态。
cache 是 GET 请求的新鲜度上限,单位为秒。请求头用于区分内容表示和凭据,响应中的 max-age 和 Age 进一步限制有效期。no-store、no-cache、private 和 Vary: * 禁用复用,文件写入采用原子替换。cache: 0 跳过已有缓存。
数据转换
| Action | 用途 |
|---|---|
select | 从当前值中读取路径 |
select-xml | 从 XML 中选择数据 |
extract | 从 HTML 或 DOM 提取字段 |
map | 把 item 映射为新对象 |
filter | 保留匹配 item |
sort | 排序列表 |
limit | 保留前 N 项 |
to_entries | 把 object 转为 key/value entries |
split_text | 拆分文本 |
set | 保存命名值 |
append | 向列表追加值 |
assert | 验证结果条件 |
yaml
- map:
title: ${{ item.title }}
author: ${{ item.by }}
- filter: item.title && !item.deleted
- sort:
by: score
order: desc
- limit: 10Control flow
| Action | 用途 |
|---|---|
if | 条件匹配时运行分支 |
each | 为每个 item 运行 child pipeline |
parallel | 并发运行独立分支 |
rate_limit | 控制一个域名或资源的节奏 |
wait | 等待时间或目标条件 |
yaml
- each:
parallel: 4
pipeline:
- fetch:
url: https://api.example.com/items/${{ item.id }}浏览器
| Action | 用途 |
|---|---|
navigate | 打开 URL |
evaluate | 运行页面 JavaScript |
click | 点击选中元素 |
type | 输入文字 |
press | 发送按键 |
scroll | 滚动页面 |
snapshot | 读取页面 snapshot 与 ref |
tap | 激活 ref |
intercept | 捕获匹配的 browser request |
yaml
- navigate:
url: https://example.com
- snapshot:
interactive: true
- click:
selector: "#sign-in"本地与桌面 orchestration
| Action | 用途 |
|---|---|
exec | 用 argv array 启动可执行程序 |
write_temp | 为后续 action 创建临时文件 |
compute_* | 通过 compute 路由 snapshot、input、screenshot、assertion 和 session action |
常用桌面操作包括 compute_snapshot、compute_find、compute_click、compute_type、compute_press、compute_scroll、compute_screenshot、compute_assert、compute_session_start、compute_session_state 和 compute_session_end。
yaml
- exec:
command: ffprobe
args: ["-v", "quiet", "-print_format", "json", ${{ args.file }}]
parse: json
timeout: 30000Registered actions
以下列出已注册的动作名称。
text
append, assert, click, compute_apps, compute_assert, compute_cdp_attach,
compute_click, compute_drag, compute_evaluate, compute_find, compute_launch,
compute_observe, compute_point_click, compute_point_scroll, compute_press,
compute_screenshot, compute_scroll, compute_session_end,
compute_session_escalate, compute_session_start, compute_session_state,
compute_snapshot, compute_text, compute_type, compute_wait, compute_windows,
download, each, evaluate, exec, extract, fetch, fetch_text, filter,
html_to_md, if, intercept, limit, map, navigate, oauth2-token, parallel,
parse_rss, press, rate_limit, scroll, select, select-xml, set, snapshot,
sort, split_text, tap, to_entries, type, wait, websocket, write_tempTransport-native actions
传输适配器还提供 macOS AX、Windows UIA、Linux AT-SPI,以及剪贴板、应用和视觉操作,名称如下。
text
applescript, ax_*, uia_*, atspi_*, clipboard_read, clipboard_write,
focus_window, launch_app, visual_*这些动作通过选中的传输提供方及其能力记录执行。src/engine/step-surface.ts 从步骤注册表和传输处理器表生成完整列表。
模板
| 表达式 | 值 |
|---|---|
${{ args.name }} | 命令参数 |
${{ item.field }} | 当前 item 字段 |
${{ index }} | 当前列表 index |
${{ env.NAME }} | 环境变量 |
步骤 Schema 和实现在 src/engine/steps/ 中。修改流水线后,运行 npm run lint:adapters。