import { memo } from 'react'
import type { SessionMessageAssistant } from '@opencode-manager/shared/opencode'
import { TextPart } from './TextPart'
import { ToolCallPart } from './ToolCallPart'
import { readShowArtifactCall } from '@/lib/artifactTool'
import { useSettings } from '@/hooks/useSettings'
import { cn } from '@/lib/utils'
import { TRANSCRIPT_DETAIL_CLASS } from './transcriptStyles'
import type { ShellNoticeOutcome } from '@/lib/backgroundWork'
import type { WalkthroughSource } from '@opencode-manager/shared/schemas'
type AssistantContentPart = SessionMessageAssistant['content'][number]
interface MessagePartProps {
part: AssistantContentPart
messageID?: string
directory?: string
repoFullPath?: string
repoLocalPath?: string
shellOutcome?: ShellNoticeOutcome
onFileClick?: (filePath: string, lineNumber?: number) => void
onChildSessionClick?: (sessionId: string) => void
onOpenWalkthrough?: (source?: WalkthroughSource) => void
}
export const MessagePart = memo(function MessagePart({ part, messageID, directory, repoFullPath, repoLocalPath, shellOutcome, onFileClick, onChildSessionClick, onOpenWalkthrough }: MessagePartProps) {
const { preferences } = useSettings()
const simpleChatMode = preferences?.simpleChatMode ?? false
const showReasoning = preferences?.showReasoning ?? false
switch (part.type) {
case 'text':
return
case 'reasoning':
if (simpleChatMode || !showReasoning) return null
if (!part.text.trim()) return null
return (
Reasoning
{part.text}
)
case 'tool':
if (simpleChatMode && part.name !== 'subagent' && !readShowArtifactCall(part)) return null
return (
)
default:
return null
}
})