工作流语法.md 5.1 KB

工作流语法

基本结构

{
  "variables": {},
  "execute": []
}

结点总结

  • 控制/循环结点scheduleifforwhile
  • 系统结点delaysetechorandomlog
  • ADB 结点inputclicklocatepressswipescrollkeyevent
  • 扩展标签(Func)
  • ocr-chatextract-messagesocr-chat-historyextract-chat-historyread-last-messagesmart-chat-appendsave-messagesgenerate-summarygenerate-history-summaryread-txt / read-textsave-txt / save-textimg-center-point-locationimg-bounding-box-locationimg-croppingai-generatestring-press

结点分类说明


一、控制/循环结点

schedule(定时执行)

{ "type": "schedule", "condition": { "interval": "1s", "repeat": -1 }, "interval": [] }
  • condition.interval:间隔(如 "1s""2m""3h")。condition.repeat:次数,-1"forever" 为无限。interval:每次执行的操作数组。

if(条件判断)

{ "type": "if", "condition": "{变量} == '值'", "then": [], "else": [] }
  • condition 支持 {变量}== != > < >= <=&& ||。兼容旧字段 ture

for(循环)

{ "type": "for", "variable": "{item}", "items": [1, 2, 3], "body": [] }
  • variable:当前元素变量。items:数组(可写 "{listVar}")。body:每轮操作数组。

while(循环)

{ "type": "while", "condition": "{变量} > 0", "body": [] }
  • condition 同 if。body:循环体。兼容旧字段 ture

二、系统结点

delay(延迟)

{ "type": "delay", "value": "2s" }
  • 也支持字段 delay。单位:smh

set(变量设置)

{ "type": "set", "variable": "{name}", "value": "value" }
  • 支持的数据类型number(整数或小数)、string(字符串)、booltrue / false)。写入后参与运算或比较时按上述类型处理;布尔在变量上下文中以 "1" / "0" 存储。
  • value 支持 {var} 替换;含 +-*/ 时按算术表达式求值。变量定义在根级 variables,引用用 "{name}",echo 中拼接用 {{name}}

echo(打印console.log信息)

{ "type": "echo", "value": "消息: {{var}}" }

{ "type": "echo", "inVars": ["{var1}", "{var2}"] }
  • 打印信息到log.txt,如果报错会把报错信息显示

log(仅 UI 输出)

{ "type": "log", "value": "调试信息" }

{ "type": "log", "inVars": ["{var}"] }

random(随机数)

{ "type": "random", "inVars": ["1", "100"], "outVars": ["{randomNum}"], "integer": true }
  • inVars[0/1]:最小/最大值。outVars[0]:结果变量。integer 默认 true。传统写法 variableminmax 仍支持。

三、ADB 结点

{ "type": "input", "value": "文本", "clear": false }
{ "type": "click", "target": "{\"x\":100,\"y\":200}" }
{ "type": "locate", "method": "image", "target": "resources/icon.png", "variable": "{pos}" }
{ "type": "press", "value": "resources/btn.png" }
{ "type": "swipe", "value": "up-down" }
{ "type": "scroll", "value": "down" }
{ "type": "keyevent", "value": "4" }

四、扩展标签(Func)

通用基础结构(多数扩展标签)

{ "type": "标签名", "inVars": [], "outVars": [] }

各扩展标签基础结构示例:

  • fun(method 为 func 目录下脚本名)

    { "type": "fun", "method": "脚本文件名", "inVars": [], "outVars": [] }
    
  • ocr-chat / extract-messages / ocr-chat-history / extract-chat-history

    { "type": "ocr-chat", "inVars": ["(r,g,b)", "(r,g,b)", "区域坐标JSON"], "outVars": ["{chatHistory}"] }
    
  • read-last-message

    { "type": "read-last-message", "inVars": ["{chatJson}"], "outVars": ["{text}", "{sender}"] }
    
  • smart-chat-append

    { "type": "smart-chat-append", "inVars": ["{history}", "{current}"], "outVars": ["{merged}"] }
    
  • read-txt / read-text

    { "type": "read-txt", "inVars": ["history/chat-history.txt"], "outVars": ["{content}"] }
    
  • save-txt / save-text

    { "type": "save-txt", "inVars": ["{content}", "history/out.txt"], "outVars": [] }
    
  • img-center-point-location

    { "type": "img-center-point-location", "inVars": ["template.png"], "outVars": ["{pos}"] }
    
  • img-bounding-box-location

    { "type": "img-bounding-box-location", "inVars": ["ScreenShot.jpg", "ChatArea.png"], "outVars": ["{corners}"] }
    
  • img-cropping

    { "type": "img-cropping", "inVars": ["{areaJson}", "history/crop.png"], "outVars": [] }
    
  • ai-generate

    { "type": "ai-generate", "prompt": "请总结:{{input}}", "inVars": ["{input}"], "outVars": ["{result}"] }
    
  • string-press

    { "type": "string-press", "inVars": ["确定"], "outVars": [] }