debug-info.tsx 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. 'use client'
  2. import type { FC } from 'react'
  3. import React from 'react'
  4. import {
  5. RiArrowRightUpLine,
  6. RiBugLine,
  7. } from '@remixicon/react'
  8. import { useTranslation } from 'react-i18next'
  9. import KeyValueItem from '../base/key-value-item'
  10. import Tooltip from '@/app/components/base/tooltip'
  11. import Button from '@/app/components/base/button'
  12. import { useDebugKey } from '@/service/use-plugins'
  13. const i18nPrefix = 'plugin.debugInfo'
  14. const DebugInfo: FC = () => {
  15. const { t } = useTranslation()
  16. const { data: info, isLoading } = useDebugKey()
  17. // info.key likes 4580bdb7-b878-471c-a8a4-bfd760263a53 mask the middle part using *.
  18. const maskedKey = info?.key?.replace(/(.{8})(.*)(.{8})/, '$1********$3')
  19. if (isLoading) return null
  20. return (
  21. <Tooltip
  22. triggerMethod='click'
  23. disabled={!info}
  24. popupContent={
  25. <>
  26. <div className='flex items-center gap-1 self-stretch'>
  27. <span className='flex flex-col justify-center items-start grow shrink-0 basis-0 text-text-secondary system-sm-semibold'>{t(`${i18nPrefix}.title`)}</span>
  28. <a href='https://docs.dify.ai/plugins/quick-start/develop-plugins/debug-plugin' target='_blank' className='flex items-center gap-0.5 text-text-accent-light-mode-only cursor-pointer'>
  29. <span className='system-xs-medium'>{t(`${i18nPrefix}.viewDocs`)}</span>
  30. <RiArrowRightUpLine className='w-3 h-3' />
  31. </a>
  32. </div>
  33. <div className='space-y-0.5'>
  34. <KeyValueItem
  35. label={'URL'}
  36. value={`${info?.host}:${info?.port}`}
  37. />
  38. <KeyValueItem
  39. label={'Key'}
  40. value={info?.key || ''}
  41. maskedValue={maskedKey}
  42. />
  43. </div>
  44. </>
  45. }
  46. popupClassName='flex flex-col items-start w-[256px] px-4 py-3.5 gap-1 border border-components-panel-border
  47. rounded-xl bg-components-tooltip-bg shadows-shadow-lg z-50'
  48. asChild={false}
  49. position='bottom'
  50. >
  51. <Button className='w-full h-full p-2 text-components-button-secondary-text'>
  52. <RiBugLine className='w-4 h-4' />
  53. </Button>
  54. </Tooltip>
  55. )
  56. }
  57. export default React.memo(DebugInfo)