Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 4178 - current generated message options should be visible #4196

Merged
merged 2 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion web/containers/ErrorMessage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@
<button
className="font-medium text-[hsla(var(--app-link))] underline"
onClick={() => {
setMainState(MainViewState.Settings)

Check warning on line 38 in web/containers/ErrorMessage/index.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

38 line is not covered with tests

if (activeThread?.assistants[0]?.model.engine) {
const engine = EngineManager.instance().get(

Check warning on line 41 in web/containers/ErrorMessage/index.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

40-41 lines are not covered with tests
activeThread.assistants[0].model.engine
)
engine?.name && setSelectedSettingScreen(engine.name)

Check warning on line 44 in web/containers/ErrorMessage/index.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

44 line is not covered with tests
}
}}
>
Expand All @@ -52,7 +52,10 @@
)
default:
return (
<p data-testid="passthrough-error-message" className="capitalize">
<p
data-testid="passthrough-error-message"
className="first-letter:uppercase"
>
{message.content[0]?.text?.value && (
<AutoLink text={message.content[0].text.value} />
)}
Expand Down
7 changes: 6 additions & 1 deletion web/screens/Thread/ThreadCenterPanel/ChatItem/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,32 +20,32 @@
} & ThreadMessage

const ChatItem = forwardRef<Ref, Props>((message, ref) => {
const [content, setContent] = useState<ThreadContent[]>(message.content)
const [status, setStatus] = useState<MessageStatus>(message.status)
const [errorMessage, setErrorMessage] = useState<ThreadMessage | undefined>(

Check warning on line 25 in web/screens/Thread/ThreadCenterPanel/ChatItem/index.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

23-25 lines are not covered with tests
message.isCurrentMessage && message.status === MessageStatus.Error
? message
: undefined
)

function onMessageUpdate(data: ThreadMessage) {
if (data.id === message.id) {
setContent(data.content)
if (data.status !== status) setStatus(data.status)
if (data.status === MessageStatus.Error && message.isCurrentMessage)
setErrorMessage(data)

Check warning on line 36 in web/screens/Thread/ThreadCenterPanel/ChatItem/index.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

32-36 lines are not covered with tests
}
}

useEffect(() => {
if (!message.isCurrentMessage && errorMessage) setErrorMessage(undefined)

Check warning on line 41 in web/screens/Thread/ThreadCenterPanel/ChatItem/index.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

40-41 lines are not covered with tests
}, [message, errorMessage])

useEffect(() => {
if (message.status === MessageStatus.Pending)
events.on(MessageEvent.OnMessageUpdate, onMessageUpdate)
return () => {
events.off(MessageEvent.OnMessageUpdate, onMessageUpdate)

Check warning on line 48 in web/screens/Thread/ThreadCenterPanel/ChatItem/index.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

44-48 lines are not covered with tests
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [])
Expand All @@ -54,7 +54,12 @@
<>
{status !== MessageStatus.Error && content?.length > 0 && (
<div ref={ref} className="relative">
<MessageContainer {...message} content={content} status={status} />
<MessageContainer
{...message}
content={content}
status={status}
isCurrentMessage={message.isCurrentMessage ?? false}
/>
</div>
)}
{errorMessage && !message.loadModelError && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
import { activeThreadAtom } from '@/helpers/atoms/Thread.atom'

const LoadModelError = () => {
const setModalTroubleShooting = useSetAtom(modalTroubleShootingAtom)
const loadModelError = useAtomValue(loadModelErrorAtom)
const setMainState = useSetAtom(mainViewStateAtom)
const setSelectedSettingScreen = useSetAtom(selectedSettingAtom)
const activeThread = useAtomValue(activeThreadAtom)

Check warning on line 21 in web/screens/Thread/ThreadCenterPanel/LoadModelError/index.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

17-21 lines are not covered with tests

const ErrorMessage = () => {
if (

Check warning on line 24 in web/screens/Thread/ThreadCenterPanel/LoadModelError/index.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

23-24 lines are not covered with tests
typeof loadModelError?.includes === 'function' &&
loadModelError.includes('EXTENSION_IS_NOT_INSTALLED')
) {
Expand All @@ -32,9 +32,9 @@
<span
className="cursor-pointer font-medium text-[hsla(var(--app-link))]"
onClick={() => {
setMainState(MainViewState.Settings)
if (activeThread?.assistants[0]?.model.engine) {
const engine = EngineManager.instance().get(

Check warning on line 37 in web/screens/Thread/ThreadCenterPanel/LoadModelError/index.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

35-37 lines are not covered with tests
activeThread.assistants[0].model.engine
)
engine?.name && setSelectedSettingScreen(engine.name)
Expand All @@ -49,7 +49,9 @@
} else {
return (
<div className="mx-6 flex flex-col items-center space-y-2 text-center font-medium text-[hsla(var(--text-secondary))]">
{loadModelError && <p className="capitalize">{loadModelError}</p>}
{loadModelError && (
<p className="first-letter:uppercase">{loadModelError}</p>
)}
<p>
{`Something's wrong.`}&nbsp;Access&nbsp;
<span
Expand Down
90 changes: 46 additions & 44 deletions web/screens/Thread/ThreadCenterPanel/TextMessage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,18 @@ import { MarkdownTextMessage } from './MarkdownTextMessage'

import {
editMessageAtom,
getCurrentChatMessagesAtom,
tokenSpeedAtom,
} from '@/helpers/atoms/ChatMessage.atom'
import { activeThreadAtom } from '@/helpers/atoms/Thread.atom'

const MessageContainer: React.FC<ThreadMessage> = (props) => {
const MessageContainer: React.FC<
ThreadMessage & { isCurrentMessage: boolean }
> = (props) => {
const isUser = props.role === ChatCompletionRole.User
const isSystem = props.role === ChatCompletionRole.System
const editMessage = useAtomValue(editMessageAtom)
const activeThread = useAtomValue(activeThreadAtom)

const tokenSpeed = useAtomValue(tokenSpeedAtom)
const messages = useAtomValue(getCurrentChatMessagesAtom)

const text = useMemo(
() => props.content[0]?.text?.value ?? '',
Expand Down Expand Up @@ -81,16 +80,6 @@ const MessageContainer: React.FC<ThreadMessage> = (props) => {
<p className="text-xs font-medium text-gray-400">
{displayDate(props.created)}
</p>
<div
className={twMerge(
'absolute right-0 cursor-pointer transition-all',
messages[messages.length - 1]?.id === props.id && !isUser
? 'absolute -bottom-8 right-4'
: 'hidden group-hover:absolute group-hover:right-4 group-hover:top-4 group-hover:flex'
)}
>
<MessageToolbar message={props} />
</div>
{tokenSpeed &&
tokenSpeed.message === props.id &&
tokenSpeed.tokenSpeed > 0 && (
Expand All @@ -100,39 +89,52 @@ const MessageContainer: React.FC<ThreadMessage> = (props) => {
)}
</div>

<div
className={twMerge(
'w-full',
!isUser && !text.includes(' ') && 'break-all'
)}
>
<>
{messageType === ContentType.Image && (
<ImageMessage content={props.content[0]} />
<div className="flex w-full flex-col">
<div
className={twMerge(
'absolute right-0 order-1 mt-2 flex cursor-pointer items-center justify-start gap-x-2 transition-all',
props.isCurrentMessage && !isUser
? 'relative order-2 flex justify-end'
: 'hidden group-hover:absolute group-hover:right-4 group-hover:top-4 group-hover:flex'
)}
{messageType === ContentType.Pdf && (
<DocMessage
id={props.id}
name={props.content[0]?.text?.name}
size={props.content[0]?.text?.size}
/>
>
<MessageToolbar message={props} />
</div>
<div
className={twMerge(
'order-2 w-full',
!isUser && !text.includes(' ') && 'break-all',
props.isCurrentMessage && !isUser && 'order-1'
)}
>
<>
{messageType === ContentType.Image && (
<ImageMessage content={props.content[0]} />
)}
{messageType === ContentType.Pdf && (
<DocMessage
id={props.id}
name={props.content[0]?.text?.name}
size={props.content[0]?.text?.size}
/>
)}

{editMessage === props.id ? (
<div>
<EditChatInput message={props} />
</div>
) : (
<div
className={twMerge(
'message max-width-[100%] flex flex-col gap-y-2 overflow-x-auto overflow-y-hidden leading-relaxed'
)}
dir="ltr"
>
<MarkdownTextMessage id={props.id} text={text} />
</div>
)}
</>
{editMessage === props.id ? (
<div>
<EditChatInput message={props} />
</div>
) : (
<div
className={twMerge(
'message max-width-[100%] flex flex-col gap-y-2 overflow-x-auto overflow-y-hidden leading-relaxed'
)}
dir="ltr"
>
<MarkdownTextMessage id={props.id} text={text} />
</div>
)}
</>
</div>
</div>
</div>
)
Expand Down
Loading