Add auto-reload functionality after login slash command
This commit is contained in:
parent
64b02bf8c9
commit
d649e9fcfc
3 changed files with 47 additions and 4 deletions
|
|
@ -11,7 +11,8 @@ import {
|
|||
export async function handleSlashCommands(
|
||||
input: string,
|
||||
assistant: AssistantConfig,
|
||||
onLoginPrompt?: (promptText: string) => Promise<string>
|
||||
onLoginPrompt?: (promptText: string) => Promise<string>,
|
||||
onReload?: () => Promise<void>
|
||||
): 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}`));
|
||||
|
|
|
|||
|
|
@ -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<TUIChatProps> = ({
|
|||
}
|
||||
};
|
||||
|
||||
// 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<TUIChatProps> = ({
|
|||
resume,
|
||||
onShowOrgSelector: () => showOrganizationSelector(),
|
||||
onLoginPrompt: handleLoginPrompt,
|
||||
onReload: handleReload,
|
||||
});
|
||||
|
||||
const { renderMessage } = useMessageRenderer();
|
||||
|
|
@ -166,4 +201,4 @@ const TUIChat: React.FC<TUIChatProps> = ({
|
|||
);
|
||||
};
|
||||
|
||||
export default TUIChat;
|
||||
export default TUIChat;
|
||||
|
|
@ -23,6 +23,7 @@ interface UseChatProps {
|
|||
resume?: boolean;
|
||||
onShowOrgSelector: () => void;
|
||||
onLoginPrompt?: (promptText: string) => Promise<string>;
|
||||
onReload?: () => Promise<void>;
|
||||
}
|
||||
|
||||
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();
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue