File size: 1,447 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
import { request } from "../request";

export interface CommandCheckResponse {
  is_control_command: boolean;
  command_token: string | null;
}

export interface ApprovalCommandResponse {
  success: boolean;
  message: string;
}

export const commandsApi = {
  /** Check if text is a system control command */
  checkCommand: async (text: string): Promise<boolean> => {
    const response = await request<CommandCheckResponse>("/commands/check", {
      method: "POST",
      body: JSON.stringify({ text }),
    });
    return response.is_control_command;
  },

  /** Send approval command (approve or deny) */
  sendApprovalCommand: async (
    action: "approve" | "deny",
    requestId: string,
    sessionId: string,
    reason?: string,
    scope?: "exact" | "similar",
  ): Promise<ApprovalCommandResponse> => {
    console.log(
      `[commandsApi] Sending ${action} for request:`,
      requestId,
      "session:",
      sessionId,
      "reason:",
      reason,
      "scope:",
      scope,
    );

    // Use dedicated approval API endpoint (bypasses chat/session system)
    return request<ApprovalCommandResponse>(`/approval/${action}`, {
      method: "POST",
      body: JSON.stringify({
        request_id: requestId,
        session_id: sessionId,
        reason: reason || undefined,
        // scope only meaningful for approve; omitted on deny.
        scope: action === "approve" ? scope : undefined,
      }),
    });
  },
};