@linxiraos/pi-tui 1.4.4 → 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 +208 -207
- package/README.md +34 -34
- package/dist/types/app-keybindings.d.ts +20 -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/context-map.d.ts +15 -0
- package/dist/types/chrome/context-presentation.d.ts +48 -0
- package/dist/types/chrome/context-view-model.d.ts +77 -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/image.d.ts +20 -0
- package/dist/types/components/loader.d.ts +1 -1
- package/dist/types/components/markdown.d.ts +7 -0
- package/dist/types/native/blobs.d.ts +11 -1
- package/dist/types/native/picker.d.ts +4 -4
- package/dist/types/overlays/advisor-config.d.ts +6 -0
- package/dist/types/overlays/agent-hub-projection.d.ts +3 -1
- package/dist/types/overlays/annotation-overlay.d.ts +7 -1
- package/dist/types/overlays/annotation-types.d.ts +28 -0
- package/dist/types/overlays/ask-dialog.d.ts +12 -3
- package/dist/types/overlays/btw-history-panel.d.ts +16 -2
- package/dist/types/overlays/btw-history.d.ts +7 -0
- package/dist/types/overlays/btw-panel.d.ts +2 -0
- package/dist/types/overlays/context-viewer-format.d.ts +42 -0
- package/dist/types/overlays/context-viewer-overview.d.ts +70 -0
- package/dist/types/overlays/context-viewer.d.ts +25 -0
- package/dist/types/overlays/hook-input.d.ts +1 -0
- package/dist/types/overlays/login-dialog.d.ts +5 -1
- package/dist/types/overlays/mcp-add-wizard.d.ts +2 -0
- package/dist/types/overlays/model-browser.d.ts +10 -1
- package/dist/types/overlays/oauth-selector.d.ts +23 -0
- package/dist/types/overlays/pause-screen.d.ts +13 -3
- 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/running-subagent-badge.d.ts +7 -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/prompt/macos-spelling.d.ts +2 -2
- package/dist/types/render/extension-links.d.ts +65 -0
- package/dist/types/render/hyperlink.d.ts +38 -7
- package/dist/types/render/index.d.ts +1 -0
- package/dist/types/render/output-pane.d.ts +1 -1
- package/dist/types/render/render-utils.d.ts +7 -1
- 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 +3 -3
- package/dist/types/status-line/context-usage.d.ts +42 -35
- package/dist/types/status-line/host.d.ts +6 -2
- package/dist/types/terminal-capabilities.d.ts +7 -0
- package/dist/types/theme/symbols.d.ts +1 -1
- package/dist/types/theme/theme.d.ts +0 -23
- package/dist/types/tools/ask.d.ts +4 -0
- 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/edit.d.ts +3 -1
- package/dist/types/tools/fetch.d.ts +1 -0
- package/dist/types/tools/github.d.ts +3 -0
- package/dist/types/tools/grouped-file-output.d.ts +2 -0
- 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 +7 -6
- package/dist/types/tools/native-view.d.ts +1 -1
- package/dist/types/tools/read.d.ts +3 -0
- 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/wait.d.ts +16 -2
- package/dist/types/tools/yield.d.ts +1 -1
- package/dist/types/tui.d.ts +9 -2
- package/dist/types/vim.d.ts +39 -0
- package/package.json +10 -14
- package/src/app-keybindings.d.ts +20 -0
- package/src/app-keybindings.ts +20 -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 +13 -1
- 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/read-tool-group.ts +1 -2
- package/src/chat/reply-write.d.ts +48 -0
- package/src/chat/reply-write.ts +127 -0
- package/src/chat/skill-message.ts +2 -6
- 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/context-map.ts +62 -0
- package/src/chrome/context-presentation.ts +26 -0
- package/src/chrome/context-view-model.ts +73 -0
- package/src/chrome/index.ts +1 -0
- package/src/chrome/transcript-container.ts +89 -59
- 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 +465 -14
- package/src/components/image.d.ts +20 -0
- package/src/components/image.ts +83 -18
- package/src/components/loader.d.ts +1 -1
- package/src/components/loader.ts +1 -1
- package/src/components/markdown.d.ts +7 -0
- package/src/components/markdown.ts +225 -13
- package/src/hotkeys-markdown.ts +2 -0
- package/src/native/backend.ts +5 -66
- package/src/native/blobs.d.ts +11 -1
- package/src/native/blobs.ts +5 -3
- package/src/native/picker.d.ts +4 -4
- package/src/native/picker.ts +4 -4
- package/src/overlays/advisor-config.ts +10 -12
- package/src/overlays/agent-hub-projection.d.ts +3 -1
- package/src/overlays/agent-hub-projection.ts +6 -5
- package/src/overlays/agent-hub.ts +51 -42
- package/src/overlays/annotation-overlay.ts +125 -37
- package/src/overlays/annotation-types.ts +24 -0
- package/src/overlays/ask-dialog.ts +125 -35
- package/src/overlays/btw-history-panel.ts +124 -12
- package/src/overlays/btw-history.ts +11 -0
- package/src/overlays/btw-panel.ts +8 -4
- package/src/overlays/context-viewer-format.ts +145 -0
- package/src/overlays/context-viewer-overview.ts +381 -0
- package/src/overlays/context-viewer.ts +728 -0
- package/src/overlays/hook-input.ts +2 -0
- package/src/overlays/hook-selector.ts +2 -2
- package/src/overlays/login-dialog.ts +31 -5
- package/src/overlays/mcp-add-wizard.ts +6 -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/pause-screen.ts +166 -33
- package/src/overlays/plan-review-overlay.ts +13 -2
- package/src/overlays/rewind-selector.ts +29 -12
- package/src/overlays/running-subagent-badge.ts +12 -1
- package/src/overlays/session-selector.ts +313 -42
- package/src/overlays/settings-defs.ts +1 -0
- package/src/overlays/usage-dashboard.ts +20 -14
- 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/prompt/macos-spelling.ts +24 -15
- package/src/render/extension-links.d.ts +65 -0
- package/src/render/extension-links.ts +214 -0
- package/src/render/hyperlink.d.ts +38 -7
- package/src/render/hyperlink.ts +102 -23
- package/src/render/index.d.ts +1 -0
- package/src/render/index.ts +1 -0
- package/src/render/output-pane.d.ts +1 -1
- package/src/render/output-pane.ts +60 -17
- package/src/render/render-utils.d.ts +7 -1
- package/src/render/render-utils.ts +11 -2
- 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 +194 -392
- 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 +10 -14
- package/src/status-line/context-usage.ts +122 -597
- package/src/status-line/host.ts +6 -2
- package/src/terminal-capabilities.d.ts +7 -0
- package/src/terminal-capabilities.ts +10 -0
- package/src/terminal.ts +24 -2
- package/src/theme/defaults.json +1 -0
- package/src/theme/loader.ts +1 -1
- package/src/theme/symbols.d.ts +1 -1
- package/src/theme/symbols.ts +16 -0
- package/src/theme/theme.d.ts +0 -23
- package/src/theme/theme.ts +2 -75
- package/src/tools/ask.d.ts +4 -0
- package/src/tools/ask.ts +4 -0
- package/src/tools/ast-grep.ts +3 -2
- 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 +7 -23
- package/src/tools/default-renderer.d.ts +6 -4
- package/src/tools/default-renderer.ts +9 -6
- package/src/tools/edit.d.ts +3 -1
- package/src/tools/edit.ts +8 -4
- package/src/tools/eval.ts +14 -4
- package/src/tools/fetch.d.ts +1 -0
- package/src/tools/fetch.ts +1 -0
- package/src/tools/find.ts +3 -10
- package/src/tools/github.d.ts +3 -0
- package/src/tools/github.ts +23 -3
- package/src/tools/glob.ts +4 -3
- package/src/tools/grep.ts +3 -4
- package/src/tools/grouped-file-output.d.ts +2 -0
- package/src/tools/grouped-file-output.ts +8 -2
- 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 +7 -6
- package/src/tools/mcp.ts +41 -15
- package/src/tools/native-view.d.ts +1 -1
- package/src/tools/native-view.ts +3 -3
- package/src/tools/read.d.ts +3 -0
- package/src/tools/read.ts +3 -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/vibe.ts +14 -3
- package/src/tools/wait.d.ts +16 -2
- package/src/tools/wait.ts +16 -2
- package/src/tools/yield.d.ts +1 -1
- package/src/tools/yield.ts +18 -9
- package/src/tui.d.ts +9 -2
- package/src/tui.ts +102 -34
- package/src/vim.d.ts +39 -0
- package/src/vim.ts +313 -22
- 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,107 +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
|
-
return theme.fg("dim", `(clipboard copy attempted; ${formatKeyHint("alt+c")} retries)`);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
class CopyablePromptInput implements Component, Focusable {
|
|
31
|
-
#input: Input;
|
|
32
|
-
#onCopy: () => void;
|
|
33
|
-
readonly #native: NativeNode;
|
|
34
|
-
|
|
35
|
-
constructor(input: Input, onCopy: () => void) {
|
|
36
|
-
this.#input = input;
|
|
37
|
-
this.#onCopy = onCopy;
|
|
38
|
-
this.#native = col([input]);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
get focused(): boolean {
|
|
42
|
-
return this.#input.focused;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
set focused(value: boolean) {
|
|
46
|
-
this.#input.focused = value;
|
|
47
|
-
}
|
|
20
|
+
import {
|
|
21
|
+
SETUP_SHEET_ROLE,
|
|
22
|
+
type SetupScene,
|
|
23
|
+
type SetupSceneController,
|
|
24
|
+
type SetupSceneHost,
|
|
25
|
+
type StyledLine,
|
|
26
|
+
} from "./types";
|
|
48
27
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
}
|
|
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.";
|
|
56
34
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
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
|
-
invalidate(): void {
|
|
71
|
-
this.#input.invalidate();
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
interface PromptState {
|
|
76
|
-
message: string;
|
|
77
|
-
placeholder?: string;
|
|
78
|
-
input: CopyablePromptInput;
|
|
79
|
-
}
|
|
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 };
|
|
80
39
|
|
|
81
40
|
/**
|
|
82
41
|
* "Sign in" scene: lets the user authenticate one or more model providers via
|
|
83
42
|
* OAuth. It never auto-advances the wizard — the user may sign in to several
|
|
84
|
-
* 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.
|
|
85
49
|
*/
|
|
86
50
|
export class SignInScene implements SetupSceneController {
|
|
87
|
-
readonly title =
|
|
51
|
+
readonly title = SCENE_TITLE;
|
|
88
52
|
get subtitle(): string {
|
|
89
53
|
return `Sign in to one or more providers. Press ${editorKey("tui.select.cancel")} when you're done.`;
|
|
90
54
|
}
|
|
91
55
|
|
|
92
56
|
#authStorage: AuthStorage;
|
|
93
57
|
#selector: OAuthSelectorComponent;
|
|
94
|
-
/**
|
|
95
|
-
#
|
|
96
|
-
#
|
|
97
|
-
|
|
98
|
-
#
|
|
99
|
-
|
|
100
|
-
#
|
|
101
|
-
#promptAbortCleanup: (() => void) | undefined;
|
|
102
|
-
#loginAbort: AbortController | undefined;
|
|
103
|
-
#loggingInProvider: string | undefined;
|
|
104
|
-
#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();
|
|
105
65
|
#step: WizardStep | undefined;
|
|
106
66
|
#native = new Memo();
|
|
107
67
|
|
|
@@ -110,380 +70,222 @@ export class SignInScene implements SetupSceneController {
|
|
|
110
70
|
constructor(host: SetupSceneHost) {
|
|
111
71
|
this.#host = host;
|
|
112
72
|
this.#authStorage = host.ctx.authStorage;
|
|
113
|
-
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
|
+
);
|
|
114
86
|
}
|
|
115
87
|
|
|
116
88
|
dispose(): void {
|
|
117
|
-
this.#
|
|
89
|
+
this.#lifetime.abort();
|
|
118
90
|
this.#selector.stopValidation();
|
|
119
|
-
this.#
|
|
120
|
-
this.#resolvePrompt("");
|
|
91
|
+
this.#dialog = undefined;
|
|
121
92
|
}
|
|
122
93
|
|
|
123
94
|
invalidate(): void {
|
|
124
95
|
this.#native.clear();
|
|
125
96
|
this.#step?.invalidate();
|
|
126
97
|
this.#selector.invalidate();
|
|
127
|
-
this.#
|
|
98
|
+
this.#dialog?.invalidate();
|
|
128
99
|
}
|
|
129
100
|
|
|
130
101
|
handleInput(data: string): void {
|
|
131
|
-
if (this.#
|
|
132
|
-
|
|
133
|
-
void this.#copyAuthUrl();
|
|
134
|
-
return;
|
|
135
|
-
}
|
|
136
|
-
if (matchesKey(data, "escape") || matchesKey(data, "ctrl+c")) {
|
|
137
|
-
this.#loginAbort?.abort();
|
|
138
|
-
}
|
|
102
|
+
if (this.#dialog) {
|
|
103
|
+
this.#dialog.handleInput(data);
|
|
139
104
|
return;
|
|
140
105
|
}
|
|
141
106
|
this.#selector.handleInput(data);
|
|
142
107
|
}
|
|
143
108
|
|
|
144
|
-
/** Forward mouse to the provider selector;
|
|
109
|
+
/** Forward mouse to the provider selector; the login dialog takes keys only. */
|
|
145
110
|
routeMouse(event: SgrMouseEvent, line: number, col: number): void {
|
|
146
|
-
if (this.#
|
|
111
|
+
if (this.#dialog) return;
|
|
147
112
|
this.#step?.routeMouse(event, line, col);
|
|
148
113
|
}
|
|
149
114
|
|
|
150
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
|
+
}
|
|
151
125
|
// Hint + blank cost two rows; the wizard subtitle already explains
|
|
152
126
|
// this panel, so on short screens the rows go to the provider list
|
|
153
127
|
// instead (17 = full selector: 4 chrome above, 10 rows, 3 below).
|
|
154
128
|
let intro: Container | undefined;
|
|
155
|
-
if (
|
|
129
|
+
if (maxLines === undefined || maxLines >= 17 + 2) {
|
|
156
130
|
intro = new Container();
|
|
157
|
-
intro.addChild(
|
|
158
|
-
new Text(theme.fg("muted", "Pick a provider to sign in — you can connect more than one."), 0, 0),
|
|
159
|
-
);
|
|
131
|
+
intro.addChild(new Text(theme.fg("muted", LIST_LEAD), 0, 0));
|
|
160
132
|
intro.addChild(new Spacer(1));
|
|
161
133
|
}
|
|
162
|
-
const
|
|
163
|
-
const
|
|
164
|
-
if (this.#authUrl) {
|
|
165
|
-
tail.addChild(
|
|
166
|
-
new Text(theme.fg("accent", `Browser login: ${loginUrlLink(this.#authUrl)} ${loginCopyHint()}`), 0, 0),
|
|
167
|
-
);
|
|
168
|
-
// Keep one URL row above the prompt; repeat the complete wrapped URL
|
|
169
|
-
// below so the input remains visible in the wizard's short viewport.
|
|
170
|
-
if (urlLines[0]) tail.addChild(new Text(urlLines[0], 0, 0));
|
|
171
|
-
if (this.#authLaunchUrl) {
|
|
172
|
-
tail.addChild(
|
|
173
|
-
new Text(theme.fg("dim", `Local shortcut (this machine only): ${this.#authLaunchUrl}`), 0, 0),
|
|
174
|
-
);
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
if (this.#prompt) {
|
|
178
|
-
tail.addChild(new Text(theme.fg("warning", this.#prompt.message), 0, 0));
|
|
179
|
-
if (this.#prompt.placeholder) {
|
|
180
|
-
tail.addChild(new Text(theme.fg("dim", this.#prompt.placeholder), 0, 0));
|
|
181
|
-
}
|
|
182
|
-
tail.addChild(this.#prompt.input);
|
|
183
|
-
}
|
|
184
|
-
if (urlLines.length > 1) {
|
|
185
|
-
for (const line of urlLines) {
|
|
186
|
-
tail.addChild(new Text(line, 0, 0));
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
for (const line of this.#statusLines) {
|
|
134
|
+
const status = new Container();
|
|
135
|
+
for (const line of this.#statusLines()) {
|
|
190
136
|
for (const wrapped of wrapTextWithAnsi(theme.fg(line.color, line.text), width)) {
|
|
191
|
-
|
|
137
|
+
status.addChild(new Text(wrapped, 0, 0));
|
|
192
138
|
}
|
|
193
139
|
}
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
if (this.#loggingInProvider) {
|
|
205
|
-
this.#step.setKind("async");
|
|
206
|
-
this.#step.setHeading(new Text(theme.bold(`Signing in to ${this.#loggingInProvider}`), 0, 0));
|
|
207
|
-
this.#step.setIntro(undefined);
|
|
208
|
-
this.#step.setContent(tail);
|
|
209
|
-
this.#step.setStatus(undefined);
|
|
210
|
-
} else {
|
|
211
|
-
this.#step.setKind("choice");
|
|
212
|
-
this.#step.setHeading(undefined);
|
|
213
|
-
this.#step.setIntro(intro);
|
|
214
|
-
this.#step.setContent(this.#selector);
|
|
215
|
-
this.#step.setStatus(tail);
|
|
216
|
-
}
|
|
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);
|
|
217
150
|
this.#step.setMaxHeight(maxLines);
|
|
218
151
|
return this.#step.render(width);
|
|
219
152
|
}
|
|
220
153
|
|
|
221
154
|
/**
|
|
222
|
-
*
|
|
223
|
-
*
|
|
224
|
-
*
|
|
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.
|
|
225
158
|
*/
|
|
226
|
-
describe(): NativeNode {
|
|
227
|
-
const
|
|
228
|
-
const
|
|
229
|
-
const
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
{
|
|
240
|
-
spans: [
|
|
241
|
-
span("Browser login: ", "accent"),
|
|
242
|
-
span("Open login URL", "accent link", { href: authUrl }),
|
|
243
|
-
span(` (clipboard copy attempted; ${copyKey} retries)`, "dim"),
|
|
244
|
-
],
|
|
245
|
-
},
|
|
246
|
-
undefined,
|
|
247
|
-
"login",
|
|
248
|
-
),
|
|
249
|
-
node(
|
|
250
|
-
"text",
|
|
251
|
-
{ spans: [span(authUrl, "dim link", { href: authUrl })], wrap: "char", actions: { menu: ["copy"] } },
|
|
252
|
-
undefined,
|
|
253
|
-
"url",
|
|
254
|
-
),
|
|
255
|
-
);
|
|
256
|
-
if (launchUrl) {
|
|
257
|
-
tail.push(
|
|
258
|
-
node(
|
|
259
|
-
"text",
|
|
260
|
-
{
|
|
261
|
-
spans: [
|
|
262
|
-
span("Local shortcut (this machine only): ", "dim"),
|
|
263
|
-
span(launchUrl, "dim link", { href: launchUrl }),
|
|
264
|
-
],
|
|
265
|
-
wrap: "char",
|
|
266
|
-
},
|
|
267
|
-
undefined,
|
|
268
|
-
"launch",
|
|
269
|
-
),
|
|
270
|
-
);
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
if (prompt) {
|
|
274
|
-
const promptChildren: NativeChild[] = [text([span(prompt.message, "warning")])];
|
|
275
|
-
if (prompt.placeholder) promptChildren.push(text([span(prompt.placeholder, "dim")]));
|
|
276
|
-
promptChildren.push(prompt.input);
|
|
277
|
-
tail.push(node("col", {}, promptChildren, "prompt"));
|
|
278
|
-
}
|
|
279
|
-
statusLines.forEach((line, index) => {
|
|
280
|
-
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}`));
|
|
281
172
|
});
|
|
282
|
-
|
|
283
|
-
if (provider) {
|
|
284
|
-
return col(
|
|
285
|
-
[
|
|
286
|
-
node(
|
|
287
|
-
"row",
|
|
288
|
-
{ gap: "sm", align: "center" },
|
|
289
|
-
[node("spinner", {}), text([span(`Signing in to ${provider}`, "strong")])],
|
|
290
|
-
"heading",
|
|
291
|
-
),
|
|
292
|
-
...tail,
|
|
293
|
-
],
|
|
294
|
-
{ gap: "sm", role: "zeta.setup.sign-in", tone: "pending" },
|
|
295
|
-
);
|
|
296
|
-
}
|
|
297
|
-
return col(
|
|
298
|
-
[
|
|
299
|
-
node(
|
|
300
|
-
"text",
|
|
301
|
-
{ spans: [span("Pick a provider to sign in — you can connect more than one.", "muted")] },
|
|
302
|
-
undefined,
|
|
303
|
-
"intro",
|
|
304
|
-
),
|
|
305
|
-
this.#selector,
|
|
306
|
-
...tail,
|
|
307
|
-
],
|
|
308
|
-
{ gap: "sm", role: "zeta.setup.sign-in" },
|
|
309
|
-
);
|
|
173
|
+
return col(children, { gap: "sm", role: "zeta.setup.sign-in" });
|
|
310
174
|
});
|
|
311
175
|
}
|
|
312
176
|
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
)
|
|
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
|
+
};
|
|
323
197
|
}
|
|
324
198
|
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
const
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
this.#authLaunchUrl = undefined;
|
|
333
|
-
this.#loginAbort = new AbortController();
|
|
334
|
-
this.#host.restoreFocus();
|
|
335
|
-
this.#host.requestRender();
|
|
336
|
-
try {
|
|
337
|
-
await this.#authStorage.oauth.login(providerId as OAuthProvider, {
|
|
338
|
-
signal: this.#loginAbort.signal,
|
|
339
|
-
onBrowserSession: (request, signal) => this.#host.ctx.captureBrowserSession(request, signal),
|
|
340
|
-
onAuth: info => {
|
|
341
|
-
// Store the full authorization URL as the primary copy/display
|
|
342
|
-
// target: it works from any machine, including SSH boxes where
|
|
343
|
-
// the OMP-hosted `launchUrl` would resolve against the user's
|
|
344
|
-
// local browser and fail. The wizard render uses
|
|
345
|
-
// `wrapTextWithAnsi`, so long URLs wrap across lines rather
|
|
346
|
-
// than getting truncated — the RFC 7636 §4.3 PKCE-downgrade
|
|
347
|
-
// bug that motivated `launchUrl` is unreachable through this
|
|
348
|
-
// surface. `launchUrl` is still surfaced as an optional local
|
|
349
|
-
// shortcut for wide-terminal local users.
|
|
350
|
-
this.#authUrl = info.url;
|
|
351
|
-
this.#authLaunchUrl = info.launchUrl && info.launchUrl !== info.url ? info.launchUrl : undefined;
|
|
352
|
-
const statusLines: StyledLine[] = [];
|
|
353
|
-
if (info.instructions) {
|
|
354
|
-
statusLines.push({ text: info.instructions, color: "warning" });
|
|
355
|
-
}
|
|
356
|
-
if (useManualInput) {
|
|
357
|
-
statusLines.push({ text: "Paste the returned code or redirect URL when prompted.", color: "dim" });
|
|
358
|
-
}
|
|
359
|
-
this.#statusLines = statusLines;
|
|
360
|
-
void this.#copyAuthUrl();
|
|
361
|
-
this.#host.ctx.openInBrowser(info.url);
|
|
362
|
-
this.#host.requestRender();
|
|
363
|
-
},
|
|
364
|
-
onPrompt: prompt => this.#showPrompt(prompt),
|
|
365
|
-
onProgress: message => {
|
|
366
|
-
this.#statusLines = [...this.#statusLines, { text: message, color: "dim" }];
|
|
367
|
-
this.#host.requestRender();
|
|
368
|
-
},
|
|
369
|
-
onManualCodeInput: signal =>
|
|
370
|
-
this.#showPrompt({ message: "Paste the authorization code (or full redirect URL):" }, signal),
|
|
371
|
-
});
|
|
372
|
-
// Provider-scoped online refresh so the just-persisted credential re-runs
|
|
373
|
-
// discovery instead of reusing a fresh authoritative cache row (#5780).
|
|
374
|
-
await this.#host.ctx.refreshProvider(providerId);
|
|
375
|
-
if (this.#disposed) return;
|
|
376
|
-
this.#statusLines = [
|
|
377
|
-
{ 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" },
|
|
378
206
|
{ text: `Credentials saved to ${getAgentDbPath()}`, color: "dim" },
|
|
379
207
|
];
|
|
380
|
-
this.#authUrl = undefined;
|
|
381
|
-
this.#authLaunchUrl = undefined;
|
|
382
|
-
this.#loggingInProvider = undefined;
|
|
383
|
-
this.#loginAbort = undefined;
|
|
384
|
-
this.#selector.stopValidation();
|
|
385
|
-
this.#selector = this.#createSelector();
|
|
386
|
-
this.#host.restoreFocus();
|
|
387
|
-
this.#host.requestRender();
|
|
388
|
-
} catch (error) {
|
|
389
|
-
if (this.#disposed) return;
|
|
390
|
-
if (this.#loginAbort?.signal.aborted) {
|
|
391
|
-
this.#statusLines = [{ text: "Login cancelled.", color: "dim" }];
|
|
392
|
-
this.#authUrl = undefined;
|
|
393
|
-
this.#authLaunchUrl = undefined;
|
|
394
|
-
} else {
|
|
395
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
396
|
-
this.#statusLines = [
|
|
397
|
-
{ text: `Login failed: ${message}`, color: "error" },
|
|
398
|
-
{
|
|
399
|
-
text: `Choose another provider or press ${editorKey("tui.select.cancel")} to continue.`,
|
|
400
|
-
color: "dim",
|
|
401
|
-
},
|
|
402
|
-
];
|
|
403
|
-
this.#authUrl = undefined;
|
|
404
|
-
this.#authLaunchUrl = undefined;
|
|
405
|
-
}
|
|
406
|
-
this.#loggingInProvider = undefined;
|
|
407
|
-
this.#loginAbort = undefined;
|
|
408
|
-
this.#host.restoreFocus();
|
|
409
|
-
this.#host.requestRender();
|
|
410
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
|
+
];
|
|
411
216
|
}
|
|
412
217
|
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
if (
|
|
416
|
-
|
|
417
|
-
await this.#host.ctx.copyToClipboard(url);
|
|
418
|
-
} catch {
|
|
419
|
-
// Clipboard integration is best-effort; the full URL remains rendered below.
|
|
420
|
-
}
|
|
421
|
-
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());
|
|
422
222
|
}
|
|
423
223
|
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
if (
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
const input = new Input();
|
|
430
|
-
input.mask = prompt.secret === true;
|
|
431
|
-
const focusInput = new CopyablePromptInput(input, () => {
|
|
432
|
-
void this.#copyAuthUrl();
|
|
433
|
-
});
|
|
434
|
-
const pending = Promise.withResolvers<string>();
|
|
435
|
-
this.#promptResolve = pending.resolve;
|
|
436
|
-
this.#promptReject = pending.reject;
|
|
437
|
-
this.#prompt = { message: prompt.message, placeholder: prompt.placeholder, input: focusInput };
|
|
438
|
-
if (signal) {
|
|
439
|
-
const onAbort = () => {
|
|
440
|
-
if (this.#promptReject !== pending.reject) return;
|
|
441
|
-
this.#rejectPrompt(signal.reason instanceof Error ? signal.reason : new Error("Login input cancelled"));
|
|
442
|
-
};
|
|
443
|
-
signal.addEventListener("abort", onAbort, { once: true });
|
|
444
|
-
this.#promptAbortCleanup = () => signal.removeEventListener("abort", onAbort);
|
|
445
|
-
}
|
|
446
|
-
input.onSubmit = value => {
|
|
447
|
-
this.#resolvePrompt(value);
|
|
448
|
-
};
|
|
449
|
-
input.onEscape = () => {
|
|
450
|
-
this.#loginAbort?.abort();
|
|
451
|
-
this.#resolvePrompt("");
|
|
452
|
-
};
|
|
453
|
-
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();
|
|
454
229
|
this.#host.requestRender();
|
|
455
|
-
return pending.promise;
|
|
456
|
-
}
|
|
457
|
-
|
|
458
|
-
#resolvePrompt(value: string): void {
|
|
459
|
-
const resolve = this.#promptResolve;
|
|
460
|
-
if (!resolve) return;
|
|
461
|
-
this.#clearPrompt();
|
|
462
|
-
resolve(value);
|
|
463
|
-
}
|
|
464
|
-
|
|
465
|
-
#rejectPrompt(error: Error): void {
|
|
466
|
-
const reject = this.#promptReject;
|
|
467
|
-
if (!reject) return;
|
|
468
|
-
this.#clearPrompt();
|
|
469
|
-
reject(error);
|
|
470
230
|
}
|
|
471
231
|
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
this.#
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
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);
|
|
479
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
|
+
}
|
|
480
281
|
}
|
|
481
282
|
}
|
|
482
283
|
|
|
483
284
|
/** Onboarding scene for provider sign-in. */
|
|
484
285
|
export const providersSetupScene: SetupScene = {
|
|
485
286
|
id: "providers",
|
|
486
|
-
title:
|
|
287
|
+
title: SCENE_TITLE,
|
|
288
|
+
step: "Sign in",
|
|
487
289
|
minVersion: 1,
|
|
488
290
|
mount: host => new SignInScene(host),
|
|
489
291
|
};
|