Skip to content

Commit cb80f83

Browse files
authored
Use STJ's polymorphism support instead of custom converter (#70)
* Use STJ's polymorphism support instead of custom converter Also: - Mark properties as required if they're required in the schema - Mark reference types as nullable if they're optional in the schema - Remove the suppression of CS8618, which is resulting in public types having incorrect nullable annotations - Annotate enums so the NativeAOT-unfriendly non-generic enum converter isn't needed * Address feedback * Fix enum attribution
1 parent 5731c68 commit cb80f83

File tree

5 files changed

+315
-365
lines changed

5 files changed

+315
-365
lines changed

dotnet/src/Client.cs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,13 @@
55
using Microsoft.Extensions.AI;
66
using Microsoft.Extensions.Logging;
77
using Microsoft.Extensions.Logging.Abstractions;
8-
using Newtonsoft.Json.Linq;
98
using StreamJsonRpc;
109
using System.Collections.Concurrent;
1110
using System.Data;
1211
using System.Diagnostics;
1312
using System.Diagnostics.CodeAnalysis;
1413
using System.Net.Sockets;
1514
using System.Text.Json;
16-
using System.Text.Json.Nodes;
1715
using System.Text.Json.Serialization;
1816
using System.Text.RegularExpressions;
1917

@@ -43,8 +41,8 @@ namespace GitHub.Copilot.SDK;
4341
/// // Handle events
4442
/// using var subscription = session.On(evt =>
4543
/// {
46-
/// if (evt.Type == "assistant.message")
47-
/// Console.WriteLine(evt.Data?.Content);
44+
/// if (evt is AssistantMessageEvent assistantMessage)
45+
/// Console.WriteLine(assistantMessage.Data?.Content);
4846
/// });
4947
///
5048
/// // Send a message
@@ -724,12 +722,10 @@ static IJsonRpcMessageFormatter CreateFormatter()
724722
{
725723
var options = new JsonSerializerOptions(JsonSerializerDefaults.Web)
726724
{
725+
AllowOutOfOrderMetadataProperties = true,
727726
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull
728727
};
729-
foreach (var converter in SerializerOptions.Default.Converters)
730-
{
731-
options.Converters.Add(converter);
732-
}
728+
733729
return new SystemTextJsonFormatter() { JsonSerializerOptions = options };
734730
}
735731

0 commit comments

Comments
 (0)