capsule-ai-cli
Version:
The AI Model Orchestrator - Intelligent multi-model workflows with device-locked licensing
110 lines • 4.97 kB
JavaScript
import React, { useState } from 'react';
import { Box, Text, useInput } from 'ink';
import SelectInput from 'ink-select-input';
import chalk from 'chalk';
export const ChatDeleter = ({ contexts, onDelete, onClose }) => {
const [confirmingId, setConfirmingId] = useState(null);
const [confirmingDeleteAll, setConfirmingDeleteAll] = useState(false);
useInput((input, key) => {
if (key.escape) {
if (confirmingId) {
setConfirmingId(null);
}
else if (confirmingDeleteAll) {
setConfirmingDeleteAll(false);
}
else {
onClose();
}
}
});
const formatDate = (date) => {
const now = new Date();
const diff = now.getTime() - date.getTime();
const days = Math.floor(diff / (1000 * 60 * 60 * 24));
const hours = Math.floor(diff / (1000 * 60 * 60));
const minutes = Math.floor(diff / (1000 * 60));
if (days > 0)
return `${days}d ago`;
if (hours > 0)
return `${hours}h ago`;
if (minutes > 0)
return `${minutes}m ago`;
return 'just now';
};
if (confirmingDeleteAll) {
const confirmItems = [
{ label: chalk.red('✗ Yes, delete ALL chats'), value: 'delete-all' },
{ label: chalk.green('✓ No, keep them'), value: 'cancel' }
];
const handleConfirm = (item) => {
if (item.value === 'delete-all') {
contexts.forEach(ctx => onDelete(ctx.id));
}
setConfirmingDeleteAll(false);
onClose();
};
return (React.createElement(Box, { flexDirection: "column", borderStyle: "single", borderColor: "red", paddingX: 1 },
React.createElement(Box, { marginBottom: 1 },
React.createElement(Text, { color: "red" }, "\u26A0\uFE0F Confirm Delete ALL")),
React.createElement(Box, { marginBottom: 1 },
React.createElement(Text, null,
"Delete ALL ",
contexts.length,
" previous chats?")),
React.createElement(Box, { marginBottom: 1 },
React.createElement(Text, { dimColor: true }, "This action cannot be undone and will delete all chat history.")),
React.createElement(SelectInput, { items: confirmItems, onSelect: handleConfirm })));
}
if (confirmingId) {
const context = contexts.find(ctx => ctx.id === confirmingId);
const confirmItems = [
{ label: chalk.red('✗ Yes, delete this chat'), value: 'delete' },
{ label: chalk.green('✓ No, keep it'), value: 'cancel' }
];
const handleConfirm = (item) => {
if (item.value === 'delete') {
onDelete(confirmingId);
}
setConfirmingId(null);
};
return (React.createElement(Box, { flexDirection: "column", borderStyle: "single", borderColor: "red", paddingX: 1 },
React.createElement(Box, { marginBottom: 1 },
React.createElement(Text, { color: "red" }, "\u26A0\uFE0F Confirm Deletion")),
React.createElement(Box, { marginBottom: 1 },
React.createElement(Text, null,
"Delete chat from ",
formatDate(context.created),
" (",
context.messageCount,
" messages)?")),
React.createElement(Box, { marginBottom: 1 },
React.createElement(Text, { dimColor: true }, "This action cannot be undone.")),
React.createElement(SelectInput, { items: confirmItems, onSelect: handleConfirm })));
}
const items = [
...contexts.map(ctx => ({
label: `${formatDate(ctx.created)} - ${ctx.messageCount} messages`,
value: ctx.id
})),
{ label: chalk.red('🗑️ Delete ALL chats'), value: 'DELETE_ALL' }
];
const handleSelect = (item) => {
if (item.value === 'DELETE_ALL') {
setConfirmingDeleteAll(true);
}
else {
setConfirmingId(item.value);
}
};
return (React.createElement(Box, { flexDirection: "column", borderStyle: "single", borderColor: "red", paddingX: 1 },
React.createElement(Box, { marginBottom: 1 },
React.createElement(Text, { color: "red" }, "\uD83D\uDDD1\uFE0F Delete Chat")),
React.createElement(Box, null,
React.createElement(Text, { dimColor: true }, "Select a chat to delete:")),
React.createElement(Box, { marginTop: 1, flexDirection: "column" },
React.createElement(SelectInput, { items: items, onSelect: handleSelect })),
React.createElement(Box, { marginTop: 1 },
React.createElement(Text, { dimColor: true }, "Press ESC to cancel"))));
};
//# sourceMappingURL=ChatDeleter.js.map