@linxiraos/pi-tui 1.4.6 → 1.4.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +194 -195
- package/README.md +34 -34
- package/dist/types/app-keybindings.d.ts +15 -0
- package/dist/types/apps/session-picker.d.ts +5 -0
- package/dist/types/charts/chart-plan.d.ts +9 -7
- package/dist/types/chat/assistant-message.d.ts +15 -3
- package/dist/types/chat/bash-execution.d.ts +2 -0
- package/dist/types/chat/display-preferences.d.ts +2 -0
- package/dist/types/chat/extension-types.d.ts +31 -0
- package/dist/types/chat/reply-write.d.ts +48 -0
- package/dist/types/chat/table-chart.d.ts +4 -3
- package/dist/types/chat/tool-execution.d.ts +1 -2
- package/dist/types/chat/transcript-outline.d.ts +7 -0
- package/dist/types/chat/transcript-render-helpers.d.ts +2 -0
- package/dist/types/chrome/index.d.ts +1 -0
- package/dist/types/chrome/transcript-notice.d.ts +35 -0
- package/dist/types/chrome/transcript-status.d.ts +20 -8
- package/dist/types/components/editor.d.ts +8 -0
- package/dist/types/components/markdown.d.ts +7 -0
- package/dist/types/native/blobs.d.ts +2 -1
- package/dist/types/native/picker.d.ts +4 -4
- package/dist/types/overlays/annotation-overlay.d.ts +7 -1
- package/dist/types/overlays/annotation-types.d.ts +28 -0
- package/dist/types/overlays/login-dialog.d.ts +5 -1
- package/dist/types/overlays/model-browser.d.ts +10 -1
- package/dist/types/overlays/oauth-selector.d.ts +23 -0
- package/dist/types/overlays/plan-review-overlay.d.ts +2 -0
- package/dist/types/overlays/rewind-selector.d.ts +1 -1
- package/dist/types/overlays/session-selector.d.ts +22 -2
- package/dist/types/prompt/composer.d.ts +43 -0
- package/dist/types/prompt/interactive-context-helpers.d.ts +10 -3
- package/dist/types/render/extension-links.d.ts +65 -0
- package/dist/types/render/hyperlink.d.ts +25 -7
- package/dist/types/render/index.d.ts +1 -0
- package/dist/types/setup/scenes/glyph.d.ts +1 -1
- package/dist/types/setup/scenes/model.d.ts +1 -1
- package/dist/types/setup/scenes/outro.d.ts +5 -4
- package/dist/types/setup/scenes/sign-in.d.ts +13 -8
- package/dist/types/setup/scenes/types.d.ts +16 -1
- package/dist/types/setup/startup-splash.d.ts +1 -1
- package/dist/types/setup/wizard-overlay.d.ts +11 -7
- package/dist/types/setup/wizard.d.ts +5 -1
- package/dist/types/status-line/component.d.ts +1 -1
- package/dist/types/status-line/context-usage.d.ts +28 -6
- package/dist/types/status-line/host.d.ts +6 -2
- package/dist/types/theme/theme.d.ts +0 -23
- package/dist/types/tools/bash-interactive.d.ts +6 -0
- package/dist/types/tools/bash.d.ts +2 -0
- package/dist/types/tools/default-renderer.d.ts +6 -4
- package/dist/types/tools/irc.d.ts +6 -0
- package/dist/types/tools/json-tree.d.ts +23 -4
- package/dist/types/tools/lsp.d.ts +2 -0
- package/dist/types/tools/mcp.d.ts +6 -5
- package/dist/types/tools/native-view.d.ts +1 -1
- package/dist/types/tools/renderer.d.ts +2 -0
- package/dist/types/tools/streaming-output.d.ts +11 -0
- package/dist/types/tools/task.d.ts +9 -1
- package/dist/types/tools/url-scheme-host.d.ts +17 -0
- package/dist/types/tools/yield.d.ts +1 -1
- package/dist/types/tui.d.ts +7 -2
- package/package.json +10 -14
- package/src/app-keybindings.d.ts +15 -0
- package/src/app-keybindings.ts +15 -0
- package/src/apps/session-picker.ts +7 -0
- package/src/charts/chart-plan.d.ts +9 -7
- package/src/charts/chart-plan.ts +20 -50
- package/src/chat/advisor-message.ts +2 -0
- package/src/chat/assistant-message.d.ts +15 -3
- package/src/chat/assistant-message.ts +137 -19
- package/src/chat/background-tan-message.ts +4 -0
- package/src/chat/bash-execution.d.ts +2 -0
- package/src/chat/bash-execution.ts +6 -0
- package/src/chat/chat-transcript-builder.ts +58 -28
- package/src/chat/compaction-summary-message.ts +2 -1
- package/src/chat/display-preferences.d.ts +2 -0
- package/src/chat/display-preferences.ts +3 -0
- package/src/chat/extension-types.d.ts +31 -0
- package/src/chat/extension-types.ts +34 -0
- package/src/chat/reply-write.d.ts +48 -0
- package/src/chat/reply-write.ts +127 -0
- package/src/chat/table-chart.d.ts +4 -3
- package/src/chat/table-chart.ts +10 -4
- package/src/chat/tool-execution.d.ts +1 -2
- package/src/chat/tool-execution.ts +20 -13
- package/src/chat/transcript-outline.d.ts +7 -0
- package/src/chat/transcript-outline.ts +27 -0
- package/src/chat/transcript-render-helpers.d.ts +2 -0
- package/src/chat/transcript-render-helpers.ts +66 -24
- package/src/chrome/index.ts +1 -0
- package/src/chrome/transcript-notice.d.ts +35 -0
- package/src/chrome/transcript-notice.ts +83 -0
- package/src/chrome/transcript-status.d.ts +20 -8
- package/src/chrome/transcript-status.ts +29 -29
- package/src/components/editor.d.ts +8 -0
- package/src/components/editor.ts +10 -1
- package/src/components/markdown.d.ts +7 -0
- package/src/components/markdown.ts +116 -6
- package/src/hotkeys-markdown.ts +1 -0
- package/src/native/backend.ts +5 -66
- package/src/native/blobs.d.ts +2 -1
- package/src/native/blobs.ts +3 -2
- package/src/native/picker.d.ts +4 -4
- package/src/native/picker.ts +4 -4
- package/src/overlays/advisor-config.ts +1 -10
- package/src/overlays/annotation-overlay.ts +125 -37
- package/src/overlays/annotation-types.ts +24 -0
- package/src/overlays/hook-selector.ts +2 -2
- package/src/overlays/login-dialog.ts +31 -5
- package/src/overlays/mcp-add-wizard.ts +1 -1
- package/src/overlays/model-browser.ts +37 -0
- package/src/overlays/model-hub.ts +1 -7
- package/src/overlays/model-picker.ts +1 -10
- package/src/overlays/oauth-selector.ts +44 -6
- package/src/overlays/plan-review-overlay.ts +13 -2
- package/src/overlays/rewind-selector.ts +29 -12
- package/src/overlays/session-selector.ts +313 -42
- package/src/overlays/usage-dashboard.ts +5 -12
- package/src/prompt/composer.ts +216 -1
- package/src/prompt/custom-editor.ts +6 -1
- package/src/prompt/emoji-autocomplete.ts +0 -2
- package/src/prompt/interactive-context-helpers.ts +29 -4
- package/src/render/extension-links.d.ts +65 -0
- package/src/render/extension-links.ts +214 -0
- package/src/render/hyperlink.d.ts +25 -7
- package/src/render/hyperlink.ts +65 -9
- package/src/render/index.d.ts +1 -0
- package/src/render/index.ts +1 -0
- package/src/setup/scenes/composer.ts +2 -0
- package/src/setup/scenes/glyph.ts +3 -1
- package/src/setup/scenes/model.ts +192 -29
- package/src/setup/scenes/outro.ts +33 -15
- package/src/setup/scenes/sign-in.ts +196 -400
- package/src/setup/scenes/theme.ts +2 -0
- package/src/setup/scenes/types.ts +18 -1
- package/src/setup/startup-splash.ts +8 -7
- package/src/setup/wizard-overlay.ts +164 -35
- package/src/setup/wizard.ts +11 -2
- package/src/status-line/component.ts +4 -10
- package/src/status-line/context-usage.ts +72 -21
- package/src/status-line/host.ts +6 -2
- package/src/terminal.ts +24 -2
- package/src/theme/defaults.json +1 -0
- package/src/theme/loader.ts +1 -1
- package/src/theme/theme.d.ts +0 -23
- package/src/theme/theme.ts +2 -75
- package/src/tools/bash-interactive.d.ts +49 -0
- package/src/tools/bash-interactive.ts +6 -1
- package/src/tools/bash.d.ts +2 -0
- package/src/tools/bash.ts +2 -0
- package/src/tools/default-renderer.d.ts +6 -4
- package/src/tools/default-renderer.ts +9 -6
- package/src/tools/eval.ts +14 -4
- package/src/tools/irc.d.ts +6 -0
- package/src/tools/irc.ts +6 -0
- package/src/tools/job-widget.ts +13 -1
- package/src/tools/json-tree.d.ts +23 -4
- package/src/tools/json-tree.ts +132 -42
- package/src/tools/lsp.d.ts +2 -0
- package/src/tools/lsp.ts +36 -15
- package/src/tools/mcp.d.ts +6 -5
- package/src/tools/mcp.ts +20 -12
- package/src/tools/native-view.d.ts +1 -1
- package/src/tools/native-view.ts +1 -1
- package/src/tools/renderer.d.ts +2 -0
- package/src/tools/renderer.ts +2 -0
- package/src/tools/streaming-output.d.ts +11 -0
- package/src/tools/streaming-output.ts +41 -0
- package/src/tools/task.d.ts +9 -1
- package/src/tools/task.ts +59 -16
- package/src/tools/url-scheme-host.d.ts +17 -0
- package/src/tools/url-scheme-host.ts +21 -0
- package/src/tools/yield.d.ts +1 -1
- package/src/tools/yield.ts +18 -9
- package/src/tui.d.ts +7 -2
- package/src/tui.ts +43 -15
- package/dist/types/theme/defaults/index.d.ts +0 -10289
- package/src/theme/defaults/alabaster.json +0 -103
- package/src/theme/defaults/amethyst.json +0 -106
- package/src/theme/defaults/anthracite.json +0 -103
- package/src/theme/defaults/basalt.json +0 -101
- package/src/theme/defaults/birch.json +0 -105
- package/src/theme/defaults/dark-abyss.json +0 -101
- package/src/theme/defaults/dark-arctic.json +0 -114
- package/src/theme/defaults/dark-aurora.json +0 -105
- package/src/theme/defaults/dark-catppuccin.json +0 -117
- package/src/theme/defaults/dark-cavern.json +0 -101
- package/src/theme/defaults/dark-celestial.json +0 -116
- package/src/theme/defaults/dark-copper.json +0 -105
- package/src/theme/defaults/dark-cosmos.json +0 -100
- package/src/theme/defaults/dark-cyberpunk.json +0 -112
- package/src/theme/defaults/dark-dracula.json +0 -108
- package/src/theme/defaults/dark-eclipse.json +0 -101
- package/src/theme/defaults/dark-ember.json +0 -105
- package/src/theme/defaults/dark-equinox.json +0 -100
- package/src/theme/defaults/dark-forest.json +0 -106
- package/src/theme/defaults/dark-github.json +0 -115
- package/src/theme/defaults/dark-gruvbox.json +0 -122
- package/src/theme/defaults/dark-lavender.json +0 -105
- package/src/theme/defaults/dark-lunar.json +0 -99
- package/src/theme/defaults/dark-midnight.json +0 -105
- package/src/theme/defaults/dark-monochrome.json +0 -104
- package/src/theme/defaults/dark-monokai.json +0 -108
- package/src/theme/defaults/dark-nebula.json +0 -100
- package/src/theme/defaults/dark-neon-noir.json +0 -110
- package/src/theme/defaults/dark-nord.json +0 -108
- package/src/theme/defaults/dark-ocean.json +0 -111
- package/src/theme/defaults/dark-one.json +0 -110
- package/src/theme/defaults/dark-poimandres.json +0 -125
- package/src/theme/defaults/dark-rainforest.json +0 -101
- package/src/theme/defaults/dark-reef.json +0 -101
- package/src/theme/defaults/dark-retro.json +0 -102
- package/src/theme/defaults/dark-rose-pine.json +0 -106
- package/src/theme/defaults/dark-sakura.json +0 -105
- package/src/theme/defaults/dark-slate.json +0 -105
- package/src/theme/defaults/dark-solarized.json +0 -107
- package/src/theme/defaults/dark-solstice.json +0 -100
- package/src/theme/defaults/dark-starfall.json +0 -101
- package/src/theme/defaults/dark-sunset.json +0 -109
- package/src/theme/defaults/dark-swamp.json +0 -100
- package/src/theme/defaults/dark-synthwave.json +0 -113
- package/src/theme/defaults/dark-taiga.json +0 -101
- package/src/theme/defaults/dark-terminal.json +0 -105
- package/src/theme/defaults/dark-tokyo-night.json +0 -111
- package/src/theme/defaults/dark-tundra.json +0 -101
- package/src/theme/defaults/dark-twilight.json +0 -101
- package/src/theme/defaults/dark-volcanic.json +0 -101
- package/src/theme/defaults/graphite.json +0 -102
- package/src/theme/defaults/index.d.ts +0 -10289
- package/src/theme/defaults/index.ts +0 -203
- package/src/theme/defaults/light-arctic.json +0 -117
- package/src/theme/defaults/light-aurora-day.json +0 -101
- package/src/theme/defaults/light-canyon.json +0 -101
- package/src/theme/defaults/light-catppuccin.json +0 -116
- package/src/theme/defaults/light-cirrus.json +0 -100
- package/src/theme/defaults/light-coral.json +0 -105
- package/src/theme/defaults/light-cyberpunk.json +0 -106
- package/src/theme/defaults/light-dawn.json +0 -100
- package/src/theme/defaults/light-dunes.json +0 -101
- package/src/theme/defaults/light-eucalyptus.json +0 -105
- package/src/theme/defaults/light-forest.json +0 -110
- package/src/theme/defaults/light-frost.json +0 -105
- package/src/theme/defaults/light-github.json +0 -125
- package/src/theme/defaults/light-glacier.json +0 -101
- package/src/theme/defaults/light-gruvbox.json +0 -118
- package/src/theme/defaults/light-haze.json +0 -100
- package/src/theme/defaults/light-honeycomb.json +0 -105
- package/src/theme/defaults/light-lagoon.json +0 -101
- package/src/theme/defaults/light-lavender.json +0 -105
- package/src/theme/defaults/light-meadow.json +0 -101
- package/src/theme/defaults/light-mint.json +0 -105
- package/src/theme/defaults/light-monochrome.json +0 -111
- package/src/theme/defaults/light-ocean.json +0 -109
- package/src/theme/defaults/light-one.json +0 -109
- package/src/theme/defaults/light-opal.json +0 -101
- package/src/theme/defaults/light-orchard.json +0 -101
- package/src/theme/defaults/light-paper.json +0 -105
- package/src/theme/defaults/light-poimandres.json +0 -125
- package/src/theme/defaults/light-prism.json +0 -100
- package/src/theme/defaults/light-retro.json +0 -108
- package/src/theme/defaults/light-sand.json +0 -105
- package/src/theme/defaults/light-savanna.json +0 -101
- package/src/theme/defaults/light-solarized.json +0 -112
- package/src/theme/defaults/light-soleil.json +0 -100
- package/src/theme/defaults/light-sunset.json +0 -109
- package/src/theme/defaults/light-synthwave.json +0 -108
- package/src/theme/defaults/light-tokyo-night.json +0 -121
- package/src/theme/defaults/light-wetland.json +0 -101
- package/src/theme/defaults/light-zenith.json +0 -99
- package/src/theme/defaults/limestone.json +0 -104
- package/src/theme/defaults/mahogany.json +0 -107
- package/src/theme/defaults/marble.json +0 -103
- package/src/theme/defaults/obsidian.json +0 -101
- package/src/theme/defaults/onyx.json +0 -101
- package/src/theme/defaults/pearl.json +0 -103
- package/src/theme/defaults/porcelain.json +0 -101
- package/src/theme/defaults/quartz.json +0 -106
- package/src/theme/defaults/sandstone.json +0 -105
- package/src/theme/defaults/titanium.json +0 -100
|
@@ -1,113 +1,67 @@
|
|
|
1
1
|
import type { AuthStorage } from "@linxiraos/pi-ai";
|
|
2
2
|
import { PASTE_CODE_LOGIN_PROVIDERS } from "@linxiraos/pi-ai";
|
|
3
|
-
import
|
|
4
|
-
import
|
|
3
|
+
import { getOAuthProviders } from "@linxiraos/pi-ai/oauth";
|
|
4
|
+
import type { OAuthProvider } from "@linxiraos/pi-ai/oauth/types";
|
|
5
|
+
import type { TspText } from "@linxiraos/pi-wire";
|
|
6
|
+
import { getAgentDbPath } from "@linxiraos/pi-utils";
|
|
7
|
+
import { Container } from "../../tui";
|
|
5
8
|
import { Spacer } from "../../components/spacer";
|
|
6
9
|
import { Text } from "../../components/text";
|
|
7
10
|
import { WizardStep } from "../../components/wizard-step";
|
|
8
|
-
import { Input } from "../../components/input";
|
|
9
|
-
import { formatKeyHint } from "../../app-keybindings";
|
|
10
11
|
import { editorKey } from "../../chrome/keybinding-hints";
|
|
11
|
-
import { matchesKey } from "../../keys";
|
|
12
12
|
import { type SgrMouseEvent } from "../../mouse";
|
|
13
13
|
import { wrapTextWithAnsi } from "../../utils";
|
|
14
|
-
import {
|
|
15
|
-
import { OAuthSelectorComponent } from "../../overlays/oauth-selector";
|
|
14
|
+
import { LoginDialogComponent } from "../../overlays/login-dialog";
|
|
15
|
+
import { type OAuthSelectorSheet, OAuthSelectorComponent } from "../../overlays/oauth-selector";
|
|
16
16
|
import { theme } from "../../theme/theme";
|
|
17
|
-
import { col, node, span
|
|
18
|
-
import type { NativeChild, NativeNode } from "../../native/node";
|
|
17
|
+
import { col, node, span } from "../../native/describe";
|
|
18
|
+
import type { DescribeContext, NativeChild, NativeNode } from "../../native/node";
|
|
19
19
|
import { Memo } from "../../native/memo";
|
|
20
|
-
import
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
get focused(): boolean {
|
|
42
|
-
return this.#input.focused;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
set focused(value: boolean) {
|
|
46
|
-
this.#input.focused = value;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
setUseTerminalCursor(useTerminalCursor: boolean): void {
|
|
50
|
-
this.#input.setUseTerminalCursor(useTerminalCursor);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
render(width: number): readonly string[] {
|
|
54
|
-
return this.#input.render(width);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/** The wrapped field describes itself (`input`, caret while focused); alt+c stays a key here. */
|
|
58
|
-
describe(): NativeNode {
|
|
59
|
-
return this.#native;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
handleInput(data: string): void {
|
|
63
|
-
if (matchesKey(data, "alt+c")) {
|
|
64
|
-
this.#onCopy();
|
|
65
|
-
return;
|
|
66
|
-
}
|
|
67
|
-
this.#input.handleInput(data);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
/** Enhanced-paste delivery targets the focused component's `pasteText`; without it the
|
|
71
|
-
* payload fell back to the detached main editor and never reached this field. */
|
|
72
|
-
pasteText(text: string): void {
|
|
73
|
-
this.#input.pasteText(text);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
invalidate(): void {
|
|
77
|
-
this.#input.invalidate();
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
interface PromptState {
|
|
82
|
-
message: string;
|
|
83
|
-
placeholder?: string;
|
|
84
|
-
input: CopyablePromptInput;
|
|
85
|
-
}
|
|
20
|
+
import {
|
|
21
|
+
SETUP_SHEET_ROLE,
|
|
22
|
+
type SetupScene,
|
|
23
|
+
type SetupSceneController,
|
|
24
|
+
type SetupSceneHost,
|
|
25
|
+
type StyledLine,
|
|
26
|
+
} from "./types";
|
|
27
|
+
|
|
28
|
+
const SCENE_TITLE = "Sign in to your providers";
|
|
29
|
+
/** Login dialog rows kept above a cut on short screens: top border, spacer, first sign-in link row. */
|
|
30
|
+
const DIALOG_HEAD_ROWS = 3;
|
|
31
|
+
const LIST_LEAD = "Pick a provider to sign in — you can connect more than one.";
|
|
32
|
+
/** The provider sheet's subtitle: its title and rows already say "pick a provider". */
|
|
33
|
+
const SHEET_LEAD = "You can connect more than one.";
|
|
34
|
+
|
|
35
|
+
/** The last finished sign-in (`provider` is the display name): shown on the provider sheet (natively) or under the list (ANSI). */
|
|
36
|
+
type SignInOutcome =
|
|
37
|
+
| { readonly kind: "success"; readonly provider: string }
|
|
38
|
+
| { readonly kind: "error"; readonly provider: string; readonly message: string };
|
|
86
39
|
|
|
87
40
|
/**
|
|
88
41
|
* "Sign in" scene: lets the user authenticate one or more model providers via
|
|
89
42
|
* OAuth. It never auto-advances the wizard — the user may sign in to several
|
|
90
|
-
* providers and then
|
|
43
|
+
* providers and then leave the step with Esc.
|
|
44
|
+
*
|
|
45
|
+
* Picking is the provider selector (natively a setup sheet: Skip/Continue on
|
|
46
|
+
* Esc, Sign in on Enter); signing in is the app's {@link LoginDialogComponent},
|
|
47
|
+
* driven like `/login` drives it: natively its own sheet over the setup page,
|
|
48
|
+
* in the cell grid drawn in the wizard body in place of the selector.
|
|
91
49
|
*/
|
|
92
50
|
export class SignInScene implements SetupSceneController {
|
|
93
|
-
readonly title =
|
|
51
|
+
readonly title = SCENE_TITLE;
|
|
94
52
|
get subtitle(): string {
|
|
95
53
|
return `Sign in to one or more providers. Press ${editorKey("tui.select.cancel")} when you're done.`;
|
|
96
54
|
}
|
|
97
55
|
|
|
98
56
|
#authStorage: AuthStorage;
|
|
99
57
|
#selector: OAuthSelectorComponent;
|
|
100
|
-
/**
|
|
101
|
-
#
|
|
102
|
-
#
|
|
103
|
-
|
|
104
|
-
#
|
|
105
|
-
|
|
106
|
-
#
|
|
107
|
-
#promptAbortCleanup: (() => void) | undefined;
|
|
108
|
-
#loginAbort: AbortController | undefined;
|
|
109
|
-
#loggingInProvider: string | undefined;
|
|
110
|
-
#disposed = false;
|
|
58
|
+
/** The login flow on screen; undefined while picking. */
|
|
59
|
+
#dialog: LoginDialogComponent | undefined;
|
|
60
|
+
#outcome: SignInOutcome | undefined;
|
|
61
|
+
/** A sign-in succeeded in this scene: leaving the step reads "Continue". */
|
|
62
|
+
#signedIn = false;
|
|
63
|
+
/** Aborts a running login when the scene goes away. */
|
|
64
|
+
#lifetime = new AbortController();
|
|
111
65
|
#step: WizardStep | undefined;
|
|
112
66
|
#native = new Memo();
|
|
113
67
|
|
|
@@ -116,380 +70,222 @@ export class SignInScene implements SetupSceneController {
|
|
|
116
70
|
constructor(host: SetupSceneHost) {
|
|
117
71
|
this.#host = host;
|
|
118
72
|
this.#authStorage = host.ctx.authStorage;
|
|
119
|
-
this.#selector =
|
|
73
|
+
this.#selector = new OAuthSelectorComponent(
|
|
74
|
+
"login",
|
|
75
|
+
this.#authStorage,
|
|
76
|
+
providerId => {
|
|
77
|
+
void this.#login(providerId);
|
|
78
|
+
},
|
|
79
|
+
() => this.#host.finish(this.#signedIn ? "done" : "skipped"),
|
|
80
|
+
{
|
|
81
|
+
requestRender: () => this.#host.requestRender(),
|
|
82
|
+
disabledProviders: this.#host.ctx.disabledProviders,
|
|
83
|
+
sheet: this.#sheet(),
|
|
84
|
+
},
|
|
85
|
+
);
|
|
120
86
|
}
|
|
121
87
|
|
|
122
88
|
dispose(): void {
|
|
123
|
-
this.#
|
|
89
|
+
this.#lifetime.abort();
|
|
124
90
|
this.#selector.stopValidation();
|
|
125
|
-
this.#
|
|
126
|
-
this.#resolvePrompt("");
|
|
91
|
+
this.#dialog = undefined;
|
|
127
92
|
}
|
|
128
93
|
|
|
129
94
|
invalidate(): void {
|
|
130
95
|
this.#native.clear();
|
|
131
96
|
this.#step?.invalidate();
|
|
132
97
|
this.#selector.invalidate();
|
|
133
|
-
this.#
|
|
98
|
+
this.#dialog?.invalidate();
|
|
134
99
|
}
|
|
135
100
|
|
|
136
101
|
handleInput(data: string): void {
|
|
137
|
-
if (this.#
|
|
138
|
-
|
|
139
|
-
void this.#copyAuthUrl();
|
|
140
|
-
return;
|
|
141
|
-
}
|
|
142
|
-
if (matchesKey(data, "escape") || matchesKey(data, "ctrl+c")) {
|
|
143
|
-
this.#loginAbort?.abort();
|
|
144
|
-
}
|
|
102
|
+
if (this.#dialog) {
|
|
103
|
+
this.#dialog.handleInput(data);
|
|
145
104
|
return;
|
|
146
105
|
}
|
|
147
106
|
this.#selector.handleInput(data);
|
|
148
107
|
}
|
|
149
108
|
|
|
150
|
-
/** Forward mouse to the provider selector;
|
|
109
|
+
/** Forward mouse to the provider selector; the login dialog takes keys only. */
|
|
151
110
|
routeMouse(event: SgrMouseEvent, line: number, col: number): void {
|
|
152
|
-
if (this.#
|
|
111
|
+
if (this.#dialog) return;
|
|
153
112
|
this.#step?.routeMouse(event, line, col);
|
|
154
113
|
}
|
|
155
114
|
|
|
156
115
|
render(width: number, maxLines?: number): readonly string[] {
|
|
116
|
+
const dialog = this.#dialog;
|
|
117
|
+
if (dialog) {
|
|
118
|
+
// Short screens cut the middle: the head keeps the title and the first link row (every
|
|
119
|
+
// wrapped URL row links the full URL), the tail the live step (code field, newest progress).
|
|
120
|
+
const lines = dialog.render(width);
|
|
121
|
+
if (maxLines === undefined || lines.length <= maxLines) return lines;
|
|
122
|
+
const head = maxLines >= DIALOG_HEAD_ROWS * 2 ? DIALOG_HEAD_ROWS : 0;
|
|
123
|
+
return [...lines.slice(0, head), ...lines.slice(lines.length - (maxLines - head))];
|
|
124
|
+
}
|
|
157
125
|
// Hint + blank cost two rows; the wizard subtitle already explains
|
|
158
126
|
// this panel, so on short screens the rows go to the provider list
|
|
159
127
|
// instead (17 = full selector: 4 chrome above, 10 rows, 3 below).
|
|
160
128
|
let intro: Container | undefined;
|
|
161
|
-
if (
|
|
129
|
+
if (maxLines === undefined || maxLines >= 17 + 2) {
|
|
162
130
|
intro = new Container();
|
|
163
|
-
intro.addChild(
|
|
164
|
-
new Text(theme.fg("muted", "Pick a provider to sign in — you can connect more than one."), 0, 0),
|
|
165
|
-
);
|
|
131
|
+
intro.addChild(new Text(theme.fg("muted", LIST_LEAD), 0, 0));
|
|
166
132
|
intro.addChild(new Spacer(1));
|
|
167
133
|
}
|
|
168
|
-
const
|
|
169
|
-
const
|
|
170
|
-
if (this.#authUrl) {
|
|
171
|
-
tail.addChild(
|
|
172
|
-
new Text(theme.fg("accent", `Browser login: ${loginUrlLink(this.#authUrl)} ${loginCopyHint()}`), 0, 0),
|
|
173
|
-
);
|
|
174
|
-
// Keep one URL row above the prompt; repeat the complete wrapped URL
|
|
175
|
-
// below so the input remains visible in the wizard's short viewport.
|
|
176
|
-
if (urlLines[0]) tail.addChild(new Text(urlLines[0], 0, 0));
|
|
177
|
-
if (this.#authLaunchUrl) {
|
|
178
|
-
tail.addChild(
|
|
179
|
-
new Text(theme.fg("dim", `Local shortcut (this machine only): ${this.#authLaunchUrl}`), 0, 0),
|
|
180
|
-
);
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
if (this.#prompt) {
|
|
184
|
-
tail.addChild(new Text(theme.fg("warning", this.#prompt.message), 0, 0));
|
|
185
|
-
if (this.#prompt.placeholder) {
|
|
186
|
-
tail.addChild(new Text(theme.fg("dim", this.#prompt.placeholder), 0, 0));
|
|
187
|
-
}
|
|
188
|
-
tail.addChild(this.#prompt.input);
|
|
189
|
-
}
|
|
190
|
-
if (urlLines.length > 1) {
|
|
191
|
-
for (const line of urlLines) {
|
|
192
|
-
tail.addChild(new Text(line, 0, 0));
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
for (const line of this.#statusLines) {
|
|
134
|
+
const status = new Container();
|
|
135
|
+
for (const line of this.#statusLines()) {
|
|
196
136
|
for (const wrapped of wrapTextWithAnsi(theme.fg(line.color, line.text), width)) {
|
|
197
|
-
|
|
137
|
+
status.addChild(new Text(wrapped, 0, 0));
|
|
198
138
|
}
|
|
199
139
|
}
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
if (this.#loggingInProvider) {
|
|
211
|
-
this.#step.setKind("async");
|
|
212
|
-
this.#step.setHeading(new Text(theme.bold(`Signing in to ${this.#loggingInProvider}`), 0, 0));
|
|
213
|
-
this.#step.setIntro(undefined);
|
|
214
|
-
this.#step.setContent(tail);
|
|
215
|
-
this.#step.setStatus(undefined);
|
|
216
|
-
} else {
|
|
217
|
-
this.#step.setKind("choice");
|
|
218
|
-
this.#step.setHeading(undefined);
|
|
219
|
-
this.#step.setIntro(intro);
|
|
220
|
-
this.#step.setContent(this.#selector);
|
|
221
|
-
this.#step.setStatus(tail);
|
|
222
|
-
}
|
|
140
|
+
this.#step ??= new WizardStep({
|
|
141
|
+
kind: "choice",
|
|
142
|
+
content: this.#selector,
|
|
143
|
+
gap: 0,
|
|
144
|
+
fitContent: budget => {
|
|
145
|
+
if (budget !== undefined) this.#selector.setMaxHeight(budget);
|
|
146
|
+
},
|
|
147
|
+
});
|
|
148
|
+
this.#step.setIntro(intro);
|
|
149
|
+
this.#step.setStatus(status);
|
|
223
150
|
this.#step.setMaxHeight(maxLines);
|
|
224
151
|
return this.#step.render(width);
|
|
225
152
|
}
|
|
226
153
|
|
|
227
154
|
/**
|
|
228
|
-
*
|
|
229
|
-
*
|
|
230
|
-
*
|
|
155
|
+
* Signing in: the login dialog (its own sheet). Picking: the provider
|
|
156
|
+
* selector, which presents the setup sheet where the terminal draws
|
|
157
|
+
* pickers; elsewhere it is an inline card under the lead and the outcome.
|
|
231
158
|
*/
|
|
232
|
-
describe(): NativeNode {
|
|
233
|
-
const
|
|
234
|
-
const
|
|
235
|
-
const
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
{
|
|
246
|
-
spans: [
|
|
247
|
-
span("Browser login: ", "accent"),
|
|
248
|
-
span("Open login URL", "accent link", { href: authUrl }),
|
|
249
|
-
span(` (clipboard copy attempted; ${copyKey} retries)`, "dim"),
|
|
250
|
-
],
|
|
251
|
-
},
|
|
252
|
-
undefined,
|
|
253
|
-
"login",
|
|
254
|
-
),
|
|
255
|
-
node(
|
|
256
|
-
"text",
|
|
257
|
-
{ spans: [span(authUrl, "dim link", { href: authUrl })], wrap: "char", actions: { menu: ["copy"] } },
|
|
258
|
-
undefined,
|
|
259
|
-
"url",
|
|
260
|
-
),
|
|
261
|
-
);
|
|
262
|
-
if (launchUrl) {
|
|
263
|
-
tail.push(
|
|
264
|
-
node(
|
|
265
|
-
"text",
|
|
266
|
-
{
|
|
267
|
-
spans: [
|
|
268
|
-
span("Local shortcut (this machine only): ", "dim"),
|
|
269
|
-
span(launchUrl, "dim link", { href: launchUrl }),
|
|
270
|
-
],
|
|
271
|
-
wrap: "char",
|
|
272
|
-
},
|
|
273
|
-
undefined,
|
|
274
|
-
"launch",
|
|
275
|
-
),
|
|
276
|
-
);
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
if (prompt) {
|
|
280
|
-
const promptChildren: NativeChild[] = [text([span(prompt.message, "warning")])];
|
|
281
|
-
if (prompt.placeholder) promptChildren.push(text([span(prompt.placeholder, "dim")]));
|
|
282
|
-
promptChildren.push(prompt.input);
|
|
283
|
-
tail.push(node("col", {}, promptChildren, "prompt"));
|
|
284
|
-
}
|
|
285
|
-
statusLines.forEach((line, index) => {
|
|
286
|
-
tail.push(node("text", { spans: [span(line.text, line.color)] }, undefined, `status:${index}`));
|
|
159
|
+
describe(cx: DescribeContext): NativeNode {
|
|
160
|
+
const dialog = this.#dialog;
|
|
161
|
+
const sheet = cx.supports("picker");
|
|
162
|
+
const outcome = this.#outcome;
|
|
163
|
+
return this.#native.get([dialog, sheet, outcome, this.#selector], () => {
|
|
164
|
+
if (dialog) return col([dialog]);
|
|
165
|
+
if (sheet) return col([this.#selector]);
|
|
166
|
+
const children: NativeChild[] = [
|
|
167
|
+
node("text", { spans: [span(LIST_LEAD, "muted")] }, undefined, "intro"),
|
|
168
|
+
this.#selector,
|
|
169
|
+
];
|
|
170
|
+
this.#statusLines().forEach((line, index) => {
|
|
171
|
+
children.push(node("text", { spans: [span(line.text, line.color)] }, undefined, `status:${index}`));
|
|
287
172
|
});
|
|
288
|
-
|
|
289
|
-
if (provider) {
|
|
290
|
-
return col(
|
|
291
|
-
[
|
|
292
|
-
node(
|
|
293
|
-
"row",
|
|
294
|
-
{ gap: "sm", align: "center" },
|
|
295
|
-
[node("spinner", {}), text([span(`Signing in to ${provider}`, "strong")])],
|
|
296
|
-
"heading",
|
|
297
|
-
),
|
|
298
|
-
...tail,
|
|
299
|
-
],
|
|
300
|
-
{ gap: "sm", role: "zeta.setup.sign-in", tone: "pending" },
|
|
301
|
-
);
|
|
302
|
-
}
|
|
303
|
-
return col(
|
|
304
|
-
[
|
|
305
|
-
node(
|
|
306
|
-
"text",
|
|
307
|
-
{ spans: [span("Pick a provider to sign in — you can connect more than one.", "muted")] },
|
|
308
|
-
undefined,
|
|
309
|
-
"intro",
|
|
310
|
-
),
|
|
311
|
-
this.#selector,
|
|
312
|
-
...tail,
|
|
313
|
-
],
|
|
314
|
-
{ gap: "sm", role: "zeta.setup.sign-in" },
|
|
315
|
-
);
|
|
173
|
+
return col(children, { gap: "sm", role: "zeta.setup.sign-in" });
|
|
316
174
|
});
|
|
317
175
|
}
|
|
318
176
|
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
)
|
|
177
|
+
/** The provider sheet: the step's copy, the last outcome above the action bar, and Skip until a sign-in succeeded. */
|
|
178
|
+
#sheet(): OAuthSelectorSheet {
|
|
179
|
+
const outcome = this.#outcome;
|
|
180
|
+
let status: TspText | undefined;
|
|
181
|
+
if (outcome?.kind === "success") {
|
|
182
|
+
status = [
|
|
183
|
+
span(`Signed in to ${outcome.provider}.`, "success"),
|
|
184
|
+
span(" Add another provider or continue.", "muted"),
|
|
185
|
+
];
|
|
186
|
+
} else if (outcome?.kind === "error") {
|
|
187
|
+
status = [span(`Couldn't sign in to ${outcome.provider}: ${outcome.message}`, "error")];
|
|
188
|
+
}
|
|
189
|
+
return {
|
|
190
|
+
title: SCENE_TITLE,
|
|
191
|
+
subtitle: SHEET_LEAD,
|
|
192
|
+
role: SETUP_SHEET_ROLE,
|
|
193
|
+
size: "lg",
|
|
194
|
+
...(status ? { status } : {}),
|
|
195
|
+
leave: { id: "skip", label: this.#signedIn ? "Continue" : "Skip" },
|
|
196
|
+
};
|
|
329
197
|
}
|
|
330
198
|
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
const
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
this.#authLaunchUrl = undefined;
|
|
339
|
-
this.#loginAbort = new AbortController();
|
|
340
|
-
this.#host.restoreFocus();
|
|
341
|
-
this.#host.requestRender();
|
|
342
|
-
try {
|
|
343
|
-
await this.#authStorage.oauth.login(providerId as OAuthProvider, {
|
|
344
|
-
signal: this.#loginAbort.signal,
|
|
345
|
-
onBrowserSession: (request, signal) => this.#host.ctx.captureBrowserSession(request, signal),
|
|
346
|
-
onAuth: info => {
|
|
347
|
-
// Store the full authorization URL as the primary copy/display
|
|
348
|
-
// target: it works from any machine, including SSH boxes where
|
|
349
|
-
// the OMP-hosted `launchUrl` would resolve against the user's
|
|
350
|
-
// local browser and fail. The wizard render uses
|
|
351
|
-
// `wrapTextWithAnsi`, so long URLs wrap across lines rather
|
|
352
|
-
// than getting truncated — the RFC 7636 §4.3 PKCE-downgrade
|
|
353
|
-
// bug that motivated `launchUrl` is unreachable through this
|
|
354
|
-
// surface. `launchUrl` is still surfaced as an optional local
|
|
355
|
-
// shortcut for wide-terminal local users.
|
|
356
|
-
this.#authUrl = info.url;
|
|
357
|
-
this.#authLaunchUrl = info.launchUrl && info.launchUrl !== info.url ? info.launchUrl : undefined;
|
|
358
|
-
const statusLines: StyledLine[] = [];
|
|
359
|
-
if (info.instructions) {
|
|
360
|
-
statusLines.push({ text: info.instructions, color: "warning" });
|
|
361
|
-
}
|
|
362
|
-
if (useManualInput) {
|
|
363
|
-
statusLines.push({ text: "Paste the returned code or redirect URL when prompted.", color: "dim" });
|
|
364
|
-
}
|
|
365
|
-
this.#statusLines = statusLines;
|
|
366
|
-
void this.#copyAuthUrl();
|
|
367
|
-
this.#host.ctx.openInBrowser(info.url);
|
|
368
|
-
this.#host.requestRender();
|
|
369
|
-
},
|
|
370
|
-
onPrompt: prompt => this.#showPrompt(prompt),
|
|
371
|
-
onProgress: message => {
|
|
372
|
-
this.#statusLines = [...this.#statusLines, { text: message, color: "dim" }];
|
|
373
|
-
this.#host.requestRender();
|
|
374
|
-
},
|
|
375
|
-
onManualCodeInput: signal =>
|
|
376
|
-
this.#showPrompt({ message: "Paste the authorization code (or full redirect URL):" }, signal),
|
|
377
|
-
});
|
|
378
|
-
// Provider-scoped online refresh so the just-persisted credential re-runs
|
|
379
|
-
// discovery instead of reusing a fresh authoritative cache row (#5780).
|
|
380
|
-
await this.#host.ctx.refreshProvider(providerId);
|
|
381
|
-
if (this.#disposed) return;
|
|
382
|
-
this.#statusLines = [
|
|
383
|
-
{ text: `${theme.status.success} Signed in to ${providerId}`, color: "success" },
|
|
199
|
+
/** The last outcome as status copy under the cell-grid list (and the inline native fallback). */
|
|
200
|
+
#statusLines(): readonly StyledLine[] {
|
|
201
|
+
const outcome = this.#outcome;
|
|
202
|
+
if (!outcome) return [];
|
|
203
|
+
if (outcome.kind === "success") {
|
|
204
|
+
return [
|
|
205
|
+
{ text: `${theme.status.success} Signed in to ${outcome.provider}`, color: "success" },
|
|
384
206
|
{ text: `Credentials saved to ${getAgentDbPath()}`, color: "dim" },
|
|
385
207
|
];
|
|
386
|
-
this.#authUrl = undefined;
|
|
387
|
-
this.#authLaunchUrl = undefined;
|
|
388
|
-
this.#loggingInProvider = undefined;
|
|
389
|
-
this.#loginAbort = undefined;
|
|
390
|
-
this.#selector.stopValidation();
|
|
391
|
-
this.#selector = this.#createSelector();
|
|
392
|
-
this.#host.restoreFocus();
|
|
393
|
-
this.#host.requestRender();
|
|
394
|
-
} catch (error) {
|
|
395
|
-
if (this.#disposed) return;
|
|
396
|
-
if (this.#loginAbort?.signal.aborted) {
|
|
397
|
-
this.#statusLines = [{ text: "Login cancelled.", color: "dim" }];
|
|
398
|
-
this.#authUrl = undefined;
|
|
399
|
-
this.#authLaunchUrl = undefined;
|
|
400
|
-
} else {
|
|
401
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
402
|
-
this.#statusLines = [
|
|
403
|
-
{ text: `Login failed: ${message}`, color: "error" },
|
|
404
|
-
{
|
|
405
|
-
text: `Choose another provider or press ${editorKey("tui.select.cancel")} to continue.`,
|
|
406
|
-
color: "dim",
|
|
407
|
-
},
|
|
408
|
-
];
|
|
409
|
-
this.#authUrl = undefined;
|
|
410
|
-
this.#authLaunchUrl = undefined;
|
|
411
|
-
}
|
|
412
|
-
this.#loggingInProvider = undefined;
|
|
413
|
-
this.#loginAbort = undefined;
|
|
414
|
-
this.#host.restoreFocus();
|
|
415
|
-
this.#host.requestRender();
|
|
416
208
|
}
|
|
209
|
+
return [
|
|
210
|
+
{ text: `Login failed: ${outcome.message}`, color: "error" },
|
|
211
|
+
{
|
|
212
|
+
text: `Choose another provider or press ${editorKey("tui.select.cancel")} to continue.`,
|
|
213
|
+
color: "dim",
|
|
214
|
+
},
|
|
215
|
+
];
|
|
417
216
|
}
|
|
418
217
|
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
if (
|
|
422
|
-
|
|
423
|
-
await this.#host.ctx.copyToClipboard(url);
|
|
424
|
-
} catch {
|
|
425
|
-
// Clipboard integration is best-effort; the full URL remains rendered below.
|
|
426
|
-
}
|
|
427
|
-
this.#host.requestRender();
|
|
218
|
+
#setOutcome(outcome: SignInOutcome | undefined): void {
|
|
219
|
+
this.#outcome = outcome;
|
|
220
|
+
if (outcome?.kind === "success") this.#signedIn = true;
|
|
221
|
+
this.#selector.setSheet(this.#sheet());
|
|
428
222
|
}
|
|
429
223
|
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
if (
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
const input = new Input();
|
|
436
|
-
input.mask = prompt.secret === true;
|
|
437
|
-
const focusInput = new CopyablePromptInput(input, () => {
|
|
438
|
-
void this.#copyAuthUrl();
|
|
439
|
-
});
|
|
440
|
-
const pending = Promise.withResolvers<string>();
|
|
441
|
-
this.#promptResolve = pending.resolve;
|
|
442
|
-
this.#promptReject = pending.reject;
|
|
443
|
-
this.#prompt = { message: prompt.message, placeholder: prompt.placeholder, input: focusInput };
|
|
444
|
-
if (signal) {
|
|
445
|
-
const onAbort = () => {
|
|
446
|
-
if (this.#promptReject !== pending.reject) return;
|
|
447
|
-
this.#rejectPrompt(signal.reason instanceof Error ? signal.reason : new Error("Login input cancelled"));
|
|
448
|
-
};
|
|
449
|
-
signal.addEventListener("abort", onAbort, { once: true });
|
|
450
|
-
this.#promptAbortCleanup = () => signal.removeEventListener("abort", onAbort);
|
|
451
|
-
}
|
|
452
|
-
input.onSubmit = value => {
|
|
453
|
-
this.#resolvePrompt(value);
|
|
454
|
-
};
|
|
455
|
-
input.onEscape = () => {
|
|
456
|
-
this.#loginAbort?.abort();
|
|
457
|
-
this.#resolvePrompt("");
|
|
458
|
-
};
|
|
459
|
-
this.#host.setFocus(focusInput);
|
|
224
|
+
/** Back to the provider list (Esc in the dialog, or the flow settled). */
|
|
225
|
+
#closeDialog(dialog: LoginDialogComponent): void {
|
|
226
|
+
if (this.#dialog !== dialog) return;
|
|
227
|
+
this.#dialog = undefined;
|
|
228
|
+
this.#host.restoreFocus();
|
|
460
229
|
this.#host.requestRender();
|
|
461
|
-
return pending.promise;
|
|
462
|
-
}
|
|
463
|
-
|
|
464
|
-
#resolvePrompt(value: string): void {
|
|
465
|
-
const resolve = this.#promptResolve;
|
|
466
|
-
if (!resolve) return;
|
|
467
|
-
this.#clearPrompt();
|
|
468
|
-
resolve(value);
|
|
469
|
-
}
|
|
470
|
-
|
|
471
|
-
#rejectPrompt(error: Error): void {
|
|
472
|
-
const reject = this.#promptReject;
|
|
473
|
-
if (!reject) return;
|
|
474
|
-
this.#clearPrompt();
|
|
475
|
-
reject(error);
|
|
476
230
|
}
|
|
477
231
|
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
this.#
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
232
|
+
/** One provider's login, driven like `/login` drives the dialog; the outcome lands on the provider sheet. */
|
|
233
|
+
async #login(providerId: string): Promise<void> {
|
|
234
|
+
if (this.#dialog || this.#lifetime.signal.aborted) return;
|
|
235
|
+
const ctx = this.#host.ctx;
|
|
236
|
+
const useManualInput = PASTE_CODE_LOGIN_PROVIDERS.has(providerId);
|
|
237
|
+
const name = getOAuthProviders().find(provider => provider.id === providerId)?.name ?? providerId;
|
|
238
|
+
const dialog = new LoginDialogComponent(
|
|
239
|
+
this.#host,
|
|
240
|
+
providerId,
|
|
241
|
+
// Fires on Esc: back to the list now; the aborted flow's rejection settles below.
|
|
242
|
+
() => this.#closeDialog(dialog),
|
|
243
|
+
url => ctx.openInBrowser(url),
|
|
244
|
+
);
|
|
245
|
+
this.#dialog = dialog;
|
|
246
|
+
this.#setOutcome(undefined);
|
|
247
|
+
this.#host.setFocus(dialog);
|
|
485
248
|
this.#host.requestRender();
|
|
249
|
+
try {
|
|
250
|
+
await this.#authStorage.oauth.login(providerId as OAuthProvider, {
|
|
251
|
+
signal: AbortSignal.any([dialog.signal, this.#lifetime.signal]),
|
|
252
|
+
onBrowserSession: (request, signal) => ctx.captureBrowserSession(request, signal),
|
|
253
|
+
onAuth: info => dialog.showAuth(info.url, info.instructions, info.launchUrl),
|
|
254
|
+
onPrompt: prompt => dialog.showPrompt(prompt),
|
|
255
|
+
onProgress: message => dialog.showProgress(message),
|
|
256
|
+
onManualCodeInput: useManualInput
|
|
257
|
+
? signal =>
|
|
258
|
+
dialog.showManualInput(
|
|
259
|
+
`Paste the authorization code (or full redirect URL), then press ${editorKey("tui.input.submit")}:`,
|
|
260
|
+
signal,
|
|
261
|
+
)
|
|
262
|
+
: undefined,
|
|
263
|
+
});
|
|
264
|
+
// Provider-scoped online refresh so the just-persisted credential re-runs
|
|
265
|
+
// discovery instead of reusing a fresh authoritative cache row (#5780).
|
|
266
|
+
await ctx.refreshProvider(providerId);
|
|
267
|
+
if (this.#lifetime.signal.aborted) return;
|
|
268
|
+
this.#selector.refreshAuth();
|
|
269
|
+
this.#setOutcome({ kind: "success", provider: name });
|
|
270
|
+
} catch (error) {
|
|
271
|
+
// A cancel (Esc in the dialog) is quiet: the list is already back.
|
|
272
|
+
if (this.#lifetime.signal.aborted || dialog.signal.aborted) return;
|
|
273
|
+
this.#setOutcome({
|
|
274
|
+
kind: "error",
|
|
275
|
+
provider: name,
|
|
276
|
+
message: error instanceof Error ? error.message : String(error),
|
|
277
|
+
});
|
|
278
|
+
} finally {
|
|
279
|
+
if (!this.#lifetime.signal.aborted) this.#closeDialog(dialog);
|
|
280
|
+
}
|
|
486
281
|
}
|
|
487
282
|
}
|
|
488
283
|
|
|
489
284
|
/** Onboarding scene for provider sign-in. */
|
|
490
285
|
export const providersSetupScene: SetupScene = {
|
|
491
286
|
id: "providers",
|
|
492
|
-
title:
|
|
287
|
+
title: SCENE_TITLE,
|
|
288
|
+
step: "Sign in",
|
|
493
289
|
minVersion: 1,
|
|
494
290
|
mount: host => new SignInScene(host),
|
|
495
291
|
};
|