Skip to content

Commit

Permalink
fix(tabby-ui): fix chat panel store session state for input message. (#…
Browse files Browse the repository at this point in the history
icycodes authored Jan 23, 2025
1 parent c8fa598 commit d46403d
Showing 2 changed files with 16 additions and 10 deletions.
5 changes: 4 additions & 1 deletion ee/tabby-ui/components/chat/chat-panel.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { RefObject, useMemo, useState } from 'react'
import slugify from '@sindresorhus/slugify'
import { Content } from '@tiptap/core'
import { Content, EditorEvents } from '@tiptap/core'
import { useWindowSize } from '@uidotdev/usehooks'
import type { UseChatHelpers } from 'ai/react'
import { AnimatePresence, motion } from 'framer-motion'
@@ -51,6 +51,7 @@ export interface ChatPanelProps extends Pick<UseChatHelpers, 'stop' | 'input'> {
id?: string
className?: string
onSubmit: (content: string) => Promise<any>
onUpdate: (p: EditorEvents['update']) => void
reload: () => void
chatMaxWidthClass: string
chatInputRef: RefObject<PromptFormRef>
@@ -68,6 +69,7 @@ function ChatPanelRenderer(
reload,
className,
onSubmit,
onUpdate,
chatMaxWidthClass,
chatInputRef
}: ChatPanelProps,
@@ -380,6 +382,7 @@ function ChatPanelRenderer(
<PromptForm
ref={chatInputRef}
onSubmit={onSubmit}
onUpdate={onUpdate}
isLoading={isLoading}
/>
<FooterText className="hidden sm:block" />
21 changes: 12 additions & 9 deletions ee/tabby-ui/components/chat/chat.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { RefObject } from 'react'
import { Content } from '@tiptap/core'
import { Content, EditorEvents } from '@tiptap/core'
import {
compact,
findIndex,
@@ -153,7 +153,7 @@ interface ChatProps extends React.ComponentProps<'div'> {
export interface SessionState {
threadId?: string | undefined
qaPairs?: QuestionAnswerPair[] | undefined
input?: string | undefined
input?: Content | undefined
relevantContext?: Context[] | undefined
selectedRepoId?: string | undefined
}
@@ -220,11 +220,11 @@ function ChatRenderer(
}
const input = chatPanelRef.current?.input ?? ''

React.useEffect(() => {
const onUpdate = (p: EditorEvents['update']) => {
if (isDataSetup) {
storeSessionState?.({ input })
storeSessionState?.({ input: p.editor.getJSON() })
}
}, [input, isDataSetup, storeSessionState])
}

const [{ data: repositoryListData, fetching: fetchingRepos }] = useQuery({
query: repositorySourceListQuery
@@ -613,10 +613,12 @@ function ChatRenderer(
}, [qaPairs])

React.useEffect(() => {
storeSessionState?.({
relevantContext
})
}, [relevantContext, storeSessionState])
if (isDataSetup) {
storeSessionState?.({
relevantContext
})
}
}, [relevantContext, isDataSetup, storeSessionState])

const debouncedUpdateActiveSelection = useDebounceCallback(
(ctx: Context | null) => {
@@ -779,6 +781,7 @@ function ChatRenderer(
reload={onReload}
input={input}
setInput={setInput}
onUpdate={onUpdate}
chatMaxWidthClass={chatMaxWidthClass}
ref={chatPanelRef}
chatInputRef={chatInputRef}

0 comments on commit d46403d

Please sign in to comment.