feat(orchestration,gateway): 子代理结果登 WS 帧 subagent_result(裁决 02.4.3)
- 编排层改为在 subagent.result 上发布带父会话归属的 SubagentResultEvent,后台批次结果不再消失在进程内总线 - gateway 中继:新帧常量 wsSubagentResult="subagent_result",eventBridge/bridgePatterns 登记该 topic,normalizeEvent 专用成形(帧壳 sessionId = 派生该批次的父会话) - 角色门 fail-closed:未登记进 frameReachesAll,owner/admin 可达、viewer 不可达,真 JWT 三角色 WS 断言钉住 - 前景(2s 内跑完)批次仍只回工具结果,不发此帧
This commit is contained in:
1 parent
0ce498754a
commit
8c6466cb00
4 files changed
+295
-22
No files matched your search
@@ -9,15 +9,23 @@ import (
|
||||
"git.yeij.top/AskaEth/Cyrene_v2/internal/runtime/orchestration/comm"
|
||||
)
|
||||
|
||||
// wsSubagentResult 是后台子代理批次结算后的下行帧类型(design/05 §9「结果回填
|
||||
// 主会话并提示用户」)。编排层在 orchestration.SubagentResultSubject 上发布批次
|
||||
// 结果,本文件的中继把它成形为这一帧并按载荷里的父会话归属。它属**内容帧**,
|
||||
// 因此走 design/11 §7.1 的 fail-closed 默认档:只发 owner + admin(不登记进那 7 个
|
||||
// 状态机信号白名单)。
|
||||
const wsSubagentResult = "subagent_result"
|
||||
|
||||
// eventBridge 把生产者 bus 主题映射为其下行 WS 事件类型。hub
|
||||
// 订阅这些(并重新归一化为 ws.* 类型),使前端既有的
|
||||
// 消费方亮起来,而生产者无需改变其主题名。
|
||||
var eventBridge = map[string]string{
|
||||
"iot.device_update": "device_update",
|
||||
"task.output": "task_output",
|
||||
"task.done": "task_done",
|
||||
"automation.result": "automation_result",
|
||||
"reminder.trigger": "reminder",
|
||||
"iot.device_update": "device_update",
|
||||
"task.output": "task_output",
|
||||
"task.done": "task_done",
|
||||
"automation.result": "automation_result",
|
||||
"reminder.trigger": "reminder",
|
||||
orchestration.SubagentResultSubject: wsSubagentResult,
|
||||
}
|
||||
|
||||
// bridgePatterns 是 hub 在 ws.> 之外额外订阅的 bus 模式,用于
|
||||
@@ -28,6 +36,9 @@ var bridgePatterns = []string{
|
||||
"automation.>",
|
||||
"reminder.>",
|
||||
"cyrene.agent.*.event",
|
||||
// 后台子代理批次结果:它既不匹配 ws.>,也不是 cyrene.agent 的 4 段广播形态,
|
||||
// 所以必须在这里登记订阅,否则后台结果永远上不了前台(只能看到进度帧)。
|
||||
orchestration.SubagentResultSubject,
|
||||
}
|
||||
|
||||
// normalizeEvent 把 bus 事件映射为下行 wsEvent。ws.* 主题保持
|
||||
@@ -36,6 +47,14 @@ var bridgePatterns = []string{
|
||||
// ws.subagent_event。对没有 WS 可见表示的事件返回 ok=false
|
||||
// (例如内部的 cyrene.agent ask/reply 流量)。
|
||||
func normalizeEvent(e bus.Event) (wsEvent, bool) {
|
||||
// 后台批次结果先走专用成形:它要按载荷里的父会话把结果归属到该会话的实时流
|
||||
// (帧壳 sessionId),这是 eventBridge 的原样透传做不到的。载荷形状不符预期时
|
||||
// 退回下面的通用映射(两路都只发 owner + admin)。
|
||||
if e.Subject == orchestration.SubagentResultSubject {
|
||||
if ev, ok := subagentResultEvent(e.Payload); ok {
|
||||
return ev, true
|
||||
}
|
||||
}
|
||||
if typ, ok := eventBridge[e.Subject]; ok {
|
||||
return wsEvent{Type: typ, Data: e.Payload}, true
|
||||
}
|
||||
@@ -48,6 +67,18 @@ func normalizeEvent(e bus.Event) (wsEvent, bool) {
|
||||
return wsEvent{}, false
|
||||
}
|
||||
|
||||
// subagentResultEvent 把后台批次的结果成形为下行帧:帧壳 sessionId 取自载荷的
|
||||
// 父会话,使结果落回**父会话**的实时消息流(design/05 §9);data 即载荷本身
|
||||
// (批次状态/汇总 + 逐代理结果,与派发工具返回给模型的结果同形)。载荷不是
|
||||
// *orchestration.SubagentResultEvent 时返回 ok=false,由调用方退回通用映射。
|
||||
func subagentResultEvent(payload any) (wsEvent, bool) {
|
||||
ev, ok := payload.(*orchestration.SubagentResultEvent)
|
||||
if !ok || ev == nil {
|
||||
return wsEvent{}, false
|
||||
}
|
||||
return wsEvent{Type: wsSubagentResult, SessionID: ev.SessionID, Data: ev}, true
|
||||
}
|
||||
|
||||
// subagentProgressEvent 把编排进度事件 —— 经 comm.PublishEvent 广播在
|
||||
// cyrene.agent.<from>.event 上 —— 映射为 ws.subagent_event
|
||||
// 帧。只有五个子代理进度名会被浮现;同一主题上广播的
|
||||
|
||||
Reference in new issue
Block a user