File size: 3,309 Bytes
4e7644b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import { request } from "../request";

export interface PushMessage {
  id: string;
  text: string;
}

export interface InboxEvent {
  id: string;
  agent_id: string;
  source_type: string;
  source_id: string;
  event_type: string;
  status: string;
  severity: string;
  title: string;
  body: string;
  payload?: Record<string, unknown>;
  read: boolean;
  created_at: number;
}

export interface InboxTrace {
  run_id: string;
  created_at: number;
  completed_at: number | null;
  status: string;
  meta: Record<string, unknown>;
  events: Array<{
    at: number;
    event: Record<string, unknown>;
  }>;
  error?: string;
}

export interface PendingApproval {
  request_id: string;
  session_id: string;
  root_session_id: string;
  owner_agent_id?: string;
  agent_id: string;
  tool_name: string;
  tool_display_name?: string;
  tool_source?: string;
  severity: string;
  findings_count: number;
  findings_summary: string;
  tool_params: Record<string, unknown>;
  created_at: number;
  timeout_seconds: number;
  // One-line rationale emitted by the agent before requesting the tool
  // call. May be an empty string when the agent gave no reasoning.
  reasoning?: string;
  // Approval-scope display fields (governance path). When is_generalized
  // is true the console offers Approve Pattern vs Approve Exact.
  is_generalized?: boolean;
  exact_target?: string;
  similar_target?: string;
  source_type: string;
}

export const consoleApi = {
  getPushMessages: (sessionId?: string) =>
    request<{ messages: PushMessage[]; pending_approvals: PendingApproval[] }>(
      sessionId
        ? `/console/push-messages?session_id=${sessionId}`
        : "/console/push-messages",
    ),

  getInboxEvents: (params?: {
    limit?: number;
    offset?: number;
    source_type?: string;
    source_types?: string[];
    status?: string;
    agent_id?: string;
    unread_only?: boolean;
  }) => {
    const query = new URLSearchParams();
    if (params?.limit !== undefined) query.set("limit", String(params.limit));
    if (params?.offset !== undefined)
      query.set("offset", String(params.offset));
    if (params?.source_type) query.set("source_type", params.source_type);
    for (const sourceType of params?.source_types ?? []) {
      query.append("source_types", sourceType);
    }
    if (params?.status) query.set("status", params.status);
    if (params?.agent_id) query.set("agent_id", params.agent_id);
    if (params?.unread_only !== undefined) {
      query.set("unread_only", String(params.unread_only));
    }
    const suffix = query.toString() ? `?${query.toString()}` : "";
    return request<{
      events: InboxEvent[];
      total?: number;
      unread_count?: number;
    }>(`/console/inbox/events${suffix}`);
  },

  markInboxRead: (payload: { event_ids?: string[]; all?: boolean }) =>
    request<{ updated: number }>("/console/inbox/read", {
      method: "POST",
      body: JSON.stringify(payload),
    }),

  deleteInboxEvent: (eventId: string) =>
    request<{
      deleted: boolean;
      trace_deleted?: boolean;
      run_id?: string | null;
    }>(`/console/inbox/events/${encodeURIComponent(eventId)}`, {
      method: "DELETE",
    }),

  getInboxTrace: (runId: string) =>
    request<InboxTrace>(`/console/inbox/traces/${encodeURIComponent(runId)}`),
};