import { Box, Text } from 'ink'
import { memo } from 'react'
import { LONG_MSG, ROLE } from '../constants.js'
import { hasAnsi, userDisplay } from '../lib/text.js'
import type { Theme } from '../theme.js'
import type { Msg } from '../types.js'
import { Md } from './markdown.js'
export const MessageLine = memo(function MessageLine({
cols,
compact,
msg,
t
}: {
cols: number
compact?: boolean
msg: Msg
t: Theme
}) {
const { body, glyph, prefix } = ROLE[msg.role](t)
const contentWidth = Math.max(20, cols - 5)
if (msg.role === 'tool') {
return (
{msg.text}
)
}
const content = (() => {
if (msg.role === 'assistant') {
return hasAnsi(msg.text) ? {msg.text} :
}
if (msg.role === 'user' && msg.text.length > LONG_MSG) {
const [head, ...rest] = userDisplay(msg.text).split('[long message]')
return (
{head}
[long message]
{rest.join('')}
)
}
return {msg.text}
})()
return (
{glyph}{' '}
{content}
)
})