Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions dotnet/src/Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -759,12 +759,13 @@ public async ValueTask DisposeAsync()
private class RpcHandler(CopilotClient client)
{
[JsonRpcMethod("session.event")]
public void OnSessionEvent(SessionEventNotification notification)
public void OnSessionEvent(string sessionId,
JsonElement? @event)
{
var session = client.GetSession(notification.SessionId);
if (session != null && notification.Event != null)
var session = client.GetSession(sessionId);
if (session != null && @event != null)
{
var evt = SessionEvent.FromJson(notification.Event.ToString());
var evt = SessionEvent.FromJson(@event.Value.GetRawText());
session.DispatchEvent(evt);
}
}
Expand Down Expand Up @@ -957,10 +958,6 @@ private record DeleteSessionResponse(
private record ListSessionsResponse(
List<SessionMetadata> Sessions);

private record SessionEventNotification(
string SessionId,
JToken? Event);

private record ToolCallResponse(
ToolResultObject? Result);

Expand Down
32 changes: 32 additions & 0 deletions dotnet/test/SessionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -285,4 +285,36 @@ public async Task Should_Pass_Streaming_Option_To_Session_Creation()
Assert.NotNull(assistantMessage);
Assert.Contains("2", assistantMessage!.Data.Content);
}

[Fact]
public async Task Should_SessionEvt_Subscribed()
{
var session = await Client.CreateSessionAsync();
var receivedEvents = new List<SessionEvent>();
var idleReceived = new TaskCompletionSource<bool>();

session.On(evt =>
{
receivedEvents.Add(evt);
if (evt is SessionIdleEvent)
{
idleReceived.TrySetResult(true);
}
});

// Send a message to trigger events
await session.SendAsync(new MessageOptions { Prompt = "Hello!" });

// Wait for session to become idle (indicating message processing is complete)
var completed = await Task.WhenAny(idleReceived.Task, Task.Delay(TimeSpan.FromSeconds(60)));
Assert.Equal(idleReceived.Task, completed);

// Should have received multiple events (user message, assistant message, idle, etc.)
Assert.NotEmpty(receivedEvents);
Assert.Contains(receivedEvents, evt => evt is UserMessageEvent);
Assert.Contains(receivedEvents, evt => evt is AssistantMessageEvent);
Assert.Contains(receivedEvents, evt => evt is SessionIdleEvent);

await session.DisposeAsync();
}
}
Loading