( host: SlashCommandHost, alias: string, effort: ThinkingEffort, persist: boolean, )
| 388 | } |
| 389 | |
| 390 | async function performModelSwitch( |
| 391 | host: SlashCommandHost, |
| 392 | alias: string, |
| 393 | effort: ThinkingEffort, |
| 394 | persist: boolean, |
| 395 | ): Promise<void> { |
| 396 | if (host.state.appState.streamingPhase !== 'idle') { |
| 397 | host.showError('Cannot switch models while streaming — press Esc or Ctrl-C first.'); |
| 398 | return; |
| 399 | } |
| 400 | |
| 401 | const prevModel = host.state.appState.model; |
| 402 | const prevEffort = host.state.appState.thinkingEffort; |
| 403 | const modelChanged = alias !== prevModel; |
| 404 | const effortChanged = effort !== prevEffort; |
| 405 | const runtimeChanged = modelChanged || effortChanged; |
| 406 | const displayName = modelDisplayName(alias, host.state.appState.availableModels[alias]); |
| 407 | |
| 408 | const session = host.session; |
| 409 | try { |
| 410 | if (session === undefined && runtimeChanged) { |
| 411 | await host.authFlow.activateModelAfterLogin(alias, effort); |
| 412 | } else if (session !== undefined) { |
| 413 | if (alias !== prevModel) { |
| 414 | await session.setModel(alias); |
| 415 | } |
| 416 | if (effort !== prevEffort) { |
| 417 | await session.setThinking(effort); |
| 418 | } |
| 419 | } |
| 420 | } catch (error) { |
| 421 | const msg = formatErrorMessage(error); |
| 422 | host.showError(`Failed to switch model: ${msg}`); |
| 423 | return; |
| 424 | } |
| 425 | |
| 426 | host.setAppState({ model: alias, thinkingEffort: effort }); |
| 427 | if (session === undefined && runtimeChanged) { |
| 428 | if (alias !== prevModel) { |
| 429 | host.track('model_switch', { model: alias }); |
| 430 | } |
| 431 | if (effort !== prevEffort) { |
| 432 | host.track('thinking_toggle', { |
| 433 | enabled: effort !== 'off', |
| 434 | effort, |
| 435 | from: prevEffort, |
| 436 | }); |
| 437 | } |
| 438 | } |
| 439 | |
| 440 | let persisted = false; |
| 441 | if (persist) { |
| 442 | try { |
| 443 | persisted = await persistModelSelection(host, alias, effort); |
| 444 | } catch (error) { |
| 445 | const msg = formatErrorMessage(error); |
| 446 | host.showError(`Switched to ${displayName}, but failed to save default: ${msg}`); |
| 447 | return; |
no test coverage detected