automagik-cli
Version:
Automagik CLI - A powerful command-line interface for interacting with Automagik Hive multi-agent AI systems
36 lines (35 loc) • 2.5 kB
JavaScript
import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
import { useState, useCallback, useEffect } from 'react';
import { Box, Text } from 'ink';
import TextInput from 'ink-text-input';
export const LibraryInputPrompt = ({ onSubmit, disabled = false, placeholder = 'Type your message...', }) => {
const [input, setInput] = useState('');
const [isMultiline, setIsMultiline] = useState(false);
// Auto-detect multiline content
useEffect(() => {
setIsMultiline(input.includes('\n') || input.length > 100);
}, [input]);
const handleSubmit = useCallback((value) => {
if (value.trim() && !disabled) {
onSubmit(value.trim());
setInput('');
setIsMultiline(false);
}
}, [onSubmit, disabled]);
const handleChange = useCallback((value) => {
setInput(value);
}, []);
// Handle paste events - automatically enable multiline for large content
const handleKeyPress = useCallback((value) => {
// This is a workaround for detecting large paste operations
if (value.length > input.length + 50) {
setIsMultiline(true);
}
}, [input.length]);
const lines = input.split('\n');
const displayLines = lines.slice(0, 8); // Max 8 lines visible
if (isMultiline && lines.length > 1) {
return (_jsxs(Box, { flexDirection: "column", marginY: 1, children: [_jsxs(Box, { flexDirection: "column", borderStyle: "round", borderColor: "cyan", paddingX: 1, children: [_jsxs(Text, { color: "cyan", children: ["Multiline input (", lines.length, " lines, ", input.length, " chars)"] }), displayLines.map((line, index) => (_jsx(Text, { children: line || ' ' }, index))), lines.length > 8 && (_jsxs(Text, { color: "gray", children: ["... ", lines.length - 8, " more lines"] }))] }), _jsx(Box, { marginTop: 1, children: _jsx(Text, { color: "gray", children: "Paste your content and press Ctrl+Enter to send, or type normally" }) })] }));
}
return (_jsxs(Box, { flexDirection: "column", marginY: 1, children: [_jsxs(Box, { children: [_jsx(Text, { color: "cyan", children: '> ' }), _jsx(TextInput, { value: input, placeholder: placeholder, onChange: handleChange, onSubmit: handleSubmit, focus: !disabled, showCursor: !disabled, highlightPastedText: true })] }), !disabled && (_jsx(Box, { marginTop: 1, children: _jsx(Text, { color: "gray", children: "Type your message \u2022 Enter to send \u2022 Large content becomes multiline automatically" }) }))] }));
};