import { useState, useRef, useEffect, useCallback } from 'react'; import ChatInput from './ChatInput'; import { api, streamChat } from '../api'; function renderMarkdown(text) { let html = text .replace(/&/g, '&').replace(//g, '>') .replace(/\*\*\*(.+?)\*\*\*/g, '$1') .replace(/\*\*(.+?)\*\*/g, '$1') .replace(/\*(.+?)\*/g, '$1') .replace(/`([^`]+)`/g, '$1') .replace(/^### (.+)$/gm, '

$1

') .replace(/^## (.+)$/gm, '

$1

') .replace(/^# (.+)$/gm, '

$1

') .replace(/^[\-*] (.+)$/gm, '
  • $1
  • ') .replace(/^\d+\. (.+)$/gm, '
  • $1
  • ') .replace(/^> (.+)$/gm, '
    $1
    ') .replace(/^---$/gm, '
    ') .replace(/\n\n/g, '

    '); html = '

    ' + html + '

    '; html = html.replace(/<\/li>\s*
  • /g, '
  • '); html = html.replace(/(
  • .*?<\/li>)/gs, m => ``); html = html.replace(/<\/ul>\s*