|
| 1 | +# VCP Tool Call Manual Approval API |
| 2 | + |
| 3 | +Here is the documentation for the Phase 1 backend implementation to facilitate frontend integration. |
| 4 | + |
| 5 | +## Backend to Frontend (WebSocket Notification) |
| 6 | + |
| 7 | +When a tool call requires manual approval, the backend broadcasts a `tool_approval_request` to all connected [AdminPanel](file:///h:/VCP/VCPToolBox/WebSocketServer.js#541-555) clients. |
| 8 | + |
| 9 | +**Message Type:** `tool_approval_request` |
| 10 | + |
| 11 | +**Payload Format:** |
| 12 | +```json |
| 13 | +{ |
| 14 | + "type": "tool_approval_request", |
| 15 | + "data": { |
| 16 | + "requestId": "approve-1710348740345-6n2d9sk0p", |
| 17 | + "toolName": "LinuxShellExecutor", |
| 18 | + "maid": "VCPMaid", |
| 19 | + "args": { |
| 20 | + "command": "rm -rf /" |
| 21 | + }, |
| 22 | + "timestamp": "2024-03-14T00:52:20.345+08:00" |
| 23 | + } |
| 24 | +} |
| 25 | +``` |
| 26 | + |
| 27 | +- `requestId`: Unique identifier for this approval request. |
| 28 | +- `toolName`: The name of the tool being called. |
| 29 | +- `maid`: The identity (maid) initiating the call. |
| 30 | +- `args`: The arguments passed to the tool. |
| 31 | +- `timestamp`: Specific local time of the request. |
| 32 | + |
| 33 | +--- |
| 34 | + |
| 35 | +## Frontend to Backend (Approval Decision) |
| 36 | + |
| 37 | +The frontend should send back a `tool_approval_response` once the user clicks "Allow" or "Reject". |
| 38 | + |
| 39 | +**Message Type:** `tool_approval_response` |
| 40 | + |
| 41 | +**Payload Format:** |
| 42 | +```json |
| 43 | +{ |
| 44 | + "type": "tool_approval_response", |
| 45 | + "data": { |
| 46 | + "requestId": "approve-1710348740345-6n2d9sk0p", |
| 47 | + "approved": true |
| 48 | + } |
| 49 | +} |
| 50 | +``` |
| 51 | + |
| 52 | +- `requestId`: Must match the `requestId` received in the request. |
| 53 | +- `approved`: `true` to allow execution, `false` to reject. |
| 54 | + |
| 55 | +--- |
| 56 | + |
| 57 | +## Configuration Settings |
| 58 | + |
| 59 | +The logic is controlled by [toolApprovalConfig.json](file:///h:/VCP/VCPToolBox/toolApprovalConfig.json) in the project root: |
| 60 | + |
| 61 | +```json |
| 62 | +{ |
| 63 | + "enabled": false, |
| 64 | + "timeoutMinutes": 5, |
| 65 | + "approveAll": false, |
| 66 | + "approvalList": [ |
| 67 | + "TestTool1", |
| 68 | + "TestTool2" |
| 69 | + ] |
| 70 | +} |
| 71 | +``` |
| 72 | + |
| 73 | +- `enabled`: Global switch for the feature. |
| 74 | +- `timeoutMinutes`: Automatic rejection if no response is received within this time. |
| 75 | +- `approveAll`: If `true`, all tool calls will require manual approval (ignoring `approvalList`). |
| 76 | +- `approvalList`: specific list of tool names that require approval if `approveAll` is `false`. |
| 77 | + |
| 78 | +--- |
| 79 | + |
| 80 | +## Implementation Status |
| 81 | +- [x] Configuration loading & hot-reloading ([ToolApprovalManager](file:///h:/VCP/VCPToolBox/modules/toolApprovalManager.js#5-78)) |
| 82 | +- [x] Tool call interception ([Plugin.js](file:///h:/VCP/VCPToolBox/Plugin.js)) |
| 83 | +- [x] Promise-based waiting with timeout |
| 84 | +- [x] WebSocket broadcasting and response handling |
0 commit comments