This commit is contained in:
07akioni
2026-07-31 19:20:12 +08:00
parent 94a600eddd
commit 57d6d9ee1c

View File

@@ -142,19 +142,39 @@ function projectUserText(text: string): ReactNode {
return <>{parts}</> return <>{parts}</>
} }
export const MessageItem = memo(function MessageItem({ /** Right-aligned bubble shared by user and steering rows (steering has no actions). */
node, retryActive = false, onFork, t, function UserStyleBubble({
}: MessageItemProps) { content, actions, t,
}: {
content: readonly unknown[]
/** Optional IconActions (or similar) below the bubble; receives the joined text. */
actions?: (text: string) => ReactNode
t: ChatViewSlotProps['t']
}): ReactNode {
const { text, rest } = contentText(content)
const truncated = (total: number): string => t('json.truncated', { total }) const truncated = (total: number): string => t('json.truncated', { total })
switch (node.kind) {
case 'user': {
const { text, rest } = contentText(node.content)
return ( return (
<div className={css.userRow}> <div className={css.userRow}>
<div className={css.bubble}> <div className={css.bubble}>
{projectUserText(text)} {projectUserText(text)}
{rest.map((block, i) => <JsonBlock key={i} label={t('message.extraBlock')} payload={block} truncatedLabel={truncated} />)} {rest.map((block, i) => <JsonBlock key={i} label={t('message.extraBlock')} payload={block} truncatedLabel={truncated} />)}
</div> </div>
{actions?.(text)}
</div>
)
}
export const MessageItem = memo(function MessageItem({
node, retryActive = false, onFork, t,
}: MessageItemProps) {
const truncated = (total: number): string => t('json.truncated', { total })
switch (node.kind) {
case 'user':
return (
<UserStyleBubble
content={node.content}
t={t}
actions={text => (
<MessageIconActions <MessageIconActions
text={text} text={text}
time={node.time} time={node.time}
@@ -163,20 +183,11 @@ export const MessageItem = memo(function MessageItem({
className={css.actions} className={css.actions}
t={t} t={t}
/> />
</div> )}
/>
) )
} case 'steering':
case 'steering': { return <UserStyleBubble content={node.content} t={t} />
const { text, rest } = contentText(node.content)
return (
<div className={css.userRow}>
<div className={css.bubble}>
{projectUserText(text)}
{rest.map((block, i) => <JsonBlock key={i} label={t('message.extraBlock')} payload={block} truncatedLabel={truncated} />)}
</div>
</div>
)
}
case 'context': case 'context':
return ( return (
<ContextInjectionRow content={node.content} source={node.source} t={t} /> <ContextInjectionRow content={node.content} source={node.source} t={t} />