mirror of
https://github.com/csunny/DB-GPT.git
synced 2025-07-25 21:14:06 +00:00
Co-authored-by: Fangyin Cheng <staneyffer@gmail.com> Co-authored-by: 谨欣 <echo.cmy@antgroup.com> Co-authored-by: 严志勇 <yanzhiyong@tiansuixiansheng.com> Co-authored-by: yanzhiyong <932374019@qq.com>
66 lines
1.8 KiB
TypeScript
66 lines
1.8 KiB
TypeScript
import { CheckOutlined, ClockCircleOutlined, CloseOutlined, LoadingOutlined } from '@ant-design/icons';
|
|
import { GPTVis } from '@antv/gpt-vis';
|
|
import classNames from 'classnames';
|
|
import { ReactNode } from 'react';
|
|
import rehypeRaw from 'rehype-raw';
|
|
import remarkGfm from 'remark-gfm';
|
|
import markdownComponents from './config';
|
|
|
|
interface IVisPlugin {
|
|
name: string;
|
|
args: {
|
|
query: string;
|
|
};
|
|
status: 'todo' | 'runing' | 'failed' | 'complete' | (string & {});
|
|
logo: string | null;
|
|
result: string;
|
|
err_msg: string | null;
|
|
}
|
|
|
|
interface Props {
|
|
data: IVisPlugin;
|
|
}
|
|
|
|
const pluginViewStatusMapper: Record<IVisPlugin['status'], { bgClass: string; icon: ReactNode }> = {
|
|
todo: {
|
|
bgClass: 'bg-gray-500',
|
|
icon: <ClockCircleOutlined className='ml-2' />,
|
|
},
|
|
runing: {
|
|
bgClass: 'bg-blue-500',
|
|
icon: <LoadingOutlined className='ml-2' />,
|
|
},
|
|
failed: {
|
|
bgClass: 'bg-red-500',
|
|
icon: <CloseOutlined className='ml-2' />,
|
|
},
|
|
complete: {
|
|
bgClass: 'bg-green-500',
|
|
icon: <CheckOutlined className='ml-2' />,
|
|
},
|
|
};
|
|
|
|
function VisPlugin({ data }: Props) {
|
|
const { bgClass, icon } = pluginViewStatusMapper[data.status] ?? {};
|
|
|
|
return (
|
|
<div className='bg-theme-light dark:bg-theme-dark-container rounded overflow-hidden my-2 flex flex-col'>
|
|
<div className={classNames('flex px-4 md:px-6 py-2 items-center text-white text-sm', bgClass)}>
|
|
{data.name}
|
|
{icon}
|
|
</div>
|
|
{data.result ? (
|
|
<div className='px-4 md:px-6 py-4 text-sm whitespace-normal'>
|
|
<GPTVis components={markdownComponents} rehypePlugins={[rehypeRaw]} remarkPlugins={[remarkGfm]}>
|
|
{data.result ?? ''}
|
|
</GPTVis>
|
|
</div>
|
|
) : (
|
|
<div className='px-4 md:px-6 py-4 text-sm'>{data.err_msg}</div>
|
|
)}
|
|
</div>
|
|
);
|
|
}
|
|
|
|
export default VisPlugin;
|