@bestdefense/bd-agent
Version:
An AI-powered coding assistant CLI that connects to AWS Bedrock
68 lines • 2.58 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getMultilineInput = getMultilineInput;
exports.detectMultilineIntent = detectMultilineIntent;
const readline_1 = __importDefault(require("readline"));
const chalk_1 = __importDefault(require("chalk"));
async function getMultilineInput(prompt) {
console.log(chalk_1.default.green(prompt));
console.log(chalk_1.default.gray('(Press Ctrl+D or type "EOF" on a new line to finish)'));
const rl = readline_1.default.createInterface({
input: process.stdin,
output: process.stdout,
terminal: true
});
const lines = [];
let isMultiline = false;
return new Promise((resolve) => {
rl.on('line', (line) => {
// Check for EOF marker
if (line.trim() === 'EOF') {
rl.close();
return;
}
// Detect if this might be multiline content
if (!isMultiline && (line.includes('```') || // Code blocks
line.endsWith('\\') || // Explicit line continuation
line.endsWith('{') || // Opening braces
line.endsWith('[') || // Opening brackets
line.trim() === '' // Empty line after content
)) {
isMultiline = true;
}
lines.push(line);
// If not in multiline mode and got a complete line, close
if (!isMultiline && lines.length === 1) {
rl.close();
}
});
rl.on('close', () => {
resolve(lines.join('\n'));
});
// Handle Ctrl+D
rl.on('SIGINT', () => {
console.log(chalk_1.default.yellow('\nInput cancelled.'));
process.exit(0);
});
process.stdin.on('keypress', (str, key) => {
if (key && key.ctrl && key.name === 'd') {
rl.close();
}
});
});
}
function detectMultilineIntent(input) {
// Patterns that suggest multiline input
const multilinePatterns = [
/```/, // Code blocks
/\\$/, // Line continuation
/[{[]$/, // Opening braces/brackets at end
/^(class|function|def|interface|type)\s+/i, // Code definitions
/^(import|from|export)\s+/i, // Import statements
];
return multilinePatterns.some(pattern => pattern.test(input));
}
//# sourceMappingURL=multi-line-input.js.map