import React from 'react'; import { observer } from 'mobx-react-lite'; import { Divider, SxProps } from '@mui/material'; import Box from '@mui/material/Box'; import UnfoldLessIcon from '@mui/icons-material/UnfoldLess'; import MoreHorizIcon from '@mui/icons-material/MoreHoriz'; import MarkdownBlock from '@/components/MarkdownBlock'; import { globalStorage } from '@/storage'; import type { IExecuteStepHistoryItem } from '@/apis/execute-plan'; import AgentIcon from '@/components/AgentIcon'; import { getAgentActionStyle } from '@/storage/plan'; export interface IStepHistoryItemProps { item: IExecuteStepHistoryItem; actionRef: React.RefObject; style?: SxProps; hoverCallback: (isHovered: boolean) => void; handleExpand?: () => void; } export default observer( ({ item, actionRef, hoverCallback, handleExpand, style = {}, }: IStepHistoryItemProps) => { const [expand, setExpand] = React.useState(false); const refDetail = React.useRef(null); // 使用useEffect来更新detail容器的高度 React.useEffect(() => { if (refDetail.current) { refDetail.current.style.height = expand ? `${refDetail.current.scrollHeight}px` : '0px'; } if (handleExpand) { let count = 0; const intervalId = setInterval(() => { handleExpand(); count++; if (count >= 20) { clearInterval(intervalId); } }, 10); } }, [expand]); const s = { ...getAgentActionStyle(item.type), ...style } as SxProps; React.useEffect(() => { console.log(item); }, [item]); return ( hoverCallback(true)} onMouseOut={() => hoverCallback(false)} > {item.agent} : {item.type} {item.result ? ( {expand ? ( <> {item.description} ) : ( <> )} { setExpand(v => !v); e.stopPropagation(); }} sx={{ position: 'absolute', right: '8px', // bottom: '12px', top: '24px', cursor: 'pointer', userSelect: 'none', height: '14px', display: 'flex', alignItems: 'center', justifyContent: 'center', background: '#0002', borderRadius: '8px', marginLeft: '4px', padding: '0 4px', '&:hover': { background: '#0003', }, }} > {expand ? ( ) : ( )} ) : ( <> )} ); }, );