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

chore: sync latest main into dev #4360

Merged
merged 9 commits into from
Dec 30, 2024
2 changes: 1 addition & 1 deletion extensions/inference-cortex-extension/bin/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.0.6
1.0.7
2 changes: 1 addition & 1 deletion web/containers/Providers/ModelHandler.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
extractInferenceParams,
ModelExtension,
} from '@janhq/core'
import { useAtom, useAtomValue, useSetAtom } from 'jotai'

Check warning on line 21 in web/containers/Providers/ModelHandler.tsx

View workflow job for this annotation

GitHub Actions / test-on-ubuntu

'useAtom' is defined but never used

Check warning on line 21 in web/containers/Providers/ModelHandler.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

'useAtom' is defined but never used

Check warning on line 21 in web/containers/Providers/ModelHandler.tsx

View workflow job for this annotation

GitHub Actions / test-on-macos

'useAtom' is defined but never used

Check warning on line 21 in web/containers/Providers/ModelHandler.tsx

View workflow job for this annotation

GitHub Actions / test-on-macos

'useAtom' is defined but never used

Check warning on line 21 in web/containers/Providers/ModelHandler.tsx

View workflow job for this annotation

GitHub Actions / test-on-ubuntu

'useAtom' is defined but never used

Check warning on line 21 in web/containers/Providers/ModelHandler.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

'useAtom' is defined but never used

Check warning on line 21 in web/containers/Providers/ModelHandler.tsx

View workflow job for this annotation

GitHub Actions / test-on-windows-pr

'useAtom' is defined but never used
import { ulid } from 'ulidx'

import { activeModelAtom, stateModelAtom } from '@/hooks/useActiveModel'
Expand Down Expand Up @@ -56,7 +56,7 @@
const activeModel = useAtomValue(activeModelAtom)
const setActiveModel = useSetAtom(activeModelAtom)
const setStateModel = useSetAtom(stateModelAtom)
const [subscribedGeneratingMessage, setSubscribedGeneratingMessage] = useAtom(
const subscribedGeneratingMessage = useAtomValue(
subscribedGeneratingMessageAtom
)
const activeThread = useAtomValue(activeThreadAtom)
Expand Down
41 changes: 40 additions & 1 deletion web/helpers/atoms/Thread.atom.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Thread, ThreadContent, ThreadState } from '@janhq/core'

import { atom } from 'jotai'
import { atomWithStorage } from 'jotai/utils'
import { atomWithStorage, selectAtom } from 'jotai/utils'

import { ModelParams } from '@/types/model'

Expand Down Expand Up @@ -34,6 +34,22 @@
{}
)

/**
* Returns whether there is a thread waiting for response or not
*/
const isWaitingForResponseAtom = selectAtom(threadStatesAtom, (threads) =>
Object.values(threads).some((t) => t.waitingForResponse)
)

/**
* Combine 2 states to reduce rerender
* 1. isWaitingForResponse
* 2. isGenerating
*/
export const isBlockingSendAtom = atom(
(get) => get(isWaitingForResponseAtom) || get(isGeneratingResponseAtom)
)

/**
* Stores all threads for the current user
*/
Expand Down Expand Up @@ -87,13 +103,13 @@
* Get the active thread state
*/
export const activeThreadStateAtom = atom<ThreadState | undefined>((get) => {
const threadId = get(activeThreadIdAtom)
if (!threadId) {
console.debug('Active thread id is undefined')
return undefined

Check warning on line 109 in web/helpers/atoms/Thread.atom.ts

View workflow job for this annotation

GitHub Actions / coverage-check

106-109 lines are not covered with tests
}

return get(threadStatesAtom)[threadId]

Check warning on line 112 in web/helpers/atoms/Thread.atom.ts

View workflow job for this annotation

GitHub Actions / coverage-check

112 line is not covered with tests
})

/**
Expand All @@ -107,7 +123,7 @@
return undefined
}

return get(threadModelParamsAtom)[threadId]

Check warning on line 126 in web/helpers/atoms/Thread.atom.ts

View workflow job for this annotation

GitHub Actions / coverage-check

126 line is not covered with tests
}
)
/// End Active Thread Atom
Expand All @@ -130,19 +146,19 @@
*/
export const createNewThreadAtom = atom(null, (get, set, newThread: Thread) => {
// create thread state for this new thread
const currentState = { ...get(threadStatesAtom) }

Check warning on line 149 in web/helpers/atoms/Thread.atom.ts

View workflow job for this annotation

GitHub Actions / coverage-check

149 line is not covered with tests

const threadState: ThreadState = {

Check warning on line 151 in web/helpers/atoms/Thread.atom.ts

View workflow job for this annotation

GitHub Actions / coverage-check

151 line is not covered with tests
hasMore: false,
waitingForResponse: false,
lastMessage: undefined,
}
currentState[newThread.id] = threadState
set(threadStatesAtom, currentState)

Check warning on line 157 in web/helpers/atoms/Thread.atom.ts

View workflow job for this annotation

GitHub Actions / coverage-check

156-157 lines are not covered with tests

// add the new thread on top of the thread list to the state
const threads = get(threadsAtom)
set(threadsAtom, [newThread, ...threads])

Check warning on line 161 in web/helpers/atoms/Thread.atom.ts

View workflow job for this annotation

GitHub Actions / coverage-check

160-161 lines are not covered with tests
})

/**
Expand All @@ -163,16 +179,39 @@
export const updateThreadWaitingForResponseAtom = atom(
null,
(get, set, threadId: string, waitingForResponse: boolean) => {
const currentState = { ...get(threadStatesAtom) }
currentState[threadId] = {

Check warning on line 183 in web/helpers/atoms/Thread.atom.ts

View workflow job for this annotation

GitHub Actions / coverage-check

182-183 lines are not covered with tests
...currentState[threadId],
waitingForResponse,
error: undefined,
}
set(threadStatesAtom, currentState)

Check warning on line 188 in web/helpers/atoms/Thread.atom.ts

View workflow job for this annotation

GitHub Actions / coverage-check

188 line is not covered with tests
}
)

/**
* Reset the thread waiting for response state
*/
export const resetThreadWaitingForResponseAtom = atom(null, (get, set) => {
const currentState = { ...get(threadStatesAtom) }
Object.keys(currentState).forEach((threadId) => {
currentState[threadId] = {

Check warning on line 198 in web/helpers/atoms/Thread.atom.ts

View workflow job for this annotation

GitHub Actions / coverage-check

196-198 lines are not covered with tests
...currentState[threadId],
waitingForResponse: false,
error: undefined,
}
})
set(threadStatesAtom, currentState)
})

/**
* Reset all generating states
**/
export const resetGeneratingResponseAtom = atom(null, (get, set) => {
set(resetThreadWaitingForResponseAtom)
set(isGeneratingResponseAtom, false)
})

/**
* Update the thread last message
*/
Expand Down
4 changes: 4 additions & 0 deletions web/hooks/useActiveModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
import { vulkanEnabledAtom } from '@/helpers/atoms/AppConfig.atom'
import { activeAssistantAtom } from '@/helpers/atoms/Assistant.atom'
import { downloadedModelsAtom } from '@/helpers/atoms/Model.atom'
import {
isGeneratingResponseAtom,

Check warning on line 14 in web/hooks/useActiveModel.ts

View workflow job for this annotation

GitHub Actions / test-on-ubuntu

'isGeneratingResponseAtom' is defined but never used

Check warning on line 14 in web/hooks/useActiveModel.ts

View workflow job for this annotation

GitHub Actions / coverage-check

'isGeneratingResponseAtom' is defined but never used

Check warning on line 14 in web/hooks/useActiveModel.ts

View workflow job for this annotation

GitHub Actions / test-on-macos

'isGeneratingResponseAtom' is defined but never used

Check warning on line 14 in web/hooks/useActiveModel.ts

View workflow job for this annotation

GitHub Actions / test-on-macos

'isGeneratingResponseAtom' is defined but never used

Check warning on line 14 in web/hooks/useActiveModel.ts

View workflow job for this annotation

GitHub Actions / test-on-ubuntu

'isGeneratingResponseAtom' is defined but never used

Check warning on line 14 in web/hooks/useActiveModel.ts

View workflow job for this annotation

GitHub Actions / coverage-check

'isGeneratingResponseAtom' is defined but never used

Check warning on line 14 in web/hooks/useActiveModel.ts

View workflow job for this annotation

GitHub Actions / test-on-windows-pr

'isGeneratingResponseAtom' is defined but never used
resetThreadWaitingForResponseAtom,

Check warning on line 15 in web/hooks/useActiveModel.ts

View workflow job for this annotation

GitHub Actions / test-on-ubuntu

'resetThreadWaitingForResponseAtom' is defined but never used

Check warning on line 15 in web/hooks/useActiveModel.ts

View workflow job for this annotation

GitHub Actions / coverage-check

'resetThreadWaitingForResponseAtom' is defined but never used

Check warning on line 15 in web/hooks/useActiveModel.ts

View workflow job for this annotation

GitHub Actions / test-on-macos

'resetThreadWaitingForResponseAtom' is defined but never used

Check warning on line 15 in web/hooks/useActiveModel.ts

View workflow job for this annotation

GitHub Actions / test-on-macos

'resetThreadWaitingForResponseAtom' is defined but never used

Check warning on line 15 in web/hooks/useActiveModel.ts

View workflow job for this annotation

GitHub Actions / test-on-ubuntu

'resetThreadWaitingForResponseAtom' is defined but never used

Check warning on line 15 in web/hooks/useActiveModel.ts

View workflow job for this annotation

GitHub Actions / coverage-check

'resetThreadWaitingForResponseAtom' is defined but never used

Check warning on line 15 in web/hooks/useActiveModel.ts

View workflow job for this annotation

GitHub Actions / test-on-windows-pr

'resetThreadWaitingForResponseAtom' is defined but never used
} from '@/helpers/atoms/Thread.atom'

export const activeModelAtom = atom<Model | undefined>(undefined)
export const loadModelErrorAtom = atom<string | undefined>(undefined)
Expand Down
3 changes: 0 additions & 3 deletions web/hooks/useCreateNewThread.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ describe('useCreateNewThread', () => {
} as any)
})

expect(mockSetAtom).toHaveBeenCalledTimes(1)
expect(extensionManager.get).toHaveBeenCalled()
})

Expand Down Expand Up @@ -113,7 +112,6 @@ describe('useCreateNewThread', () => {
} as any)
})

expect(mockSetAtom).toHaveBeenCalledTimes(1) // Check if all the necessary atoms were set
expect(extensionManager.get).toHaveBeenCalled()
})

Expand Down Expand Up @@ -158,7 +156,6 @@ describe('useCreateNewThread', () => {
} as any)
})

expect(mockSetAtom).toHaveBeenCalledTimes(1) // Check if all the necessary atoms were set
expect(extensionManager.get).toHaveBeenCalled()
})

Expand Down
8 changes: 0 additions & 8 deletions web/hooks/useCreateNewThread.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
ExtensionTypeEnum,
Thread,
ThreadAssistantInfo,
ThreadState,

Check warning on line 8 in web/hooks/useCreateNewThread.ts

View workflow job for this annotation

GitHub Actions / test-on-ubuntu

'ThreadState' is defined but never used

Check warning on line 8 in web/hooks/useCreateNewThread.ts

View workflow job for this annotation

GitHub Actions / coverage-check

'ThreadState' is defined but never used

Check warning on line 8 in web/hooks/useCreateNewThread.ts

View workflow job for this annotation

GitHub Actions / test-on-macos

'ThreadState' is defined but never used

Check warning on line 8 in web/hooks/useCreateNewThread.ts

View workflow job for this annotation

GitHub Actions / test-on-macos

'ThreadState' is defined but never used

Check warning on line 8 in web/hooks/useCreateNewThread.ts

View workflow job for this annotation

GitHub Actions / test-on-ubuntu

'ThreadState' is defined but never used

Check warning on line 8 in web/hooks/useCreateNewThread.ts

View workflow job for this annotation

GitHub Actions / coverage-check

'ThreadState' is defined but never used

Check warning on line 8 in web/hooks/useCreateNewThread.ts

View workflow job for this annotation

GitHub Actions / test-on-windows-pr

'ThreadState' is defined but never used
AssistantTool,
Model,
Assistant,
} from '@janhq/core'
import { atom, useAtom, useAtomValue, useSetAtom } from 'jotai'

Check warning on line 13 in web/hooks/useCreateNewThread.ts

View workflow job for this annotation

GitHub Actions / test-on-ubuntu

'atom' is defined but never used

Check warning on line 13 in web/hooks/useCreateNewThread.ts

View workflow job for this annotation

GitHub Actions / coverage-check

'atom' is defined but never used

Check warning on line 13 in web/hooks/useCreateNewThread.ts

View workflow job for this annotation

GitHub Actions / test-on-macos

'atom' is defined but never used

Check warning on line 13 in web/hooks/useCreateNewThread.ts

View workflow job for this annotation

GitHub Actions / test-on-macos

'atom' is defined but never used

Check warning on line 13 in web/hooks/useCreateNewThread.ts

View workflow job for this annotation

GitHub Actions / test-on-ubuntu

'atom' is defined but never used

Check warning on line 13 in web/hooks/useCreateNewThread.ts

View workflow job for this annotation

GitHub Actions / coverage-check

'atom' is defined but never used

Check warning on line 13 in web/hooks/useCreateNewThread.ts

View workflow job for this annotation

GitHub Actions / test-on-windows-pr

'atom' is defined but never used

import { useDebouncedCallback } from 'use-debounce'

Expand All @@ -21,8 +21,6 @@

import { isLocalEngine } from '@/utils/modelEngine'

import { useActiveModel } from './useActiveModel'

import useRecommendedModel from './useRecommendedModel'
import useSetActiveThread from './useSetActiveThread'

Expand All @@ -35,7 +33,7 @@
threadsAtom,
updateThreadAtom,
setThreadModelParamsAtom,
isGeneratingResponseAtom,

Check warning on line 36 in web/hooks/useCreateNewThread.ts

View workflow job for this annotation

GitHub Actions / test-on-ubuntu

'isGeneratingResponseAtom' is defined but never used

Check warning on line 36 in web/hooks/useCreateNewThread.ts

View workflow job for this annotation

GitHub Actions / coverage-check

'isGeneratingResponseAtom' is defined but never used

Check warning on line 36 in web/hooks/useCreateNewThread.ts

View workflow job for this annotation

GitHub Actions / test-on-macos

'isGeneratingResponseAtom' is defined but never used

Check warning on line 36 in web/hooks/useCreateNewThread.ts

View workflow job for this annotation

GitHub Actions / test-on-macos

'isGeneratingResponseAtom' is defined but never used

Check warning on line 36 in web/hooks/useCreateNewThread.ts

View workflow job for this annotation

GitHub Actions / test-on-ubuntu

'isGeneratingResponseAtom' is defined but never used

Check warning on line 36 in web/hooks/useCreateNewThread.ts

View workflow job for this annotation

GitHub Actions / coverage-check

'isGeneratingResponseAtom' is defined but never used

Check warning on line 36 in web/hooks/useCreateNewThread.ts

View workflow job for this annotation

GitHub Actions / test-on-windows-pr

'isGeneratingResponseAtom' is defined but never used
createNewThreadAtom,
} from '@/helpers/atoms/Thread.atom'

Expand All @@ -52,21 +50,15 @@
const [activeAssistant, setActiveAssistant] = useAtom(activeAssistantAtom)

const experimentalEnabled = useAtomValue(experimentalFeatureEnabledAtom)
const setIsGeneratingResponse = useSetAtom(isGeneratingResponseAtom)

const threads = useAtomValue(threadsAtom)
const { stopInference } = useActiveModel()

const { recommendedModel } = useRecommendedModel()

const requestCreateNewThread = async (
assistant: (ThreadAssistantInfo & { id: string; name: string }) | Assistant,
model?: Model | undefined
) => {
// Stop generating if any
setIsGeneratingResponse(false)
stopInference()

const defaultModel = model || recommendedModel

if (!model) {
Expand Down
1 change: 1 addition & 0 deletions web/hooks/useDeleteThread.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export default function useDeleteThread() {
if (thread) {
const updatedThread = {
...thread,
title: 'New Thread',
metadata: {
...thread.metadata,
title: 'New Thread',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import {
activeThreadAtom,
engineParamsUpdateAtom,
resetGeneratingResponseAtom,
} from '@/helpers/atoms/Thread.atom'

type Props = {
Expand All @@ -24,6 +25,7 @@
const { updateThreadMetadata } = useCreateNewThread()
const { stopModel } = useActiveModel()
const setEngineParamsUpdate = useSetAtom(engineParamsUpdateAtom)
const resetGenerating = useSetAtom(resetGeneratingResponseAtom)

const onValueChanged = useCallback(
(key: string, value: string | number | boolean | string[]) => {
Expand All @@ -32,6 +34,7 @@
componentData.find((x) => x.key === key)?.requireModelReload ?? false
if (shouldReloadModel) {
setEngineParamsUpdate(true)
resetGenerating()
stopModel()
}

Expand Down Expand Up @@ -78,7 +81,7 @@
],
})
},
[

Check warning on line 84 in web/screens/Thread/ThreadCenterPanel/AssistantSetting/index.tsx

View workflow job for this annotation

GitHub Actions / test-on-ubuntu

React Hook useCallback has a missing dependency: 'resetGenerating'. Either include it or remove the dependency array

Check warning on line 84 in web/screens/Thread/ThreadCenterPanel/AssistantSetting/index.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

React Hook useCallback has a missing dependency: 'resetGenerating'. Either include it or remove the dependency array

Check warning on line 84 in web/screens/Thread/ThreadCenterPanel/AssistantSetting/index.tsx

View workflow job for this annotation

GitHub Actions / test-on-macos

React Hook useCallback has a missing dependency: 'resetGenerating'. Either include it or remove the dependency array

Check warning on line 84 in web/screens/Thread/ThreadCenterPanel/AssistantSetting/index.tsx

View workflow job for this annotation

GitHub Actions / test-on-macos

React Hook useCallback has a missing dependency: 'resetGenerating'. Either include it or remove the dependency array

Check warning on line 84 in web/screens/Thread/ThreadCenterPanel/AssistantSetting/index.tsx

View workflow job for this annotation

GitHub Actions / test-on-ubuntu

React Hook useCallback has a missing dependency: 'resetGenerating'. Either include it or remove the dependency array

Check warning on line 84 in web/screens/Thread/ThreadCenterPanel/AssistantSetting/index.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

React Hook useCallback has a missing dependency: 'resetGenerating'. Either include it or remove the dependency array

Check warning on line 84 in web/screens/Thread/ThreadCenterPanel/AssistantSetting/index.tsx

View workflow job for this annotation

GitHub Actions / test-on-windows-pr

React Hook useCallback has a missing dependency: 'resetGenerating'. Either include it or remove the dependency array
activeAssistant,
activeThread,
componentData,
Expand Down
41 changes: 7 additions & 34 deletions web/screens/Thread/ThreadCenterPanel/ChatBody/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ import EmptyThread from './EmptyThread'
import { getCurrentChatMessagesAtom } from '@/helpers/atoms/ChatMessage.atom'
import {
activeThreadAtom,
isGeneratingResponseAtom,
threadStatesAtom,
isBlockingSendAtom,
} from '@/helpers/atoms/Thread.atom'

const ChatConfigurator = memo(() => {
Expand Down Expand Up @@ -65,12 +64,7 @@ const ChatBody = memo(
const prevScrollTop = useRef(0)
const isUserManuallyScrollingUp = useRef(false)
const currentThread = useAtomValue(activeThreadAtom)
const threadStates = useAtomValue(threadStatesAtom)
const isGeneratingResponse = useAtomValue(isGeneratingResponseAtom)

const isStreamingResponse = Object.values(threadStates).some(
(threadState) => threadState.waitingForResponse
)
const isBlockingSend = useAtomValue(isBlockingSendAtom)

const count = useMemo(
() => (messages?.length ?? 0) + (loadModelError ? 1 : 0),
Expand All @@ -85,34 +79,13 @@ const ChatBody = memo(
overscan: 5,
})

useEffect(() => {
if (parentRef.current) {
parentRef.current.scrollTo({ top: parentRef.current.scrollHeight })
virtualizer.scrollToIndex(count - 1)
}
}, [count, virtualizer])

useEffect(() => {
if (parentRef.current && isGeneratingResponse) {
parentRef.current.scrollTo({ top: parentRef.current.scrollHeight })
virtualizer.scrollToIndex(count - 1)
}
}, [count, virtualizer, isGeneratingResponse])

useEffect(() => {
if (parentRef.current && isGeneratingResponse) {
parentRef.current.scrollTo({ top: parentRef.current.scrollHeight })
virtualizer.scrollToIndex(count - 1)
}
}, [count, virtualizer, isGeneratingResponse, currentThread?.id])

useEffect(() => {
isUserManuallyScrollingUp.current = false
if (parentRef.current) {
if (parentRef.current && isBlockingSend) {
parentRef.current.scrollTo({ top: parentRef.current.scrollHeight })
virtualizer.scrollToIndex(count - 1)
}
}, [count, currentThread?.id, virtualizer])
}, [count, virtualizer, isBlockingSend, currentThread?.id])

const items = virtualizer.getVirtualItems()

Expand All @@ -121,7 +94,7 @@ const ChatBody = memo(
_,
instance
) => {
if (isUserManuallyScrollingUp.current === true && isStreamingResponse)
if (isUserManuallyScrollingUp.current === true && isBlockingSend)
return false
return (
// item.start < (instance.scrollOffset ?? 0) &&
Expand All @@ -133,7 +106,7 @@ const ChatBody = memo(
(event: React.UIEvent<HTMLElement>) => {
const currentScrollTop = event.currentTarget.scrollTop

if (prevScrollTop.current > currentScrollTop && isStreamingResponse) {
if (prevScrollTop.current > currentScrollTop && isBlockingSend) {
isUserManuallyScrollingUp.current = true
} else {
const currentScrollTop = event.currentTarget.scrollTop
Expand All @@ -151,7 +124,7 @@ const ChatBody = memo(
}
prevScrollTop.current = currentScrollTop
},
[isStreamingResponse]
[isBlockingSend]
)

return (
Expand Down
16 changes: 3 additions & 13 deletions web/screens/Thread/ThreadCenterPanel/ChatInput/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { useEffect, useRef, useState } from 'react'

import { InferenceEngine, MessageStatus } from '@janhq/core'

Check warning on line 4 in web/screens/Thread/ThreadCenterPanel/ChatInput/index.tsx

View workflow job for this annotation

GitHub Actions / test-on-ubuntu

'MessageStatus' is defined but never used

Check warning on line 4 in web/screens/Thread/ThreadCenterPanel/ChatInput/index.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

'MessageStatus' is defined but never used

Check warning on line 4 in web/screens/Thread/ThreadCenterPanel/ChatInput/index.tsx

View workflow job for this annotation

GitHub Actions / test-on-macos

'MessageStatus' is defined but never used

import { TextArea, Button, Tooltip, useClickOutside, Badge } from '@janhq/joi'
import { useAtom, useAtomValue } from 'jotai'
Expand Down Expand Up @@ -35,22 +35,19 @@
import { showRightPanelAtom } from '@/helpers/atoms/App.atom'
import { experimentalFeatureEnabledAtom } from '@/helpers/atoms/AppConfig.atom'
import { activeAssistantAtom } from '@/helpers/atoms/Assistant.atom'
import { getCurrentChatMessagesAtom } from '@/helpers/atoms/ChatMessage.atom'
import { selectedModelAtom } from '@/helpers/atoms/Model.atom'
import { spellCheckAtom } from '@/helpers/atoms/Setting.atom'
import {
activeSettingInputBoxAtom,
activeThreadAtom,
getActiveThreadIdAtom,
isGeneratingResponseAtom,
threadStatesAtom,
isBlockingSendAtom,
} from '@/helpers/atoms/Thread.atom'
import { activeTabThreadRightPanelAtom } from '@/helpers/atoms/ThreadRightPanel.atom'

const ChatInput = () => {
const activeThread = useAtomValue(activeThreadAtom)
const { stateModel } = useActiveModel()
const messages = useAtomValue(getCurrentChatMessagesAtom)
const spellCheck = useAtomValue(spellCheckAtom)

const [currentPrompt, setCurrentPrompt] = useAtom(currentPromptAtom)
Expand All @@ -67,8 +64,7 @@
const fileInputRef = useRef<HTMLInputElement>(null)
const imageInputRef = useRef<HTMLInputElement>(null)
const experimentalFeature = useAtomValue(experimentalFeatureEnabledAtom)
const isGeneratingResponse = useAtomValue(isGeneratingResponseAtom)
const threadStates = useAtomValue(threadStatesAtom)
const isBlockingSend = useAtomValue(isBlockingSendAtom)
const activeAssistant = useAtomValue(activeAssistantAtom)
const { stopInference } = useActiveModel()

Expand All @@ -77,10 +73,6 @@
activeTabThreadRightPanelAtom
)

const isStreamingResponse = Object.values(threadStates).some(
(threadState) => threadState.waitingForResponse
)

const refAttachmentMenus = useClickOutside(() => setShowAttacmentMenus(false))
const [showRightPanel, setShowRightPanel] = useAtom(showRightPanelAtom)

Expand Down Expand Up @@ -302,9 +294,7 @@
</div>
)}

{messages[messages.length - 1]?.status !== MessageStatus.Pending &&
!isGeneratingResponse &&
!isStreamingResponse ? (
{!isBlockingSend ? (
<>
{currentPrompt.length !== 0 && (
<Button
Expand Down
8 changes: 6 additions & 2 deletions web/screens/Thread/ThreadCenterPanel/MessageToolbar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
} from '@/helpers/atoms/ChatMessage.atom'
import {
activeThreadAtom,
isBlockingSendAtom,
updateThreadAtom,
updateThreadStateLastMessageAtom,
} from '@/helpers/atoms/Thread.atom'
Expand All @@ -43,6 +44,7 @@ const MessageToolbar = ({ message }: { message: ThreadMessage }) => {
const clipboard = useClipboard({ timeout: 1000 })
const updateThreadLastMessage = useSetAtom(updateThreadStateLastMessageAtom)
const updateThread = useSetAtom(updateThreadAtom)
const isBlockingSend = useAtomValue(isBlockingSendAtom)

const onDeleteClick = useCallback(async () => {
deleteMessage(message.id ?? '')
Expand Down Expand Up @@ -91,7 +93,8 @@ const MessageToolbar = ({ message }: { message: ThreadMessage }) => {
<div className="flex flex-row items-center">
<div className="flex gap-1 bg-[hsla(var(--app-bg))]">
{message.role === ChatCompletionRole.User &&
message.content[0]?.type === ContentType.Text && (
message.content[0]?.type === ContentType.Text &&
!isBlockingSend && (
<div
className="cursor-pointer rounded-lg border border-[hsla(var(--app-border))] p-2"
onClick={onEditClick}
Expand All @@ -110,7 +113,8 @@ const MessageToolbar = ({ message }: { message: ThreadMessage }) => {

{message.id === messages[messages.length - 1]?.id &&
!messages[messages.length - 1]?.metadata?.error &&
!messages[messages.length - 1].attachments?.length && (
!messages[messages.length - 1].attachments?.length &&
!isBlockingSend && (
<div
className="cursor-pointer rounded-lg border border-[hsla(var(--app-border))] p-2"
onClick={resendChatMessage}
Expand Down
Loading