UNPKG

askme-cli

Version:

askme-cli MCP server that collects user's next plan or confirmation through terminal window

48 lines 4.26 kB
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; import { useState } from 'react'; import { Box, Text, useApp, useStdin, useInput } from 'ink'; import { useExitProtection } from '../hooks/useExitProtection.js'; import { sendAskMeToSocket } from '../../shared/utils/socket.js'; import { MultiLineTextInput } from './MultiLineTextInput.js'; import { HelpPanel } from './HelpPanel.js'; import { SimpleMarkdown } from './SimpleMarkdown.js'; export const AskMeApp = ({ message = "Please enter your next plan or confirm:", socketPath = null }) => { const [askMe, setAskMe] = useState(''); const [images, setImages] = useState([]); const [isSubmitted, setIsSubmitted] = useState(false); const [showHelp, setShowHelp] = useState(false); const [isProcessingPaste, setIsProcessingPaste] = useState(false); const { exit } = useApp(); const { isRawModeSupported } = useStdin(); useExitProtection(); // Handle ESC key to hide help panel useInput((input, key) => { if (key.escape && showHelp) { setShowHelp(false); setAskMe(''); // Clear ask me to prevent re-showing help } }); const handleSubmit = async (value, images) => { if (socketPath) { await sendAskMeToSocket(socketPath, value, images); } setIsSubmitted(true); exit(); }; if (isSubmitted) { return (_jsx(Box, { flexDirection: "column", padding: 1, children: _jsx(Text, { color: "green", children: "\u2705 Successfully submitted!" }) })); } if (!isRawModeSupported) { return (_jsxs(Box, { flexDirection: "column", padding: 1, children: [_jsx(Box, { marginBottom: 1, children: _jsx(Text, { color: "cyan", bold: true, children: "\uD83D\uDCCB ASKME-CLI User Confirmation" }) }), _jsx(Box, { marginBottom: 1, children: _jsx(SimpleMarkdown, { children: message }) }), _jsxs(Box, { flexDirection: "column", borderStyle: "round", borderColor: "red", padding: 1, children: [_jsx(Text, { color: "red", children: "\u26A0\uFE0F TTY mode not supported, cannot receive keyboard input" }), _jsx(Text, { color: "yellow", children: "Please run this program in a real terminal" }), _jsx(Text, { color: "gray", children: "Or use the readline version of user confirmation collector" })] }), _jsx(Box, { marginTop: 1, children: _jsx(Text, { color: "gray", dimColor: true, children: "Press Ctrl+C to exit" }) })] })); } if (showHelp) { return (_jsxs(Box, { flexDirection: "column", padding: 1, children: [_jsx(HelpPanel, { visible: true }), _jsx(Box, { justifyContent: "center", marginTop: 1, children: _jsx(Text, { color: "gray", children: "Press ESC to exit help" }) })] })); } return (_jsxs(Box, { flexDirection: "column", padding: 1, children: [_jsx(Box, { marginBottom: 1, children: _jsx(Text, { color: "cyan", bold: true, children: "Ask User Confirmation" }) }), _jsx(Box, { marginBottom: 2, children: _jsx(SimpleMarkdown, { children: message }) }), _jsx(Box, { flexDirection: "column", borderStyle: "round", borderColor: "blue", padding: 1, children: _jsx(MultiLineTextInput, { value: askMe, onChange: (newValue) => { setAskMe(newValue); if (newValue.trim() === '/help') { setShowHelp(true); } }, onSubmit: handleSubmit, placeholder: "Type your plan or confirmation here...", images: images, onImagesChange: setImages, onProcessingStateChange: setIsProcessingPaste }) }), _jsxs(Box, { marginLeft: 1, children: [!askMe.trim() && (_jsx(Text, { color: "cyan", dimColor: true, children: "/help get help" })), askMe.trim() && (_jsx(Text, { color: "gray", children: "\u2022 Double Enter to submit" }))] }), images.length > 0 && (_jsx(Box, { marginTop: 1, marginLeft: 2, flexDirection: "column", children: images.map((image) => (_jsxs(Text, { color: "green", children: ["\u2022 ", image.placeholder, " (", Math.round(image.size / 1024), "KB, ", image.mimeType, ")"] }, image.id))) })), isProcessingPaste && (_jsx(Box, { marginTop: 1, marginLeft: 2, children: _jsx(Text, { color: "yellow", children: "\u23F3 Processing..." }) })), _jsx(HelpPanel, { visible: showHelp })] })); }; //# sourceMappingURL=AskMeApp.js.map