From 2350b79bb5e39e9cb0faebebe3fa5ee7d6363238 Mon Sep 17 00:00:00 2001 From: Henry Estela Date: Fri, 20 Mar 2026 13:53:08 -0700 Subject: [PATCH] fix(ai-chat): small PDFs did not show up in queue or stored files this was seen when using LM Studio --- admin/inertia/components/chat/KnowledgeBaseModal.tsx | 1 + admin/inertia/hooks/useEmbedJobs.ts | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/admin/inertia/components/chat/KnowledgeBaseModal.tsx b/admin/inertia/components/chat/KnowledgeBaseModal.tsx index 508cf1e..00425d9 100644 --- a/admin/inertia/components/chat/KnowledgeBaseModal.tsx +++ b/admin/inertia/components/chat/KnowledgeBaseModal.tsx @@ -46,6 +46,7 @@ export default function KnowledgeBaseModal({ aiAssistantName = "AI Assistant", o if (fileUploaderRef.current) { fileUploaderRef.current.clear() } + queryClient.invalidateQueries({ queryKey: ['embed-jobs'] }) }, onError: (error: any) => { addNotification({ diff --git a/admin/inertia/hooks/useEmbedJobs.ts b/admin/inertia/hooks/useEmbedJobs.ts index b4e1e0c..a31cdda 100644 --- a/admin/inertia/hooks/useEmbedJobs.ts +++ b/admin/inertia/hooks/useEmbedJobs.ts @@ -1,8 +1,10 @@ +import { useEffect, useRef } from 'react' import { useQuery, useQueryClient } from '@tanstack/react-query' import api from '~/lib/api' const useEmbedJobs = (props: { enabled?: boolean } = {}) => { const queryClient = useQueryClient() + const prevCountRef = useRef(0) const queryData = useQuery({ queryKey: ['embed-jobs'], @@ -15,6 +17,15 @@ const useEmbedJobs = (props: { enabled?: boolean } = {}) => { enabled: props.enabled ?? true, }) + // When jobs drain to zero, refresh stored files so they appear without reopening the modal + useEffect(() => { + const currentCount = queryData.data?.length ?? 0 + if (prevCountRef.current > 0 && currentCount === 0) { + queryClient.invalidateQueries({ queryKey: ['storedFiles'] }) + } + prevCountRef.current = currentCount + }, [queryData.data, queryClient]) + const invalidate = () => { queryClient.invalidateQueries({ queryKey: ['embed-jobs'] }) }