File size: 712 Bytes
4e23b01
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import type { ServerMessage } from './union';

export function entityId(msg: ServerMessage): string {
  const m = msg as {
    message_id?: string;
    tool_call_id?: string;
    interaction_id?: string;
    task_id?: string;
    todo_id?: string;
    system_id?: string;
    step_id?: string;
    turn_id?: string;
    agent_id?: string;
  };
  return (
    m.message_id ??
    m.tool_call_id ??
    m.interaction_id ??
    m.task_id ??
    m.todo_id ??
    m.system_id ??
    m.step_id ??
    m.turn_id ??
    m.agent_id ??
    ''
  );
}

export function entityKey(msg: ServerMessage): string {
  const agent = (msg as { agent_id?: string }).agent_id ?? '';
  return `${agent}:${msg.type}:${entityId(msg)}`;
}