Skip to content

Commit 443ba57

Browse files
devm33Copilot
andcommitted
feat: add clientName to SessionConfig across all SDKs
Add clientName as an optional field to SessionConfig and ResumeSessionConfig in all four SDK languages (Node.js, Python, Go, .NET). This allows SDK consumers to identify their application, which is included in the User-Agent header for API requests. The CLI server protocol already supports clientName on both session.create and session.resume requests, but the SDK types were not exposing it. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 19d8cea commit 443ba57

8 files changed

Lines changed: 50 additions & 0 deletions

File tree

dotnet/src/Client.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,7 @@ public async Task<CopilotSession> CreateSessionAsync(SessionConfig? config = nul
371371
var request = new CreateSessionRequest(
372372
config?.Model,
373373
config?.SessionId,
374+
config?.ClientName,
374375
config?.ReasoningEffort,
375376
config?.Tools?.Select(ToolDefinition.FromAIFunction).ToList(),
376377
config?.SystemMessage,
@@ -454,6 +455,7 @@ public async Task<CopilotSession> ResumeSessionAsync(string sessionId, ResumeSes
454455

455456
var request = new ResumeSessionRequest(
456457
sessionId,
458+
config?.ClientName,
457459
config?.Model,
458460
config?.ReasoningEffort,
459461
config?.Tools?.Select(ToolDefinition.FromAIFunction).ToList(),
@@ -1375,6 +1377,7 @@ public static string Escape(string arg)
13751377
internal record CreateSessionRequest(
13761378
string? Model,
13771379
string? SessionId,
1380+
string? ClientName,
13781381
string? ReasoningEffort,
13791382
List<ToolDefinition>? Tools,
13801383
SystemMessageConfig? SystemMessage,
@@ -1409,6 +1412,7 @@ internal record CreateSessionResponse(
14091412

14101413
internal record ResumeSessionRequest(
14111414
string SessionId,
1415+
string? ClientName,
14121416
string? Model,
14131417
string? ReasoningEffort,
14141418
List<ToolDefinition>? Tools,

dotnet/src/Types.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -745,6 +745,7 @@ protected SessionConfig(SessionConfig? other)
745745
if (other is null) return;
746746

747747
AvailableTools = other.AvailableTools is not null ? [.. other.AvailableTools] : null;
748+
ClientName = other.ClientName;
748749
ConfigDir = other.ConfigDir;
749750
CustomAgents = other.CustomAgents is not null ? [.. other.CustomAgents] : null;
750751
DisabledSkills = other.DisabledSkills is not null ? [.. other.DisabledSkills] : null;
@@ -768,6 +769,13 @@ protected SessionConfig(SessionConfig? other)
768769
}
769770

770771
public string? SessionId { get; set; }
772+
773+
/// <summary>
774+
/// Client name to identify the application using the SDK.
775+
/// Included in the User-Agent header for API requests.
776+
/// </summary>
777+
public string? ClientName { get; set; }
778+
771779
public string? Model { get; set; }
772780

773781
/// <summary>
@@ -874,6 +882,7 @@ protected ResumeSessionConfig(ResumeSessionConfig? other)
874882
if (other is null) return;
875883

876884
AvailableTools = other.AvailableTools is not null ? [.. other.AvailableTools] : null;
885+
ClientName = other.ClientName;
877886
ConfigDir = other.ConfigDir;
878887
CustomAgents = other.CustomAgents is not null ? [.. other.CustomAgents] : null;
879888
DisabledSkills = other.DisabledSkills is not null ? [.. other.DisabledSkills] : null;
@@ -896,6 +905,12 @@ protected ResumeSessionConfig(ResumeSessionConfig? other)
896905
WorkingDirectory = other.WorkingDirectory;
897906
}
898907

908+
/// <summary>
909+
/// Client name to identify the application using the SDK.
910+
/// Included in the User-Agent header for API requests.
911+
/// </summary>
912+
public string? ClientName { get; set; }
913+
899914
/// <summary>
900915
/// Model to use for this session. Can change the model when resuming.
901916
/// </summary>

go/client.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,7 @@ func (c *Client) CreateSession(ctx context.Context, config *SessionConfig) (*Ses
455455
if config != nil {
456456
req.Model = config.Model
457457
req.SessionID = config.SessionID
458+
req.ClientName = config.ClientName
458459
req.ReasoningEffort = config.ReasoningEffort
459460
req.ConfigDir = config.ConfigDir
460461
req.Tools = config.Tools
@@ -552,6 +553,7 @@ func (c *Client) ResumeSessionWithOptions(ctx context.Context, sessionID string,
552553
var req resumeSessionRequest
553554
req.SessionID = sessionID
554555
if config != nil {
556+
req.ClientName = config.ClientName
555557
req.Model = config.Model
556558
req.ReasoningEffort = config.ReasoningEffort
557559
req.SystemMessage = config.SystemMessage

go/types.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,9 @@ type InfiniteSessionConfig struct {
330330
type SessionConfig struct {
331331
// SessionID is an optional custom session ID
332332
SessionID string
333+
// ClientName identifies the application using the SDK.
334+
// Included in the User-Agent header for API requests.
335+
ClientName string
333336
// Model to use for this session
334337
Model string
335338
// ReasoningEffort level for models that support it.
@@ -409,6 +412,9 @@ type ToolResult struct {
409412

410413
// ResumeSessionConfig configures options when resuming a session
411414
type ResumeSessionConfig struct {
415+
// ClientName identifies the application using the SDK.
416+
// Included in the User-Agent header for API requests.
417+
ClientName string
412418
// Model to use for this session. Can change the model when resuming.
413419
Model string
414420
// Tools exposes caller-implemented tools to the CLI
@@ -626,6 +632,7 @@ type permissionRequestResponse struct {
626632
type createSessionRequest struct {
627633
Model string `json:"model,omitempty"`
628634
SessionID string `json:"sessionId,omitempty"`
635+
ClientName string `json:"clientName,omitempty"`
629636
ReasoningEffort string `json:"reasoningEffort,omitempty"`
630637
Tools []Tool `json:"tools,omitempty"`
631638
SystemMessage *SystemMessageConfig `json:"systemMessage,omitempty"`
@@ -655,6 +662,7 @@ type createSessionResponse struct {
655662
// resumeSessionRequest is the request for session.resume
656663
type resumeSessionRequest struct {
657664
SessionID string `json:"sessionId"`
665+
ClientName string `json:"clientName,omitempty"`
658666
Model string `json:"model,omitempty"`
659667
ReasoningEffort string `json:"reasoningEffort,omitempty"`
660668
Tools []Tool `json:"tools,omitempty"`

nodejs/src/client.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,7 @@ export class CopilotClient {
513513
const response = await this.connection!.sendRequest("session.create", {
514514
model: config.model,
515515
sessionId: config.sessionId,
516+
clientName: config.clientName,
516517
reasoningEffort: config.reasoningEffort,
517518
tools: config.tools?.map((tool) => ({
518519
name: tool.name,
@@ -594,6 +595,7 @@ export class CopilotClient {
594595

595596
const response = await this.connection!.sendRequest("session.resume", {
596597
sessionId,
598+
clientName: config.clientName,
597599
model: config.model,
598600
reasoningEffort: config.reasoningEffort,
599601
systemMessage: config.systemMessage,

nodejs/src/types.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,12 @@ export interface SessionConfig {
615615
*/
616616
sessionId?: string;
617617

618+
/**
619+
* Client name to identify the application using the SDK.
620+
* Included in the User-Agent header for API requests.
621+
*/
622+
clientName?: string;
623+
618624
/**
619625
* Model to use for this session
620626
*/
@@ -730,6 +736,7 @@ export interface SessionConfig {
730736
*/
731737
export type ResumeSessionConfig = Pick<
732738
SessionConfig,
739+
| "clientName"
733740
| "model"
734741
| "tools"
735742
| "systemMessage"

python/copilot/client.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,8 @@ async def create_session(self, config: Optional[SessionConfig] = None) -> Copilo
467467
payload["model"] = cfg["model"]
468468
if cfg.get("session_id"):
469469
payload["sessionId"] = cfg["session_id"]
470+
if cfg.get("client_name"):
471+
payload["clientName"] = cfg["client_name"]
470472
if cfg.get("reasoning_effort"):
471473
payload["reasoningEffort"] = cfg["reasoning_effort"]
472474
if tool_defs:
@@ -629,6 +631,11 @@ async def resume_session(
629631

630632
payload: dict[str, Any] = {"sessionId": session_id}
631633

634+
# Add client name if provided
635+
client_name = cfg.get("client_name")
636+
if client_name:
637+
payload["clientName"] = client_name
638+
632639
# Add model if provided
633640
model = cfg.get("model")
634641
if model:

python/copilot/types.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,9 @@ class SessionConfig(TypedDict, total=False):
462462
"""Configuration for creating a session"""
463463

464464
session_id: str # Optional custom session ID
465+
# Client name to identify the application using the SDK.
466+
# Included in the User-Agent header for API requests.
467+
client_name: str
465468
model: str # Model to use for this session. Use client.list_models() to see available models.
466469
# Reasoning effort level for models that support it.
467470
# Only valid for models where capabilities.supports.reasoning_effort is True.
@@ -529,6 +532,8 @@ class ProviderConfig(TypedDict, total=False):
529532
class ResumeSessionConfig(TypedDict, total=False):
530533
"""Configuration for resuming a session"""
531534

535+
# Client name to identify the application using the SDK.
536+
client_name: str
532537
# Model to use for this session. Can change the model when resuming.
533538
model: str
534539
tools: list[Tool]

0 commit comments

Comments
 (0)