| using System; |
| using System.Threading.Tasks; |
| namespace OnDeviceAgent.AgentCore |
| { |
|
|
| public sealed class ToolApprovalGate |
| { |
| public async Task<bool> IsApprovedOrRequest(IAgentTool tool, AgentToolContext ctx) |
| { |
| if (tool == null) |
| throw new ArgumentNullException("tool"); |
| if (ctx == null) |
| throw new ArgumentNullException("ctx"); |
|
|
| if (!ctx.ApprovalEnabledGlobally) |
| return true; |
|
|
| var approvalProp = ctx.Properties.Get(tool.Name, "approval"); |
| if (string.IsNullOrWhiteSpace(approvalProp) || |
| !approvalProp.Equals("required", StringComparison.OrdinalIgnoreCase)) |
| return true; |
|
|
| if (ctx.RequestApproval != null) |
| return await ctx.RequestApproval(tool.Name).ConfigureAwait(false); |
|
|
| return false; |
| } |
| } |
| } |
|
|