Skip to content

Commit

Permalink
chore: refactor knowledge code in admin ui
Browse files Browse the repository at this point in the history
This should have no effect on logic or UI/UX. it just extracts some subcomponents and abstracts data logic into reusable hooks.

Doing this in preparation for thread level knowledge implementations
  • Loading branch information
ryanhopperlowe committed Dec 20, 2024
1 parent d0121f8 commit a326d45
Show file tree
Hide file tree
Showing 8 changed files with 611 additions and 492 deletions.
42 changes: 10 additions & 32 deletions ui/admin/app/components/knowledge/AddSourceModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { FC, useState } from "react";

import { KNOWLEDGE_TOOL } from "~/lib/model/agents";
import { KnowledgeSourceType } from "~/lib/model/knowledge";
import { KnowledgeService } from "~/lib/service/api/knowledgeService";

import KnowledgeSourceAvatar from "~/components/knowledge/KnowledgeSourceAvatar";
import { Button } from "~/components/ui/button";
Expand All @@ -11,58 +10,39 @@ import { Input } from "~/components/ui/input";
import { Label } from "~/components/ui/label";

interface AddSourceModalProps {
agentId: string;
sourceType: KnowledgeSourceType;
startPolling: () => void;
isOpen: boolean;
onOpenChange: (open: boolean) => void;
onSave: (knowledgeSourceId: string) => void;
addTool: (tool: string) => void;
onAddWebsite: (website: string) => void;
onAddOneDrive: (link: string) => void;
}

const AddSourceModal: FC<AddSourceModalProps> = ({
agentId,
export const AddSourceModal: FC<AddSourceModalProps> = ({
sourceType,
startPolling,
isOpen,
onOpenChange,
onSave,
addTool,
onAddWebsite,
onAddOneDrive,
}) => {
const [newWebsite, setNewWebsite] = useState("");
const [newLink, setNewLink] = useState("");

const handleAddWebsite = async () => {
if (newWebsite) {
const trimmedWebsite = newWebsite.trim();
const formattedWebsite =
trimmedWebsite.startsWith("http://") ||
trimmedWebsite.startsWith("https://")
? trimmedWebsite
: `https://${trimmedWebsite}`;

const res = await KnowledgeService.createKnowledgeSource(agentId, {
websiteCrawlingConfig: {
urls: [formattedWebsite],
},
});
onSave(res.id);
startPolling();
onAddWebsite(newWebsite);
setNewWebsite("");
onOpenChange(false);
}
};

const handleAddOneDrive = async () => {
const res = await KnowledgeService.createKnowledgeSource(agentId, {
onedriveConfig: {
sharedLinks: [newLink.trim()],
},
});
onSave(res.id);
setNewLink("");
startPolling();
onOpenChange(false);
if (newLink) {
onAddOneDrive(newLink);
setNewLink("");
}
};

const handleAdd = async () => {
Expand Down Expand Up @@ -163,5 +143,3 @@ const AddSourceModal: FC<AddSourceModalProps> = ({
</Dialog>
);
};

export default AddSourceModal;
Loading

0 comments on commit a326d45

Please sign in to comment.