Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/Contracts/CopilotSession.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Closure;
use Revolution\Copilot\Enums\SessionEventType;
use Revolution\Copilot\Exceptions\JsonRpcException;
use Revolution\Copilot\Rpc\SessionRpc;
use Revolution\Copilot\Types\SessionEvent;

Expand All @@ -24,6 +25,13 @@ public function id(): string;
*/
public function rpc(): SessionRpc;

/**
* Switch the model for this session.
*
* @throws JsonRpcException
*/
public function setModel(string $modelId): void;

/**
* Send a message to this session.
*/
Expand Down
11 changes: 11 additions & 0 deletions src/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use Revolution\Copilot\JsonRpc\JsonRpcClient;
use Revolution\Copilot\Rpc\SessionRpc;
use Revolution\Copilot\Support\PermissionRequestKind;
use Revolution\Copilot\Types\Rpc\SessionModelSwitchToParams;
use Revolution\Copilot\Types\SessionEvent;
use Revolution\Copilot\Types\SessionHooks;
use Revolution\Copilot\Types\UserInputRequest;
Expand Down Expand Up @@ -662,6 +663,16 @@ public function destroy(): void
$this->hooks = null;
}

/**
* Switch the model for this session.
*
* @throws JsonRpcException
*/
public function setModel(string $modelId): void
{
$this->rpc()->model()->switchTo(new SessionModelSwitchToParams(modelId: $modelId));
}

/**
* Abort the currently processing message.
*
Expand Down
5 changes: 5 additions & 0 deletions src/Testing/FakeSession.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ public function rpc(): SessionRpc
);
}

public function setModel(string $modelId): void
{
// No-op in fake
}

public function send(string $prompt, ?array $attachments = null, ?string $mode = null): string
{
$this->recorded[] = [
Expand Down
14 changes: 14 additions & 0 deletions tests/Feature/SessionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,20 @@
$session->abort();
});

it('setModel calls session.model.switchTo via rpc', function () {
$mockClient = Mockery::mock(JsonRpcClient::class);
$mockClient->shouldReceive('request')
->with('session.model.switchTo', [
'modelId' => 'claude-sonnet-4',
'sessionId' => 'test-session',
])
->once()
->andReturn(['modelId' => 'claude-sonnet-4']);

$session = new Session('test-session', $mockClient);
$session->setModel('claude-sonnet-4');
});

it('handlePermissionRequest uses registered handler', function () {
$mockClient = Mockery::mock(JsonRpcClient::class);
$session = new Session('test-session', $mockClient);
Expand Down