import { useTranslation } from 'react-i18next'; import { TerminalIcon, WrenchIcon } from '@phosphor-icons/react'; import { cn } from '@/lib/utils'; import { ToolStatus } from 'shared/types'; import { ToolStatusDot } from './ToolStatusDot'; import { useLogsPanel } from '@/contexts/LogsPanelContext'; interface ChatScriptEntryProps { title: string; processId: string; exitCode?: number | null; className?: string; status: ToolStatus; onFix?: () => void; } export function ChatScriptEntry({ title, processId, exitCode, className, status, onFix, }: ChatScriptEntryProps) { const { t } = useTranslation('tasks'); const { viewProcessInPanel } = useLogsPanel(); const isRunning = status.status === 'created'; const isSuccess = status.status === 'success'; const isFailed = status.status === 'failed'; const handleFixClick = (e: React.MouseEvent) => { e.stopPropagation(); onFix?.(); }; const handleClick = () => { viewProcessInPanel(processId); }; const getSubtitle = () => { if (isRunning) { return t('conversation.script.running'); } if (isFailed && exitCode !== null && exitCode !== undefined) { return t('conversation.script.exitCode', { code: exitCode }); } if (isSuccess) { return t('conversation.script.completedSuccessfully'); } return t('conversation.script.clickToViewLogs'); }; return (
{ if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); handleClick(); } }} >
{title} {getSubtitle()}
{isFailed && onFix && ( )}
); }