diff --git a/pkg/api/handlers/agent.go b/pkg/api/handlers/agent.go index c47bbc977..0746cc4c9 100644 --- a/pkg/api/handlers/agent.go +++ b/pkg/api/handlers/agent.go @@ -417,12 +417,6 @@ func (a *AgentHandler) ReSyncKnowledgeSource(req api.Context) error { return err } - knowledgeSource.Status.SyncState = types.KnowledgeSourceStatePending - knowledgeSource.Status.Status = "" - if err := req.Storage.Status().Update(req.Context(), &knowledgeSource); err != nil { - return err - } - req.WriteHeader(http.StatusNoContent) return nil } diff --git a/ui/admin/app/components/knowledge/AgentKnowledgePanel.tsx b/ui/admin/app/components/knowledge/AgentKnowledgePanel.tsx index 8c406031a..dd360613d 100644 --- a/ui/admin/app/components/knowledge/AgentKnowledgePanel.tsx +++ b/ui/admin/app/components/knowledge/AgentKnowledgePanel.tsx @@ -2,7 +2,11 @@ import { Globe, SettingsIcon, UploadIcon } from "lucide-react"; import { useEffect, useMemo, useState } from "react"; import useSWR, { SWRResponse } from "swr"; -import { KnowledgeFile, KnowledgeFileState } from "~/lib/model/knowledge"; +import { + KnowledgeFile, + KnowledgeFileState, + KnowledgeSourceStatus, +} from "~/lib/model/knowledge"; import { KnowledgeService } from "~/lib/service/api/knowledgeService"; import { assetUrl } from "~/lib/utils"; @@ -60,7 +64,12 @@ export default function AgentKnowledgePanel({ agentId }: { agentId: string }) { ({ agentId }) => KnowledgeService.getKnowledgeSourcesForAgent(agentId), { revalidateOnFocus: false, - refreshInterval: 5000, + refreshInterval: + blockPollingNotion && + blockPollingOneDrive && + blockPollingWebsite + ? undefined + : 1000, } ); const knowledgeSources = useMemo( @@ -68,11 +77,11 @@ export default function AgentKnowledgePanel({ agentId }: { agentId: string }) { [getKnowledgeSources.data] ); - const notionSource = knowledgeSources.find((source) => source.notionConfig); - const onedriveSource = knowledgeSources.find( + let notionSource = knowledgeSources.find((source) => source.notionConfig); + let onedriveSource = knowledgeSources.find( (source) => source.onedriveConfig ); - const websiteSource = knowledgeSources.find( + let websiteSource = knowledgeSources.find( (source) => source.websiteCrawlingConfig ); @@ -155,6 +164,10 @@ export default function AgentKnowledgePanel({ agentId }: { agentId: string }) { await KnowledgeService.createKnowledgeSource(agentId, { notionConfig: {}, }); + getKnowledgeSources.mutate(); + notionSource = getKnowledgeSources.data?.find( + (source) => source.notionConfig + ); } setIsNotionModalOpen(true); }; @@ -174,16 +187,19 @@ export default function AgentKnowledgePanel({ agentId }: { agentId: string }) { const startPollingNotion = () => { getNotionFiles.mutate(); + getKnowledgeSources.mutate(); setBlockPollingNotion(false); }; const startPollingOneDrive = () => { getOnedriveFiles.mutate(); + getKnowledgeSources.mutate(); setBlockPollingOneDrive(false); }; const startPollingWebsite = () => { getWebsiteFiles.mutate(); + getKnowledgeSources.mutate(); setBlockPollingWebsite(false); }; @@ -232,6 +248,45 @@ export default function AgentKnowledgePanel({ agentId }: { agentId: string }) { } }, [websiteFiles]); + useEffect(() => { + notionSource = knowledgeSources.find((source) => source.notionConfig); + if ( + !notionSource || + notionSource?.state === KnowledgeSourceStatus.Synced + ) { + getNotionFiles.mutate(); + setBlockPollingNotion(true); + } else { + setBlockPollingNotion(false); + } + + onedriveSource = knowledgeSources.find( + (source) => source.onedriveConfig + ); + if ( + !onedriveSource || + onedriveSource?.state === KnowledgeSourceStatus.Synced + ) { + getOnedriveFiles.mutate(); + setBlockPollingOneDrive(true); + } else { + setBlockPollingOneDrive(false); + } + + websiteSource = knowledgeSources.find( + (source) => source.websiteCrawlingConfig + ); + if ( + !websiteSource || + websiteSource?.state === KnowledgeSourceStatus.Synced + ) { + getWebsiteFiles.mutate(); + setBlockPollingWebsite(true); + } else { + setBlockPollingWebsite(false); + } + }, [getKnowledgeSources]); + return (
diff --git a/ui/admin/app/components/knowledge/RemoteKnowledgeSourceStatus.tsx b/ui/admin/app/components/knowledge/RemoteKnowledgeSourceStatus.tsx index 31d1663de..bb47a932d 100644 --- a/ui/admin/app/components/knowledge/RemoteKnowledgeSourceStatus.tsx +++ b/ui/admin/app/components/knowledge/RemoteKnowledgeSourceStatus.tsx @@ -19,18 +19,18 @@ const RemoteKnowledgeSourceStatus: React.FC< RemoteKnowledgeSourceStatusProps > = ({ source, sourceType }) => { return ( -
+
{(source?.state === KnowledgeSourceStatus.Syncing || source?.state === KnowledgeSourceStatus.Pending) && ( - <> +
- + {source.status || "Syncing Files..."} + - - +
)} - {source?.state === "error" && ( + {source?.state === KnowledgeSourceStatus.Error && ( {source.error} diff --git a/ui/admin/app/components/knowledge/notion/NotionModal.tsx b/ui/admin/app/components/knowledge/notion/NotionModal.tsx index 620eef1aa..f82882707 100644 --- a/ui/admin/app/components/knowledge/notion/NotionModal.tsx +++ b/ui/admin/app/components/knowledge/notion/NotionModal.tsx @@ -5,7 +5,6 @@ import { KnowledgeFile, KnowledgeFileState, KnowledgeSource, - KnowledgeSourceStatus, RemoteKnowledgeSourceType, } from "~/lib/model/knowledge"; import { KnowledgeService } from "~/lib/service/api/knowledgeService"; @@ -199,7 +198,7 @@ export const NotionModal: FC = ({ {files?.some( (item) => item.state === KnowledgeFileState.Ingesting ) && } - {knowledgeSource?.state === KnowledgeSourceStatus.Syncing && ( + {!authUrl && ( = ({ ) : ( Processing OneDrive link... - )} @@ -444,10 +443,12 @@ export const OnedriveModal: FC = ({ {files?.some((item) => item.approved) && ( )} - + {!authUrl && ( + + )}
- -
- {websites.map((website, index) => ( - + {websites.map((website, index) => ( + + {/* eslint-disable-next-line */} +
{ + if ( + showTable[index] === undefined || + showTable[index] === false + ) { + setShowTable((prev) => ({ + ...prev, + [index]: true, + })); + } else { + setShowTable((prev) => ({ + ...prev, + [index]: false, + })); + } + }} > - {/* eslint-disable-next-line */} -
{ - if ( - showTable[index] === undefined || - showTable[index] === false - ) { - setShowTable((prev) => ({ - ...prev, - [index]: true, - })); - } else { - setShowTable((prev) => ({ - ...prev, - [index]: false, - })); - } - }} - > - - - - - {showTable[index] ? ( - - ) : ( - - )} -
- {showTable[index] && ( -
- {files - .filter((item) => { - return ( - knowledgeSource?.syncDetails - ?.websiteCrawlingState - ?.pages?.[item.url!] - ?.parentURL === website - ); - }) - .sort((a, b) => - a.url!.localeCompare(b.url!) - ) - .map((item) => ( - { - await KnowledgeService.approveFile( - agentId, - file.id, - approved - ); - startPolling(); - }} - reingestFile={(file) => { - KnowledgeService.reingestFile( - file.agentID, - file.knowledgeSourceID, - file.id - ); - startPolling(); - }} - /> - ))} + + + + + {showTable[index] ? ( + + ) : ( + )} - - ))} -
- +
+ {showTable[index] && ( +
+ {files + .filter((item) => { + return ( + knowledgeSource?.syncDetails + ?.websiteCrawlingState + ?.pages?.[item.url!] + ?.parentURL === website + ); + }) + .sort((a, b) => + a.url!.localeCompare(b.url!) + ) + .map((item) => ( + { + await KnowledgeService.approveFile( + agentId, + file.id, + approved + ); + startPolling(); + }} + reingestFile={(file) => { + KnowledgeService.reingestFile( + file.agentID, + file.knowledgeSourceID, + file.id + ); + startPolling(); + }} + /> + ))} +
+ )} +
+ ))} +
{files?.some((item) => item.approved) && (