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 {
|
if !success {
|
||||||
r.result = res.Error
|
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)
|
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()
|
m.mu.Unlock()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
res.payload = map[string]any{
|
res.metadata = map[string]any{"vendor_uuid": turn.ID}
|
||||||
"subtype": res.subtype,
|
|
||||||
"is_error": res.isError,
|
|
||||||
"result": res.result,
|
|
||||||
"vendor_uuid": turn.ID,
|
|
||||||
}
|
|
||||||
return m.turnEnded(ctx, l, res)
|
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) != ""
|
finished := !res.isError && !interrupted && strings.TrimSpace(res.result) != ""
|
||||||
handoff := compacting && finished
|
handoff := compacting && finished
|
||||||
|
|
||||||
payload := res.payload
|
payload := res.payload()
|
||||||
if handoff {
|
if handoff {
|
||||||
payload["handoff"] = true
|
payload["handoff"] = true
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1086,7 +1086,12 @@ func (m *Manager) handle(ctx context.Context, l *live, ev claude.Event) error {
|
|||||||
subtype: res.Subtype,
|
subtype: res.Subtype,
|
||||||
isError: res.IsError,
|
isError: res.IsError,
|
||||||
result: res.Result,
|
result: res.Result,
|
||||||
payload: store.ToPayload(res),
|
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,
|
window: res.ModelUsage[l.contextModel].ContextWindow,
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -1156,10 +1161,21 @@ type endResult struct {
|
|||||||
subtype string
|
subtype string
|
||||||
isError bool
|
isError bool
|
||||||
result string
|
result string
|
||||||
payload map[string]any
|
metadata map[string]any
|
||||||
window int
|
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 {
|
func (m *Manager) turnEnded(ctx context.Context, l *live, res endResult) error {
|
||||||
go m.readUsage(l.vendor)
|
go m.readUsage(l.vendor)
|
||||||
if l.owner != "" {
|
if l.owner != "" {
|
||||||
@@ -1178,7 +1194,7 @@ func (m *Manager) turnEnded(ctx context.Context, l *live, res endResult) error {
|
|||||||
|
|
||||||
finished := !res.isError && !interrupted && strings.TrimSpace(res.result) != ""
|
finished := !res.isError && !interrupted && strings.TrimSpace(res.result) != ""
|
||||||
|
|
||||||
payload := res.payload
|
payload := res.payload()
|
||||||
if l.member != "" {
|
if l.member != "" {
|
||||||
payload["member"] = 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
|
interrupted := l.interrupted
|
||||||
m.mu.Unlock()
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user