From d649e9fcfcccb8e0ba6e65579f4da5410d386704 Mon Sep 17 00:00:00 2001 From: Nate Date: Wed, 16 Jul 2025 01:22:27 -0700 Subject: [PATCH] Add auto-reload functionality after login slash command --- src/slashCommands.ts | 10 ++++++++-- src/ui/TUIChat.tsx | 37 ++++++++++++++++++++++++++++++++++++- src/ui/hooks/useChat.ts | 4 +++- 3 files changed, 47 insertions(+), 4 deletions(-) diff --git a/src/slashCommands.ts b/src/slashCommands.ts index e9c7b5c26..475029f11 100644 --- a/src/slashCommands.ts +++ b/src/slashCommands.ts @@ -11,7 +11,8 @@ import { export async function handleSlashCommands( input: string, assistant: AssistantConfig, - onLoginPrompt?: (promptText: string) => Promise + onLoginPrompt?: (promptText: string) => Promise, + onReload?: () => Promise ): Promise<{ output?: string; exit?: boolean; @@ -41,7 +42,7 @@ export async function handleSlashCommands( return { exit: true, output: "Goodbye!" }; case "login": login(false, onLoginPrompt) - .then((config) => { + .then(async (config) => { if (config && isAuthenticatedConfig(config)) { console.info( chalk.green( @@ -51,6 +52,11 @@ export async function handleSlashCommands( } else { console.info(chalk.green(`\nLogged in successfully`)); } + + // Reload everything after successful login + if (onReload) { + await onReload(); + } }) .catch((error) => { console.error(chalk.red(`\nLogin failed: ${error.message}`)); diff --git a/src/ui/TUIChat.tsx b/src/ui/TUIChat.tsx index 457b24910..8602b29b6 100644 --- a/src/ui/TUIChat.tsx +++ b/src/ui/TUIChat.tsx @@ -2,6 +2,9 @@ import { AssistantUnrolled } from "@continuedev/config-yaml"; import { BaseLlmApi } from "@continuedev/openai-adapters"; import { Box, Text } from "ink"; import React, { useState } from "react"; +import { loadAuthConfig } from "../auth/workos.js"; +import { initialize } from "../config.js"; +import { introMessage } from "../intro.js"; import { MCPService } from "../mcp.js"; import { useChat } from "./hooks/useChat.js"; import { useMessageRenderer } from "./hooks/useMessageRenderer.js"; @@ -58,6 +61,37 @@ const TUIChat: React.FC = ({ } }; + // Reload function for after login + const handleReload = async () => { + try { + // Reload auth config and reinitialize + const authConfig = loadAuthConfig(); + const { + config: newAssistant, + llmApi: newLlmApi, + model: newModel, + mcpService: newMcpService, + } = await initialize(authConfig, configPath); + + // Update all the state + setAssistant(newAssistant); + setModel(newModel); + setLlmApi(newLlmApi); + setMcpService(newMcpService); + + // Reset chat history + resetChatHistory(); + + // Clear the screen completely + process.stdout.write("\x1b[2J\x1b[H"); + + // Show the new intro message + introMessage(newAssistant, newModel, newMcpService); + } catch (error: any) { + console.error(`Failed to reload after login: ${error.message}`); + } + }; + const { messages, setMessages, @@ -75,6 +109,7 @@ const TUIChat: React.FC = ({ resume, onShowOrgSelector: () => showOrganizationSelector(), onLoginPrompt: handleLoginPrompt, + onReload: handleReload, }); const { renderMessage } = useMessageRenderer(); @@ -166,4 +201,4 @@ const TUIChat: React.FC = ({ ); }; -export default TUIChat; +export default TUIChat; \ No newline at end of file diff --git a/src/ui/hooks/useChat.ts b/src/ui/hooks/useChat.ts index 5bb0a4bcf..5f7f8cb63 100644 --- a/src/ui/hooks/useChat.ts +++ b/src/ui/hooks/useChat.ts @@ -23,6 +23,7 @@ interface UseChatProps { resume?: boolean; onShowOrgSelector: () => void; onLoginPrompt?: (promptText: string) => Promise; + onReload?: () => Promise; } export function useChat({ @@ -33,6 +34,7 @@ export function useChat({ resume, onShowOrgSelector, onLoginPrompt, + onReload, }: UseChatProps) { const { exit } = useApp(); @@ -96,7 +98,7 @@ export function useChat({ } // Handle slash commands - const commandResult = await handleSlashCommands(message, assistant, onLoginPrompt); + const commandResult = await handleSlashCommands(message, assistant, onLoginPrompt, onReload); if (commandResult) { if (commandResult.exit) { exit();