Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore: Fix notion, more UI enhancement #385

Merged
merged 1 commit into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions pkg/api/handlers/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
65 changes: 60 additions & 5 deletions ui/admin/app/components/knowledge/AgentKnowledgePanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
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";

Expand Down Expand Up @@ -60,19 +64,24 @@
({ agentId }) => KnowledgeService.getKnowledgeSourcesForAgent(agentId),
{
revalidateOnFocus: false,
refreshInterval: 5000,
refreshInterval:
blockPollingNotion &&
blockPollingOneDrive &&
blockPollingWebsite
? undefined
: 1000,
}
);
const knowledgeSources = useMemo(
() => getKnowledgeSources.data || [],
[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
);

Expand Down Expand Up @@ -155,6 +164,10 @@
await KnowledgeService.createKnowledgeSource(agentId, {
notionConfig: {},
});
getKnowledgeSources.mutate();
notionSource = getKnowledgeSources.data?.find(
(source) => source.notionConfig
);
}
setIsNotionModalOpen(true);
};
Expand All @@ -174,16 +187,19 @@

const startPollingNotion = () => {
getNotionFiles.mutate();
getKnowledgeSources.mutate();
setBlockPollingNotion(false);
};

const startPollingOneDrive = () => {
getOnedriveFiles.mutate();
getKnowledgeSources.mutate();
setBlockPollingOneDrive(false);
};

const startPollingWebsite = () => {
getWebsiteFiles.mutate();
getKnowledgeSources.mutate();
setBlockPollingWebsite(false);
};

Expand Down Expand Up @@ -232,6 +248,45 @@
}
}, [websiteFiles]);

useEffect(() => {
notionSource = knowledgeSources.find((source) => source.notionConfig);

Check warning on line 252 in ui/admin/app/components/knowledge/AgentKnowledgePanel.tsx

View workflow job for this annotation

GitHub Actions / lint

Assignments to the 'notionSource' variable from inside React Hook useEffect will be lost after each render. To preserve the value over time, store it in a useRef Hook and keep the mutable value in the '.current' property. Otherwise, you can move this variable directly inside useEffect
if (
!notionSource ||
notionSource?.state === KnowledgeSourceStatus.Synced
) {
getNotionFiles.mutate();
setBlockPollingNotion(true);
} else {
setBlockPollingNotion(false);
}

onedriveSource = knowledgeSources.find(

Check warning on line 263 in ui/admin/app/components/knowledge/AgentKnowledgePanel.tsx

View workflow job for this annotation

GitHub Actions / lint

Assignments to the 'onedriveSource' variable from inside React Hook useEffect will be lost after each render. To preserve the value over time, store it in a useRef Hook and keep the mutable value in the '.current' property. Otherwise, you can move this variable directly inside useEffect
(source) => source.onedriveConfig
);
if (
!onedriveSource ||
onedriveSource?.state === KnowledgeSourceStatus.Synced
) {
getOnedriveFiles.mutate();
setBlockPollingOneDrive(true);
} else {
setBlockPollingOneDrive(false);
}

websiteSource = knowledgeSources.find(

Check warning on line 276 in ui/admin/app/components/knowledge/AgentKnowledgePanel.tsx

View workflow job for this annotation

GitHub Actions / lint

Assignments to the 'websiteSource' variable from inside React Hook useEffect will be lost after each render. To preserve the value over time, store it in a useRef Hook and keep the mutable value in the '.current' property. Otherwise, you can move this variable directly inside useEffect
(source) => source.websiteCrawlingConfig
);
if (
!websiteSource ||
websiteSource?.state === KnowledgeSourceStatus.Synced
) {
getWebsiteFiles.mutate();
setBlockPollingWebsite(true);
} else {
setBlockPollingWebsite(false);
}
}, [getKnowledgeSources]);

return (
<div className="flex flex-col gap-4 justify-center items-center">
<div className="flex w-full items-center justify-between gap-3 rounded-md bg-background px-3 py-2 text-sm font-semibold text-gray-900 shadow-sm ring-1 ring-inset ring-muted-foreground/20 focus-visible:ring-transparent">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@ const RemoteKnowledgeSourceStatus: React.FC<
RemoteKnowledgeSourceStatusProps
> = ({ source, sourceType }) => {
return (
<div className="flex flex-row mt-2 flex items-center">
<div className="flex flex-row mt-2 flex items-center max-w-[80%]">
{(source?.state === KnowledgeSourceStatus.Syncing ||
source?.state === KnowledgeSourceStatus.Pending) && (
<>
<div className="flex flex-row items-center">
<RemoteFileAvatar knowledgeSourceType={sourceType} />
<span className="text-sm mr-2 text-gray-500">
<span className="text-sm mr-2 text-gray-500 flex items-center">
{source.status || "Syncing Files..."}
<LoadingSpinner className="w-4 h-4 ml-2" />
</span>
<LoadingSpinner className="w-4 h-4" />
</>
</div>
)}
{source?.state === "error" && (
{source?.state === KnowledgeSourceStatus.Error && (
<span className="text-sm mr-2 text-destructive">
{source.error}
</span>
Expand Down
3 changes: 1 addition & 2 deletions ui/admin/app/components/knowledge/notion/NotionModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
KnowledgeFile,
KnowledgeFileState,
KnowledgeSource,
KnowledgeSourceStatus,
RemoteKnowledgeSourceType,
} from "~/lib/model/knowledge";
import { KnowledgeService } from "~/lib/service/api/knowledgeService";
Expand Down Expand Up @@ -199,7 +198,7 @@ export const NotionModal: FC<NotionModalProps> = ({
{files?.some(
(item) => item.state === KnowledgeFileState.Ingesting
) && <IngestionStatusComponent files={files} />}
{knowledgeSource?.state === KnowledgeSourceStatus.Syncing && (
{!authUrl && (
<RemoteKnowledgeSourceStatus
source={knowledgeSource}
sourceType={RemoteKnowledgeSourceType.Notion}
Expand Down
11 changes: 6 additions & 5 deletions ui/admin/app/components/knowledge/onedrive/OneDriveModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,6 @@ export const OnedriveModal: FC<OnedriveModalProps> = ({
) : (
<span className="flex items-center">
Processing OneDrive link...
<LoadingSpinner className="ml-2 h-4 w-4" />
</span>
)}
</span>
Expand Down Expand Up @@ -444,10 +443,12 @@ export const OnedriveModal: FC<OnedriveModalProps> = ({
{files?.some((item) => item.approved) && (
<IngestionStatusComponent files={files} />
)}
<RemoteKnowledgeSourceStatus
source={knowledgeSource}
sourceType={RemoteKnowledgeSourceType.OneDrive}
/>
{!authUrl && (
<RemoteKnowledgeSourceStatus
source={knowledgeSource}
sourceType={RemoteKnowledgeSourceType.OneDrive}
/>
)}
<div className="mt-4 flex justify-between">
<Button
className="approve-button"
Expand Down
Loading