clean up chat history implementation
This commit is contained in:
parent
de10c05eef
commit
d58f721edc
2 changed files with 20 additions and 29 deletions
|
|
@ -26,6 +26,7 @@ export function KnowledgeDropdown({ active, variant = 'navigation' }: KnowledgeD
|
||||||
const [bucketUrl, setBucketUrl] = useState("s3://")
|
const [bucketUrl, setBucketUrl] = useState("s3://")
|
||||||
const [folderLoading, setFolderLoading] = useState(false)
|
const [folderLoading, setFolderLoading] = useState(false)
|
||||||
const [s3Loading, setS3Loading] = useState(false)
|
const [s3Loading, setS3Loading] = useState(false)
|
||||||
|
const [fileUploading, setFileUploading] = useState(false)
|
||||||
const fileInputRef = useRef<HTMLInputElement>(null)
|
const fileInputRef = useRef<HTMLInputElement>(null)
|
||||||
const dropdownRef = useRef<HTMLDivElement>(null)
|
const dropdownRef = useRef<HTMLDivElement>(null)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -154,6 +154,22 @@ export function Navigation() {
|
||||||
|
|
||||||
const isOnChatPage = pathname === "/" || pathname === "/chat"
|
const isOnChatPage = pathname === "/" || pathname === "/chat"
|
||||||
|
|
||||||
|
const createDefaultPlaceholder = useCallback(() => {
|
||||||
|
return {
|
||||||
|
response_id: 'new-conversation-' + Date.now(),
|
||||||
|
title: 'New conversation',
|
||||||
|
endpoint: endpoint,
|
||||||
|
messages: [{
|
||||||
|
role: 'assistant',
|
||||||
|
content: 'How can I assist?',
|
||||||
|
timestamp: new Date().toISOString()
|
||||||
|
}],
|
||||||
|
created_at: new Date().toISOString(),
|
||||||
|
last_activity: new Date().toISOString(),
|
||||||
|
total_messages: 1
|
||||||
|
} as ChatConversation
|
||||||
|
}, [endpoint])
|
||||||
|
|
||||||
const fetchConversations = useCallback(async () => {
|
const fetchConversations = useCallback(async () => {
|
||||||
setLoadingConversations(true)
|
setLoadingConversations(true)
|
||||||
try {
|
try {
|
||||||
|
|
@ -182,40 +198,14 @@ export function Navigation() {
|
||||||
|
|
||||||
// If no conversations exist and no placeholder is shown, create a default placeholder
|
// If no conversations exist and no placeholder is shown, create a default placeholder
|
||||||
if (conversations.length === 0 && !placeholderConversation) {
|
if (conversations.length === 0 && !placeholderConversation) {
|
||||||
const defaultPlaceholder: ChatConversation = {
|
setPlaceholderConversation(createDefaultPlaceholder())
|
||||||
response_id: 'new-conversation-' + Date.now(),
|
|
||||||
title: 'New conversation',
|
|
||||||
endpoint: endpoint,
|
|
||||||
messages: [{
|
|
||||||
role: 'assistant',
|
|
||||||
content: 'How can I assist?',
|
|
||||||
timestamp: new Date().toISOString()
|
|
||||||
}],
|
|
||||||
created_at: new Date().toISOString(),
|
|
||||||
last_activity: new Date().toISOString(),
|
|
||||||
total_messages: 1
|
|
||||||
}
|
|
||||||
setPlaceholderConversation(defaultPlaceholder)
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
setConversations([])
|
setConversations([])
|
||||||
|
|
||||||
// Also create placeholder when request fails and no conversations exist
|
// Also create placeholder when request fails and no conversations exist
|
||||||
if (!placeholderConversation) {
|
if (!placeholderConversation) {
|
||||||
const defaultPlaceholder: ChatConversation = {
|
setPlaceholderConversation(createDefaultPlaceholder())
|
||||||
response_id: 'new-conversation-' + Date.now(),
|
|
||||||
title: 'New conversation',
|
|
||||||
endpoint: endpoint,
|
|
||||||
messages: [{
|
|
||||||
role: 'assistant',
|
|
||||||
content: 'How can I assist?',
|
|
||||||
timestamp: new Date().toISOString()
|
|
||||||
}],
|
|
||||||
created_at: new Date().toISOString(),
|
|
||||||
last_activity: new Date().toISOString(),
|
|
||||||
total_messages: 1
|
|
||||||
}
|
|
||||||
setPlaceholderConversation(defaultPlaceholder)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -227,7 +217,7 @@ export function Navigation() {
|
||||||
} finally {
|
} finally {
|
||||||
setLoadingConversations(false)
|
setLoadingConversations(false)
|
||||||
}
|
}
|
||||||
}, [endpoint])
|
}, [endpoint, placeholderConversation, setPlaceholderConversation, createDefaultPlaceholder])
|
||||||
|
|
||||||
// Fetch chat conversations when on chat page, endpoint changes, or refresh is triggered
|
// Fetch chat conversations when on chat page, endpoint changes, or refresh is triggered
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue