Skip to content

Commit a7bee9d

Browse files
Rename PermissionHandlers to PermissionHandler across all SDK languages
- Node.js: rename const PermissionHandlers -> PermissionHandler in types.ts/index.ts - Python: rename class PermissionHandlers -> PermissionHandler; rename type alias PermissionHandler -> _PermissionHandlerFn (internal) - Go: rename var PermissionHandlers -> PermissionHandler in permissions.go - .NET: rename class PermissionHandlers -> PermissionHandler; rename delegate PermissionHandler -> PermissionRequestHandler Update all tests and samples to use PermissionHandler.ApproveAll / PermissionHandler.approve_all. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 64256b9 commit a7bee9d

26 files changed

Lines changed: 59 additions & 61 deletions

dotnet/samples/Chat.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
await using var client = new CopilotClient();
44
await using var session = await client.CreateSessionAsync(new SessionConfig
55
{
6-
OnPermissionRequest = PermissionHandlers.ApproveAll
6+
OnPermissionRequest = PermissionHandler.ApproveAll
77
});
88

99
using var _ = session.On(evt =>

dotnet/src/PermissionHandlers.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44

55
namespace GitHub.Copilot.SDK;
66

7-
/// <summary>Provides pre-built <see cref="PermissionHandler"/> implementations.</summary>
8-
public static class PermissionHandlers
7+
/// <summary>Provides pre-built <see cref="PermissionRequestHandler"/> implementations.</summary>
8+
public static class PermissionHandler
99
{
10-
/// <summary>A <see cref="PermissionHandler"/> that approves all permission requests.</summary>
11-
public static PermissionHandler ApproveAll { get; } =
10+
/// <summary>A <see cref="PermissionRequestHandler"/> that approves all permission requests.</summary>
11+
public static PermissionRequestHandler ApproveAll { get; } =
1212
(_, _) => Task.FromResult(new PermissionRequestResult { Kind = "approved" });
1313
}

dotnet/src/Session.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public partial class CopilotSession : IAsyncDisposable
4747
private readonly HashSet<SessionEventHandler> _eventHandlers = new();
4848
private readonly Dictionary<string, AIFunction> _toolHandlers = new();
4949
private readonly JsonRpc _rpc;
50-
private PermissionHandler? _permissionHandler;
50+
private PermissionRequestHandler? _permissionHandler;
5151
private readonly SemaphoreSlim _permissionHandlerLock = new(1, 1);
5252
private UserInputHandler? _userInputHandler;
5353
private readonly SemaphoreSlim _userInputHandlerLock = new(1, 1);
@@ -292,7 +292,7 @@ internal void RegisterTools(ICollection<AIFunction> tools)
292292
/// When the assistant needs permission to perform certain actions (e.g., file operations),
293293
/// this handler is called to approve or deny the request.
294294
/// </remarks>
295-
internal void RegisterPermissionHandler(PermissionHandler handler)
295+
internal void RegisterPermissionHandler(PermissionRequestHandler handler)
296296
{
297297
_permissionHandlerLock.Wait();
298298
try
@@ -313,7 +313,7 @@ internal void RegisterPermissionHandler(PermissionHandler handler)
313313
internal async Task<PermissionRequestResult> HandlePermissionRequestAsync(JsonElement permissionRequestData)
314314
{
315315
await _permissionHandlerLock.WaitAsync();
316-
PermissionHandler? handler;
316+
PermissionRequestHandler? handler;
317317
try
318318
{
319319
handler = _permissionHandler;

dotnet/src/Types.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ public class PermissionInvocation
166166
public string SessionId { get; set; } = string.Empty;
167167
}
168168

169-
public delegate Task<PermissionRequestResult> PermissionHandler(PermissionRequest request, PermissionInvocation invocation);
169+
public delegate Task<PermissionRequestResult> PermissionRequestHandler(PermissionRequest request, PermissionInvocation invocation);
170170

171171
// ============================================================================
172172
// User Input Handler Types
@@ -793,7 +793,7 @@ protected SessionConfig(SessionConfig? other)
793793
/// Handler for permission requests from the server.
794794
/// When provided, the server will call this handler to request permission for operations.
795795
/// </summary>
796-
public PermissionHandler? OnPermissionRequest { get; set; }
796+
public PermissionRequestHandler? OnPermissionRequest { get; set; }
797797

798798
/// <summary>
799799
/// Handler for user input requests from the agent.
@@ -932,7 +932,7 @@ protected ResumeSessionConfig(ResumeSessionConfig? other)
932932
/// Handler for permission requests from the server.
933933
/// When provided, the server will call this handler to request permission for operations.
934934
/// </summary>
935-
public PermissionHandler? OnPermissionRequest { get; set; }
935+
public PermissionRequestHandler? OnPermissionRequest { get; set; }
936936

937937
/// <summary>
938938
/// Handler for user input requests from the agent.

dotnet/test/HooksTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public async Task Should_Invoke_PreToolUse_Hook_When_Model_Runs_A_Tool()
1717
CopilotSession? session = null;
1818
session = await Client.CreateSessionAsync(new SessionConfig
1919
{
20-
OnPermissionRequest = PermissionHandlers.ApproveAll,
20+
OnPermissionRequest = PermissionHandler.ApproveAll,
2121
Hooks = new SessionHooks
2222
{
2323
OnPreToolUse = (input, invocation) =>
@@ -53,7 +53,7 @@ public async Task Should_Invoke_PostToolUse_Hook_After_Model_Runs_A_Tool()
5353
CopilotSession? session = null;
5454
session = await Client.CreateSessionAsync(new SessionConfig
5555
{
56-
OnPermissionRequest = PermissionHandlers.ApproveAll,
56+
OnPermissionRequest = PermissionHandler.ApproveAll,
5757
Hooks = new SessionHooks
5858
{
5959
OnPostToolUse = (input, invocation) =>
@@ -91,7 +91,7 @@ public async Task Should_Invoke_Both_PreToolUse_And_PostToolUse_Hooks_For_Single
9191

9292
var session = await Client.CreateSessionAsync(new SessionConfig
9393
{
94-
OnPermissionRequest = PermissionHandlers.ApproveAll,
94+
OnPermissionRequest = PermissionHandler.ApproveAll,
9595
Hooks = new SessionHooks
9696
{
9797
OnPreToolUse = (input, invocation) =>
@@ -133,7 +133,7 @@ public async Task Should_Deny_Tool_Execution_When_PreToolUse_Returns_Deny()
133133

134134
var session = await Client.CreateSessionAsync(new SessionConfig
135135
{
136-
OnPermissionRequest = PermissionHandlers.ApproveAll,
136+
OnPermissionRequest = PermissionHandler.ApproveAll,
137137
Hooks = new SessionHooks
138138
{
139139
OnPreToolUse = (input, invocation) =>

dotnet/test/McpAndAgentsTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ public async Task Should_Pass_Literal_Env_Values_To_Mcp_Server_Subprocess()
280280
var session = await Client.CreateSessionAsync(new SessionConfig
281281
{
282282
McpServers = mcpServers,
283-
OnPermissionRequest = PermissionHandlers.ApproveAll,
283+
OnPermissionRequest = PermissionHandler.ApproveAll,
284284
});
285285

286286
Assert.Matches(@"^[a-f0-9-]+$", session.SessionId);

dotnet/test/SessionTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ public async Task Send_Returns_Immediately_While_Events_Stream_In_Background()
335335
{
336336
var session = await Client.CreateSessionAsync(new SessionConfig
337337
{
338-
OnPermissionRequest = PermissionHandlers.ApproveAll,
338+
OnPermissionRequest = PermissionHandler.ApproveAll,
339339
});
340340
var events = new List<string>();
341341

dotnet/test/ToolsTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ await File.WriteAllTextAsync(
2323

2424
var session = await Client.CreateSessionAsync(new SessionConfig
2525
{
26-
OnPermissionRequest = PermissionHandlers.ApproveAll,
26+
OnPermissionRequest = PermissionHandler.ApproveAll,
2727
});
2828

2929
await session.SendAsync(new MessageOptions

go/internal/e2e/hooks_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func TestHooks(t *testing.T) {
2222
var mu sync.Mutex
2323

2424
session, err := client.CreateSession(t.Context(), &copilot.SessionConfig{
25-
OnPermissionRequest: copilot.PermissionHandlers.ApproveAll,
25+
OnPermissionRequest: copilot.PermissionHandler.ApproveAll,
2626
Hooks: &copilot.SessionHooks{
2727
OnPreToolUse: func(input copilot.PreToolUseHookInput, invocation copilot.HookInvocation) (*copilot.PreToolUseHookOutput, error) {
2828
mu.Lock()
@@ -81,7 +81,7 @@ func TestHooks(t *testing.T) {
8181
var mu sync.Mutex
8282

8383
session, err := client.CreateSession(t.Context(), &copilot.SessionConfig{
84-
OnPermissionRequest: copilot.PermissionHandlers.ApproveAll,
84+
OnPermissionRequest: copilot.PermissionHandler.ApproveAll,
8585
Hooks: &copilot.SessionHooks{
8686
OnPostToolUse: func(input copilot.PostToolUseHookInput, invocation copilot.HookInvocation) (*copilot.PostToolUseHookOutput, error) {
8787
mu.Lock()
@@ -147,7 +147,7 @@ func TestHooks(t *testing.T) {
147147
var mu sync.Mutex
148148

149149
session, err := client.CreateSession(t.Context(), &copilot.SessionConfig{
150-
OnPermissionRequest: copilot.PermissionHandlers.ApproveAll,
150+
OnPermissionRequest: copilot.PermissionHandler.ApproveAll,
151151
Hooks: &copilot.SessionHooks{
152152
OnPreToolUse: func(input copilot.PreToolUseHookInput, invocation copilot.HookInvocation) (*copilot.PreToolUseHookOutput, error) {
153153
mu.Lock()
@@ -217,7 +217,7 @@ func TestHooks(t *testing.T) {
217217
var mu sync.Mutex
218218

219219
session, err := client.CreateSession(t.Context(), &copilot.SessionConfig{
220-
OnPermissionRequest: copilot.PermissionHandlers.ApproveAll,
220+
OnPermissionRequest: copilot.PermissionHandler.ApproveAll,
221221
Hooks: &copilot.SessionHooks{
222222
OnPreToolUse: func(input copilot.PreToolUseHookInput, invocation copilot.HookInvocation) (*copilot.PreToolUseHookOutput, error) {
223223
mu.Lock()

go/internal/e2e/mcp_and_agents_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ func TestMCPServers(t *testing.T) {
127127

128128
session, err := client.CreateSession(t.Context(), &copilot.SessionConfig{
129129
MCPServers: mcpServers,
130-
OnPermissionRequest: copilot.PermissionHandlers.ApproveAll,
130+
OnPermissionRequest: copilot.PermissionHandler.ApproveAll,
131131
})
132132
if err != nil {
133133
t.Fatalf("Failed to create session: %v", err)

0 commit comments

Comments
 (0)