vis-plugin.tsx 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import { CheckOutlined, ClockCircleOutlined, CloseOutlined, LoadingOutlined } from '@ant-design/icons';
  2. import { GPTVis } from '@antv/gpt-vis';
  3. import classNames from 'classnames';
  4. import { ReactNode } from 'react';
  5. import rehypeRaw from 'rehype-raw';
  6. import remarkGfm from 'remark-gfm';
  7. import markdownComponents from './config';
  8. interface IVisPlugin {
  9. name: string;
  10. args: {
  11. query: string;
  12. };
  13. status: 'todo' | 'runing' | 'failed' | 'complete' | (string & {});
  14. logo: string | null;
  15. result: string;
  16. err_msg: string | null;
  17. }
  18. interface Props {
  19. data: IVisPlugin;
  20. }
  21. const pluginViewStatusMapper: Record<IVisPlugin['status'], { bgClass: string; icon: ReactNode }> = {
  22. todo: {
  23. bgClass: 'bg-gray-500',
  24. icon: <ClockCircleOutlined className='ml-2' />,
  25. },
  26. runing: {
  27. bgClass: 'bg-blue-500',
  28. icon: <LoadingOutlined className='ml-2' />,
  29. },
  30. failed: {
  31. bgClass: 'bg-red-500',
  32. icon: <CloseOutlined className='ml-2' />,
  33. },
  34. complete: {
  35. bgClass: 'bg-green-500',
  36. icon: <CheckOutlined className='ml-2' />,
  37. },
  38. };
  39. function VisPlugin({ data }: Props) {
  40. const { bgClass, icon } = pluginViewStatusMapper[data.status] ?? {};
  41. return (
  42. <div className='bg-theme-light dark:bg-theme-dark-container rounded overflow-hidden my-2 flex flex-col'>
  43. <div className={classNames('flex px-4 md:px-6 py-2 items-center text-white text-sm', bgClass)}>
  44. {data.name}
  45. {icon}
  46. </div>
  47. {data.result ? (
  48. <div className='px-4 md:px-6 py-4 text-sm whitespace-normal'>
  49. <GPTVis components={markdownComponents} rehypePlugins={[rehypeRaw]} remarkPlugins={[remarkGfm]}>
  50. {data.result ?? ''}
  51. </GPTVis>
  52. </div>
  53. ) : (
  54. <div className='px-4 md:px-6 py-4 text-sm'>{data.err_msg}</div>
  55. )}
  56. </div>
  57. );
  58. }
  59. export default VisPlugin;