Skip to content

Commit 09ca61e

Browse files
Improve setModel API: variadic Go opts, reuse TS ReasoningEffort type, fix .NET overloads
- Go: use variadic ...SetModelOptions for backward compatibility - TypeScript: reuse ReasoningEffort type instead of inline union - .NET: remove redundant default on reasoningEffort param, make CancellationToken optional in both overloads - Revert unrelated dotnet/test/RpcTests.cs change Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent c0c4635 commit 09ca61e

File tree

5 files changed

+13
-13
lines changed

5 files changed

+13
-13
lines changed

dotnet/src/Session.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -663,23 +663,23 @@ await InvokeRpcAsync<object>(
663663
/// The new model takes effect for the next message. Conversation history is preserved.
664664
/// </summary>
665665
/// <param name="model">Model ID to switch to (e.g., "gpt-4.1").</param>
666-
/// <param name="reasoningEffort">Optional reasoning effort level (e.g., "low", "medium", "high", "xhigh").</param>
666+
/// <param name="reasoningEffort">Reasoning effort level (e.g., "low", "medium", "high", "xhigh").</param>
667667
/// <param name="cancellationToken">Optional cancellation token.</param>
668668
/// <example>
669669
/// <code>
670670
/// await session.SetModelAsync("gpt-4.1");
671671
/// await session.SetModelAsync("claude-sonnet-4.6", SessionModelSwitchToRequestReasoningEffort.High);
672672
/// </code>
673673
/// </example>
674-
public async Task SetModelAsync(string model, SessionModelSwitchToRequestReasoningEffort? reasoningEffort = null, CancellationToken cancellationToken = default)
674+
public async Task SetModelAsync(string model, SessionModelSwitchToRequestReasoningEffort? reasoningEffort, CancellationToken cancellationToken = default)
675675
{
676676
await Rpc.Model.SwitchToAsync(model, reasoningEffort, cancellationToken);
677677
}
678678

679679
/// <summary>
680-
/// Changes the model for this session (backward-compatible overload).
680+
/// Changes the model for this session.
681681
/// </summary>
682-
public Task SetModelAsync(string model, CancellationToken cancellationToken)
682+
public Task SetModelAsync(string model, CancellationToken cancellationToken = default)
683683
{
684684
return SetModelAsync(model, reasoningEffort: null, cancellationToken);
685685
}

dotnet/test/RpcTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public async Task Should_Call_Session_Rpc_Model_SwitchTo()
7373
Assert.NotNull(before.ModelId);
7474

7575
// Switch to a different model
76-
var result = await session.Rpc.Model.SwitchToAsync(modelId: "gpt-4.1", reasoningEffort: null);
76+
var result = await session.Rpc.Model.SwitchToAsync(modelId: "gpt-4.1");
7777
Assert.Equal("gpt-4.1", result.ModelId);
7878

7979
// Verify the switch persisted

go/internal/e2e/rpc_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ func TestSessionRpc(t *testing.T) {
201201
t.Fatalf("Failed to create session: %v", err)
202202
}
203203

204-
if err := session.SetModel(t.Context(), "gpt-4.1", nil); err != nil {
204+
if err := session.SetModel(t.Context(), "gpt-4.1"); err != nil {
205205
t.Fatalf("SetModel returned error: %v", err)
206206
}
207207
})

go/session.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -693,20 +693,19 @@ type SetModelOptions struct {
693693

694694
// SetModel changes the model for this session.
695695
// The new model takes effect for the next message. Conversation history is preserved.
696-
// Pass nil for opts if no additional options are needed.
697696
//
698697
// Example:
699698
//
700-
// if err := session.SetModel(context.Background(), "gpt-4.1", nil); err != nil {
699+
// if err := session.SetModel(context.Background(), "gpt-4.1"); err != nil {
701700
// log.Printf("Failed to set model: %v", err)
702701
// }
703-
// if err := session.SetModel(context.Background(), "claude-sonnet-4.6", &SetModelOptions{ReasoningEffort: "high"}); err != nil {
702+
// if err := session.SetModel(context.Background(), "claude-sonnet-4.6", SetModelOptions{ReasoningEffort: "high"}); err != nil {
704703
// log.Printf("Failed to set model: %v", err)
705704
// }
706-
func (s *Session) SetModel(ctx context.Context, model string, opts *SetModelOptions) error {
705+
func (s *Session) SetModel(ctx context.Context, model string, opts ...SetModelOptions) error {
707706
params := &rpc.SessionModelSwitchToParams{ModelID: model}
708-
if opts != nil && opts.ReasoningEffort != "" {
709-
re := opts.ReasoningEffort
707+
if len(opts) > 0 && opts[0].ReasoningEffort != "" {
708+
re := opts[0].ReasoningEffort
710709
params.ReasoningEffort = &re
711710
}
712711
_, err := s.RPC.Model.SwitchTo(ctx, params)

nodejs/src/session.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import type {
1515
PermissionHandler,
1616
PermissionRequest,
1717
PermissionRequestResult,
18+
ReasoningEffort,
1819
SessionEvent,
1920
SessionEventHandler,
2021
SessionEventPayload,
@@ -694,7 +695,7 @@ export class CopilotSession {
694695
*/
695696
async setModel(
696697
model: string,
697-
options?: { reasoningEffort?: "low" | "medium" | "high" | "xhigh" }
698+
options?: { reasoningEffort?: ReasoningEffort }
698699
): Promise<void> {
699700
await this.rpc.model.switchTo({ modelId: model, ...options });
700701
}

0 commit comments

Comments
 (0)