# 工作流语法 ## 基本结构 ```json { "variables": {}, "execute": [] } ``` ## 结点总结 - **控制/循环结点**:`schedule`、`if`、`for`、`while` - **系统结点**:`delay`、`set`、`echo`、`random`、`log` - **ADB 结点**:`input`、`click`、`locate`、`press`、`swipe`、`scroll`、`keyevent` - **扩展标签(Func)**: - `ocr-chat`、`extract-messages`、`ocr-chat-history`、`extract-chat-history`、`read-last-message`、`smart-chat-append`、`save-messages`、`generate-summary`、`generate-history-summary`、`read-txt` / `read-text`、`save-txt` / `save-text`、`img-center-point-location`、`img-bounding-box-location`、`img-cropping`、`ai-generate`、`string-press` --- ## 结点分类说明 --- ### 一、控制/循环结点 **schedule**(定时执行) ```json { "type": "schedule", "condition": { "interval": "1s", "repeat": -1 }, "interval": [] } ``` - `condition.interval`:间隔(如 `"1s"`、`"2m"`、`"3h"`)。`condition.repeat`:次数,`-1` 或 `"forever"` 为无限。`interval`:每次执行的操作数组。 **if**(条件判断) ```json { "type": "if", "condition": "{变量} == '值'", "then": [], "else": [] } ``` - `condition` 支持 `{变量}`、`==` `!=` `>` `<` `>=` `<=`、`&&` `||`。兼容旧字段 **ture**。 **for**(循环) ```json { "type": "for", "variable": "{item}", "items": [1, 2, 3], "body": [] } ``` - `variable`:当前元素变量。`items`:数组(可写 `"{listVar}"`)。`body`:每轮操作数组。 **while**(循环) ```json { "type": "while", "condition": "{变量} > 0", "body": [] } ``` - `condition` 同 if。`body`:循环体。兼容旧字段 **ture**。 --- ### 二、系统结点 **delay**(延迟) ```json { "type": "delay", "value": "2s" } ``` - 也支持字段 `delay`。单位:`s`、`m`、`h`。 **set**(变量设置) ```json { "type": "set", "variable": "{name}", "value": "value" } ``` - **支持的数据类型**:`number`(整数或小数)、`string`(字符串)、`bool`(`true` / `false`)。写入后参与运算或比较时按上述类型处理;布尔在变量上下文中以 `"1"` / `"0"` 存储。 - `value` 支持 `{var}` 替换;含 `+`、`-`、`*`、`/` 时按算术表达式求值。变量定义在根级 `variables`,引用用 `"{name}"`,echo 中拼接用 `{{name}}`。 **echo**(打印console.log信息) ```json { "type": "echo", "value": "消息: {{var}}" } ``` 或 ```json { "type": "echo", "inVars": ["{var1}", "{var2}"] } ``` - 打印信息到log.txt,如果报错会把报错信息显示 **log**(仅 UI 输出) ```json { "type": "log", "value": "调试信息" } ``` 或 ```json { "type": "log", "inVars": ["{var}"] } ``` **random**(随机数) ```json { "type": "random", "inVars": ["1", "100"], "outVars": ["{randomNum}"], "integer": true } ``` - `inVars[0/1]`:最小/最大值。`outVars[0]`:结果变量。`integer` 默认 `true`。传统写法 `variable`、`min`、`max` 仍支持。 --- ### 三、ADB 结点 ```json { "type": "input", "value": "文本", "clear": false } ``` ```json { "type": "click", "target": "{\"x\":100,\"y\":200}" } ``` ```json { "type": "locate", "method": "image", "target": "resources/icon.png", "variable": "{pos}" } ``` ```json { "type": "press", "value": "resources/btn.png" } ``` ```json { "type": "swipe", "value": "up-down" } ``` ```json { "type": "scroll", "value": "down" } ``` ```json { "type": "keyevent", "value": "4" } ``` --- ### 四、扩展标签(Func) **通用基础结构**(多数扩展标签) ```json { "type": "标签名", "inVars": [], "outVars": [] } ``` 各扩展标签基础结构示例: - **fun**(method 为 func 目录下脚本名) ```json { "type": "fun", "method": "脚本文件名", "inVars": [], "outVars": [] } ``` - **ocr-chat** / **extract-messages** / **ocr-chat-history** / **extract-chat-history** ```json { "type": "ocr-chat", "inVars": ["(r,g,b)", "(r,g,b)", "区域坐标JSON"], "outVars": ["{chatHistory}"] } ``` - **read-last-message** ```json { "type": "read-last-message", "inVars": ["{chatJson}"], "outVars": ["{text}", "{sender}"] } ``` - **smart-chat-append** ```json { "type": "smart-chat-append", "inVars": ["{history}", "{current}"], "outVars": ["{merged}"] } ``` - **read-txt** / **read-text** ```json { "type": "read-txt", "inVars": ["history/chat-history.txt"], "outVars": ["{content}"] } ``` - **save-txt** / **save-text** ```json { "type": "save-txt", "inVars": ["{content}", "history/out.txt"], "outVars": [] } ``` - **img-center-point-location** ```json { "type": "img-center-point-location", "inVars": ["template.png"], "outVars": ["{pos}"] } ``` - **img-bounding-box-location** ```json { "type": "img-bounding-box-location", "inVars": ["ScreenShot.jpg", "ChatArea.png"], "outVars": ["{corners}"] } ``` - **img-cropping** ```json { "type": "img-cropping", "inVars": ["{areaJson}", "history/crop.png"], "outVars": [] } ``` - **ai-generate** ```json { "type": "ai-generate", "prompt": "请总结:{{input}}", "inVars": ["{input}"], "outVars": ["{result}"] } ``` - **string-press** ```json { "type": "string-press", "inVars": ["确定"], "outVars": [] } ``` ---