feat: add protocol version 3 support with v3 broadcast event model#4
Open
pjperez wants to merge 5 commits intocopilot-community-sdk:mainfrom
Open
feat: add protocol version 3 support with v3 broadcast event model#4pjperez wants to merge 5 commits intocopilot-community-sdk:mainfrom
pjperez wants to merge 5 commits intocopilot-community-sdk:mainfrom
Conversation
- Bump SDK_PROTOCOL_VERSION to 3 (matches official SDKs) - Add MIN_PROTOCOL_VERSION = 2 for range-based checking - SDK now declares support for protocol versions 2-3
Report supported version range (min-max) in error message instead of a single expected version. Aligns with official SDKs.
Add ExternalToolRequestedData and PermissionRequestedData structs for the protocol v3 broadcast model where tool calls and permission requests arrive as session events instead of RPC requests.
Add handle_broadcast_event() to Session::dispatch_event() that intercepts external_tool.requested and permission.requested events, executes registered handlers, and responds via handlePendingToolCall / handlePendingPermissionRequest RPC. v2 RPC handlers kept as backward-compat adapters.
- verify_protocol_version() now checks MIN..MAX range - Stores negotiated_protocol_version for runtime use - Added v2/v3 backward-compat comments to setup_handlers - Aligns with official Python/Node/Go SDK implementations
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.
Protocol Version 3 Support
Add full protocol v3 support to align with the official GitHub Copilot SDKs (Python, Node.js, Go, .NET).
Problem
The Copilot CLI runtime has updated to protocol version 3, but the Rust SDK only supported version 2 with a strict equality check. This causes a hard failure:
Protocol version mismatch: expected 2, got 3.All official SDKs (in the
github/copilot-sdkmonorepo) already declare support for protocol versions 2-3 with range-based checking and include v3 broadcast event handling.Changes
Version constants and range checking:
SDK_PROTOCOL_VERSIONbumped from 2 to 3MIN_PROTOCOL_VERSION = 2to establish a supported version rangeverify_protocol_version()now usesMIN..MAXrange check instead of strict equalityProtocolMismatcherror now reports the supported version rangeProtocol v3 broadcast event model:
In protocol v3, tool calls and permission requests are sent as broadcast session events (
external_tool.requested,permission.requested) instead of JSON-RPC requests. This PR adds:ExternalToolRequestedData,PermissionRequestedDataSessionEventDatavariants for these eventshandle_broadcast_event()inSession— intercepts v3 events indispatch_event(), executes the registered tool/permission handlers, and sends results back viasession.tools.handlePendingToolCall/session.permissions.handlePendingPermissionRequestRPC callstool.call,permission.request) are kept as backward-compatibility adapters — a v3 server simply never sends themComparison with Official SDKs
Files changed
src/types.rs— Version constantssrc/error.rs— ProtocolMismatch error formatsrc/events.rs— New v3 event types and parsingsrc/session.rs— Broadcast event handling in dispatchsrc/client.rs— Range check, negotiated version, handler comments