fix: user input slow
This commit is contained in:
parent
c8bf0d263c
commit
dc7288e11b
@ -41,9 +41,9 @@ import { openSettingsModalWithError } from '../../utils/open-settings-modal'
|
|||||||
import { PromptGenerator } from '../../utils/prompt-generator'
|
import { PromptGenerator } from '../../utils/prompt-generator'
|
||||||
|
|
||||||
import AssistantMessageActions from './AssistantMessageActions'
|
import AssistantMessageActions from './AssistantMessageActions'
|
||||||
import ChatUserInput, { ChatUserInputRef } from './chat-input/ChatUserInput'
|
import PromptInputWithActions, { ChatUserInputRef } from './chat-input/PromptInputWithActions'
|
||||||
import { editorStateToPlainText } from './chat-input/utils/editor-state-to-plain-text'
|
import { editorStateToPlainText } from './chat-input/utils/editor-state-to-plain-text'
|
||||||
import { ChatListDropdown } from './ChatListDropdown'
|
import { ChatHistory } from './ChatHistory'
|
||||||
import QueryProgress, { QueryProgressState } from './QueryProgress'
|
import QueryProgress, { QueryProgressState } from './QueryProgress'
|
||||||
import ReactMarkdown from './ReactMarkdown'
|
import ReactMarkdown from './ReactMarkdown'
|
||||||
import ShortcutInfo from './ShortcutInfo'
|
import ShortcutInfo from './ShortcutInfo'
|
||||||
@ -557,7 +557,7 @@ const Chat = forwardRef<ChatRef, ChatProps>((props, ref) => {
|
|||||||
>
|
>
|
||||||
<Plus size={18} />
|
<Plus size={18} />
|
||||||
</button>
|
</button>
|
||||||
<ChatListDropdown
|
<ChatHistory
|
||||||
chatList={chatList}
|
chatList={chatList}
|
||||||
currentConversationId={currentConversationId}
|
currentConversationId={currentConversationId}
|
||||||
onSelect={async (conversationId) => {
|
onSelect={async (conversationId) => {
|
||||||
@ -583,7 +583,7 @@ const Chat = forwardRef<ChatRef, ChatProps>((props, ref) => {
|
|||||||
className="infio-chat-list-dropdown"
|
className="infio-chat-list-dropdown"
|
||||||
>
|
>
|
||||||
<History size={18} />
|
<History size={18} />
|
||||||
</ChatListDropdown>
|
</ChatHistory>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="infio-chat-messages" ref={chatMessagesRef}>
|
<div className="infio-chat-messages" ref={chatMessagesRef}>
|
||||||
@ -604,21 +604,9 @@ const Chat = forwardRef<ChatRef, ChatProps>((props, ref) => {
|
|||||||
{chatMessages.map((message, index) =>
|
{chatMessages.map((message, index) =>
|
||||||
message.role === 'user' ? (
|
message.role === 'user' ? (
|
||||||
<div key={message.id} className="infio-chat-messages-user">
|
<div key={message.id} className="infio-chat-messages-user">
|
||||||
<ChatUserInput
|
<PromptInputWithActions
|
||||||
ref={(ref) => registerChatUserInputRef(message.id, ref)}
|
ref={(ref) => registerChatUserInputRef(message.id, ref)}
|
||||||
initialSerializedEditorState={message.content}
|
initialSerializedEditorState={message.content}
|
||||||
onChange={(content) => {
|
|
||||||
setChatMessages((prevChatHistory) =>
|
|
||||||
prevChatHistory.map((msg) =>
|
|
||||||
msg.role === 'user' && msg.id === message.id
|
|
||||||
? {
|
|
||||||
...msg,
|
|
||||||
content,
|
|
||||||
}
|
|
||||||
: msg,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
}}
|
|
||||||
onSubmit={(content, useVaultSearch) => {
|
onSubmit={(content, useVaultSearch) => {
|
||||||
if (editorStateToPlainText(content).trim() === '') return
|
if (editorStateToPlainText(content).trim() === '') return
|
||||||
handleSubmit(
|
handleSubmit(
|
||||||
@ -674,16 +662,10 @@ const Chat = forwardRef<ChatRef, ChatProps>((props, ref) => {
|
|||||||
</button>
|
</button>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
<ChatUserInput
|
<PromptInputWithActions
|
||||||
key={inputMessage.id} // this is needed to clear the editor when the user submits a new message
|
key={inputMessage.id}
|
||||||
ref={(ref) => registerChatUserInputRef(inputMessage.id, ref)}
|
ref={(ref) => registerChatUserInputRef(inputMessage.id, ref)}
|
||||||
initialSerializedEditorState={inputMessage.content}
|
initialSerializedEditorState={inputMessage.content}
|
||||||
onChange={(content) => {
|
|
||||||
setInputMessage((prevInputMessage) => ({
|
|
||||||
...prevInputMessage,
|
|
||||||
content,
|
|
||||||
}))
|
|
||||||
}}
|
|
||||||
onSubmit={(content, useVaultSearch) => {
|
onSubmit={(content, useVaultSearch) => {
|
||||||
if (editorStateToPlainText(content).trim() === '') return
|
if (editorStateToPlainText(content).trim() === '') return
|
||||||
handleSubmit(
|
handleSubmit(
|
||||||
|
|||||||
@ -106,7 +106,7 @@ function ChatListItem({
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function ChatListDropdown({
|
export function ChatHistory({
|
||||||
chatList,
|
chatList,
|
||||||
currentConversationId,
|
currentConversationId,
|
||||||
onSelect,
|
onSelect,
|
||||||
@ -33,7 +33,6 @@ import { ModelSelect } from './ModelSelect'
|
|||||||
import { MentionNode } from './plugins/mention/MentionNode'
|
import { MentionNode } from './plugins/mention/MentionNode'
|
||||||
import { NodeMutations } from './plugins/on-mutation/OnMutationPlugin'
|
import { NodeMutations } from './plugins/on-mutation/OnMutationPlugin'
|
||||||
import { SubmitButton } from './SubmitButton'
|
import { SubmitButton } from './SubmitButton'
|
||||||
import { VaultChatButton } from './VaultChatButton'
|
|
||||||
|
|
||||||
export type ChatUserInputRef = {
|
export type ChatUserInputRef = {
|
||||||
focus: () => void
|
focus: () => void
|
||||||
@ -41,7 +40,7 @@ export type ChatUserInputRef = {
|
|||||||
|
|
||||||
export type ChatUserInputProps = {
|
export type ChatUserInputProps = {
|
||||||
initialSerializedEditorState: SerializedEditorState | null
|
initialSerializedEditorState: SerializedEditorState | null
|
||||||
onChange: (content: SerializedEditorState) => void
|
onChange?: (content: SerializedEditorState) => void
|
||||||
onSubmit: (content: SerializedEditorState, useVaultSearch?: boolean) => void
|
onSubmit: (content: SerializedEditorState, useVaultSearch?: boolean) => void
|
||||||
onFocus: () => void
|
onFocus: () => void
|
||||||
mentionables: Mentionable[]
|
mentionables: Mentionable[]
|
||||||
@ -50,7 +49,7 @@ export type ChatUserInputProps = {
|
|||||||
addedBlockKey?: string | null
|
addedBlockKey?: string | null
|
||||||
}
|
}
|
||||||
|
|
||||||
const ChatUserInput = forwardRef<ChatUserInputRef, ChatUserInputProps>(
|
const PromptInputWithActions = forwardRef<ChatUserInputRef, ChatUserInputProps>(
|
||||||
(
|
(
|
||||||
{
|
{
|
||||||
initialSerializedEditorState,
|
initialSerializedEditorState,
|
||||||
@ -279,11 +278,6 @@ const ChatUserInput = forwardRef<ChatUserInputRef, ChatUserInputProps>(
|
|||||||
</div>
|
</div>
|
||||||
<div className="infio-chat-user-input-controls__buttons">
|
<div className="infio-chat-user-input-controls__buttons">
|
||||||
<SubmitButton onClick={() => handleSubmit()} />
|
<SubmitButton onClick={() => handleSubmit()} />
|
||||||
{/* <VaultChatButton
|
|
||||||
onClick={() => {
|
|
||||||
handleSubmit({ useVaultSearch: true })
|
|
||||||
}}
|
|
||||||
/> */}
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -369,6 +363,6 @@ function MentionableContentPreview({
|
|||||||
) : null
|
) : null
|
||||||
}
|
}
|
||||||
|
|
||||||
ChatUserInput.displayName = 'ChatUserInput'
|
PromptInputWithActions.displayName = 'ChatUserInput'
|
||||||
|
|
||||||
export default ChatUserInput
|
export default PromptInputWithActions
|
||||||
@ -1,42 +0,0 @@
|
|||||||
import * as Tooltip from '@radix-ui/react-tooltip'
|
|
||||||
import {
|
|
||||||
ArrowBigUp,
|
|
||||||
ChevronUp,
|
|
||||||
Command,
|
|
||||||
CornerDownLeftIcon,
|
|
||||||
} from 'lucide-react'
|
|
||||||
import { Platform } from 'obsidian'
|
|
||||||
|
|
||||||
export function VaultChatButton({ onClick }: { onClick: () => void }) {
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
<Tooltip.Provider delayDuration={0}>
|
|
||||||
<Tooltip.Root>
|
|
||||||
<Tooltip.Trigger asChild>
|
|
||||||
<button
|
|
||||||
className="infio-chat-user-input-vault-button"
|
|
||||||
onClick={onClick}
|
|
||||||
>
|
|
||||||
<div>vault</div>
|
|
||||||
<div className="infio-chat-user-input-vault-button-icons">
|
|
||||||
{Platform.isMacOS ? (
|
|
||||||
<Command size={10} />
|
|
||||||
) : (
|
|
||||||
<ChevronUp size={12} />
|
|
||||||
)}
|
|
||||||
{/* TODO: Replace with a custom icon */}
|
|
||||||
{/* <ArrowBigUp size={12} /> */}
|
|
||||||
<CornerDownLeftIcon size={12} />
|
|
||||||
</div>
|
|
||||||
</button>
|
|
||||||
</Tooltip.Trigger>
|
|
||||||
<Tooltip.Portal>
|
|
||||||
<Tooltip.Content className="infio-tooltip-content" sideOffset={5}>
|
|
||||||
Chat with your entire vault
|
|
||||||
</Tooltip.Content>
|
|
||||||
</Tooltip.Portal>
|
|
||||||
</Tooltip.Root>
|
|
||||||
</Tooltip.Provider>
|
|
||||||
</>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
@ -1,9 +1,9 @@
|
|||||||
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext'
|
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext'
|
||||||
import clsx from 'clsx'
|
import clsx from 'clsx'
|
||||||
import {
|
import {
|
||||||
$parseSerializedNode,
|
$parseSerializedNode,
|
||||||
COMMAND_PRIORITY_NORMAL,
|
COMMAND_PRIORITY_NORMAL,
|
||||||
TextNode,
|
TextNode,
|
||||||
} from 'lexical'
|
} from 'lexical'
|
||||||
import { Trash2 } from 'lucide-react'
|
import { Trash2 } from 'lucide-react'
|
||||||
import { useCallback, useEffect, useMemo, useState } from 'react'
|
import { useCallback, useEffect, useMemo, useState } from 'react'
|
||||||
@ -13,8 +13,8 @@ import { useDatabase } from '../../../../../contexts/DatabaseContext'
|
|||||||
import { SelectTemplate } from '../../../../../database/schema'
|
import { SelectTemplate } from '../../../../../database/schema'
|
||||||
import { MenuOption } from '../shared/LexicalMenu'
|
import { MenuOption } from '../shared/LexicalMenu'
|
||||||
import {
|
import {
|
||||||
LexicalTypeaheadMenuPlugin,
|
LexicalTypeaheadMenuPlugin,
|
||||||
useBasicTypeaheadTriggerMatch,
|
useBasicTypeaheadTriggerMatch,
|
||||||
} from '../typeahead-menu/LexicalTypeaheadMenuPlugin'
|
} from '../typeahead-menu/LexicalTypeaheadMenuPlugin'
|
||||||
|
|
||||||
class TemplateTypeaheadOption extends MenuOption {
|
class TemplateTypeaheadOption extends MenuOption {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user