diff --git a/src/Types/ResumeSessionConfig.php b/src/Types/ResumeSessionConfig.php index 7efe478..6a86fcd 100644 --- a/src/Types/ResumeSessionConfig.php +++ b/src/Types/ResumeSessionConfig.php @@ -14,6 +14,11 @@ readonly class ResumeSessionConfig implements Arrayable { public function __construct( + /** + * Client name to identify the application using the SDK. + * Included in the User-Agent header for API requests. + */ + public ?string $clientName = null, /** * Model to use for this session. */ @@ -146,6 +151,7 @@ public static function fromArray(array $data): self } return new self( + clientName: $data['clientName'] ?? null, model: $data['model'] ?? null, reasoningEffort: $data['reasoningEffort'] ?? null, configDir: $data['configDir'] ?? null, @@ -194,6 +200,7 @@ public function toArray(): array : $this->hooks; return array_filter([ + 'clientName' => $this->clientName, 'model' => $this->model, 'reasoningEffort' => $reasoningEffort, 'configDir' => $this->configDir, diff --git a/src/Types/SessionConfig.php b/src/Types/SessionConfig.php index 25a3f2b..14756d2 100644 --- a/src/Types/SessionConfig.php +++ b/src/Types/SessionConfig.php @@ -19,6 +19,11 @@ public function __construct( * If not provided, server will generate one. */ public ?string $sessionId = null, + /** + * Client name to identify the application using the SDK. + * Included in the User-Agent header for API requests. + */ + public ?string $clientName = null, /** * Model to use for this session. */ @@ -145,6 +150,7 @@ public static function fromArray(array $data): self return new self( sessionId: $data['sessionId'] ?? null, + clientName: $data['clientName'] ?? null, model: $data['model'] ?? null, reasoningEffort: $data['reasoningEffort'] ?? null, configDir: $data['configDir'] ?? null, @@ -193,6 +199,7 @@ public function toArray(): array return array_filter([ 'sessionId' => $this->sessionId, + 'clientName' => $this->clientName, 'model' => $this->model, 'reasoningEffort' => $reasoningEffort, 'configDir' => $this->configDir, diff --git a/tests/Unit/Types/ResumeSessionConfigTest.php b/tests/Unit/Types/ResumeSessionConfigTest.php index 1291714..64decc1 100644 --- a/tests/Unit/Types/ResumeSessionConfigTest.php +++ b/tests/Unit/Types/ResumeSessionConfigTest.php @@ -16,6 +16,7 @@ $preToolUseHook = fn () => null; $config = ResumeSessionConfig::fromArray([ + 'clientName' => 'my-app', 'model' => 'claude-opus-4.6', 'reasoningEffort' => ReasoningEffort::XHIGH, 'configDir' => './src', @@ -38,6 +39,7 @@ ]); expect($config->tools)->toBe([['name' => 'test_tool']]) + ->and($config->clientName)->toBe('my-app') ->and($config->model)->toBe('claude-opus-4.6') ->and($config->reasoningEffort)->toBe(ReasoningEffort::XHIGH) ->and($config->systemMessage->content)->toBe('Instructions') @@ -96,6 +98,7 @@ $preToolUseHook = fn () => null; $config = new ResumeSessionConfig( + clientName: 'my-app', model: 'claude-opus-4.6', reasoningEffort: ReasoningEffort::XHIGH, configDir: './src', @@ -120,6 +123,7 @@ $array = $config->toArray(); expect($array['tools'])->toBe([['name' => 'tool1']]) + ->and($array['clientName'])->toBe('my-app') ->and($array['provider'])->toBe(['baseUrl' => 'https://api.test.com']) ->and($array['onPermissionRequest'])->toBe($handler) ->and($array['onUserInputRequest'])->toBe($userInputHandler) diff --git a/tests/Unit/Types/SessionConfigTest.php b/tests/Unit/Types/SessionConfigTest.php index bae29e3..eaee2fa 100644 --- a/tests/Unit/Types/SessionConfigTest.php +++ b/tests/Unit/Types/SessionConfigTest.php @@ -17,6 +17,7 @@ $config = SessionConfig::fromArray([ 'sessionId' => 'test-session-id', + 'clientName' => 'my-app', 'model' => 'claude-sonnet-4.5', 'configDir' => '/tmp/config', 'tools' => [['name' => 'test_tool']], @@ -37,6 +38,7 @@ ]); expect($config->sessionId)->toBe('test-session-id') + ->and($config->clientName)->toBe('my-app') ->and($config->model)->toBe('claude-sonnet-4.5') ->and($config->configDir)->toBe('/tmp/config') ->and($config->tools)->toBe([['name' => 'test_tool']]) @@ -63,6 +65,7 @@ $config = SessionConfig::fromArray([]); expect($config->sessionId)->toBeNull() + ->and($config->clientName)->toBeNull() ->and($config->model)->toBeNull() ->and($config->configDir)->toBeNull() ->and($config->tools)->toBeNull() @@ -107,6 +110,7 @@ $config = new SessionConfig( sessionId: 'session-123', + clientName: 'my-app', model: 'gpt-4', configDir: '/config', tools: [['name' => 'tool1']], @@ -129,6 +133,7 @@ $array = $config->toArray(); expect($array['sessionId'])->toBe('session-123') + ->and($array['clientName'])->toBe('my-app') ->and($array['model'])->toBe('gpt-4') ->and($array['configDir'])->toBe('/config') ->and($array['tools'])->toBe([['name' => 'tool1']])