Add PermissionRequestResultKind type for .NET and Go SDKs#631
Draft
stephentoub wants to merge 3 commits intogithub:mainfrom
Draft
Add PermissionRequestResultKind type for .NET and Go SDKs#631stephentoub wants to merge 3 commits intogithub:mainfrom
stephentoub wants to merge 3 commits intogithub:mainfrom
Conversation
Replace magic strings for permission request result kinds with strongly-typed values. .NET uses a readonly struct following the ChatRole pattern from Microsoft.Extensions.AI. Go uses a typed string constant block following the existing ConnectionState pattern. Both remain extensible for custom values while making the well-known kinds (approved, denied-by-rules, denied-interactively-by-user, denied-no-approval-rule-and-could-not-request-from-user) discoverable via IntelliSense/autocomplete. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Adds strongly-typed permission request result kinds to the Go and .NET SDKs to replace previously required “magic string” values, aligning these SDKs with the more constrained typing already present in other languages.
Changes:
- Go: Introduces
PermissionRequestResultKind(typed string) with exported constants, updates SDK and e2e tests to use them. - .NET: Introduces
PermissionRequestResultKind(readonly struct +JsonConverter), updates SDK code and tests to use it. - Adds new unit tests validating constants and JSON round-trips in both SDKs.
Reviewed changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| go/types.go | Adds PermissionRequestResultKind and updates PermissionRequestResult.Kind to use it. |
| go/types_test.go | New unit tests for Go constants and JSON serialization/deserialization. |
| go/session.go | Replaces denial magic string with the new Go constant. |
| go/permissions.go | Updates ApproveAll handler to use the new Go constant. |
| go/client.go | Updates fallback denial kind to use the new Go constant. |
| go/internal/e2e/tools_test.go | Updates e2e permission handler returns to use new Go constants. |
| go/internal/e2e/permissions_test.go | Updates e2e permission handler returns to use new Go constants. |
| dotnet/src/Types.cs | Adds PermissionRequestResultKind struct + converter and updates PermissionRequestResult.Kind type. |
| dotnet/src/Session.cs | Updates default denial to use PermissionRequestResultKind. |
| dotnet/src/PermissionHandlers.cs | Updates ApproveAll to use PermissionRequestResultKind. |
| dotnet/src/Client.cs | Updates fallback denial to use PermissionRequestResultKind. |
| dotnet/test/ToolsTests.cs | Updates tests to return typed kinds. |
| dotnet/test/PermissionTests.cs | Updates tests to return typed kinds. |
| dotnet/test/PermissionRequestResultKindTests.cs | New unit tests for value correctness, equality, and JSON round-trips. |
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The 'forwards clientName in session.resume request' test calls through to the real CLI, which requires COPILOT_HMAC_KEY for authentication. This secret is unavailable to fork PRs, causing CI failures. Mock the sendRequest return value since the test only verifies parameter forwarding. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Replace magic strings for permission request result kinds with strongly-typed values in the .NET and Go SDKs.
Problem
The
PermissionRequestResult.Kindfield was typed as a plainstringin both .NET and Go, requiring developers to use undiscoverable magic strings like"approved"or"denied-interactively-by-user". Node.js and Python already constrain these via union/literal types.Solution
C# (.NET): Add a
PermissionRequestResultKindreadonly struct following theChatRolepattern fromMicrosoft.Extensions.AI:IEquatable<T>, case-insensitive equality, customJsonConverterApproved,DeniedByRules,DeniedCouldNotRequestFromUser,DeniedInteractivelyByUserGo: Add a
PermissionRequestResultKindtyped string with constants, following the existingConnectionStatepattern:PermissionKindApproved,PermissionKindDeniedByRules,PermissionKindDeniedCouldNotRequestFromUser,PermissionKindDeniedInteractivelyByUserBoth SDKs include unit tests covering value correctness, equality, and JSON serialization round-trips. All existing magic string usages in source and test files have been replaced with the new constants.