Derive turn event payloads from canonical result fields
This commit is contained in:
@@ -166,11 +166,6 @@ func (m *Manager) agyTurnEnded(ctx context.Context, l *live, p antigravityProces
|
||||
if !success {
|
||||
r.result = res.Error
|
||||
}
|
||||
r.payload = map[string]any{
|
||||
"subtype": r.subtype,
|
||||
"is_error": r.isError,
|
||||
"result": r.result,
|
||||
}
|
||||
return m.turnEnded(ctx, l, r)
|
||||
}
|
||||
|
||||
|
||||
@@ -270,11 +270,6 @@ func (m *Manager) codexTurnCompleted(ctx context.Context, l *live, s *codex.Sess
|
||||
m.mu.Unlock()
|
||||
}
|
||||
}
|
||||
res.payload = map[string]any{
|
||||
"subtype": res.subtype,
|
||||
"is_error": res.isError,
|
||||
"result": res.result,
|
||||
"vendor_uuid": turn.ID,
|
||||
}
|
||||
res.metadata = map[string]any{"vendor_uuid": turn.ID}
|
||||
return m.turnEnded(ctx, l, res)
|
||||
}
|
||||
|
||||
@@ -304,7 +304,7 @@ func (m *Manager) leadTurnEnded(ctx context.Context, l *live, res endResult) err
|
||||
finished := !res.isError && !interrupted && strings.TrimSpace(res.result) != ""
|
||||
handoff := compacting && finished
|
||||
|
||||
payload := res.payload
|
||||
payload := res.payload()
|
||||
if handoff {
|
||||
payload["handoff"] = true
|
||||
}
|
||||
|
||||
@@ -1086,8 +1086,13 @@ func (m *Manager) handle(ctx context.Context, l *live, ev claude.Event) error {
|
||||
subtype: res.Subtype,
|
||||
isError: res.IsError,
|
||||
result: res.Result,
|
||||
payload: store.ToPayload(res),
|
||||
window: res.ModelUsage[l.contextModel].ContextWindow,
|
||||
metadata: map[string]any{
|
||||
"duration_ms": res.DurationMS,
|
||||
"num_turns": res.NumTurns,
|
||||
"total_cost_usd": res.TotalCostUSD,
|
||||
"modelUsage": store.ToPayload(res.ModelUsage),
|
||||
},
|
||||
window: res.ModelUsage[l.contextModel].ContextWindow,
|
||||
})
|
||||
|
||||
case "stream_event":
|
||||
@@ -1153,11 +1158,22 @@ func (m *Manager) trackSubagents(ctx context.Context, l *live, raw map[string]an
|
||||
}
|
||||
|
||||
type endResult struct {
|
||||
subtype string
|
||||
isError bool
|
||||
result string
|
||||
payload map[string]any
|
||||
window int
|
||||
subtype string
|
||||
isError bool
|
||||
result string
|
||||
metadata map[string]any
|
||||
window int
|
||||
}
|
||||
|
||||
func (r endResult) payload() map[string]any {
|
||||
payload := map[string]any{}
|
||||
for key, value := range r.metadata {
|
||||
payload[key] = value
|
||||
}
|
||||
payload["subtype"] = r.subtype
|
||||
payload["is_error"] = r.isError
|
||||
payload["result"] = r.result
|
||||
return payload
|
||||
}
|
||||
|
||||
func (m *Manager) turnEnded(ctx context.Context, l *live, res endResult) error {
|
||||
@@ -1178,7 +1194,7 @@ func (m *Manager) turnEnded(ctx context.Context, l *live, res endResult) error {
|
||||
|
||||
finished := !res.isError && !interrupted && strings.TrimSpace(res.result) != ""
|
||||
|
||||
payload := res.payload
|
||||
payload := res.payload()
|
||||
if l.member != "" {
|
||||
payload["member"] = l.member
|
||||
}
|
||||
|
||||
@@ -547,7 +547,7 @@ func (m *Manager) reviewTurnEnded(ctx context.Context, l *live, res endResult) e
|
||||
interrupted := l.interrupted
|
||||
m.mu.Unlock()
|
||||
|
||||
err := m.emit(ctx, l, agentActor, "turn.ended", res.payload)
|
||||
err := m.emit(ctx, l, agentActor, "turn.ended", res.payload())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user