Skip to content

Commit 74fa8c2

Browse files
committed
Fix model selector
1 parent 55782f6 commit 74fa8c2

1 file changed

Lines changed: 31 additions & 18 deletions

File tree

src/cli.ts

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -451,36 +451,49 @@ export async function runCli() {
451451
queueLength: defaultQueue.length(),
452452
});
453453
}
454-
tui.setFocus(editor);
454+
if (!modelSelection.isInSelectionFlow() && !agentRunner.pendingApproval) {
455+
tui.setFocus(editor);
456+
}
455457
};
456458

457459
/**
458-
* Show an overlay screen using pi-tui's native overlay system.
459-
* Does NOT touch the root tree — overlays render on top.
460+
* Show a full-screen selection view by replacing the root content.
461+
* Used for infrequent user-initiated overlays (model selection, approval).
460462
*/
461-
const showScreenOverlay = (
463+
const showScreenView = (
462464
title: string,
463465
description: string,
464466
body: any,
465467
footer?: string,
466468
focusTarget?: any,
467469
) => {
468-
if (tui.hasOverlay()) tui.hideOverlay();
469-
const screen = createScreen(title, description, body, footer);
470-
tui.showOverlay(screen);
470+
root.clear();
471+
root.addChild(createScreen(title, description, body, footer));
471472
if (focusTarget) {
472473
tui.setFocus(focusTarget);
473474
}
474475
};
475476

477+
/**
478+
* Restore the main view after an overlay screen closes.
479+
*/
480+
const restoreMainView = () => {
481+
root.clear();
482+
root.addChild(intro);
483+
root.addChild(chatLog);
484+
root.addChild(errorText);
485+
root.addChild(workingIndicator);
486+
root.addChild(spacer);
487+
root.addChild(editor);
488+
root.addChild(hintBar);
489+
root.addChild(debugPanel);
490+
updateView();
491+
};
492+
476493
const renderSelectionOverlay = () => {
477494
const state = modelSelection.state;
478495
if (state.appState === 'idle' && !agentRunner.pendingApproval) {
479-
if (tui.hasOverlay()) {
480-
tui.hideOverlay();
481-
tui.setFocus(editor);
482-
}
483-
updateView();
496+
restoreMainView();
484497
tui.requestRender();
485498
return;
486499
}
@@ -493,15 +506,15 @@ export async function runCli() {
493506
prompt.onSelect = (decision: ApprovalDecision) => {
494507
agentRunner.respondToApproval(decision);
495508
};
496-
showScreenOverlay('', '', prompt, undefined, prompt.selector);
509+
showScreenView('', '', prompt, undefined, prompt.selector);
497510
return;
498511
}
499512

500513
if (state.appState === 'provider_select') {
501514
const selector = createProviderSelector(modelSelection.provider, (providerId) => {
502515
void modelSelection.handleProviderSelect(providerId);
503516
});
504-
showScreenOverlay(
517+
showScreenView(
505518
'Select provider',
506519
'Switch between LLM providers. Applies to this session and future sessions.',
507520
selector,
@@ -518,7 +531,7 @@ export async function runCli() {
518531
(modelId) => modelSelection.handleModelSelect(modelId),
519532
state.pendingProvider,
520533
);
521-
showScreenOverlay(
534+
showScreenView(
522535
`Select model for ${getProviderDisplayName(state.pendingProvider)}`,
523536
'',
524537
selector,
@@ -532,7 +545,7 @@ export async function runCli() {
532545
const input = new ApiKeyInputComponent();
533546
input.onSubmit = (value) => modelSelection.handleModelInputSubmit(value);
534547
input.onCancel = () => modelSelection.handleModelInputSubmit(null);
535-
showScreenOverlay(
548+
showScreenView(
536549
`Enter model name for ${getProviderDisplayName(state.pendingProvider)}`,
537550
'Type or paste the model name from openrouter.ai/models',
538551
input,
@@ -546,7 +559,7 @@ export async function runCli() {
546559
const selector = createApiKeyConfirmSelector((wantsToSet) =>
547560
modelSelection.handleApiKeyConfirm(wantsToSet),
548561
);
549-
showScreenOverlay(
562+
showScreenView(
550563
'Set API Key',
551564
`Would you like to set your ${getProviderDisplayName(state.pendingProvider)} API key?`,
552565
selector,
@@ -561,7 +574,7 @@ export async function runCli() {
561574
input.onSubmit = (apiKey) => modelSelection.handleApiKeySubmit(apiKey);
562575
input.onCancel = () => modelSelection.handleApiKeySubmit(null);
563576
const apiKeyName = getApiKeyNameForProvider(state.pendingProvider) ?? '';
564-
showScreenOverlay(
577+
showScreenView(
565578
`Enter ${getProviderDisplayName(state.pendingProvider)} API Key`,
566579
apiKeyName ? `(${apiKeyName})` : '',
567580
input,

0 commit comments

Comments
 (0)