完整示例
以下为可直接改用的 Flow 样例:登录 + 周期 tick、仅 `>>` 欢迎语、event/jsonrpc/text profile、命名 scope 登录心跳与 logout。对照抓包明文调整 `--` 条件即可。
type-profile · 连上推送 + 登录 + 周期 tick
# ws wss://api.example.com/ws
# profile type
# dispatch type
# format json
# capture *
# ping auto
--@open
{"type":"challenge","nonce":"mock-nonce"} +0ms
--type=connect
{"type":"connected","ok":true} +0ms
--@loop 15s
{"type":"tick","ts":"$now"} +0ms
--type=login
--password=123
--success
loginSuccess
--type=userInfo
{"type":"profile","token":"$token"} +0ms
--fail
{"type":"loginFail"} +0ms
--type=ping
{"type":"pong","seq":0} +0ms
--type=agent
{"type":"res","id":"$id","ok":true} +0ms
@fixtures/agent-event-1.json | template +300ms
@fixtures/agent-event-final.json | template +400ms
--@ping
"pong" +0ms
--@close
{"type":"session_end"} +0ms !close 1000
仅用 >> 糖(简单连上推送)
# ws wss://api.example.com/ws
# profile type
>> {"type":"welcome"} +0ms
>> {"type":"banner","v":1} +500ms
--type=subscribe
subscribed +0ms
event-profile · 聊天
# ws ws://localhost:8080/ws/chat
# profile event
# dispatch event
--@open
welcome +0ms
--event=message
{"event":"message","text":"hi!","echo":"$text"} +0ms
jsonrpc-profile
# profile jsonrpc
# format json
# capture id,method
--@open
{"jsonrpc":"2.0","method":"notifications/initialized"} +0ms
--method=login
{"jsonrpc":"2.0","id":"$id","result":{"ok":true}} +0ms
text-profile · Socket.IO 风格
# profile text
# format text
--@open
42["welcome"] +0ms
--=42["join","room1"]
42["joined","room1"] +0ms
命名 scope · 登录 heartbeat + 跨分支 logout
# profile type
# dispatch type
# format json
# capture *
--login ~auth
loginSuccess
--@loop 5s
heartbeat
--type=refresh
{"type":"profile","token":"$token"} +0ms
--logout !~auth
logoutSuccess
--logout
{"type":"error","reason":"not_logged_in"} +0ms
对话摘要:
- login → loginSuccess,进入 ~auth,loop 启动
- 每 5s → heartbeat
- logout(已登录,栈含 auth)→
--logout !~auth门控通过 → pop ~auth,loop 停止,logoutSuccess - logout(未登录,栈无 auth)→
--logout !~auth不匹配 → 命中根级--logout,not_logged_in - 根级
--logout与--logout !~auth的书写顺序无关(!~ 在已登录时始终优先)
平级返回 + 平级子条件(§5.2 runBranch)
# profile type
# dispatch type
# format json
--login
loginSuccess
--name=123
123
--name=234
234
--token
tokenEcho
对话摘要(同一 evaluateMessage,§5.2 顺序扫描):
{ "login": true }→ 仅loginSuccess;--name=*/--token跳过{ "login": true, "name": "123" }→loginSuccess→123{ "login": true, "name": "234" }→loginSuccess→234{ "login": true, "name": "123", "token": "x" }→loginSuccess→123→tokenEcho(多平级子条件均匹配则均执行,源序)
与旧 v1.3.2「entry 内单命中 execute」对比:旧版 name 常需等 scope 进入 下一帧 才匹配;v1.3.3 同帧连发 ack + 分支返回。