Skip to content

Commit 24b9ac3

Browse files
stephentoubCopilot
andcommitted
Adapt hand-authored code to renamed schema in @github/copilot 1.0.40-1
The 1.0.40-1 schema renames several types that are referenced from hand-authored code: - ToolsHandlePendingToolCallRequest -> HandlePendingToolCallRequest - ToolsHandlePendingToolCall (union) -> ExternalToolResult (union) - ToolCallResult -> ExternalToolTextResultForLlm - PermissionCompletedKind enum -> PermissionResult polymorphism (PermissionResultApproved, PermissionResultDeniedInteractivelyByUser, ...) Update the corresponding hand-authored files so the SDKs build again: - go/rpc/result_union.go: rename receiver and union field references on the custom (Un)MarshalJSON methods. - go/session.go: use the new request/result type and union field names when sending tool call results back via RPC. - python/copilot/session.py: import the renamed RPC types and use them when constructing handle_pending_tool_call requests. - dotnet/test/MultiClientTests.cs: switch from a removed Kind enum comparison to Assert.IsType<PermissionResult*> against the new polymorphic PermissionResult derived types. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 1fd7b51 commit 24b9ac3

4 files changed

Lines changed: 25 additions & 25 deletions

File tree

dotnet/test/MultiClientTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ public async Task One_Client_Approves_Permission_And_Both_See_The_Result()
194194
foreach (var evt in client1Events.OfType<PermissionCompletedEvent>()
195195
.Concat(client2Events.OfType<PermissionCompletedEvent>()))
196196
{
197-
Assert.Equal(PermissionCompletedKind.Approved, evt.Data.Result.Kind);
197+
Assert.IsType<PermissionResultApproved>(evt.Data.Result);
198198
}
199199

200200
await session2.DisposeAsync();
@@ -246,7 +246,7 @@ await session1.SendAndWaitAsync(new MessageOptions
246246
foreach (var evt in client1Events.OfType<PermissionCompletedEvent>()
247247
.Concat(client2Events.OfType<PermissionCompletedEvent>()))
248248
{
249-
Assert.Equal(PermissionCompletedKind.DeniedInteractivelyByUser, evt.Data.Result.Kind);
249+
Assert.IsType<PermissionResultDeniedInteractivelyByUser>(evt.Data.Result);
250250
}
251251

252252
await session2.DisposeAsync();

go/rpc/result_union.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,33 @@ package rpc
22

33
import "encoding/json"
44

5-
// MarshalJSON serializes ToolsHandlePendingToolCall as the appropriate JSON variant:
6-
// a plain string when String is set, or the ToolCallResult object otherwise.
5+
// MarshalJSON serializes ExternalToolResult as the appropriate JSON variant:
6+
// a plain string when String is set, or the ExternalToolTextResultForLlm object otherwise.
77
// The generated struct has no custom marshaler, so without this the Go
8-
// struct fields would serialize as {"ToolCallResult":...,"String":...}
8+
// struct fields would serialize as {"ExternalToolTextResultForLlm":...,"String":...}
99
// instead of the union the server expects.
10-
func (r ToolsHandlePendingToolCall) MarshalJSON() ([]byte, error) {
10+
func (r ExternalToolResult) MarshalJSON() ([]byte, error) {
1111
if r.String != nil {
1212
return json.Marshal(*r.String)
1313
}
14-
if r.ToolCallResult != nil {
15-
return json.Marshal(*r.ToolCallResult)
14+
if r.ExternalToolTextResultForLlm != nil {
15+
return json.Marshal(*r.ExternalToolTextResultForLlm)
1616
}
1717
return []byte("null"), nil
1818
}
1919

20-
// UnmarshalJSON deserializes a JSON value into the appropriate ToolsHandlePendingToolCall variant.
21-
func (r *ToolsHandlePendingToolCall) UnmarshalJSON(data []byte) error {
20+
// UnmarshalJSON deserializes a JSON value into the appropriate ExternalToolResult variant.
21+
func (r *ExternalToolResult) UnmarshalJSON(data []byte) error {
2222
// Try string first
2323
var s string
2424
if err := json.Unmarshal(data, &s); err == nil {
2525
r.String = &s
2626
return nil
2727
}
28-
// Try ToolCallResult object
29-
var rr ToolCallResult
28+
// Try ExternalToolTextResultForLlm object
29+
var rr ExternalToolTextResultForLlm
3030
if err := json.Unmarshal(data, &rr); err == nil {
31-
r.ToolCallResult = &rr
31+
r.ExternalToolTextResultForLlm = &rr
3232
return nil
3333
}
3434
return nil

go/session.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -966,7 +966,7 @@ func (s *Session) executeToolAndRespond(requestID, toolName, toolCallID string,
966966
defer func() {
967967
if r := recover(); r != nil {
968968
errMsg := fmt.Sprintf("tool panic: %v", r)
969-
s.RPC.Tools.HandlePendingToolCall(ctx, &rpc.ToolsHandlePendingToolCallRequest{
969+
s.RPC.Tools.HandlePendingToolCall(ctx, &rpc.HandlePendingToolCallRequest{
970970
RequestID: requestID,
971971
Error: &errMsg,
972972
})
@@ -984,7 +984,7 @@ func (s *Session) executeToolAndRespond(requestID, toolName, toolCallID string,
984984
result, err := handler(invocation)
985985
if err != nil {
986986
errMsg := err.Error()
987-
s.RPC.Tools.HandlePendingToolCall(ctx, &rpc.ToolsHandlePendingToolCallRequest{
987+
s.RPC.Tools.HandlePendingToolCall(ctx, &rpc.HandlePendingToolCallRequest{
988988
RequestID: requestID,
989989
Error: &errMsg,
990990
})
@@ -1006,17 +1006,17 @@ func (s *Session) executeToolAndRespond(requestID, toolName, toolCallID string,
10061006
}
10071007
}
10081008

1009-
rpcResult := rpc.ToolsHandlePendingToolCall{
1010-
ToolCallResult: &rpc.ToolCallResult{
1009+
rpcResult := rpc.ExternalToolResult{
1010+
ExternalToolTextResultForLlm: &rpc.ExternalToolTextResultForLlm{
10111011
TextResultForLlm: textResultForLLM,
10121012
ToolTelemetry: result.ToolTelemetry,
10131013
ResultType: &effectiveResultType,
10141014
},
10151015
}
10161016
if result.Error != "" {
1017-
rpcResult.ToolCallResult.Error = &result.Error
1017+
rpcResult.ExternalToolTextResultForLlm.Error = &result.Error
10181018
}
1019-
s.RPC.Tools.HandlePendingToolCall(ctx, &rpc.ToolsHandlePendingToolCallRequest{
1019+
s.RPC.Tools.HandlePendingToolCall(ctx, &rpc.HandlePendingToolCallRequest{
10201020
RequestID: requestID,
10211021
Result: &rpcResult,
10221022
})

python/copilot/session.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@
2424
from .generated.rpc import (
2525
ClientSessionApiHandlers,
2626
CommandsHandlePendingCommandRequest,
27+
ExternalToolTextResultForLlm,
28+
HandlePendingToolCallRequest,
2729
LogRequest,
2830
ModelSwitchToRequest,
2931
PermissionDecision,
3032
PermissionDecisionKind,
3133
PermissionDecisionRequest,
3234
SessionLogLevel,
3335
SessionRpc,
34-
ToolCallResult,
35-
ToolsHandlePendingToolCallRequest,
3636
UIElicitationRequest,
3737
UIElicitationResponse,
3838
UIElicitationResponseAction,
@@ -1403,16 +1403,16 @@ async def _execute_tool_and_respond(
14031403
# failures send the full structured result to preserve metadata.
14041404
if tool_result._from_exception:
14051405
await self.rpc.tools.handle_pending_tool_call(
1406-
ToolsHandlePendingToolCallRequest(
1406+
HandlePendingToolCallRequest(
14071407
request_id=request_id,
14081408
error=tool_result.error,
14091409
)
14101410
)
14111411
else:
14121412
await self.rpc.tools.handle_pending_tool_call(
1413-
ToolsHandlePendingToolCallRequest(
1413+
HandlePendingToolCallRequest(
14141414
request_id=request_id,
1415-
result=ToolCallResult(
1415+
result=ExternalToolTextResultForLlm(
14161416
text_result_for_llm=tool_result.text_result_for_llm,
14171417
error=tool_result.error,
14181418
result_type=tool_result.result_type,
@@ -1423,7 +1423,7 @@ async def _execute_tool_and_respond(
14231423
except Exception as exc:
14241424
try:
14251425
await self.rpc.tools.handle_pending_tool_call(
1426-
ToolsHandlePendingToolCallRequest(
1426+
HandlePendingToolCallRequest(
14271427
request_id=request_id,
14281428
error=str(exc),
14291429
)

0 commit comments

Comments
 (0)