login slash command

This commit is contained in:
Nate 2025-07-16 00:07:47 -07:00
parent 2fed357453
commit 7f87a24ac0
6 changed files with 68 additions and 12 deletions

View file

@ -251,7 +251,8 @@ async function refreshToken(
* Authenticates using the Continue web flow
*/
export async function login(
useOnboarding: boolean = false
useOnboarding: boolean = false,
onPrompt?: (promptText: string) => Promise<string>
): Promise<AuthConfig> {
// If CONTINUE_API_KEY environment variable exists, use that instead
if (process.env.CONTINUE_API_KEY) {
@ -275,7 +276,9 @@ export async function login(
console.info(chalk.yellow("\nAfter signing in, you'll receive a token."));
// Get token from user
const token = await prompt(chalk.yellow("Paste your sign-in token here: "));
const token = onPrompt
? await onPrompt(chalk.yellow("Paste your sign-in token here: "))
: await prompt(chalk.yellow("Paste your sign-in token here: "));
console.info(chalk.cyan("Verifying token..."));

View file

@ -181,7 +181,6 @@ export async function runNormalFlow(
// Step 2: If user is logged in, look for first assistant in selected org
if (isAuthenticated()) {
try {
console.log(chalk.blue("✓ Loading your first assistant from Continue"));
const result = await initialize(authConfig, undefined);
return { ...result, wasOnboarded: true };
} catch (error) {

View file

@ -10,7 +10,8 @@ import {
export async function handleSlashCommands(
input: string,
assistant: AssistantConfig
assistant: AssistantConfig,
onLoginPrompt?: (promptText: string) => Promise<string>
): Promise<{
output?: string;
exit?: boolean;
@ -37,7 +38,7 @@ export async function handleSlashCommands(
case "exit":
return { exit: true, output: "Goodbye!" };
case "login":
login()
login(false, onLoginPrompt)
.then((config) => {
if (config && isAuthenticatedConfig(config)) {
console.info(

View file

@ -20,7 +20,6 @@ interface TUIChatProps {
resume?: boolean;
}
const TUIChat: React.FC<TUIChatProps> = ({
config: initialAssistant,
model: initialModel,
@ -36,6 +35,29 @@ const TUIChat: React.FC<TUIChatProps> = ({
const [llmApi, setLlmApi] = useState(initialLlmApi);
const [mcpService, setMcpService] = useState(initialMcpService);
// State for login prompt handling
const [loginPrompt, setLoginPrompt] = useState<{
text: string;
resolve: (value: string) => void;
} | null>(null);
const [loginToken, setLoginToken] = useState("");
// Custom login prompt handler for TUI
const handleLoginPrompt = (promptText: string): Promise<string> => {
return new Promise((resolve) => {
setLoginPrompt({ text: promptText, resolve });
});
};
// Handle login token submission
const handleLoginTokenSubmit = (token: string) => {
if (loginPrompt) {
setLoginToken("");
loginPrompt.resolve(token);
setLoginPrompt(null);
}
};
const {
messages,
setMessages,
@ -52,6 +74,7 @@ const TUIChat: React.FC<TUIChatProps> = ({
initialPrompt,
resume,
onShowOrgSelector: () => showOrganizationSelector(),
onLoginPrompt: handleLoginPrompt,
});
const { renderMessage } = useMessageRenderer();
@ -75,7 +98,6 @@ const TUIChat: React.FC<TUIChatProps> = ({
onChatReset: resetChatHistory,
});
return (
<Box flexDirection="column" height="100%">
{/* Chat history - takes up all available space above input */}
@ -93,6 +115,31 @@ const TUIChat: React.FC<TUIChatProps> = ({
</Box>
)}
{/* Login prompt - shows above input when active */}
{loginPrompt && (
<Box
paddingX={1}
borderStyle="round"
borderColor="yellow"
flexDirection="column"
gap={1}
>
<Text color="yellow" bold>
Login Required
</Text>
<Text>{loginPrompt.text}</Text>
<UserInput
onSubmit={handleLoginTokenSubmit}
isWaitingForResponse={false}
inputMode={true}
assistant={assistant}
disabled={false}
placeholder="Enter your token..."
hideNormalUI={true}
/>
</Box>
)}
{/* Organization selector - shows above input when active */}
{showOrgSelector && (
<OrganizationSelector
@ -109,7 +156,7 @@ const TUIChat: React.FC<TUIChatProps> = ({
onInterrupt={handleInterrupt}
assistant={assistant}
onFileAttached={handleFileAttached}
disabled={showOrgSelector}
disabled={showOrgSelector || !!loginPrompt}
/>
<Box marginRight={2} justifyContent="flex-end">
<Text color="gray">● Continue CLI</Text>

View file

@ -15,6 +15,8 @@ interface UserInputProps {
assistant: AssistantConfig;
onFileAttached?: (filePath: string, content: string) => void;
disabled?: boolean;
placeholder?: string;
hideNormalUI?: boolean;
}
const UserInput: React.FC<UserInputProps> = ({
@ -25,6 +27,8 @@ const UserInput: React.FC<UserInputProps> = ({
assistant,
onFileAttached,
disabled = false,
placeholder,
hideNormalUI = false,
}) => {
const [textBuffer] = useState(() => new TextBuffer());
const [inputHistory] = useState(() => new InputHistory());
@ -378,7 +382,7 @@ const UserInput: React.FC<UserInputProps> = ({
});
const renderInputText = () => {
const placeholderText = "Ask anything, @ for context, / for slash commands";
const placeholderText = placeholder || "Ask anything, @ for context, / for slash commands";
if (inputText.length === 0) {
return (
<>
@ -466,7 +470,7 @@ const UserInput: React.FC<UserInputProps> = ({
</Box>
{/* Slash command UI */}
{showSlashCommands && inputMode && (
{showSlashCommands && inputMode && !hideNormalUI && (
<SlashCommandUI
assistant={assistant}
filter={slashCommandFilter}
@ -476,7 +480,7 @@ const UserInput: React.FC<UserInputProps> = ({
)}
{/* File search UI */}
{showFileSearch && inputMode && (
{showFileSearch && inputMode && !hideNormalUI && (
<FileSearchUI
filter={fileSearchFilter}
selectedIndex={selectedFileIndex}

View file

@ -22,6 +22,7 @@ interface UseChatProps {
initialPrompt?: string;
resume?: boolean;
onShowOrgSelector: () => void;
onLoginPrompt?: (promptText: string) => Promise<string>;
}
export function useChat({
@ -31,6 +32,7 @@ export function useChat({
initialPrompt,
resume,
onShowOrgSelector,
onLoginPrompt,
}: UseChatProps) {
const { exit } = useApp();
@ -94,7 +96,7 @@ export function useChat({
}
// Handle slash commands
const commandResult = await handleSlashCommands(message, assistant);
const commandResult = await handleSlashCommands(message, assistant, onLoginPrompt);
if (commandResult) {
if (commandResult.exit) {
exit();