Class WsToolApprovalFilter

java.lang.Object
com.tnsai.server.ws.WsToolApprovalFilter
All Implemented Interfaces:
com.tnsai.agents.execution.ToolCallFilter

public final class WsToolApprovalFilter extends Object implements com.tnsai.agents.execution.ToolCallFilter
Tool call filter that sends approval requests to WebSocket clients and blocks until the user responds.

For tools that require confirmation, this filter:

  1. Sends a tool_approve_request event to the client
  2. Blocks the (virtual) thread until the user responds
  3. Returns true (approved) or false (rejected)

Auto-approved tools (read-only, build/test) pass through without user interaction. Escalation commands (sudo, su) are always rejected without asking.

Phase 6: Autonomy-level-aware approval and audit trail recording.

  • Constructor Details

  • Method Details

    • setAutonomyLevel

      public void setAutonomyLevel(AutonomyLevel level)
    • isAllowed

      public boolean isAllowed(String toolName, Map<String,Object> arguments)
      Specified by:
      isAllowed in interface com.tnsai.agents.execution.ToolCallFilter
    • handleApproval

      public boolean handleApproval(String toolCallId, String decision)
      Called when the client sends a tool_approve response.

      In multi-agent sessions each agent has its own filter, but the toolCallId is unique across the session. The caller (WsHandler) iterates every filter in the session and asks each whether it owns this id; the one that does completes its future, every other returns false with no side effects. Before TNS-308 this returned void, the caller bailed after the first filter, and approvals on later filters were lost.

      Parameters:
      toolCallId - the tool call ID
      decision - "approve", "reject", or "always"
      Returns:
      true if this filter owned a pending approval for toolCallId and completed it; false if the id was unknown to this filter (caller should try the next filter in the session)
    • alwaysTrust

      public void alwaysTrust(String toolName)
      Marks a tool as always trusted for this session.
    • cancelAll

      public void cancelAll()
      Cancel all pending approvals (e.g., on disconnect).