fix: distinguish model mention sources
This commit is contained in:
parent
219dc2c8bf
commit
e066db763a
@ -102,6 +102,8 @@ const Inputbar: FC<Props> = ({ assistant: _assistant, setActiveTopic }) => {
|
|||||||
|
|
||||||
const [tokenCount, setTokenCount] = useState(0)
|
const [tokenCount, setTokenCount] = useState(0)
|
||||||
|
|
||||||
|
const [mentionFromKeyboard, setMentionFromKeyboard] = useState(false)
|
||||||
|
|
||||||
const debouncedEstimate = useCallback(
|
const debouncedEstimate = useCallback(
|
||||||
debounce((newText) => {
|
debounce((newText) => {
|
||||||
if (showInputEstimatedTokens) {
|
if (showInputEstimatedTokens) {
|
||||||
@ -192,6 +194,7 @@ const Inputbar: FC<Props> = ({ assistant: _assistant, setActiveTopic }) => {
|
|||||||
const cursorPosition = textArea.selectionStart
|
const cursorPosition = textArea.selectionStart
|
||||||
const textBeforeCursor = text.substring(0, cursorPosition)
|
const textBeforeCursor = text.substring(0, cursorPosition)
|
||||||
if (cursorPosition === 0 || textBeforeCursor.endsWith(' ')) {
|
if (cursorPosition === 0 || textBeforeCursor.endsWith(' ')) {
|
||||||
|
setMentionFromKeyboard(true)
|
||||||
EventEmitter.emit(EVENT_NAMES.SHOW_MODEL_SELECTOR)
|
EventEmitter.emit(EVENT_NAMES.SHOW_MODEL_SELECTOR)
|
||||||
setIsMentionPopupOpen(true)
|
setIsMentionPopupOpen(true)
|
||||||
return
|
return
|
||||||
@ -557,16 +560,18 @@ const Inputbar: FC<Props> = ({ assistant: _assistant, setActiveTopic }) => {
|
|||||||
setSelectedKnowledgeBases(bases ?? [])
|
setSelectedKnowledgeBases(bases ?? [])
|
||||||
}
|
}
|
||||||
|
|
||||||
const onMentionModel = (model: Model) => {
|
const onMentionModel = (model: Model, fromKeyboard: boolean = false) => {
|
||||||
const textArea = textareaRef.current?.resizableTextArea?.textArea
|
const textArea = textareaRef.current?.resizableTextArea?.textArea
|
||||||
if (textArea) {
|
if (textArea) {
|
||||||
const cursorPosition = textArea.selectionStart
|
if (fromKeyboard) {
|
||||||
const textBeforeCursor = text.substring(0, cursorPosition)
|
const cursorPosition = textArea.selectionStart
|
||||||
const lastAtIndex = textBeforeCursor.lastIndexOf('@')
|
const textBeforeCursor = text.substring(0, cursorPosition)
|
||||||
|
const lastAtIndex = textBeforeCursor.lastIndexOf('@')
|
||||||
|
|
||||||
if (lastAtIndex !== -1) {
|
if (lastAtIndex !== -1) {
|
||||||
const newText = text.substring(0, lastAtIndex) + text.substring(cursorPosition)
|
const newText = text.substring(0, lastAtIndex) + text.substring(cursorPosition)
|
||||||
setText(newText)
|
setText(newText)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
setMentionModels((prev) => [...prev, model])
|
setMentionModels((prev) => [...prev, model])
|
||||||
@ -574,6 +579,7 @@ const Inputbar: FC<Props> = ({ assistant: _assistant, setActiveTopic }) => {
|
|||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
textareaRef.current?.focus()
|
textareaRef.current?.focus()
|
||||||
}, 0)
|
}, 0)
|
||||||
|
setMentionFromKeyboard(false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -672,7 +678,7 @@ const Inputbar: FC<Props> = ({ assistant: _assistant, setActiveTopic }) => {
|
|||||||
</Tooltip>
|
</Tooltip>
|
||||||
<MentionModelsButton
|
<MentionModelsButton
|
||||||
mentionModels={mentionModels}
|
mentionModels={mentionModels}
|
||||||
onMentionModel={onMentionModel}
|
onMentionModel={(model) => onMentionModel(model, mentionFromKeyboard)}
|
||||||
ToolbarButton={ToolbarButton}
|
ToolbarButton={ToolbarButton}
|
||||||
/>
|
/>
|
||||||
<Tooltip placement="top" title={t('chat.input.web_search')} arrow>
|
<Tooltip placement="top" title={t('chat.input.web_search')} arrow>
|
||||||
|
|||||||
@ -14,7 +14,7 @@ import styled, { createGlobalStyle } from 'styled-components'
|
|||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
mentionModels: Model[]
|
mentionModels: Model[]
|
||||||
onMentionModel: (model: Model) => void
|
onMentionModel: (model: Model, fromKeyboard?: boolean) => void
|
||||||
ToolbarButton: any
|
ToolbarButton: any
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -30,6 +30,8 @@ const MentionModelsButton: FC<Props> = ({ mentionModels, onMentionModel: onSelec
|
|||||||
const itemRefs = useRef<Array<HTMLDivElement | null>>([])
|
const itemRefs = useRef<Array<HTMLDivElement | null>>([])
|
||||||
// Add a new state to track if menu was dismissed
|
// Add a new state to track if menu was dismissed
|
||||||
const [menuDismissed, setMenuDismissed] = useState(false)
|
const [menuDismissed, setMenuDismissed] = useState(false)
|
||||||
|
// Add a state to track if the model selector was triggered by keyboard
|
||||||
|
const [fromKeyboard, setFromKeyboard] = useState(false)
|
||||||
|
|
||||||
const setItemRef = (index: number, el: HTMLDivElement | null) => {
|
const setItemRef = (index: number, el: HTMLDivElement | null) => {
|
||||||
itemRefs.current[index] = el
|
itemRefs.current[index] = el
|
||||||
@ -49,7 +51,7 @@ const MentionModelsButton: FC<Props> = ({ mentionModels, onMentionModel: onSelec
|
|||||||
if (mentionModels.some((selected) => getModelUniqId(selected) === getModelUniqId(model))) {
|
if (mentionModels.some((selected) => getModelUniqId(selected) === getModelUniqId(model))) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
onSelect(model)
|
onSelect(model, fromKeyboard)
|
||||||
setIsOpen(false)
|
setIsOpen(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -190,6 +192,7 @@ const MentionModelsButton: FC<Props> = ({ mentionModels, onMentionModel: onSelec
|
|||||||
setSelectedIndex(0)
|
setSelectedIndex(0)
|
||||||
setSearchText('')
|
setSearchText('')
|
||||||
setMenuDismissed(false) // Reset dismissed flag when manually showing selector
|
setMenuDismissed(false) // Reset dismissed flag when manually showing selector
|
||||||
|
setFromKeyboard(true) // Set fromKeyboard to true when triggered by keyboard
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleKeyDown = (e: KeyboardEvent) => {
|
const handleKeyDown = (e: KeyboardEvent) => {
|
||||||
@ -307,7 +310,12 @@ const MentionModelsButton: FC<Props> = ({ mentionModels, onMentionModel: onSelec
|
|||||||
dropdownRender={() => menu}
|
dropdownRender={() => menu}
|
||||||
trigger={['click']}
|
trigger={['click']}
|
||||||
open={isOpen}
|
open={isOpen}
|
||||||
onOpenChange={setIsOpen}
|
onOpenChange={(open) => {
|
||||||
|
setIsOpen(open)
|
||||||
|
if (open) {
|
||||||
|
setFromKeyboard(false) // Set fromKeyboard to false when opened by button click
|
||||||
|
}
|
||||||
|
}}
|
||||||
overlayClassName="mention-models-dropdown">
|
overlayClassName="mention-models-dropdown">
|
||||||
<Tooltip placement="top" title={t('agents.edit.model.select.title')} arrow>
|
<Tooltip placement="top" title={t('agents.edit.model.select.title')} arrow>
|
||||||
<ToolbarButton type="text" ref={dropdownRef}>
|
<ToolbarButton type="text" ref={dropdownRef}>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user