Package com.tnsai.server.ws
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:
- Sends a
tool_approve_requestevent to the client - Blocks the (virtual) thread until the user responds
- 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 Summary
ConstructorsConstructorDescriptionWsToolApprovalFilter(String sessionId, String agentId, WsConnectionManager connectionManager, AuditService auditService) -
Method Summary
Modifier and TypeMethodDescriptionvoidalwaysTrust(String toolName) Marks a tool as always trusted for this session.voidCancel all pending approvals (e.g., on disconnect).booleanhandleApproval(String toolCallId, String decision) Called when the client sends a tool_approve response.booleanvoidsetAutonomyLevel(AutonomyLevel level) Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.tnsai.agents.execution.ToolCallFilter
evaluate
-
Constructor Details
-
WsToolApprovalFilter
public WsToolApprovalFilter(String sessionId, String agentId, WsConnectionManager connectionManager, AuditService auditService)
-
-
Method Details
-
setAutonomyLevel
-
isAllowed
- Specified by:
isAllowedin interfacecom.tnsai.agents.execution.ToolCallFilter
-
handleApproval
Called when the client sends a tool_approve response.In multi-agent sessions each agent has its own filter, but the
toolCallIdis 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 returnsfalsewith no side effects. Before TNS-308 this returnedvoid, the caller bailed after the first filter, and approvals on later filters were lost.- Parameters:
toolCallId- the tool call IDdecision-"approve","reject", or"always"- Returns:
trueif this filter owned a pending approval fortoolCallIdand completed it;falseif the id was unknown to this filter (caller should try the next filter in the session)
-
alwaysTrust
Marks a tool as always trusted for this session. -
cancelAll
public void cancelAll()Cancel all pending approvals (e.g., on disconnect).
-