feat(oauth): support interactive login selection (#4190)

This commit is contained in:
Armin Ronacher
2026-05-05 13:16:56 +02:00
committed by GitHub
parent bb25a3944c
commit b5755fd27d
4 changed files with 47 additions and 1 deletions

View File

@@ -15,6 +15,7 @@ import {
type Message,
type Model,
type OAuthProviderId,
type OAuthSelectPrompt,
} from "@mariozechner/pi-ai";
import type {
AutocompleteItem,
@@ -4645,6 +4646,34 @@ export class InteractiveMode {
}
}
private showOAuthLoginSelect(dialog: LoginDialogComponent, prompt: OAuthSelectPrompt): Promise<string | undefined> {
return new Promise((resolve) => {
const restoreDialog = () => {
this.editorContainer.clear();
this.editorContainer.addChild(dialog);
this.ui.setFocus(dialog);
this.ui.requestRender();
};
const labels = prompt.options.map((option) => option.label);
const selector = new ExtensionSelectorComponent(
prompt.message,
labels,
(optionLabel) => {
restoreDialog();
resolve(prompt.options.find((option) => option.label === optionLabel)?.id);
},
() => {
restoreDialog();
resolve(undefined);
},
);
this.editorContainer.clear();
this.editorContainer.addChild(selector);
this.ui.setFocus(selector);
this.ui.requestRender();
});
}
private async showLoginDialog(providerId: string, providerName: string): Promise<void> {
const providerInfo = this.session.modelRegistry.authStorage
.getOAuthProviders()
@@ -4722,6 +4751,8 @@ export class InteractiveMode {
dialog.showProgress(message);
},
onSelect: (prompt: OAuthSelectPrompt) => this.showOAuthLoginSelect(dialog, prompt),
onManualCodeInput: () => manualCodePromise,
signal: dialog.signal,