Skip to content

Commit b595685

Browse files
committed
Address feedback
1 parent 0c327e4 commit b595685

File tree

4 files changed

+19
-12
lines changed

4 files changed

+19
-12
lines changed

dotnet/src/Client.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ namespace GitHub.Copilot.SDK;
4141
/// // Handle events
4242
/// using var subscription = session.On(evt =>
4343
/// {
44-
/// if (evt is AssistantMessageEvent)
45-
/// Console.WriteLine(evt.Data?.Content);
44+
/// if (evt is AssistantMessageEvent assistantMessage)
45+
/// Console.WriteLine(assistantMessage.Data?.Content);
4646
/// });
4747
///
4848
/// // Send a message

dotnet/src/Generated/SessionEvents.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
//
77
// Generated from: @github/copilot/session-events.schema.json
88
// Generated by: scripts/generate-session-types.ts
9-
// Generated at: 2026-01-21T14:22:41.128Z
9+
// Generated at: 2026-01-21T14:50:29.306Z
1010
//
1111
// To update these types:
1212
// 1. Update the schema in copilot-agent-runtime
@@ -924,7 +924,7 @@ public partial class SubagentSelectedData
924924
public required string AgentDisplayName { get; set; }
925925

926926
[JsonPropertyName("tools")]
927-
public required string[]? Tools { get; set; }
927+
public string[]? Tools { get; set; }
928928
}
929929

930930
public partial class HookStartData

dotnet/src/Session.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ namespace GitHub.Copilot.SDK;
3030
/// // Subscribe to events
3131
/// using var subscription = session.On(evt =>
3232
/// {
33-
/// if (evt is AssistantMessageEvent)
33+
/// if (evt is AssistantMessageEvent assistantMessage)
3434
/// {
35-
/// Console.WriteLine($"Assistant: {evt.Data?.Content}");
35+
/// Console.WriteLine($"Assistant: {assistantMessage.Data?.Content}");
3636
/// }
3737
/// });
3838
///

nodejs/scripts/generate-csharp-session-types.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -269,13 +269,15 @@ function generateDataClass(
269269
enumOutput
270270
);
271271

272+
const isNullableType = csharpType.endsWith("?");
272273
if (!isRequired) {
273274
lines.push(
274275
`${indent} [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]`
275276
);
276277
}
277278
lines.push(`${indent} [JsonPropertyName("${propName}")]`);
278-
const requiredModifier = isRequired ? "required " : "";
279+
280+
const requiredModifier = isRequired && !isNullableType ? "required " : "";
279281
lines.push(`${indent} public ${requiredModifier}${csharpType} ${csharpName} { get; set; }`);
280282
lines.push("");
281283
}
@@ -330,7 +332,9 @@ function generateNestedClass(
330332
);
331333
}
332334
lines.push(`${indent} [JsonPropertyName("${propName}")]`);
333-
const requiredModifier = isRequired ? "required " : "";
335+
336+
const isNullableType = csharpType.endsWith("?");
337+
const requiredModifier = isRequired && !isNullableType ? "required " : "";
334338
lines.push(`${indent} public ${requiredModifier}${csharpType} ${csharpName} { get; set; }`);
335339
lines.push("");
336340
}
@@ -361,24 +365,27 @@ function resolvePropertyType(
361365
): string {
362366
// Handle anyOf - simplify to nullable of the non-null type or object
363367
if (propSchema.anyOf) {
368+
const hasNull = propSchema.anyOf.some(
369+
(s) => typeof s === "object" && (s as JSONSchema7).type === "null"
370+
);
364371
const nonNullTypes = propSchema.anyOf.filter(
365372
(s) => typeof s === "object" && (s as JSONSchema7).type !== "null"
366373
);
367374
if (nonNullTypes.length === 1) {
368-
// Simple nullable - recurse with the inner type
375+
// Simple nullable - recurse with the inner type, marking as not required if null is an option
369376
return resolvePropertyType(
370377
nonNullTypes[0] as JSONSchema7,
371378
parentClassName,
372379
propName,
373-
false,
380+
isRequired && !hasNull,
374381
indent,
375382
knownTypes,
376383
nestedClasses,
377384
enumOutput
378385
);
379386
}
380-
// Complex union - use object
381-
return "object";
387+
// Complex union - use object, nullable if null is in the union or property is not required
388+
return (hasNull || !isRequired) ? "object?" : "object";
382389
}
383390

384391
// Handle enum types

0 commit comments

Comments
 (0)