@@ -45,6 +45,7 @@ public partial class CopilotSession : IAsyncDisposable
4545{
4646 private readonly HashSet < SessionEventHandler > _eventHandlers = new ( ) ;
4747 private readonly Dictionary < string , AIFunction > _toolHandlers = new ( ) ;
48+ private readonly Dictionary < string , bool > _toolRequiresApproval = new ( ) ;
4849 private readonly JsonRpc _rpc ;
4950 private PermissionHandler ? _permissionHandler ;
5051 private readonly SemaphoreSlim _permissionHandlerLock = new ( 1 , 1 ) ;
@@ -255,12 +256,36 @@ internal void DispatchEvent(SessionEvent sessionEvent)
255256 /// Tools allow the assistant to execute custom functions. When the assistant invokes a tool,
256257 /// the corresponding handler is called with the tool arguments.
257258 /// </remarks>
258- internal void RegisterTools ( ICollection < AIFunction > tools )
259+ internal void RegisterTools ( ICollection < AIFunction > ? tools )
259260 {
260261 _toolHandlers . Clear ( ) ;
262+ _toolRequiresApproval . Clear ( ) ;
263+ if ( tools == null ) return ;
264+
261265 foreach ( var tool in tools )
262266 {
263267 _toolHandlers . Add ( tool . Name , tool ) ;
268+ _toolRequiresApproval [ tool . Name ] = false ;
269+ }
270+ }
271+
272+ /// <summary>
273+ /// Registers custom tool handlers for this session with requiresApproval support.
274+ /// </summary>
275+ /// <param name="tools">A collection of CopilotTools that can be invoked by the assistant.</param>
276+ /// <remarks>
277+ /// Tools allow the assistant to execute custom functions. When the assistant invokes a tool,
278+ /// the corresponding handler is called with the tool arguments.
279+ /// CopilotTools support the RequiresApproval flag for permission handling.
280+ /// </remarks>
281+ internal void RegisterTools ( ICollection < CopilotTool > tools )
282+ {
283+ _toolHandlers . Clear ( ) ;
284+ _toolRequiresApproval . Clear ( ) ;
285+ foreach ( var tool in tools )
286+ {
287+ _toolHandlers . Add ( tool . Function . Name , tool . Function ) ;
288+ _toolRequiresApproval [ tool . Function . Name ] = tool . RequiresApproval ;
264289 }
265290 }
266291
@@ -272,6 +297,14 @@ internal void RegisterTools(ICollection<AIFunction> tools)
272297 internal AIFunction ? GetTool ( string name ) =>
273298 _toolHandlers . TryGetValue ( name , out var tool ) ? tool : null ;
274299
300+ /// <summary>
301+ /// Checks if a tool requires approval before execution.
302+ /// </summary>
303+ /// <param name="name">The name of the tool to check.</param>
304+ /// <returns>True if the tool requires approval, false otherwise.</returns>
305+ internal bool ToolRequiresApproval ( string name ) =>
306+ _toolRequiresApproval . TryGetValue ( name , out var requiresApproval ) && requiresApproval ;
307+
275308 /// <summary>
276309 /// Registers a handler for permission requests.
277310 /// </summary>
0 commit comments