From d82fd624414fbc5ec23751caa18cc1a01b1092ad Mon Sep 17 00:00:00 2001 From: Ron Borysovski Date: Fri, 20 Mar 2026 12:49:10 +0200 Subject: [PATCH 1/3] fix(dotnet): handle unknown session event types gracefully (#881) * fix(dotnet): handle unknown session event types gracefully Add UnknownSessionEvent type and TryFromJson method so that unrecognized event types from newer CLI versions do not crash GetMessagesAsync or real-time event dispatch. * refactor: use IgnoreUnrecognizedTypeDiscriminators per review feedback --- dotnet/src/Generated/SessionEvents.cs | 6 +- dotnet/test/ForwardCompatibilityTests.cs | 100 +++++++++++++++++++++++ scripts/codegen/csharp.ts | 6 +- 3 files changed, 106 insertions(+), 6 deletions(-) create mode 100644 dotnet/test/ForwardCompatibilityTests.cs diff --git a/dotnet/src/Generated/SessionEvents.cs b/dotnet/src/Generated/SessionEvents.cs index 08c6bf5e0..40d2daf22 100644 --- a/dotnet/src/Generated/SessionEvents.cs +++ b/dotnet/src/Generated/SessionEvents.cs @@ -17,7 +17,7 @@ namespace GitHub.Copilot.SDK; [DebuggerDisplay("{DebuggerDisplay,nq}")] [JsonPolymorphic( TypeDiscriminatorPropertyName = "type", - UnknownDerivedTypeHandling = JsonUnknownDerivedTypeHandling.FailSerialization)] + IgnoreUnrecognizedTypeDiscriminators = true)] [JsonDerivedType(typeof(AbortEvent), "abort")] [JsonDerivedType(typeof(AssistantIntentEvent), "assistant.intent")] [JsonDerivedType(typeof(AssistantMessageEvent), "assistant.message")] @@ -79,7 +79,7 @@ namespace GitHub.Copilot.SDK; [JsonDerivedType(typeof(UserInputCompletedEvent), "user_input.completed")] [JsonDerivedType(typeof(UserInputRequestedEvent), "user_input.requested")] [JsonDerivedType(typeof(UserMessageEvent), "user.message")] -public abstract partial class SessionEvent +public partial class SessionEvent { /// Unique event identifier (UUID v4), generated when the event is emitted. [JsonPropertyName("id")] @@ -102,7 +102,7 @@ public abstract partial class SessionEvent /// The event type discriminator. /// [JsonIgnore] - public abstract string Type { get; } + public virtual string Type => "unknown"; /// Deserializes a JSON string into a . public static SessionEvent FromJson(string json) => diff --git a/dotnet/test/ForwardCompatibilityTests.cs b/dotnet/test/ForwardCompatibilityTests.cs new file mode 100644 index 000000000..d3f5b7785 --- /dev/null +++ b/dotnet/test/ForwardCompatibilityTests.cs @@ -0,0 +1,100 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + *--------------------------------------------------------------------------------------------*/ + +using Xunit; + +namespace GitHub.Copilot.SDK.Test; + +/// +/// Tests for forward-compatible handling of unknown session event types. +/// Verifies that the SDK gracefully handles event types introduced by newer CLI versions. +/// +public class ForwardCompatibilityTests +{ + [Fact] + public void FromJson_KnownEventType_DeserializesNormally() + { + var json = """ + { + "id": "00000000-0000-0000-0000-000000000001", + "timestamp": "2026-01-01T00:00:00Z", + "parentId": null, + "type": "user.message", + "data": { + "content": "Hello" + } + } + """; + + var result = SessionEvent.FromJson(json); + + Assert.IsType(result); + Assert.Equal("user.message", result.Type); + } + + [Fact] + public void FromJson_UnknownEventType_ReturnsBaseSessionEvent() + { + var json = """ + { + "id": "12345678-1234-1234-1234-123456789abc", + "timestamp": "2026-06-15T10:30:00Z", + "parentId": "abcdefab-abcd-abcd-abcd-abcdefabcdef", + "type": "future.feature_from_server", + "data": { "key": "value" } + } + """; + + var result = SessionEvent.FromJson(json); + + Assert.IsType(result); + Assert.Equal("unknown", result.Type); + } + + [Fact] + public void FromJson_UnknownEventType_PreservesBaseMetadata() + { + var json = """ + { + "id": "12345678-1234-1234-1234-123456789abc", + "timestamp": "2026-06-15T10:30:00Z", + "parentId": "abcdefab-abcd-abcd-abcd-abcdefabcdef", + "type": "future.feature_from_server", + "data": {} + } + """; + + var result = SessionEvent.FromJson(json); + + Assert.Equal(Guid.Parse("12345678-1234-1234-1234-123456789abc"), result.Id); + Assert.Equal(DateTimeOffset.Parse("2026-06-15T10:30:00Z"), result.Timestamp); + Assert.Equal(Guid.Parse("abcdefab-abcd-abcd-abcd-abcdefabcdef"), result.ParentId); + } + + [Fact] + public void FromJson_MultipleEvents_MixedKnownAndUnknown() + { + var events = new[] + { + """{"id":"00000000-0000-0000-0000-000000000001","timestamp":"2026-01-01T00:00:00Z","parentId":null,"type":"user.message","data":{"content":"Hi"}}""", + """{"id":"00000000-0000-0000-0000-000000000002","timestamp":"2026-01-01T00:00:00Z","parentId":null,"type":"future.unknown_type","data":{}}""", + """{"id":"00000000-0000-0000-0000-000000000003","timestamp":"2026-01-01T00:00:00Z","parentId":null,"type":"user.message","data":{"content":"Bye"}}""", + }; + + var results = events.Select(SessionEvent.FromJson).ToList(); + + Assert.Equal(3, results.Count); + Assert.IsType(results[0]); + Assert.IsType(results[1]); + Assert.IsType(results[2]); + } + + [Fact] + public void SessionEvent_Type_DefaultsToUnknown() + { + var evt = new SessionEvent(); + + Assert.Equal("unknown", evt.Type); + } +} diff --git a/scripts/codegen/csharp.ts b/scripts/codegen/csharp.ts index c44973fb1..a48ed47b6 100644 --- a/scripts/codegen/csharp.ts +++ b/scripts/codegen/csharp.ts @@ -522,11 +522,11 @@ namespace GitHub.Copilot.SDK; lines.push(`/// Provides the base class from which all session events derive.`); lines.push(`/// `); lines.push(`[DebuggerDisplay("{DebuggerDisplay,nq}")]`); - lines.push(`[JsonPolymorphic(`, ` TypeDiscriminatorPropertyName = "type",`, ` UnknownDerivedTypeHandling = JsonUnknownDerivedTypeHandling.FailSerialization)]`); + lines.push(`[JsonPolymorphic(`, ` TypeDiscriminatorPropertyName = "type",`, ` IgnoreUnrecognizedTypeDiscriminators = true)]`); for (const variant of [...variants].sort((a, b) => a.typeName.localeCompare(b.typeName))) { lines.push(`[JsonDerivedType(typeof(${variant.className}), "${variant.typeName}")]`); } - lines.push(`public abstract partial class SessionEvent`, `{`); + lines.push(`public partial class SessionEvent`, `{`); lines.push(...xmlDocComment(baseDesc("id"), " ")); lines.push(` [JsonPropertyName("id")]`, ` public Guid Id { get; set; }`, ""); lines.push(...xmlDocComment(baseDesc("timestamp"), " ")); @@ -536,7 +536,7 @@ namespace GitHub.Copilot.SDK; lines.push(...xmlDocComment(baseDesc("ephemeral"), " ")); lines.push(` [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]`, ` [JsonPropertyName("ephemeral")]`, ` public bool? Ephemeral { get; set; }`, ""); lines.push(` /// `, ` /// The event type discriminator.`, ` /// `); - lines.push(` [JsonIgnore]`, ` public abstract string Type { get; }`, ""); + lines.push(` [JsonIgnore]`, ` public virtual string Type => "unknown";`, ""); lines.push(` /// Deserializes a JSON string into a .`); lines.push(` public static SessionEvent FromJson(string json) =>`, ` JsonSerializer.Deserialize(json, SessionEventsJsonContext.Default.SessionEvent)!;`, ""); lines.push(` /// Serializes this event to a JSON string.`); From a1240966c0dee71cf017b8ca67a91731ea5471f7 Mon Sep 17 00:00:00 2001 From: Mackinnon Buck Date: Fri, 20 Mar 2026 06:18:41 -0700 Subject: [PATCH 2/3] fix: Go codegen enum prefixes and type name reconciliation (#883) * Update @github/copilot to 1.0.10-0 - Updated nodejs and test harness dependencies - Re-ran code generators - Formatted generated code * refactor(go): update handwritten files to use prefixed enum constant names Rename all references to copilot session event type and rpc constants to use the new prefixed naming convention matching the generated code: - copilot.SessionCompactionStart -> copilot.SessionEventTypeSessionCompactionStart - copilot.ExternalToolRequested -> copilot.SessionEventTypeExternalToolRequested - copilot.PermissionRequested -> copilot.SessionEventTypePermissionRequested - copilot.ToolExecutionStart -> copilot.SessionEventTypeToolExecutionStart - copilot.AssistantReasoning -> copilot.SessionEventTypeAssistantReasoning - copilot.Abort -> copilot.SessionEventTypeAbort - rpc.Interactive -> rpc.ModeInteractive - rpc.Plan -> rpc.ModePlan - rpc.Warning -> rpc.LevelWarning - rpc.Error -> rpc.LevelError - rpc.Info -> rpc.LevelInfo (and all other constants listed in the rename) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * fix: Go codegen enum prefixes and type name reconciliation - Add 'mcp' to goInitialisms so toPascalCase produces SessionMCP* matching quicktype - Post-process enum constants to use canonical Go TypeNameValue convention (replaces quicktype's Purple/Fluffy/Tentacled prefixes and unprefixed constants) - Reconcile type names: extract actual quicktype-generated struct names and use them in RPC wrapper code instead of recomputing via toPascalCase - Extract field name mappings from quicktype output to handle keyword-avoidance renames - Update all handwritten Go references to use new prefixed constant names Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * docs: update Go image-input examples to use copilot.AttachmentTypeFile The generated enum constant was renamed from copilot.File to copilot.AttachmentTypeFile to follow Go's TypeNameValue convention. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * fix(codegen): resolve Python type names from quicktype output for acronyms The Python codegen used toPascalCase() to compute type names like SessionMcpListResult, but quicktype generates SessionMCPListResult (uppercase MCP). This caused runtime NameError in Python scenarios. Apply the same approach as go.ts: after quicktype runs, parse the generated output to extract actual class names and build a case-insensitive lookup map. Use resolveType() in emitMethod() and emitRpcWrapper() instead of recomputing names via toPascalCase(). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * fix: update Go E2E tests for agent list and multi-client timeout - TestAgentSelectionRpc: CLI now returns built-in agents, so instead of asserting zero agents, verify no custom agents appear when none configured - TestMultiClient: increase broadcast event timeout from 10s to 30s Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Fix LogAsync compilation error by adding missing url parameter The generated Rpc.LogAsync method added a 'url' parameter between 'ephemeral' and 'cancellationToken', causing a type mismatch when Session.LogAsync passed cancellationToken as the 4th positional arg. Added the 'url' parameter to Session.LogAsync to match the generated Rpc method signature and pass it through correctly. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * fix: address review comments - valuePascal initialisms, Phase 2 regex, add pr/ado - valuePascal now uses goInitialisms so 'url' -> 'URL', 'mcp' -> 'MCP', etc. - Phase 2 regex uses [\s\S]*? to match multi-line func bodies - Added 'pr' and 'ado' to goInitialisms Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Fix Python E2E agent list test for built-in agents The CLI now returns built-in/default agents even when no custom agents are configured. Update the assertion to verify no custom test agent names appear in the list, rather than asserting the list is empty. Matches the pattern used in the Go E2E test. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Skip multi-client broadcast test across Go, Python, and C# CLI 1.0.7 no longer delivers broadcast external_tool events to secondary clients. Skip the 'both clients see tool request and completion events' test in all three languages with a clear note. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Revert multi-client broadcast test skips for CLI 1.0.7 Remove the t.Skip/pytest.skip/Fact(Skip=...) additions that were disabling the multi-client broadcast tests across Go, Python, and C#. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * fix: remove mcp/pr/ado from goInitialisms to avoid SessionRpc.MCP rename resolveType() already handles type name reconciliation from quicktype output, so these initialisms aren't needed and would cause an unnecessary breaking change to the SessionRpc.Mcp field name. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Another Go codegen fix after rebase * Regenerate code * Python formatting Co-Authored-By: Copilot <223556219+Copilot@users.noreply.github.com> * Type name update Co-Authored-By: Copilot <223556219+Copilot@users.noreply.github.com> * Fix Python codegen Co-Authored-By: Copilot <223556219+Copilot@users.noreply.github.com> * fix: update copilot.Blob to copilot.AttachmentTypeBlob and fix Python Optional codegen - Update Go E2E test, README, and docs to use prefixed enum constant - Fix Python codegen modernizePython to handle deeply nested Optional types - Fix ruff formatting in e2e/test_multi_client.py Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: Steve Sanderson --- docs/features/image-input.md | 8 +- dotnet/src/Generated/Rpc.cs | 742 +++++++- dotnet/src/Generated/SessionEvents.cs | 585 ++++++- dotnet/src/Session.cs | 5 +- go/README.md | 2 +- go/generated_session_events.go | 476 ++++-- go/internal/e2e/agent_and_compact_rpc_test.go | 11 +- go/internal/e2e/compaction_test.go | 6 +- go/internal/e2e/multi_client_test.go | 26 +- go/internal/e2e/permissions_test.go | 4 +- go/internal/e2e/rpc_test.go | 12 +- go/internal/e2e/session_test.go | 22 +- go/internal/e2e/testharness/helper.go | 2 +- go/rpc/generated_rpc.go | 619 ++++++- go/samples/chat.go | 4 +- go/session.go | 20 +- nodejs/package-lock.json | 56 +- nodejs/package.json | 2 +- nodejs/samples/package-lock.json | 2 +- nodejs/src/generated/rpc.ts | 477 ++++++ nodejs/src/generated/session-events.ts | 426 ++++- python/copilot/generated/rpc.py | 1496 ++++++++++++++--- python/copilot/generated/session_events.py | 439 ++++- python/e2e/test_agent_and_compact_rpc.py | 10 +- scripts/codegen/go.ts | 143 +- scripts/codegen/python.ts | 57 +- test/harness/package-lock.json | 56 +- test/harness/package.json | 2 +- test/scenarios/prompts/attachments/README.md | 2 +- 29 files changed, 5053 insertions(+), 659 deletions(-) diff --git a/docs/features/image-input.md b/docs/features/image-input.md index acec80d4a..8295b83d7 100644 --- a/docs/features/image-input.md +++ b/docs/features/image-input.md @@ -121,7 +121,7 @@ func main() { Prompt: "Describe what you see in this image", Attachments: []copilot.Attachment{ { - Type: copilot.File, + Type: copilot.AttachmentTypeFile, Path: &path, }, }, @@ -147,7 +147,7 @@ session.Send(ctx, copilot.MessageOptions{ Prompt: "Describe what you see in this image", Attachments: []copilot.Attachment{ { - Type: copilot.File, + Type: copilot.AttachmentTypeFile, Path: &path, }, }, @@ -315,7 +315,7 @@ func main() { Prompt: "Describe what you see in this image", Attachments: []copilot.Attachment{ { - Type: copilot.Blob, + Type: copilot.AttachmentTypeBlob, Data: &base64ImageData, MIMEType: &mimeType, DisplayName: &displayName, @@ -333,7 +333,7 @@ session.Send(ctx, copilot.MessageOptions{ Prompt: "Describe what you see in this image", Attachments: []copilot.Attachment{ { - Type: copilot.Blob, + Type: copilot.AttachmentTypeBlob, Data: &base64ImageData, // base64-encoded string MIMEType: &mimeType, DisplayName: &displayName, diff --git a/dotnet/src/Generated/Rpc.cs b/dotnet/src/Generated/Rpc.cs index 6fc593c12..fabe4817e 100644 --- a/dotnet/src/Generated/Rpc.cs +++ b/dotnet/src/Generated/Rpc.cs @@ -245,6 +245,10 @@ internal class SessionLogRequest /// When true, the message is transient and not persisted to the session event log on disk. [JsonPropertyName("ephemeral")] public bool? Ephemeral { get; set; } + + /// Optional URL the user can open in their browser for more details. + [JsonPropertyName("url")] + public string? Url { get; set; } } /// RPC data type for SessionModelGetCurrent operations. @@ -577,6 +581,347 @@ internal class SessionAgentDeselectRequest public string SessionId { get; set; } = string.Empty; } +/// RPC data type for SessionAgentReload operations. +[Experimental(Diagnostics.Experimental)] +public class SessionAgentReloadResult +{ + /// Reloaded custom agents. + [JsonPropertyName("agents")] + public List Agents { get => field ??= []; set; } +} + +/// RPC data type for SessionAgentReload operations. +[Experimental(Diagnostics.Experimental)] +internal class SessionAgentReloadRequest +{ + /// Target session identifier. + [JsonPropertyName("sessionId")] + public string SessionId { get; set; } = string.Empty; +} + +/// RPC data type for Skill operations. +public class Skill +{ + /// Unique identifier for the skill. + [JsonPropertyName("name")] + public string Name { get; set; } = string.Empty; + + /// Description of what the skill does. + [JsonPropertyName("description")] + public string Description { get; set; } = string.Empty; + + /// Source location type (e.g., project, personal, plugin). + [JsonPropertyName("source")] + public string Source { get; set; } = string.Empty; + + /// Whether the skill can be invoked by the user as a slash command. + [JsonPropertyName("userInvocable")] + public bool UserInvocable { get; set; } + + /// Whether the skill is currently enabled. + [JsonPropertyName("enabled")] + public bool Enabled { get; set; } + + /// Absolute path to the skill file. + [JsonPropertyName("path")] + public string? Path { get; set; } +} + +/// RPC data type for SessionSkillsList operations. +[Experimental(Diagnostics.Experimental)] +public class SessionSkillsListResult +{ + /// Available skills. + [JsonPropertyName("skills")] + public List Skills { get => field ??= []; set; } +} + +/// RPC data type for SessionSkillsList operations. +[Experimental(Diagnostics.Experimental)] +internal class SessionSkillsListRequest +{ + /// Target session identifier. + [JsonPropertyName("sessionId")] + public string SessionId { get; set; } = string.Empty; +} + +/// RPC data type for SessionSkillsEnable operations. +[Experimental(Diagnostics.Experimental)] +public class SessionSkillsEnableResult +{ +} + +/// RPC data type for SessionSkillsEnable operations. +[Experimental(Diagnostics.Experimental)] +internal class SessionSkillsEnableRequest +{ + /// Target session identifier. + [JsonPropertyName("sessionId")] + public string SessionId { get; set; } = string.Empty; + + /// Name of the skill to enable. + [JsonPropertyName("name")] + public string Name { get; set; } = string.Empty; +} + +/// RPC data type for SessionSkillsDisable operations. +[Experimental(Diagnostics.Experimental)] +public class SessionSkillsDisableResult +{ +} + +/// RPC data type for SessionSkillsDisable operations. +[Experimental(Diagnostics.Experimental)] +internal class SessionSkillsDisableRequest +{ + /// Target session identifier. + [JsonPropertyName("sessionId")] + public string SessionId { get; set; } = string.Empty; + + /// Name of the skill to disable. + [JsonPropertyName("name")] + public string Name { get; set; } = string.Empty; +} + +/// RPC data type for SessionSkillsReload operations. +[Experimental(Diagnostics.Experimental)] +public class SessionSkillsReloadResult +{ +} + +/// RPC data type for SessionSkillsReload operations. +[Experimental(Diagnostics.Experimental)] +internal class SessionSkillsReloadRequest +{ + /// Target session identifier. + [JsonPropertyName("sessionId")] + public string SessionId { get; set; } = string.Empty; +} + +/// RPC data type for Server operations. +public class Server +{ + /// Server name (config key). + [JsonPropertyName("name")] + public string Name { get; set; } = string.Empty; + + /// Connection status: connected, failed, pending, disabled, or not_configured. + [JsonPropertyName("status")] + public ServerStatus Status { get; set; } + + /// Configuration source: user, workspace, plugin, or builtin. + [JsonPropertyName("source")] + public string? Source { get; set; } + + /// Error message if the server failed to connect. + [JsonPropertyName("error")] + public string? Error { get; set; } +} + +/// RPC data type for SessionMcpList operations. +[Experimental(Diagnostics.Experimental)] +public class SessionMcpListResult +{ + /// Configured MCP servers. + [JsonPropertyName("servers")] + public List Servers { get => field ??= []; set; } +} + +/// RPC data type for SessionMcpList operations. +[Experimental(Diagnostics.Experimental)] +internal class SessionMcpListRequest +{ + /// Target session identifier. + [JsonPropertyName("sessionId")] + public string SessionId { get; set; } = string.Empty; +} + +/// RPC data type for SessionMcpEnable operations. +[Experimental(Diagnostics.Experimental)] +public class SessionMcpEnableResult +{ +} + +/// RPC data type for SessionMcpEnable operations. +[Experimental(Diagnostics.Experimental)] +internal class SessionMcpEnableRequest +{ + /// Target session identifier. + [JsonPropertyName("sessionId")] + public string SessionId { get; set; } = string.Empty; + + /// Name of the MCP server to enable. + [JsonPropertyName("serverName")] + public string ServerName { get; set; } = string.Empty; +} + +/// RPC data type for SessionMcpDisable operations. +[Experimental(Diagnostics.Experimental)] +public class SessionMcpDisableResult +{ +} + +/// RPC data type for SessionMcpDisable operations. +[Experimental(Diagnostics.Experimental)] +internal class SessionMcpDisableRequest +{ + /// Target session identifier. + [JsonPropertyName("sessionId")] + public string SessionId { get; set; } = string.Empty; + + /// Name of the MCP server to disable. + [JsonPropertyName("serverName")] + public string ServerName { get; set; } = string.Empty; +} + +/// RPC data type for SessionMcpReload operations. +[Experimental(Diagnostics.Experimental)] +public class SessionMcpReloadResult +{ +} + +/// RPC data type for SessionMcpReload operations. +[Experimental(Diagnostics.Experimental)] +internal class SessionMcpReloadRequest +{ + /// Target session identifier. + [JsonPropertyName("sessionId")] + public string SessionId { get; set; } = string.Empty; +} + +/// RPC data type for Plugin operations. +public class Plugin +{ + /// Plugin name. + [JsonPropertyName("name")] + public string Name { get; set; } = string.Empty; + + /// Marketplace the plugin came from. + [JsonPropertyName("marketplace")] + public string Marketplace { get; set; } = string.Empty; + + /// Installed version. + [JsonPropertyName("version")] + public string? Version { get; set; } + + /// Whether the plugin is currently enabled. + [JsonPropertyName("enabled")] + public bool Enabled { get; set; } +} + +/// RPC data type for SessionPluginsList operations. +[Experimental(Diagnostics.Experimental)] +public class SessionPluginsListResult +{ + /// Installed plugins. + [JsonPropertyName("plugins")] + public List Plugins { get => field ??= []; set; } +} + +/// RPC data type for SessionPluginsList operations. +[Experimental(Diagnostics.Experimental)] +internal class SessionPluginsListRequest +{ + /// Target session identifier. + [JsonPropertyName("sessionId")] + public string SessionId { get; set; } = string.Empty; +} + +/// RPC data type for Extension operations. +public class Extension +{ + /// Source-qualified ID (e.g., 'project:my-ext', 'user:auth-helper'). + [JsonPropertyName("id")] + public string Id { get; set; } = string.Empty; + + /// Extension name (directory name). + [JsonPropertyName("name")] + public string Name { get; set; } = string.Empty; + + /// Discovery source: project (.github/extensions/) or user (~/.copilot/extensions/). + [JsonPropertyName("source")] + public ExtensionSource Source { get; set; } + + /// Current status: running, disabled, failed, or starting. + [JsonPropertyName("status")] + public ExtensionStatus Status { get; set; } + + /// Process ID if the extension is running. + [JsonPropertyName("pid")] + public double? Pid { get; set; } +} + +/// RPC data type for SessionExtensionsList operations. +[Experimental(Diagnostics.Experimental)] +public class SessionExtensionsListResult +{ + /// Discovered extensions and their current status. + [JsonPropertyName("extensions")] + public List Extensions { get => field ??= []; set; } +} + +/// RPC data type for SessionExtensionsList operations. +[Experimental(Diagnostics.Experimental)] +internal class SessionExtensionsListRequest +{ + /// Target session identifier. + [JsonPropertyName("sessionId")] + public string SessionId { get; set; } = string.Empty; +} + +/// RPC data type for SessionExtensionsEnable operations. +[Experimental(Diagnostics.Experimental)] +public class SessionExtensionsEnableResult +{ +} + +/// RPC data type for SessionExtensionsEnable operations. +[Experimental(Diagnostics.Experimental)] +internal class SessionExtensionsEnableRequest +{ + /// Target session identifier. + [JsonPropertyName("sessionId")] + public string SessionId { get; set; } = string.Empty; + + /// Source-qualified extension ID to enable. + [JsonPropertyName("id")] + public string Id { get; set; } = string.Empty; +} + +/// RPC data type for SessionExtensionsDisable operations. +[Experimental(Diagnostics.Experimental)] +public class SessionExtensionsDisableResult +{ +} + +/// RPC data type for SessionExtensionsDisable operations. +[Experimental(Diagnostics.Experimental)] +internal class SessionExtensionsDisableRequest +{ + /// Target session identifier. + [JsonPropertyName("sessionId")] + public string SessionId { get; set; } = string.Empty; + + /// Source-qualified extension ID to disable. + [JsonPropertyName("id")] + public string Id { get; set; } = string.Empty; +} + +/// RPC data type for SessionExtensionsReload operations. +[Experimental(Diagnostics.Experimental)] +public class SessionExtensionsReloadResult +{ +} + +/// RPC data type for SessionExtensionsReload operations. +[Experimental(Diagnostics.Experimental)] +internal class SessionExtensionsReloadRequest +{ + /// Target session identifier. + [JsonPropertyName("sessionId")] + public string SessionId { get; set; } = string.Empty; +} + /// RPC data type for SessionCompactionCompact operations. [Experimental(Diagnostics.Experimental)] public class SessionCompactionCompactResult @@ -631,6 +976,74 @@ internal class SessionToolsHandlePendingToolCallRequest public string? Error { get; set; } } +/// RPC data type for SessionCommandsHandlePendingCommand operations. +public class SessionCommandsHandlePendingCommandResult +{ + /// Gets or sets the success value. + [JsonPropertyName("success")] + public bool Success { get; set; } +} + +/// RPC data type for SessionCommandsHandlePendingCommand operations. +internal class SessionCommandsHandlePendingCommandRequest +{ + /// Target session identifier. + [JsonPropertyName("sessionId")] + public string SessionId { get; set; } = string.Empty; + + /// Request ID from the command invocation event. + [JsonPropertyName("requestId")] + public string RequestId { get; set; } = string.Empty; + + /// Error message if the command handler failed. + [JsonPropertyName("error")] + public string? Error { get; set; } +} + +/// RPC data type for SessionUiElicitation operations. +public class SessionUiElicitationResult +{ + /// The user's response: accept (submitted), decline (rejected), or cancel (dismissed). + [JsonPropertyName("action")] + public SessionUiElicitationResultAction Action { get; set; } + + /// The form values submitted by the user (present when action is 'accept'). + [JsonPropertyName("content")] + public Dictionary? Content { get; set; } +} + +/// JSON Schema describing the form fields to present to the user. +public class SessionUiElicitationRequestRequestedSchema +{ + /// Schema type indicator (always 'object'). + [JsonPropertyName("type")] + public string Type { get; set; } = string.Empty; + + /// Form field definitions, keyed by field name. + [JsonPropertyName("properties")] + public Dictionary Properties { get => field ??= []; set; } + + /// List of required field names. + [JsonPropertyName("required")] + public List? Required { get; set; } +} + +/// RPC data type for SessionUiElicitation operations. +internal class SessionUiElicitationRequest +{ + /// Target session identifier. + [JsonPropertyName("sessionId")] + public string SessionId { get; set; } = string.Empty; + + /// Message describing what information is needed from the user. + [JsonPropertyName("message")] + public string Message { get; set; } = string.Empty; + + /// JSON Schema describing the form fields to present to the user. + [JsonPropertyName("requestedSchema")] + public SessionUiElicitationRequestRequestedSchema RequestedSchema { get => field ??= new(); set; } +} + /// RPC data type for SessionPermissionsHandlePendingPermissionRequest operations. public class SessionPermissionsHandlePendingPermissionRequestResult { @@ -739,6 +1152,76 @@ public enum SessionModeGetResultMode } +/// Connection status: connected, failed, pending, disabled, or not_configured. +[JsonConverter(typeof(JsonStringEnumConverter))] +public enum ServerStatus +{ + /// The connected variant. + [JsonStringEnumMemberName("connected")] + Connected, + /// The failed variant. + [JsonStringEnumMemberName("failed")] + Failed, + /// The pending variant. + [JsonStringEnumMemberName("pending")] + Pending, + /// The disabled variant. + [JsonStringEnumMemberName("disabled")] + Disabled, + /// The not_configured variant. + [JsonStringEnumMemberName("not_configured")] + NotConfigured, +} + + +/// Discovery source: project (.github/extensions/) or user (~/.copilot/extensions/). +[JsonConverter(typeof(JsonStringEnumConverter))] +public enum ExtensionSource +{ + /// The project variant. + [JsonStringEnumMemberName("project")] + Project, + /// The user variant. + [JsonStringEnumMemberName("user")] + User, +} + + +/// Current status: running, disabled, failed, or starting. +[JsonConverter(typeof(JsonStringEnumConverter))] +public enum ExtensionStatus +{ + /// The running variant. + [JsonStringEnumMemberName("running")] + Running, + /// The disabled variant. + [JsonStringEnumMemberName("disabled")] + Disabled, + /// The failed variant. + [JsonStringEnumMemberName("failed")] + Failed, + /// The starting variant. + [JsonStringEnumMemberName("starting")] + Starting, +} + + +/// The user's response: accept (submitted), decline (rejected), or cancel (dismissed). +[JsonConverter(typeof(JsonStringEnumConverter))] +public enum SessionUiElicitationResultAction +{ + /// The accept variant. + [JsonStringEnumMemberName("accept")] + Accept, + /// The decline variant. + [JsonStringEnumMemberName("decline")] + Decline, + /// The cancel variant. + [JsonStringEnumMemberName("cancel")] + Cancel, +} + + /// Signal to send (default: SIGTERM). [JsonConverter(typeof(JsonStringEnumConverter))] public enum SessionShellKillRequestSignal @@ -853,8 +1336,14 @@ internal SessionRpc(JsonRpc rpc, string sessionId) Workspace = new WorkspaceApi(rpc, sessionId); Fleet = new FleetApi(rpc, sessionId); Agent = new AgentApi(rpc, sessionId); + Skills = new SkillsApi(rpc, sessionId); + Mcp = new McpApi(rpc, sessionId); + Plugins = new PluginsApi(rpc, sessionId); + Extensions = new ExtensionsApi(rpc, sessionId); Compaction = new CompactionApi(rpc, sessionId); Tools = new ToolsApi(rpc, sessionId); + Commands = new CommandsApi(rpc, sessionId); + Ui = new UiApi(rpc, sessionId); Permissions = new PermissionsApi(rpc, sessionId); Shell = new ShellApi(rpc, sessionId); } @@ -877,12 +1366,30 @@ internal SessionRpc(JsonRpc rpc, string sessionId) /// Agent APIs. public AgentApi Agent { get; } + /// Skills APIs. + public SkillsApi Skills { get; } + + /// Mcp APIs. + public McpApi Mcp { get; } + + /// Plugins APIs. + public PluginsApi Plugins { get; } + + /// Extensions APIs. + public ExtensionsApi Extensions { get; } + /// Compaction APIs. public CompactionApi Compaction { get; } /// Tools APIs. public ToolsApi Tools { get; } + /// Commands APIs. + public CommandsApi Commands { get; } + + /// Ui APIs. + public UiApi Ui { get; } + /// Permissions APIs. public PermissionsApi Permissions { get; } @@ -890,9 +1397,9 @@ internal SessionRpc(JsonRpc rpc, string sessionId) public ShellApi Shell { get; } /// Calls "session.log". - public async Task LogAsync(string message, SessionLogRequestLevel? level = null, bool? ephemeral = null, CancellationToken cancellationToken = default) + public async Task LogAsync(string message, SessionLogRequestLevel? level = null, bool? ephemeral = null, string? url = null, CancellationToken cancellationToken = default) { - var request = new SessionLogRequest { SessionId = _sessionId, Message = message, Level = level, Ephemeral = ephemeral }; + var request = new SessionLogRequest { SessionId = _sessionId, Message = message, Level = level, Ephemeral = ephemeral, Url = url }; return await CopilotClient.InvokeRpcAsync(_rpc, "session.log", [request], cancellationToken); } } @@ -1080,6 +1587,160 @@ public async Task DeselectAsync(CancellationToken ca var request = new SessionAgentDeselectRequest { SessionId = _sessionId }; return await CopilotClient.InvokeRpcAsync(_rpc, "session.agent.deselect", [request], cancellationToken); } + + /// Calls "session.agent.reload". + public async Task ReloadAsync(CancellationToken cancellationToken = default) + { + var request = new SessionAgentReloadRequest { SessionId = _sessionId }; + return await CopilotClient.InvokeRpcAsync(_rpc, "session.agent.reload", [request], cancellationToken); + } +} + +/// Provides session-scoped Skills APIs. +[Experimental(Diagnostics.Experimental)] +public class SkillsApi +{ + private readonly JsonRpc _rpc; + private readonly string _sessionId; + + internal SkillsApi(JsonRpc rpc, string sessionId) + { + _rpc = rpc; + _sessionId = sessionId; + } + + /// Calls "session.skills.list". + public async Task ListAsync(CancellationToken cancellationToken = default) + { + var request = new SessionSkillsListRequest { SessionId = _sessionId }; + return await CopilotClient.InvokeRpcAsync(_rpc, "session.skills.list", [request], cancellationToken); + } + + /// Calls "session.skills.enable". + public async Task EnableAsync(string name, CancellationToken cancellationToken = default) + { + var request = new SessionSkillsEnableRequest { SessionId = _sessionId, Name = name }; + return await CopilotClient.InvokeRpcAsync(_rpc, "session.skills.enable", [request], cancellationToken); + } + + /// Calls "session.skills.disable". + public async Task DisableAsync(string name, CancellationToken cancellationToken = default) + { + var request = new SessionSkillsDisableRequest { SessionId = _sessionId, Name = name }; + return await CopilotClient.InvokeRpcAsync(_rpc, "session.skills.disable", [request], cancellationToken); + } + + /// Calls "session.skills.reload". + public async Task ReloadAsync(CancellationToken cancellationToken = default) + { + var request = new SessionSkillsReloadRequest { SessionId = _sessionId }; + return await CopilotClient.InvokeRpcAsync(_rpc, "session.skills.reload", [request], cancellationToken); + } +} + +/// Provides session-scoped Mcp APIs. +[Experimental(Diagnostics.Experimental)] +public class McpApi +{ + private readonly JsonRpc _rpc; + private readonly string _sessionId; + + internal McpApi(JsonRpc rpc, string sessionId) + { + _rpc = rpc; + _sessionId = sessionId; + } + + /// Calls "session.mcp.list". + public async Task ListAsync(CancellationToken cancellationToken = default) + { + var request = new SessionMcpListRequest { SessionId = _sessionId }; + return await CopilotClient.InvokeRpcAsync(_rpc, "session.mcp.list", [request], cancellationToken); + } + + /// Calls "session.mcp.enable". + public async Task EnableAsync(string serverName, CancellationToken cancellationToken = default) + { + var request = new SessionMcpEnableRequest { SessionId = _sessionId, ServerName = serverName }; + return await CopilotClient.InvokeRpcAsync(_rpc, "session.mcp.enable", [request], cancellationToken); + } + + /// Calls "session.mcp.disable". + public async Task DisableAsync(string serverName, CancellationToken cancellationToken = default) + { + var request = new SessionMcpDisableRequest { SessionId = _sessionId, ServerName = serverName }; + return await CopilotClient.InvokeRpcAsync(_rpc, "session.mcp.disable", [request], cancellationToken); + } + + /// Calls "session.mcp.reload". + public async Task ReloadAsync(CancellationToken cancellationToken = default) + { + var request = new SessionMcpReloadRequest { SessionId = _sessionId }; + return await CopilotClient.InvokeRpcAsync(_rpc, "session.mcp.reload", [request], cancellationToken); + } +} + +/// Provides session-scoped Plugins APIs. +[Experimental(Diagnostics.Experimental)] +public class PluginsApi +{ + private readonly JsonRpc _rpc; + private readonly string _sessionId; + + internal PluginsApi(JsonRpc rpc, string sessionId) + { + _rpc = rpc; + _sessionId = sessionId; + } + + /// Calls "session.plugins.list". + public async Task ListAsync(CancellationToken cancellationToken = default) + { + var request = new SessionPluginsListRequest { SessionId = _sessionId }; + return await CopilotClient.InvokeRpcAsync(_rpc, "session.plugins.list", [request], cancellationToken); + } +} + +/// Provides session-scoped Extensions APIs. +[Experimental(Diagnostics.Experimental)] +public class ExtensionsApi +{ + private readonly JsonRpc _rpc; + private readonly string _sessionId; + + internal ExtensionsApi(JsonRpc rpc, string sessionId) + { + _rpc = rpc; + _sessionId = sessionId; + } + + /// Calls "session.extensions.list". + public async Task ListAsync(CancellationToken cancellationToken = default) + { + var request = new SessionExtensionsListRequest { SessionId = _sessionId }; + return await CopilotClient.InvokeRpcAsync(_rpc, "session.extensions.list", [request], cancellationToken); + } + + /// Calls "session.extensions.enable". + public async Task EnableAsync(string id, CancellationToken cancellationToken = default) + { + var request = new SessionExtensionsEnableRequest { SessionId = _sessionId, Id = id }; + return await CopilotClient.InvokeRpcAsync(_rpc, "session.extensions.enable", [request], cancellationToken); + } + + /// Calls "session.extensions.disable". + public async Task DisableAsync(string id, CancellationToken cancellationToken = default) + { + var request = new SessionExtensionsDisableRequest { SessionId = _sessionId, Id = id }; + return await CopilotClient.InvokeRpcAsync(_rpc, "session.extensions.disable", [request], cancellationToken); + } + + /// Calls "session.extensions.reload". + public async Task ReloadAsync(CancellationToken cancellationToken = default) + { + var request = new SessionExtensionsReloadRequest { SessionId = _sessionId }; + return await CopilotClient.InvokeRpcAsync(_rpc, "session.extensions.reload", [request], cancellationToken); + } } /// Provides session-scoped Compaction APIs. @@ -1123,6 +1784,46 @@ public async Task HandlePendingToolCall } } +/// Provides session-scoped Commands APIs. +public class CommandsApi +{ + private readonly JsonRpc _rpc; + private readonly string _sessionId; + + internal CommandsApi(JsonRpc rpc, string sessionId) + { + _rpc = rpc; + _sessionId = sessionId; + } + + /// Calls "session.commands.handlePendingCommand". + public async Task HandlePendingCommandAsync(string requestId, string? error = null, CancellationToken cancellationToken = default) + { + var request = new SessionCommandsHandlePendingCommandRequest { SessionId = _sessionId, RequestId = requestId, Error = error }; + return await CopilotClient.InvokeRpcAsync(_rpc, "session.commands.handlePendingCommand", [request], cancellationToken); + } +} + +/// Provides session-scoped Ui APIs. +public class UiApi +{ + private readonly JsonRpc _rpc; + private readonly string _sessionId; + + internal UiApi(JsonRpc rpc, string sessionId) + { + _rpc = rpc; + _sessionId = sessionId; + } + + /// Calls "session.ui.elicitation". + public async Task ElicitationAsync(string message, SessionUiElicitationRequestRequestedSchema requestedSchema, CancellationToken cancellationToken = default) + { + var request = new SessionUiElicitationRequest { SessionId = _sessionId, Message = message, RequestedSchema = requestedSchema }; + return await CopilotClient.InvokeRpcAsync(_rpc, "session.ui.elicitation", [request], cancellationToken); + } +} + /// Provides session-scoped Permissions APIs. public class PermissionsApi { @@ -1177,6 +1878,7 @@ public async Task KillAsync(string processId, SessionShe [JsonSerializable(typeof(AccountGetQuotaResult))] [JsonSerializable(typeof(AccountGetQuotaResultQuotaSnapshotsValue))] [JsonSerializable(typeof(Agent))] +[JsonSerializable(typeof(Extension))] [JsonSerializable(typeof(Model))] [JsonSerializable(typeof(ModelBilling))] [JsonSerializable(typeof(ModelCapabilities))] @@ -1186,6 +1888,8 @@ public async Task KillAsync(string processId, SessionShe [JsonSerializable(typeof(ModelsListResult))] [JsonSerializable(typeof(PingRequest))] [JsonSerializable(typeof(PingResult))] +[JsonSerializable(typeof(Plugin))] +[JsonSerializable(typeof(Server))] [JsonSerializable(typeof(SessionAgentDeselectRequest))] [JsonSerializable(typeof(SessionAgentDeselectResult))] [JsonSerializable(typeof(SessionAgentGetCurrentRequest))] @@ -1193,15 +1897,35 @@ public async Task KillAsync(string processId, SessionShe [JsonSerializable(typeof(SessionAgentGetCurrentResultAgent))] [JsonSerializable(typeof(SessionAgentListRequest))] [JsonSerializable(typeof(SessionAgentListResult))] +[JsonSerializable(typeof(SessionAgentReloadRequest))] +[JsonSerializable(typeof(SessionAgentReloadResult))] [JsonSerializable(typeof(SessionAgentSelectRequest))] [JsonSerializable(typeof(SessionAgentSelectResult))] [JsonSerializable(typeof(SessionAgentSelectResultAgent))] +[JsonSerializable(typeof(SessionCommandsHandlePendingCommandRequest))] +[JsonSerializable(typeof(SessionCommandsHandlePendingCommandResult))] [JsonSerializable(typeof(SessionCompactionCompactRequest))] [JsonSerializable(typeof(SessionCompactionCompactResult))] +[JsonSerializable(typeof(SessionExtensionsDisableRequest))] +[JsonSerializable(typeof(SessionExtensionsDisableResult))] +[JsonSerializable(typeof(SessionExtensionsEnableRequest))] +[JsonSerializable(typeof(SessionExtensionsEnableResult))] +[JsonSerializable(typeof(SessionExtensionsListRequest))] +[JsonSerializable(typeof(SessionExtensionsListResult))] +[JsonSerializable(typeof(SessionExtensionsReloadRequest))] +[JsonSerializable(typeof(SessionExtensionsReloadResult))] [JsonSerializable(typeof(SessionFleetStartRequest))] [JsonSerializable(typeof(SessionFleetStartResult))] [JsonSerializable(typeof(SessionLogRequest))] [JsonSerializable(typeof(SessionLogResult))] +[JsonSerializable(typeof(SessionMcpDisableRequest))] +[JsonSerializable(typeof(SessionMcpDisableResult))] +[JsonSerializable(typeof(SessionMcpEnableRequest))] +[JsonSerializable(typeof(SessionMcpEnableResult))] +[JsonSerializable(typeof(SessionMcpListRequest))] +[JsonSerializable(typeof(SessionMcpListResult))] +[JsonSerializable(typeof(SessionMcpReloadRequest))] +[JsonSerializable(typeof(SessionMcpReloadResult))] [JsonSerializable(typeof(SessionModeGetRequest))] [JsonSerializable(typeof(SessionModeGetResult))] [JsonSerializable(typeof(SessionModeSetRequest))] @@ -1218,18 +1942,32 @@ public async Task KillAsync(string processId, SessionShe [JsonSerializable(typeof(SessionPlanReadResult))] [JsonSerializable(typeof(SessionPlanUpdateRequest))] [JsonSerializable(typeof(SessionPlanUpdateResult))] +[JsonSerializable(typeof(SessionPluginsListRequest))] +[JsonSerializable(typeof(SessionPluginsListResult))] [JsonSerializable(typeof(SessionShellExecRequest))] [JsonSerializable(typeof(SessionShellExecResult))] [JsonSerializable(typeof(SessionShellKillRequest))] [JsonSerializable(typeof(SessionShellKillResult))] +[JsonSerializable(typeof(SessionSkillsDisableRequest))] +[JsonSerializable(typeof(SessionSkillsDisableResult))] +[JsonSerializable(typeof(SessionSkillsEnableRequest))] +[JsonSerializable(typeof(SessionSkillsEnableResult))] +[JsonSerializable(typeof(SessionSkillsListRequest))] +[JsonSerializable(typeof(SessionSkillsListResult))] +[JsonSerializable(typeof(SessionSkillsReloadRequest))] +[JsonSerializable(typeof(SessionSkillsReloadResult))] [JsonSerializable(typeof(SessionToolsHandlePendingToolCallRequest))] [JsonSerializable(typeof(SessionToolsHandlePendingToolCallResult))] +[JsonSerializable(typeof(SessionUiElicitationRequest))] +[JsonSerializable(typeof(SessionUiElicitationRequestRequestedSchema))] +[JsonSerializable(typeof(SessionUiElicitationResult))] [JsonSerializable(typeof(SessionWorkspaceCreateFileRequest))] [JsonSerializable(typeof(SessionWorkspaceCreateFileResult))] [JsonSerializable(typeof(SessionWorkspaceListFilesRequest))] [JsonSerializable(typeof(SessionWorkspaceListFilesResult))] [JsonSerializable(typeof(SessionWorkspaceReadFileRequest))] [JsonSerializable(typeof(SessionWorkspaceReadFileResult))] +[JsonSerializable(typeof(Skill))] [JsonSerializable(typeof(Tool))] [JsonSerializable(typeof(ToolsListRequest))] [JsonSerializable(typeof(ToolsListResult))] diff --git a/dotnet/src/Generated/SessionEvents.cs b/dotnet/src/Generated/SessionEvents.cs index 40d2daf22..2821052d0 100644 --- a/dotnet/src/Generated/SessionEvents.cs +++ b/dotnet/src/Generated/SessionEvents.cs @@ -29,7 +29,9 @@ namespace GitHub.Copilot.SDK; [JsonDerivedType(typeof(AssistantTurnStartEvent), "assistant.turn_start")] [JsonDerivedType(typeof(AssistantUsageEvent), "assistant.usage")] [JsonDerivedType(typeof(CommandCompletedEvent), "command.completed")] +[JsonDerivedType(typeof(CommandExecuteEvent), "command.execute")] [JsonDerivedType(typeof(CommandQueuedEvent), "command.queued")] +[JsonDerivedType(typeof(CommandsChangedEvent), "commands.changed")] [JsonDerivedType(typeof(ElicitationCompletedEvent), "elicitation.completed")] [JsonDerivedType(typeof(ElicitationRequestedEvent), "elicitation.requested")] [JsonDerivedType(typeof(ExitPlanModeCompletedEvent), "exit_plan_mode.completed")] @@ -38,6 +40,8 @@ namespace GitHub.Copilot.SDK; [JsonDerivedType(typeof(ExternalToolRequestedEvent), "external_tool.requested")] [JsonDerivedType(typeof(HookEndEvent), "hook.end")] [JsonDerivedType(typeof(HookStartEvent), "hook.start")] +[JsonDerivedType(typeof(McpOauthCompletedEvent), "mcp.oauth_completed")] +[JsonDerivedType(typeof(McpOauthRequiredEvent), "mcp.oauth_required")] [JsonDerivedType(typeof(PendingMessagesModifiedEvent), "pending_messages.modified")] [JsonDerivedType(typeof(PermissionCompletedEvent), "permission.completed")] [JsonDerivedType(typeof(PermissionRequestedEvent), "permission.requested")] @@ -46,14 +50,18 @@ namespace GitHub.Copilot.SDK; [JsonDerivedType(typeof(SessionCompactionStartEvent), "session.compaction_start")] [JsonDerivedType(typeof(SessionContextChangedEvent), "session.context_changed")] [JsonDerivedType(typeof(SessionErrorEvent), "session.error")] +[JsonDerivedType(typeof(SessionExtensionsLoadedEvent), "session.extensions_loaded")] [JsonDerivedType(typeof(SessionHandoffEvent), "session.handoff")] [JsonDerivedType(typeof(SessionIdleEvent), "session.idle")] [JsonDerivedType(typeof(SessionInfoEvent), "session.info")] +[JsonDerivedType(typeof(SessionMcpServerStatusChangedEvent), "session.mcp_server_status_changed")] +[JsonDerivedType(typeof(SessionMcpServersLoadedEvent), "session.mcp_servers_loaded")] [JsonDerivedType(typeof(SessionModeChangedEvent), "session.mode_changed")] [JsonDerivedType(typeof(SessionModelChangeEvent), "session.model_change")] [JsonDerivedType(typeof(SessionPlanChangedEvent), "session.plan_changed")] [JsonDerivedType(typeof(SessionResumeEvent), "session.resume")] [JsonDerivedType(typeof(SessionShutdownEvent), "session.shutdown")] +[JsonDerivedType(typeof(SessionSkillsLoadedEvent), "session.skills_loaded")] [JsonDerivedType(typeof(SessionSnapshotRewindEvent), "session.snapshot_rewind")] [JsonDerivedType(typeof(SessionStartEvent), "session.start")] [JsonDerivedType(typeof(SessionTaskCompleteEvent), "session.task_complete")] @@ -337,7 +345,7 @@ public partial class SessionUsageInfoEvent : SessionEvent public required SessionUsageInfoData Data { get; set; } } -/// Empty payload; the event signals that LLM-powered conversation compaction has begun. +/// Context window breakdown at the start of LLM-powered conversation compaction. /// Represents the session.compaction_start event. public partial class SessionCompactionStartEvent : SessionEvent { @@ -363,7 +371,7 @@ public partial class SessionCompactionCompleteEvent : SessionEvent public required SessionCompactionCompleteData Data { get; set; } } -/// Task completion notification with optional summary from the agent. +/// Task completion notification with summary from the agent. /// Represents the session.task_complete event. public partial class SessionTaskCompleteEvent : SessionEvent { @@ -376,8 +384,7 @@ public partial class SessionTaskCompleteEvent : SessionEvent public required SessionTaskCompleteData Data { get; set; } } -/// User message content with optional attachments, source information, and interaction metadata. -/// Represents the user.message event. +/// Represents the user.message event. public partial class UserMessageEvent : SessionEvent { /// @@ -779,7 +786,7 @@ public partial class UserInputCompletedEvent : SessionEvent public required UserInputCompletedData Data { get; set; } } -/// Structured form elicitation request with JSON schema definition for form fields. +/// Elicitation request; may be form-based (structured input) or URL-based (browser redirect). /// Represents the elicitation.requested event. public partial class ElicitationRequestedEvent : SessionEvent { @@ -805,6 +812,32 @@ public partial class ElicitationCompletedEvent : SessionEvent public required ElicitationCompletedData Data { get; set; } } +/// OAuth authentication request for an MCP server. +/// Represents the mcp.oauth_required event. +public partial class McpOauthRequiredEvent : SessionEvent +{ + /// + [JsonIgnore] + public override string Type => "mcp.oauth_required"; + + /// The mcp.oauth_required event payload. + [JsonPropertyName("data")] + public required McpOauthRequiredData Data { get; set; } +} + +/// MCP OAuth request completion notification. +/// Represents the mcp.oauth_completed event. +public partial class McpOauthCompletedEvent : SessionEvent +{ + /// + [JsonIgnore] + public override string Type => "mcp.oauth_completed"; + + /// The mcp.oauth_completed event payload. + [JsonPropertyName("data")] + public required McpOauthCompletedData Data { get; set; } +} + /// External tool invocation request for client-side tool execution. /// Represents the external_tool.requested event. public partial class ExternalToolRequestedEvent : SessionEvent @@ -844,6 +877,19 @@ public partial class CommandQueuedEvent : SessionEvent public required CommandQueuedData Data { get; set; } } +/// Registered command dispatch request routed to the owning client. +/// Represents the command.execute event. +public partial class CommandExecuteEvent : SessionEvent +{ + /// + [JsonIgnore] + public override string Type => "command.execute"; + + /// The command.execute event payload. + [JsonPropertyName("data")] + public required CommandExecuteData Data { get; set; } +} + /// Queued command completion notification signaling UI dismissal. /// Represents the command.completed event. public partial class CommandCompletedEvent : SessionEvent @@ -857,6 +903,19 @@ public partial class CommandCompletedEvent : SessionEvent public required CommandCompletedData Data { get; set; } } +/// SDK command registration change notification. +/// Represents the commands.changed event. +public partial class CommandsChangedEvent : SessionEvent +{ + /// + [JsonIgnore] + public override string Type => "commands.changed"; + + /// The commands.changed event payload. + [JsonPropertyName("data")] + public required CommandsChangedData Data { get; set; } +} + /// Plan approval request with plan content and available user actions. /// Represents the exit_plan_mode.requested event. public partial class ExitPlanModeRequestedEvent : SessionEvent @@ -907,6 +966,54 @@ public partial class SessionBackgroundTasksChangedEvent : SessionEvent public required SessionBackgroundTasksChangedData Data { get; set; } } +/// Represents the session.skills_loaded event. +public partial class SessionSkillsLoadedEvent : SessionEvent +{ + /// + [JsonIgnore] + public override string Type => "session.skills_loaded"; + + /// The session.skills_loaded event payload. + [JsonPropertyName("data")] + public required SessionSkillsLoadedData Data { get; set; } +} + +/// Represents the session.mcp_servers_loaded event. +public partial class SessionMcpServersLoadedEvent : SessionEvent +{ + /// + [JsonIgnore] + public override string Type => "session.mcp_servers_loaded"; + + /// The session.mcp_servers_loaded event payload. + [JsonPropertyName("data")] + public required SessionMcpServersLoadedData Data { get; set; } +} + +/// Represents the session.mcp_server_status_changed event. +public partial class SessionMcpServerStatusChangedEvent : SessionEvent +{ + /// + [JsonIgnore] + public override string Type => "session.mcp_server_status_changed"; + + /// The session.mcp_server_status_changed event payload. + [JsonPropertyName("data")] + public required SessionMcpServerStatusChangedData Data { get; set; } +} + +/// Represents the session.extensions_loaded event. +public partial class SessionExtensionsLoadedEvent : SessionEvent +{ + /// + [JsonIgnore] + public override string Type => "session.extensions_loaded"; + + /// The session.extensions_loaded event payload. + [JsonPropertyName("data")] + public required SessionExtensionsLoadedData Data { get; set; } +} + /// Session initialization metadata including context and configuration. public partial class SessionStartData { @@ -1008,6 +1115,11 @@ public partial class SessionErrorData [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] [JsonPropertyName("providerCallId")] public string? ProviderCallId { get; set; } + + /// Optional URL associated with this error that the user can open in a browser. + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("url")] + public string? Url { get; set; } } /// Payload indicating the agent is idle; includes any background tasks still in flight. @@ -1037,6 +1149,11 @@ public partial class SessionInfoData /// Human-readable informational message for display in the timeline. [JsonPropertyName("message")] public required string Message { get; set; } + + /// Optional URL associated with this message that the user can open in a browser. + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("url")] + public string? Url { get; set; } } /// Warning message for timeline display with categorization. @@ -1049,6 +1166,11 @@ public partial class SessionWarningData /// Human-readable warning message for display in the timeline. [JsonPropertyName("message")] public required string Message { get; set; } + + /// Optional URL associated with this warning that the user can open in a browser. + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("url")] + public string? Url { get; set; } } /// Model change details including previous and new model identifiers. @@ -1222,6 +1344,26 @@ public partial class SessionShutdownData [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] [JsonPropertyName("currentModel")] public string? CurrentModel { get; set; } + + /// Total tokens in context window at shutdown. + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("currentTokens")] + public double? CurrentTokens { get; set; } + + /// System message token count at shutdown. + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("systemTokens")] + public double? SystemTokens { get; set; } + + /// Non-system message token count at shutdown. + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("conversationTokens")] + public double? ConversationTokens { get; set; } + + /// Tool definitions token count at shutdown. + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("toolDefinitionsTokens")] + public double? ToolDefinitionsTokens { get; set; } } /// Updated working directory and git context after the change. @@ -1276,11 +1418,45 @@ public partial class SessionUsageInfoData /// Current number of messages in the conversation. [JsonPropertyName("messagesLength")] public required double MessagesLength { get; set; } + + /// Token count from system message(s). + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("systemTokens")] + public double? SystemTokens { get; set; } + + /// Token count from non-system messages (user, assistant, tool). + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("conversationTokens")] + public double? ConversationTokens { get; set; } + + /// Token count from tool definitions. + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("toolDefinitionsTokens")] + public double? ToolDefinitionsTokens { get; set; } + + /// Whether this is the first usage_info event emitted in this session. + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("isInitial")] + public bool? IsInitial { get; set; } } -/// Empty payload; the event signals that LLM-powered conversation compaction has begun. +/// Context window breakdown at the start of LLM-powered conversation compaction. public partial class SessionCompactionStartData { + /// Token count from system message(s) at compaction start. + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("systemTokens")] + public double? SystemTokens { get; set; } + + /// Token count from non-system messages (user, assistant, tool) at compaction start. + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("conversationTokens")] + public double? ConversationTokens { get; set; } + + /// Token count from tool definitions at compaction start. + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("toolDefinitionsTokens")] + public double? ToolDefinitionsTokens { get; set; } } /// Conversation compaction results including success status, metrics, and optional error details. @@ -1344,18 +1520,38 @@ public partial class SessionCompactionCompleteData [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] [JsonPropertyName("requestId")] public string? RequestId { get; set; } + + /// Token count from system message(s) after compaction. + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("systemTokens")] + public double? SystemTokens { get; set; } + + /// Token count from non-system messages (user, assistant, tool) after compaction. + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("conversationTokens")] + public double? ConversationTokens { get; set; } + + /// Token count from tool definitions after compaction. + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("toolDefinitionsTokens")] + public double? ToolDefinitionsTokens { get; set; } } -/// Task completion notification with optional summary from the agent. +/// Task completion notification with summary from the agent. public partial class SessionTaskCompleteData { - /// Optional summary of the completed task, provided by the agent. + /// Summary of the completed task, provided by the agent. [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] [JsonPropertyName("summary")] public string? Summary { get; set; } + + /// Whether the tool call succeeded. False when validation failed (e.g., invalid arguments). + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("success")] + public bool? Success { get; set; } } -/// User message content with optional attachments, source information, and interaction metadata. +/// Event payload for . public partial class UserMessageData { /// The user's message text as displayed in the timeline. @@ -1372,10 +1568,10 @@ public partial class UserMessageData [JsonPropertyName("attachments")] public UserMessageDataAttachmentsItem[]? Attachments { get; set; } - /// Origin of this message, used for timeline filtering and telemetry (e.g., "user", "autopilot", "skill", or "command"). + /// Origin of this message, used for timeline filtering (e.g., "skill-pdf" for skill-injected messages that should be hidden from the user). [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] [JsonPropertyName("source")] - public UserMessageDataSource? Source { get; set; } + public string? Source { get; set; } /// The agent mode that was active when this message was sent. [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] @@ -1953,6 +2149,11 @@ public partial class UserInputRequestedData [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] [JsonPropertyName("allowFreeform")] public bool? AllowFreeform { get; set; } + + /// The LLM-assigned tool call ID that triggered this request; used by remote UIs to correlate responses. + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("toolCallId")] + public string? ToolCallId { get; set; } } /// User input request completion notification signaling UI dismissal. @@ -1963,25 +2164,41 @@ public partial class UserInputCompletedData public required string RequestId { get; set; } } -/// Structured form elicitation request with JSON schema definition for form fields. +/// Elicitation request; may be form-based (structured input) or URL-based (browser redirect). public partial class ElicitationRequestedData { /// Unique identifier for this elicitation request; used to respond via session.respondToElicitation(). [JsonPropertyName("requestId")] public required string RequestId { get; set; } + /// Tool call ID from the LLM completion; used to correlate with CompletionChunk.toolCall.id for remote UIs. + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("toolCallId")] + public string? ToolCallId { get; set; } + + /// The source that initiated the request (MCP server name, or absent for agent-initiated). + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("elicitationSource")] + public string? ElicitationSource { get; set; } + /// Message describing what information is needed from the user. [JsonPropertyName("message")] public required string Message { get; set; } - /// Elicitation mode; currently only "form" is supported. Defaults to "form" when absent. + /// Elicitation mode; "form" for structured input, "url" for browser-based. Defaults to "form" when absent. [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] [JsonPropertyName("mode")] - public string? Mode { get; set; } + public ElicitationRequestedDataMode? Mode { get; set; } - /// JSON Schema describing the form fields to present to the user. + /// JSON Schema describing the form fields to present to the user (form mode only). + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] [JsonPropertyName("requestedSchema")] - public required ElicitationRequestedDataRequestedSchema RequestedSchema { get; set; } + public ElicitationRequestedDataRequestedSchema? RequestedSchema { get; set; } + + /// URL to open in the user's browser (url mode only). + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("url")] + public string? Url { get; set; } } /// Elicitation request completion notification signaling UI dismissal. @@ -1992,6 +2209,35 @@ public partial class ElicitationCompletedData public required string RequestId { get; set; } } +/// OAuth authentication request for an MCP server. +public partial class McpOauthRequiredData +{ + /// Unique identifier for this OAuth request; used to respond via session.respondToMcpOAuth(). + [JsonPropertyName("requestId")] + public required string RequestId { get; set; } + + /// Display name of the MCP server that requires OAuth. + [JsonPropertyName("serverName")] + public required string ServerName { get; set; } + + /// URL of the MCP server that requires OAuth. + [JsonPropertyName("serverUrl")] + public required string ServerUrl { get; set; } + + /// Static OAuth client configuration, if the server specifies one. + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("staticClientConfig")] + public McpOauthRequiredDataStaticClientConfig? StaticClientConfig { get; set; } +} + +/// MCP OAuth request completion notification. +public partial class McpOauthCompletedData +{ + /// Request ID of the resolved OAuth request. + [JsonPropertyName("requestId")] + public required string RequestId { get; set; } +} + /// External tool invocation request for client-side tool execution. public partial class ExternalToolRequestedData { @@ -2047,6 +2293,26 @@ public partial class CommandQueuedData public required string Command { get; set; } } +/// Registered command dispatch request routed to the owning client. +public partial class CommandExecuteData +{ + /// Unique identifier; used to respond via session.commands.handlePendingCommand(). + [JsonPropertyName("requestId")] + public required string RequestId { get; set; } + + /// The full command text (e.g., /deploy production). + [JsonPropertyName("command")] + public required string Command { get; set; } + + /// Command name without leading /. + [JsonPropertyName("commandName")] + public required string CommandName { get; set; } + + /// Raw argument string after the command name. + [JsonPropertyName("args")] + public required string Args { get; set; } +} + /// Queued command completion notification signaling UI dismissal. public partial class CommandCompletedData { @@ -2055,6 +2321,14 @@ public partial class CommandCompletedData public required string RequestId { get; set; } } +/// SDK command registration change notification. +public partial class CommandsChangedData +{ + /// Current list of registered SDK commands. + [JsonPropertyName("commands")] + public required CommandsChangedDataCommandsItem[] Commands { get; set; } +} + /// Plan approval request with plan content and available user actions. public partial class ExitPlanModeRequestedData { @@ -2100,6 +2374,42 @@ public partial class SessionBackgroundTasksChangedData { } +/// Event payload for . +public partial class SessionSkillsLoadedData +{ + /// Array of resolved skill metadata. + [JsonPropertyName("skills")] + public required SessionSkillsLoadedDataSkillsItem[] Skills { get; set; } +} + +/// Event payload for . +public partial class SessionMcpServersLoadedData +{ + /// Array of MCP server status summaries. + [JsonPropertyName("servers")] + public required SessionMcpServersLoadedDataServersItem[] Servers { get; set; } +} + +/// Event payload for . +public partial class SessionMcpServerStatusChangedData +{ + /// Name of the MCP server whose status changed. + [JsonPropertyName("serverName")] + public required string ServerName { get; set; } + + /// New connection status: connected, failed, pending, disabled, or not_configured. + [JsonPropertyName("status")] + public required SessionMcpServersLoadedDataServersItemStatus Status { get; set; } +} + +/// Event payload for . +public partial class SessionExtensionsLoadedData +{ + /// Array of discovered extensions and their status. + [JsonPropertyName("extensions")] + public required SessionExtensionsLoadedDataExtensionsItem[] Extensions { get; set; } +} + /// Working directory and git context at session start. /// Nested data type for SessionStartDataContext. public partial class SessionStartDataContext @@ -2787,6 +3097,27 @@ public partial class SystemNotificationDataKindAgentCompleted : SystemNotificati public string? Prompt { get; set; } } +/// The agent_idle variant of . +public partial class SystemNotificationDataKindAgentIdle : SystemNotificationDataKind +{ + /// + [JsonIgnore] + public override string Type => "agent_idle"; + + /// Unique identifier of the background agent. + [JsonPropertyName("agentId")] + public required string AgentId { get; set; } + + /// Type of the agent (e.g., explore, task, general-purpose). + [JsonPropertyName("agentType")] + public required string AgentType { get; set; } + + /// Human-readable description of the agent task. + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("description")] + public string? Description { get; set; } +} + /// The shell_completed variant of . public partial class SystemNotificationDataKindShellCompleted : SystemNotificationDataKind { @@ -2832,6 +3163,7 @@ public partial class SystemNotificationDataKindShellDetachedCompleted : SystemNo TypeDiscriminatorPropertyName = "type", UnknownDerivedTypeHandling = JsonUnknownDerivedTypeHandling.FallBackToBaseType)] [JsonDerivedType(typeof(SystemNotificationDataKindAgentCompleted), "agent_completed")] +[JsonDerivedType(typeof(SystemNotificationDataKindAgentIdle), "agent_idle")] [JsonDerivedType(typeof(SystemNotificationDataKindShellCompleted), "shell_completed")] [JsonDerivedType(typeof(SystemNotificationDataKindShellDetachedCompleted), "shell_detached_completed")] public partial class SystemNotificationDataKind @@ -3130,7 +3462,7 @@ public partial class PermissionCompletedDataResult public required PermissionCompletedDataResultKind Kind { get; set; } } -/// JSON Schema describing the form fields to present to the user. +/// JSON Schema describing the form fields to present to the user (form mode only). /// Nested data type for ElicitationRequestedDataRequestedSchema. public partial class ElicitationRequestedDataRequestedSchema { @@ -3148,6 +3480,104 @@ public partial class ElicitationRequestedDataRequestedSchema public string[]? Required { get; set; } } +/// Static OAuth client configuration, if the server specifies one. +/// Nested data type for McpOauthRequiredDataStaticClientConfig. +public partial class McpOauthRequiredDataStaticClientConfig +{ + /// OAuth client ID for the server. + [JsonPropertyName("clientId")] + public required string ClientId { get; set; } + + /// Whether this is a public OAuth client. + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("publicClient")] + public bool? PublicClient { get; set; } +} + +/// Nested data type for CommandsChangedDataCommandsItem. +public partial class CommandsChangedDataCommandsItem +{ + /// Gets or sets the name value. + [JsonPropertyName("name")] + public required string Name { get; set; } + + /// Gets or sets the description value. + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("description")] + public string? Description { get; set; } +} + +/// Nested data type for SessionSkillsLoadedDataSkillsItem. +public partial class SessionSkillsLoadedDataSkillsItem +{ + /// Unique identifier for the skill. + [JsonPropertyName("name")] + public required string Name { get; set; } + + /// Description of what the skill does. + [JsonPropertyName("description")] + public required string Description { get; set; } + + /// Source location type of the skill (e.g., project, personal, plugin). + [JsonPropertyName("source")] + public required string Source { get; set; } + + /// Whether the skill can be invoked by the user as a slash command. + [JsonPropertyName("userInvocable")] + public required bool UserInvocable { get; set; } + + /// Whether the skill is currently enabled. + [JsonPropertyName("enabled")] + public required bool Enabled { get; set; } + + /// Absolute path to the skill file, if available. + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("path")] + public string? Path { get; set; } +} + +/// Nested data type for SessionMcpServersLoadedDataServersItem. +public partial class SessionMcpServersLoadedDataServersItem +{ + /// Server name (config key). + [JsonPropertyName("name")] + public required string Name { get; set; } + + /// Connection status: connected, failed, pending, disabled, or not_configured. + [JsonPropertyName("status")] + public required SessionMcpServersLoadedDataServersItemStatus Status { get; set; } + + /// Configuration source: user, workspace, plugin, or builtin. + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("source")] + public string? Source { get; set; } + + /// Error message if the server failed to connect. + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("error")] + public string? Error { get; set; } +} + +/// Nested data type for SessionExtensionsLoadedDataExtensionsItem. +public partial class SessionExtensionsLoadedDataExtensionsItem +{ + /// Source-qualified extension ID (e.g., 'project:my-ext', 'user:auth-helper'). + [JsonPropertyName("id")] + public required string Id { get; set; } + + /// Extension name (directory name). + [JsonPropertyName("name")] + public required string Name { get; set; } + + /// Discovery source. + [JsonPropertyName("source")] + public required SessionExtensionsLoadedDataExtensionsItemSource Source { get; set; } + + /// Current status: running, disabled, failed, or starting. + [JsonPropertyName("status")] + public required SessionExtensionsLoadedDataExtensionsItemStatus Status { get; set; } +} + /// Hosting platform type of the repository (github or ado). [JsonConverter(typeof(JsonStringEnumConverter))] public enum SessionStartDataContextHostType @@ -3226,42 +3656,6 @@ public enum UserMessageDataAttachmentsItemGithubReferenceReferenceType Discussion, } -/// Origin of this message, used for timeline filtering and telemetry (e.g., "user", "autopilot", "skill", or "command"). -[JsonConverter(typeof(JsonStringEnumConverter))] -public enum UserMessageDataSource -{ - /// The user variant. - [JsonStringEnumMemberName("user")] - User, - /// The autopilot variant. - [JsonStringEnumMemberName("autopilot")] - Autopilot, - /// The skill variant. - [JsonStringEnumMemberName("skill")] - Skill, - /// The system variant. - [JsonStringEnumMemberName("system")] - System, - /// The command variant. - [JsonStringEnumMemberName("command")] - Command, - /// The immediate-prompt variant. - [JsonStringEnumMemberName("immediate-prompt")] - ImmediatePrompt, - /// The jit-instruction variant. - [JsonStringEnumMemberName("jit-instruction")] - JitInstruction, - /// The snippy-blocking variant. - [JsonStringEnumMemberName("snippy-blocking")] - SnippyBlocking, - /// The thinking-exhausted-continuation variant. - [JsonStringEnumMemberName("thinking-exhausted-continuation")] - ThinkingExhaustedContinuation, - /// The other variant. - [JsonStringEnumMemberName("other")] - Other, -} - /// The agent mode that was active when this message was sent. [JsonConverter(typeof(JsonStringEnumConverter))] public enum UserMessageDataAgentMode @@ -3349,6 +3743,69 @@ public enum PermissionCompletedDataResultKind DeniedByContentExclusionPolicy, } +/// Elicitation mode; "form" for structured input, "url" for browser-based. Defaults to "form" when absent. +[JsonConverter(typeof(JsonStringEnumConverter))] +public enum ElicitationRequestedDataMode +{ + /// The form variant. + [JsonStringEnumMemberName("form")] + Form, + /// The url variant. + [JsonStringEnumMemberName("url")] + Url, +} + +/// Connection status: connected, failed, pending, disabled, or not_configured. +[JsonConverter(typeof(JsonStringEnumConverter))] +public enum SessionMcpServersLoadedDataServersItemStatus +{ + /// The connected variant. + [JsonStringEnumMemberName("connected")] + Connected, + /// The failed variant. + [JsonStringEnumMemberName("failed")] + Failed, + /// The pending variant. + [JsonStringEnumMemberName("pending")] + Pending, + /// The disabled variant. + [JsonStringEnumMemberName("disabled")] + Disabled, + /// The not_configured variant. + [JsonStringEnumMemberName("not_configured")] + NotConfigured, +} + +/// Discovery source. +[JsonConverter(typeof(JsonStringEnumConverter))] +public enum SessionExtensionsLoadedDataExtensionsItemSource +{ + /// The project variant. + [JsonStringEnumMemberName("project")] + Project, + /// The user variant. + [JsonStringEnumMemberName("user")] + User, +} + +/// Current status: running, disabled, failed, or starting. +[JsonConverter(typeof(JsonStringEnumConverter))] +public enum SessionExtensionsLoadedDataExtensionsItemStatus +{ + /// The running variant. + [JsonStringEnumMemberName("running")] + Running, + /// The disabled variant. + [JsonStringEnumMemberName("disabled")] + Disabled, + /// The failed variant. + [JsonStringEnumMemberName("failed")] + Failed, + /// The starting variant. + [JsonStringEnumMemberName("starting")] + Starting, +} + [JsonSourceGenerationOptions( JsonSerializerDefaults.Web, AllowOutOfOrderMetadataProperties = true, @@ -3379,8 +3836,13 @@ public enum PermissionCompletedDataResultKind [JsonSerializable(typeof(AssistantUsageEvent))] [JsonSerializable(typeof(CommandCompletedData))] [JsonSerializable(typeof(CommandCompletedEvent))] +[JsonSerializable(typeof(CommandExecuteData))] +[JsonSerializable(typeof(CommandExecuteEvent))] [JsonSerializable(typeof(CommandQueuedData))] [JsonSerializable(typeof(CommandQueuedEvent))] +[JsonSerializable(typeof(CommandsChangedData))] +[JsonSerializable(typeof(CommandsChangedDataCommandsItem))] +[JsonSerializable(typeof(CommandsChangedEvent))] [JsonSerializable(typeof(ElicitationCompletedData))] [JsonSerializable(typeof(ElicitationCompletedEvent))] [JsonSerializable(typeof(ElicitationRequestedData))] @@ -3399,6 +3861,11 @@ public enum PermissionCompletedDataResultKind [JsonSerializable(typeof(HookEndEvent))] [JsonSerializable(typeof(HookStartData))] [JsonSerializable(typeof(HookStartEvent))] +[JsonSerializable(typeof(McpOauthCompletedData))] +[JsonSerializable(typeof(McpOauthCompletedEvent))] +[JsonSerializable(typeof(McpOauthRequiredData))] +[JsonSerializable(typeof(McpOauthRequiredDataStaticClientConfig))] +[JsonSerializable(typeof(McpOauthRequiredEvent))] [JsonSerializable(typeof(PendingMessagesModifiedData))] [JsonSerializable(typeof(PendingMessagesModifiedEvent))] [JsonSerializable(typeof(PermissionCompletedData))] @@ -3429,6 +3896,9 @@ public enum PermissionCompletedDataResultKind [JsonSerializable(typeof(SessionErrorData))] [JsonSerializable(typeof(SessionErrorEvent))] [JsonSerializable(typeof(SessionEvent))] +[JsonSerializable(typeof(SessionExtensionsLoadedData))] +[JsonSerializable(typeof(SessionExtensionsLoadedDataExtensionsItem))] +[JsonSerializable(typeof(SessionExtensionsLoadedEvent))] [JsonSerializable(typeof(SessionHandoffData))] [JsonSerializable(typeof(SessionHandoffDataRepository))] [JsonSerializable(typeof(SessionHandoffEvent))] @@ -3439,6 +3909,11 @@ public enum PermissionCompletedDataResultKind [JsonSerializable(typeof(SessionIdleEvent))] [JsonSerializable(typeof(SessionInfoData))] [JsonSerializable(typeof(SessionInfoEvent))] +[JsonSerializable(typeof(SessionMcpServerStatusChangedData))] +[JsonSerializable(typeof(SessionMcpServerStatusChangedEvent))] +[JsonSerializable(typeof(SessionMcpServersLoadedData))] +[JsonSerializable(typeof(SessionMcpServersLoadedDataServersItem))] +[JsonSerializable(typeof(SessionMcpServersLoadedEvent))] [JsonSerializable(typeof(SessionModeChangedData))] [JsonSerializable(typeof(SessionModeChangedEvent))] [JsonSerializable(typeof(SessionModelChangeData))] @@ -3451,6 +3926,9 @@ public enum PermissionCompletedDataResultKind [JsonSerializable(typeof(SessionShutdownData))] [JsonSerializable(typeof(SessionShutdownDataCodeChanges))] [JsonSerializable(typeof(SessionShutdownEvent))] +[JsonSerializable(typeof(SessionSkillsLoadedData))] +[JsonSerializable(typeof(SessionSkillsLoadedDataSkillsItem))] +[JsonSerializable(typeof(SessionSkillsLoadedEvent))] [JsonSerializable(typeof(SessionSnapshotRewindData))] [JsonSerializable(typeof(SessionSnapshotRewindEvent))] [JsonSerializable(typeof(SessionStartData))] @@ -3488,6 +3966,7 @@ public enum PermissionCompletedDataResultKind [JsonSerializable(typeof(SystemNotificationData))] [JsonSerializable(typeof(SystemNotificationDataKind))] [JsonSerializable(typeof(SystemNotificationDataKindAgentCompleted))] +[JsonSerializable(typeof(SystemNotificationDataKindAgentIdle))] [JsonSerializable(typeof(SystemNotificationDataKindShellCompleted))] [JsonSerializable(typeof(SystemNotificationDataKindShellDetachedCompleted))] [JsonSerializable(typeof(SystemNotificationEvent))] diff --git a/dotnet/src/Session.cs b/dotnet/src/Session.cs index 606c0b052..0014ec7f0 100644 --- a/dotnet/src/Session.cs +++ b/dotnet/src/Session.cs @@ -749,6 +749,7 @@ public Task SetModelAsync(string model, CancellationToken cancellationToken = de /// The message to log. /// Log level (default: info). /// When true, the message is not persisted to disk. + /// Optional URL to associate with the log entry. /// Optional cancellation token. /// /// @@ -758,9 +759,9 @@ public Task SetModelAsync(string model, CancellationToken cancellationToken = de /// await session.LogAsync("Temporary status", ephemeral: true); /// /// - public async Task LogAsync(string message, SessionLogRequestLevel? level = null, bool? ephemeral = null, CancellationToken cancellationToken = default) + public async Task LogAsync(string message, SessionLogRequestLevel? level = null, bool? ephemeral = null, string? url = null, CancellationToken cancellationToken = default) { - await Rpc.LogAsync(message, level, ephemeral, cancellationToken); + await Rpc.LogAsync(message, level, ephemeral, url, cancellationToken); } /// diff --git a/go/README.md b/go/README.md index 1d0665130..8cbb382c3 100644 --- a/go/README.md +++ b/go/README.md @@ -201,7 +201,7 @@ _, err = session.Send(context.Background(), copilot.MessageOptions{ Prompt: "What's in this image?", Attachments: []copilot.Attachment{ { - Type: copilot.Blob, + Type: copilot.AttachmentTypeBlob, Data: &base64ImageData, MIMEType: &mimeType, }, diff --git a/go/generated_session_events.go b/go/generated_session_events.go index 55eea011e..fbdb1597f 100644 --- a/go/generated_session_events.go +++ b/go/generated_session_events.go @@ -61,15 +61,12 @@ type SessionEvent struct { // // Current context window usage statistics including token and message counts // - // Empty payload; the event signals that LLM-powered conversation compaction has begun + // Context window breakdown at the start of LLM-powered conversation compaction // // Conversation compaction results including success status, metrics, and optional error // details // - // Task completion notification with optional summary from the agent - // - // User message content with optional attachments, source information, and interaction - // metadata + // Task completion notification with summary from the agent // // Empty payload; the event signals that the pending message queue has changed // @@ -135,18 +132,27 @@ type SessionEvent struct { // // User input request completion notification signaling UI dismissal // - // Structured form elicitation request with JSON schema definition for form fields + // Elicitation request; may be form-based (structured input) or URL-based (browser + // redirect) // // Elicitation request completion notification signaling UI dismissal // + // OAuth authentication request for an MCP server + // + // MCP OAuth request completion notification + // // External tool invocation request for client-side tool execution // // External tool completion notification signaling UI dismissal // // Queued slash command dispatch request for client execution // + // Registered command dispatch request routed to the owning client + // // Queued command completion notification signaling UI dismissal // + // SDK command registration change notification + // // Plan approval request with plan content and available user actions // // Plan mode exit completion notification signaling UI dismissal @@ -198,15 +204,12 @@ type SessionEvent struct { // // # Current context window usage statistics including token and message counts // -// Empty payload; the event signals that LLM-powered conversation compaction has begun +// # Context window breakdown at the start of LLM-powered conversation compaction // // Conversation compaction results including success status, metrics, and optional error // details // -// # Task completion notification with optional summary from the agent -// -// User message content with optional attachments, source information, and interaction -// metadata +// # Task completion notification with summary from the agent // // Empty payload; the event signals that the pending message queue has changed // @@ -272,18 +275,27 @@ type SessionEvent struct { // // # User input request completion notification signaling UI dismissal // -// # Structured form elicitation request with JSON schema definition for form fields +// Elicitation request; may be form-based (structured input) or URL-based (browser +// redirect) // // # Elicitation request completion notification signaling UI dismissal // +// # OAuth authentication request for an MCP server +// +// # MCP OAuth request completion notification +// // # External tool invocation request for client-side tool execution // // # External tool completion notification signaling UI dismissal // // # Queued slash command dispatch request for client execution // +// # Registered command dispatch request routed to the owning client +// // # Queued command completion notification signaling UI dismissal // +// # SDK command registration change notification +// // # Plan approval request with plan content and available user actions // // Plan mode exit completion notification signaling UI dismissal @@ -343,6 +355,14 @@ type Data struct { Stack *string `json:"stack,omitempty"` // HTTP status code from the upstream request, if applicable StatusCode *int64 `json:"statusCode,omitempty"` + // Optional URL associated with this error that the user can open in a browser + // + // Optional URL associated with this message that the user can open in a browser + // + // Optional URL associated with this warning that the user can open in a browser + // + // URL to open in the user's browser (url mode only) + URL *string `json:"url,omitempty"` // Background tasks still running when the agent became idle BackgroundTasks *BackgroundTasks `json:"backgroundTasks,omitempty"` // The new display title for the session @@ -383,7 +403,7 @@ type Data struct { SourceType *SourceType `json:"sourceType,omitempty"` // Summary of the work done in the source session // - // Optional summary of the completed task, provided by the agent + // Summary of the completed task, provided by the agent // // Summary of the plan that was created Summary *string `json:"summary,omitempty"` @@ -409,8 +429,20 @@ type Data struct { UpToEventID *string `json:"upToEventId,omitempty"` // Aggregate code change metrics for the session CodeChanges *CodeChanges `json:"codeChanges,omitempty"` + // Non-system message token count at shutdown + // + // Token count from non-system messages (user, assistant, tool) + // + // Token count from non-system messages (user, assistant, tool) at compaction start + // + // Token count from non-system messages (user, assistant, tool) after compaction + ConversationTokens *float64 `json:"conversationTokens,omitempty"` // Model that was selected at the time of shutdown CurrentModel *string `json:"currentModel,omitempty"` + // Total tokens in context window at shutdown + // + // Current number of tokens in the context window + CurrentTokens *float64 `json:"currentTokens,omitempty"` // Error description when shutdownType is "error" ErrorReason *string `json:"errorReason,omitempty"` // Per-model usage breakdown, keyed by model identifier @@ -419,6 +451,22 @@ type Data struct { SessionStartTime *float64 `json:"sessionStartTime,omitempty"` // Whether the session ended normally ("routine") or due to a crash/fatal error ("error") ShutdownType *ShutdownType `json:"shutdownType,omitempty"` + // System message token count at shutdown + // + // Token count from system message(s) + // + // Token count from system message(s) at compaction start + // + // Token count from system message(s) after compaction + SystemTokens *float64 `json:"systemTokens,omitempty"` + // Tool definitions token count at shutdown + // + // Token count from tool definitions + // + // Token count from tool definitions at compaction start + // + // Token count from tool definitions after compaction + ToolDefinitionsTokens *float64 `json:"toolDefinitionsTokens,omitempty"` // Cumulative time spent in API calls during the session, in milliseconds TotalAPIDurationMS *float64 `json:"totalApiDurationMs,omitempty"` // Total number of premium API requests used during the session @@ -435,8 +483,8 @@ type Data struct { HeadCommit *string `json:"headCommit,omitempty"` // Hosting platform type of the repository (github or ado) HostType *HostType `json:"hostType,omitempty"` - // Current number of tokens in the context window - CurrentTokens *float64 `json:"currentTokens,omitempty"` + // Whether this is the first usage_info event emitted in this session + IsInitial *bool `json:"isInitial,omitempty"` // Current number of messages in the conversation MessagesLength *float64 `json:"messagesLength,omitempty"` // Checkpoint snapshot number created for recovery @@ -481,6 +529,11 @@ type Data struct { // Request ID of the resolved elicitation request; clients should dismiss any UI for this // request // + // Unique identifier for this OAuth request; used to respond via + // session.respondToMcpOAuth() + // + // Request ID of the resolved OAuth request + // // Unique identifier for this request; used to respond via session.respondToExternalTool() // // Request ID of the resolved external tool request; clients should dismiss any UI for this @@ -488,6 +541,8 @@ type Data struct { // // Unique identifier for this request; used to respond via session.respondToQueuedCommand() // + // Unique identifier; used to respond via session.commands.handlePendingCommand() + // // Request ID of the resolved command request; clients should dismiss any UI for this // request // @@ -498,6 +553,8 @@ type Data struct { RequestID *string `json:"requestId,omitempty"` // Whether compaction completed successfully // + // Whether the tool call succeeded. False when validation failed (e.g., invalid arguments) + // // Whether the tool execution completed successfully // // Whether the hook completed successfully @@ -530,9 +587,9 @@ type Data struct { // // CAPI interaction ID for correlating this tool execution with upstream telemetry InteractionID *string `json:"interactionId,omitempty"` - // Origin of this message, used for timeline filtering and telemetry (e.g., "user", - // "autopilot", "skill", or "command") - Source *Source `json:"source,omitempty"` + // Origin of this message, used for timeline filtering (e.g., "skill-pdf" for skill-injected + // messages that should be hidden from the user) + Source *string `json:"source,omitempty"` // Transformed version of the message sent to the model, with XML wrapping, timestamps, and // other augmentations for prompt caching TransformedContent *string `json:"transformedContent,omitempty"` @@ -618,6 +675,12 @@ type Data struct { // // Tool call ID of the parent tool invocation that spawned this sub-agent // + // The LLM-assigned tool call ID that triggered this request; used by remote UIs to + // correlate responses + // + // Tool call ID from the LLM completion; used to correlate with CompletionChunk.toolCall.id + // for remote UIs + // // Tool call ID assigned to this external tool invocation ToolCallID *string `json:"toolCallId,omitempty"` // Name of the tool the user wants to invoke @@ -690,22 +753,49 @@ type Data struct { Choices []string `json:"choices,omitempty"` // The question or prompt to present to the user Question *string `json:"question,omitempty"` - // Elicitation mode; currently only "form" is supported. Defaults to "form" when absent. + // The source that initiated the request (MCP server name, or absent for agent-initiated) + ElicitationSource *string `json:"elicitationSource,omitempty"` + // Elicitation mode; "form" for structured input, "url" for browser-based. Defaults to + // "form" when absent. Mode *Mode `json:"mode,omitempty"` - // JSON Schema describing the form fields to present to the user + // JSON Schema describing the form fields to present to the user (form mode only) RequestedSchema *RequestedSchema `json:"requestedSchema,omitempty"` + // Display name of the MCP server that requires OAuth + // + // Name of the MCP server whose status changed + ServerName *string `json:"serverName,omitempty"` + // URL of the MCP server that requires OAuth + ServerURL *string `json:"serverUrl,omitempty"` + // Static OAuth client configuration, if the server specifies one + StaticClientConfig *StaticClientConfig `json:"staticClientConfig,omitempty"` // W3C Trace Context traceparent header for the execute_tool span Traceparent *string `json:"traceparent,omitempty"` // W3C Trace Context tracestate header for the execute_tool span Tracestate *string `json:"tracestate,omitempty"` // The slash command text to be executed (e.g., /help, /clear) + // + // The full command text (e.g., /deploy production) Command *string `json:"command,omitempty"` + // Raw argument string after the command name + Args *string `json:"args,omitempty"` + // Command name without leading / + CommandName *string `json:"commandName,omitempty"` + // Current list of registered SDK commands + Commands []DataCommand `json:"commands,omitempty"` // Available actions the user can take (e.g., approve, edit, reject) Actions []string `json:"actions,omitempty"` // Full content of the plan file PlanContent *string `json:"planContent,omitempty"` // The recommended action for the user to take RecommendedAction *string `json:"recommendedAction,omitempty"` + // Array of resolved skill metadata + Skills []Skill `json:"skills,omitempty"` + // Array of MCP server status summaries + Servers []Server `json:"servers,omitempty"` + // New connection status: connected, failed, pending, disabled, or not_configured + Status *ServerStatus `json:"status,omitempty"` + // Array of discovered extensions and their status + Extensions []Extension `json:"extensions,omitempty"` } // A user message attachment — a file, directory, code selection, blob, or GitHub reference @@ -822,6 +912,11 @@ type CodeChanges struct { LinesRemoved float64 `json:"linesRemoved"` } +type DataCommand struct { + Description *string `json:"description,omitempty"` + Name string `json:"name"` +} + // Token usage breakdown for the compaction LLM call type CompactionTokensUsed struct { // Cached input tokens reused in the compaction LLM call @@ -885,6 +980,17 @@ type ErrorClass struct { Stack *string `json:"stack,omitempty"` } +type Extension struct { + // Source-qualified extension ID (e.g., 'project:my-ext', 'user:auth-helper') + ID string `json:"id"` + // Extension name (directory name) + Name string `json:"name"` + // Discovery source + Source Source `json:"source"` + // Current status: running, disabled, failed, or starting + Status ExtensionStatus `json:"status"` +} + // Structured metadata identifying what triggered this notification type KindClass struct { // Unique identifier of the background agent @@ -898,8 +1004,8 @@ type KindClass struct { // The full prompt given to the background agent Prompt *string `json:"prompt,omitempty"` // Whether the agent completed successfully or failed - Status *Status `json:"status,omitempty"` - Type KindType `json:"type"` + Status *KindStatus `json:"status,omitempty"` + Type KindType `json:"type"` // Exit code of the shell command, if available ExitCode *float64 `json:"exitCode,omitempty"` // Unique identifier of the shell session @@ -964,7 +1070,7 @@ type PermissionRequest struct { // Whether the UI can offer session-wide approval for this command pattern CanOfferSessionApproval *bool `json:"canOfferSessionApproval,omitempty"` // Parsed command identifiers found in the command text - Commands []CommandElement `json:"commands,omitempty"` + Commands []PermissionRequestCommand `json:"commands,omitempty"` // The complete shell command text to be executed FullCommandText *string `json:"fullCommandText,omitempty"` // Whether the command includes a file write redirection (e.g., > or >>) @@ -1027,7 +1133,7 @@ type PermissionRequest struct { ToolArgs interface{} `json:"toolArgs"` } -type CommandElement struct { +type PermissionRequestCommand struct { // Command identifier (e.g., executable name) Identifier string `json:"identifier"` // Whether this command is read-only (no side effects) @@ -1068,7 +1174,7 @@ type RepositoryClass struct { Owner string `json:"owner"` } -// JSON Schema describing the form fields to present to the user +// JSON Schema describing the form fields to present to the user (form mode only) type RequestedSchema struct { // Form field definitions, keyed by field name Properties map[string]interface{} `json:"properties"` @@ -1172,6 +1278,40 @@ type ResourceClass struct { Blob *string `json:"blob,omitempty"` } +type Server struct { + // Error message if the server failed to connect + Error *string `json:"error,omitempty"` + // Server name (config key) + Name string `json:"name"` + // Configuration source: user, workspace, plugin, or builtin + Source *string `json:"source,omitempty"` + // Connection status: connected, failed, pending, disabled, or not_configured + Status ServerStatus `json:"status"` +} + +type Skill struct { + // Description of what the skill does + Description string `json:"description"` + // Whether the skill is currently enabled + Enabled bool `json:"enabled"` + // Unique identifier for the skill + Name string `json:"name"` + // Absolute path to the skill file, if available + Path *string `json:"path,omitempty"` + // Source location type of the skill (e.g., project, personal, plugin) + Source string `json:"source"` + // Whether the skill can be invoked by the user as a slash command + UserInvocable bool `json:"userInvocable"` +} + +// Static OAuth client configuration, if the server specifies one +type StaticClientConfig struct { + // OAuth client ID for the server + ClientID string `json:"clientId"` + // Whether this is a public OAuth client + PublicClient *bool `json:"publicClient,omitempty"` +} + // A tool invocation request from the assistant type ToolRequest struct { // Arguments to pass to the tool, format depends on the tool @@ -1193,59 +1333,81 @@ type ToolRequest struct { type AgentMode string const ( - AgentModeAutopilot AgentMode = "autopilot" - AgentModeShell AgentMode = "shell" - Interactive AgentMode = "interactive" - Plan AgentMode = "plan" + AgentModeShell AgentMode = "shell" + AgentModeAutopilot AgentMode = "autopilot" + AgentModeInteractive AgentMode = "interactive" + AgentModePlan AgentMode = "plan" ) // Type of GitHub reference type ReferenceType string const ( - Discussion ReferenceType = "discussion" - Issue ReferenceType = "issue" - PR ReferenceType = "pr" + ReferenceTypeDiscussion ReferenceType = "discussion" + ReferenceTypeIssue ReferenceType = "issue" + ReferenceTypePr ReferenceType = "pr" ) type AttachmentType string const ( - Blob AttachmentType = "blob" - Directory AttachmentType = "directory" - File AttachmentType = "file" - GithubReference AttachmentType = "github_reference" - Selection AttachmentType = "selection" + AttachmentTypeBlob AttachmentType = "blob" + AttachmentTypeDirectory AttachmentType = "directory" + AttachmentTypeFile AttachmentType = "file" + AttachmentTypeGithubReference AttachmentType = "github_reference" + AttachmentTypeSelection AttachmentType = "selection" ) // Hosting platform type of the repository (github or ado) type HostType string const ( - ADO HostType = "ado" - Github HostType = "github" + HostTypeAdo HostType = "ado" + HostTypeGithub HostType = "github" +) + +// Discovery source +type Source string + +const ( + SourceProject Source = "project" + SourceUser Source = "user" +) + +// Current status: running, disabled, failed, or starting +type ExtensionStatus string + +const ( + ExtensionStatusDisabled ExtensionStatus = "disabled" + ExtensionStatusFailed ExtensionStatus = "failed" + ExtensionStatusRunning ExtensionStatus = "running" + ExtensionStatusStarting ExtensionStatus = "starting" ) // Whether the agent completed successfully or failed -type Status string +type KindStatus string const ( - Completed Status = "completed" - Failed Status = "failed" + KindStatusCompleted KindStatus = "completed" + KindStatusFailed KindStatus = "failed" ) type KindType string const ( - AgentCompleted KindType = "agent_completed" - ShellCompleted KindType = "shell_completed" - ShellDetachedCompleted KindType = "shell_detached_completed" + KindTypeAgentCompleted KindType = "agent_completed" + KindTypeAgentIdle KindType = "agent_idle" + KindTypeShellCompleted KindType = "shell_completed" + KindTypeShellDetachedCompleted KindType = "shell_detached_completed" ) +// Elicitation mode; "form" for structured input, "url" for browser-based. Defaults to +// "form" when absent. type Mode string const ( - Form Mode = "form" + ModeForm Mode = "form" + ModeURL Mode = "url" ) // The type of operation performed on the plan file @@ -1254,99 +1416,95 @@ const ( type Operation string const ( - Create Operation = "create" - Delete Operation = "delete" - Update Operation = "update" + OperationCreate Operation = "create" + OperationDelete Operation = "delete" + OperationUpdate Operation = "update" ) type PermissionRequestKind string const ( - CustomTool PermissionRequestKind = "custom-tool" - Hook PermissionRequestKind = "hook" - KindShell PermissionRequestKind = "shell" - MCP PermissionRequestKind = "mcp" - Memory PermissionRequestKind = "memory" - Read PermissionRequestKind = "read" - URL PermissionRequestKind = "url" - Write PermissionRequestKind = "write" + PermissionRequestKindCustomTool PermissionRequestKind = "custom-tool" + PermissionRequestKindHook PermissionRequestKind = "hook" + PermissionRequestKindShell PermissionRequestKind = "shell" + PermissionRequestKindURL PermissionRequestKind = "url" + PermissionRequestKindMcp PermissionRequestKind = "mcp" + PermissionRequestKindMemory PermissionRequestKind = "memory" + PermissionRequestKindRead PermissionRequestKind = "read" + PermissionRequestKindWrite PermissionRequestKind = "write" ) type RequestedSchemaType string const ( - Object RequestedSchemaType = "object" + RequestedSchemaTypeObject RequestedSchemaType = "object" ) // Theme variant this icon is intended for type Theme string const ( - Dark Theme = "dark" - Light Theme = "light" + ThemeDark Theme = "dark" + ThemeLight Theme = "light" ) type ContentType string const ( - Audio ContentType = "audio" - Image ContentType = "image" - Resource ContentType = "resource" - ResourceLink ContentType = "resource_link" - Terminal ContentType = "terminal" - Text ContentType = "text" + ContentTypeAudio ContentType = "audio" + ContentTypeImage ContentType = "image" + ContentTypeResource ContentType = "resource" + ContentTypeResourceLink ContentType = "resource_link" + ContentTypeTerminal ContentType = "terminal" + ContentTypeText ContentType = "text" ) // The outcome of the permission request type ResultKind string const ( - Approved ResultKind = "approved" - DeniedByContentExclusionPolicy ResultKind = "denied-by-content-exclusion-policy" - DeniedByRules ResultKind = "denied-by-rules" - DeniedInteractivelyByUser ResultKind = "denied-interactively-by-user" - DeniedNoApprovalRuleAndCouldNotRequestFromUser ResultKind = "denied-no-approval-rule-and-could-not-request-from-user" + ResultKindApproved ResultKind = "approved" + ResultKindDeniedByContentExclusionPolicy ResultKind = "denied-by-content-exclusion-policy" + ResultKindDeniedByRules ResultKind = "denied-by-rules" + ResultKindDeniedInteractivelyByUser ResultKind = "denied-interactively-by-user" + ResultKindDeniedNoApprovalRuleAndCouldNotRequestFromUser ResultKind = "denied-no-approval-rule-and-could-not-request-from-user" ) // Message role: "system" for system prompts, "developer" for developer-injected instructions type Role string const ( - Developer Role = "developer" - RoleSystem Role = "system" + RoleDeveloper Role = "developer" + RoleSystem Role = "system" ) -// Whether the session ended normally ("routine") or due to a crash/fatal error ("error") -type ShutdownType string +// Connection status: connected, failed, pending, disabled, or not_configured +// +// New connection status: connected, failed, pending, disabled, or not_configured +type ServerStatus string const ( - Error ShutdownType = "error" - Routine ShutdownType = "routine" + ServerStatusConnected ServerStatus = "connected" + ServerStatusDisabled ServerStatus = "disabled" + ServerStatusNotConfigured ServerStatus = "not_configured" + ServerStatusPending ServerStatus = "pending" + ServerStatusFailed ServerStatus = "failed" ) -// Origin of this message, used for timeline filtering and telemetry (e.g., "user", -// "autopilot", "skill", or "command") -type Source string +// Whether the session ended normally ("routine") or due to a crash/fatal error ("error") +type ShutdownType string const ( - Command Source = "command" - ImmediatePrompt Source = "immediate-prompt" - JITInstruction Source = "jit-instruction" - Other Source = "other" - Skill Source = "skill" - SnippyBlocking Source = "snippy-blocking" - SourceAutopilot Source = "autopilot" - SourceSystem Source = "system" - ThinkingExhaustedContinuation Source = "thinking-exhausted-continuation" - User Source = "user" + ShutdownTypeError ShutdownType = "error" + ShutdownTypeRoutine ShutdownType = "routine" ) // Origin type of the session being handed off type SourceType string const ( - Local SourceType = "local" - Remote SourceType = "remote" + SourceTypeLocal SourceType = "local" + SourceTypeRemote SourceType = "remote" ) // Tool call type: "function" for standard tool calls, "custom" for grammar-based tool @@ -1354,74 +1512,82 @@ const ( type ToolRequestType string const ( - Custom ToolRequestType = "custom" - Function ToolRequestType = "function" + ToolRequestTypeCustom ToolRequestType = "custom" + ToolRequestTypeFunction ToolRequestType = "function" ) type SessionEventType string const ( - Abort SessionEventType = "abort" - AssistantIntent SessionEventType = "assistant.intent" - AssistantMessage SessionEventType = "assistant.message" - AssistantMessageDelta SessionEventType = "assistant.message_delta" - AssistantReasoning SessionEventType = "assistant.reasoning" - AssistantReasoningDelta SessionEventType = "assistant.reasoning_delta" - AssistantStreamingDelta SessionEventType = "assistant.streaming_delta" - AssistantTurnEnd SessionEventType = "assistant.turn_end" - AssistantTurnStart SessionEventType = "assistant.turn_start" - AssistantUsage SessionEventType = "assistant.usage" - CommandCompleted SessionEventType = "command.completed" - CommandQueued SessionEventType = "command.queued" - ElicitationCompleted SessionEventType = "elicitation.completed" - ElicitationRequested SessionEventType = "elicitation.requested" - ExitPlanModeCompleted SessionEventType = "exit_plan_mode.completed" - ExitPlanModeRequested SessionEventType = "exit_plan_mode.requested" - ExternalToolCompleted SessionEventType = "external_tool.completed" - ExternalToolRequested SessionEventType = "external_tool.requested" - HookEnd SessionEventType = "hook.end" - HookStart SessionEventType = "hook.start" - PendingMessagesModified SessionEventType = "pending_messages.modified" - PermissionCompleted SessionEventType = "permission.completed" - PermissionRequested SessionEventType = "permission.requested" - SessionBackgroundTasksChanged SessionEventType = "session.background_tasks_changed" - SessionCompactionComplete SessionEventType = "session.compaction_complete" - SessionCompactionStart SessionEventType = "session.compaction_start" - SessionContextChanged SessionEventType = "session.context_changed" - SessionError SessionEventType = "session.error" - SessionHandoff SessionEventType = "session.handoff" - SessionIdle SessionEventType = "session.idle" - SessionInfo SessionEventType = "session.info" - SessionModeChanged SessionEventType = "session.mode_changed" - SessionModelChange SessionEventType = "session.model_change" - SessionPlanChanged SessionEventType = "session.plan_changed" - SessionResume SessionEventType = "session.resume" - SessionShutdown SessionEventType = "session.shutdown" - SessionSnapshotRewind SessionEventType = "session.snapshot_rewind" - SessionStart SessionEventType = "session.start" - SessionTaskComplete SessionEventType = "session.task_complete" - SessionTitleChanged SessionEventType = "session.title_changed" - SessionToolsUpdated SessionEventType = "session.tools_updated" - SessionTruncation SessionEventType = "session.truncation" - SessionUsageInfo SessionEventType = "session.usage_info" - SessionWarning SessionEventType = "session.warning" - SessionWorkspaceFileChanged SessionEventType = "session.workspace_file_changed" - SkillInvoked SessionEventType = "skill.invoked" - SubagentCompleted SessionEventType = "subagent.completed" - SubagentDeselected SessionEventType = "subagent.deselected" - SubagentFailed SessionEventType = "subagent.failed" - SubagentSelected SessionEventType = "subagent.selected" - SubagentStarted SessionEventType = "subagent.started" - SystemMessage SessionEventType = "system.message" - SystemNotification SessionEventType = "system.notification" - ToolExecutionComplete SessionEventType = "tool.execution_complete" - ToolExecutionPartialResult SessionEventType = "tool.execution_partial_result" - ToolExecutionProgress SessionEventType = "tool.execution_progress" - ToolExecutionStart SessionEventType = "tool.execution_start" - ToolUserRequested SessionEventType = "tool.user_requested" - UserInputCompleted SessionEventType = "user_input.completed" - UserInputRequested SessionEventType = "user_input.requested" - UserMessage SessionEventType = "user.message" + SessionEventTypeAbort SessionEventType = "abort" + SessionEventTypeAssistantIntent SessionEventType = "assistant.intent" + SessionEventTypeAssistantMessage SessionEventType = "assistant.message" + SessionEventTypeAssistantMessageDelta SessionEventType = "assistant.message_delta" + SessionEventTypeAssistantReasoning SessionEventType = "assistant.reasoning" + SessionEventTypeAssistantReasoningDelta SessionEventType = "assistant.reasoning_delta" + SessionEventTypeAssistantStreamingDelta SessionEventType = "assistant.streaming_delta" + SessionEventTypeAssistantTurnEnd SessionEventType = "assistant.turn_end" + SessionEventTypeAssistantTurnStart SessionEventType = "assistant.turn_start" + SessionEventTypeAssistantUsage SessionEventType = "assistant.usage" + SessionEventTypeCommandCompleted SessionEventType = "command.completed" + SessionEventTypeCommandExecute SessionEventType = "command.execute" + SessionEventTypeCommandQueued SessionEventType = "command.queued" + SessionEventTypeCommandsChanged SessionEventType = "commands.changed" + SessionEventTypeElicitationCompleted SessionEventType = "elicitation.completed" + SessionEventTypeElicitationRequested SessionEventType = "elicitation.requested" + SessionEventTypeExitPlanModeCompleted SessionEventType = "exit_plan_mode.completed" + SessionEventTypeExitPlanModeRequested SessionEventType = "exit_plan_mode.requested" + SessionEventTypeExternalToolCompleted SessionEventType = "external_tool.completed" + SessionEventTypeExternalToolRequested SessionEventType = "external_tool.requested" + SessionEventTypeHookEnd SessionEventType = "hook.end" + SessionEventTypeHookStart SessionEventType = "hook.start" + SessionEventTypeMcpOauthCompleted SessionEventType = "mcp.oauth_completed" + SessionEventTypeMcpOauthRequired SessionEventType = "mcp.oauth_required" + SessionEventTypePendingMessagesModified SessionEventType = "pending_messages.modified" + SessionEventTypePermissionCompleted SessionEventType = "permission.completed" + SessionEventTypePermissionRequested SessionEventType = "permission.requested" + SessionEventTypeSessionBackgroundTasksChanged SessionEventType = "session.background_tasks_changed" + SessionEventTypeSessionCompactionComplete SessionEventType = "session.compaction_complete" + SessionEventTypeSessionCompactionStart SessionEventType = "session.compaction_start" + SessionEventTypeSessionContextChanged SessionEventType = "session.context_changed" + SessionEventTypeSessionError SessionEventType = "session.error" + SessionEventTypeSessionExtensionsLoaded SessionEventType = "session.extensions_loaded" + SessionEventTypeSessionHandoff SessionEventType = "session.handoff" + SessionEventTypeSessionIdle SessionEventType = "session.idle" + SessionEventTypeSessionInfo SessionEventType = "session.info" + SessionEventTypeSessionMcpServerStatusChanged SessionEventType = "session.mcp_server_status_changed" + SessionEventTypeSessionMcpServersLoaded SessionEventType = "session.mcp_servers_loaded" + SessionEventTypeSessionModeChanged SessionEventType = "session.mode_changed" + SessionEventTypeSessionModelChange SessionEventType = "session.model_change" + SessionEventTypeSessionPlanChanged SessionEventType = "session.plan_changed" + SessionEventTypeSessionResume SessionEventType = "session.resume" + SessionEventTypeSessionShutdown SessionEventType = "session.shutdown" + SessionEventTypeSessionSkillsLoaded SessionEventType = "session.skills_loaded" + SessionEventTypeSessionSnapshotRewind SessionEventType = "session.snapshot_rewind" + SessionEventTypeSessionStart SessionEventType = "session.start" + SessionEventTypeSessionTaskComplete SessionEventType = "session.task_complete" + SessionEventTypeSessionTitleChanged SessionEventType = "session.title_changed" + SessionEventTypeSessionToolsUpdated SessionEventType = "session.tools_updated" + SessionEventTypeSessionTruncation SessionEventType = "session.truncation" + SessionEventTypeSessionUsageInfo SessionEventType = "session.usage_info" + SessionEventTypeSessionWarning SessionEventType = "session.warning" + SessionEventTypeSessionWorkspaceFileChanged SessionEventType = "session.workspace_file_changed" + SessionEventTypeSkillInvoked SessionEventType = "skill.invoked" + SessionEventTypeSubagentCompleted SessionEventType = "subagent.completed" + SessionEventTypeSubagentDeselected SessionEventType = "subagent.deselected" + SessionEventTypeSubagentFailed SessionEventType = "subagent.failed" + SessionEventTypeSubagentSelected SessionEventType = "subagent.selected" + SessionEventTypeSubagentStarted SessionEventType = "subagent.started" + SessionEventTypeSystemMessage SessionEventType = "system.message" + SessionEventTypeSystemNotification SessionEventType = "system.notification" + SessionEventTypeToolExecutionComplete SessionEventType = "tool.execution_complete" + SessionEventTypeToolExecutionPartialResult SessionEventType = "tool.execution_partial_result" + SessionEventTypeToolExecutionProgress SessionEventType = "tool.execution_progress" + SessionEventTypeToolExecutionStart SessionEventType = "tool.execution_start" + SessionEventTypeToolUserRequested SessionEventType = "tool.user_requested" + SessionEventTypeUserInputCompleted SessionEventType = "user_input.completed" + SessionEventTypeUserInputRequested SessionEventType = "user_input.requested" + SessionEventTypeUserMessage SessionEventType = "user.message" ) type ContextUnion struct { diff --git a/go/internal/e2e/agent_and_compact_rpc_test.go b/go/internal/e2e/agent_and_compact_rpc_test.go index 338f4da67..cbd52a326 100644 --- a/go/internal/e2e/agent_and_compact_rpc_test.go +++ b/go/internal/e2e/agent_and_compact_rpc_test.go @@ -215,7 +215,7 @@ func TestAgentSelectionRpc(t *testing.T) { } }) - t.Run("should return empty list when no custom agents configured", func(t *testing.T) { + t.Run("should return no custom agents when none configured", func(t *testing.T) { client := copilot.NewClient(&copilot.ClientOptions{ CLIPath: cliPath, UseStdio: copilot.Bool(true), @@ -238,8 +238,13 @@ func TestAgentSelectionRpc(t *testing.T) { t.Fatalf("Failed to list agents: %v", err) } - if len(result.Agents) != 0 { - t.Errorf("Expected empty agent list, got %d agents", len(result.Agents)) + // The CLI may return built-in/default agents even when no custom agents + // are configured, so just verify none of the known custom agent names appear. + customNames := map[string]bool{"test-agent": true, "another-agent": true} + for _, agent := range result.Agents { + if customNames[agent.Name] { + t.Errorf("Expected no custom agents, but found %q", agent.Name) + } } if err := client.Stop(); err != nil { diff --git a/go/internal/e2e/compaction_test.go b/go/internal/e2e/compaction_test.go index aee80704d..888ab2aa9 100644 --- a/go/internal/e2e/compaction_test.go +++ b/go/internal/e2e/compaction_test.go @@ -36,10 +36,10 @@ func TestCompaction(t *testing.T) { var compactionCompleteEvents []copilot.SessionEvent session.On(func(event copilot.SessionEvent) { - if event.Type == copilot.SessionCompactionStart { + if event.Type == copilot.SessionEventTypeSessionCompactionStart { compactionStartEvents = append(compactionStartEvents, event) } - if event.Type == copilot.SessionCompactionComplete { + if event.Type == copilot.SessionEventTypeSessionCompactionComplete { compactionCompleteEvents = append(compactionCompleteEvents, event) } }) @@ -105,7 +105,7 @@ func TestCompaction(t *testing.T) { var compactionEvents []copilot.SessionEvent session.On(func(event copilot.SessionEvent) { - if event.Type == copilot.SessionCompactionStart || event.Type == copilot.SessionCompactionComplete { + if event.Type == copilot.SessionEventTypeSessionCompactionStart || event.Type == copilot.SessionEventTypeSessionCompactionComplete { compactionEvents = append(compactionEvents, event) } }) diff --git a/go/internal/e2e/multi_client_test.go b/go/internal/e2e/multi_client_test.go index 9571ab58e..3c7dc34c3 100644 --- a/go/internal/e2e/multi_client_test.go +++ b/go/internal/e2e/multi_client_test.go @@ -79,13 +79,13 @@ func TestMultiClient(t *testing.T) { client2Completed := make(chan struct{}, 1) session1.On(func(event copilot.SessionEvent) { - if event.Type == copilot.ExternalToolRequested { + if event.Type == copilot.SessionEventTypeExternalToolRequested { select { case client1Requested <- struct{}{}: default: } } - if event.Type == copilot.ExternalToolCompleted { + if event.Type == copilot.SessionEventTypeExternalToolCompleted { select { case client1Completed <- struct{}{}: default: @@ -93,13 +93,13 @@ func TestMultiClient(t *testing.T) { } }) session2.On(func(event copilot.SessionEvent) { - if event.Type == copilot.ExternalToolRequested { + if event.Type == copilot.SessionEventTypeExternalToolRequested { select { case client2Requested <- struct{}{}: default: } } - if event.Type == copilot.ExternalToolCompleted { + if event.Type == copilot.SessionEventTypeExternalToolCompleted { select { case client2Completed <- struct{}{}: default: @@ -120,7 +120,7 @@ func TestMultiClient(t *testing.T) { } // Wait for all broadcast events to arrive on both clients - timeout := time.After(10 * time.Second) + timeout := time.After(30 * time.Second) for _, ch := range []chan struct{}{client1Requested, client2Requested, client1Completed, client2Completed} { select { case <-ch: @@ -197,10 +197,10 @@ func TestMultiClient(t *testing.T) { // Both clients should have seen permission.requested events mu1.Lock() - c1PermRequested := filterEventsByType(client1Events, copilot.PermissionRequested) + c1PermRequested := filterEventsByType(client1Events, copilot.SessionEventTypePermissionRequested) mu1.Unlock() mu2.Lock() - c2PermRequested := filterEventsByType(client2Events, copilot.PermissionRequested) + c2PermRequested := filterEventsByType(client2Events, copilot.SessionEventTypePermissionRequested) mu2.Unlock() if len(c1PermRequested) == 0 { @@ -212,10 +212,10 @@ func TestMultiClient(t *testing.T) { // Both clients should have seen permission.completed events with approved result mu1.Lock() - c1PermCompleted := filterEventsByType(client1Events, copilot.PermissionCompleted) + c1PermCompleted := filterEventsByType(client1Events, copilot.SessionEventTypePermissionCompleted) mu1.Unlock() mu2.Lock() - c2PermCompleted := filterEventsByType(client2Events, copilot.PermissionCompleted) + c2PermCompleted := filterEventsByType(client2Events, copilot.SessionEventTypePermissionCompleted) mu2.Unlock() if len(c1PermCompleted) == 0 { @@ -293,10 +293,10 @@ func TestMultiClient(t *testing.T) { // Both clients should have seen permission.requested events mu1.Lock() - c1PermRequested := filterEventsByType(client1Events, copilot.PermissionRequested) + c1PermRequested := filterEventsByType(client1Events, copilot.SessionEventTypePermissionRequested) mu1.Unlock() mu2.Lock() - c2PermRequested := filterEventsByType(client2Events, copilot.PermissionRequested) + c2PermRequested := filterEventsByType(client2Events, copilot.SessionEventTypePermissionRequested) mu2.Unlock() if len(c1PermRequested) == 0 { @@ -308,10 +308,10 @@ func TestMultiClient(t *testing.T) { // Both clients should see the denial in the completed event mu1.Lock() - c1PermCompleted := filterEventsByType(client1Events, copilot.PermissionCompleted) + c1PermCompleted := filterEventsByType(client1Events, copilot.SessionEventTypePermissionCompleted) mu1.Unlock() mu2.Lock() - c2PermCompleted := filterEventsByType(client2Events, copilot.PermissionCompleted) + c2PermCompleted := filterEventsByType(client2Events, copilot.SessionEventTypePermissionCompleted) mu2.Unlock() if len(c1PermCompleted) == 0 { diff --git a/go/internal/e2e/permissions_test.go b/go/internal/e2e/permissions_test.go index 328e7e788..98f620043 100644 --- a/go/internal/e2e/permissions_test.go +++ b/go/internal/e2e/permissions_test.go @@ -173,7 +173,7 @@ func TestPermissions(t *testing.T) { permissionDenied := false session.On(func(event copilot.SessionEvent) { - if event.Type == copilot.ToolExecutionComplete && + if event.Type == copilot.SessionEventTypeToolExecutionComplete && event.Data.Success != nil && !*event.Data.Success && event.Data.Error != nil && event.Data.Error.ErrorClass != nil && strings.Contains(event.Data.Error.ErrorClass.Message, "Permission denied") { @@ -223,7 +223,7 @@ func TestPermissions(t *testing.T) { permissionDenied := false session2.On(func(event copilot.SessionEvent) { - if event.Type == copilot.ToolExecutionComplete && + if event.Type == copilot.SessionEventTypeToolExecutionComplete && event.Data.Success != nil && !*event.Data.Success && event.Data.Error != nil && event.Data.Error.ErrorClass != nil && strings.Contains(event.Data.Error.ErrorClass.Message, "Permission denied") { diff --git a/go/internal/e2e/rpc_test.go b/go/internal/e2e/rpc_test.go index ebcbe1130..3d69b97ad 100644 --- a/go/internal/e2e/rpc_test.go +++ b/go/internal/e2e/rpc_test.go @@ -219,16 +219,16 @@ func TestSessionRpc(t *testing.T) { if err != nil { t.Fatalf("Failed to get mode: %v", err) } - if initial.Mode != rpc.Interactive { + if initial.Mode != rpc.ModeInteractive { t.Errorf("Expected initial mode 'interactive', got %q", initial.Mode) } // Switch to plan mode - planResult, err := session.RPC.Mode.Set(t.Context(), &rpc.SessionModeSetParams{Mode: rpc.Plan}) + planResult, err := session.RPC.Mode.Set(t.Context(), &rpc.SessionModeSetParams{Mode: rpc.ModePlan}) if err != nil { t.Fatalf("Failed to set mode to plan: %v", err) } - if planResult.Mode != rpc.Plan { + if planResult.Mode != rpc.ModePlan { t.Errorf("Expected mode 'plan', got %q", planResult.Mode) } @@ -237,16 +237,16 @@ func TestSessionRpc(t *testing.T) { if err != nil { t.Fatalf("Failed to get mode after plan: %v", err) } - if afterPlan.Mode != rpc.Plan { + if afterPlan.Mode != rpc.ModePlan { t.Errorf("Expected mode 'plan' after set, got %q", afterPlan.Mode) } // Switch back to interactive - interactiveResult, err := session.RPC.Mode.Set(t.Context(), &rpc.SessionModeSetParams{Mode: rpc.Interactive}) + interactiveResult, err := session.RPC.Mode.Set(t.Context(), &rpc.SessionModeSetParams{Mode: rpc.ModeInteractive}) if err != nil { t.Fatalf("Failed to set mode to interactive: %v", err) } - if interactiveResult.Mode != rpc.Interactive { + if interactiveResult.Mode != rpc.ModeInteractive { t.Errorf("Expected mode 'interactive', got %q", interactiveResult.Mode) } }) diff --git a/go/internal/e2e/session_test.go b/go/internal/e2e/session_test.go index 052ae1580..1eaeacd1e 100644 --- a/go/internal/e2e/session_test.go +++ b/go/internal/e2e/session_test.go @@ -506,7 +506,7 @@ func TestSession(t *testing.T) { toolStartCh := make(chan *copilot.SessionEvent, 1) toolStartErrCh := make(chan error, 1) go func() { - evt, err := testharness.GetNextEventOfType(session, copilot.ToolExecutionStart, 60*time.Second) + evt, err := testharness.GetNextEventOfType(session, copilot.SessionEventTypeToolExecutionStart, 60*time.Second) if err != nil { toolStartErrCh <- err } else { @@ -517,7 +517,7 @@ func TestSession(t *testing.T) { sessionIdleCh := make(chan *copilot.SessionEvent, 1) sessionIdleErrCh := make(chan error, 1) go func() { - evt, err := testharness.GetNextEventOfType(session, copilot.SessionIdle, 60*time.Second) + evt, err := testharness.GetNextEventOfType(session, copilot.SessionEventTypeSessionIdle, 60*time.Second) if err != nil { sessionIdleErrCh <- err } else { @@ -565,7 +565,7 @@ func TestSession(t *testing.T) { // Verify messages contain an abort event hasAbortEvent := false for _, msg := range messages { - if msg.Type == copilot.Abort { + if msg.Type == copilot.SessionEventTypeAbort { hasAbortEvent = true break } @@ -913,7 +913,7 @@ func TestSetModelWithReasoningEffort(t *testing.T) { modelChanged := make(chan copilot.SessionEvent, 1) session.On(func(event copilot.SessionEvent) { - if event.Type == copilot.SessionModelChange { + if event.Type == copilot.SessionEventTypeSessionModelChange { select { case modelChanged <- event: default: @@ -964,7 +964,7 @@ func TestSessionBlobAttachment(t *testing.T) { Prompt: "Describe this image", Attachments: []copilot.Attachment{ { - Type: copilot.Blob, + Type: copilot.AttachmentTypeBlob, Data: &data, MIMEType: &mimeType, DisplayName: &displayName, @@ -1028,7 +1028,7 @@ func TestSessionLog(t *testing.T) { t.Fatalf("Log failed: %v", err) } - evt := waitForEvent(t, &mu, &events, copilot.SessionInfo, "Info message", 5*time.Second) + evt := waitForEvent(t, &mu, &events, copilot.SessionEventTypeSessionInfo, "Info message", 5*time.Second) if evt.Data.InfoType == nil || *evt.Data.InfoType != "notification" { t.Errorf("Expected infoType 'notification', got %v", evt.Data.InfoType) } @@ -1038,11 +1038,11 @@ func TestSessionLog(t *testing.T) { }) t.Run("should log warning message", func(t *testing.T) { - if err := session.Log(t.Context(), "Warning message", &copilot.LogOptions{Level: rpc.Warning}); err != nil { + if err := session.Log(t.Context(), "Warning message", &copilot.LogOptions{Level: rpc.LevelWarning}); err != nil { t.Fatalf("Log failed: %v", err) } - evt := waitForEvent(t, &mu, &events, copilot.SessionWarning, "Warning message", 5*time.Second) + evt := waitForEvent(t, &mu, &events, copilot.SessionEventTypeSessionWarning, "Warning message", 5*time.Second) if evt.Data.WarningType == nil || *evt.Data.WarningType != "notification" { t.Errorf("Expected warningType 'notification', got %v", evt.Data.WarningType) } @@ -1052,11 +1052,11 @@ func TestSessionLog(t *testing.T) { }) t.Run("should log error message", func(t *testing.T) { - if err := session.Log(t.Context(), "Error message", &copilot.LogOptions{Level: rpc.Error}); err != nil { + if err := session.Log(t.Context(), "Error message", &copilot.LogOptions{Level: rpc.LevelError}); err != nil { t.Fatalf("Log failed: %v", err) } - evt := waitForEvent(t, &mu, &events, copilot.SessionError, "Error message", 5*time.Second) + evt := waitForEvent(t, &mu, &events, copilot.SessionEventTypeSessionError, "Error message", 5*time.Second) if evt.Data.ErrorType == nil || *evt.Data.ErrorType != "notification" { t.Errorf("Expected errorType 'notification', got %v", evt.Data.ErrorType) } @@ -1070,7 +1070,7 @@ func TestSessionLog(t *testing.T) { t.Fatalf("Log failed: %v", err) } - evt := waitForEvent(t, &mu, &events, copilot.SessionInfo, "Ephemeral message", 5*time.Second) + evt := waitForEvent(t, &mu, &events, copilot.SessionEventTypeSessionInfo, "Ephemeral message", 5*time.Second) if evt.Data.InfoType == nil || *evt.Data.InfoType != "notification" { t.Errorf("Expected infoType 'notification', got %v", evt.Data.InfoType) } diff --git a/go/internal/e2e/testharness/helper.go b/go/internal/e2e/testharness/helper.go index 05947c806..3b521f330 100644 --- a/go/internal/e2e/testharness/helper.go +++ b/go/internal/e2e/testharness/helper.go @@ -67,7 +67,7 @@ func GetNextEventOfType(session *copilot.Session, eventType copilot.SessionEvent case result <- &event: default: } - case copilot.SessionError: + case copilot.SessionEventTypeSessionError: msg := "session error" if event.Data.Message != nil { msg = *event.Data.Message diff --git a/go/rpc/generated_rpc.go b/go/rpc/generated_rpc.go index 401f38305..b9ba408b5 100644 --- a/go/rpc/generated_rpc.go +++ b/go/rpc/generated_rpc.go @@ -223,10 +223,10 @@ type SessionFleetStartParams struct { // Experimental: SessionAgentListResult is part of an experimental API and may change or be removed. type SessionAgentListResult struct { // Available custom agents - Agents []AgentElement `json:"agents"` + Agents []SessionAgentListResultAgent `json:"agents"` } -type AgentElement struct { +type SessionAgentListResultAgent struct { // Description of the agent's purpose Description string `json:"description"` // Human-readable display name @@ -276,6 +276,161 @@ type SessionAgentSelectParams struct { type SessionAgentDeselectResult struct { } +// Experimental: SessionAgentReloadResult is part of an experimental API and may change or be removed. +type SessionAgentReloadResult struct { + // Reloaded custom agents + Agents []SessionAgentReloadResultAgent `json:"agents"` +} + +type SessionAgentReloadResultAgent struct { + // Description of the agent's purpose + Description string `json:"description"` + // Human-readable display name + DisplayName string `json:"displayName"` + // Unique identifier of the custom agent + Name string `json:"name"` +} + +// Experimental: SessionSkillsListResult is part of an experimental API and may change or be removed. +type SessionSkillsListResult struct { + // Available skills + Skills []Skill `json:"skills"` +} + +type Skill struct { + // Description of what the skill does + Description string `json:"description"` + // Whether the skill is currently enabled + Enabled bool `json:"enabled"` + // Unique identifier for the skill + Name string `json:"name"` + // Absolute path to the skill file + Path *string `json:"path,omitempty"` + // Source location type (e.g., project, personal, plugin) + Source string `json:"source"` + // Whether the skill can be invoked by the user as a slash command + UserInvocable bool `json:"userInvocable"` +} + +// Experimental: SessionSkillsEnableResult is part of an experimental API and may change or be removed. +type SessionSkillsEnableResult struct { +} + +// Experimental: SessionSkillsEnableParams is part of an experimental API and may change or be removed. +type SessionSkillsEnableParams struct { + // Name of the skill to enable + Name string `json:"name"` +} + +// Experimental: SessionSkillsDisableResult is part of an experimental API and may change or be removed. +type SessionSkillsDisableResult struct { +} + +// Experimental: SessionSkillsDisableParams is part of an experimental API and may change or be removed. +type SessionSkillsDisableParams struct { + // Name of the skill to disable + Name string `json:"name"` +} + +// Experimental: SessionSkillsReloadResult is part of an experimental API and may change or be removed. +type SessionSkillsReloadResult struct { +} + +type SessionMCPListResult struct { + // Configured MCP servers + Servers []Server `json:"servers"` +} + +type Server struct { + // Error message if the server failed to connect + Error *string `json:"error,omitempty"` + // Server name (config key) + Name string `json:"name"` + // Configuration source: user, workspace, plugin, or builtin + Source *string `json:"source,omitempty"` + // Connection status: connected, failed, pending, disabled, or not_configured + Status ServerStatus `json:"status"` +} + +type SessionMCPEnableResult struct { +} + +type SessionMCPEnableParams struct { + // Name of the MCP server to enable + ServerName string `json:"serverName"` +} + +type SessionMCPDisableResult struct { +} + +type SessionMCPDisableParams struct { + // Name of the MCP server to disable + ServerName string `json:"serverName"` +} + +type SessionMCPReloadResult struct { +} + +// Experimental: SessionPluginsListResult is part of an experimental API and may change or be removed. +type SessionPluginsListResult struct { + // Installed plugins + Plugins []Plugin `json:"plugins"` +} + +type Plugin struct { + // Whether the plugin is currently enabled + Enabled bool `json:"enabled"` + // Marketplace the plugin came from + Marketplace string `json:"marketplace"` + // Plugin name + Name string `json:"name"` + // Installed version + Version *string `json:"version,omitempty"` +} + +// Experimental: SessionExtensionsListResult is part of an experimental API and may change or be removed. +type SessionExtensionsListResult struct { + // Discovered extensions and their current status + Extensions []Extension `json:"extensions"` +} + +type Extension struct { + // Source-qualified ID (e.g., 'project:my-ext', 'user:auth-helper') + ID string `json:"id"` + // Extension name (directory name) + Name string `json:"name"` + // Process ID if the extension is running + PID *int64 `json:"pid,omitempty"` + // Discovery source: project (.github/extensions/) or user (~/.copilot/extensions/) + Source Source `json:"source"` + // Current status: running, disabled, failed, or starting + Status ExtensionStatus `json:"status"` +} + +// Experimental: SessionExtensionsEnableResult is part of an experimental API and may change or be removed. +type SessionExtensionsEnableResult struct { +} + +// Experimental: SessionExtensionsEnableParams is part of an experimental API and may change or be removed. +type SessionExtensionsEnableParams struct { + // Source-qualified extension ID to enable + ID string `json:"id"` +} + +// Experimental: SessionExtensionsDisableResult is part of an experimental API and may change or be removed. +type SessionExtensionsDisableResult struct { +} + +// Experimental: SessionExtensionsDisableParams is part of an experimental API and may change or be removed. +type SessionExtensionsDisableParams struct { + // Source-qualified extension ID to disable + ID string `json:"id"` +} + +// Experimental: SessionExtensionsReloadResult is part of an experimental API and may change or be removed. +type SessionExtensionsReloadResult struct { +} + // Experimental: SessionCompactionCompactResult is part of an experimental API and may change or be removed. type SessionCompactionCompactResult struct { // Number of messages removed during compaction @@ -304,6 +459,75 @@ type ResultResult struct { ToolTelemetry map[string]interface{} `json:"toolTelemetry,omitempty"` } +type SessionCommandsHandlePendingCommandResult struct { + Success bool `json:"success"` +} + +type SessionCommandsHandlePendingCommandParams struct { + // Error message if the command handler failed + Error *string `json:"error,omitempty"` + // Request ID from the command invocation event + RequestID string `json:"requestId"` +} + +type SessionUIElicitationResult struct { + // The user's response: accept (submitted), decline (rejected), or cancel (dismissed) + Action Action `json:"action"` + // The form values submitted by the user (present when action is 'accept') + Content map[string]*Content `json:"content,omitempty"` +} + +type SessionUIElicitationParams struct { + // Message describing what information is needed from the user + Message string `json:"message"` + // JSON Schema describing the form fields to present to the user + RequestedSchema RequestedSchema `json:"requestedSchema"` +} + +// JSON Schema describing the form fields to present to the user +type RequestedSchema struct { + // Form field definitions, keyed by field name + Properties map[string]Property `json:"properties"` + // List of required field names + Required []string `json:"required,omitempty"` + // Schema type indicator (always 'object') + Type RequestedSchemaType `json:"type"` +} + +type Property struct { + Default *Content `json:"default"` + Description *string `json:"description,omitempty"` + Enum []string `json:"enum,omitempty"` + EnumNames []string `json:"enumNames,omitempty"` + Title *string `json:"title,omitempty"` + Type PropertyType `json:"type"` + OneOf []OneOf `json:"oneOf,omitempty"` + Items *Items `json:"items,omitempty"` + MaxItems *float64 `json:"maxItems,omitempty"` + MinItems *float64 `json:"minItems,omitempty"` + Format *Format `json:"format,omitempty"` + MaxLength *float64 `json:"maxLength,omitempty"` + MinLength *float64 `json:"minLength,omitempty"` + Maximum *float64 `json:"maximum,omitempty"` + Minimum *float64 `json:"minimum,omitempty"` +} + +type Items struct { + Enum []string `json:"enum,omitempty"` + Type *ItemsType `json:"type,omitempty"` + AnyOf []AnyOf `json:"anyOf,omitempty"` +} + +type AnyOf struct { + Const string `json:"const"` + Title string `json:"title"` +} + +type OneOf struct { + Const string `json:"const"` + Title string `json:"title"` +} + type SessionPermissionsHandlePendingPermissionRequestResult struct { // Whether the permission request was handled successfully Success bool `json:"success"` @@ -335,6 +559,8 @@ type SessionLogParams struct { Level *Level `json:"level,omitempty"` // Human-readable message Message string `json:"message"` + // Optional URL the user can open in their browser for more details + URL *string `json:"url,omitempty"` } type SessionShellExecResult struct { @@ -371,19 +597,88 @@ type SessionShellKillParams struct { type Mode string const ( - Autopilot Mode = "autopilot" - Interactive Mode = "interactive" - Plan Mode = "plan" + ModeAutopilot Mode = "autopilot" + ModeInteractive Mode = "interactive" + ModePlan Mode = "plan" +) + +// Connection status: connected, failed, pending, disabled, or not_configured +type ServerStatus string + +const ( + ServerStatusConnected ServerStatus = "connected" + ServerStatusNotConfigured ServerStatus = "not_configured" + ServerStatusPending ServerStatus = "pending" + ServerStatusDisabled ServerStatus = "disabled" + ServerStatusFailed ServerStatus = "failed" +) + +// Discovery source: project (.github/extensions/) or user (~/.copilot/extensions/) +type Source string + +const ( + SourceProject Source = "project" + SourceUser Source = "user" +) + +// Current status: running, disabled, failed, or starting +type ExtensionStatus string + +const ( + ExtensionStatusDisabled ExtensionStatus = "disabled" + ExtensionStatusFailed ExtensionStatus = "failed" + ExtensionStatusRunning ExtensionStatus = "running" + ExtensionStatusStarting ExtensionStatus = "starting" +) + +// The user's response: accept (submitted), decline (rejected), or cancel (dismissed) +type Action string + +const ( + ActionAccept Action = "accept" + ActionCancel Action = "cancel" + ActionDecline Action = "decline" +) + +type Format string + +const ( + FormatDate Format = "date" + FormatDateTime Format = "date-time" + FormatEmail Format = "email" + FormatUri Format = "uri" +) + +type ItemsType string + +const ( + ItemsTypeString ItemsType = "string" +) + +type PropertyType string + +const ( + PropertyTypeArray PropertyType = "array" + PropertyTypeBoolean PropertyType = "boolean" + PropertyTypeString PropertyType = "string" + PropertyTypeInteger PropertyType = "integer" + PropertyTypeNumber PropertyType = "number" +) + +type RequestedSchemaType string + +const ( + RequestedSchemaTypeObject RequestedSchemaType = "object" ) type Kind string const ( - Approved Kind = "approved" - DeniedByContentExclusionPolicy Kind = "denied-by-content-exclusion-policy" - DeniedByRules Kind = "denied-by-rules" - DeniedInteractivelyByUser Kind = "denied-interactively-by-user" - DeniedNoApprovalRuleAndCouldNotRequestFromUser Kind = "denied-no-approval-rule-and-could-not-request-from-user" + KindApproved Kind = "approved" + KindDeniedByContentExclusionPolicy Kind = "denied-by-content-exclusion-policy" + KindDeniedByRules Kind = "denied-by-rules" + KindDeniedInteractivelyByUser Kind = "denied-interactively-by-user" + KindDeniedNoApprovalRuleAndCouldNotRequestFromUser Kind = "denied-no-approval-rule-and-could-not-request-from-user" ) // Log severity level. Determines how the message is displayed in the timeline. Defaults to @@ -391,18 +686,18 @@ const ( type Level string const ( - Error Level = "error" - Info Level = "info" - Warning Level = "warning" + LevelError Level = "error" + LevelInfo Level = "info" + LevelWarning Level = "warning" ) // Signal to send (default: SIGTERM) type Signal string const ( - Sigint Signal = "SIGINT" - Sigkill Signal = "SIGKILL" - Sigterm Signal = "SIGTERM" + SignalSIGINT Signal = "SIGINT" + SignalSIGKILL Signal = "SIGKILL" + SignalSIGTERM Signal = "SIGTERM" ) type ResultUnion struct { @@ -410,6 +705,13 @@ type ResultUnion struct { String *string } +type Content struct { + Bool *bool + Double *float64 + String *string + StringArray []string +} + type ServerModelsRpcApi struct { client *jsonrpc2.Client } @@ -740,6 +1042,230 @@ func (a *AgentRpcApi) Deselect(ctx context.Context) (*SessionAgentDeselectResult return &result, nil } +func (a *AgentRpcApi) Reload(ctx context.Context) (*SessionAgentReloadResult, error) { + req := map[string]interface{}{"sessionId": a.sessionID} + raw, err := a.client.Request("session.agent.reload", req) + if err != nil { + return nil, err + } + var result SessionAgentReloadResult + if err := json.Unmarshal(raw, &result); err != nil { + return nil, err + } + return &result, nil +} + +// Experimental: SkillsRpcApi contains experimental APIs that may change or be removed. +type SkillsRpcApi struct { + client *jsonrpc2.Client + sessionID string +} + +func (a *SkillsRpcApi) List(ctx context.Context) (*SessionSkillsListResult, error) { + req := map[string]interface{}{"sessionId": a.sessionID} + raw, err := a.client.Request("session.skills.list", req) + if err != nil { + return nil, err + } + var result SessionSkillsListResult + if err := json.Unmarshal(raw, &result); err != nil { + return nil, err + } + return &result, nil +} + +func (a *SkillsRpcApi) Enable(ctx context.Context, params *SessionSkillsEnableParams) (*SessionSkillsEnableResult, error) { + req := map[string]interface{}{"sessionId": a.sessionID} + if params != nil { + req["name"] = params.Name + } + raw, err := a.client.Request("session.skills.enable", req) + if err != nil { + return nil, err + } + var result SessionSkillsEnableResult + if err := json.Unmarshal(raw, &result); err != nil { + return nil, err + } + return &result, nil +} + +func (a *SkillsRpcApi) Disable(ctx context.Context, params *SessionSkillsDisableParams) (*SessionSkillsDisableResult, error) { + req := map[string]interface{}{"sessionId": a.sessionID} + if params != nil { + req["name"] = params.Name + } + raw, err := a.client.Request("session.skills.disable", req) + if err != nil { + return nil, err + } + var result SessionSkillsDisableResult + if err := json.Unmarshal(raw, &result); err != nil { + return nil, err + } + return &result, nil +} + +func (a *SkillsRpcApi) Reload(ctx context.Context) (*SessionSkillsReloadResult, error) { + req := map[string]interface{}{"sessionId": a.sessionID} + raw, err := a.client.Request("session.skills.reload", req) + if err != nil { + return nil, err + } + var result SessionSkillsReloadResult + if err := json.Unmarshal(raw, &result); err != nil { + return nil, err + } + return &result, nil +} + +// Experimental: McpRpcApi contains experimental APIs that may change or be removed. +type McpRpcApi struct { + client *jsonrpc2.Client + sessionID string +} + +func (a *McpRpcApi) List(ctx context.Context) (*SessionMCPListResult, error) { + req := map[string]interface{}{"sessionId": a.sessionID} + raw, err := a.client.Request("session.mcp.list", req) + if err != nil { + return nil, err + } + var result SessionMCPListResult + if err := json.Unmarshal(raw, &result); err != nil { + return nil, err + } + return &result, nil +} + +func (a *McpRpcApi) Enable(ctx context.Context, params *SessionMCPEnableParams) (*SessionMCPEnableResult, error) { + req := map[string]interface{}{"sessionId": a.sessionID} + if params != nil { + req["serverName"] = params.ServerName + } + raw, err := a.client.Request("session.mcp.enable", req) + if err != nil { + return nil, err + } + var result SessionMCPEnableResult + if err := json.Unmarshal(raw, &result); err != nil { + return nil, err + } + return &result, nil +} + +func (a *McpRpcApi) Disable(ctx context.Context, params *SessionMCPDisableParams) (*SessionMCPDisableResult, error) { + req := map[string]interface{}{"sessionId": a.sessionID} + if params != nil { + req["serverName"] = params.ServerName + } + raw, err := a.client.Request("session.mcp.disable", req) + if err != nil { + return nil, err + } + var result SessionMCPDisableResult + if err := json.Unmarshal(raw, &result); err != nil { + return nil, err + } + return &result, nil +} + +func (a *McpRpcApi) Reload(ctx context.Context) (*SessionMCPReloadResult, error) { + req := map[string]interface{}{"sessionId": a.sessionID} + raw, err := a.client.Request("session.mcp.reload", req) + if err != nil { + return nil, err + } + var result SessionMCPReloadResult + if err := json.Unmarshal(raw, &result); err != nil { + return nil, err + } + return &result, nil +} + +// Experimental: PluginsRpcApi contains experimental APIs that may change or be removed. +type PluginsRpcApi struct { + client *jsonrpc2.Client + sessionID string +} + +func (a *PluginsRpcApi) List(ctx context.Context) (*SessionPluginsListResult, error) { + req := map[string]interface{}{"sessionId": a.sessionID} + raw, err := a.client.Request("session.plugins.list", req) + if err != nil { + return nil, err + } + var result SessionPluginsListResult + if err := json.Unmarshal(raw, &result); err != nil { + return nil, err + } + return &result, nil +} + +// Experimental: ExtensionsRpcApi contains experimental APIs that may change or be removed. +type ExtensionsRpcApi struct { + client *jsonrpc2.Client + sessionID string +} + +func (a *ExtensionsRpcApi) List(ctx context.Context) (*SessionExtensionsListResult, error) { + req := map[string]interface{}{"sessionId": a.sessionID} + raw, err := a.client.Request("session.extensions.list", req) + if err != nil { + return nil, err + } + var result SessionExtensionsListResult + if err := json.Unmarshal(raw, &result); err != nil { + return nil, err + } + return &result, nil +} + +func (a *ExtensionsRpcApi) Enable(ctx context.Context, params *SessionExtensionsEnableParams) (*SessionExtensionsEnableResult, error) { + req := map[string]interface{}{"sessionId": a.sessionID} + if params != nil { + req["id"] = params.ID + } + raw, err := a.client.Request("session.extensions.enable", req) + if err != nil { + return nil, err + } + var result SessionExtensionsEnableResult + if err := json.Unmarshal(raw, &result); err != nil { + return nil, err + } + return &result, nil +} + +func (a *ExtensionsRpcApi) Disable(ctx context.Context, params *SessionExtensionsDisableParams) (*SessionExtensionsDisableResult, error) { + req := map[string]interface{}{"sessionId": a.sessionID} + if params != nil { + req["id"] = params.ID + } + raw, err := a.client.Request("session.extensions.disable", req) + if err != nil { + return nil, err + } + var result SessionExtensionsDisableResult + if err := json.Unmarshal(raw, &result); err != nil { + return nil, err + } + return &result, nil +} + +func (a *ExtensionsRpcApi) Reload(ctx context.Context) (*SessionExtensionsReloadResult, error) { + req := map[string]interface{}{"sessionId": a.sessionID} + raw, err := a.client.Request("session.extensions.reload", req) + if err != nil { + return nil, err + } + var result SessionExtensionsReloadResult + if err := json.Unmarshal(raw, &result); err != nil { + return nil, err + } + return &result, nil +} + // Experimental: CompactionRpcApi contains experimental APIs that may change or be removed. type CompactionRpcApi struct { client *jsonrpc2.Client @@ -786,6 +1312,52 @@ func (a *ToolsRpcApi) HandlePendingToolCall(ctx context.Context, params *Session return &result, nil } +type CommandsRpcApi struct { + client *jsonrpc2.Client + sessionID string +} + +func (a *CommandsRpcApi) HandlePendingCommand(ctx context.Context, params *SessionCommandsHandlePendingCommandParams) (*SessionCommandsHandlePendingCommandResult, error) { + req := map[string]interface{}{"sessionId": a.sessionID} + if params != nil { + req["requestId"] = params.RequestID + if params.Error != nil { + req["error"] = *params.Error + } + } + raw, err := a.client.Request("session.commands.handlePendingCommand", req) + if err != nil { + return nil, err + } + var result SessionCommandsHandlePendingCommandResult + if err := json.Unmarshal(raw, &result); err != nil { + return nil, err + } + return &result, nil +} + +type UiRpcApi struct { + client *jsonrpc2.Client + sessionID string +} + +func (a *UiRpcApi) Elicitation(ctx context.Context, params *SessionUIElicitationParams) (*SessionUIElicitationResult, error) { + req := map[string]interface{}{"sessionId": a.sessionID} + if params != nil { + req["message"] = params.Message + req["requestedSchema"] = params.RequestedSchema + } + raw, err := a.client.Request("session.ui.elicitation", req) + if err != nil { + return nil, err + } + var result SessionUIElicitationResult + if err := json.Unmarshal(raw, &result); err != nil { + return nil, err + } + return &result, nil +} + type PermissionsRpcApi struct { client *jsonrpc2.Client sessionID string @@ -864,8 +1436,14 @@ type SessionRpc struct { Workspace *WorkspaceRpcApi Fleet *FleetRpcApi Agent *AgentRpcApi + Skills *SkillsRpcApi + Mcp *McpRpcApi + Plugins *PluginsRpcApi + Extensions *ExtensionsRpcApi Compaction *CompactionRpcApi Tools *ToolsRpcApi + Commands *CommandsRpcApi + Ui *UiRpcApi Permissions *PermissionsRpcApi Shell *ShellRpcApi } @@ -880,6 +1458,9 @@ func (a *SessionRpc) Log(ctx context.Context, params *SessionLogParams) (*Sessio if params.Ephemeral != nil { req["ephemeral"] = *params.Ephemeral } + if params.URL != nil { + req["url"] = *params.URL + } } raw, err := a.client.Request("session.log", req) if err != nil { @@ -900,8 +1481,14 @@ func NewSessionRpc(client *jsonrpc2.Client, sessionID string) *SessionRpc { Workspace: &WorkspaceRpcApi{client: client, sessionID: sessionID}, Fleet: &FleetRpcApi{client: client, sessionID: sessionID}, Agent: &AgentRpcApi{client: client, sessionID: sessionID}, + Skills: &SkillsRpcApi{client: client, sessionID: sessionID}, + Mcp: &McpRpcApi{client: client, sessionID: sessionID}, + Plugins: &PluginsRpcApi{client: client, sessionID: sessionID}, + Extensions: &ExtensionsRpcApi{client: client, sessionID: sessionID}, Compaction: &CompactionRpcApi{client: client, sessionID: sessionID}, Tools: &ToolsRpcApi{client: client, sessionID: sessionID}, + Commands: &CommandsRpcApi{client: client, sessionID: sessionID}, + Ui: &UiRpcApi{client: client, sessionID: sessionID}, Permissions: &PermissionsRpcApi{client: client, sessionID: sessionID}, Shell: &ShellRpcApi{client: client, sessionID: sessionID}, } diff --git a/go/samples/chat.go b/go/samples/chat.go index f984f758a..4d5e98d7d 100644 --- a/go/samples/chat.go +++ b/go/samples/chat.go @@ -35,11 +35,11 @@ func main() { session.On(func(event copilot.SessionEvent) { var output string switch event.Type { - case copilot.AssistantReasoning: + case copilot.SessionEventTypeAssistantReasoning: if event.Data.Content != nil { output = fmt.Sprintf("[reasoning: %s]", *event.Data.Content) } - case copilot.ToolExecutionStart: + case copilot.SessionEventTypeToolExecutionStart: if event.Data.ToolName != nil { output = fmt.Sprintf("[tool: %s]", *event.Data.ToolName) } diff --git a/go/session.go b/go/session.go index d2a5785be..107ac9824 100644 --- a/go/session.go +++ b/go/session.go @@ -182,17 +182,17 @@ func (s *Session) SendAndWait(ctx context.Context, options MessageOptions) (*Ses unsubscribe := s.On(func(event SessionEvent) { switch event.Type { - case AssistantMessage: + case SessionEventTypeAssistantMessage: mu.Lock() eventCopy := event lastAssistantMessage = &eventCopy mu.Unlock() - case SessionIdle: + case SessionEventTypeSessionIdle: select { case idleCh <- struct{}{}: default: } - case SessionError: + case SessionEventTypeSessionError: errMsg := "session error" if event.Data.Message != nil { errMsg = *event.Data.Message @@ -501,7 +501,7 @@ func (s *Session) processEvents() { // cause RPC deadlocks. func (s *Session) handleBroadcastEvent(event SessionEvent) { switch event.Type { - case ExternalToolRequested: + case SessionEventTypeExternalToolRequested: requestID := event.Data.RequestID toolName := event.Data.ToolName if requestID == nil || toolName == nil { @@ -524,7 +524,7 @@ func (s *Session) handleBroadcastEvent(event SessionEvent) { } s.executeToolAndRespond(*requestID, *toolName, toolCallID, event.Data.Arguments, handler, tp, ts) - case PermissionRequested: + case SessionEventTypePermissionRequested: requestID := event.Data.RequestID if requestID == nil || event.Data.PermissionRequest == nil { return @@ -585,7 +585,7 @@ func (s *Session) executePermissionAndRespond(requestID string, permissionReques s.RPC.Permissions.HandlePendingPermissionRequest(context.Background(), &rpc.SessionPermissionsHandlePendingPermissionRequestParams{ RequestID: requestID, Result: rpc.SessionPermissionsHandlePendingPermissionRequestParamsResult{ - Kind: rpc.DeniedNoApprovalRuleAndCouldNotRequestFromUser, + Kind: rpc.KindDeniedNoApprovalRuleAndCouldNotRequestFromUser, }, }) } @@ -600,7 +600,7 @@ func (s *Session) executePermissionAndRespond(requestID string, permissionReques s.RPC.Permissions.HandlePendingPermissionRequest(context.Background(), &rpc.SessionPermissionsHandlePendingPermissionRequestParams{ RequestID: requestID, Result: rpc.SessionPermissionsHandlePendingPermissionRequestParamsResult{ - Kind: rpc.DeniedNoApprovalRuleAndCouldNotRequestFromUser, + Kind: rpc.KindDeniedNoApprovalRuleAndCouldNotRequestFromUser, }, }) return @@ -770,8 +770,8 @@ func (s *Session) SetModel(ctx context.Context, model string, opts ...SetModelOp // LogOptions configures optional parameters for [Session.Log]. type LogOptions struct { - // Level sets the log severity. Valid values are [rpc.Info] (default), - // [rpc.Warning], and [rpc.Error]. + // Level sets the log severity. Valid values are [rpc.LevelInfo] (default), + // [rpc.LevelWarning], and [rpc.LevelError]. Level rpc.Level // Ephemeral marks the message as transient so it is not persisted // to the session event log on disk. When nil the server decides the @@ -791,7 +791,7 @@ type LogOptions struct { // session.Log(ctx, "Processing started") // // // Warning with options -// session.Log(ctx, "Rate limit approaching", &copilot.LogOptions{Level: rpc.Warning}) +// session.Log(ctx, "Rate limit approaching", &copilot.LogOptions{Level: rpc.LevelWarning}) // // // Ephemeral message (not persisted) // session.Log(ctx, "Working...", &copilot.LogOptions{Ephemeral: copilot.Bool(true)}) diff --git a/nodejs/package-lock.json b/nodejs/package-lock.json index 0952122f0..fd56aa84b 100644 --- a/nodejs/package-lock.json +++ b/nodejs/package-lock.json @@ -9,7 +9,7 @@ "version": "0.1.8", "license": "MIT", "dependencies": { - "@github/copilot": "^1.0.4", + "@github/copilot": "^1.0.10-0", "vscode-jsonrpc": "^8.2.1", "zod": "^4.3.6" }, @@ -662,26 +662,26 @@ } }, "node_modules/@github/copilot": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/@github/copilot/-/copilot-1.0.4.tgz", - "integrity": "sha512-IpPg+zYplLu4F4lmatEDdR/1Y/jJ9cGWt89m3K3H4YSfYrZ5Go4UlM28llulYCG7sVdQeIGauQN1/KiBI/Rocg==", + "version": "1.0.10-0", + "resolved": "https://registry.npmjs.org/@github/copilot/-/copilot-1.0.10-0.tgz", + "integrity": "sha512-LmVe3yVDamZc4cbZeyprZ6WjTME9Z4UcB5YWnEagtXJ19KP5PBKbBZVG7pZnQHL2/IHZ/dqcZW3IHMgYDoqDvg==", "license": "SEE LICENSE IN LICENSE.md", "bin": { "copilot": "npm-loader.js" }, "optionalDependencies": { - "@github/copilot-darwin-arm64": "1.0.4", - "@github/copilot-darwin-x64": "1.0.4", - "@github/copilot-linux-arm64": "1.0.4", - "@github/copilot-linux-x64": "1.0.4", - "@github/copilot-win32-arm64": "1.0.4", - "@github/copilot-win32-x64": "1.0.4" + "@github/copilot-darwin-arm64": "1.0.10-0", + "@github/copilot-darwin-x64": "1.0.10-0", + "@github/copilot-linux-arm64": "1.0.10-0", + "@github/copilot-linux-x64": "1.0.10-0", + "@github/copilot-win32-arm64": "1.0.10-0", + "@github/copilot-win32-x64": "1.0.10-0" } }, "node_modules/@github/copilot-darwin-arm64": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/@github/copilot-darwin-arm64/-/copilot-darwin-arm64-1.0.4.tgz", - "integrity": "sha512-/YGGhv6cp0ItolsF0HsLq2KmesA4atn0IEYApBs770fzJ8OP2pkOEzrxo3gWU3wc7fHF2uDB1RrJEZ7QSFLdEQ==", + "version": "1.0.10-0", + "resolved": "https://registry.npmjs.org/@github/copilot-darwin-arm64/-/copilot-darwin-arm64-1.0.10-0.tgz", + "integrity": "sha512-u5CbflcTpvc4E48E0jrqbN3Y5hWzValMs21RR6L+GDjQpPI2pvDeUWAJZ03Y7qQ2Uk3KZ+hOIJWJvje9VHxrDQ==", "cpu": [ "arm64" ], @@ -695,9 +695,9 @@ } }, "node_modules/@github/copilot-darwin-x64": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/@github/copilot-darwin-x64/-/copilot-darwin-x64-1.0.4.tgz", - "integrity": "sha512-gwn2QjZbc1SqPVSAtDMesU1NopyHZT8Qsn37xPfznpV9s94KVyX4TTiDZaUwfnI0wr8kVHBL46RPLNz6I8kR9A==", + "version": "1.0.10-0", + "resolved": "https://registry.npmjs.org/@github/copilot-darwin-x64/-/copilot-darwin-x64-1.0.10-0.tgz", + "integrity": "sha512-4y5OXhAfWX+il9slhrq7v8ONzq+Hpw46ktnz7l1fAZKdmn+dzmFVCvr6pJPr5Az78cAKBuN+Gt4eeSNaxuKCmA==", "cpu": [ "x64" ], @@ -711,9 +711,9 @@ } }, "node_modules/@github/copilot-linux-arm64": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/@github/copilot-linux-arm64/-/copilot-linux-arm64-1.0.4.tgz", - "integrity": "sha512-92vzHKxN55BpI76sP/5fXIXfat1gzAhsq4bNLqLENGfZyMP/25OiVihCZuQHnvxzXaHBITFGUvtxfdll2kbcng==", + "version": "1.0.10-0", + "resolved": "https://registry.npmjs.org/@github/copilot-linux-arm64/-/copilot-linux-arm64-1.0.10-0.tgz", + "integrity": "sha512-j+Z/ZahEIT5SCblUqOJ2+2glWeIIUPKXXFS5bbu5kFZ9Xyag37FBvTjyxDeB02dpSKKDD4xbMVjcijFbtyr1PA==", "cpu": [ "arm64" ], @@ -727,9 +727,9 @@ } }, "node_modules/@github/copilot-linux-x64": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/@github/copilot-linux-x64/-/copilot-linux-x64-1.0.4.tgz", - "integrity": "sha512-wQvpwf4/VMTnSmWyYzq07Xg18Vxg7aZ5NVkkXqlLTuXRASW0kvCCb5USEtXHHzR7E6rJztkhCjFRE1bZW8jAGw==", + "version": "1.0.10-0", + "resolved": "https://registry.npmjs.org/@github/copilot-linux-x64/-/copilot-linux-x64-1.0.10-0.tgz", + "integrity": "sha512-S8IfuiMZWwnFW1v0vOGHalPIXq/75kL/RpZCYd1sleQA/yztCNNjxH9tNpXsdZnhYrAgU/3hqseWq5hbz8xjxA==", "cpu": [ "x64" ], @@ -743,9 +743,9 @@ } }, "node_modules/@github/copilot-win32-arm64": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/@github/copilot-win32-arm64/-/copilot-win32-arm64-1.0.4.tgz", - "integrity": "sha512-zOvD/5GVxDf0ZdlTkK+m55Vs55xuHNmACX50ZO2N23ZGG2dmkdS4mkruL59XB5ISgrOfeqvnqrwTFHbmPZtLfw==", + "version": "1.0.10-0", + "resolved": "https://registry.npmjs.org/@github/copilot-win32-arm64/-/copilot-win32-arm64-1.0.10-0.tgz", + "integrity": "sha512-6HJErp91fLrwIkoXegLK8SXjHzLgbl9GF+QdOtUGqZ915UUfXcchef0tQjN8u35yNLEW82VnAmft/PJ9Ok2UhQ==", "cpu": [ "arm64" ], @@ -759,9 +759,9 @@ } }, "node_modules/@github/copilot-win32-x64": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/@github/copilot-win32-x64/-/copilot-win32-x64-1.0.4.tgz", - "integrity": "sha512-yQenHMdkV0b77mF6aLM60TuwtNZ592TluptVDF+80Sj2zPfCpLyvrRh2FCIHRtuwTy4BfxETh2hCFHef8E6IOw==", + "version": "1.0.10-0", + "resolved": "https://registry.npmjs.org/@github/copilot-win32-x64/-/copilot-win32-x64-1.0.10-0.tgz", + "integrity": "sha512-AQwZYHoarRACbmPUPmH7gPOEomTAtDusCn65ancI3BoWGj9fzAgZEZ5JSaR3N/VUoXWoEbSe+PcH380ZYwsPag==", "cpu": [ "x64" ], diff --git a/nodejs/package.json b/nodejs/package.json index 6b0d30f2c..7d1822a9c 100644 --- a/nodejs/package.json +++ b/nodejs/package.json @@ -56,7 +56,7 @@ "author": "GitHub", "license": "MIT", "dependencies": { - "@github/copilot": "^1.0.4", + "@github/copilot": "^1.0.10-0", "vscode-jsonrpc": "^8.2.1", "zod": "^4.3.6" }, diff --git a/nodejs/samples/package-lock.json b/nodejs/samples/package-lock.json index 4f93a271c..77daced15 100644 --- a/nodejs/samples/package-lock.json +++ b/nodejs/samples/package-lock.json @@ -18,7 +18,7 @@ "version": "0.1.8", "license": "MIT", "dependencies": { - "@github/copilot": "^1.0.4", + "@github/copilot": "^1.0.10-0", "vscode-jsonrpc": "^8.2.1", "zod": "^4.3.6" }, diff --git a/nodejs/src/generated/rpc.ts b/nodejs/src/generated/rpc.ts index 16907fdba..dadb9e79d 100644 --- a/nodejs/src/generated/rpc.ts +++ b/nodejs/src/generated/rpc.ts @@ -462,6 +462,302 @@ export interface SessionAgentDeselectParams { sessionId: string; } +/** @experimental */ +export interface SessionAgentReloadResult { + /** + * Reloaded custom agents + */ + agents: { + /** + * Unique identifier of the custom agent + */ + name: string; + /** + * Human-readable display name + */ + displayName: string; + /** + * Description of the agent's purpose + */ + description: string; + }[]; +} + +/** @experimental */ +export interface SessionAgentReloadParams { + /** + * Target session identifier + */ + sessionId: string; +} + +/** @experimental */ +export interface SessionSkillsListResult { + /** + * Available skills + */ + skills: { + /** + * Unique identifier for the skill + */ + name: string; + /** + * Description of what the skill does + */ + description: string; + /** + * Source location type (e.g., project, personal, plugin) + */ + source: string; + /** + * Whether the skill can be invoked by the user as a slash command + */ + userInvocable: boolean; + /** + * Whether the skill is currently enabled + */ + enabled: boolean; + /** + * Absolute path to the skill file + */ + path?: string; + }[]; +} + +/** @experimental */ +export interface SessionSkillsListParams { + /** + * Target session identifier + */ + sessionId: string; +} + +/** @experimental */ +export interface SessionSkillsEnableResult {} + +/** @experimental */ +export interface SessionSkillsEnableParams { + /** + * Target session identifier + */ + sessionId: string; + /** + * Name of the skill to enable + */ + name: string; +} + +/** @experimental */ +export interface SessionSkillsDisableResult {} + +/** @experimental */ +export interface SessionSkillsDisableParams { + /** + * Target session identifier + */ + sessionId: string; + /** + * Name of the skill to disable + */ + name: string; +} + +/** @experimental */ +export interface SessionSkillsReloadResult {} + +/** @experimental */ +export interface SessionSkillsReloadParams { + /** + * Target session identifier + */ + sessionId: string; +} + +/** @experimental */ +export interface SessionMcpListResult { + /** + * Configured MCP servers + */ + servers: { + /** + * Server name (config key) + */ + name: string; + /** + * Connection status: connected, failed, pending, disabled, or not_configured + */ + status: "connected" | "failed" | "pending" | "disabled" | "not_configured"; + /** + * Configuration source: user, workspace, plugin, or builtin + */ + source?: string; + /** + * Error message if the server failed to connect + */ + error?: string; + }[]; +} + +/** @experimental */ +export interface SessionMcpListParams { + /** + * Target session identifier + */ + sessionId: string; +} + +/** @experimental */ +export interface SessionMcpEnableResult {} + +/** @experimental */ +export interface SessionMcpEnableParams { + /** + * Target session identifier + */ + sessionId: string; + /** + * Name of the MCP server to enable + */ + serverName: string; +} + +/** @experimental */ +export interface SessionMcpDisableResult {} + +/** @experimental */ +export interface SessionMcpDisableParams { + /** + * Target session identifier + */ + sessionId: string; + /** + * Name of the MCP server to disable + */ + serverName: string; +} + +/** @experimental */ +export interface SessionMcpReloadResult {} + +/** @experimental */ +export interface SessionMcpReloadParams { + /** + * Target session identifier + */ + sessionId: string; +} + +/** @experimental */ +export interface SessionPluginsListResult { + /** + * Installed plugins + */ + plugins: { + /** + * Plugin name + */ + name: string; + /** + * Marketplace the plugin came from + */ + marketplace: string; + /** + * Installed version + */ + version?: string; + /** + * Whether the plugin is currently enabled + */ + enabled: boolean; + }[]; +} + +/** @experimental */ +export interface SessionPluginsListParams { + /** + * Target session identifier + */ + sessionId: string; +} + +/** @experimental */ +export interface SessionExtensionsListResult { + /** + * Discovered extensions and their current status + */ + extensions: { + /** + * Source-qualified ID (e.g., 'project:my-ext', 'user:auth-helper') + */ + id: string; + /** + * Extension name (directory name) + */ + name: string; + /** + * Discovery source: project (.github/extensions/) or user (~/.copilot/extensions/) + */ + source: "project" | "user"; + /** + * Current status: running, disabled, failed, or starting + */ + status: "running" | "disabled" | "failed" | "starting"; + /** + * Process ID if the extension is running + */ + pid?: number; + }[]; +} + +/** @experimental */ +export interface SessionExtensionsListParams { + /** + * Target session identifier + */ + sessionId: string; +} + +/** @experimental */ +export interface SessionExtensionsEnableResult {} + +/** @experimental */ +export interface SessionExtensionsEnableParams { + /** + * Target session identifier + */ + sessionId: string; + /** + * Source-qualified extension ID to enable + */ + id: string; +} + +/** @experimental */ +export interface SessionExtensionsDisableResult {} + +/** @experimental */ +export interface SessionExtensionsDisableParams { + /** + * Target session identifier + */ + sessionId: string; + /** + * Source-qualified extension ID to disable + */ + id: string; +} + +/** @experimental */ +export interface SessionExtensionsReloadResult {} + +/** @experimental */ +export interface SessionExtensionsReloadParams { + /** + * Target session identifier + */ + sessionId: string; +} + /** @experimental */ export interface SessionCompactionCompactResult { /** @@ -512,6 +808,135 @@ export interface SessionToolsHandlePendingToolCallParams { error?: string; } +export interface SessionCommandsHandlePendingCommandResult { + success: boolean; +} + +export interface SessionCommandsHandlePendingCommandParams { + /** + * Target session identifier + */ + sessionId: string; + /** + * Request ID from the command invocation event + */ + requestId: string; + /** + * Error message if the command handler failed + */ + error?: string; +} + +export interface SessionUiElicitationResult { + /** + * The user's response: accept (submitted), decline (rejected), or cancel (dismissed) + */ + action: "accept" | "decline" | "cancel"; + /** + * The form values submitted by the user (present when action is 'accept') + */ + content?: { + [k: string]: string | number | boolean | string[]; + }; +} + +export interface SessionUiElicitationParams { + /** + * Target session identifier + */ + sessionId: string; + /** + * Message describing what information is needed from the user + */ + message: string; + /** + * JSON Schema describing the form fields to present to the user + */ + requestedSchema: { + /** + * Schema type indicator (always 'object') + */ + type: "object"; + /** + * Form field definitions, keyed by field name + */ + properties: { + [k: string]: + | { + type: "string"; + title?: string; + description?: string; + enum: string[]; + enumNames?: string[]; + default?: string; + } + | { + type: "string"; + title?: string; + description?: string; + oneOf: { + const: string; + title: string; + }[]; + default?: string; + } + | { + type: "array"; + title?: string; + description?: string; + minItems?: number; + maxItems?: number; + items: { + type: "string"; + enum: string[]; + }; + default?: string[]; + } + | { + type: "array"; + title?: string; + description?: string; + minItems?: number; + maxItems?: number; + items: { + anyOf: { + const: string; + title: string; + }[]; + }; + default?: string[]; + } + | { + type: "boolean"; + title?: string; + description?: string; + default?: boolean; + } + | { + type: "string"; + title?: string; + description?: string; + minLength?: number; + maxLength?: number; + format?: "email" | "uri" | "date" | "date-time"; + default?: string; + } + | { + type: "number" | "integer"; + title?: string; + description?: string; + minimum?: number; + maximum?: number; + default?: number; + }; + }; + /** + * List of required field names + */ + required?: string[]; + }; +} + export interface SessionPermissionsHandlePendingPermissionRequestResult { /** * Whether the permission request was handled successfully @@ -571,6 +996,10 @@ export interface SessionLogParams { * When true, the message is transient and not persisted to the session event log on disk */ ephemeral?: boolean; + /** + * Optional URL the user can open in their browser for more details + */ + url?: string; } export interface SessionShellExecResult { @@ -687,6 +1116,46 @@ export function createSessionRpc(connection: MessageConnection, sessionId: strin connection.sendRequest("session.agent.select", { sessionId, ...params }), deselect: async (): Promise => connection.sendRequest("session.agent.deselect", { sessionId }), + reload: async (): Promise => + connection.sendRequest("session.agent.reload", { sessionId }), + }, + /** @experimental */ + skills: { + list: async (): Promise => + connection.sendRequest("session.skills.list", { sessionId }), + enable: async (params: Omit): Promise => + connection.sendRequest("session.skills.enable", { sessionId, ...params }), + disable: async (params: Omit): Promise => + connection.sendRequest("session.skills.disable", { sessionId, ...params }), + reload: async (): Promise => + connection.sendRequest("session.skills.reload", { sessionId }), + }, + /** @experimental */ + mcp: { + list: async (): Promise => + connection.sendRequest("session.mcp.list", { sessionId }), + enable: async (params: Omit): Promise => + connection.sendRequest("session.mcp.enable", { sessionId, ...params }), + disable: async (params: Omit): Promise => + connection.sendRequest("session.mcp.disable", { sessionId, ...params }), + reload: async (): Promise => + connection.sendRequest("session.mcp.reload", { sessionId }), + }, + /** @experimental */ + plugins: { + list: async (): Promise => + connection.sendRequest("session.plugins.list", { sessionId }), + }, + /** @experimental */ + extensions: { + list: async (): Promise => + connection.sendRequest("session.extensions.list", { sessionId }), + enable: async (params: Omit): Promise => + connection.sendRequest("session.extensions.enable", { sessionId, ...params }), + disable: async (params: Omit): Promise => + connection.sendRequest("session.extensions.disable", { sessionId, ...params }), + reload: async (): Promise => + connection.sendRequest("session.extensions.reload", { sessionId }), }, /** @experimental */ compaction: { @@ -697,6 +1166,14 @@ export function createSessionRpc(connection: MessageConnection, sessionId: strin handlePendingToolCall: async (params: Omit): Promise => connection.sendRequest("session.tools.handlePendingToolCall", { sessionId, ...params }), }, + commands: { + handlePendingCommand: async (params: Omit): Promise => + connection.sendRequest("session.commands.handlePendingCommand", { sessionId, ...params }), + }, + ui: { + elicitation: async (params: Omit): Promise => + connection.sendRequest("session.ui.elicitation", { sessionId, ...params }), + }, permissions: { handlePendingPermissionRequest: async (params: Omit): Promise => connection.sendRequest("session.permissions.handlePendingPermissionRequest", { sessionId, ...params }), diff --git a/nodejs/src/generated/session-events.ts b/nodejs/src/generated/session-events.ts index e9d48bc57..9ad6d3c02 100644 --- a/nodejs/src/generated/session-events.ts +++ b/nodejs/src/generated/session-events.ts @@ -212,6 +212,10 @@ export type SessionEvent = * GitHub request tracing ID (x-github-request-id header) for correlating with server-side logs */ providerCallId?: string; + /** + * Optional URL associated with this error that the user can open in a browser + */ + url?: string; }; } | { @@ -325,6 +329,10 @@ export type SessionEvent = * Human-readable informational message for display in the timeline */ message: string; + /** + * Optional URL associated with this message that the user can open in a browser + */ + url?: string; }; } | { @@ -357,6 +365,10 @@ export type SessionEvent = * Human-readable warning message for display in the timeline */ message: string; + /** + * Optional URL associated with this warning that the user can open in a browser + */ + url?: string; }; } | { @@ -741,6 +753,22 @@ export type SessionEvent = * Model that was selected at the time of shutdown */ currentModel?: string; + /** + * Total tokens in context window at shutdown + */ + currentTokens?: number; + /** + * System message token count at shutdown + */ + systemTokens?: number; + /** + * Non-system message token count at shutdown + */ + conversationTokens?: number; + /** + * Tool definitions token count at shutdown + */ + toolDefinitionsTokens?: number; }; } | { @@ -826,6 +854,22 @@ export type SessionEvent = * Current number of messages in the conversation */ messagesLength: number; + /** + * Token count from system message(s) + */ + systemTokens?: number; + /** + * Token count from non-system messages (user, assistant, tool) + */ + conversationTokens?: number; + /** + * Token count from tool definitions + */ + toolDefinitionsTokens?: number; + /** + * Whether this is the first usage_info event emitted in this session + */ + isInitial?: boolean; }; } | { @@ -847,9 +891,22 @@ export type SessionEvent = ephemeral?: boolean; type: "session.compaction_start"; /** - * Empty payload; the event signals that LLM-powered conversation compaction has begun + * Context window breakdown at the start of LLM-powered conversation compaction */ - data: {}; + data: { + /** + * Token count from system message(s) at compaction start + */ + systemTokens?: number; + /** + * Token count from non-system messages (user, assistant, tool) at compaction start + */ + conversationTokens?: number; + /** + * Token count from tool definitions at compaction start + */ + toolDefinitionsTokens?: number; + }; } | { /** @@ -934,6 +991,18 @@ export type SessionEvent = * GitHub request tracing ID (x-github-request-id header) for the compaction LLM call */ requestId?: string; + /** + * Token count from system message(s) after compaction + */ + systemTokens?: number; + /** + * Token count from non-system messages (user, assistant, tool) after compaction + */ + conversationTokens?: number; + /** + * Token count from tool definitions after compaction + */ + toolDefinitionsTokens?: number; }; } | { @@ -955,13 +1024,17 @@ export type SessionEvent = ephemeral?: boolean; type: "session.task_complete"; /** - * Task completion notification with optional summary from the agent + * Task completion notification with summary from the agent */ data: { /** - * Optional summary of the completed task, provided by the agent + * Summary of the completed task, provided by the agent */ summary?: string; + /** + * Whether the tool call succeeded. False when validation failed (e.g., invalid arguments) + */ + success?: boolean; }; } | { @@ -982,9 +1055,6 @@ export type SessionEvent = */ ephemeral?: boolean; type: "user.message"; - /** - * User message content with optional attachments, source information, and interaction metadata - */ data: { /** * The user's message text as displayed in the timeline @@ -1134,19 +1204,9 @@ export type SessionEvent = } )[]; /** - * Origin of this message, used for timeline filtering and telemetry (e.g., "user", "autopilot", "skill", or "command") + * Origin of this message, used for timeline filtering (e.g., "skill-pdf" for skill-injected messages that should be hidden from the user) */ - source?: - | "user" - | "autopilot" - | "skill" - | "system" - | "command" - | "immediate-prompt" - | "jit-instruction" - | "snippy-blocking" - | "thinking-exhausted-continuation" - | "other"; + source?: string; /** * The agent mode that was active when this message was sent */ @@ -2434,6 +2494,21 @@ export type SessionEvent = */ prompt?: string; } + | { + type: "agent_idle"; + /** + * Unique identifier of the background agent + */ + agentId: string; + /** + * Type of the agent (e.g., explore, task, general-purpose) + */ + agentType: string; + /** + * Human-readable description of the agent task + */ + description?: string; + } | { type: "shell_completed"; /** @@ -2785,6 +2860,10 @@ export type SessionEvent = * Whether the user can provide a free-form text response in addition to predefined choices */ allowFreeform?: boolean; + /** + * The LLM-assigned tool call ID that triggered this request; used by remote UIs to correlate responses + */ + toolCallId?: string; }; } | { @@ -2828,25 +2907,33 @@ export type SessionEvent = ephemeral: true; type: "elicitation.requested"; /** - * Structured form elicitation request with JSON schema definition for form fields + * Elicitation request; may be form-based (structured input) or URL-based (browser redirect) */ data: { /** * Unique identifier for this elicitation request; used to respond via session.respondToElicitation() */ requestId: string; + /** + * Tool call ID from the LLM completion; used to correlate with CompletionChunk.toolCall.id for remote UIs + */ + toolCallId?: string; + /** + * The source that initiated the request (MCP server name, or absent for agent-initiated) + */ + elicitationSource?: string; /** * Message describing what information is needed from the user */ message: string; /** - * Elicitation mode; currently only "form" is supported. Defaults to "form" when absent. + * Elicitation mode; "form" for structured input, "url" for browser-based. Defaults to "form" when absent. */ - mode?: "form"; + mode?: "form" | "url"; /** - * JSON Schema describing the form fields to present to the user + * JSON Schema describing the form fields to present to the user (form mode only) */ - requestedSchema: { + requestedSchema?: { /** * Schema type indicator (always 'object') */ @@ -2862,6 +2949,10 @@ export type SessionEvent = */ required?: string[]; }; + /** + * URL to open in the user's browser (url mode only) + */ + url?: string; [k: string]: unknown; }; } @@ -2890,6 +2981,77 @@ export type SessionEvent = requestId: string; }; } + | { + /** + * Unique event identifier (UUID v4), generated when the event is emitted + */ + id: string; + /** + * ISO 8601 timestamp when the event was created + */ + timestamp: string; + /** + * ID of the chronologically preceding event in the session, forming a linked chain. Null for the first event. + */ + parentId: string | null; + ephemeral: true; + type: "mcp.oauth_required"; + /** + * OAuth authentication request for an MCP server + */ + data: { + /** + * Unique identifier for this OAuth request; used to respond via session.respondToMcpOAuth() + */ + requestId: string; + /** + * Display name of the MCP server that requires OAuth + */ + serverName: string; + /** + * URL of the MCP server that requires OAuth + */ + serverUrl: string; + /** + * Static OAuth client configuration, if the server specifies one + */ + staticClientConfig?: { + /** + * OAuth client ID for the server + */ + clientId: string; + /** + * Whether this is a public OAuth client + */ + publicClient?: boolean; + }; + }; + } + | { + /** + * Unique event identifier (UUID v4), generated when the event is emitted + */ + id: string; + /** + * ISO 8601 timestamp when the event was created + */ + timestamp: string; + /** + * ID of the chronologically preceding event in the session, forming a linked chain. Null for the first event. + */ + parentId: string | null; + ephemeral: true; + type: "mcp.oauth_completed"; + /** + * MCP OAuth request completion notification + */ + data: { + /** + * Request ID of the resolved OAuth request + */ + requestId: string; + }; + } | { /** * Unique event identifier (UUID v4), generated when the event is emitted @@ -2995,6 +3157,43 @@ export type SessionEvent = command: string; }; } + | { + /** + * Unique event identifier (UUID v4), generated when the event is emitted + */ + id: string; + /** + * ISO 8601 timestamp when the event was created + */ + timestamp: string; + /** + * ID of the chronologically preceding event in the session, forming a linked chain. Null for the first event. + */ + parentId: string | null; + ephemeral: true; + type: "command.execute"; + /** + * Registered command dispatch request routed to the owning client + */ + data: { + /** + * Unique identifier; used to respond via session.commands.handlePendingCommand() + */ + requestId: string; + /** + * The full command text (e.g., /deploy production) + */ + command: string; + /** + * Command name without leading / + */ + commandName: string; + /** + * Raw argument string after the command name + */ + args: string; + }; + } | { /** * Unique event identifier (UUID v4), generated when the event is emitted @@ -3020,6 +3219,34 @@ export type SessionEvent = requestId: string; }; } + | { + /** + * Unique event identifier (UUID v4), generated when the event is emitted + */ + id: string; + /** + * ISO 8601 timestamp when the event was created + */ + timestamp: string; + /** + * ID of the chronologically preceding event in the session, forming a linked chain. Null for the first event. + */ + parentId: string | null; + ephemeral: true; + type: "commands.changed"; + /** + * SDK command registration change notification + */ + data: { + /** + * Current list of registered SDK commands + */ + commands: { + name: string; + description?: string; + }[]; + }; + } | { /** * Unique event identifier (UUID v4), generated when the event is emitted @@ -3121,4 +3348,155 @@ export type SessionEvent = ephemeral: true; type: "session.background_tasks_changed"; data: {}; + } + | { + /** + * Unique event identifier (UUID v4), generated when the event is emitted + */ + id: string; + /** + * ISO 8601 timestamp when the event was created + */ + timestamp: string; + /** + * ID of the chronologically preceding event in the session, forming a linked chain. Null for the first event. + */ + parentId: string | null; + ephemeral: true; + type: "session.skills_loaded"; + data: { + /** + * Array of resolved skill metadata + */ + skills: { + /** + * Unique identifier for the skill + */ + name: string; + /** + * Description of what the skill does + */ + description: string; + /** + * Source location type of the skill (e.g., project, personal, plugin) + */ + source: string; + /** + * Whether the skill can be invoked by the user as a slash command + */ + userInvocable: boolean; + /** + * Whether the skill is currently enabled + */ + enabled: boolean; + /** + * Absolute path to the skill file, if available + */ + path?: string; + }[]; + }; + } + | { + /** + * Unique event identifier (UUID v4), generated when the event is emitted + */ + id: string; + /** + * ISO 8601 timestamp when the event was created + */ + timestamp: string; + /** + * ID of the chronologically preceding event in the session, forming a linked chain. Null for the first event. + */ + parentId: string | null; + ephemeral: true; + type: "session.mcp_servers_loaded"; + data: { + /** + * Array of MCP server status summaries + */ + servers: { + /** + * Server name (config key) + */ + name: string; + /** + * Connection status: connected, failed, pending, disabled, or not_configured + */ + status: "connected" | "failed" | "pending" | "disabled" | "not_configured"; + /** + * Configuration source: user, workspace, plugin, or builtin + */ + source?: string; + /** + * Error message if the server failed to connect + */ + error?: string; + }[]; + }; + } + | { + /** + * Unique event identifier (UUID v4), generated when the event is emitted + */ + id: string; + /** + * ISO 8601 timestamp when the event was created + */ + timestamp: string; + /** + * ID of the chronologically preceding event in the session, forming a linked chain. Null for the first event. + */ + parentId: string | null; + ephemeral: true; + type: "session.mcp_server_status_changed"; + data: { + /** + * Name of the MCP server whose status changed + */ + serverName: string; + /** + * New connection status: connected, failed, pending, disabled, or not_configured + */ + status: "connected" | "failed" | "pending" | "disabled" | "not_configured"; + }; + } + | { + /** + * Unique event identifier (UUID v4), generated when the event is emitted + */ + id: string; + /** + * ISO 8601 timestamp when the event was created + */ + timestamp: string; + /** + * ID of the chronologically preceding event in the session, forming a linked chain. Null for the first event. + */ + parentId: string | null; + ephemeral: true; + type: "session.extensions_loaded"; + data: { + /** + * Array of discovered extensions and their status + */ + extensions: { + /** + * Source-qualified extension ID (e.g., 'project:my-ext', 'user:auth-helper') + */ + id: string; + /** + * Extension name (directory name) + */ + name: string; + /** + * Discovery source + */ + source: "project" | "user"; + /** + * Current status: running, disabled, failed, or starting + */ + status: "running" | "disabled" | "failed" | "starting"; + }[]; + }; }; diff --git a/python/copilot/generated/rpc.py b/python/copilot/generated/rpc.py index da6748d79..14ae307d7 100644 --- a/python/copilot/generated/rpc.py +++ b/python/copilot/generated/rpc.py @@ -74,6 +74,11 @@ def to_enum(c: type[EnumT], x: Any) -> EnumT: return x.value +def from_int(x: Any) -> int: + assert isinstance(x, int) and not isinstance(x, bool) + return x + + @dataclass class PingResult: message: str @@ -762,7 +767,7 @@ def to_dict(self) -> dict: @dataclass -class AgentElement: +class SessionAgentListResultAgent: description: str """Description of the agent's purpose""" @@ -773,12 +778,12 @@ class AgentElement: """Unique identifier of the custom agent""" @staticmethod - def from_dict(obj: Any) -> 'AgentElement': + def from_dict(obj: Any) -> 'SessionAgentListResultAgent': assert isinstance(obj, dict) description = from_str(obj.get("description")) display_name = from_str(obj.get("displayName")) name = from_str(obj.get("name")) - return AgentElement(description, display_name, name) + return SessionAgentListResultAgent(description, display_name, name) def to_dict(self) -> dict: result: dict = {} @@ -791,18 +796,18 @@ def to_dict(self) -> dict: # Experimental: this type is part of an experimental API and may change or be removed. @dataclass class SessionAgentListResult: - agents: list[AgentElement] + agents: list[SessionAgentListResultAgent] """Available custom agents""" @staticmethod def from_dict(obj: Any) -> 'SessionAgentListResult': assert isinstance(obj, dict) - agents = from_list(AgentElement.from_dict, obj.get("agents")) + agents = from_list(SessionAgentListResultAgent.from_dict, obj.get("agents")) return SessionAgentListResult(agents) def to_dict(self) -> dict: result: dict = {} - result["agents"] = from_list(lambda x: to_class(AgentElement, x), self.agents) + result["agents"] = from_list(lambda x: to_class(SessionAgentListResultAgent, x), self.agents) return result @@ -929,334 +934,1129 @@ def to_dict(self) -> dict: return result -# Experimental: this type is part of an experimental API and may change or be removed. @dataclass -class SessionCompactionCompactResult: - messages_removed: float - """Number of messages removed during compaction""" +class SessionAgentReloadResultAgent: + description: str + """Description of the agent's purpose""" - success: bool - """Whether compaction completed successfully""" + display_name: str + """Human-readable display name""" - tokens_removed: float - """Number of tokens freed by compaction""" + name: str + """Unique identifier of the custom agent""" @staticmethod - def from_dict(obj: Any) -> 'SessionCompactionCompactResult': + def from_dict(obj: Any) -> 'SessionAgentReloadResultAgent': assert isinstance(obj, dict) - messages_removed = from_float(obj.get("messagesRemoved")) - success = from_bool(obj.get("success")) - tokens_removed = from_float(obj.get("tokensRemoved")) - return SessionCompactionCompactResult(messages_removed, success, tokens_removed) + description = from_str(obj.get("description")) + display_name = from_str(obj.get("displayName")) + name = from_str(obj.get("name")) + return SessionAgentReloadResultAgent(description, display_name, name) def to_dict(self) -> dict: result: dict = {} - result["messagesRemoved"] = to_float(self.messages_removed) - result["success"] = from_bool(self.success) - result["tokensRemoved"] = to_float(self.tokens_removed) + result["description"] = from_str(self.description) + result["displayName"] = from_str(self.display_name) + result["name"] = from_str(self.name) return result +# Experimental: this type is part of an experimental API and may change or be removed. @dataclass -class SessionToolsHandlePendingToolCallResult: - success: bool - """Whether the tool call result was handled successfully""" +class SessionAgentReloadResult: + agents: list[SessionAgentReloadResultAgent] + """Reloaded custom agents""" @staticmethod - def from_dict(obj: Any) -> 'SessionToolsHandlePendingToolCallResult': + def from_dict(obj: Any) -> 'SessionAgentReloadResult': assert isinstance(obj, dict) - success = from_bool(obj.get("success")) - return SessionToolsHandlePendingToolCallResult(success) + agents = from_list(SessionAgentReloadResultAgent.from_dict, obj.get("agents")) + return SessionAgentReloadResult(agents) def to_dict(self) -> dict: result: dict = {} - result["success"] = from_bool(self.success) + result["agents"] = from_list(lambda x: to_class(SessionAgentReloadResultAgent, x), self.agents) return result @dataclass -class ResultResult: - text_result_for_llm: str - error: str | None = None - result_type: str | None = None - tool_telemetry: dict[str, Any] | None = None +class Skill: + description: str + """Description of what the skill does""" + + enabled: bool + """Whether the skill is currently enabled""" + + name: str + """Unique identifier for the skill""" + + source: str + """Source location type (e.g., project, personal, plugin)""" + + user_invocable: bool + """Whether the skill can be invoked by the user as a slash command""" + + path: str | None = None + """Absolute path to the skill file""" @staticmethod - def from_dict(obj: Any) -> 'ResultResult': + def from_dict(obj: Any) -> 'Skill': assert isinstance(obj, dict) - text_result_for_llm = from_str(obj.get("textResultForLlm")) - error = from_union([from_str, from_none], obj.get("error")) - result_type = from_union([from_str, from_none], obj.get("resultType")) - tool_telemetry = from_union([lambda x: from_dict(lambda x: x, x), from_none], obj.get("toolTelemetry")) - return ResultResult(text_result_for_llm, error, result_type, tool_telemetry) + description = from_str(obj.get("description")) + enabled = from_bool(obj.get("enabled")) + name = from_str(obj.get("name")) + source = from_str(obj.get("source")) + user_invocable = from_bool(obj.get("userInvocable")) + path = from_union([from_str, from_none], obj.get("path")) + return Skill(description, enabled, name, source, user_invocable, path) def to_dict(self) -> dict: result: dict = {} - result["textResultForLlm"] = from_str(self.text_result_for_llm) - if self.error is not None: - result["error"] = from_union([from_str, from_none], self.error) - if self.result_type is not None: - result["resultType"] = from_union([from_str, from_none], self.result_type) - if self.tool_telemetry is not None: - result["toolTelemetry"] = from_union([lambda x: from_dict(lambda x: x, x), from_none], self.tool_telemetry) + result["description"] = from_str(self.description) + result["enabled"] = from_bool(self.enabled) + result["name"] = from_str(self.name) + result["source"] = from_str(self.source) + result["userInvocable"] = from_bool(self.user_invocable) + if self.path is not None: + result["path"] = from_union([from_str, from_none], self.path) return result +# Experimental: this type is part of an experimental API and may change or be removed. @dataclass -class SessionToolsHandlePendingToolCallParams: - request_id: str - error: str | None = None - result: ResultResult | str | None = None +class SessionSkillsListResult: + skills: list[Skill] + """Available skills""" @staticmethod - def from_dict(obj: Any) -> 'SessionToolsHandlePendingToolCallParams': + def from_dict(obj: Any) -> 'SessionSkillsListResult': assert isinstance(obj, dict) - request_id = from_str(obj.get("requestId")) - error = from_union([from_str, from_none], obj.get("error")) - result = from_union([ResultResult.from_dict, from_str, from_none], obj.get("result")) - return SessionToolsHandlePendingToolCallParams(request_id, error, result) + skills = from_list(Skill.from_dict, obj.get("skills")) + return SessionSkillsListResult(skills) def to_dict(self) -> dict: result: dict = {} - result["requestId"] = from_str(self.request_id) - if self.error is not None: - result["error"] = from_union([from_str, from_none], self.error) - if self.result is not None: - result["result"] = from_union([lambda x: to_class(ResultResult, x), from_str, from_none], self.result) + result["skills"] = from_list(lambda x: to_class(Skill, x), self.skills) return result +# Experimental: this type is part of an experimental API and may change or be removed. @dataclass -class SessionPermissionsHandlePendingPermissionRequestResult: - success: bool - """Whether the permission request was handled successfully""" - +class SessionSkillsEnableResult: @staticmethod - def from_dict(obj: Any) -> 'SessionPermissionsHandlePendingPermissionRequestResult': + def from_dict(obj: Any) -> 'SessionSkillsEnableResult': assert isinstance(obj, dict) - success = from_bool(obj.get("success")) - return SessionPermissionsHandlePendingPermissionRequestResult(success) + return SessionSkillsEnableResult() def to_dict(self) -> dict: result: dict = {} - result["success"] = from_bool(self.success) return result -class Kind(Enum): - APPROVED = "approved" - DENIED_BY_CONTENT_EXCLUSION_POLICY = "denied-by-content-exclusion-policy" - DENIED_BY_RULES = "denied-by-rules" - DENIED_INTERACTIVELY_BY_USER = "denied-interactively-by-user" - DENIED_NO_APPROVAL_RULE_AND_COULD_NOT_REQUEST_FROM_USER = "denied-no-approval-rule-and-could-not-request-from-user" +# Experimental: this type is part of an experimental API and may change or be removed. +@dataclass +class SessionSkillsEnableParams: + name: str + """Name of the skill to enable""" + @staticmethod + def from_dict(obj: Any) -> 'SessionSkillsEnableParams': + assert isinstance(obj, dict) + name = from_str(obj.get("name")) + return SessionSkillsEnableParams(name) + + def to_dict(self) -> dict: + result: dict = {} + result["name"] = from_str(self.name) + return result -@dataclass -class SessionPermissionsHandlePendingPermissionRequestParamsResult: - kind: Kind - rules: list[Any] | None = None - feedback: str | None = None - message: str | None = None - path: str | None = None +# Experimental: this type is part of an experimental API and may change or be removed. +@dataclass +class SessionSkillsDisableResult: @staticmethod - def from_dict(obj: Any) -> 'SessionPermissionsHandlePendingPermissionRequestParamsResult': + def from_dict(obj: Any) -> 'SessionSkillsDisableResult': assert isinstance(obj, dict) - kind = Kind(obj.get("kind")) - rules = from_union([lambda x: from_list(lambda x: x, x), from_none], obj.get("rules")) - feedback = from_union([from_str, from_none], obj.get("feedback")) - message = from_union([from_str, from_none], obj.get("message")) - path = from_union([from_str, from_none], obj.get("path")) - return SessionPermissionsHandlePendingPermissionRequestParamsResult(kind, rules, feedback, message, path) + return SessionSkillsDisableResult() def to_dict(self) -> dict: result: dict = {} - result["kind"] = to_enum(Kind, self.kind) - if self.rules is not None: - result["rules"] = from_union([lambda x: from_list(lambda x: x, x), from_none], self.rules) - if self.feedback is not None: - result["feedback"] = from_union([from_str, from_none], self.feedback) - if self.message is not None: - result["message"] = from_union([from_str, from_none], self.message) - if self.path is not None: - result["path"] = from_union([from_str, from_none], self.path) return result +# Experimental: this type is part of an experimental API and may change or be removed. @dataclass -class SessionPermissionsHandlePendingPermissionRequestParams: - request_id: str - result: SessionPermissionsHandlePendingPermissionRequestParamsResult +class SessionSkillsDisableParams: + name: str + """Name of the skill to disable""" @staticmethod - def from_dict(obj: Any) -> 'SessionPermissionsHandlePendingPermissionRequestParams': + def from_dict(obj: Any) -> 'SessionSkillsDisableParams': assert isinstance(obj, dict) - request_id = from_str(obj.get("requestId")) - result = SessionPermissionsHandlePendingPermissionRequestParamsResult.from_dict(obj.get("result")) - return SessionPermissionsHandlePendingPermissionRequestParams(request_id, result) + name = from_str(obj.get("name")) + return SessionSkillsDisableParams(name) def to_dict(self) -> dict: result: dict = {} - result["requestId"] = from_str(self.request_id) - result["result"] = to_class(SessionPermissionsHandlePendingPermissionRequestParamsResult, self.result) + result["name"] = from_str(self.name) return result +# Experimental: this type is part of an experimental API and may change or be removed. @dataclass -class SessionLogResult: - event_id: UUID - """The unique identifier of the emitted session event""" - +class SessionSkillsReloadResult: @staticmethod - def from_dict(obj: Any) -> 'SessionLogResult': + def from_dict(obj: Any) -> 'SessionSkillsReloadResult': assert isinstance(obj, dict) - event_id = UUID(obj.get("eventId")) - return SessionLogResult(event_id) + return SessionSkillsReloadResult() def to_dict(self) -> dict: result: dict = {} - result["eventId"] = str(self.event_id) return result -class Level(Enum): - """Log severity level. Determines how the message is displayed in the timeline. Defaults to - "info". - """ - ERROR = "error" - INFO = "info" - WARNING = "warning" +class ServerStatus(Enum): + """Connection status: connected, failed, pending, disabled, or not_configured""" + + CONNECTED = "connected" + DISABLED = "disabled" + FAILED = "failed" + NOT_CONFIGURED = "not_configured" + PENDING = "pending" @dataclass -class SessionLogParams: - message: str - """Human-readable message""" +class Server: + name: str + """Server name (config key)""" - ephemeral: bool | None = None - """When true, the message is transient and not persisted to the session event log on disk""" + status: ServerStatus + """Connection status: connected, failed, pending, disabled, or not_configured""" - level: Level | None = None - """Log severity level. Determines how the message is displayed in the timeline. Defaults to - "info". - """ + error: str | None = None + """Error message if the server failed to connect""" + + source: str | None = None + """Configuration source: user, workspace, plugin, or builtin""" @staticmethod - def from_dict(obj: Any) -> 'SessionLogParams': + def from_dict(obj: Any) -> 'Server': assert isinstance(obj, dict) - message = from_str(obj.get("message")) - ephemeral = from_union([from_bool, from_none], obj.get("ephemeral")) - level = from_union([Level, from_none], obj.get("level")) - return SessionLogParams(message, ephemeral, level) + name = from_str(obj.get("name")) + status = ServerStatus(obj.get("status")) + error = from_union([from_str, from_none], obj.get("error")) + source = from_union([from_str, from_none], obj.get("source")) + return Server(name, status, error, source) def to_dict(self) -> dict: result: dict = {} - result["message"] = from_str(self.message) - if self.ephemeral is not None: - result["ephemeral"] = from_union([from_bool, from_none], self.ephemeral) - if self.level is not None: - result["level"] = from_union([lambda x: to_enum(Level, x), from_none], self.level) + result["name"] = from_str(self.name) + result["status"] = to_enum(ServerStatus, self.status) + if self.error is not None: + result["error"] = from_union([from_str, from_none], self.error) + if self.source is not None: + result["source"] = from_union([from_str, from_none], self.source) return result @dataclass -class SessionShellExecResult: - process_id: str - """Unique identifier for tracking streamed output""" +class SessionMCPListResult: + servers: list[Server] + """Configured MCP servers""" @staticmethod - def from_dict(obj: Any) -> 'SessionShellExecResult': + def from_dict(obj: Any) -> 'SessionMCPListResult': assert isinstance(obj, dict) - process_id = from_str(obj.get("processId")) - return SessionShellExecResult(process_id) + servers = from_list(Server.from_dict, obj.get("servers")) + return SessionMCPListResult(servers) def to_dict(self) -> dict: result: dict = {} - result["processId"] = from_str(self.process_id) + result["servers"] = from_list(lambda x: to_class(Server, x), self.servers) return result @dataclass -class SessionShellExecParams: - command: str - """Shell command to execute""" - - cwd: str | None = None - """Working directory (defaults to session working directory)""" - - timeout: float | None = None - """Timeout in milliseconds (default: 30000)""" - +class SessionMCPEnableResult: @staticmethod - def from_dict(obj: Any) -> 'SessionShellExecParams': + def from_dict(obj: Any) -> 'SessionMCPEnableResult': assert isinstance(obj, dict) - command = from_str(obj.get("command")) - cwd = from_union([from_str, from_none], obj.get("cwd")) - timeout = from_union([from_float, from_none], obj.get("timeout")) - return SessionShellExecParams(command, cwd, timeout) + return SessionMCPEnableResult() def to_dict(self) -> dict: result: dict = {} - result["command"] = from_str(self.command) - if self.cwd is not None: - result["cwd"] = from_union([from_str, from_none], self.cwd) - if self.timeout is not None: - result["timeout"] = from_union([to_float, from_none], self.timeout) return result @dataclass -class SessionShellKillResult: - killed: bool - """Whether the signal was sent successfully""" +class SessionMCPEnableParams: + server_name: str + """Name of the MCP server to enable""" @staticmethod - def from_dict(obj: Any) -> 'SessionShellKillResult': + def from_dict(obj: Any) -> 'SessionMCPEnableParams': assert isinstance(obj, dict) - killed = from_bool(obj.get("killed")) - return SessionShellKillResult(killed) + server_name = from_str(obj.get("serverName")) + return SessionMCPEnableParams(server_name) def to_dict(self) -> dict: result: dict = {} - result["killed"] = from_bool(self.killed) + result["serverName"] = from_str(self.server_name) return result -class Signal(Enum): - """Signal to send (default: SIGTERM)""" +@dataclass +class SessionMCPDisableResult: + @staticmethod + def from_dict(obj: Any) -> 'SessionMCPDisableResult': + assert isinstance(obj, dict) + return SessionMCPDisableResult() - SIGINT = "SIGINT" - SIGKILL = "SIGKILL" - SIGTERM = "SIGTERM" + def to_dict(self) -> dict: + result: dict = {} + return result @dataclass -class SessionShellKillParams: - process_id: str - """Process identifier returned by shell.exec""" - - signal: Signal | None = None - """Signal to send (default: SIGTERM)""" +class SessionMCPDisableParams: + server_name: str + """Name of the MCP server to disable""" @staticmethod - def from_dict(obj: Any) -> 'SessionShellKillParams': + def from_dict(obj: Any) -> 'SessionMCPDisableParams': assert isinstance(obj, dict) - process_id = from_str(obj.get("processId")) - signal = from_union([Signal, from_none], obj.get("signal")) - return SessionShellKillParams(process_id, signal) + server_name = from_str(obj.get("serverName")) + return SessionMCPDisableParams(server_name) def to_dict(self) -> dict: result: dict = {} - result["processId"] = from_str(self.process_id) - if self.signal is not None: - result["signal"] = from_union([lambda x: to_enum(Signal, x), from_none], self.signal) + result["serverName"] = from_str(self.server_name) return result -def ping_result_from_dict(s: Any) -> PingResult: - return PingResult.from_dict(s) - - +@dataclass +class SessionMCPReloadResult: + @staticmethod + def from_dict(obj: Any) -> 'SessionMCPReloadResult': + assert isinstance(obj, dict) + return SessionMCPReloadResult() + + def to_dict(self) -> dict: + result: dict = {} + return result + + +@dataclass +class Plugin: + enabled: bool + """Whether the plugin is currently enabled""" + + marketplace: str + """Marketplace the plugin came from""" + + name: str + """Plugin name""" + + version: str | None = None + """Installed version""" + + @staticmethod + def from_dict(obj: Any) -> 'Plugin': + assert isinstance(obj, dict) + enabled = from_bool(obj.get("enabled")) + marketplace = from_str(obj.get("marketplace")) + name = from_str(obj.get("name")) + version = from_union([from_str, from_none], obj.get("version")) + return Plugin(enabled, marketplace, name, version) + + def to_dict(self) -> dict: + result: dict = {} + result["enabled"] = from_bool(self.enabled) + result["marketplace"] = from_str(self.marketplace) + result["name"] = from_str(self.name) + if self.version is not None: + result["version"] = from_union([from_str, from_none], self.version) + return result + + +# Experimental: this type is part of an experimental API and may change or be removed. +@dataclass +class SessionPluginsListResult: + plugins: list[Plugin] + """Installed plugins""" + + @staticmethod + def from_dict(obj: Any) -> 'SessionPluginsListResult': + assert isinstance(obj, dict) + plugins = from_list(Plugin.from_dict, obj.get("plugins")) + return SessionPluginsListResult(plugins) + + def to_dict(self) -> dict: + result: dict = {} + result["plugins"] = from_list(lambda x: to_class(Plugin, x), self.plugins) + return result + + +class Source(Enum): + """Discovery source: project (.github/extensions/) or user (~/.copilot/extensions/)""" + + PROJECT = "project" + USER = "user" + + +class ExtensionStatus(Enum): + """Current status: running, disabled, failed, or starting""" + + DISABLED = "disabled" + FAILED = "failed" + RUNNING = "running" + STARTING = "starting" + + +@dataclass +class Extension: + id: str + """Source-qualified ID (e.g., 'project:my-ext', 'user:auth-helper')""" + + name: str + """Extension name (directory name)""" + + source: Source + """Discovery source: project (.github/extensions/) or user (~/.copilot/extensions/)""" + + status: ExtensionStatus + """Current status: running, disabled, failed, or starting""" + + pid: int | None = None + """Process ID if the extension is running""" + + @staticmethod + def from_dict(obj: Any) -> 'Extension': + assert isinstance(obj, dict) + id = from_str(obj.get("id")) + name = from_str(obj.get("name")) + source = Source(obj.get("source")) + status = ExtensionStatus(obj.get("status")) + pid = from_union([from_int, from_none], obj.get("pid")) + return Extension(id, name, source, status, pid) + + def to_dict(self) -> dict: + result: dict = {} + result["id"] = from_str(self.id) + result["name"] = from_str(self.name) + result["source"] = to_enum(Source, self.source) + result["status"] = to_enum(ExtensionStatus, self.status) + if self.pid is not None: + result["pid"] = from_union([from_int, from_none], self.pid) + return result + + +# Experimental: this type is part of an experimental API and may change or be removed. +@dataclass +class SessionExtensionsListResult: + extensions: list[Extension] + """Discovered extensions and their current status""" + + @staticmethod + def from_dict(obj: Any) -> 'SessionExtensionsListResult': + assert isinstance(obj, dict) + extensions = from_list(Extension.from_dict, obj.get("extensions")) + return SessionExtensionsListResult(extensions) + + def to_dict(self) -> dict: + result: dict = {} + result["extensions"] = from_list(lambda x: to_class(Extension, x), self.extensions) + return result + + +# Experimental: this type is part of an experimental API and may change or be removed. +@dataclass +class SessionExtensionsEnableResult: + @staticmethod + def from_dict(obj: Any) -> 'SessionExtensionsEnableResult': + assert isinstance(obj, dict) + return SessionExtensionsEnableResult() + + def to_dict(self) -> dict: + result: dict = {} + return result + + +# Experimental: this type is part of an experimental API and may change or be removed. +@dataclass +class SessionExtensionsEnableParams: + id: str + """Source-qualified extension ID to enable""" + + @staticmethod + def from_dict(obj: Any) -> 'SessionExtensionsEnableParams': + assert isinstance(obj, dict) + id = from_str(obj.get("id")) + return SessionExtensionsEnableParams(id) + + def to_dict(self) -> dict: + result: dict = {} + result["id"] = from_str(self.id) + return result + + +# Experimental: this type is part of an experimental API and may change or be removed. +@dataclass +class SessionExtensionsDisableResult: + @staticmethod + def from_dict(obj: Any) -> 'SessionExtensionsDisableResult': + assert isinstance(obj, dict) + return SessionExtensionsDisableResult() + + def to_dict(self) -> dict: + result: dict = {} + return result + + +# Experimental: this type is part of an experimental API and may change or be removed. +@dataclass +class SessionExtensionsDisableParams: + id: str + """Source-qualified extension ID to disable""" + + @staticmethod + def from_dict(obj: Any) -> 'SessionExtensionsDisableParams': + assert isinstance(obj, dict) + id = from_str(obj.get("id")) + return SessionExtensionsDisableParams(id) + + def to_dict(self) -> dict: + result: dict = {} + result["id"] = from_str(self.id) + return result + + +# Experimental: this type is part of an experimental API and may change or be removed. +@dataclass +class SessionExtensionsReloadResult: + @staticmethod + def from_dict(obj: Any) -> 'SessionExtensionsReloadResult': + assert isinstance(obj, dict) + return SessionExtensionsReloadResult() + + def to_dict(self) -> dict: + result: dict = {} + return result + + +# Experimental: this type is part of an experimental API and may change or be removed. +@dataclass +class SessionCompactionCompactResult: + messages_removed: float + """Number of messages removed during compaction""" + + success: bool + """Whether compaction completed successfully""" + + tokens_removed: float + """Number of tokens freed by compaction""" + + @staticmethod + def from_dict(obj: Any) -> 'SessionCompactionCompactResult': + assert isinstance(obj, dict) + messages_removed = from_float(obj.get("messagesRemoved")) + success = from_bool(obj.get("success")) + tokens_removed = from_float(obj.get("tokensRemoved")) + return SessionCompactionCompactResult(messages_removed, success, tokens_removed) + + def to_dict(self) -> dict: + result: dict = {} + result["messagesRemoved"] = to_float(self.messages_removed) + result["success"] = from_bool(self.success) + result["tokensRemoved"] = to_float(self.tokens_removed) + return result + + +@dataclass +class SessionToolsHandlePendingToolCallResult: + success: bool + """Whether the tool call result was handled successfully""" + + @staticmethod + def from_dict(obj: Any) -> 'SessionToolsHandlePendingToolCallResult': + assert isinstance(obj, dict) + success = from_bool(obj.get("success")) + return SessionToolsHandlePendingToolCallResult(success) + + def to_dict(self) -> dict: + result: dict = {} + result["success"] = from_bool(self.success) + return result + + +@dataclass +class ResultResult: + text_result_for_llm: str + error: str | None = None + result_type: str | None = None + tool_telemetry: dict[str, Any] | None = None + + @staticmethod + def from_dict(obj: Any) -> 'ResultResult': + assert isinstance(obj, dict) + text_result_for_llm = from_str(obj.get("textResultForLlm")) + error = from_union([from_str, from_none], obj.get("error")) + result_type = from_union([from_str, from_none], obj.get("resultType")) + tool_telemetry = from_union([lambda x: from_dict(lambda x: x, x), from_none], obj.get("toolTelemetry")) + return ResultResult(text_result_for_llm, error, result_type, tool_telemetry) + + def to_dict(self) -> dict: + result: dict = {} + result["textResultForLlm"] = from_str(self.text_result_for_llm) + if self.error is not None: + result["error"] = from_union([from_str, from_none], self.error) + if self.result_type is not None: + result["resultType"] = from_union([from_str, from_none], self.result_type) + if self.tool_telemetry is not None: + result["toolTelemetry"] = from_union([lambda x: from_dict(lambda x: x, x), from_none], self.tool_telemetry) + return result + + +@dataclass +class SessionToolsHandlePendingToolCallParams: + request_id: str + error: str | None = None + result: ResultResult | str | None = None + + @staticmethod + def from_dict(obj: Any) -> 'SessionToolsHandlePendingToolCallParams': + assert isinstance(obj, dict) + request_id = from_str(obj.get("requestId")) + error = from_union([from_str, from_none], obj.get("error")) + result = from_union([ResultResult.from_dict, from_str, from_none], obj.get("result")) + return SessionToolsHandlePendingToolCallParams(request_id, error, result) + + def to_dict(self) -> dict: + result: dict = {} + result["requestId"] = from_str(self.request_id) + if self.error is not None: + result["error"] = from_union([from_str, from_none], self.error) + if self.result is not None: + result["result"] = from_union([lambda x: to_class(ResultResult, x), from_str, from_none], self.result) + return result + + +@dataclass +class SessionCommandsHandlePendingCommandResult: + success: bool + + @staticmethod + def from_dict(obj: Any) -> 'SessionCommandsHandlePendingCommandResult': + assert isinstance(obj, dict) + success = from_bool(obj.get("success")) + return SessionCommandsHandlePendingCommandResult(success) + + def to_dict(self) -> dict: + result: dict = {} + result["success"] = from_bool(self.success) + return result + + +@dataclass +class SessionCommandsHandlePendingCommandParams: + request_id: str + """Request ID from the command invocation event""" + + error: str | None = None + """Error message if the command handler failed""" + + @staticmethod + def from_dict(obj: Any) -> 'SessionCommandsHandlePendingCommandParams': + assert isinstance(obj, dict) + request_id = from_str(obj.get("requestId")) + error = from_union([from_str, from_none], obj.get("error")) + return SessionCommandsHandlePendingCommandParams(request_id, error) + + def to_dict(self) -> dict: + result: dict = {} + result["requestId"] = from_str(self.request_id) + if self.error is not None: + result["error"] = from_union([from_str, from_none], self.error) + return result + + +class Action(Enum): + """The user's response: accept (submitted), decline (rejected), or cancel (dismissed)""" + + ACCEPT = "accept" + CANCEL = "cancel" + DECLINE = "decline" + + +@dataclass +class SessionUIElicitationResult: + action: Action + """The user's response: accept (submitted), decline (rejected), or cancel (dismissed)""" + + content: dict[str, float | bool | list[str] | str] | None = None + """The form values submitted by the user (present when action is 'accept')""" + + @staticmethod + def from_dict(obj: Any) -> 'SessionUIElicitationResult': + assert isinstance(obj, dict) + action = Action(obj.get("action")) + content = from_union([lambda x: from_dict(lambda x: from_union([from_float, from_bool, lambda x: from_list(from_str, x), from_str], x), x), from_none], obj.get("content")) + return SessionUIElicitationResult(action, content) + + def to_dict(self) -> dict: + result: dict = {} + result["action"] = to_enum(Action, self.action) + if self.content is not None: + result["content"] = from_union([lambda x: from_dict(lambda x: from_union([to_float, from_bool, lambda x: from_list(from_str, x), from_str], x), x), from_none], self.content) + return result + + +class Format(Enum): + DATE = "date" + DATE_TIME = "date-time" + EMAIL = "email" + URI = "uri" + + +@dataclass +class AnyOf: + const: str + title: str + + @staticmethod + def from_dict(obj: Any) -> 'AnyOf': + assert isinstance(obj, dict) + const = from_str(obj.get("const")) + title = from_str(obj.get("title")) + return AnyOf(const, title) + + def to_dict(self) -> dict: + result: dict = {} + result["const"] = from_str(self.const) + result["title"] = from_str(self.title) + return result + + +class ItemsType(Enum): + STRING = "string" + + +@dataclass +class Items: + enum: list[str] | None = None + type: ItemsType | None = None + any_of: list[AnyOf] | None = None + + @staticmethod + def from_dict(obj: Any) -> 'Items': + assert isinstance(obj, dict) + enum = from_union([lambda x: from_list(from_str, x), from_none], obj.get("enum")) + type = from_union([ItemsType, from_none], obj.get("type")) + any_of = from_union([lambda x: from_list(AnyOf.from_dict, x), from_none], obj.get("anyOf")) + return Items(enum, type, any_of) + + def to_dict(self) -> dict: + result: dict = {} + if self.enum is not None: + result["enum"] = from_union([lambda x: from_list(from_str, x), from_none], self.enum) + if self.type is not None: + result["type"] = from_union([lambda x: to_enum(ItemsType, x), from_none], self.type) + if self.any_of is not None: + result["anyOf"] = from_union([lambda x: from_list(lambda x: to_class(AnyOf, x), x), from_none], self.any_of) + return result + + +@dataclass +class OneOf: + const: str + title: str + + @staticmethod + def from_dict(obj: Any) -> 'OneOf': + assert isinstance(obj, dict) + const = from_str(obj.get("const")) + title = from_str(obj.get("title")) + return OneOf(const, title) + + def to_dict(self) -> dict: + result: dict = {} + result["const"] = from_str(self.const) + result["title"] = from_str(self.title) + return result + + +class PropertyType(Enum): + ARRAY = "array" + BOOLEAN = "boolean" + INTEGER = "integer" + NUMBER = "number" + STRING = "string" + + +@dataclass +class Property: + type: PropertyType + default: float | bool | list[str] | str | None = None + description: str | None = None + enum: list[str] | None = None + enum_names: list[str] | None = None + title: str | None = None + one_of: list[OneOf] | None = None + items: Items | None = None + max_items: float | None = None + min_items: float | None = None + format: Format | None = None + max_length: float | None = None + min_length: float | None = None + maximum: float | None = None + minimum: float | None = None + + @staticmethod + def from_dict(obj: Any) -> 'Property': + assert isinstance(obj, dict) + type = PropertyType(obj.get("type")) + default = from_union([from_float, from_bool, lambda x: from_list(from_str, x), from_str, from_none], obj.get("default")) + description = from_union([from_str, from_none], obj.get("description")) + enum = from_union([lambda x: from_list(from_str, x), from_none], obj.get("enum")) + enum_names = from_union([lambda x: from_list(from_str, x), from_none], obj.get("enumNames")) + title = from_union([from_str, from_none], obj.get("title")) + one_of = from_union([lambda x: from_list(OneOf.from_dict, x), from_none], obj.get("oneOf")) + items = from_union([Items.from_dict, from_none], obj.get("items")) + max_items = from_union([from_float, from_none], obj.get("maxItems")) + min_items = from_union([from_float, from_none], obj.get("minItems")) + format = from_union([Format, from_none], obj.get("format")) + max_length = from_union([from_float, from_none], obj.get("maxLength")) + min_length = from_union([from_float, from_none], obj.get("minLength")) + maximum = from_union([from_float, from_none], obj.get("maximum")) + minimum = from_union([from_float, from_none], obj.get("minimum")) + return Property(type, default, description, enum, enum_names, title, one_of, items, max_items, min_items, format, max_length, min_length, maximum, minimum) + + def to_dict(self) -> dict: + result: dict = {} + result["type"] = to_enum(PropertyType, self.type) + if self.default is not None: + result["default"] = from_union([to_float, from_bool, lambda x: from_list(from_str, x), from_str, from_none], self.default) + if self.description is not None: + result["description"] = from_union([from_str, from_none], self.description) + if self.enum is not None: + result["enum"] = from_union([lambda x: from_list(from_str, x), from_none], self.enum) + if self.enum_names is not None: + result["enumNames"] = from_union([lambda x: from_list(from_str, x), from_none], self.enum_names) + if self.title is not None: + result["title"] = from_union([from_str, from_none], self.title) + if self.one_of is not None: + result["oneOf"] = from_union([lambda x: from_list(lambda x: to_class(OneOf, x), x), from_none], self.one_of) + if self.items is not None: + result["items"] = from_union([lambda x: to_class(Items, x), from_none], self.items) + if self.max_items is not None: + result["maxItems"] = from_union([to_float, from_none], self.max_items) + if self.min_items is not None: + result["minItems"] = from_union([to_float, from_none], self.min_items) + if self.format is not None: + result["format"] = from_union([lambda x: to_enum(Format, x), from_none], self.format) + if self.max_length is not None: + result["maxLength"] = from_union([to_float, from_none], self.max_length) + if self.min_length is not None: + result["minLength"] = from_union([to_float, from_none], self.min_length) + if self.maximum is not None: + result["maximum"] = from_union([to_float, from_none], self.maximum) + if self.minimum is not None: + result["minimum"] = from_union([to_float, from_none], self.minimum) + return result + + +class RequestedSchemaType(Enum): + OBJECT = "object" + + +@dataclass +class RequestedSchema: + """JSON Schema describing the form fields to present to the user""" + + properties: dict[str, Property] + """Form field definitions, keyed by field name""" + + type: RequestedSchemaType + """Schema type indicator (always 'object')""" + + required: list[str] | None = None + """List of required field names""" + + @staticmethod + def from_dict(obj: Any) -> 'RequestedSchema': + assert isinstance(obj, dict) + properties = from_dict(Property.from_dict, obj.get("properties")) + type = RequestedSchemaType(obj.get("type")) + required = from_union([lambda x: from_list(from_str, x), from_none], obj.get("required")) + return RequestedSchema(properties, type, required) + + def to_dict(self) -> dict: + result: dict = {} + result["properties"] = from_dict(lambda x: to_class(Property, x), self.properties) + result["type"] = to_enum(RequestedSchemaType, self.type) + if self.required is not None: + result["required"] = from_union([lambda x: from_list(from_str, x), from_none], self.required) + return result + + +@dataclass +class SessionUIElicitationParams: + message: str + """Message describing what information is needed from the user""" + + requested_schema: RequestedSchema + """JSON Schema describing the form fields to present to the user""" + + @staticmethod + def from_dict(obj: Any) -> 'SessionUIElicitationParams': + assert isinstance(obj, dict) + message = from_str(obj.get("message")) + requested_schema = RequestedSchema.from_dict(obj.get("requestedSchema")) + return SessionUIElicitationParams(message, requested_schema) + + def to_dict(self) -> dict: + result: dict = {} + result["message"] = from_str(self.message) + result["requestedSchema"] = to_class(RequestedSchema, self.requested_schema) + return result + + +@dataclass +class SessionPermissionsHandlePendingPermissionRequestResult: + success: bool + """Whether the permission request was handled successfully""" + + @staticmethod + def from_dict(obj: Any) -> 'SessionPermissionsHandlePendingPermissionRequestResult': + assert isinstance(obj, dict) + success = from_bool(obj.get("success")) + return SessionPermissionsHandlePendingPermissionRequestResult(success) + + def to_dict(self) -> dict: + result: dict = {} + result["success"] = from_bool(self.success) + return result + + +class Kind(Enum): + APPROVED = "approved" + DENIED_BY_CONTENT_EXCLUSION_POLICY = "denied-by-content-exclusion-policy" + DENIED_BY_RULES = "denied-by-rules" + DENIED_INTERACTIVELY_BY_USER = "denied-interactively-by-user" + DENIED_NO_APPROVAL_RULE_AND_COULD_NOT_REQUEST_FROM_USER = "denied-no-approval-rule-and-could-not-request-from-user" + + +@dataclass +class SessionPermissionsHandlePendingPermissionRequestParamsResult: + kind: Kind + rules: list[Any] | None = None + feedback: str | None = None + message: str | None = None + path: str | None = None + + @staticmethod + def from_dict(obj: Any) -> 'SessionPermissionsHandlePendingPermissionRequestParamsResult': + assert isinstance(obj, dict) + kind = Kind(obj.get("kind")) + rules = from_union([lambda x: from_list(lambda x: x, x), from_none], obj.get("rules")) + feedback = from_union([from_str, from_none], obj.get("feedback")) + message = from_union([from_str, from_none], obj.get("message")) + path = from_union([from_str, from_none], obj.get("path")) + return SessionPermissionsHandlePendingPermissionRequestParamsResult(kind, rules, feedback, message, path) + + def to_dict(self) -> dict: + result: dict = {} + result["kind"] = to_enum(Kind, self.kind) + if self.rules is not None: + result["rules"] = from_union([lambda x: from_list(lambda x: x, x), from_none], self.rules) + if self.feedback is not None: + result["feedback"] = from_union([from_str, from_none], self.feedback) + if self.message is not None: + result["message"] = from_union([from_str, from_none], self.message) + if self.path is not None: + result["path"] = from_union([from_str, from_none], self.path) + return result + + +@dataclass +class SessionPermissionsHandlePendingPermissionRequestParams: + request_id: str + result: SessionPermissionsHandlePendingPermissionRequestParamsResult + + @staticmethod + def from_dict(obj: Any) -> 'SessionPermissionsHandlePendingPermissionRequestParams': + assert isinstance(obj, dict) + request_id = from_str(obj.get("requestId")) + result = SessionPermissionsHandlePendingPermissionRequestParamsResult.from_dict(obj.get("result")) + return SessionPermissionsHandlePendingPermissionRequestParams(request_id, result) + + def to_dict(self) -> dict: + result: dict = {} + result["requestId"] = from_str(self.request_id) + result["result"] = to_class(SessionPermissionsHandlePendingPermissionRequestParamsResult, self.result) + return result + + +@dataclass +class SessionLogResult: + event_id: UUID + """The unique identifier of the emitted session event""" + + @staticmethod + def from_dict(obj: Any) -> 'SessionLogResult': + assert isinstance(obj, dict) + event_id = UUID(obj.get("eventId")) + return SessionLogResult(event_id) + + def to_dict(self) -> dict: + result: dict = {} + result["eventId"] = str(self.event_id) + return result + + +class Level(Enum): + """Log severity level. Determines how the message is displayed in the timeline. Defaults to + "info". + """ + ERROR = "error" + INFO = "info" + WARNING = "warning" + + +@dataclass +class SessionLogParams: + message: str + """Human-readable message""" + + ephemeral: bool | None = None + """When true, the message is transient and not persisted to the session event log on disk""" + + level: Level | None = None + """Log severity level. Determines how the message is displayed in the timeline. Defaults to + "info". + """ + url: str | None = None + """Optional URL the user can open in their browser for more details""" + + @staticmethod + def from_dict(obj: Any) -> 'SessionLogParams': + assert isinstance(obj, dict) + message = from_str(obj.get("message")) + ephemeral = from_union([from_bool, from_none], obj.get("ephemeral")) + level = from_union([Level, from_none], obj.get("level")) + url = from_union([from_str, from_none], obj.get("url")) + return SessionLogParams(message, ephemeral, level, url) + + def to_dict(self) -> dict: + result: dict = {} + result["message"] = from_str(self.message) + if self.ephemeral is not None: + result["ephemeral"] = from_union([from_bool, from_none], self.ephemeral) + if self.level is not None: + result["level"] = from_union([lambda x: to_enum(Level, x), from_none], self.level) + if self.url is not None: + result["url"] = from_union([from_str, from_none], self.url) + return result + + +@dataclass +class SessionShellExecResult: + process_id: str + """Unique identifier for tracking streamed output""" + + @staticmethod + def from_dict(obj: Any) -> 'SessionShellExecResult': + assert isinstance(obj, dict) + process_id = from_str(obj.get("processId")) + return SessionShellExecResult(process_id) + + def to_dict(self) -> dict: + result: dict = {} + result["processId"] = from_str(self.process_id) + return result + + +@dataclass +class SessionShellExecParams: + command: str + """Shell command to execute""" + + cwd: str | None = None + """Working directory (defaults to session working directory)""" + + timeout: float | None = None + """Timeout in milliseconds (default: 30000)""" + + @staticmethod + def from_dict(obj: Any) -> 'SessionShellExecParams': + assert isinstance(obj, dict) + command = from_str(obj.get("command")) + cwd = from_union([from_str, from_none], obj.get("cwd")) + timeout = from_union([from_float, from_none], obj.get("timeout")) + return SessionShellExecParams(command, cwd, timeout) + + def to_dict(self) -> dict: + result: dict = {} + result["command"] = from_str(self.command) + if self.cwd is not None: + result["cwd"] = from_union([from_str, from_none], self.cwd) + if self.timeout is not None: + result["timeout"] = from_union([to_float, from_none], self.timeout) + return result + + +@dataclass +class SessionShellKillResult: + killed: bool + """Whether the signal was sent successfully""" + + @staticmethod + def from_dict(obj: Any) -> 'SessionShellKillResult': + assert isinstance(obj, dict) + killed = from_bool(obj.get("killed")) + return SessionShellKillResult(killed) + + def to_dict(self) -> dict: + result: dict = {} + result["killed"] = from_bool(self.killed) + return result + + +class Signal(Enum): + """Signal to send (default: SIGTERM)""" + + SIGINT = "SIGINT" + SIGKILL = "SIGKILL" + SIGTERM = "SIGTERM" + + +@dataclass +class SessionShellKillParams: + process_id: str + """Process identifier returned by shell.exec""" + + signal: Signal | None = None + """Signal to send (default: SIGTERM)""" + + @staticmethod + def from_dict(obj: Any) -> 'SessionShellKillParams': + assert isinstance(obj, dict) + process_id = from_str(obj.get("processId")) + signal = from_union([Signal, from_none], obj.get("signal")) + return SessionShellKillParams(process_id, signal) + + def to_dict(self) -> dict: + result: dict = {} + result["processId"] = from_str(self.process_id) + if self.signal is not None: + result["signal"] = from_union([lambda x: to_enum(Signal, x), from_none], self.signal) + return result + + +def ping_result_from_dict(s: Any) -> PingResult: + return PingResult.from_dict(s) + + def ping_result_to_dict(x: PingResult) -> Any: return to_class(PingResult, x) @@ -1477,6 +2277,166 @@ def session_agent_deselect_result_to_dict(x: SessionAgentDeselectResult) -> Any: return to_class(SessionAgentDeselectResult, x) +def session_agent_reload_result_from_dict(s: Any) -> SessionAgentReloadResult: + return SessionAgentReloadResult.from_dict(s) + + +def session_agent_reload_result_to_dict(x: SessionAgentReloadResult) -> Any: + return to_class(SessionAgentReloadResult, x) + + +def session_skills_list_result_from_dict(s: Any) -> SessionSkillsListResult: + return SessionSkillsListResult.from_dict(s) + + +def session_skills_list_result_to_dict(x: SessionSkillsListResult) -> Any: + return to_class(SessionSkillsListResult, x) + + +def session_skills_enable_result_from_dict(s: Any) -> SessionSkillsEnableResult: + return SessionSkillsEnableResult.from_dict(s) + + +def session_skills_enable_result_to_dict(x: SessionSkillsEnableResult) -> Any: + return to_class(SessionSkillsEnableResult, x) + + +def session_skills_enable_params_from_dict(s: Any) -> SessionSkillsEnableParams: + return SessionSkillsEnableParams.from_dict(s) + + +def session_skills_enable_params_to_dict(x: SessionSkillsEnableParams) -> Any: + return to_class(SessionSkillsEnableParams, x) + + +def session_skills_disable_result_from_dict(s: Any) -> SessionSkillsDisableResult: + return SessionSkillsDisableResult.from_dict(s) + + +def session_skills_disable_result_to_dict(x: SessionSkillsDisableResult) -> Any: + return to_class(SessionSkillsDisableResult, x) + + +def session_skills_disable_params_from_dict(s: Any) -> SessionSkillsDisableParams: + return SessionSkillsDisableParams.from_dict(s) + + +def session_skills_disable_params_to_dict(x: SessionSkillsDisableParams) -> Any: + return to_class(SessionSkillsDisableParams, x) + + +def session_skills_reload_result_from_dict(s: Any) -> SessionSkillsReloadResult: + return SessionSkillsReloadResult.from_dict(s) + + +def session_skills_reload_result_to_dict(x: SessionSkillsReloadResult) -> Any: + return to_class(SessionSkillsReloadResult, x) + + +def session_mcp_list_result_from_dict(s: Any) -> SessionMCPListResult: + return SessionMCPListResult.from_dict(s) + + +def session_mcp_list_result_to_dict(x: SessionMCPListResult) -> Any: + return to_class(SessionMCPListResult, x) + + +def session_mcp_enable_result_from_dict(s: Any) -> SessionMCPEnableResult: + return SessionMCPEnableResult.from_dict(s) + + +def session_mcp_enable_result_to_dict(x: SessionMCPEnableResult) -> Any: + return to_class(SessionMCPEnableResult, x) + + +def session_mcp_enable_params_from_dict(s: Any) -> SessionMCPEnableParams: + return SessionMCPEnableParams.from_dict(s) + + +def session_mcp_enable_params_to_dict(x: SessionMCPEnableParams) -> Any: + return to_class(SessionMCPEnableParams, x) + + +def session_mcp_disable_result_from_dict(s: Any) -> SessionMCPDisableResult: + return SessionMCPDisableResult.from_dict(s) + + +def session_mcp_disable_result_to_dict(x: SessionMCPDisableResult) -> Any: + return to_class(SessionMCPDisableResult, x) + + +def session_mcp_disable_params_from_dict(s: Any) -> SessionMCPDisableParams: + return SessionMCPDisableParams.from_dict(s) + + +def session_mcp_disable_params_to_dict(x: SessionMCPDisableParams) -> Any: + return to_class(SessionMCPDisableParams, x) + + +def session_mcp_reload_result_from_dict(s: Any) -> SessionMCPReloadResult: + return SessionMCPReloadResult.from_dict(s) + + +def session_mcp_reload_result_to_dict(x: SessionMCPReloadResult) -> Any: + return to_class(SessionMCPReloadResult, x) + + +def session_plugins_list_result_from_dict(s: Any) -> SessionPluginsListResult: + return SessionPluginsListResult.from_dict(s) + + +def session_plugins_list_result_to_dict(x: SessionPluginsListResult) -> Any: + return to_class(SessionPluginsListResult, x) + + +def session_extensions_list_result_from_dict(s: Any) -> SessionExtensionsListResult: + return SessionExtensionsListResult.from_dict(s) + + +def session_extensions_list_result_to_dict(x: SessionExtensionsListResult) -> Any: + return to_class(SessionExtensionsListResult, x) + + +def session_extensions_enable_result_from_dict(s: Any) -> SessionExtensionsEnableResult: + return SessionExtensionsEnableResult.from_dict(s) + + +def session_extensions_enable_result_to_dict(x: SessionExtensionsEnableResult) -> Any: + return to_class(SessionExtensionsEnableResult, x) + + +def session_extensions_enable_params_from_dict(s: Any) -> SessionExtensionsEnableParams: + return SessionExtensionsEnableParams.from_dict(s) + + +def session_extensions_enable_params_to_dict(x: SessionExtensionsEnableParams) -> Any: + return to_class(SessionExtensionsEnableParams, x) + + +def session_extensions_disable_result_from_dict(s: Any) -> SessionExtensionsDisableResult: + return SessionExtensionsDisableResult.from_dict(s) + + +def session_extensions_disable_result_to_dict(x: SessionExtensionsDisableResult) -> Any: + return to_class(SessionExtensionsDisableResult, x) + + +def session_extensions_disable_params_from_dict(s: Any) -> SessionExtensionsDisableParams: + return SessionExtensionsDisableParams.from_dict(s) + + +def session_extensions_disable_params_to_dict(x: SessionExtensionsDisableParams) -> Any: + return to_class(SessionExtensionsDisableParams, x) + + +def session_extensions_reload_result_from_dict(s: Any) -> SessionExtensionsReloadResult: + return SessionExtensionsReloadResult.from_dict(s) + + +def session_extensions_reload_result_to_dict(x: SessionExtensionsReloadResult) -> Any: + return to_class(SessionExtensionsReloadResult, x) + + def session_compaction_compact_result_from_dict(s: Any) -> SessionCompactionCompactResult: return SessionCompactionCompactResult.from_dict(s) @@ -1501,6 +2461,38 @@ def session_tools_handle_pending_tool_call_params_to_dict(x: SessionToolsHandleP return to_class(SessionToolsHandlePendingToolCallParams, x) +def session_commands_handle_pending_command_result_from_dict(s: Any) -> SessionCommandsHandlePendingCommandResult: + return SessionCommandsHandlePendingCommandResult.from_dict(s) + + +def session_commands_handle_pending_command_result_to_dict(x: SessionCommandsHandlePendingCommandResult) -> Any: + return to_class(SessionCommandsHandlePendingCommandResult, x) + + +def session_commands_handle_pending_command_params_from_dict(s: Any) -> SessionCommandsHandlePendingCommandParams: + return SessionCommandsHandlePendingCommandParams.from_dict(s) + + +def session_commands_handle_pending_command_params_to_dict(x: SessionCommandsHandlePendingCommandParams) -> Any: + return to_class(SessionCommandsHandlePendingCommandParams, x) + + +def session_ui_elicitation_result_from_dict(s: Any) -> SessionUIElicitationResult: + return SessionUIElicitationResult.from_dict(s) + + +def session_ui_elicitation_result_to_dict(x: SessionUIElicitationResult) -> Any: + return to_class(SessionUIElicitationResult, x) + + +def session_ui_elicitation_params_from_dict(s: Any) -> SessionUIElicitationParams: + return SessionUIElicitationParams.from_dict(s) + + +def session_ui_elicitation_params_to_dict(x: SessionUIElicitationParams) -> Any: + return to_class(SessionUIElicitationParams, x) + + def session_permissions_handle_pending_permission_request_result_from_dict(s: Any) -> SessionPermissionsHandlePendingPermissionRequestResult: return SessionPermissionsHandlePendingPermissionRequestResult.from_dict(s) @@ -1706,6 +2698,88 @@ async def select(self, params: SessionAgentSelectParams, *, timeout: float | Non async def deselect(self, *, timeout: float | None = None) -> SessionAgentDeselectResult: return SessionAgentDeselectResult.from_dict(await self._client.request("session.agent.deselect", {"sessionId": self._session_id}, **_timeout_kwargs(timeout))) + async def reload(self, *, timeout: float | None = None) -> SessionAgentReloadResult: + return SessionAgentReloadResult.from_dict(await self._client.request("session.agent.reload", {"sessionId": self._session_id}, **_timeout_kwargs(timeout))) + + +# Experimental: this API group is experimental and may change or be removed. +class SkillsApi: + def __init__(self, client: "JsonRpcClient", session_id: str): + self._client = client + self._session_id = session_id + + async def list(self, *, timeout: float | None = None) -> SessionSkillsListResult: + return SessionSkillsListResult.from_dict(await self._client.request("session.skills.list", {"sessionId": self._session_id}, **_timeout_kwargs(timeout))) + + async def enable(self, params: SessionSkillsEnableParams, *, timeout: float | None = None) -> SessionSkillsEnableResult: + params_dict = {k: v for k, v in params.to_dict().items() if v is not None} + params_dict["sessionId"] = self._session_id + return SessionSkillsEnableResult.from_dict(await self._client.request("session.skills.enable", params_dict, **_timeout_kwargs(timeout))) + + async def disable(self, params: SessionSkillsDisableParams, *, timeout: float | None = None) -> SessionSkillsDisableResult: + params_dict = {k: v for k, v in params.to_dict().items() if v is not None} + params_dict["sessionId"] = self._session_id + return SessionSkillsDisableResult.from_dict(await self._client.request("session.skills.disable", params_dict, **_timeout_kwargs(timeout))) + + async def reload(self, *, timeout: float | None = None) -> SessionSkillsReloadResult: + return SessionSkillsReloadResult.from_dict(await self._client.request("session.skills.reload", {"sessionId": self._session_id}, **_timeout_kwargs(timeout))) + + +# Experimental: this API group is experimental and may change or be removed. +class McpApi: + def __init__(self, client: "JsonRpcClient", session_id: str): + self._client = client + self._session_id = session_id + + async def list(self, *, timeout: float | None = None) -> SessionMCPListResult: + return SessionMCPListResult.from_dict(await self._client.request("session.mcp.list", {"sessionId": self._session_id}, **_timeout_kwargs(timeout))) + + async def enable(self, params: SessionMCPEnableParams, *, timeout: float | None = None) -> SessionMCPEnableResult: + params_dict = {k: v for k, v in params.to_dict().items() if v is not None} + params_dict["sessionId"] = self._session_id + return SessionMCPEnableResult.from_dict(await self._client.request("session.mcp.enable", params_dict, **_timeout_kwargs(timeout))) + + async def disable(self, params: SessionMCPDisableParams, *, timeout: float | None = None) -> SessionMCPDisableResult: + params_dict = {k: v for k, v in params.to_dict().items() if v is not None} + params_dict["sessionId"] = self._session_id + return SessionMCPDisableResult.from_dict(await self._client.request("session.mcp.disable", params_dict, **_timeout_kwargs(timeout))) + + async def reload(self, *, timeout: float | None = None) -> SessionMCPReloadResult: + return SessionMCPReloadResult.from_dict(await self._client.request("session.mcp.reload", {"sessionId": self._session_id}, **_timeout_kwargs(timeout))) + + +# Experimental: this API group is experimental and may change or be removed. +class PluginsApi: + def __init__(self, client: "JsonRpcClient", session_id: str): + self._client = client + self._session_id = session_id + + async def list(self, *, timeout: float | None = None) -> SessionPluginsListResult: + return SessionPluginsListResult.from_dict(await self._client.request("session.plugins.list", {"sessionId": self._session_id}, **_timeout_kwargs(timeout))) + + +# Experimental: this API group is experimental and may change or be removed. +class ExtensionsApi: + def __init__(self, client: "JsonRpcClient", session_id: str): + self._client = client + self._session_id = session_id + + async def list(self, *, timeout: float | None = None) -> SessionExtensionsListResult: + return SessionExtensionsListResult.from_dict(await self._client.request("session.extensions.list", {"sessionId": self._session_id}, **_timeout_kwargs(timeout))) + + async def enable(self, params: SessionExtensionsEnableParams, *, timeout: float | None = None) -> SessionExtensionsEnableResult: + params_dict = {k: v for k, v in params.to_dict().items() if v is not None} + params_dict["sessionId"] = self._session_id + return SessionExtensionsEnableResult.from_dict(await self._client.request("session.extensions.enable", params_dict, **_timeout_kwargs(timeout))) + + async def disable(self, params: SessionExtensionsDisableParams, *, timeout: float | None = None) -> SessionExtensionsDisableResult: + params_dict = {k: v for k, v in params.to_dict().items() if v is not None} + params_dict["sessionId"] = self._session_id + return SessionExtensionsDisableResult.from_dict(await self._client.request("session.extensions.disable", params_dict, **_timeout_kwargs(timeout))) + + async def reload(self, *, timeout: float | None = None) -> SessionExtensionsReloadResult: + return SessionExtensionsReloadResult.from_dict(await self._client.request("session.extensions.reload", {"sessionId": self._session_id}, **_timeout_kwargs(timeout))) + # Experimental: this API group is experimental and may change or be removed. class CompactionApi: @@ -1728,6 +2802,28 @@ async def handle_pending_tool_call(self, params: SessionToolsHandlePendingToolCa return SessionToolsHandlePendingToolCallResult.from_dict(await self._client.request("session.tools.handlePendingToolCall", params_dict, **_timeout_kwargs(timeout))) +class CommandsApi: + def __init__(self, client: "JsonRpcClient", session_id: str): + self._client = client + self._session_id = session_id + + async def handle_pending_command(self, params: SessionCommandsHandlePendingCommandParams, *, timeout: float | None = None) -> SessionCommandsHandlePendingCommandResult: + params_dict = {k: v for k, v in params.to_dict().items() if v is not None} + params_dict["sessionId"] = self._session_id + return SessionCommandsHandlePendingCommandResult.from_dict(await self._client.request("session.commands.handlePendingCommand", params_dict, **_timeout_kwargs(timeout))) + + +class UiApi: + def __init__(self, client: "JsonRpcClient", session_id: str): + self._client = client + self._session_id = session_id + + async def elicitation(self, params: SessionUIElicitationParams, *, timeout: float | None = None) -> SessionUIElicitationResult: + params_dict = {k: v for k, v in params.to_dict().items() if v is not None} + params_dict["sessionId"] = self._session_id + return SessionUIElicitationResult.from_dict(await self._client.request("session.ui.elicitation", params_dict, **_timeout_kwargs(timeout))) + + class PermissionsApi: def __init__(self, client: "JsonRpcClient", session_id: str): self._client = client @@ -1766,8 +2862,14 @@ def __init__(self, client: "JsonRpcClient", session_id: str): self.workspace = WorkspaceApi(client, session_id) self.fleet = FleetApi(client, session_id) self.agent = AgentApi(client, session_id) + self.skills = SkillsApi(client, session_id) + self.mcp = McpApi(client, session_id) + self.plugins = PluginsApi(client, session_id) + self.extensions = ExtensionsApi(client, session_id) self.compaction = CompactionApi(client, session_id) self.tools = ToolsApi(client, session_id) + self.commands = CommandsApi(client, session_id) + self.ui = UiApi(client, session_id) self.permissions = PermissionsApi(client, session_id) self.shell = ShellApi(client, session_id) diff --git a/python/copilot/generated/session_events.py b/python/copilot/generated/session_events.py index 3fc313399..f3970b815 100644 --- a/python/copilot/generated/session_events.py +++ b/python/copilot/generated/session_events.py @@ -419,6 +419,26 @@ def to_dict(self) -> dict: return result +@dataclass +class DataCommand: + name: str + description: str | None = None + + @staticmethod + def from_dict(obj: Any) -> 'DataCommand': + assert isinstance(obj, dict) + name = from_str(obj.get("name")) + description = from_union([from_str, from_none], obj.get("description")) + return DataCommand(name, description) + + def to_dict(self) -> dict: + result: dict = {} + result["name"] = from_str(self.name) + if self.description is not None: + result["description"] = from_union([from_str, from_none], self.description) + return result + + @dataclass class CompactionTokensUsed: """Token usage breakdown for the compaction LLM call""" @@ -605,7 +625,55 @@ def to_dict(self) -> dict: return result -class Status(Enum): +class Source(Enum): + """Discovery source""" + + PROJECT = "project" + USER = "user" + + +class ExtensionStatus(Enum): + """Current status: running, disabled, failed, or starting""" + + DISABLED = "disabled" + FAILED = "failed" + RUNNING = "running" + STARTING = "starting" + + +@dataclass +class Extension: + id: str + """Source-qualified extension ID (e.g., 'project:my-ext', 'user:auth-helper')""" + + name: str + """Extension name (directory name)""" + + source: Source + """Discovery source""" + + status: ExtensionStatus + """Current status: running, disabled, failed, or starting""" + + @staticmethod + def from_dict(obj: Any) -> 'Extension': + assert isinstance(obj, dict) + id = from_str(obj.get("id")) + name = from_str(obj.get("name")) + source = Source(obj.get("source")) + status = ExtensionStatus(obj.get("status")) + return Extension(id, name, source, status) + + def to_dict(self) -> dict: + result: dict = {} + result["id"] = from_str(self.id) + result["name"] = from_str(self.name) + result["source"] = to_enum(Source, self.source) + result["status"] = to_enum(ExtensionStatus, self.status) + return result + + +class KindStatus(Enum): """Whether the agent completed successfully or failed""" COMPLETED = "completed" @@ -614,6 +682,7 @@ class Status(Enum): class KindType(Enum): AGENT_COMPLETED = "agent_completed" + AGENT_IDLE = "agent_idle" SHELL_COMPLETED = "shell_completed" SHELL_DETACHED_COMPLETED = "shell_detached_completed" @@ -637,7 +706,7 @@ class KindClass: prompt: str | None = None """The full prompt given to the background agent""" - status: Status | None = None + status: KindStatus | None = None """Whether the agent completed successfully or failed""" exit_code: float | None = None @@ -657,7 +726,7 @@ def from_dict(obj: Any) -> 'KindClass': agent_type = from_union([from_str, from_none], obj.get("agentType")) description = from_union([from_str, from_none], obj.get("description")) prompt = from_union([from_str, from_none], obj.get("prompt")) - status = from_union([Status, from_none], obj.get("status")) + status = from_union([KindStatus, from_none], obj.get("status")) exit_code = from_union([from_float, from_none], obj.get("exitCode")) shell_id = from_union([from_str, from_none], obj.get("shellId")) return KindClass(type, agent_id, agent_type, description, prompt, status, exit_code, shell_id) @@ -674,7 +743,7 @@ def to_dict(self) -> dict: if self.prompt is not None: result["prompt"] = from_union([from_str, from_none], self.prompt) if self.status is not None: - result["status"] = from_union([lambda x: to_enum(Status, x), from_none], self.status) + result["status"] = from_union([lambda x: to_enum(KindStatus, x), from_none], self.status) if self.exit_code is not None: result["exitCode"] = from_union([to_float, from_none], self.exit_code) if self.shell_id is not None: @@ -709,7 +778,11 @@ def to_dict(self) -> dict: class Mode(Enum): + """Elicitation mode; "form" for structured input, "url" for browser-based. Defaults to + "form" when absent. + """ FORM = "form" + URL = "url" @dataclass @@ -803,7 +876,7 @@ class Operation(Enum): @dataclass -class Command: +class PermissionRequestCommand: identifier: str """Command identifier (e.g., executable name)""" @@ -811,11 +884,11 @@ class Command: """Whether this command is read-only (no side effects)""" @staticmethod - def from_dict(obj: Any) -> 'Command': + def from_dict(obj: Any) -> 'PermissionRequestCommand': assert isinstance(obj, dict) identifier = from_str(obj.get("identifier")) read_only = from_bool(obj.get("readOnly")) - return Command(identifier, read_only) + return PermissionRequestCommand(identifier, read_only) def to_dict(self) -> dict: result: dict = {} @@ -878,7 +951,7 @@ class PermissionRequest: can_offer_session_approval: bool | None = None """Whether the UI can offer session-wide approval for this command pattern""" - commands: list[Command] | None = None + commands: list[PermissionRequestCommand] | None = None """Parsed command identifiers found in the command text""" full_command_text: str | None = None @@ -967,7 +1040,7 @@ def from_dict(obj: Any) -> 'PermissionRequest': assert isinstance(obj, dict) kind = PermissionRequestKind(obj.get("kind")) can_offer_session_approval = from_union([from_bool, from_none], obj.get("canOfferSessionApproval")) - commands = from_union([lambda x: from_list(Command.from_dict, x), from_none], obj.get("commands")) + commands = from_union([lambda x: from_list(PermissionRequestCommand.from_dict, x), from_none], obj.get("commands")) full_command_text = from_union([from_str, from_none], obj.get("fullCommandText")) has_write_file_redirection = from_union([from_bool, from_none], obj.get("hasWriteFileRedirection")) intention = from_union([from_str, from_none], obj.get("intention")) @@ -999,7 +1072,7 @@ def to_dict(self) -> dict: if self.can_offer_session_approval is not None: result["canOfferSessionApproval"] = from_union([from_bool, from_none], self.can_offer_session_approval) if self.commands is not None: - result["commands"] = from_union([lambda x: from_list(lambda x: to_class(Command, x), x), from_none], self.commands) + result["commands"] = from_union([lambda x: from_list(lambda x: to_class(PermissionRequestCommand, x), x), from_none], self.commands) if self.full_command_text is not None: result["fullCommandText"] = from_union([from_str, from_none], self.full_command_text) if self.has_write_file_redirection is not None: @@ -1138,7 +1211,7 @@ class RequestedSchemaType(Enum): @dataclass class RequestedSchema: - """JSON Schema describing the form fields to present to the user""" + """JSON Schema describing the form fields to present to the user (form mode only)""" properties: dict[str, Any] """Form field definitions, keyed by field name""" @@ -1430,6 +1503,52 @@ class Role(Enum): SYSTEM = "system" +class ServerStatus(Enum): + """Connection status: connected, failed, pending, disabled, or not_configured + + New connection status: connected, failed, pending, disabled, or not_configured + """ + CONNECTED = "connected" + DISABLED = "disabled" + FAILED = "failed" + NOT_CONFIGURED = "not_configured" + PENDING = "pending" + + +@dataclass +class Server: + name: str + """Server name (config key)""" + + status: ServerStatus + """Connection status: connected, failed, pending, disabled, or not_configured""" + + error: str | None = None + """Error message if the server failed to connect""" + + source: str | None = None + """Configuration source: user, workspace, plugin, or builtin""" + + @staticmethod + def from_dict(obj: Any) -> 'Server': + assert isinstance(obj, dict) + name = from_str(obj.get("name")) + status = ServerStatus(obj.get("status")) + error = from_union([from_str, from_none], obj.get("error")) + source = from_union([from_str, from_none], obj.get("source")) + return Server(name, status, error, source) + + def to_dict(self) -> dict: + result: dict = {} + result["name"] = from_str(self.name) + result["status"] = to_enum(ServerStatus, self.status) + if self.error is not None: + result["error"] = from_union([from_str, from_none], self.error) + if self.source is not None: + result["source"] = from_union([from_str, from_none], self.source) + return result + + class ShutdownType(Enum): """Whether the session ended normally ("routine") or due to a crash/fatal error ("error")""" @@ -1437,20 +1556,47 @@ class ShutdownType(Enum): ROUTINE = "routine" -class Source(Enum): - """Origin of this message, used for timeline filtering and telemetry (e.g., "user", - "autopilot", "skill", or "command") - """ - AUTOPILOT = "autopilot" - COMMAND = "command" - IMMEDIATE_PROMPT = "immediate-prompt" - JIT_INSTRUCTION = "jit-instruction" - OTHER = "other" - SKILL = "skill" - SNIPPY_BLOCKING = "snippy-blocking" - SYSTEM = "system" - THINKING_EXHAUSTED_CONTINUATION = "thinking-exhausted-continuation" - USER = "user" +@dataclass +class Skill: + description: str + """Description of what the skill does""" + + enabled: bool + """Whether the skill is currently enabled""" + + name: str + """Unique identifier for the skill""" + + source: str + """Source location type of the skill (e.g., project, personal, plugin)""" + + user_invocable: bool + """Whether the skill can be invoked by the user as a slash command""" + + path: str | None = None + """Absolute path to the skill file, if available""" + + @staticmethod + def from_dict(obj: Any) -> 'Skill': + assert isinstance(obj, dict) + description = from_str(obj.get("description")) + enabled = from_bool(obj.get("enabled")) + name = from_str(obj.get("name")) + source = from_str(obj.get("source")) + user_invocable = from_bool(obj.get("userInvocable")) + path = from_union([from_str, from_none], obj.get("path")) + return Skill(description, enabled, name, source, user_invocable, path) + + def to_dict(self) -> dict: + result: dict = {} + result["description"] = from_str(self.description) + result["enabled"] = from_bool(self.enabled) + result["name"] = from_str(self.name) + result["source"] = from_str(self.source) + result["userInvocable"] = from_bool(self.user_invocable) + if self.path is not None: + result["path"] = from_union([from_str, from_none], self.path) + return result class SourceType(Enum): @@ -1460,6 +1606,31 @@ class SourceType(Enum): REMOTE = "remote" +@dataclass +class StaticClientConfig: + """Static OAuth client configuration, if the server specifies one""" + + client_id: str + """OAuth client ID for the server""" + + public_client: bool | None = None + """Whether this is a public OAuth client""" + + @staticmethod + def from_dict(obj: Any) -> 'StaticClientConfig': + assert isinstance(obj, dict) + client_id = from_str(obj.get("clientId")) + public_client = from_union([from_bool, from_none], obj.get("publicClient")) + return StaticClientConfig(client_id, public_client) + + def to_dict(self) -> dict: + result: dict = {} + result["clientId"] = from_str(self.client_id) + if self.public_client is not None: + result["publicClient"] = from_union([from_bool, from_none], self.public_client) + return result + + class ToolRequestType(Enum): """Tool call type: "function" for standard tool calls, "custom" for grammar-based tool calls. Defaults to "function" when absent. @@ -1555,15 +1726,12 @@ class Data: Current context window usage statistics including token and message counts - Empty payload; the event signals that LLM-powered conversation compaction has begun + Context window breakdown at the start of LLM-powered conversation compaction Conversation compaction results including success status, metrics, and optional error details - Task completion notification with optional summary from the agent - - User message content with optional attachments, source information, and interaction - metadata + Task completion notification with summary from the agent Empty payload; the event signals that the pending message queue has changed @@ -1629,18 +1797,27 @@ class Data: User input request completion notification signaling UI dismissal - Structured form elicitation request with JSON schema definition for form fields + Elicitation request; may be form-based (structured input) or URL-based (browser + redirect) Elicitation request completion notification signaling UI dismissal + OAuth authentication request for an MCP server + + MCP OAuth request completion notification + External tool invocation request for client-side tool execution External tool completion notification signaling UI dismissal Queued slash command dispatch request for client execution + Registered command dispatch request routed to the owning client + Queued command completion notification signaling UI dismissal + SDK command registration change notification + Plan approval request with plan content and available user actions Plan mode exit completion notification signaling UI dismissal @@ -1716,6 +1893,15 @@ class Data: status_code: int | None = None """HTTP status code from the upstream request, if applicable""" + url: str | None = None + """Optional URL associated with this error that the user can open in a browser + + Optional URL associated with this message that the user can open in a browser + + Optional URL associated with this warning that the user can open in a browser + + URL to open in the user's browser (url mode only) + """ background_tasks: BackgroundTasks | None = None """Background tasks still running when the agent became idle""" @@ -1772,7 +1958,7 @@ class Data: summary: str | None = None """Summary of the work done in the source session - Optional summary of the completed task, provided by the agent + Summary of the completed task, provided by the agent Summary of the plan that was created """ @@ -1809,9 +1995,23 @@ class Data: code_changes: CodeChanges | None = None """Aggregate code change metrics for the session""" + conversation_tokens: float | None = None + """Non-system message token count at shutdown + + Token count from non-system messages (user, assistant, tool) + + Token count from non-system messages (user, assistant, tool) at compaction start + + Token count from non-system messages (user, assistant, tool) after compaction + """ current_model: str | None = None """Model that was selected at the time of shutdown""" + current_tokens: float | None = None + """Total tokens in context window at shutdown + + Current number of tokens in the context window + """ error_reason: str | None = None """Error description when shutdownType is "error\"""" @@ -1824,6 +2024,24 @@ class Data: shutdown_type: ShutdownType | None = None """Whether the session ended normally ("routine") or due to a crash/fatal error ("error")""" + system_tokens: float | None = None + """System message token count at shutdown + + Token count from system message(s) + + Token count from system message(s) at compaction start + + Token count from system message(s) after compaction + """ + tool_definitions_tokens: float | None = None + """Tool definitions token count at shutdown + + Token count from tool definitions + + Token count from tool definitions at compaction start + + Token count from tool definitions after compaction + """ total_api_duration_ms: float | None = None """Cumulative time spent in API calls during the session, in milliseconds""" @@ -1848,8 +2066,8 @@ class Data: host_type: HostType | None = None """Hosting platform type of the repository (github or ado)""" - current_tokens: float | None = None - """Current number of tokens in the context window""" + is_initial: bool | None = None + """Whether this is the first usage_info event emitted in this session""" messages_length: float | None = None """Current number of messages in the conversation""" @@ -1905,6 +2123,11 @@ class Data: Request ID of the resolved elicitation request; clients should dismiss any UI for this request + Unique identifier for this OAuth request; used to respond via + session.respondToMcpOAuth() + + Request ID of the resolved OAuth request + Unique identifier for this request; used to respond via session.respondToExternalTool() Request ID of the resolved external tool request; clients should dismiss any UI for this @@ -1912,6 +2135,8 @@ class Data: Unique identifier for this request; used to respond via session.respondToQueuedCommand() + Unique identifier; used to respond via session.commands.handlePendingCommand() + Request ID of the resolved command request; clients should dismiss any UI for this request @@ -1923,6 +2148,8 @@ class Data: success: bool | None = None """Whether compaction completed successfully + Whether the tool call succeeded. False when validation failed (e.g., invalid arguments) + Whether the tool execution completed successfully Whether the hook completed successfully @@ -1961,9 +2188,9 @@ class Data: CAPI interaction ID for correlating this tool execution with upstream telemetry """ - source: Source | None = None - """Origin of this message, used for timeline filtering and telemetry (e.g., "user", - "autopilot", "skill", or "command") + source: str | None = None + """Origin of this message, used for timeline filtering (e.g., "skill-pdf" for skill-injected + messages that should be hidden from the user) """ transformed_content: str | None = None """Transformed version of the message sent to the model, with XML wrapping, timestamps, and @@ -2077,6 +2304,12 @@ class Data: Tool call ID of the parent tool invocation that spawned this sub-agent + The LLM-assigned tool call ID that triggered this request; used by remote UIs to + correlate responses + + Tool call ID from the LLM completion; used to correlate with CompletionChunk.toolCall.id + for remote UIs + Tool call ID assigned to this external tool invocation """ tool_name: str | None = None @@ -2176,11 +2409,26 @@ class Data: question: str | None = None """The question or prompt to present to the user""" - mode: Mode | None = None - """Elicitation mode; currently only "form" is supported. Defaults to "form" when absent.""" + elicitation_source: str | None = None + """The source that initiated the request (MCP server name, or absent for agent-initiated)""" + mode: Mode | None = None + """Elicitation mode; "form" for structured input, "url" for browser-based. Defaults to + "form" when absent. + """ requested_schema: RequestedSchema | None = None - """JSON Schema describing the form fields to present to the user""" + """JSON Schema describing the form fields to present to the user (form mode only)""" + + server_name: str | None = None + """Display name of the MCP server that requires OAuth + + Name of the MCP server whose status changed + """ + server_url: str | None = None + """URL of the MCP server that requires OAuth""" + + static_client_config: StaticClientConfig | None = None + """Static OAuth client configuration, if the server specifies one""" traceparent: str | None = None """W3C Trace Context traceparent header for the execute_tool span""" @@ -2189,7 +2437,18 @@ class Data: """W3C Trace Context tracestate header for the execute_tool span""" command: str | None = None - """The slash command text to be executed (e.g., /help, /clear)""" + """The slash command text to be executed (e.g., /help, /clear) + + The full command text (e.g., /deploy production) + """ + args: str | None = None + """Raw argument string after the command name""" + + command_name: str | None = None + """Command name without leading /""" + + commands: list[DataCommand] | None = None + """Current list of registered SDK commands""" actions: list[str] | None = None """Available actions the user can take (e.g., approve, edit, reject)""" @@ -2200,6 +2459,18 @@ class Data: recommended_action: str | None = None """The recommended action for the user to take""" + skills: list[Skill] | None = None + """Array of resolved skill metadata""" + + servers: list[Server] | None = None + """Array of MCP server status summaries""" + + status: ServerStatus | None = None + """New connection status: connected, failed, pending, disabled, or not_configured""" + + extensions: list[Extension] | None = None + """Array of discovered extensions and their status""" + @staticmethod def from_dict(obj: Any) -> 'Data': assert isinstance(obj, dict) @@ -2219,6 +2490,7 @@ def from_dict(obj: Any) -> 'Data': provider_call_id = from_union([from_str, from_none], obj.get("providerCallId")) stack = from_union([from_str, from_none], obj.get("stack")) status_code = from_union([from_int, from_none], obj.get("statusCode")) + url = from_union([from_str, from_none], obj.get("url")) background_tasks = from_union([BackgroundTasks.from_dict, from_none], obj.get("backgroundTasks")) title = from_union([from_str, from_none], obj.get("title")) info_type = from_union([from_str, from_none], obj.get("infoType")) @@ -2246,11 +2518,15 @@ def from_dict(obj: Any) -> 'Data': events_removed = from_union([from_float, from_none], obj.get("eventsRemoved")) up_to_event_id = from_union([from_str, from_none], obj.get("upToEventId")) code_changes = from_union([CodeChanges.from_dict, from_none], obj.get("codeChanges")) + conversation_tokens = from_union([from_float, from_none], obj.get("conversationTokens")) current_model = from_union([from_str, from_none], obj.get("currentModel")) + current_tokens = from_union([from_float, from_none], obj.get("currentTokens")) error_reason = from_union([from_str, from_none], obj.get("errorReason")) model_metrics = from_union([lambda x: from_dict(ModelMetric.from_dict, x), from_none], obj.get("modelMetrics")) session_start_time = from_union([from_float, from_none], obj.get("sessionStartTime")) shutdown_type = from_union([ShutdownType, from_none], obj.get("shutdownType")) + system_tokens = from_union([from_float, from_none], obj.get("systemTokens")) + tool_definitions_tokens = from_union([from_float, from_none], obj.get("toolDefinitionsTokens")) total_api_duration_ms = from_union([from_float, from_none], obj.get("totalApiDurationMs")) total_premium_requests = from_union([from_float, from_none], obj.get("totalPremiumRequests")) base_commit = from_union([from_str, from_none], obj.get("baseCommit")) @@ -2259,7 +2535,7 @@ def from_dict(obj: Any) -> 'Data': git_root = from_union([from_str, from_none], obj.get("gitRoot")) head_commit = from_union([from_str, from_none], obj.get("headCommit")) host_type = from_union([HostType, from_none], obj.get("hostType")) - current_tokens = from_union([from_float, from_none], obj.get("currentTokens")) + is_initial = from_union([from_bool, from_none], obj.get("isInitial")) messages_length = from_union([from_float, from_none], obj.get("messagesLength")) checkpoint_number = from_union([from_float, from_none], obj.get("checkpointNumber")) checkpoint_path = from_union([from_str, from_none], obj.get("checkpointPath")) @@ -2277,7 +2553,7 @@ def from_dict(obj: Any) -> 'Data': attachments = from_union([lambda x: from_list(Attachment.from_dict, x), from_none], obj.get("attachments")) content = from_union([from_str, from_none], obj.get("content")) interaction_id = from_union([from_str, from_none], obj.get("interactionId")) - source = from_union([Source, from_none], obj.get("source")) + source = from_union([from_str, from_none], obj.get("source")) transformed_content = from_union([from_str, from_none], obj.get("transformedContent")) turn_id = from_union([from_str, from_none], obj.get("turnId")) intent = from_union([from_str, from_none], obj.get("intent")) @@ -2332,15 +2608,26 @@ def from_dict(obj: Any) -> 'Data': allow_freeform = from_union([from_bool, from_none], obj.get("allowFreeform")) choices = from_union([lambda x: from_list(from_str, x), from_none], obj.get("choices")) question = from_union([from_str, from_none], obj.get("question")) + elicitation_source = from_union([from_str, from_none], obj.get("elicitationSource")) mode = from_union([Mode, from_none], obj.get("mode")) requested_schema = from_union([RequestedSchema.from_dict, from_none], obj.get("requestedSchema")) + server_name = from_union([from_str, from_none], obj.get("serverName")) + server_url = from_union([from_str, from_none], obj.get("serverUrl")) + static_client_config = from_union([StaticClientConfig.from_dict, from_none], obj.get("staticClientConfig")) traceparent = from_union([from_str, from_none], obj.get("traceparent")) tracestate = from_union([from_str, from_none], obj.get("tracestate")) command = from_union([from_str, from_none], obj.get("command")) + args = from_union([from_str, from_none], obj.get("args")) + command_name = from_union([from_str, from_none], obj.get("commandName")) + commands = from_union([lambda x: from_list(DataCommand.from_dict, x), from_none], obj.get("commands")) actions = from_union([lambda x: from_list(from_str, x), from_none], obj.get("actions")) plan_content = from_union([from_str, from_none], obj.get("planContent")) recommended_action = from_union([from_str, from_none], obj.get("recommendedAction")) - return Data(already_in_use, context, copilot_version, producer, reasoning_effort, selected_model, session_id, start_time, version, event_count, resume_time, error_type, message, provider_call_id, stack, status_code, background_tasks, title, info_type, warning_type, new_model, previous_model, previous_reasoning_effort, new_mode, previous_mode, operation, path, handoff_time, remote_session_id, repository, source_type, summary, messages_removed_during_truncation, performed_by, post_truncation_messages_length, post_truncation_tokens_in_messages, pre_truncation_messages_length, pre_truncation_tokens_in_messages, token_limit, tokens_removed_during_truncation, events_removed, up_to_event_id, code_changes, current_model, error_reason, model_metrics, session_start_time, shutdown_type, total_api_duration_ms, total_premium_requests, base_commit, branch, cwd, git_root, head_commit, host_type, current_tokens, messages_length, checkpoint_number, checkpoint_path, compaction_tokens_used, error, messages_removed, post_compaction_tokens, pre_compaction_messages_length, pre_compaction_tokens, request_id, success, summary_content, tokens_removed, agent_mode, attachments, content, interaction_id, source, transformed_content, turn_id, intent, reasoning_id, delta_content, total_response_size_bytes, encrypted_content, message_id, output_tokens, parent_tool_call_id, phase, reasoning_opaque, reasoning_text, tool_requests, api_call_id, cache_read_tokens, cache_write_tokens, copilot_usage, cost, duration, initiator, input_tokens, model, quota_snapshots, reason, arguments, tool_call_id, tool_name, mcp_server_name, mcp_tool_name, partial_output, progress_message, is_user_requested, result, tool_telemetry, allowed_tools, name, plugin_name, plugin_version, agent_description, agent_display_name, agent_name, tools, hook_invocation_id, hook_type, input, output, metadata, role, kind, permission_request, allow_freeform, choices, question, mode, requested_schema, traceparent, tracestate, command, actions, plan_content, recommended_action) + skills = from_union([lambda x: from_list(Skill.from_dict, x), from_none], obj.get("skills")) + servers = from_union([lambda x: from_list(Server.from_dict, x), from_none], obj.get("servers")) + status = from_union([ServerStatus, from_none], obj.get("status")) + extensions = from_union([lambda x: from_list(Extension.from_dict, x), from_none], obj.get("extensions")) + return Data(already_in_use, context, copilot_version, producer, reasoning_effort, selected_model, session_id, start_time, version, event_count, resume_time, error_type, message, provider_call_id, stack, status_code, url, background_tasks, title, info_type, warning_type, new_model, previous_model, previous_reasoning_effort, new_mode, previous_mode, operation, path, handoff_time, remote_session_id, repository, source_type, summary, messages_removed_during_truncation, performed_by, post_truncation_messages_length, post_truncation_tokens_in_messages, pre_truncation_messages_length, pre_truncation_tokens_in_messages, token_limit, tokens_removed_during_truncation, events_removed, up_to_event_id, code_changes, conversation_tokens, current_model, current_tokens, error_reason, model_metrics, session_start_time, shutdown_type, system_tokens, tool_definitions_tokens, total_api_duration_ms, total_premium_requests, base_commit, branch, cwd, git_root, head_commit, host_type, is_initial, messages_length, checkpoint_number, checkpoint_path, compaction_tokens_used, error, messages_removed, post_compaction_tokens, pre_compaction_messages_length, pre_compaction_tokens, request_id, success, summary_content, tokens_removed, agent_mode, attachments, content, interaction_id, source, transformed_content, turn_id, intent, reasoning_id, delta_content, total_response_size_bytes, encrypted_content, message_id, output_tokens, parent_tool_call_id, phase, reasoning_opaque, reasoning_text, tool_requests, api_call_id, cache_read_tokens, cache_write_tokens, copilot_usage, cost, duration, initiator, input_tokens, model, quota_snapshots, reason, arguments, tool_call_id, tool_name, mcp_server_name, mcp_tool_name, partial_output, progress_message, is_user_requested, result, tool_telemetry, allowed_tools, name, plugin_name, plugin_version, agent_description, agent_display_name, agent_name, tools, hook_invocation_id, hook_type, input, output, metadata, role, kind, permission_request, allow_freeform, choices, question, elicitation_source, mode, requested_schema, server_name, server_url, static_client_config, traceparent, tracestate, command, args, command_name, commands, actions, plan_content, recommended_action, skills, servers, status, extensions) def to_dict(self) -> dict: result: dict = {} @@ -2376,6 +2663,8 @@ def to_dict(self) -> dict: result["stack"] = from_union([from_str, from_none], self.stack) if self.status_code is not None: result["statusCode"] = from_union([from_int, from_none], self.status_code) + if self.url is not None: + result["url"] = from_union([from_str, from_none], self.url) if self.background_tasks is not None: result["backgroundTasks"] = from_union([lambda x: to_class(BackgroundTasks, x), from_none], self.background_tasks) if self.title is not None: @@ -2430,8 +2719,12 @@ def to_dict(self) -> dict: result["upToEventId"] = from_union([from_str, from_none], self.up_to_event_id) if self.code_changes is not None: result["codeChanges"] = from_union([lambda x: to_class(CodeChanges, x), from_none], self.code_changes) + if self.conversation_tokens is not None: + result["conversationTokens"] = from_union([to_float, from_none], self.conversation_tokens) if self.current_model is not None: result["currentModel"] = from_union([from_str, from_none], self.current_model) + if self.current_tokens is not None: + result["currentTokens"] = from_union([to_float, from_none], self.current_tokens) if self.error_reason is not None: result["errorReason"] = from_union([from_str, from_none], self.error_reason) if self.model_metrics is not None: @@ -2440,6 +2733,10 @@ def to_dict(self) -> dict: result["sessionStartTime"] = from_union([to_float, from_none], self.session_start_time) if self.shutdown_type is not None: result["shutdownType"] = from_union([lambda x: to_enum(ShutdownType, x), from_none], self.shutdown_type) + if self.system_tokens is not None: + result["systemTokens"] = from_union([to_float, from_none], self.system_tokens) + if self.tool_definitions_tokens is not None: + result["toolDefinitionsTokens"] = from_union([to_float, from_none], self.tool_definitions_tokens) if self.total_api_duration_ms is not None: result["totalApiDurationMs"] = from_union([to_float, from_none], self.total_api_duration_ms) if self.total_premium_requests is not None: @@ -2456,8 +2753,8 @@ def to_dict(self) -> dict: result["headCommit"] = from_union([from_str, from_none], self.head_commit) if self.host_type is not None: result["hostType"] = from_union([lambda x: to_enum(HostType, x), from_none], self.host_type) - if self.current_tokens is not None: - result["currentTokens"] = from_union([to_float, from_none], self.current_tokens) + if self.is_initial is not None: + result["isInitial"] = from_union([from_bool, from_none], self.is_initial) if self.messages_length is not None: result["messagesLength"] = from_union([to_float, from_none], self.messages_length) if self.checkpoint_number is not None: @@ -2493,7 +2790,7 @@ def to_dict(self) -> dict: if self.interaction_id is not None: result["interactionId"] = from_union([from_str, from_none], self.interaction_id) if self.source is not None: - result["source"] = from_union([lambda x: to_enum(Source, x), from_none], self.source) + result["source"] = from_union([from_str, from_none], self.source) if self.transformed_content is not None: result["transformedContent"] = from_union([from_str, from_none], self.transformed_content) if self.turn_id is not None: @@ -2602,22 +2899,44 @@ def to_dict(self) -> dict: result["choices"] = from_union([lambda x: from_list(from_str, x), from_none], self.choices) if self.question is not None: result["question"] = from_union([from_str, from_none], self.question) + if self.elicitation_source is not None: + result["elicitationSource"] = from_union([from_str, from_none], self.elicitation_source) if self.mode is not None: result["mode"] = from_union([lambda x: to_enum(Mode, x), from_none], self.mode) if self.requested_schema is not None: result["requestedSchema"] = from_union([lambda x: to_class(RequestedSchema, x), from_none], self.requested_schema) + if self.server_name is not None: + result["serverName"] = from_union([from_str, from_none], self.server_name) + if self.server_url is not None: + result["serverUrl"] = from_union([from_str, from_none], self.server_url) + if self.static_client_config is not None: + result["staticClientConfig"] = from_union([lambda x: to_class(StaticClientConfig, x), from_none], self.static_client_config) if self.traceparent is not None: result["traceparent"] = from_union([from_str, from_none], self.traceparent) if self.tracestate is not None: result["tracestate"] = from_union([from_str, from_none], self.tracestate) if self.command is not None: result["command"] = from_union([from_str, from_none], self.command) + if self.args is not None: + result["args"] = from_union([from_str, from_none], self.args) + if self.command_name is not None: + result["commandName"] = from_union([from_str, from_none], self.command_name) + if self.commands is not None: + result["commands"] = from_union([lambda x: from_list(lambda x: to_class(DataCommand, x), x), from_none], self.commands) if self.actions is not None: result["actions"] = from_union([lambda x: from_list(from_str, x), from_none], self.actions) if self.plan_content is not None: result["planContent"] = from_union([from_str, from_none], self.plan_content) if self.recommended_action is not None: result["recommendedAction"] = from_union([from_str, from_none], self.recommended_action) + if self.skills is not None: + result["skills"] = from_union([lambda x: from_list(lambda x: to_class(Skill, x), x), from_none], self.skills) + if self.servers is not None: + result["servers"] = from_union([lambda x: from_list(lambda x: to_class(Server, x), x), from_none], self.servers) + if self.status is not None: + result["status"] = from_union([lambda x: to_enum(ServerStatus, x), from_none], self.status) + if self.extensions is not None: + result["extensions"] = from_union([lambda x: from_list(lambda x: to_class(Extension, x), x), from_none], self.extensions) return result @@ -2632,7 +2951,9 @@ class SessionEventType(Enum): ASSISTANT_TURN_END = "assistant.turn_end" ASSISTANT_TURN_START = "assistant.turn_start" ASSISTANT_USAGE = "assistant.usage" + COMMANDS_CHANGED = "commands.changed" COMMAND_COMPLETED = "command.completed" + COMMAND_EXECUTE = "command.execute" COMMAND_QUEUED = "command.queued" ELICITATION_COMPLETED = "elicitation.completed" ELICITATION_REQUESTED = "elicitation.requested" @@ -2642,6 +2963,8 @@ class SessionEventType(Enum): EXTERNAL_TOOL_REQUESTED = "external_tool.requested" HOOK_END = "hook.end" HOOK_START = "hook.start" + MCP_OAUTH_COMPLETED = "mcp.oauth_completed" + MCP_OAUTH_REQUIRED = "mcp.oauth_required" PENDING_MESSAGES_MODIFIED = "pending_messages.modified" PERMISSION_COMPLETED = "permission.completed" PERMISSION_REQUESTED = "permission.requested" @@ -2650,14 +2973,18 @@ class SessionEventType(Enum): SESSION_COMPACTION_START = "session.compaction_start" SESSION_CONTEXT_CHANGED = "session.context_changed" SESSION_ERROR = "session.error" + SESSION_EXTENSIONS_LOADED = "session.extensions_loaded" SESSION_HANDOFF = "session.handoff" SESSION_IDLE = "session.idle" SESSION_INFO = "session.info" + SESSION_MCP_SERVERS_LOADED = "session.mcp_servers_loaded" + SESSION_MCP_SERVER_STATUS_CHANGED = "session.mcp_server_status_changed" SESSION_MODEL_CHANGE = "session.model_change" SESSION_MODE_CHANGED = "session.mode_changed" SESSION_PLAN_CHANGED = "session.plan_changed" SESSION_RESUME = "session.resume" SESSION_SHUTDOWN = "session.shutdown" + SESSION_SKILLS_LOADED = "session.skills_loaded" SESSION_SNAPSHOT_REWIND = "session.snapshot_rewind" SESSION_START = "session.start" SESSION_TASK_COMPLETE = "session.task_complete" @@ -2731,15 +3058,12 @@ class SessionEvent: Current context window usage statistics including token and message counts - Empty payload; the event signals that LLM-powered conversation compaction has begun + Context window breakdown at the start of LLM-powered conversation compaction Conversation compaction results including success status, metrics, and optional error details - Task completion notification with optional summary from the agent - - User message content with optional attachments, source information, and interaction - metadata + Task completion notification with summary from the agent Empty payload; the event signals that the pending message queue has changed @@ -2805,18 +3129,27 @@ class SessionEvent: User input request completion notification signaling UI dismissal - Structured form elicitation request with JSON schema definition for form fields + Elicitation request; may be form-based (structured input) or URL-based (browser + redirect) Elicitation request completion notification signaling UI dismissal + OAuth authentication request for an MCP server + + MCP OAuth request completion notification + External tool invocation request for client-side tool execution External tool completion notification signaling UI dismissal Queued slash command dispatch request for client execution + Registered command dispatch request routed to the owning client + Queued command completion notification signaling UI dismissal + SDK command registration change notification + Plan approval request with plan content and available user actions Plan mode exit completion notification signaling UI dismissal diff --git a/python/e2e/test_agent_and_compact_rpc.py b/python/e2e/test_agent_and_compact_rpc.py index 63d3e7322..e82fcc024 100644 --- a/python/e2e/test_agent_and_compact_rpc.py +++ b/python/e2e/test_agent_and_compact_rpc.py @@ -147,7 +147,7 @@ async def test_should_deselect_current_agent(self): @pytest.mark.asyncio async def test_should_return_empty_list_when_no_custom_agents_configured(self): - """Test listing agents returns empty when none configured.""" + """Test listing agents returns no custom agents when none configured.""" client = CopilotClient(SubprocessConfig(cli_path=CLI_PATH, use_stdio=True)) try: @@ -157,7 +157,13 @@ async def test_should_return_empty_list_when_no_custom_agents_configured(self): ) result = await session.rpc.agent.list() - assert result.agents == [] + # The CLI may return built-in/default agents even when no custom agents + # are configured. Verify no custom test agents appear in the list. + custom_names = {"test-agent", "another-agent"} + for agent in result.agents: + assert agent.name not in custom_names, ( + f"Expected no custom agents, but found {agent.name!r}" + ) await session.disconnect() await client.stop() diff --git a/scripts/codegen/go.ts b/scripts/codegen/go.ts index c467761d0..59abee298 100644 --- a/scripts/codegen/go.ts +++ b/scripts/codegen/go.ts @@ -45,6 +45,77 @@ function toGoFieldName(jsonName: string): string { .join(""); } +/** + * Post-process Go enum constants so every constant follows the canonical + * Go `TypeNameValue` convention. quicktype disambiguates collisions with + * whimsical prefixes (Purple, Fluffy, …) that we replace. + */ +function postProcessEnumConstants(code: string): string { + const renames = new Map(); + + // Match constant declarations inside const ( … ) blocks. + const constLineRe = /^\s+(\w+)\s+(\w+)\s*=\s*"([^"]+)"/gm; + let m; + while ((m = constLineRe.exec(code)) !== null) { + const [, constName, typeName, value] = m; + if (constName.startsWith(typeName)) continue; + + // Use the same initialism logic as toPascalCase so "url" → "URL", "mcp" → "MCP", etc. + const valuePascal = value + .split(/[._-]/) + .map((w) => goInitialisms.has(w.toLowerCase()) ? w.toUpperCase() : w.charAt(0).toUpperCase() + w.slice(1)) + .join(""); + const desired = typeName + valuePascal; + if (constName !== desired) { + renames.set(constName, desired); + } + } + + // Replace each const block in place, then fix switch-case references + // in marshal/unmarshal functions. This avoids renaming struct fields. + + // Phase 1: Rename inside const ( … ) blocks + code = code.replace(/^(const \([\s\S]*?\n\))/gm, (block) => { + let b = block; + for (const [oldName, newName] of renames) { + b = b.replace(new RegExp(`\\b${oldName}\\b`, "g"), newName); + } + return b; + }); + + // Phase 2: Rename inside func bodies (marshal/unmarshal helpers use case statements) + code = code.replace(/^(func \([\s\S]*?\n\})/gm, (funcBlock) => { + let b = funcBlock; + for (const [oldName, newName] of renames) { + b = b.replace(new RegExp(`\\b${oldName}\\b`, "g"), newName); + } + return b; + }); + + return code; +} + +/** + * Extract a mapping from (structName, jsonFieldName) → goFieldName + * so the wrapper code references the actual quicktype-generated field names. + */ +function extractFieldNames(qtCode: string): Map> { + const result = new Map>(); + const structRe = /^type\s+(\w+)\s+struct\s*\{([^}]*)\}/gm; + let sm; + while ((sm = structRe.exec(qtCode)) !== null) { + const [, structName, body] = sm; + const fields = new Map(); + const fieldRe = /^\s+(\w+)\s+[^`\n]+`json:"([^",]+)/gm; + let fm; + while ((fm = fieldRe.exec(body)) !== null) { + fields.set(fm[2], fm[1]); + } + result.set(structName, fields); + } + return result; +} + async function formatGoFile(filePath: string): Promise { try { await execFileAsync("go", ["fmt", filePath]); @@ -93,7 +164,7 @@ async function generateSessionEvents(schemaPath?: string): Promise { `; - const outPath = await writeGeneratedFile("go/generated_session_events.go", banner + result.lines.join("\n")); + const outPath = await writeGeneratedFile("go/generated_session_events.go", banner + postProcessEnumConstants(result.lines.join("\n"))); console.log(` ✓ ${outPath}`); await formatGoFile(outPath); @@ -154,22 +225,25 @@ async function generateRpc(schemaPath?: string): Promise { rendererOptions: { package: "copilot", "just-types": "true" }, }); - // Build method wrappers - const lines: string[] = []; - lines.push(`// AUTO-GENERATED FILE - DO NOT EDIT`); - lines.push(`// Generated from: api.schema.json`); - lines.push(``); - lines.push(`package rpc`); - lines.push(``); - lines.push(`import (`); - lines.push(`\t"context"`); - lines.push(`\t"encoding/json"`); - lines.push(``); - lines.push(`\t"github.com/github/copilot-sdk/go/internal/jsonrpc2"`); - lines.push(`)`); - lines.push(``); + // Post-process quicktype output: fix enum constant names + let qtCode = qtResult.lines.filter((l) => !l.startsWith("package ")).join("\n"); + qtCode = postProcessEnumConstants(qtCode); + // Strip trailing whitespace from quicktype output (gofmt requirement) + qtCode = qtCode.replace(/[ \t]+$/gm, ""); - // Add quicktype-generated types (skip package line), annotating experimental types + // Extract actual type names generated by quicktype (may differ from toPascalCase) + const actualTypeNames = new Map(); + const structRe = /^type\s+(\w+)\s+struct\b/gm; + let sm; + while ((sm = structRe.exec(qtCode)) !== null) { + actualTypeNames.set(sm[1].toLowerCase(), sm[1]); + } + const resolveType = (name: string): string => actualTypeNames.get(name.toLowerCase()) ?? name; + + // Extract field name mappings (quicktype may rename fields to avoid Go keyword conflicts) + const fieldNames = extractFieldNames(qtCode); + + // Annotate experimental data types const experimentalTypeNames = new Set(); for (const method of allMethods) { if (method.stability !== "experimental") continue; @@ -179,9 +253,6 @@ async function generateRpc(schemaPath?: string): Promise { experimentalTypeNames.add(baseName + "Params"); } } - let qtCode = qtResult.lines.filter((l) => !l.startsWith("package ")).join("\n"); - // Strip trailing whitespace from quicktype output (gofmt requirement) - qtCode = qtCode.replace(/[ \t]+$/gm, ""); for (const typeName of experimentalTypeNames) { qtCode = qtCode.replace( new RegExp(`^(type ${typeName} struct)`, "m"), @@ -190,17 +261,33 @@ async function generateRpc(schemaPath?: string): Promise { } // Remove trailing blank lines from quicktype output before appending qtCode = qtCode.replace(/\n+$/, ""); + + // Build method wrappers + const lines: string[] = []; + lines.push(`// AUTO-GENERATED FILE - DO NOT EDIT`); + lines.push(`// Generated from: api.schema.json`); + lines.push(``); + lines.push(`package rpc`); + lines.push(``); + lines.push(`import (`); + lines.push(`\t"context"`); + lines.push(`\t"encoding/json"`); + lines.push(``); + lines.push(`\t"github.com/github/copilot-sdk/go/internal/jsonrpc2"`); + lines.push(`)`); + lines.push(``); + lines.push(qtCode); lines.push(``); // Emit ServerRpc if (schema.server) { - emitRpcWrapper(lines, schema.server, false); + emitRpcWrapper(lines, schema.server, false, resolveType, fieldNames); } // Emit SessionRpc if (schema.session) { - emitRpcWrapper(lines, schema.session, true); + emitRpcWrapper(lines, schema.session, true, resolveType, fieldNames); } const outPath = await writeGeneratedFile("go/rpc/generated_rpc.go", lines.join("\n")); @@ -209,7 +296,7 @@ async function generateRpc(schemaPath?: string): Promise { await formatGoFile(outPath); } -function emitRpcWrapper(lines: string[], node: Record, isSession: boolean): void { +function emitRpcWrapper(lines: string[], node: Record, isSession: boolean, resolveType: (name: string) => string, fieldNames: Map>): void { const groups = Object.entries(node).filter(([, v]) => typeof v === "object" && v !== null && !isRpcMethod(v)); const topLevelMethods = Object.entries(node).filter(([, v]) => isRpcMethod(v)); @@ -235,7 +322,7 @@ function emitRpcWrapper(lines: string[], node: Record, isSessio lines.push(``); for (const [key, value] of Object.entries(groupNode as Record)) { if (!isRpcMethod(value)) continue; - emitMethod(lines, apiName, key, value, isSession, groupExperimental); + emitMethod(lines, apiName, key, value, isSession, resolveType, fieldNames, groupExperimental); } } @@ -260,7 +347,7 @@ function emitRpcWrapper(lines: string[], node: Record, isSessio // Top-level methods (server only) for (const [key, value] of topLevelMethods) { if (!isRpcMethod(value)) continue; - emitMethod(lines, wrapperName, key, value, isSession, false); + emitMethod(lines, wrapperName, key, value, isSession, resolveType, fieldNames, false); } // Compute key alignment for constructor composite literal (gofmt aligns key: value) @@ -284,15 +371,15 @@ function emitRpcWrapper(lines: string[], node: Record, isSessio lines.push(``); } -function emitMethod(lines: string[], receiver: string, name: string, method: RpcMethod, isSession: boolean, groupExperimental = false): void { +function emitMethod(lines: string[], receiver: string, name: string, method: RpcMethod, isSession: boolean, resolveType: (name: string) => string, fieldNames: Map>, groupExperimental = false): void { const methodName = toPascalCase(name); - const resultType = toPascalCase(method.rpcMethod) + "Result"; + const resultType = resolveType(toPascalCase(method.rpcMethod) + "Result"); const paramProps = method.params?.properties || {}; const requiredParams = new Set(method.params?.required || []); const nonSessionParams = Object.keys(paramProps).filter((k) => k !== "sessionId"); const hasParams = isSession ? nonSessionParams.length > 0 : Object.keys(paramProps).length > 0; - const paramsType = hasParams ? toPascalCase(method.rpcMethod) + "Params" : ""; + const paramsType = hasParams ? resolveType(toPascalCase(method.rpcMethod) + "Params") : ""; if (method.stability === "experimental" && !groupExperimental) { lines.push(`// Experimental: ${methodName} is an experimental API and may change or be removed in future versions.`); @@ -308,7 +395,7 @@ function emitMethod(lines: string[], receiver: string, name: string, method: Rpc if (hasParams) { lines.push(`\tif params != nil {`); for (const pName of nonSessionParams) { - const goField = toGoFieldName(pName); + const goField = fieldNames.get(paramsType)?.get(pName) ?? toGoFieldName(pName); const isOptional = !requiredParams.has(pName); if (isOptional) { // Optional fields are pointers - only add when non-nil and dereference diff --git a/scripts/codegen/python.ts b/scripts/codegen/python.ts index cbbc3df38..0340cf1f1 100644 --- a/scripts/codegen/python.ts +++ b/scripts/codegen/python.ts @@ -32,12 +32,37 @@ import { * - Callable from collections.abc instead of typing * - Clean up unused typing imports */ +function replaceBalancedBrackets(code: string, prefix: string, replacer: (inner: string) => string): string { + let result = ""; + let i = 0; + while (i < code.length) { + const idx = code.indexOf(prefix + "[", i); + if (idx === -1) { + result += code.slice(i); + break; + } + result += code.slice(i, idx); + const start = idx + prefix.length + 1; // after '[' + let depth = 1; + let j = start; + while (j < code.length && depth > 0) { + if (code[j] === "[") depth++; + else if (code[j] === "]") depth--; + j++; + } + const inner = code.slice(start, j - 1); + result += replacer(inner); + i = j; + } + return result; +} + function modernizePython(code: string): string { - // Replace Optional[X] with X | None (handles nested brackets) - code = code.replace(/Optional\[([^\[\]]*(?:\[[^\[\]]*\])*[^\[\]]*)\]/g, "$1 | None"); + // Replace Optional[X] with X | None (handles arbitrarily nested brackets) + code = replaceBalancedBrackets(code, "Optional", (inner) => `${inner} | None`); // Replace Union[X, Y] with X | Y - code = code.replace(/Union\[([^\[\]]*(?:\[[^\[\]]*\])*[^\[\]]*)\]/g, (_match, inner: string) => { + code = replaceBalancedBrackets(code, "Union", (inner) => { return inner.split(",").map((s: string) => s.trim()).join(" | "); }); @@ -234,6 +259,16 @@ async function generateRpc(schemaPath?: string): Promise { ); } + // Extract actual class names generated by quicktype (may differ from toPascalCase, + // e.g. quicktype produces "SessionMCPList" not "SessionMcpList") + const actualTypeNames = new Map(); + const classRe = /^class\s+(\w+)\b/gm; + let cm; + while ((cm = classRe.exec(typesCode)) !== null) { + actualTypeNames.set(cm[1].toLowerCase(), cm[1]); + } + const resolveType = (name: string): string => actualTypeNames.get(name.toLowerCase()) ?? name; + const lines: string[] = []; lines.push(`""" AUTO-GENERATED FILE - DO NOT EDIT @@ -258,17 +293,17 @@ def _timeout_kwargs(timeout: float | None) -> dict: // Emit RPC wrapper classes if (schema.server) { - emitRpcWrapper(lines, schema.server, false); + emitRpcWrapper(lines, schema.server, false, resolveType); } if (schema.session) { - emitRpcWrapper(lines, schema.session, true); + emitRpcWrapper(lines, schema.session, true, resolveType); } const outPath = await writeGeneratedFile("python/copilot/generated/rpc.py", lines.join("\n")); console.log(` ✓ ${outPath}`); } -function emitRpcWrapper(lines: string[], node: Record, isSession: boolean): void { +function emitRpcWrapper(lines: string[], node: Record, isSession: boolean, resolveType: (name: string) => string): void { const groups = Object.entries(node).filter(([, v]) => typeof v === "object" && v !== null && !isRpcMethod(v)); const topLevelMethods = Object.entries(node).filter(([, v]) => isRpcMethod(v)); @@ -298,7 +333,7 @@ function emitRpcWrapper(lines: string[], node: Record, isSessio lines.push(``); for (const [key, value] of Object.entries(groupNode as Record)) { if (!isRpcMethod(value)) continue; - emitMethod(lines, key, value, isSession, groupExperimental); + emitMethod(lines, key, value, isSession, resolveType, groupExperimental); } lines.push(``); } @@ -327,19 +362,19 @@ function emitRpcWrapper(lines: string[], node: Record, isSessio // Top-level methods for (const [key, value] of topLevelMethods) { if (!isRpcMethod(value)) continue; - emitMethod(lines, key, value, isSession, false); + emitMethod(lines, key, value, isSession, resolveType, false); } lines.push(``); } -function emitMethod(lines: string[], name: string, method: RpcMethod, isSession: boolean, groupExperimental = false): void { +function emitMethod(lines: string[], name: string, method: RpcMethod, isSession: boolean, resolveType: (name: string) => string, groupExperimental = false): void { const methodName = toSnakeCase(name); - const resultType = toPascalCase(method.rpcMethod) + "Result"; + const resultType = resolveType(toPascalCase(method.rpcMethod) + "Result"); const paramProps = method.params?.properties || {}; const nonSessionParams = Object.keys(paramProps).filter((k) => k !== "sessionId"); const hasParams = isSession ? nonSessionParams.length > 0 : Object.keys(paramProps).length > 0; - const paramsType = toPascalCase(method.rpcMethod) + "Params"; + const paramsType = resolveType(toPascalCase(method.rpcMethod) + "Params"); // Build signature with typed params + optional timeout const sig = hasParams diff --git a/test/harness/package-lock.json b/test/harness/package-lock.json index bf9564d9a..c8ec038fb 100644 --- a/test/harness/package-lock.json +++ b/test/harness/package-lock.json @@ -9,7 +9,7 @@ "version": "1.0.0", "license": "ISC", "devDependencies": { - "@github/copilot": "^1.0.4", + "@github/copilot": "^1.0.10-0", "@modelcontextprotocol/sdk": "^1.26.0", "@types/node": "^25.3.3", "openai": "^6.17.0", @@ -462,27 +462,27 @@ } }, "node_modules/@github/copilot": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/@github/copilot/-/copilot-1.0.4.tgz", - "integrity": "sha512-IpPg+zYplLu4F4lmatEDdR/1Y/jJ9cGWt89m3K3H4YSfYrZ5Go4UlM28llulYCG7sVdQeIGauQN1/KiBI/Rocg==", + "version": "1.0.10-0", + "resolved": "https://registry.npmjs.org/@github/copilot/-/copilot-1.0.10-0.tgz", + "integrity": "sha512-LmVe3yVDamZc4cbZeyprZ6WjTME9Z4UcB5YWnEagtXJ19KP5PBKbBZVG7pZnQHL2/IHZ/dqcZW3IHMgYDoqDvg==", "dev": true, "license": "SEE LICENSE IN LICENSE.md", "bin": { "copilot": "npm-loader.js" }, "optionalDependencies": { - "@github/copilot-darwin-arm64": "1.0.4", - "@github/copilot-darwin-x64": "1.0.4", - "@github/copilot-linux-arm64": "1.0.4", - "@github/copilot-linux-x64": "1.0.4", - "@github/copilot-win32-arm64": "1.0.4", - "@github/copilot-win32-x64": "1.0.4" + "@github/copilot-darwin-arm64": "1.0.10-0", + "@github/copilot-darwin-x64": "1.0.10-0", + "@github/copilot-linux-arm64": "1.0.10-0", + "@github/copilot-linux-x64": "1.0.10-0", + "@github/copilot-win32-arm64": "1.0.10-0", + "@github/copilot-win32-x64": "1.0.10-0" } }, "node_modules/@github/copilot-darwin-arm64": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/@github/copilot-darwin-arm64/-/copilot-darwin-arm64-1.0.4.tgz", - "integrity": "sha512-/YGGhv6cp0ItolsF0HsLq2KmesA4atn0IEYApBs770fzJ8OP2pkOEzrxo3gWU3wc7fHF2uDB1RrJEZ7QSFLdEQ==", + "version": "1.0.10-0", + "resolved": "https://registry.npmjs.org/@github/copilot-darwin-arm64/-/copilot-darwin-arm64-1.0.10-0.tgz", + "integrity": "sha512-u5CbflcTpvc4E48E0jrqbN3Y5hWzValMs21RR6L+GDjQpPI2pvDeUWAJZ03Y7qQ2Uk3KZ+hOIJWJvje9VHxrDQ==", "cpu": [ "arm64" ], @@ -497,9 +497,9 @@ } }, "node_modules/@github/copilot-darwin-x64": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/@github/copilot-darwin-x64/-/copilot-darwin-x64-1.0.4.tgz", - "integrity": "sha512-gwn2QjZbc1SqPVSAtDMesU1NopyHZT8Qsn37xPfznpV9s94KVyX4TTiDZaUwfnI0wr8kVHBL46RPLNz6I8kR9A==", + "version": "1.0.10-0", + "resolved": "https://registry.npmjs.org/@github/copilot-darwin-x64/-/copilot-darwin-x64-1.0.10-0.tgz", + "integrity": "sha512-4y5OXhAfWX+il9slhrq7v8ONzq+Hpw46ktnz7l1fAZKdmn+dzmFVCvr6pJPr5Az78cAKBuN+Gt4eeSNaxuKCmA==", "cpu": [ "x64" ], @@ -514,9 +514,9 @@ } }, "node_modules/@github/copilot-linux-arm64": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/@github/copilot-linux-arm64/-/copilot-linux-arm64-1.0.4.tgz", - "integrity": "sha512-92vzHKxN55BpI76sP/5fXIXfat1gzAhsq4bNLqLENGfZyMP/25OiVihCZuQHnvxzXaHBITFGUvtxfdll2kbcng==", + "version": "1.0.10-0", + "resolved": "https://registry.npmjs.org/@github/copilot-linux-arm64/-/copilot-linux-arm64-1.0.10-0.tgz", + "integrity": "sha512-j+Z/ZahEIT5SCblUqOJ2+2glWeIIUPKXXFS5bbu5kFZ9Xyag37FBvTjyxDeB02dpSKKDD4xbMVjcijFbtyr1PA==", "cpu": [ "arm64" ], @@ -531,9 +531,9 @@ } }, "node_modules/@github/copilot-linux-x64": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/@github/copilot-linux-x64/-/copilot-linux-x64-1.0.4.tgz", - "integrity": "sha512-wQvpwf4/VMTnSmWyYzq07Xg18Vxg7aZ5NVkkXqlLTuXRASW0kvCCb5USEtXHHzR7E6rJztkhCjFRE1bZW8jAGw==", + "version": "1.0.10-0", + "resolved": "https://registry.npmjs.org/@github/copilot-linux-x64/-/copilot-linux-x64-1.0.10-0.tgz", + "integrity": "sha512-S8IfuiMZWwnFW1v0vOGHalPIXq/75kL/RpZCYd1sleQA/yztCNNjxH9tNpXsdZnhYrAgU/3hqseWq5hbz8xjxA==", "cpu": [ "x64" ], @@ -548,9 +548,9 @@ } }, "node_modules/@github/copilot-win32-arm64": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/@github/copilot-win32-arm64/-/copilot-win32-arm64-1.0.4.tgz", - "integrity": "sha512-zOvD/5GVxDf0ZdlTkK+m55Vs55xuHNmACX50ZO2N23ZGG2dmkdS4mkruL59XB5ISgrOfeqvnqrwTFHbmPZtLfw==", + "version": "1.0.10-0", + "resolved": "https://registry.npmjs.org/@github/copilot-win32-arm64/-/copilot-win32-arm64-1.0.10-0.tgz", + "integrity": "sha512-6HJErp91fLrwIkoXegLK8SXjHzLgbl9GF+QdOtUGqZ915UUfXcchef0tQjN8u35yNLEW82VnAmft/PJ9Ok2UhQ==", "cpu": [ "arm64" ], @@ -565,9 +565,9 @@ } }, "node_modules/@github/copilot-win32-x64": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/@github/copilot-win32-x64/-/copilot-win32-x64-1.0.4.tgz", - "integrity": "sha512-yQenHMdkV0b77mF6aLM60TuwtNZ592TluptVDF+80Sj2zPfCpLyvrRh2FCIHRtuwTy4BfxETh2hCFHef8E6IOw==", + "version": "1.0.10-0", + "resolved": "https://registry.npmjs.org/@github/copilot-win32-x64/-/copilot-win32-x64-1.0.10-0.tgz", + "integrity": "sha512-AQwZYHoarRACbmPUPmH7gPOEomTAtDusCn65ancI3BoWGj9fzAgZEZ5JSaR3N/VUoXWoEbSe+PcH380ZYwsPag==", "cpu": [ "x64" ], diff --git a/test/harness/package.json b/test/harness/package.json index 9f336dfd4..25117cac9 100644 --- a/test/harness/package.json +++ b/test/harness/package.json @@ -11,7 +11,7 @@ "test": "vitest run" }, "devDependencies": { - "@github/copilot": "^1.0.4", + "@github/copilot": "^1.0.10-0", "@modelcontextprotocol/sdk": "^1.26.0", "@types/node": "^25.3.3", "openai": "^6.17.0", diff --git a/test/scenarios/prompts/attachments/README.md b/test/scenarios/prompts/attachments/README.md index d61a26e57..76b76751d 100644 --- a/test/scenarios/prompts/attachments/README.md +++ b/test/scenarios/prompts/attachments/README.md @@ -39,7 +39,7 @@ Demonstrates sending **file attachments** alongside a prompt using the Copilot S |----------|------------------------| | TypeScript | `attachments: [{ type: "blob", data: base64Data, mimeType: "image/png" }]` | | Python | `"attachments": [{"type": "blob", "data": base64_data, "mimeType": "image/png"}]` | -| Go | `Attachments: []copilot.Attachment{{Type: copilot.Blob, Data: &data, MIMEType: &mime}}` | +| Go | `Attachments: []copilot.Attachment{{Type: copilot.AttachmentTypeBlob, Data: &data, MIMEType: &mime}}` | ## Sample Data From 005b780c3b4d320ccbba37d0873d730dfaacc9c5 Mon Sep 17 00:00:00 2001 From: Mackinnon Buck Date: Fri, 20 Mar 2026 08:54:53 -0700 Subject: [PATCH 3/3] Add fine-grained system prompt customization (customize mode) (#816) * Add fine-grained system prompt customization (customize mode) Add a new 'customize' mode for systemMessage configuration, enabling SDK consumers to selectively override individual sections of the CLI system prompt while preserving the rest. This sits between the existing 'append' and 'replace' modes. 9 configurable sections: identity, tone, tool_efficiency, environment_context, code_change_rules, guidelines, safety, tool_instructions, custom_instructions. 4 override actions per section: replace, remove, append, prepend. Unknown section IDs are handled gracefully: content-bearing overrides are appended to additional instructions with a warning, and remove on unknown sections is silently ignored. Types and constants added to all 4 SDK languages (TypeScript, Python, Go, .NET). Documentation updated across all READMEs and getting-started guide. Companion runtime PR: github/copilot-agent-runtime#4751 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Address PR review feedback: fix docs, add examples and E2E tests - Fix incorrect package name in nodejs/README.md (@anthropic-ai/sdk -> @github/copilot-sdk) - Add standalone 'System Message Customization' sections with full code examples to Python and Go READMEs (matching TypeScript/.NET) - Add E2E tests for customize mode to Python, Go, and .NET (matching existing Node.js E2E test coverage) - Fix 'end of the prompt' wording in docs to 'additional instructions' Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Add last_instructions configurable section Expose lastInstructions as a customizable section across all 4 SDKs, addressing review feedback about duplicate tool-efficiency blocks. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Fix lint: prettier formatting, Python import order and line length Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Add transform operation for system prompt section customization Adds a new 'transform' action to SectionOverride that enables read-then-write mutation of system prompt sections via callbacks. The SDK intercepts function- valued actions before serialization, stores the callbacks locally, and handles the batched systemMessage.transform JSON-RPC callback from the runtime. Changes across all 4 SDKs (TypeScript, Python, Go, .NET): - Types: SectionTransformFn, SectionOverrideAction (TS/Python), Transform field (Go/.NET), SectionOverrideAction constants (Go) - Client: extractTransformCallbacks helper, transform callback registration, systemMessage.transform RPC handler - Session: transform callback storage and batched dispatch with error handling - E2E tests and shared snapshot YAML files Wire protocol: single batched RPC call with all transform sections, matching the runtime implementation in copilot-agent-runtime PR #5103. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Formatting Co-Authored-By: Copilot <223556219+Copilot@users.noreply.github.com> * Add E2E snapshot for customized systemMessage config test Generate the missing snapshot file that the 'should create a session with customized systemMessage config' test requires across all SDK languages (Node, Python, Go, .NET). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Fix Go fmt blank comment line and Python import ordering - Add blank // comment line between doc example and extractTransformCallbacks function doc comment in go/client.go (required by go fmt) - Fix ruff import sorting in python/copilot/__init__.py Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Fix Python ty type error in session transform handler Use str() to ensure transform callback result is typed as str, fixing the invalid-assignment error from ty type checker at session.py:689. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Fix Python E2E test to use keyword args for create_session The create_session() method was refactored to keyword-only params. Update the customized systemMessage test to use keyword arguments instead of a positional dict, and fix send_and_wait() call to pass prompt as a positional string. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Assert transform result in system message via HTTP traffic The 'should apply transform modifications' tests previously only verified that the transform callback was invoked, not that the transformed content actually reached the model. Now all 4 SDKs assert that TRANSFORM_MARKER appears in the system message captured from HTTP traffic. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Fix Go transform JSON serialization: add json tags for content field The systemMessageTransformRequest and systemMessageTransformResponse used anonymous structs without json tags, causing Content to serialize as uppercase 'Content' instead of lowercase 'content'. The CLI expects lowercase, so transform results were silently ignored. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: Steve Sanderson --- docs/getting-started.md | 24 ++- dotnet/README.md | 28 +++ dotnet/src/Client.cs | 62 +++++- dotnet/src/SdkProtocolVersion.cs | 5 +- dotnet/src/Session.cs | 71 +++++++ dotnet/src/Types.cs | 118 ++++++++++- dotnet/test/SessionTests.cs | 31 +++ dotnet/test/SystemMessageTransformTests.cs | 140 +++++++++++++ go/README.md | 51 ++++- go/client.go | 64 +++++- go/internal/e2e/session_test.go | 45 +++++ .../e2e/system_message_transform_test.go | 189 ++++++++++++++++++ go/session.go | 80 ++++++-- go/types.go | 57 +++++- nodejs/README.md | 40 +++- nodejs/src/client.ts | 93 ++++++++- nodejs/src/index.ts | 7 +- nodejs/src/session.ts | 44 ++++ nodejs/src/types.ts | 100 ++++++++- nodejs/test/e2e/session.test.ts | 27 +++ .../test/e2e/system_message_transform.test.ts | 125 ++++++++++++ python/README.md | 53 ++++- python/copilot/__init__.py | 18 ++ python/copilot/client.py | 81 +++++++- python/copilot/session.py | 59 ++++++ python/copilot/types.py | 66 +++++- python/e2e/test_session.py | 27 +++ python/e2e/test_system_message_transform.py | 123 ++++++++++++ ..._with_customized_systemmessage_config.yaml | 35 ++++ ...form_modifications_to_section_content.yaml | 33 +++ ...nsform_callbacks_with_section_content.yaml | 54 +++++ ...tic_overrides_and_transforms_together.yaml | 50 +++++ 32 files changed, 1955 insertions(+), 45 deletions(-) create mode 100644 dotnet/test/SystemMessageTransformTests.cs create mode 100644 go/internal/e2e/system_message_transform_test.go create mode 100644 nodejs/test/e2e/system_message_transform.test.ts create mode 100644 python/e2e/test_system_message_transform.py create mode 100644 test/snapshots/session/should_create_a_session_with_customized_systemmessage_config.yaml create mode 100644 test/snapshots/system_message_transform/should_apply_transform_modifications_to_section_content.yaml create mode 100644 test/snapshots/system_message_transform/should_invoke_transform_callbacks_with_section_content.yaml create mode 100644 test/snapshots/system_message_transform/should_work_with_static_overrides_and_transforms_together.yaml diff --git a/docs/getting-started.md b/docs/getting-started.md index 6c0aee72e..9d4189f56 100644 --- a/docs/getting-started.md +++ b/docs/getting-started.md @@ -1235,7 +1235,7 @@ const session = await client.createSession({ ### Customize the System Message -Control the AI's behavior and personality: +Control the AI's behavior and personality by appending instructions: ```typescript const session = await client.createSession({ @@ -1245,6 +1245,28 @@ const session = await client.createSession({ }); ``` +For more fine-grained control, use `mode: "customize"` to override individual sections of the system prompt while preserving the rest: + +```typescript +const session = await client.createSession({ + systemMessage: { + mode: "customize", + sections: { + tone: { action: "replace", content: "Respond in a warm, professional tone. Be thorough in explanations." }, + code_change_rules: { action: "remove" }, + guidelines: { action: "append", content: "\n* Always cite data sources" }, + }, + content: "Focus on financial analysis and reporting.", + }, +}); +``` + +Available section IDs: `identity`, `tone`, `tool_efficiency`, `environment_context`, `code_change_rules`, `guidelines`, `safety`, `tool_instructions`, `custom_instructions`, `last_instructions`. + +Each override supports four actions: `replace`, `remove`, `append`, and `prepend`. Unknown section IDs are handled gracefully — content is appended to additional instructions and a warning is emitted; `remove` on unknown sections is silently ignored. + +See the language-specific SDK READMEs for examples in [TypeScript](../nodejs/README.md), [Python](../python/README.md), [Go](../go/README.md), and [C#](../dotnet/README.md). + --- ## Connecting to an External CLI Server diff --git a/dotnet/README.md b/dotnet/README.md index cb7dbba18..cab1cf068 100644 --- a/dotnet/README.md +++ b/dotnet/README.md @@ -509,6 +509,34 @@ var session = await client.CreateSessionAsync(new SessionConfig }); ``` +#### Customize Mode + +Use `Mode = SystemMessageMode.Customize` to selectively override individual sections of the prompt while preserving the rest: + +```csharp +var session = await client.CreateSessionAsync(new SessionConfig +{ + Model = "gpt-5", + SystemMessage = new SystemMessageConfig + { + Mode = SystemMessageMode.Customize, + Sections = new Dictionary + { + [SystemPromptSections.Tone] = new() { Action = SectionOverrideAction.Replace, Content = "Respond in a warm, professional tone. Be thorough in explanations." }, + [SystemPromptSections.CodeChangeRules] = new() { Action = SectionOverrideAction.Remove }, + [SystemPromptSections.Guidelines] = new() { Action = SectionOverrideAction.Append, Content = "\n* Always cite data sources" }, + }, + Content = "Focus on financial analysis and reporting." + } +}); +``` + +Available section IDs are defined as constants on `SystemPromptSections`: `Identity`, `Tone`, `ToolEfficiency`, `EnvironmentContext`, `CodeChangeRules`, `Guidelines`, `Safety`, `ToolInstructions`, `CustomInstructions`, `LastInstructions`. + +Each section override supports four actions: `Replace`, `Remove`, `Append`, and `Prepend`. Unknown section IDs are handled gracefully: content is appended to additional instructions, and `Remove` overrides are silently ignored. + +#### Replace Mode + For full control (removes all guardrails), use `Mode = SystemMessageMode.Replace`: ```csharp diff --git a/dotnet/src/Client.cs b/dotnet/src/Client.cs index a9ad1fccd..99c0eff00 100644 --- a/dotnet/src/Client.cs +++ b/dotnet/src/Client.cs @@ -365,6 +365,44 @@ private async Task CleanupConnectionAsync(List? errors) } } + private static (SystemMessageConfig? wireConfig, Dictionary>>? callbacks) ExtractTransformCallbacks(SystemMessageConfig? systemMessage) + { + if (systemMessage?.Mode != SystemMessageMode.Customize || systemMessage.Sections == null) + { + return (systemMessage, null); + } + + var callbacks = new Dictionary>>(); + var wireSections = new Dictionary(); + + foreach (var (sectionId, sectionOverride) in systemMessage.Sections) + { + if (sectionOverride.Transform != null) + { + callbacks[sectionId] = sectionOverride.Transform; + wireSections[sectionId] = new SectionOverride { Action = SectionOverrideAction.Transform }; + } + else + { + wireSections[sectionId] = sectionOverride; + } + } + + if (callbacks.Count == 0) + { + return (systemMessage, null); + } + + var wireConfig = new SystemMessageConfig + { + Mode = systemMessage.Mode, + Content = systemMessage.Content, + Sections = wireSections + }; + + return (wireConfig, callbacks); + } + /// /// Creates a new Copilot session with the specified configuration. /// @@ -409,6 +447,8 @@ public async Task CreateSessionAsync(SessionConfig config, Cance config.Hooks.OnSessionEnd != null || config.Hooks.OnErrorOccurred != null); + var (wireSystemMessage, transformCallbacks) = ExtractTransformCallbacks(config.SystemMessage); + var sessionId = config.SessionId ?? Guid.NewGuid().ToString(); // Create and register the session before issuing the RPC so that @@ -424,6 +464,10 @@ public async Task CreateSessionAsync(SessionConfig config, Cance { session.RegisterHooks(config.Hooks); } + if (transformCallbacks != null) + { + session.RegisterTransformCallbacks(transformCallbacks); + } if (config.OnEvent != null) { session.On(config.OnEvent); @@ -440,7 +484,7 @@ public async Task CreateSessionAsync(SessionConfig config, Cance config.ClientName, config.ReasoningEffort, config.Tools?.Select(ToolDefinition.FromAIFunction).ToList(), - config.SystemMessage, + wireSystemMessage, config.AvailableTools, config.ExcludedTools, config.Provider, @@ -519,6 +563,8 @@ public async Task ResumeSessionAsync(string sessionId, ResumeSes config.Hooks.OnSessionEnd != null || config.Hooks.OnErrorOccurred != null); + var (wireSystemMessage, transformCallbacks) = ExtractTransformCallbacks(config.SystemMessage); + // Create and register the session before issuing the RPC so that // events emitted by the CLI (e.g. session.start) are not dropped. var session = new CopilotSession(sessionId, connection.Rpc, _logger); @@ -532,6 +578,10 @@ public async Task ResumeSessionAsync(string sessionId, ResumeSes { session.RegisterHooks(config.Hooks); } + if (transformCallbacks != null) + { + session.RegisterTransformCallbacks(transformCallbacks); + } if (config.OnEvent != null) { session.On(config.OnEvent); @@ -548,7 +598,7 @@ public async Task ResumeSessionAsync(string sessionId, ResumeSes config.Model, config.ReasoningEffort, config.Tools?.Select(ToolDefinition.FromAIFunction).ToList(), - config.SystemMessage, + wireSystemMessage, config.AvailableTools, config.ExcludedTools, config.Provider, @@ -1222,6 +1272,7 @@ private async Task ConnectToServerAsync(Process? cliProcess, string? rpc.AddLocalRpcMethod("permission.request", handler.OnPermissionRequestV2); rpc.AddLocalRpcMethod("userInput.request", handler.OnUserInputRequest); rpc.AddLocalRpcMethod("hooks.invoke", handler.OnHooksInvoke); + rpc.AddLocalRpcMethod("systemMessage.transform", handler.OnSystemMessageTransform); rpc.StartListening(); // Transition state to Disconnected if the JSON-RPC connection drops @@ -1350,6 +1401,12 @@ public async Task OnHooksInvoke(string sessionId, string ho return new HooksInvokeResponse(output); } + public async Task OnSystemMessageTransform(string sessionId, JsonElement sections) + { + var session = client.GetSession(sessionId) ?? throw new ArgumentException($"Unknown session {sessionId}"); + return await session.HandleSystemMessageTransformAsync(sections); + } + // Protocol v2 backward-compatibility adapters public async Task OnToolCallV2(string sessionId, @@ -1685,6 +1742,7 @@ private static LogLevel MapLevel(TraceEventType eventType) [JsonSerializable(typeof(ResumeSessionResponse))] [JsonSerializable(typeof(SessionMetadata))] [JsonSerializable(typeof(SystemMessageConfig))] + [JsonSerializable(typeof(SystemMessageTransformRpcResponse))] [JsonSerializable(typeof(ToolCallResponseV2))] [JsonSerializable(typeof(ToolDefinition))] [JsonSerializable(typeof(ToolResultAIContent))] diff --git a/dotnet/src/SdkProtocolVersion.cs b/dotnet/src/SdkProtocolVersion.cs index f3d8f04c5..889af460b 100644 --- a/dotnet/src/SdkProtocolVersion.cs +++ b/dotnet/src/SdkProtocolVersion.cs @@ -16,8 +16,5 @@ internal static class SdkProtocolVersion /// /// Gets the SDK protocol version. /// - public static int GetVersion() - { - return Version; - } + public static int GetVersion() => Version; } diff --git a/dotnet/src/Session.cs b/dotnet/src/Session.cs index 0014ec7f0..675a3e0c0 100644 --- a/dotnet/src/Session.cs +++ b/dotnet/src/Session.cs @@ -65,6 +65,8 @@ public sealed partial class CopilotSession : IAsyncDisposable private SessionHooks? _hooks; private readonly SemaphoreSlim _hooksLock = new(1, 1); + private Dictionary>>? _transformCallbacks; + private readonly SemaphoreSlim _transformCallbacksLock = new(1, 1); private SessionRpc? _sessionRpc; private int _isDisposed; @@ -653,6 +655,72 @@ internal void RegisterHooks(SessionHooks hooks) }; } + /// + /// Registers transform callbacks for system message sections. + /// + /// The transform callbacks keyed by section identifier. + internal void RegisterTransformCallbacks(Dictionary>>? callbacks) + { + _transformCallbacksLock.Wait(); + try + { + _transformCallbacks = callbacks; + } + finally + { + _transformCallbacksLock.Release(); + } + } + + /// + /// Handles a systemMessage.transform RPC call from the Copilot CLI. + /// + /// The raw JSON element containing sections to transform. + /// A task that resolves with the transformed sections. + internal async Task HandleSystemMessageTransformAsync(JsonElement sections) + { + Dictionary>>? callbacks; + await _transformCallbacksLock.WaitAsync(); + try + { + callbacks = _transformCallbacks; + } + finally + { + _transformCallbacksLock.Release(); + } + + var parsed = JsonSerializer.Deserialize( + sections.GetRawText(), + SessionJsonContext.Default.DictionaryStringSystemMessageTransformSection) ?? new(); + + var result = new Dictionary(); + foreach (var (sectionId, data) in parsed) + { + Func>? callback = null; + callbacks?.TryGetValue(sectionId, out callback); + + if (callback != null) + { + try + { + var transformed = await callback(data.Content ?? ""); + result[sectionId] = new SystemMessageTransformSection { Content = transformed }; + } + catch + { + result[sectionId] = new SystemMessageTransformSection { Content = data.Content ?? "" }; + } + } + else + { + result[sectionId] = new SystemMessageTransformSection { Content = data.Content ?? "" }; + } + } + + return new SystemMessageTransformRpcResponse { Sections = result }; + } + /// /// Gets the complete list of messages and events in the session. /// @@ -891,5 +959,8 @@ internal record SessionDestroyRequest [JsonSerializable(typeof(SessionEndHookOutput))] [JsonSerializable(typeof(ErrorOccurredHookInput))] [JsonSerializable(typeof(ErrorOccurredHookOutput))] + [JsonSerializable(typeof(SystemMessageTransformSection))] + [JsonSerializable(typeof(SystemMessageTransformRpcResponse))] + [JsonSerializable(typeof(Dictionary))] internal partial class SessionJsonContext : JsonSerializerContext; } diff --git a/dotnet/src/Types.cs b/dotnet/src/Types.cs index 84e7feaed..d6530f9c7 100644 --- a/dotnet/src/Types.cs +++ b/dotnet/src/Types.cs @@ -968,7 +968,86 @@ public enum SystemMessageMode Append, /// Replace the default system message entirely. [JsonStringEnumMemberName("replace")] - Replace + Replace, + /// Override individual sections of the system prompt. + [JsonStringEnumMemberName("customize")] + Customize +} + +/// +/// Specifies the operation to perform on a system prompt section. +/// +[JsonConverter(typeof(JsonStringEnumConverter))] +public enum SectionOverrideAction +{ + /// Replace the section content entirely. + [JsonStringEnumMemberName("replace")] + Replace, + /// Remove the section from the prompt. + [JsonStringEnumMemberName("remove")] + Remove, + /// Append content after the existing section. + [JsonStringEnumMemberName("append")] + Append, + /// Prepend content before the existing section. + [JsonStringEnumMemberName("prepend")] + Prepend, + /// Transform the section content via a callback. + [JsonStringEnumMemberName("transform")] + Transform +} + +/// +/// Override operation for a single system prompt section. +/// +public class SectionOverride +{ + /// + /// The operation to perform on this section. Ignored when Transform is set. + /// + [JsonPropertyName("action")] + public SectionOverrideAction? Action { get; set; } + + /// + /// Content for the override. Optional for all actions. Ignored for remove. + /// + [JsonPropertyName("content")] + public string? Content { get; set; } + + /// + /// Transform callback. When set, takes precedence over Action. + /// Receives current section content, returns transformed content. + /// Not serialized — the SDK handles this locally. + /// + [JsonIgnore] + public Func>? Transform { get; set; } +} + +/// +/// Known system prompt section identifiers for the "customize" mode. +/// +public static class SystemPromptSections +{ + /// Agent identity preamble and mode statement. + public const string Identity = "identity"; + /// Response style, conciseness rules, output formatting preferences. + public const string Tone = "tone"; + /// Tool usage patterns, parallel calling, batching guidelines. + public const string ToolEfficiency = "tool_efficiency"; + /// CWD, OS, git root, directory listing, available tools. + public const string EnvironmentContext = "environment_context"; + /// Coding rules, linting/testing, ecosystem tools, style. + public const string CodeChangeRules = "code_change_rules"; + /// Tips, behavioral best practices, behavioral guidelines. + public const string Guidelines = "guidelines"; + /// Environment limitations, prohibited actions, security policies. + public const string Safety = "safety"; + /// Per-tool usage instructions. + public const string ToolInstructions = "tool_instructions"; + /// Repository and organization custom instructions. + public const string CustomInstructions = "custom_instructions"; + /// End-of-prompt instructions: parallel tool calling, persistence, task completion. + public const string LastInstructions = "last_instructions"; } /// @@ -977,13 +1056,21 @@ public enum SystemMessageMode public class SystemMessageConfig { /// - /// How the system message is applied (append or replace). + /// How the system message is applied (append, replace, or customize). /// public SystemMessageMode? Mode { get; set; } + /// - /// Content of the system message. + /// Content of the system message. Used by append and replace modes. + /// In customize mode, additional content appended after all sections. /// public string? Content { get; set; } + + /// + /// Section-level overrides for customize mode. + /// Keys are section identifiers (see ). + /// + public Dictionary? Sections { get; set; } } /// @@ -2032,6 +2119,30 @@ public class SetForegroundSessionResponse public string? Error { get; set; } } +/// +/// Content data for a single system prompt section in a transform RPC call. +/// +public class SystemMessageTransformSection +{ + /// + /// The content of the section. + /// + [JsonPropertyName("content")] + public string? Content { get; set; } +} + +/// +/// Response to a systemMessage.transform RPC call. +/// +public class SystemMessageTransformRpcResponse +{ + /// + /// The transformed sections keyed by section identifier. + /// + [JsonPropertyName("sections")] + public Dictionary? Sections { get; set; } +} + [JsonSourceGenerationOptions( JsonSerializerDefaults.Web, AllowOutOfOrderMetadataProperties = true, @@ -2061,6 +2172,7 @@ public class SetForegroundSessionResponse [JsonSerializable(typeof(SessionLifecycleEvent))] [JsonSerializable(typeof(SessionLifecycleEventMetadata))] [JsonSerializable(typeof(SessionListFilter))] +[JsonSerializable(typeof(SectionOverride))] [JsonSerializable(typeof(SessionMetadata))] [JsonSerializable(typeof(SetForegroundSessionResponse))] [JsonSerializable(typeof(SystemMessageConfig))] diff --git a/dotnet/test/SessionTests.cs b/dotnet/test/SessionTests.cs index 30a9135a5..5aecaccba 100644 --- a/dotnet/test/SessionTests.cs +++ b/dotnet/test/SessionTests.cs @@ -91,6 +91,37 @@ public async Task Should_Create_A_Session_With_Replaced_SystemMessage_Config() Assert.Equal(testSystemMessage, GetSystemMessage(traffic[0])); } + [Fact] + public async Task Should_Create_A_Session_With_Customized_SystemMessage_Config() + { + var customTone = "Respond in a warm, professional tone. Be thorough in explanations."; + var appendedContent = "Always mention quarterly earnings."; + var session = await CreateSessionAsync(new SessionConfig + { + SystemMessage = new SystemMessageConfig + { + Mode = SystemMessageMode.Customize, + Sections = new Dictionary + { + [SystemPromptSections.Tone] = new() { Action = SectionOverrideAction.Replace, Content = customTone }, + [SystemPromptSections.CodeChangeRules] = new() { Action = SectionOverrideAction.Remove }, + }, + Content = appendedContent + } + }); + + await session.SendAsync(new MessageOptions { Prompt = "Who are you?" }); + var assistantMessage = await TestHelper.GetFinalAssistantMessageAsync(session); + Assert.NotNull(assistantMessage); + + var traffic = await Ctx.GetExchangesAsync(); + Assert.NotEmpty(traffic); + var systemMessage = GetSystemMessage(traffic[0]); + Assert.Contains(customTone, systemMessage); + Assert.Contains(appendedContent, systemMessage); + Assert.DoesNotContain("", systemMessage); + } + [Fact] public async Task Should_Create_A_Session_With_AvailableTools() { diff --git a/dotnet/test/SystemMessageTransformTests.cs b/dotnet/test/SystemMessageTransformTests.cs new file mode 100644 index 000000000..cdddc5a79 --- /dev/null +++ b/dotnet/test/SystemMessageTransformTests.cs @@ -0,0 +1,140 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + *--------------------------------------------------------------------------------------------*/ + +using GitHub.Copilot.SDK.Test.Harness; +using Xunit; +using Xunit.Abstractions; + +namespace GitHub.Copilot.SDK.Test; + +public class SystemMessageTransformTests(E2ETestFixture fixture, ITestOutputHelper output) : E2ETestBase(fixture, "system_message_transform", output) +{ + [Fact] + public async Task Should_Invoke_Transform_Callbacks_With_Section_Content() + { + var identityCallbackInvoked = false; + var toneCallbackInvoked = false; + + var session = await CreateSessionAsync(new SessionConfig + { + OnPermissionRequest = PermissionHandler.ApproveAll, + SystemMessage = new SystemMessageConfig + { + Mode = SystemMessageMode.Customize, + Sections = new Dictionary + { + ["identity"] = new SectionOverride + { + Transform = async (content) => + { + Assert.False(string.IsNullOrEmpty(content)); + identityCallbackInvoked = true; + return content; + } + }, + ["tone"] = new SectionOverride + { + Transform = async (content) => + { + Assert.False(string.IsNullOrEmpty(content)); + toneCallbackInvoked = true; + return content; + } + } + } + } + }); + + await File.WriteAllTextAsync(Path.Combine(Ctx.WorkDir, "test.txt"), "Hello transform!"); + + await session.SendAsync(new MessageOptions + { + Prompt = "Read the contents of test.txt and tell me what it says" + }); + + await TestHelper.GetFinalAssistantMessageAsync(session); + + Assert.True(identityCallbackInvoked, "Expected identity transform callback to be invoked"); + Assert.True(toneCallbackInvoked, "Expected tone transform callback to be invoked"); + } + + [Fact] + public async Task Should_Apply_Transform_Modifications_To_Section_Content() + { + var session = await CreateSessionAsync(new SessionConfig + { + OnPermissionRequest = PermissionHandler.ApproveAll, + SystemMessage = new SystemMessageConfig + { + Mode = SystemMessageMode.Customize, + Sections = new Dictionary + { + ["identity"] = new SectionOverride + { + Transform = async (content) => + { + return content + "\nAlways end your reply with TRANSFORM_MARKER"; + } + } + } + } + }); + + await File.WriteAllTextAsync(Path.Combine(Ctx.WorkDir, "hello.txt"), "Hello!"); + + await session.SendAsync(new MessageOptions + { + Prompt = "Read the contents of hello.txt" + }); + + await TestHelper.GetFinalAssistantMessageAsync(session); + + // Verify the transform result was actually applied to the system message + var traffic = await Ctx.GetExchangesAsync(); + Assert.NotEmpty(traffic); + var systemMessage = GetSystemMessage(traffic[0]); + Assert.Contains("TRANSFORM_MARKER", systemMessage); + } + + [Fact] + public async Task Should_Work_With_Static_Overrides_And_Transforms_Together() + { + var transformCallbackInvoked = false; + + var session = await CreateSessionAsync(new SessionConfig + { + OnPermissionRequest = PermissionHandler.ApproveAll, + SystemMessage = new SystemMessageConfig + { + Mode = SystemMessageMode.Customize, + Sections = new Dictionary + { + ["safety"] = new SectionOverride + { + Action = SectionOverrideAction.Remove + }, + ["identity"] = new SectionOverride + { + Transform = async (content) => + { + transformCallbackInvoked = true; + return content; + } + } + } + } + }); + + await File.WriteAllTextAsync(Path.Combine(Ctx.WorkDir, "combo.txt"), "Combo test!"); + + await session.SendAsync(new MessageOptions + { + Prompt = "Read the contents of combo.txt and tell me what it says" + }); + + await TestHelper.GetFinalAssistantMessageAsync(session); + + Assert.True(transformCallbackInvoked, "Expected identity transform callback to be invoked"); + } +} diff --git a/go/README.md b/go/README.md index 8cbb382c3..f29ef9fb7 100644 --- a/go/README.md +++ b/go/README.md @@ -150,7 +150,10 @@ Event types: `SessionLifecycleCreated`, `SessionLifecycleDeleted`, `SessionLifec - `ReasoningEffort` (string): Reasoning effort level for models that support it ("low", "medium", "high", "xhigh"). Use `ListModels()` to check which models support this option. - `SessionID` (string): Custom session ID - `Tools` ([]Tool): Custom tools exposed to the CLI -- `SystemMessage` (\*SystemMessageConfig): System message configuration +- `SystemMessage` (\*SystemMessageConfig): System message configuration. Supports three modes: + - **append** (default): Appends `Content` after the SDK-managed prompt + - **replace**: Replaces the entire prompt with `Content` + - **customize**: Selectively override individual sections via `Sections` map (keys: `SectionIdentity`, `SectionTone`, `SectionToolEfficiency`, `SectionEnvironmentContext`, `SectionCodeChangeRules`, `SectionGuidelines`, `SectionSafety`, `SectionToolInstructions`, `SectionCustomInstructions`, `SectionLastInstructions`; values: `SectionOverride` with `Action` and optional `Content`) - `Provider` (\*ProviderConfig): Custom API provider configuration (BYOK). See [Custom Providers](#custom-providers) section. - `Streaming` (bool): Enable streaming delta events - `InfiniteSessions` (\*InfiniteSessionConfig): Automatic context compaction configuration @@ -179,6 +182,52 @@ Event types: `SessionLifecycleCreated`, `SessionLifecycleDeleted`, `SessionLifec - `Bool(v bool) *bool` - Helper to create bool pointers for `AutoStart` option +### System Message Customization + +Control the system prompt using `SystemMessage` in session config: + +```go +session, err := client.CreateSession(ctx, &copilot.SessionConfig{ + SystemMessage: &copilot.SystemMessageConfig{ + Content: "Always check for security vulnerabilities before suggesting changes.", + }, +}) +``` + +The SDK auto-injects environment context, tool instructions, and security guardrails. The default CLI persona is preserved, and your `Content` is appended after SDK-managed sections. To change the persona or fully redefine the prompt, use `Mode: "replace"` or `Mode: "customize"`. + +#### Customize Mode + +Use `Mode: "customize"` to selectively override individual sections of the prompt while preserving the rest: + +```go +session, err := client.CreateSession(ctx, &copilot.SessionConfig{ + SystemMessage: &copilot.SystemMessageConfig{ + Mode: "customize", + Sections: map[string]copilot.SectionOverride{ + // Replace the tone/style section + copilot.SectionTone: {Action: "replace", Content: "Respond in a warm, professional tone. Be thorough in explanations."}, + // Remove coding-specific rules + copilot.SectionCodeChangeRules: {Action: "remove"}, + // Append to existing guidelines + copilot.SectionGuidelines: {Action: "append", Content: "\n* Always cite data sources"}, + }, + // Additional instructions appended after all sections + Content: "Focus on financial analysis and reporting.", + }, +}) +``` + +Available section constants: `SectionIdentity`, `SectionTone`, `SectionToolEfficiency`, `SectionEnvironmentContext`, `SectionCodeChangeRules`, `SectionGuidelines`, `SectionSafety`, `SectionToolInstructions`, `SectionCustomInstructions`, `SectionLastInstructions`. + +Each section override supports four actions: +- **`replace`** — Replace the section content entirely +- **`remove`** — Remove the section from the prompt +- **`append`** — Add content after the existing section +- **`prepend`** — Add content before the existing section + +Unknown section IDs are handled gracefully: content from `replace`/`append`/`prepend` overrides is appended to additional instructions, and `remove` overrides are silently ignored. + ## Image Support The SDK supports image attachments via the `Attachments` field in `MessageOptions`. You can attach images by providing their file path, or by passing base64-encoded data directly using a blob attachment: diff --git a/go/client.go b/go/client.go index a2431ad39..22be47ec6 100644 --- a/go/client.go +++ b/go/client.go @@ -482,6 +482,37 @@ func (c *Client) ensureConnected(ctx context.Context) error { // }, // }, // }) +// +// extractTransformCallbacks separates transform callbacks from a SystemMessageConfig, +// returning a wire-safe config and a map of callbacks (nil if none). +func extractTransformCallbacks(config *SystemMessageConfig) (*SystemMessageConfig, map[string]SectionTransformFn) { + if config == nil || config.Mode != "customize" || len(config.Sections) == 0 { + return config, nil + } + + callbacks := make(map[string]SectionTransformFn) + wireSections := make(map[string]SectionOverride) + for id, override := range config.Sections { + if override.Transform != nil { + callbacks[id] = override.Transform + wireSections[id] = SectionOverride{Action: "transform"} + } else { + wireSections[id] = override + } + } + + if len(callbacks) == 0 { + return config, nil + } + + wireConfig := &SystemMessageConfig{ + Mode: config.Mode, + Content: config.Content, + Sections: wireSections, + } + return wireConfig, callbacks +} + func (c *Client) CreateSession(ctx context.Context, config *SessionConfig) (*Session, error) { if config == nil || config.OnPermissionRequest == nil { return nil, fmt.Errorf("an OnPermissionRequest handler is required when creating a session. For example, to allow all permissions, use &copilot.SessionConfig{OnPermissionRequest: copilot.PermissionHandler.ApproveAll}") @@ -497,7 +528,8 @@ func (c *Client) CreateSession(ctx context.Context, config *SessionConfig) (*Ses req.ReasoningEffort = config.ReasoningEffort req.ConfigDir = config.ConfigDir req.Tools = config.Tools - req.SystemMessage = config.SystemMessage + wireSystemMessage, transformCallbacks := extractTransformCallbacks(config.SystemMessage) + req.SystemMessage = wireSystemMessage req.AvailableTools = config.AvailableTools req.ExcludedTools = config.ExcludedTools req.Provider = config.Provider @@ -548,6 +580,9 @@ func (c *Client) CreateSession(ctx context.Context, config *SessionConfig) (*Ses if config.Hooks != nil { session.registerHooks(config.Hooks) } + if transformCallbacks != nil { + session.registerTransformCallbacks(transformCallbacks) + } if config.OnEvent != nil { session.On(config.OnEvent) } @@ -616,7 +651,8 @@ func (c *Client) ResumeSessionWithOptions(ctx context.Context, sessionID string, req.ClientName = config.ClientName req.Model = config.Model req.ReasoningEffort = config.ReasoningEffort - req.SystemMessage = config.SystemMessage + wireSystemMessage, transformCallbacks := extractTransformCallbacks(config.SystemMessage) + req.SystemMessage = wireSystemMessage req.Tools = config.Tools req.Provider = config.Provider req.AvailableTools = config.AvailableTools @@ -665,6 +701,9 @@ func (c *Client) ResumeSessionWithOptions(ctx context.Context, sessionID string, if config.Hooks != nil { session.registerHooks(config.Hooks) } + if transformCallbacks != nil { + session.registerTransformCallbacks(transformCallbacks) + } if config.OnEvent != nil { session.On(config.OnEvent) } @@ -1402,6 +1441,7 @@ func (c *Client) setupNotificationHandler() { c.client.SetRequestHandler("permission.request", jsonrpc2.RequestHandlerFor(c.handlePermissionRequestV2)) c.client.SetRequestHandler("userInput.request", jsonrpc2.RequestHandlerFor(c.handleUserInputRequest)) c.client.SetRequestHandler("hooks.invoke", jsonrpc2.RequestHandlerFor(c.handleHooksInvoke)) + c.client.SetRequestHandler("systemMessage.transform", jsonrpc2.RequestHandlerFor(c.handleSystemMessageTransform)) } func (c *Client) handleSessionEvent(req sessionEventRequest) { @@ -1468,6 +1508,26 @@ func (c *Client) handleHooksInvoke(req hooksInvokeRequest) (map[string]any, *jso return result, nil } +// handleSystemMessageTransform handles a system message transform request from the CLI server. +func (c *Client) handleSystemMessageTransform(req systemMessageTransformRequest) (systemMessageTransformResponse, *jsonrpc2.Error) { + if req.SessionID == "" { + return systemMessageTransformResponse{}, &jsonrpc2.Error{Code: -32602, Message: "invalid system message transform payload"} + } + + c.sessionsMux.Lock() + session, ok := c.sessions[req.SessionID] + c.sessionsMux.Unlock() + if !ok { + return systemMessageTransformResponse{}, &jsonrpc2.Error{Code: -32602, Message: fmt.Sprintf("unknown session %s", req.SessionID)} + } + + resp, err := session.handleSystemMessageTransform(req.Sections) + if err != nil { + return systemMessageTransformResponse{}, &jsonrpc2.Error{Code: -32603, Message: err.Error()} + } + return resp, nil +} + // ======================================================================== // Protocol v2 backward-compatibility adapters // ======================================================================== diff --git a/go/internal/e2e/session_test.go b/go/internal/e2e/session_test.go index 1eaeacd1e..7f1817da9 100644 --- a/go/internal/e2e/session_test.go +++ b/go/internal/e2e/session_test.go @@ -184,6 +184,51 @@ func TestSession(t *testing.T) { } }) + t.Run("should create a session with customized systemMessage config", func(t *testing.T) { + ctx.ConfigureForTest(t) + + customTone := "Respond in a warm, professional tone. Be thorough in explanations." + appendedContent := "Always mention quarterly earnings." + session, err := client.CreateSession(t.Context(), &copilot.SessionConfig{ + OnPermissionRequest: copilot.PermissionHandler.ApproveAll, + SystemMessage: &copilot.SystemMessageConfig{ + Mode: "customize", + Sections: map[string]copilot.SectionOverride{ + copilot.SectionTone: {Action: "replace", Content: customTone}, + copilot.SectionCodeChangeRules: {Action: "remove"}, + }, + Content: appendedContent, + }, + }) + if err != nil { + t.Fatalf("Failed to create session: %v", err) + } + + _, err = session.SendAndWait(t.Context(), copilot.MessageOptions{Prompt: "Who are you?"}) + if err != nil { + t.Fatalf("Failed to send message: %v", err) + } + + // Validate the system message sent to the model + traffic, err := ctx.GetExchanges() + if err != nil { + t.Fatalf("Failed to get exchanges: %v", err) + } + if len(traffic) == 0 { + t.Fatal("Expected at least one exchange") + } + systemMessage := getSystemMessage(traffic[0]) + if !strings.Contains(systemMessage, customTone) { + t.Errorf("Expected system message to contain custom tone, got %q", systemMessage) + } + if !strings.Contains(systemMessage, appendedContent) { + t.Errorf("Expected system message to contain appended content, got %q", systemMessage) + } + if strings.Contains(systemMessage, "") { + t.Error("Expected system message to NOT contain code_change_instructions (it was removed)") + } + }) + t.Run("should create a session with availableTools", func(t *testing.T) { ctx.ConfigureForTest(t) diff --git a/go/internal/e2e/system_message_transform_test.go b/go/internal/e2e/system_message_transform_test.go new file mode 100644 index 000000000..2d62b01cf --- /dev/null +++ b/go/internal/e2e/system_message_transform_test.go @@ -0,0 +1,189 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +package e2e + +import ( + "os" + "path/filepath" + "strings" + "sync" + "testing" + + copilot "github.com/github/copilot-sdk/go" + "github.com/github/copilot-sdk/go/internal/e2e/testharness" +) + +func TestSystemMessageTransform(t *testing.T) { + ctx := testharness.NewTestContext(t) + client := ctx.NewClient() + t.Cleanup(func() { client.ForceStop() }) + + t.Run("should_invoke_transform_callbacks_with_section_content", func(t *testing.T) { + ctx.ConfigureForTest(t) + + var identityContent string + var toneContent string + var mu sync.Mutex + identityCalled := false + toneCalled := false + + session, err := client.CreateSession(t.Context(), &copilot.SessionConfig{ + OnPermissionRequest: copilot.PermissionHandler.ApproveAll, + SystemMessage: &copilot.SystemMessageConfig{ + Mode: "customize", + Sections: map[string]copilot.SectionOverride{ + "identity": { + Transform: func(currentContent string) (string, error) { + mu.Lock() + identityCalled = true + identityContent = currentContent + mu.Unlock() + return currentContent, nil + }, + }, + "tone": { + Transform: func(currentContent string) (string, error) { + mu.Lock() + toneCalled = true + toneContent = currentContent + mu.Unlock() + return currentContent, nil + }, + }, + }, + }, + }) + if err != nil { + t.Fatalf("Failed to create session: %v", err) + } + + testFile := filepath.Join(ctx.WorkDir, "test.txt") + err = os.WriteFile(testFile, []byte("Hello transform!"), 0644) + if err != nil { + t.Fatalf("Failed to write test file: %v", err) + } + + _, err = session.SendAndWait(t.Context(), copilot.MessageOptions{ + Prompt: "Read the contents of test.txt and tell me what it says", + }) + if err != nil { + t.Fatalf("Failed to send message: %v", err) + } + + mu.Lock() + defer mu.Unlock() + + if !identityCalled { + t.Error("Expected identity transform callback to be invoked") + } + if !toneCalled { + t.Error("Expected tone transform callback to be invoked") + } + if identityContent == "" { + t.Error("Expected identity transform to receive non-empty content") + } + if toneContent == "" { + t.Error("Expected tone transform to receive non-empty content") + } + }) + + t.Run("should_apply_transform_modifications_to_section_content", func(t *testing.T) { + ctx.ConfigureForTest(t) + + session, err := client.CreateSession(t.Context(), &copilot.SessionConfig{ + OnPermissionRequest: copilot.PermissionHandler.ApproveAll, + SystemMessage: &copilot.SystemMessageConfig{ + Mode: "customize", + Sections: map[string]copilot.SectionOverride{ + "identity": { + Transform: func(currentContent string) (string, error) { + return currentContent + "\nAlways end your reply with TRANSFORM_MARKER", nil + }, + }, + }, + }, + }) + if err != nil { + t.Fatalf("Failed to create session: %v", err) + } + + testFile := filepath.Join(ctx.WorkDir, "hello.txt") + err = os.WriteFile(testFile, []byte("Hello!"), 0644) + if err != nil { + t.Fatalf("Failed to write test file: %v", err) + } + + assistantMessage, err := session.SendAndWait(t.Context(), copilot.MessageOptions{ + Prompt: "Read the contents of hello.txt", + }) + if err != nil { + t.Fatalf("Failed to send message: %v", err) + } + + // Verify the transform result was actually applied to the system message + traffic, err := ctx.GetExchanges() + if err != nil { + t.Fatalf("Failed to get exchanges: %v", err) + } + if len(traffic) == 0 { + t.Fatal("Expected at least one exchange") + } + systemMessage := getSystemMessage(traffic[0]) + if !strings.Contains(systemMessage, "TRANSFORM_MARKER") { + t.Errorf("Expected system message to contain TRANSFORM_MARKER, got %q", systemMessage) + } + + _ = assistantMessage + }) + + t.Run("should_work_with_static_overrides_and_transforms_together", func(t *testing.T) { + ctx.ConfigureForTest(t) + + var mu sync.Mutex + transformCalled := false + + session, err := client.CreateSession(t.Context(), &copilot.SessionConfig{ + OnPermissionRequest: copilot.PermissionHandler.ApproveAll, + SystemMessage: &copilot.SystemMessageConfig{ + Mode: "customize", + Sections: map[string]copilot.SectionOverride{ + "safety": { + Action: copilot.SectionActionRemove, + }, + "identity": { + Transform: func(currentContent string) (string, error) { + mu.Lock() + transformCalled = true + mu.Unlock() + return currentContent, nil + }, + }, + }, + }, + }) + if err != nil { + t.Fatalf("Failed to create session: %v", err) + } + + testFile := filepath.Join(ctx.WorkDir, "combo.txt") + err = os.WriteFile(testFile, []byte("Combo test!"), 0644) + if err != nil { + t.Fatalf("Failed to write test file: %v", err) + } + + _, err = session.SendAndWait(t.Context(), copilot.MessageOptions{ + Prompt: "Read the contents of combo.txt and tell me what it says", + }) + if err != nil { + t.Fatalf("Failed to send message: %v", err) + } + + mu.Lock() + defer mu.Unlock() + + if !transformCalled { + t.Error("Expected identity transform callback to be invoked") + } + }) +} diff --git a/go/session.go b/go/session.go index 107ac9824..3a94a818e 100644 --- a/go/session.go +++ b/go/session.go @@ -50,20 +50,22 @@ type sessionHandler struct { // }) type Session struct { // SessionID is the unique identifier for this session. - SessionID string - workspacePath string - client *jsonrpc2.Client - handlers []sessionHandler - nextHandlerID uint64 - handlerMutex sync.RWMutex - toolHandlers map[string]ToolHandler - toolHandlersM sync.RWMutex - permissionHandler PermissionHandlerFunc - permissionMux sync.RWMutex - userInputHandler UserInputHandler - userInputMux sync.RWMutex - hooks *SessionHooks - hooksMux sync.RWMutex + SessionID string + workspacePath string + client *jsonrpc2.Client + handlers []sessionHandler + nextHandlerID uint64 + handlerMutex sync.RWMutex + toolHandlers map[string]ToolHandler + toolHandlersM sync.RWMutex + permissionHandler PermissionHandlerFunc + permissionMux sync.RWMutex + userInputHandler UserInputHandler + userInputMux sync.RWMutex + hooks *SessionHooks + hooksMux sync.RWMutex + transformCallbacks map[string]SectionTransformFn + transformMu sync.Mutex // eventCh serializes user event handler dispatch. dispatchEvent enqueues; // a single goroutine (processEvents) dequeues and invokes handlers in FIFO order. @@ -446,6 +448,56 @@ func (s *Session) handleHooksInvoke(hookType string, rawInput json.RawMessage) ( } } +// registerTransformCallbacks registers transform callbacks for this session. +// +// Transform callbacks are invoked when the CLI requests system message section +// transforms. This method is internal and typically called when creating a session. +func (s *Session) registerTransformCallbacks(callbacks map[string]SectionTransformFn) { + s.transformMu.Lock() + defer s.transformMu.Unlock() + s.transformCallbacks = callbacks +} + +type systemMessageTransformSection struct { + Content string `json:"content"` +} + +type systemMessageTransformRequest struct { + SessionID string `json:"sessionId"` + Sections map[string]systemMessageTransformSection `json:"sections"` +} + +type systemMessageTransformResponse struct { + Sections map[string]systemMessageTransformSection `json:"sections"` +} + +// handleSystemMessageTransform handles a system message transform request from the Copilot CLI. +// This is an internal method called by the SDK when the CLI requests section transforms. +func (s *Session) handleSystemMessageTransform(sections map[string]systemMessageTransformSection) (systemMessageTransformResponse, error) { + s.transformMu.Lock() + callbacks := s.transformCallbacks + s.transformMu.Unlock() + + result := make(map[string]systemMessageTransformSection) + for sectionID, data := range sections { + var callback SectionTransformFn + if callbacks != nil { + callback = callbacks[sectionID] + } + if callback != nil { + transformed, err := callback(data.Content) + if err != nil { + result[sectionID] = systemMessageTransformSection{Content: data.Content} + } else { + result[sectionID] = systemMessageTransformSection{Content: transformed} + } + } else { + result[sectionID] = systemMessageTransformSection{Content: data.Content} + } + } + return systemMessageTransformResponse{Sections: result}, nil +} + // dispatchEvent enqueues an event for delivery to user handlers and fires // broadcast handlers concurrently. // diff --git a/go/types.go b/go/types.go index fd9968e3e..502d61c1c 100644 --- a/go/types.go +++ b/go/types.go @@ -111,6 +111,51 @@ func Float64(v float64) *float64 { return &v } +// Known system prompt section identifiers for the "customize" mode. +const ( + SectionIdentity = "identity" + SectionTone = "tone" + SectionToolEfficiency = "tool_efficiency" + SectionEnvironmentContext = "environment_context" + SectionCodeChangeRules = "code_change_rules" + SectionGuidelines = "guidelines" + SectionSafety = "safety" + SectionToolInstructions = "tool_instructions" + SectionCustomInstructions = "custom_instructions" + SectionLastInstructions = "last_instructions" +) + +// SectionOverrideAction represents the action to perform on a system prompt section. +type SectionOverrideAction string + +const ( + // SectionActionReplace replaces section content entirely. + SectionActionReplace SectionOverrideAction = "replace" + // SectionActionRemove removes the section. + SectionActionRemove SectionOverrideAction = "remove" + // SectionActionAppend appends to existing section content. + SectionActionAppend SectionOverrideAction = "append" + // SectionActionPrepend prepends to existing section content. + SectionActionPrepend SectionOverrideAction = "prepend" +) + +// SectionTransformFn is a callback that receives the current content of a system prompt section +// and returns the transformed content. Used with the "transform" action to read-then-write +// modify sections at runtime. +type SectionTransformFn func(currentContent string) (string, error) + +// SectionOverride defines an override operation for a single system prompt section. +type SectionOverride struct { + // Action is the operation to perform: "replace", "remove", "append", "prepend", or "transform". + Action SectionOverrideAction `json:"action,omitempty"` + // Content for the override. Optional for all actions. Ignored for "remove". + Content string `json:"content,omitempty"` + // Transform is a callback invoked when Action is "transform". + // The runtime calls this with the current section content and uses the returned string. + // Excluded from JSON serialization; the SDK registers it as an RPC callback internally. + Transform SectionTransformFn `json:"-"` +} + // SystemMessageAppendConfig is append mode: use CLI foundation with optional appended content. type SystemMessageAppendConfig struct { // Mode is optional, defaults to "append" @@ -129,11 +174,15 @@ type SystemMessageReplaceConfig struct { } // SystemMessageConfig represents system message configuration for session creation. -// Use SystemMessageAppendConfig for default behavior, SystemMessageReplaceConfig for full control. -// In Go, use one struct or the other based on your needs. +// - Append mode (default): SDK foundation + optional custom content +// - Replace mode: Full control, caller provides entire system message +// - Customize mode: Section-level overrides with graceful fallback +// +// In Go, use one struct and set fields appropriate for the desired mode. type SystemMessageConfig struct { - Mode string `json:"mode,omitempty"` - Content string `json:"content,omitempty"` + Mode string `json:"mode,omitempty"` + Content string `json:"content,omitempty"` + Sections map[string]SectionOverride `json:"sections,omitempty"` } // PermissionRequestResultKind represents the kind of a permission request result. diff --git a/nodejs/README.md b/nodejs/README.md index e9d23c529..cc5d62416 100644 --- a/nodejs/README.md +++ b/nodejs/README.md @@ -473,7 +473,45 @@ const session = await client.createSession({ }); ``` -The SDK auto-injects environment context, tool instructions, and security guardrails. The default CLI persona is preserved, and your `content` is appended after SDK-managed sections. To change the persona or fully redefine the prompt, use `mode: "replace"`. +The SDK auto-injects environment context, tool instructions, and security guardrails. The default CLI persona is preserved, and your `content` is appended after SDK-managed sections. To change the persona or fully redefine the prompt, use `mode: "replace"` or `mode: "customize"`. + +#### Customize Mode + +Use `mode: "customize"` to selectively override individual sections of the prompt while preserving the rest: + +```typescript +import { SYSTEM_PROMPT_SECTIONS } from "@github/copilot-sdk"; +import type { SectionOverride, SystemPromptSection } from "@github/copilot-sdk"; + +const session = await client.createSession({ + model: "gpt-5", + systemMessage: { + mode: "customize", + sections: { + // Replace the tone/style section + tone: { action: "replace", content: "Respond in a warm, professional tone. Be thorough in explanations." }, + // Remove coding-specific rules + code_change_rules: { action: "remove" }, + // Append to existing guidelines + guidelines: { action: "append", content: "\n* Always cite data sources" }, + }, + // Additional instructions appended after all sections + content: "Focus on financial analysis and reporting.", + }, +}); +``` + +Available section IDs: `identity`, `tone`, `tool_efficiency`, `environment_context`, `code_change_rules`, `guidelines`, `safety`, `tool_instructions`, `custom_instructions`, `last_instructions`. Use the `SYSTEM_PROMPT_SECTIONS` constant for descriptions of each section. + +Each section override supports four actions: +- **`replace`** — Replace the section content entirely +- **`remove`** — Remove the section from the prompt +- **`append`** — Add content after the existing section +- **`prepend`** — Add content before the existing section + +Unknown section IDs are handled gracefully: content from `replace`/`append`/`prepend` overrides is appended to additional instructions, and `remove` overrides are silently ignored. + +#### Replace Mode For full control (removes all guardrails), use `mode: "replace"`: diff --git a/nodejs/src/client.ts b/nodejs/src/client.ts index 46d932242..9b8af3dd1 100644 --- a/nodejs/src/client.ts +++ b/nodejs/src/client.ts @@ -36,6 +36,7 @@ import type { GetStatusResponse, ModelInfo, ResumeSessionConfig, + SectionTransformFn, SessionConfig, SessionContext, SessionEvent, @@ -44,6 +45,7 @@ import type { SessionLifecycleHandler, SessionListFilter, SessionMetadata, + SystemMessageCustomizeConfig, TelemetryConfig, Tool, ToolCallRequestPayload, @@ -82,6 +84,45 @@ function toJsonSchema(parameters: Tool["parameters"]): Record | return parameters; } +/** + * Extract transform callbacks from a system message config and prepare the wire payload. + * Function-valued actions are replaced with `{ action: "transform" }` for serialization, + * and the original callbacks are returned in a separate map. + */ +function extractTransformCallbacks(systemMessage: SessionConfig["systemMessage"]): { + wirePayload: SessionConfig["systemMessage"]; + transformCallbacks: Map | undefined; +} { + if (!systemMessage || systemMessage.mode !== "customize" || !systemMessage.sections) { + return { wirePayload: systemMessage, transformCallbacks: undefined }; + } + + const transformCallbacks = new Map(); + const wireSections: Record = {}; + + for (const [sectionId, override] of Object.entries(systemMessage.sections)) { + if (!override) continue; + + if (typeof override.action === "function") { + transformCallbacks.set(sectionId, override.action); + wireSections[sectionId] = { action: "transform" }; + } else { + wireSections[sectionId] = { action: override.action, content: override.content }; + } + } + + if (transformCallbacks.size === 0) { + return { wirePayload: systemMessage, transformCallbacks: undefined }; + } + + const wirePayload: SystemMessageCustomizeConfig = { + ...systemMessage, + sections: wireSections as SystemMessageCustomizeConfig["sections"], + }; + + return { wirePayload, transformCallbacks }; +} + function getNodeExecPath(): string { if (process.versions.bun) { return "node"; @@ -605,6 +646,15 @@ export class CopilotClient { if (config.hooks) { session.registerHooks(config.hooks); } + + // Extract transform callbacks from system message config before serialization. + const { wirePayload: wireSystemMessage, transformCallbacks } = extractTransformCallbacks( + config.systemMessage + ); + if (transformCallbacks) { + session.registerTransformCallbacks(transformCallbacks); + } + if (config.onEvent) { session.on(config.onEvent); } @@ -624,7 +674,7 @@ export class CopilotClient { overridesBuiltInTool: tool.overridesBuiltInTool, skipPermission: tool.skipPermission, })), - systemMessage: config.systemMessage, + systemMessage: wireSystemMessage, availableTools: config.availableTools, excludedTools: config.excludedTools, provider: config.provider, @@ -711,6 +761,15 @@ export class CopilotClient { if (config.hooks) { session.registerHooks(config.hooks); } + + // Extract transform callbacks from system message config before serialization. + const { wirePayload: wireSystemMessage, transformCallbacks } = extractTransformCallbacks( + config.systemMessage + ); + if (transformCallbacks) { + session.registerTransformCallbacks(transformCallbacks); + } + if (config.onEvent) { session.on(config.onEvent); } @@ -723,7 +782,7 @@ export class CopilotClient { clientName: config.clientName, model: config.model, reasoningEffort: config.reasoningEffort, - systemMessage: config.systemMessage, + systemMessage: wireSystemMessage, availableTools: config.availableTools, excludedTools: config.excludedTools, tools: config.tools?.map((tool) => ({ @@ -1477,6 +1536,15 @@ export class CopilotClient { }): Promise<{ output?: unknown }> => await this.handleHooksInvoke(params) ); + this.connection.onRequest( + "systemMessage.transform", + async (params: { + sessionId: string; + sections: Record; + }): Promise<{ sections: Record }> => + await this.handleSystemMessageTransform(params) + ); + this.connection.onClose(() => { this.state = "disconnected"; }); @@ -1588,6 +1656,27 @@ export class CopilotClient { return { output }; } + private async handleSystemMessageTransform(params: { + sessionId: string; + sections: Record; + }): Promise<{ sections: Record }> { + if ( + !params || + typeof params.sessionId !== "string" || + !params.sections || + typeof params.sections !== "object" + ) { + throw new Error("Invalid systemMessage.transform payload"); + } + + const session = this.sessions.get(params.sessionId); + if (!session) { + throw new Error(`Session not found: ${params.sessionId}`); + } + + return await session._handleSystemMessageTransform(params.sections); + } + // ======================================================================== // Protocol v2 backward-compatibility adapters // ======================================================================== diff --git a/nodejs/src/index.ts b/nodejs/src/index.ts index 214b80050..f3788e168 100644 --- a/nodejs/src/index.ts +++ b/nodejs/src/index.ts @@ -10,7 +10,7 @@ export { CopilotClient } from "./client.js"; export { CopilotSession, type AssistantMessageEvent } from "./session.js"; -export { defineTool, approveAll } from "./types.js"; +export { defineTool, approveAll, SYSTEM_PROMPT_SECTIONS } from "./types.js"; export type { ConnectionState, CopilotClientOptions, @@ -31,6 +31,9 @@ export type { PermissionRequest, PermissionRequestResult, ResumeSessionConfig, + SectionOverride, + SectionOverrideAction, + SectionTransformFn, SessionConfig, SessionEvent, SessionEventHandler, @@ -44,7 +47,9 @@ export type { SessionMetadata, SystemMessageAppendConfig, SystemMessageConfig, + SystemMessageCustomizeConfig, SystemMessageReplaceConfig, + SystemPromptSection, TelemetryConfig, TraceContext, TraceContextProvider, diff --git a/nodejs/src/session.ts b/nodejs/src/session.ts index 674526764..122f4ece8 100644 --- a/nodejs/src/session.ts +++ b/nodejs/src/session.ts @@ -17,6 +17,7 @@ import type { PermissionRequest, PermissionRequestResult, ReasoningEffort, + SectionTransformFn, SessionEvent, SessionEventHandler, SessionEventPayload, @@ -70,6 +71,7 @@ export class CopilotSession { private permissionHandler?: PermissionHandler; private userInputHandler?: UserInputHandler; private hooks?: SessionHooks; + private transformCallbacks?: Map; private _rpc: ReturnType | null = null; private traceContextProvider?: TraceContextProvider; @@ -517,6 +519,48 @@ export class CopilotSession { this.hooks = hooks; } + /** + * Registers transform callbacks for system message sections. + * + * @param callbacks - Map of section ID to transform callback, or undefined to clear + * @internal This method is typically called internally when creating a session. + */ + registerTransformCallbacks(callbacks?: Map): void { + this.transformCallbacks = callbacks; + } + + /** + * Handles a systemMessage.transform request from the runtime. + * Dispatches each section to its registered transform callback. + * + * @param sections - Map of section IDs to their current rendered content + * @returns A promise that resolves with the transformed sections + * @internal This method is for internal use by the SDK. + */ + async _handleSystemMessageTransform( + sections: Record + ): Promise<{ sections: Record }> { + const result: Record = {}; + + for (const [sectionId, { content }] of Object.entries(sections)) { + const callback = this.transformCallbacks?.get(sectionId); + if (callback) { + try { + const transformed = await callback(content); + result[sectionId] = { content: transformed }; + } catch (_error) { + // Callback failed — return original content + result[sectionId] = { content }; + } + } else { + // No callback for this section — pass through unchanged + result[sectionId] = { content }; + } + } + + return { sections: result }; + } + /** * Handles a permission request in the v2 protocol format (synchronous RPC). * Used as a back-compat adapter when connected to a v2 server. diff --git a/nodejs/src/types.ts b/nodejs/src/types.ts index 9052bde52..992dbdb9d 100644 --- a/nodejs/src/types.ts +++ b/nodejs/src/types.ts @@ -272,6 +272,79 @@ export interface ToolCallResponsePayload { result: ToolResult; } +/** + * Known system prompt section identifiers for the "customize" mode. + * Each section corresponds to a distinct part of the system prompt. + */ +export type SystemPromptSection = + | "identity" + | "tone" + | "tool_efficiency" + | "environment_context" + | "code_change_rules" + | "guidelines" + | "safety" + | "tool_instructions" + | "custom_instructions" + | "last_instructions"; + +/** Section metadata for documentation and tooling. */ +export const SYSTEM_PROMPT_SECTIONS: Record = { + identity: { description: "Agent identity preamble and mode statement" }, + tone: { description: "Response style, conciseness rules, output formatting preferences" }, + tool_efficiency: { description: "Tool usage patterns, parallel calling, batching guidelines" }, + environment_context: { description: "CWD, OS, git root, directory listing, available tools" }, + code_change_rules: { description: "Coding rules, linting/testing, ecosystem tools, style" }, + guidelines: { description: "Tips, behavioral best practices, behavioral guidelines" }, + safety: { description: "Environment limitations, prohibited actions, security policies" }, + tool_instructions: { description: "Per-tool usage instructions" }, + custom_instructions: { description: "Repository and organization custom instructions" }, + last_instructions: { + description: + "End-of-prompt instructions: parallel tool calling, persistence, task completion", + }, +}; + +/** + * Transform callback for a single section: receives current content, returns new content. + */ +export type SectionTransformFn = (currentContent: string) => string | Promise; + +/** + * Override action: a string literal for static overrides, or a callback for transforms. + * + * - `"replace"`: Replace section content entirely + * - `"remove"`: Remove the section + * - `"append"`: Append to existing section content + * - `"prepend"`: Prepend to existing section content + * - `function`: Transform callback — receives current section content, returns new content + */ +export type SectionOverrideAction = + | "replace" + | "remove" + | "append" + | "prepend" + | SectionTransformFn; + +/** + * Override operation for a single system prompt section. + */ +export interface SectionOverride { + /** + * The operation to perform on this section. + * Can be a string action or a transform callback function. + */ + action: SectionOverrideAction; + + /** + * Content for the override. Optional for all actions. + * - For replace, omitting content replaces with an empty string. + * - For append/prepend, content is added before/after the existing section. + * - Ignored for the remove action. + */ + content?: string; +} + /** * Append mode: Use CLI foundation with optional appended content (default). */ @@ -298,12 +371,37 @@ export interface SystemMessageReplaceConfig { content: string; } +/** + * Customize mode: Override individual sections of the system prompt. + * Keeps the SDK-managed prompt structure while allowing targeted modifications. + */ +export interface SystemMessageCustomizeConfig { + mode: "customize"; + + /** + * Override specific sections of the system prompt by section ID. + * Unknown section IDs gracefully fall back: content-bearing overrides are appended + * to additional instructions, and "remove" on unknown sections is a silent no-op. + */ + sections?: Partial>; + + /** + * Additional content appended after all sections. + * Equivalent to append mode's content field — provided for convenience. + */ + content?: string; +} + /** * System message configuration for session creation. * - Append mode (default): SDK foundation + optional custom content * - Replace mode: Full control, caller provides entire system message + * - Customize mode: Section-level overrides with graceful fallback */ -export type SystemMessageConfig = SystemMessageAppendConfig | SystemMessageReplaceConfig; +export type SystemMessageConfig = + | SystemMessageAppendConfig + | SystemMessageReplaceConfig + | SystemMessageCustomizeConfig; /** * Permission request types from the server diff --git a/nodejs/test/e2e/session.test.ts b/nodejs/test/e2e/session.test.ts index 1eb8a175d..dbcbed8bb 100644 --- a/nodejs/test/e2e/session.test.ts +++ b/nodejs/test/e2e/session.test.ts @@ -96,6 +96,33 @@ describe("Sessions", async () => { expect(systemMessage).toEqual(testSystemMessage); // Exact match }); + it("should create a session with customized systemMessage config", async () => { + const customTone = "Respond in a warm, professional tone. Be thorough in explanations."; + const appendedContent = "Always mention quarterly earnings."; + const session = await client.createSession({ + onPermissionRequest: approveAll, + systemMessage: { + mode: "customize", + sections: { + tone: { action: "replace", content: customTone }, + code_change_rules: { action: "remove" }, + }, + content: appendedContent, + }, + }); + + const assistantMessage = await session.sendAndWait({ prompt: "Who are you?" }); + expect(assistantMessage?.data.content).toBeDefined(); + + // Validate the system message sent to the model + const traffic = await openAiEndpoint.getExchanges(); + const systemMessage = getSystemMessage(traffic[0]); + expect(systemMessage).toContain(customTone); + expect(systemMessage).toContain(appendedContent); + // The code_change_rules section should have been removed + expect(systemMessage).not.toContain(""); + }); + it("should create a session with availableTools", async () => { const session = await client.createSession({ onPermissionRequest: approveAll, diff --git a/nodejs/test/e2e/system_message_transform.test.ts b/nodejs/test/e2e/system_message_transform.test.ts new file mode 100644 index 000000000..ef37c39e9 --- /dev/null +++ b/nodejs/test/e2e/system_message_transform.test.ts @@ -0,0 +1,125 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + *--------------------------------------------------------------------------------------------*/ + +import { writeFile } from "fs/promises"; +import { join } from "path"; +import { describe, expect, it } from "vitest"; +import { ParsedHttpExchange } from "../../../test/harness/replayingCapiProxy.js"; +import { approveAll } from "../../src/index.js"; +import { createSdkTestContext } from "./harness/sdkTestContext.js"; + +describe("System message transform", async () => { + const { copilotClient: client, openAiEndpoint, workDir } = await createSdkTestContext(); + + it("should invoke transform callbacks with section content", async () => { + const transformedSections: Record = {}; + + const session = await client.createSession({ + onPermissionRequest: approveAll, + systemMessage: { + mode: "customize", + sections: { + identity: { + action: (content: string) => { + transformedSections["identity"] = content; + // Pass through unchanged + return content; + }, + }, + tone: { + action: (content: string) => { + transformedSections["tone"] = content; + return content; + }, + }, + }, + }, + }); + + await writeFile(join(workDir, "test.txt"), "Hello transform!"); + + await session.sendAndWait({ + prompt: "Read the contents of test.txt and tell me what it says", + }); + + // Transform callbacks should have been invoked with real section content + expect(Object.keys(transformedSections).length).toBe(2); + expect(transformedSections["identity"]).toBeDefined(); + expect(transformedSections["identity"]!.length).toBeGreaterThan(0); + expect(transformedSections["tone"]).toBeDefined(); + expect(transformedSections["tone"]!.length).toBeGreaterThan(0); + + await session.disconnect(); + }); + + it("should apply transform modifications to section content", async () => { + const session = await client.createSession({ + onPermissionRequest: approveAll, + systemMessage: { + mode: "customize", + sections: { + identity: { + action: (content: string) => { + return content + "\nTRANSFORM_MARKER"; + }, + }, + }, + }, + }); + + await writeFile(join(workDir, "hello.txt"), "Hello!"); + + await session.sendAndWait({ + prompt: "Read the contents of hello.txt", + }); + + // Verify the transform result was actually applied to the system message + const traffic = await openAiEndpoint.getExchanges(); + const systemMessage = getSystemMessage(traffic[0]); + expect(systemMessage).toContain("TRANSFORM_MARKER"); + + await session.disconnect(); + }); + + it("should work with static overrides and transforms together", async () => { + const transformedSections: Record = {}; + + const session = await client.createSession({ + onPermissionRequest: approveAll, + systemMessage: { + mode: "customize", + sections: { + // Static override + safety: { action: "remove" }, + // Transform + identity: { + action: (content: string) => { + transformedSections["identity"] = content; + return content; + }, + }, + }, + }, + }); + + await writeFile(join(workDir, "combo.txt"), "Combo test!"); + + await session.sendAndWait({ + prompt: "Read the contents of combo.txt and tell me what it says", + }); + + // Transform should have been invoked + expect(transformedSections["identity"]).toBeDefined(); + expect(transformedSections["identity"]!.length).toBeGreaterThan(0); + + await session.disconnect(); + }); +}); + +function getSystemMessage(exchange: ParsedHttpExchange): string | undefined { + const systemMessage = exchange.request.messages.find((m) => m.role === "system") as + | { role: "system"; content: string } + | undefined; + return systemMessage?.content; +} diff --git a/python/README.md b/python/README.md index 2394c351a..139098fa3 100644 --- a/python/README.md +++ b/python/README.md @@ -144,7 +144,10 @@ All parameters are keyword-only: - `client_name` (str): Client name to identify the application using the SDK. Included in the User-Agent header for API requests. - `reasoning_effort` (str): Reasoning effort level for models that support it ("low", "medium", "high", "xhigh"). Use `list_models()` to check which models support this option. - `tools` (list): Custom tools exposed to the CLI. -- `system_message` (dict): System message configuration. +- `system_message` (dict): System message configuration. Supports three modes: + - **append** (default): Appends `content` after the SDK-managed prompt + - **replace**: Replaces the entire prompt with `content` + - **customize**: Selectively override individual sections via `sections` dict (keys: `"identity"`, `"tone"`, `"tool_efficiency"`, `"environment_context"`, `"code_change_rules"`, `"guidelines"`, `"safety"`, `"tool_instructions"`, `"custom_instructions"`, `"last_instructions"`; values: `SectionOverride` with `action` and optional `content`) - `available_tools` (list[str]): List of tool names to allow. Takes precedence over `excluded_tools`. - `excluded_tools` (list[str]): List of tool names to disable. Ignored if `available_tools` is set. - `on_user_input_request` (callable): Handler for user input requests from the agent (enables ask_user tool). See [User Input Requests](#user-input-requests) section. @@ -217,6 +220,54 @@ unsubscribe() - `session.foreground` - A session became the foreground session in TUI - `session.background` - A session is no longer the foreground session +### System Message Customization + +Control the system prompt using `system_message` in session config: + +```python +session = await client.create_session( + system_message={ + "content": "Always check for security vulnerabilities before suggesting changes." + } +) +``` + +The SDK auto-injects environment context, tool instructions, and security guardrails. The default CLI persona is preserved, and your `content` is appended after SDK-managed sections. To change the persona or fully redefine the prompt, use `mode: "replace"` or `mode: "customize"`. + +#### Customize Mode + +Use `mode: "customize"` to selectively override individual sections of the prompt while preserving the rest: + +```python +from copilot import SYSTEM_PROMPT_SECTIONS + +session = await client.create_session( + system_message={ + "mode": "customize", + "sections": { + # Replace the tone/style section + "tone": {"action": "replace", "content": "Respond in a warm, professional tone. Be thorough in explanations."}, + # Remove coding-specific rules + "code_change_rules": {"action": "remove"}, + # Append to existing guidelines + "guidelines": {"action": "append", "content": "\n* Always cite data sources"}, + }, + # Additional instructions appended after all sections + "content": "Focus on financial analysis and reporting.", + } +) +``` + +Available section IDs: `"identity"`, `"tone"`, `"tool_efficiency"`, `"environment_context"`, `"code_change_rules"`, `"guidelines"`, `"safety"`, `"tool_instructions"`, `"custom_instructions"`, `"last_instructions"`. Use the `SYSTEM_PROMPT_SECTIONS` dict for descriptions of each section. + +Each section override supports four actions: +- **`replace`** — Replace the section content entirely +- **`remove`** — Remove the section from the prompt +- **`append`** — Add content after the existing section +- **`prepend`** — Add content before the existing section + +Unknown section IDs are handled gracefully: content from `replace`/`append`/`prepend` overrides is appended to additional instructions, and `remove` overrides are silently ignored. + ### Tools Define tools with automatic JSON schema generation using the `@define_tool` decorator and Pydantic models: diff --git a/python/copilot/__init__.py b/python/copilot/__init__.py index e1fdf9253..6a007afa3 100644 --- a/python/copilot/__init__.py +++ b/python/copilot/__init__.py @@ -8,6 +8,7 @@ from .session import CopilotSession from .tools import define_tool from .types import ( + SYSTEM_PROMPT_SECTIONS, Attachment, AzureProviderOptions, BlobAttachment, @@ -30,6 +31,9 @@ PermissionRequestResult, PingResponse, ProviderConfig, + SectionOverride, + SectionOverrideAction, + SectionTransformFn, SelectionAttachment, SessionContext, SessionEvent, @@ -37,6 +41,11 @@ SessionMetadata, StopError, SubprocessConfig, + SystemMessageAppendConfig, + SystemMessageConfig, + SystemMessageCustomizeConfig, + SystemMessageReplaceConfig, + SystemPromptSection, TelemetryConfig, Tool, ToolHandler, @@ -71,13 +80,22 @@ "PermissionRequestResult", "PingResponse", "ProviderConfig", + "SectionOverride", + "SectionOverrideAction", + "SectionTransformFn", "SelectionAttachment", "SessionContext", "SessionEvent", "SessionListFilter", "SessionMetadata", "StopError", + "SYSTEM_PROMPT_SECTIONS", "SubprocessConfig", + "SystemMessageAppendConfig", + "SystemMessageConfig", + "SystemMessageCustomizeConfig", + "SystemMessageReplaceConfig", + "SystemPromptSection", "TelemetryConfig", "Tool", "ToolHandler", diff --git a/python/copilot/client.py b/python/copilot/client.py index 28050088e..e9dd98d35 100644 --- a/python/copilot/client.py +++ b/python/copilot/client.py @@ -45,6 +45,7 @@ PingResponse, ProviderConfig, ReasoningEffort, + SectionTransformFn, SessionEvent, SessionHooks, SessionLifecycleEvent, @@ -73,6 +74,40 @@ MIN_PROTOCOL_VERSION = 2 +def _extract_transform_callbacks( + system_message: dict | None, +) -> tuple[dict | None, dict[str, SectionTransformFn] | None]: + """Extract function-valued actions from system message config. + + Returns a wire-safe payload (with callable actions replaced by ``"transform"``) + and a dict of transform callbacks keyed by section ID. + """ + if ( + not system_message + or system_message.get("mode") != "customize" + or not system_message.get("sections") + ): + return system_message, None + + callbacks: dict[str, SectionTransformFn] = {} + wire_sections: dict[str, dict] = {} + for section_id, override in system_message["sections"].items(): + if not override: + continue + action = override.get("action") + if callable(action): + callbacks[section_id] = action + wire_sections[section_id] = {"action": "transform"} + else: + wire_sections[section_id] = override + + if not callbacks: + return system_message, None + + wire_payload = {**system_message, "sections": wire_sections} + return wire_payload, callbacks + + def _get_bundled_cli_path() -> str | None: """Get the path to the bundled CLI binary, if available.""" # The binary is bundled in copilot/bin/ within the package @@ -548,8 +583,9 @@ async def create_session( if tool_defs: payload["tools"] = tool_defs - if system_message: - payload["systemMessage"] = system_message + wire_system_message, transform_callbacks = _extract_transform_callbacks(system_message) + if wire_system_message: + payload["systemMessage"] = wire_system_message if available_tools is not None: payload["availableTools"] = available_tools @@ -627,6 +663,8 @@ async def create_session( session._register_user_input_handler(on_user_input_request) if hooks: session._register_hooks(hooks) + if transform_callbacks: + session._register_transform_callbacks(transform_callbacks) if on_event: session.on(on_event) with self._sessions_lock: @@ -760,8 +798,9 @@ async def resume_session( if tool_defs: payload["tools"] = tool_defs - if system_message: - payload["systemMessage"] = system_message + wire_system_message, transform_callbacks = _extract_transform_callbacks(system_message) + if wire_system_message: + payload["systemMessage"] = wire_system_message if available_tools is not None: payload["availableTools"] = available_tools @@ -839,6 +878,8 @@ async def resume_session( session._register_user_input_handler(on_user_input_request) if hooks: session._register_hooks(hooks) + if transform_callbacks: + session._register_transform_callbacks(transform_callbacks) if on_event: session.on(on_event) with self._sessions_lock: @@ -1485,6 +1526,9 @@ def handle_notification(method: str, params: dict): self._client.set_request_handler("permission.request", self._handle_permission_request_v2) self._client.set_request_handler("userInput.request", self._handle_user_input_request) self._client.set_request_handler("hooks.invoke", self._handle_hooks_invoke) + self._client.set_request_handler( + "systemMessage.transform", self._handle_system_message_transform + ) # Start listening for messages loop = asyncio.get_running_loop() @@ -1570,6 +1614,9 @@ def handle_notification(method: str, params: dict): self._client.set_request_handler("permission.request", self._handle_permission_request_v2) self._client.set_request_handler("userInput.request", self._handle_user_input_request) self._client.set_request_handler("hooks.invoke", self._handle_hooks_invoke) + self._client.set_request_handler( + "systemMessage.transform", self._handle_system_message_transform + ) # Start listening for messages loop = asyncio.get_running_loop() @@ -1630,6 +1677,32 @@ async def _handle_hooks_invoke(self, params: dict) -> dict: output = await session._handle_hooks_invoke(hook_type, input_data) return {"output": output} + async def _handle_system_message_transform(self, params: dict) -> dict: + """ + Handle a systemMessage.transform request from the CLI server. + + Args: + params: The transform parameters from the server. + + Returns: + A dict containing the transformed sections. + + Raises: + ValueError: If the request payload is invalid. + """ + session_id = params.get("sessionId") + sections = params.get("sections") + + if not session_id or not sections: + raise ValueError("invalid systemMessage.transform payload") + + with self._sessions_lock: + session = self._sessions.get(session_id) + if not session: + raise ValueError(f"unknown session {session_id}") + + return await session._handle_system_message_transform(sections) + # ======================================================================== # Protocol v2 backward-compatibility adapters # ======================================================================== diff --git a/python/copilot/session.py b/python/copilot/session.py index 7a8b9f05d..29421724c 100644 --- a/python/copilot/session.py +++ b/python/copilot/session.py @@ -29,6 +29,7 @@ Attachment, PermissionRequest, PermissionRequestResult, + SectionTransformFn, SessionHooks, Tool, ToolHandler, @@ -97,6 +98,8 @@ def __init__(self, session_id: str, client: Any, workspace_path: str | None = No self._user_input_handler_lock = threading.Lock() self._hooks: SessionHooks | None = None self._hooks_lock = threading.Lock() + self._transform_callbacks: dict[str, SectionTransformFn] | None = None + self._transform_callbacks_lock = threading.Lock() self._rpc: SessionRpc | None = None @property @@ -634,6 +637,62 @@ async def _handle_hooks_invoke(self, hook_type: str, input_data: Any) -> Any: # Hook failed, return None return None + def _register_transform_callbacks( + self, callbacks: dict[str, SectionTransformFn] | None + ) -> None: + """ + Register transform callbacks for system message sections. + + Transform callbacks allow modifying individual sections of the system + prompt at runtime. Each callback receives the current section content + and returns the transformed content. + + Note: + This method is internal. Transform callbacks are typically registered + when creating a session via :meth:`CopilotClient.create_session`. + + Args: + callbacks: A dict mapping section IDs to transform functions, + or None to remove all callbacks. + """ + with self._transform_callbacks_lock: + self._transform_callbacks = callbacks + + async def _handle_system_message_transform( + self, sections: dict[str, dict[str, str]] + ) -> dict[str, dict[str, dict[str, str]]]: + """ + Handle a systemMessage.transform request from the runtime. + + Note: + This method is internal and should not be called directly. + + Args: + sections: A dict mapping section IDs to section data dicts + containing a ``"content"`` key. + + Returns: + A dict with a ``"sections"`` key containing the transformed section data. + """ + with self._transform_callbacks_lock: + callbacks = self._transform_callbacks + + result: dict[str, dict[str, str]] = {} + for section_id, section_data in sections.items(): + content = section_data.get("content", "") + callback = callbacks.get(section_id) if callbacks else None + if callback: + try: + transformed = callback(content) + if inspect.isawaitable(transformed): + transformed = await transformed + result[section_id] = {"content": str(transformed)} + except Exception: # pylint: disable=broad-except + result[section_id] = {"content": content} + else: + result[section_id] = {"content": content} + return {"sections": result} + async def get_messages(self) -> list[SessionEvent]: """ Retrieve all events and messages from this session's history. diff --git a/python/copilot/types.py b/python/copilot/types.py index 17be065bc..ef9a4bce4 100644 --- a/python/copilot/types.py +++ b/python/copilot/types.py @@ -6,7 +6,7 @@ from collections.abc import Awaitable, Callable from dataclasses import KW_ONLY, dataclass, field -from typing import Any, Literal, NotRequired, TypedDict +from typing import Any, Literal, NotRequired, Required, TypedDict # Import generated SessionEvent types from .generated.session_events import ( @@ -213,7 +213,52 @@ class Tool: # System message configuration (discriminated union) -# Use SystemMessageAppendConfig for default behavior, SystemMessageReplaceConfig for full control +# Use SystemMessageAppendConfig for default behavior, +# SystemMessageReplaceConfig for full control, +# or SystemMessageCustomizeConfig for section-level overrides. + +# Known system prompt section identifiers for the "customize" mode. +SystemPromptSection = Literal[ + "identity", + "tone", + "tool_efficiency", + "environment_context", + "code_change_rules", + "guidelines", + "safety", + "tool_instructions", + "custom_instructions", + "last_instructions", +] + +SYSTEM_PROMPT_SECTIONS: dict[SystemPromptSection, str] = { + "identity": "Agent identity preamble and mode statement", + "tone": "Response style, conciseness rules, output formatting preferences", + "tool_efficiency": "Tool usage patterns, parallel calling, batching guidelines", + "environment_context": "CWD, OS, git root, directory listing, available tools", + "code_change_rules": "Coding rules, linting/testing, ecosystem tools, style", + "guidelines": "Tips, behavioral best practices, behavioral guidelines", + "safety": "Environment limitations, prohibited actions, security policies", + "tool_instructions": "Per-tool usage instructions", + "custom_instructions": "Repository and organization custom instructions", + "last_instructions": ( + "End-of-prompt instructions: parallel tool calling, persistence, task completion" + ), +} + + +SectionTransformFn = Callable[[str], str | Awaitable[str]] +"""Transform callback: receives current section content, returns new content.""" + +SectionOverrideAction = Literal["replace", "remove", "append", "prepend"] | SectionTransformFn +"""Override action: a string literal for static overrides, or a callback for transforms.""" + + +class SectionOverride(TypedDict, total=False): + """Override operation for a single system prompt section.""" + + action: Required[SectionOverrideAction] + content: NotRequired[str] class SystemMessageAppendConfig(TypedDict, total=False): @@ -235,8 +280,21 @@ class SystemMessageReplaceConfig(TypedDict): content: str -# Union type - use one or the other -SystemMessageConfig = SystemMessageAppendConfig | SystemMessageReplaceConfig +class SystemMessageCustomizeConfig(TypedDict, total=False): + """ + Customize mode: Override individual sections of the system prompt. + Keeps the SDK-managed prompt structure while allowing targeted modifications. + """ + + mode: Required[Literal["customize"]] + sections: NotRequired[dict[SystemPromptSection, SectionOverride]] + content: NotRequired[str] + + +# Union type - use one based on your needs +SystemMessageConfig = ( + SystemMessageAppendConfig | SystemMessageReplaceConfig | SystemMessageCustomizeConfig +) # Permission result types diff --git a/python/e2e/test_session.py b/python/e2e/test_session.py index ffb0cd2bc..04f0b448e 100644 --- a/python/e2e/test_session.py +++ b/python/e2e/test_session.py @@ -82,6 +82,33 @@ async def test_should_create_a_session_with_replaced_systemMessage_config( system_message = _get_system_message(traffic[0]) assert system_message == test_system_message # Exact match + async def test_should_create_a_session_with_customized_systemMessage_config( + self, ctx: E2ETestContext + ): + custom_tone = "Respond in a warm, professional tone. Be thorough in explanations." + appended_content = "Always mention quarterly earnings." + session = await ctx.client.create_session( + on_permission_request=PermissionHandler.approve_all, + system_message={ + "mode": "customize", + "sections": { + "tone": {"action": "replace", "content": custom_tone}, + "code_change_rules": {"action": "remove"}, + }, + "content": appended_content, + }, + ) + + assistant_message = await session.send_and_wait("Who are you?") + assert assistant_message is not None + + # Validate the system message sent to the model + traffic = await ctx.get_exchanges() + system_message = _get_system_message(traffic[0]) + assert custom_tone in system_message + assert appended_content in system_message + assert "" not in system_message + async def test_should_create_a_session_with_availableTools(self, ctx: E2ETestContext): session = await ctx.client.create_session( on_permission_request=PermissionHandler.approve_all, diff --git a/python/e2e/test_system_message_transform.py b/python/e2e/test_system_message_transform.py new file mode 100644 index 000000000..9ae170637 --- /dev/null +++ b/python/e2e/test_system_message_transform.py @@ -0,0 +1,123 @@ +""" +Copyright (c) Microsoft Corporation. + +Tests for system message transform functionality +""" + +import pytest + +from copilot import PermissionHandler + +from .testharness import E2ETestContext +from .testharness.helper import write_file + +pytestmark = pytest.mark.asyncio(loop_scope="module") + + +class TestSystemMessageTransform: + async def test_should_invoke_transform_callbacks_with_section_content( + self, ctx: E2ETestContext + ): + """Test that transform callbacks are invoked with the section content""" + identity_contents = [] + tone_contents = [] + + async def identity_transform(content: str) -> str: + identity_contents.append(content) + return content + + async def tone_transform(content: str) -> str: + tone_contents.append(content) + return content + + session = await ctx.client.create_session( + system_message={ + "mode": "customize", + "sections": { + "identity": {"action": identity_transform}, + "tone": {"action": tone_transform}, + }, + }, + on_permission_request=PermissionHandler.approve_all, + ) + + write_file(ctx.work_dir, "test.txt", "Hello transform!") + + await session.send_and_wait("Read the contents of test.txt and tell me what it says") + + # Both transform callbacks should have been invoked + assert len(identity_contents) > 0 + assert len(tone_contents) > 0 + + # Callbacks should have received non-empty content + assert all(len(c) > 0 for c in identity_contents) + assert all(len(c) > 0 for c in tone_contents) + + await session.disconnect() + + async def test_should_apply_transform_modifications_to_section_content( + self, ctx: E2ETestContext + ): + """Test that transform modifications are applied to the section content""" + + async def identity_transform(content: str) -> str: + return content + "\nTRANSFORM_MARKER" + + session = await ctx.client.create_session( + system_message={ + "mode": "customize", + "sections": { + "identity": {"action": identity_transform}, + }, + }, + on_permission_request=PermissionHandler.approve_all, + ) + + write_file(ctx.work_dir, "hello.txt", "Hello!") + + await session.send_and_wait("Read the contents of hello.txt") + + # Verify the transform result was actually applied to the system message + traffic = await ctx.get_exchanges() + system_message = _get_system_message(traffic[0]) + assert "TRANSFORM_MARKER" in system_message + + await session.disconnect() + + async def test_should_work_with_static_overrides_and_transforms_together( + self, ctx: E2ETestContext + ): + """Test that static overrides and transforms work together""" + identity_contents = [] + + async def identity_transform(content: str) -> str: + identity_contents.append(content) + return content + + session = await ctx.client.create_session( + system_message={ + "mode": "customize", + "sections": { + "safety": {"action": "remove"}, + "identity": {"action": identity_transform}, + }, + }, + on_permission_request=PermissionHandler.approve_all, + ) + + write_file(ctx.work_dir, "combo.txt", "Combo test!") + + await session.send_and_wait("Read the contents of combo.txt and tell me what it says") + + # The transform callback should have been invoked + assert len(identity_contents) > 0 + + await session.disconnect() + + +def _get_system_message(exchange: dict) -> str: + messages = exchange.get("request", {}).get("messages", []) + for msg in messages: + if msg.get("role") == "system": + return msg.get("content", "") + return "" diff --git a/test/snapshots/session/should_create_a_session_with_customized_systemmessage_config.yaml b/test/snapshots/session/should_create_a_session_with_customized_systemmessage_config.yaml new file mode 100644 index 000000000..f3ce077a6 --- /dev/null +++ b/test/snapshots/session/should_create_a_session_with_customized_systemmessage_config.yaml @@ -0,0 +1,35 @@ +models: + - claude-sonnet-4.5 +conversations: + - messages: + - role: system + content: ${system} + - role: user + content: Who are you? + - role: assistant + content: >- + I'm **GitHub Copilot CLI**, a terminal assistant built by GitHub. I'm powered by claude-sonnet-4.5 (model ID: + claude-sonnet-4.5). + + + I'm here to help you with software engineering tasks, including: + + - Writing, debugging, and refactoring code + + - Running commands and managing development workflows + + - Exploring codebases and understanding how things work + + - Setting up projects, installing dependencies, and configuring tools + + - Working with Git, testing, and deployment tasks + + - Planning and implementing features + + + I have access to a variety of tools including file operations, shell commands, code search, and specialized + sub-agents for specific tasks. I can work with multiple languages and frameworks, and I'm designed to be + efficient by running tasks in parallel when possible. + + + How can I help you today? diff --git a/test/snapshots/system_message_transform/should_apply_transform_modifications_to_section_content.yaml b/test/snapshots/system_message_transform/should_apply_transform_modifications_to_section_content.yaml new file mode 100644 index 000000000..98004f2b0 --- /dev/null +++ b/test/snapshots/system_message_transform/should_apply_transform_modifications_to_section_content.yaml @@ -0,0 +1,33 @@ +models: + - claude-sonnet-4.5 +conversations: + - messages: + - role: system + content: ${system} + - role: user + content: Read the contents of hello.txt + - role: assistant + content: I'll read the hello.txt file for you. + tool_calls: + - id: toolcall_0 + type: function + function: + name: report_intent + arguments: '{"intent":"Reading hello.txt file"}' + - id: toolcall_1 + type: function + function: + name: view + arguments: '{"path":"${workdir}/hello.txt"}' + - role: tool + tool_call_id: toolcall_0 + content: Intent logged + - role: tool + tool_call_id: toolcall_1 + content: 1. Hello! + - role: assistant + content: |- + The file hello.txt contains: + ``` + Hello! + ``` diff --git a/test/snapshots/system_message_transform/should_invoke_transform_callbacks_with_section_content.yaml b/test/snapshots/system_message_transform/should_invoke_transform_callbacks_with_section_content.yaml new file mode 100644 index 000000000..631a8eef8 --- /dev/null +++ b/test/snapshots/system_message_transform/should_invoke_transform_callbacks_with_section_content.yaml @@ -0,0 +1,54 @@ +models: + - claude-sonnet-4.5 +conversations: + - messages: + - role: system + content: ${system} + - role: user + content: Read the contents of test.txt and tell me what it says + - role: assistant + content: I'll read the test.txt file for you. + - role: assistant + tool_calls: + - id: toolcall_0 + type: function + function: + name: report_intent + arguments: '{"intent":"Reading test.txt file"}' + - role: assistant + tool_calls: + - id: toolcall_1 + type: function + function: + name: view + arguments: '{"path":"${workdir}/test.txt"}' + - messages: + - role: system + content: ${system} + - role: user + content: Read the contents of test.txt and tell me what it says + - role: assistant + content: I'll read the test.txt file for you. + tool_calls: + - id: toolcall_0 + type: function + function: + name: report_intent + arguments: '{"intent":"Reading test.txt file"}' + - id: toolcall_1 + type: function + function: + name: view + arguments: '{"path":"${workdir}/test.txt"}' + - role: tool + tool_call_id: toolcall_0 + content: Intent logged + - role: tool + tool_call_id: toolcall_1 + content: 1. Hello transform! + - role: assistant + content: |- + The file test.txt contains: + ``` + Hello transform! + ``` diff --git a/test/snapshots/system_message_transform/should_work_with_static_overrides_and_transforms_together.yaml b/test/snapshots/system_message_transform/should_work_with_static_overrides_and_transforms_together.yaml new file mode 100644 index 000000000..9cb515694 --- /dev/null +++ b/test/snapshots/system_message_transform/should_work_with_static_overrides_and_transforms_together.yaml @@ -0,0 +1,50 @@ +models: + - claude-sonnet-4.5 +conversations: + - messages: + - role: system + content: ${system} + - role: user + content: Read the contents of combo.txt and tell me what it says + - role: assistant + content: I'll read the contents of combo.txt for you. + - role: assistant + tool_calls: + - id: toolcall_0 + type: function + function: + name: report_intent + arguments: '{"intent":"Reading file contents"}' + - role: assistant + tool_calls: + - id: toolcall_1 + type: function + function: + name: view + arguments: '{"path":"${workdir}/combo.txt"}' + - messages: + - role: system + content: ${system} + - role: user + content: Read the contents of combo.txt and tell me what it says + - role: assistant + content: I'll read the contents of combo.txt for you. + tool_calls: + - id: toolcall_0 + type: function + function: + name: report_intent + arguments: '{"intent":"Reading file contents"}' + - id: toolcall_1 + type: function + function: + name: view + arguments: '{"path":"${workdir}/combo.txt"}' + - role: tool + tool_call_id: toolcall_0 + content: Intent logged + - role: tool + tool_call_id: toolcall_1 + content: 1. Combo test! + - role: assistant + content: The file combo.txt contains a single line that says "Combo test!"