Skip to content

Commit fbe8a24

Browse files
authored
Merge pull request #9 from invokable/copilot/update-official-sdk-client-name
feat: add clientName to SessionConfig and ResumeSessionConfig
2 parents 73403b7 + 9ef37bc commit fbe8a24

4 files changed

Lines changed: 23 additions & 0 deletions

File tree

src/Types/ResumeSessionConfig.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414
readonly class ResumeSessionConfig implements Arrayable
1515
{
1616
public function __construct(
17+
/**
18+
* Client name to identify the application using the SDK.
19+
* Included in the User-Agent header for API requests.
20+
*/
21+
public ?string $clientName = null,
1722
/**
1823
* Model to use for this session.
1924
*/
@@ -146,6 +151,7 @@ public static function fromArray(array $data): self
146151
}
147152

148153
return new self(
154+
clientName: $data['clientName'] ?? null,
149155
model: $data['model'] ?? null,
150156
reasoningEffort: $data['reasoningEffort'] ?? null,
151157
configDir: $data['configDir'] ?? null,
@@ -194,6 +200,7 @@ public function toArray(): array
194200
: $this->hooks;
195201

196202
return array_filter([
203+
'clientName' => $this->clientName,
197204
'model' => $this->model,
198205
'reasoningEffort' => $reasoningEffort,
199206
'configDir' => $this->configDir,

src/Types/SessionConfig.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ public function __construct(
1919
* If not provided, server will generate one.
2020
*/
2121
public ?string $sessionId = null,
22+
/**
23+
* Client name to identify the application using the SDK.
24+
* Included in the User-Agent header for API requests.
25+
*/
26+
public ?string $clientName = null,
2227
/**
2328
* Model to use for this session.
2429
*/
@@ -145,6 +150,7 @@ public static function fromArray(array $data): self
145150

146151
return new self(
147152
sessionId: $data['sessionId'] ?? null,
153+
clientName: $data['clientName'] ?? null,
148154
model: $data['model'] ?? null,
149155
reasoningEffort: $data['reasoningEffort'] ?? null,
150156
configDir: $data['configDir'] ?? null,
@@ -193,6 +199,7 @@ public function toArray(): array
193199

194200
return array_filter([
195201
'sessionId' => $this->sessionId,
202+
'clientName' => $this->clientName,
196203
'model' => $this->model,
197204
'reasoningEffort' => $reasoningEffort,
198205
'configDir' => $this->configDir,

tests/Unit/Types/ResumeSessionConfigTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
$preToolUseHook = fn () => null;
1717

1818
$config = ResumeSessionConfig::fromArray([
19+
'clientName' => 'my-app',
1920
'model' => 'claude-opus-4.6',
2021
'reasoningEffort' => ReasoningEffort::XHIGH,
2122
'configDir' => './src',
@@ -38,6 +39,7 @@
3839
]);
3940

4041
expect($config->tools)->toBe([['name' => 'test_tool']])
42+
->and($config->clientName)->toBe('my-app')
4143
->and($config->model)->toBe('claude-opus-4.6')
4244
->and($config->reasoningEffort)->toBe(ReasoningEffort::XHIGH)
4345
->and($config->systemMessage->content)->toBe('Instructions')
@@ -96,6 +98,7 @@
9698
$preToolUseHook = fn () => null;
9799

98100
$config = new ResumeSessionConfig(
101+
clientName: 'my-app',
99102
model: 'claude-opus-4.6',
100103
reasoningEffort: ReasoningEffort::XHIGH,
101104
configDir: './src',
@@ -120,6 +123,7 @@
120123
$array = $config->toArray();
121124

122125
expect($array['tools'])->toBe([['name' => 'tool1']])
126+
->and($array['clientName'])->toBe('my-app')
123127
->and($array['provider'])->toBe(['baseUrl' => 'https://api.test.com'])
124128
->and($array['onPermissionRequest'])->toBe($handler)
125129
->and($array['onUserInputRequest'])->toBe($userInputHandler)

tests/Unit/Types/SessionConfigTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
$config = SessionConfig::fromArray([
1919
'sessionId' => 'test-session-id',
20+
'clientName' => 'my-app',
2021
'model' => 'claude-sonnet-4.5',
2122
'configDir' => '/tmp/config',
2223
'tools' => [['name' => 'test_tool']],
@@ -37,6 +38,7 @@
3738
]);
3839

3940
expect($config->sessionId)->toBe('test-session-id')
41+
->and($config->clientName)->toBe('my-app')
4042
->and($config->model)->toBe('claude-sonnet-4.5')
4143
->and($config->configDir)->toBe('/tmp/config')
4244
->and($config->tools)->toBe([['name' => 'test_tool']])
@@ -63,6 +65,7 @@
6365
$config = SessionConfig::fromArray([]);
6466

6567
expect($config->sessionId)->toBeNull()
68+
->and($config->clientName)->toBeNull()
6669
->and($config->model)->toBeNull()
6770
->and($config->configDir)->toBeNull()
6871
->and($config->tools)->toBeNull()
@@ -107,6 +110,7 @@
107110

108111
$config = new SessionConfig(
109112
sessionId: 'session-123',
113+
clientName: 'my-app',
110114
model: 'gpt-4',
111115
configDir: '/config',
112116
tools: [['name' => 'tool1']],
@@ -129,6 +133,7 @@
129133
$array = $config->toArray();
130134

131135
expect($array['sessionId'])->toBe('session-123')
136+
->and($array['clientName'])->toBe('my-app')
132137
->and($array['model'])->toBe('gpt-4')
133138
->and($array['configDir'])->toBe('/config')
134139
->and($array['tools'])->toBe([['name' => 'tool1']])

0 commit comments

Comments
 (0)