Derive turn event payloads from canonical result fields
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user