@nanocollective/nanocoder
Version:
A local-first CLI coding agent that brings the power of agentic coding tools like Claude Code and Gemini CLI to local models or controlled APIs like OpenRouter
29 lines • 2.04 kB
JavaScript
import { jsxs as _jsxs, jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
import { Box, Text } from 'ink';
import { memo, useMemo } from 'react';
import { useTerminalWidth } from '../hooks/useTerminalWidth.js';
import { useTheme } from '../hooks/useTheme.js';
import { parseMarkdown } from '../markdown-parser/index.js';
import { wrapWithTrimmedContinuations } from '../utils/text-wrapping.js';
import { calculateTokens } from '../utils/token-calculator.js';
export default memo(function AssistantMessage({ message, model, }) {
const { colors } = useTheme();
const boxWidth = useTerminalWidth();
const tokens = calculateTokens(message);
// Inner text width: outer width minus left border (1) and padding (1 each side)
const textWidth = boxWidth - 3;
// Render markdown to terminal-formatted text with theme colors
// Pre-wrap to avoid Ink's trim:false leaving leading spaces on wrapped lines
const renderedMessage = useMemo(() => {
try {
const parsed = parseMarkdown(message, colors, textWidth).trimEnd();
return wrapWithTrimmedContinuations(parsed, textWidth);
}
catch {
// Fallback to plain text if markdown parsing fails
return wrapWithTrimmedContinuations(message.trimEnd(), textWidth);
}
}, [message, colors, textWidth]);
return (_jsxs(_Fragment, { children: [_jsx(Box, { marginBottom: 1, marginTop: 1, children: _jsxs(Text, { color: colors.info, bold: true, children: [model, ":"] }) }), _jsx(Box, { flexDirection: "column", marginBottom: 1, backgroundColor: colors.base, width: boxWidth, padding: 1, borderStyle: "bold", borderLeft: true, borderRight: false, borderTop: false, borderBottom: false, borderLeftColor: colors.secondary, children: _jsx(Text, { children: renderedMessage }) }), _jsx(Box, { marginBottom: 2, children: _jsxs(Text, { color: colors.secondary, dimColor: true, children: ["~", tokens.toLocaleString(), " tokens"] }) })] }));
});
//# sourceMappingURL=assistant-message.js.map