UNPKG

@graphteon/juricode

Version:

We are forging the future with lines of digital steel

67 lines 4.85 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const jsx_runtime_1 = require("react/jsx-runtime"); const react_1 = require("react"); const ink_1 = require("ink"); const open_hands_1 = __importDefault(require("../api/open-hands")); const TasksTUI = ({ onBack, onSelectTask }) => { const [tasks, setTasks] = (0, react_1.useState)([]); const [selectedIndex, setSelectedIndex] = (0, react_1.useState)(0); const [loading, setLoading] = (0, react_1.useState)(true); const [error, setError] = (0, react_1.useState)(null); const { exit } = (0, ink_1.useApp)(); (0, react_1.useEffect)(() => { const fetchTasks = async () => { try { setLoading(true); const userTasks = await open_hands_1.default.getUserConversations(); setTasks(userTasks); setError(null); } catch (err) { setError(err instanceof Error ? err.message : 'Failed to fetch tasks'); } finally { setLoading(false); } }; fetchTasks(); }, []); (0, ink_1.useInput)((input, key) => { if (key.escape) { onBack(); return; } if (loading) return; if (key.upArrow && selectedIndex > 0) { setSelectedIndex(selectedIndex - 1); } if (key.downArrow && selectedIndex < tasks.length - 1) { setSelectedIndex(selectedIndex + 1); } if (key.return && tasks.length > 0) { onSelectTask(tasks[selectedIndex].conversation_id); } if (input === 'q') { exit(); } }); const getStatusColor = (status) => { switch (status.toLowerCase()) { case 'running': return 'green'; case 'stopped': return 'red'; case 'finished': return 'blue'; default: return 'yellow'; } }; const formatDate = (dateString) => { return new Date(dateString).toLocaleDateString(); }; return ((0, jsx_runtime_1.jsxs)(ink_1.Box, { flexDirection: "column", height: "100%", children: [(0, jsx_runtime_1.jsx)(ink_1.Box, { borderStyle: "single", borderColor: "blue", paddingX: 1, children: (0, jsx_runtime_1.jsx)(ink_1.Text, { color: "blue", bold: true, children: "\uD83D\uDCCB All Tasks" }) }), (0, jsx_runtime_1.jsx)(ink_1.Box, { flexDirection: "column", flexGrow: 1, paddingX: 1, paddingY: 1, children: loading ? ((0, jsx_runtime_1.jsx)(ink_1.Box, { justifyContent: "center", alignItems: "center", height: "100%", children: (0, jsx_runtime_1.jsx)(ink_1.Text, { color: "yellow", children: "\u23F3 Loading tasks..." }) })) : error ? ((0, jsx_runtime_1.jsx)(ink_1.Box, { justifyContent: "center", alignItems: "center", height: "100%", children: (0, jsx_runtime_1.jsxs)(ink_1.Text, { color: "red", children: ["\u274C Error: ", error] }) })) : tasks.length === 0 ? ((0, jsx_runtime_1.jsx)(ink_1.Box, { justifyContent: "center", alignItems: "center", height: "100%", children: (0, jsx_runtime_1.jsx)(ink_1.Text, { color: "gray", children: "No tasks found. Create a new task to get started!" }) })) : (tasks.map((task, index) => ((0, jsx_runtime_1.jsx)(ink_1.Box, { marginBottom: 1, children: (0, jsx_runtime_1.jsx)(ink_1.Box, { borderStyle: "single", borderColor: index === selectedIndex ? 'green' : 'gray', paddingX: 1, paddingY: 0, children: (0, jsx_runtime_1.jsxs)(ink_1.Box, { flexDirection: "column", children: [(0, jsx_runtime_1.jsx)(ink_1.Box, { children: (0, jsx_runtime_1.jsxs)(ink_1.Text, { color: index === selectedIndex ? 'green' : 'white', bold: true, children: [index === selectedIndex ? '▶ ' : ' ', task.title || 'Untitled Task'] }) }), (0, jsx_runtime_1.jsxs)(ink_1.Box, { marginTop: 1, children: [(0, jsx_runtime_1.jsx)(ink_1.Text, { color: "gray", children: "ID: " }), (0, jsx_runtime_1.jsx)(ink_1.Text, { color: "cyan", children: task.conversation_id }), (0, jsx_runtime_1.jsx)(ink_1.Text, { color: "gray", children: " | Status: " }), (0, jsx_runtime_1.jsx)(ink_1.Text, { color: getStatusColor(task.status), children: task.status }), (0, jsx_runtime_1.jsx)(ink_1.Text, { color: "gray", children: " | Created: " }), (0, jsx_runtime_1.jsx)(ink_1.Text, { color: "blue", children: formatDate(task.created_at) })] })] }) }) }, task.conversation_id)))) }), (0, jsx_runtime_1.jsx)(ink_1.Box, { borderStyle: "single", borderColor: "gray", paddingX: 1, children: (0, jsx_runtime_1.jsxs)(ink_1.Text, { color: "gray", children: [tasks.length > 0 ? '↑↓ Navigate • Enter Select • ' : '', "ESC Back \u2022 Q Quit"] }) })] })); }; exports.default = TasksTUI; //# sourceMappingURL=TasksTUI.js.map