UNPKG

@tomisakae/tomibot

Version:

TomiBot - AI Chatbot CLI với Google Genkit. Một chatbot AI thông minh chạy trên command line với giao diện đẹp.

208 lines 7.41 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.MenuComponent = void 0; const inquirer_1 = __importDefault(require("inquirer")); const logger_util_1 = require("../../utils/logger.util"); class MenuComponent { constructor() { this.logger = new logger_util_1.Logger('MenuComponent'); } async showMainMenu() { const menuOptions = [ { name: '💬 Bắt đầu Chat với AI', value: 'chat', description: 'Trò chuyện với TomiBot AI' }, { name: '📊 Xem trạng thái hệ thống', value: 'status', description: 'Kiểm tra trạng thái các component' }, { name: '⚙️ Cấu hình', value: 'config', description: 'Cấu hình API key và settings' }, { name: '❓ Trợ giúp', value: 'help', description: 'Xem hướng dẫn sử dụng' }, { name: '🚪 Thoát', value: 'exit', description: 'Thoát khỏi ứng dụng' } ]; return this.showMenu('🎯 Chọn một tùy chọn:', menuOptions); } async showConfigMenu() { const configOptions = [ { name: '🔑 Cấu hình API Key', value: 'apikey', description: 'Cấu hình GEMINI_API_KEY' }, { name: '🗑️ Xóa lịch sử chat', value: 'clear', description: 'Xóa toàn bộ lịch sử hội thoại' }, { name: '📋 Xem thông tin cấu hình', value: 'info', description: 'Hiển thị thông tin cấu hình hiện tại' }, { name: '🎨 Cài đặt giao diện', value: 'ui', description: 'Tùy chỉnh giao diện và theme' }, { name: '🔙 Quay lại', value: 'back', description: 'Quay lại menu chính' } ]; return this.showMenu('⚙️ Chọn tùy chọn cấu hình:', configOptions); } async showMenu(message, choices, defaultChoice) { try { this.logger.debug('Showing menu', { message, choiceCount: choices.length, defaultChoice }); const promptConfig = { type: 'list', name: 'selection', message, choices: choices.map(choice => ({ name: choice.description ? `${choice.name} - ${choice.description}` : choice.name, value: choice.value, disabled: choice.disabled || false, })), }; if (defaultChoice !== undefined) { promptConfig.default = defaultChoice; } const { selection } = await inquirer_1.default.prompt(promptConfig); this.logger.debug('Menu selection made', { selection }); return selection; } catch (error) { this.logger.error('Error showing menu:', error); throw error; } } async showCheckboxMenu(message, choices, defaultChoices) { try { this.logger.debug('Showing checkbox menu', { message, choiceCount: choices.length, defaultChoices }); const { selections } = await inquirer_1.default.prompt({ type: 'checkbox', name: 'selections', message, choices: choices.map(choice => ({ name: choice.description ? `${choice.name} - ${choice.description}` : choice.name, value: choice.value, checked: defaultChoices?.includes(choice.value) || false, disabled: choice.disabled || false, })), }); this.logger.debug('Checkbox selections made', { selections }); return selections; } catch (error) { this.logger.error('Error showing checkbox menu:', error); throw error; } } async confirmAction(message, defaultValue = false) { try { this.logger.debug('Showing confirmation dialog', { message, defaultValue }); const { confirmed } = await inquirer_1.default.prompt({ type: 'confirm', name: 'confirmed', message, default: defaultValue, }); this.logger.debug('Confirmation result', { confirmed }); return confirmed; } catch (error) { this.logger.error('Error showing confirmation:', error); throw error; } } async promptText(message, defaultValue, validator) { try { this.logger.debug('Showing text prompt', { message, hasDefault: !!defaultValue }); const promptConfig = { type: 'input', name: 'input', message, }; if (defaultValue !== undefined) { promptConfig.default = defaultValue; } if (validator) { promptConfig.validate = validator; } const { input } = await inquirer_1.default.prompt(promptConfig); this.logger.debug('Text input received', { inputLength: input.length }); return input; } catch (error) { this.logger.error('Error showing text prompt:', error); throw error; } } async promptPassword(message, validator) { try { this.logger.debug('Showing password prompt', { message }); const promptConfig = { type: 'password', name: 'password', message, mask: '*', }; if (validator) { promptConfig.validate = validator; } const { password } = await inquirer_1.default.prompt(promptConfig); this.logger.debug('Password input received'); return password; } catch (error) { this.logger.error('Error showing password prompt:', error); throw error; } } render() { return ''; } update(data) { this.logger.debug('Menu component updated', { data }); } async pauseForUser(message = 'Nhấn Enter để tiếp tục...') { await this.promptText(message); } async showLoadingMessage(message, duration = 2000) { console.log(`⏳ ${message}`); await new Promise(resolve => setTimeout(resolve, duration)); } } exports.MenuComponent = MenuComponent; //# sourceMappingURL=menu.component.js.map