import React, { FC, useCallback, useEffect, useRef, useState } from 'react'; import { useTranslation } from 'react-i18next'; import { Avatar, Button, Menu, MenuPopover, MenuTrigger, PresenceBadge, Textarea } from '@fluentui/react-components'; import commonStore, { ModelStatus } from '../stores/commonStore'; import { observer } from 'mobx-react-lite'; import { v4 as uuid } from 'uuid'; import classnames from 'classnames'; import { fetchEventSource } from '@microsoft/fetch-event-source'; import { KebabHorizontalIcon, PencilIcon, SyncIcon, TrashIcon } from '@primer/octicons-react'; import logo from '../assets/images/logo.png'; import MarkdownRender from '../components/MarkdownRender'; import { ToolTipButton } from '../components/ToolTipButton'; import { ArrowCircleUp28Regular, ArrowClockwise16Regular, Attach16Regular, Delete28Regular, Dismiss16Regular, RecordStop28Regular, Save28Regular } from '@fluentui/react-icons'; import { CopyButton } from '../components/CopyButton'; import { ReadButton } from '../components/ReadButton'; import { toast } from 'react-toastify'; import { WorkHeader } from '../components/WorkHeader'; import { DialogButton } from '../components/DialogButton'; import { OpenFileFolder, OpenOpenFileDialog, OpenSaveFileDialog } from '../../wailsjs/go/backend_golang/App'; import { absPathAsset, bytesToReadable, toastWithButton } from '../utils'; import { PresetsButton } from './PresetsManager/PresetsButton'; import { useMediaQuery } from 'usehooks-ts'; import { botName, ConversationMessage, MessageType, userName, welcomeUuid } from '../types/chat'; let chatSseControllers: { [id: string]: AbortController } = {}; const MoreUtilsButton: FC<{ uuid: string, setEditing: (editing: boolean) => void }> = observer(({ uuid, setEditing }) => { const { t } = useTranslation(); const [speaking, setSpeaking] = useState(false); const messageItem = commonStore.conversation[uuid]; return ; }); const ChatMessageItem: FC<{ uuid: string, onSubmit: (message: string | null, answerId: string | null, startUuid: string | null, endUuid: string | null, includeEndUuid: boolean) => void }> = observer(({ uuid, onSubmit }) => { const { t } = useTranslation(); const [editing, setEditing] = useState(false); const textareaRef = useRef(null); const messageItem = commonStore.conversation[uuid]; console.log(uuid); const setEditingInner = (editing: boolean) => { setEditing(editing); if (editing) { setTimeout(() => { const textarea = textareaRef.current; if (textarea) { textarea.focus(); textarea.selectionStart = textarea.value.length; textarea.selectionEnd = textarea.value.length; textarea.style.height = textarea.scrollHeight + 'px'; } }); } }; let avatarImg: string | undefined; if (commonStore.activePreset && messageItem.sender === botName) { avatarImg = absPathAsset(commonStore.activePreset.avatarImg); } else if (messageItem.avatarImg) { avatarImg = messageItem.avatarImg; } return
{ const utils = document.getElementById('utils-' + uuid); if (utils) utils.classList.remove('invisible'); }} onMouseLeave={() => { const utils = document.getElementById('utils-' + uuid); if (utils) utils.classList.add('invisible'); }} >
{!editing ?
{messageItem.content} {uuid in commonStore.attachments &&
}
: