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
269 changes: 233 additions & 36 deletions dotnet/src/Generated/Rpc.cs

Large diffs are not rendered by default.

47 changes: 43 additions & 4 deletions dotnet/src/Generated/SessionEvents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ namespace GitHub.Copilot.SDK;
[JsonDerivedType(typeof(AssistantMessageDeltaEvent), "assistant.message_delta")]
[JsonDerivedType(typeof(AssistantReasoningEvent), "assistant.reasoning")]
[JsonDerivedType(typeof(AssistantReasoningDeltaEvent), "assistant.reasoning_delta")]
[JsonDerivedType(typeof(AssistantStreamingDeltaEvent), "assistant.streaming_delta")]
[JsonDerivedType(typeof(AssistantTurnEndEvent), "assistant.turn_end")]
[JsonDerivedType(typeof(AssistantTurnStartEvent), "assistant.turn_start")]
[JsonDerivedType(typeof(AssistantUsageEvent), "assistant.usage")]
Expand All @@ -42,6 +43,7 @@ namespace GitHub.Copilot.SDK;
[JsonDerivedType(typeof(SessionShutdownEvent), "session.shutdown")]
[JsonDerivedType(typeof(SessionSnapshotRewindEvent), "session.snapshot_rewind")]
[JsonDerivedType(typeof(SessionStartEvent), "session.start")]
[JsonDerivedType(typeof(SessionTaskCompleteEvent), "session.task_complete")]
[JsonDerivedType(typeof(SessionTitleChangedEvent), "session.title_changed")]
[JsonDerivedType(typeof(SessionTruncationEvent), "session.truncation")]
[JsonDerivedType(typeof(SessionUsageInfoEvent), "session.usage_info")]
Expand Down Expand Up @@ -315,6 +317,18 @@ public partial class SessionCompactionCompleteEvent : SessionEvent
public required SessionCompactionCompleteData Data { get; set; }
}

/// <summary>
/// Event: session.task_complete
/// </summary>
public partial class SessionTaskCompleteEvent : SessionEvent
{
[JsonIgnore]
public override string Type => "session.task_complete";

[JsonPropertyName("data")]
public required SessionTaskCompleteData Data { get; set; }
}

/// <summary>
/// Event: user.message
/// </summary>
Expand Down Expand Up @@ -387,6 +401,18 @@ public partial class AssistantReasoningDeltaEvent : SessionEvent
public required AssistantReasoningDeltaData Data { get; set; }
}

/// <summary>
/// Event: assistant.streaming_delta
/// </summary>
public partial class AssistantStreamingDeltaEvent : SessionEvent
{
[JsonIgnore]
public override string Type => "assistant.streaming_delta";

[JsonPropertyName("data")]
public required AssistantStreamingDeltaData Data { get; set; }
}

/// <summary>
/// Event: assistant.message
/// </summary>
Expand Down Expand Up @@ -899,6 +925,13 @@ public partial class SessionCompactionCompleteData
public string? RequestId { get; set; }
}

public partial class SessionTaskCompleteData
{
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[JsonPropertyName("summary")]
public string? Summary { get; set; }
}

public partial class UserMessageData
{
[JsonPropertyName("content")]
Expand Down Expand Up @@ -955,6 +988,12 @@ public partial class AssistantReasoningDeltaData
public required string DeltaContent { get; set; }
}

public partial class AssistantStreamingDeltaData
{
[JsonPropertyName("totalResponseSizeBytes")]
public required double TotalResponseSizeBytes { get; set; }
}

public partial class AssistantMessageData
{
[JsonPropertyName("messageId")]
Expand Down Expand Up @@ -996,10 +1035,6 @@ public partial class AssistantMessageDeltaData
[JsonPropertyName("deltaContent")]
public required string DeltaContent { get; set; }

[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[JsonPropertyName("totalResponseSizeBytes")]
public double? TotalResponseSizeBytes { get; set; }

[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[JsonPropertyName("parentToolCallId")]
public string? ParentToolCallId { get; set; }
Expand Down Expand Up @@ -1736,6 +1771,8 @@ public enum SystemMessageDataRole
[JsonSerializable(typeof(AssistantReasoningDeltaData))]
[JsonSerializable(typeof(AssistantReasoningDeltaEvent))]
[JsonSerializable(typeof(AssistantReasoningEvent))]
[JsonSerializable(typeof(AssistantStreamingDeltaData))]
[JsonSerializable(typeof(AssistantStreamingDeltaEvent))]
[JsonSerializable(typeof(AssistantTurnEndData))]
[JsonSerializable(typeof(AssistantTurnEndEvent))]
[JsonSerializable(typeof(AssistantTurnStartData))]
Expand Down Expand Up @@ -1783,6 +1820,8 @@ public enum SystemMessageDataRole
[JsonSerializable(typeof(SessionStartData))]
[JsonSerializable(typeof(SessionStartDataContext))]
[JsonSerializable(typeof(SessionStartEvent))]
[JsonSerializable(typeof(SessionTaskCompleteData))]
[JsonSerializable(typeof(SessionTaskCompleteEvent))]
[JsonSerializable(typeof(SessionTitleChangedData))]
[JsonSerializable(typeof(SessionTitleChangedEvent))]
[JsonSerializable(typeof(SessionTruncationData))]
Expand Down
141 changes: 141 additions & 0 deletions dotnet/test/AgentAndCompactRpcTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
*--------------------------------------------------------------------------------------------*/

using GitHub.Copilot.SDK.Rpc;
using GitHub.Copilot.SDK.Test.Harness;
using Xunit;
using Xunit.Abstractions;

namespace GitHub.Copilot.SDK.Test;

public class AgentAndCompactRpcTests(E2ETestFixture fixture, ITestOutputHelper output)
: E2ETestBase(fixture, "agent_and_compact_rpc", output)
{
[Fact]
public async Task Should_List_Available_Custom_Agents()
{
var customAgents = new List<CustomAgentConfig>
{
new()
{
Name = "test-agent",
DisplayName = "Test Agent",
Description = "A test agent",
Prompt = "You are a test agent."
},
new()
{
Name = "another-agent",
DisplayName = "Another Agent",
Description = "Another test agent",
Prompt = "You are another agent."
}
};

var session = await CreateSessionAsync(new SessionConfig { CustomAgents = customAgents });

var result = await session.Rpc.Agent.ListAsync();
Assert.NotNull(result.Agents);
Assert.Equal(2, result.Agents.Count);
Assert.Equal("test-agent", result.Agents[0].Name);
Assert.Equal("Test Agent", result.Agents[0].DisplayName);
Assert.Equal("A test agent", result.Agents[0].Description);
Assert.Equal("another-agent", result.Agents[1].Name);
}

[Fact]
public async Task Should_Return_Null_When_No_Agent_Is_Selected()
{
var customAgents = new List<CustomAgentConfig>
{
new()
{
Name = "test-agent",
DisplayName = "Test Agent",
Description = "A test agent",
Prompt = "You are a test agent."
}
};

var session = await CreateSessionAsync(new SessionConfig { CustomAgents = customAgents });

var result = await session.Rpc.Agent.GetCurrentAsync();
Assert.Null(result.Agent);
}

[Fact]
public async Task Should_Select_And_Get_Current_Agent()
{
var customAgents = new List<CustomAgentConfig>
{
new()
{
Name = "test-agent",
DisplayName = "Test Agent",
Description = "A test agent",
Prompt = "You are a test agent."
}
};

var session = await CreateSessionAsync(new SessionConfig { CustomAgents = customAgents });

// Select the agent
var selectResult = await session.Rpc.Agent.SelectAsync("test-agent");
Assert.NotNull(selectResult.Agent);
Assert.Equal("test-agent", selectResult.Agent.Name);
Assert.Equal("Test Agent", selectResult.Agent.DisplayName);

// Verify getCurrent returns the selected agent
var currentResult = await session.Rpc.Agent.GetCurrentAsync();
Assert.NotNull(currentResult.Agent);
Assert.Equal("test-agent", currentResult.Agent.Name);
}

[Fact]
public async Task Should_Deselect_Current_Agent()
{
var customAgents = new List<CustomAgentConfig>
{
new()
{
Name = "test-agent",
DisplayName = "Test Agent",
Description = "A test agent",
Prompt = "You are a test agent."
}
};

var session = await CreateSessionAsync(new SessionConfig { CustomAgents = customAgents });

// Select then deselect
await session.Rpc.Agent.SelectAsync("test-agent");
await session.Rpc.Agent.DeselectAsync();

// Verify no agent is selected
var currentResult = await session.Rpc.Agent.GetCurrentAsync();
Assert.Null(currentResult.Agent);
}

[Fact]
public async Task Should_Return_Empty_List_When_No_Custom_Agents_Configured()
{
var session = await CreateSessionAsync();

var result = await session.Rpc.Agent.ListAsync();
Assert.Empty(result.Agents);
}

[Fact]
public async Task Should_Compact_Session_History_After_Messages()
{
var session = await CreateSessionAsync();

// Send a message to create some history
await session.SendAndWaitAsync(new MessageOptions { Prompt = "What is 2+2?" });

// Compact the session
var result = await session.Rpc.Compaction.CompactAsync();
Assert.NotNull(result);
}
}
2 changes: 1 addition & 1 deletion dotnet/test/CompactionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public async Task Should_Trigger_Compaction_With_Low_Threshold_And_Emit_Events()
// Send multiple messages to fill up the context window
await session.SendAndWaitAsync(new MessageOptions
{
Prompt = "Tell me a long story about a dragon. Be very detailed."
Prompt = "Tell me a story about a dragon. Be detailed."
});
await session.SendAndWaitAsync(new MessageOptions
{
Expand Down
4 changes: 3 additions & 1 deletion go/generated_session_events.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading