UNPKG

automagik-cli

Version:

Automagik CLI - A powerful command-line interface for interacting with Automagik Hive multi-agent AI systems

56 lines (55 loc) 3.36 kB
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; import { Box, Text } from 'ink'; import { marked } from 'marked'; import { Colors } from '../colors.js'; export const MarkdownText = ({ children, color = Colors.Foreground }) => { try { // Parse markdown to tokens const tokens = marked.lexer(children); return (_jsx(Box, { flexDirection: "column", children: tokens.map((token, index) => renderToken(token, index, color)) })); } catch (error) { // Fallback to plain text if markdown parsing fails console.warn('Markdown parsing failed:', error); return (_jsx(Text, { color: color, children: children })); } }; const renderToken = (token, index, color) => { switch (token.type) { case 'heading': return (_jsx(Box, { marginY: token.depth === 1 ? 1 : 0, children: _jsxs(Text, { color: Colors.AccentPurple, bold: true, underline: token.depth === 1, children: ['#'.repeat(token.depth), " ", token.text] }) }, index)); case 'paragraph': return (_jsx(Box, { marginBottom: 1, children: _jsx(Text, { color: color, children: renderInlineTokens(token.tokens || [token.text], index) }) }, index)); case 'code': return (_jsx(Box, { borderStyle: "round", borderColor: Colors.AccentGreen, paddingX: 1, marginY: 1, children: _jsxs(Box, { flexDirection: "column", children: [_jsx(Text, { color: Colors.AccentGreen, bold: true, children: token.lang || 'code' }), _jsx(Text, { color: Colors.AccentGreen, children: token.text })] }) }, index)); case 'list': return (_jsx(Box, { flexDirection: "column", marginY: 1, children: token.items.map((item, itemIndex) => (_jsxs(Box, { marginLeft: 2, children: [_jsx(Text, { color: Colors.AccentYellow, children: "\u2022 " }), _jsx(Text, { color: color, children: renderInlineTokens(item.tokens || [item.text], itemIndex) })] }, itemIndex))) }, index)); case 'blockquote': return (_jsx(Box, { marginY: 1, marginLeft: 2, children: _jsx(Text, { color: Colors.Gray, children: token.tokens ? renderInlineTokens(token.tokens, index) : `> ${token.text}` }) }, index)); case 'space': return _jsx(Box, { height: 1 }, index); default: return (_jsx(Box, { marginBottom: 1, children: _jsx(Text, { color: color, children: token.text || token.raw || '' }) }, index)); } }; const renderInlineTokens = (tokens, parentIndex) => { if (typeof tokens === 'string') { return [_jsx(Text, { children: tokens }, `${parentIndex}-text`)]; } return tokens.map((token, index) => { const key = `${parentIndex}-${index}`; switch (token.type) { case 'strong': return (_jsx(Text, { bold: true, children: token.text }, key)); case 'em': return (_jsx(Text, { italic: true, children: token.text }, key)); case 'codespan': return (_jsx(Text, { color: Colors.AccentGreen, backgroundColor: Colors.Gray, bold: true, children: token.text }, key)); case 'link': return (_jsx(Text, { color: Colors.AccentCyan, underline: true, children: token.text }, key)); case 'text': default: return (_jsx(Text, { children: token.text || token.raw || '' }, key)); } }); };