mirror of
https://github.com/QuivrHQ/quivr.git
synced 2024-12-16 10:02:30 +03:00
8fc8c5e3ed
# Description Please include a summary of the changes and the related issue. Please also include relevant motivation and context. ## Checklist before requesting a review Please delete options that are not relevant. - [ ] My code follows the style guidelines of this project - [ ] I have performed a self-review of my code - [ ] I have commented hard-to-understand areas - [ ] I have ideally added tests that prove my fix is effective or that my feature works - [ ] New and existing unit tests pass locally with my changes - [ ] Any dependent changes have been merged ## Screenshots (if appropriate):
47 lines
1.3 KiB
TypeScript
47 lines
1.3 KiB
TypeScript
import { UUID } from "crypto";
|
|
|
|
import { useKnowledgeToFeedInput } from "@/lib/components/KnowledgeToFeedInput/hooks/useKnowledgeToFeedInput.ts";
|
|
import { useKnowledgeToFeedFilesAndUrls } from "@/lib/hooks/useKnowledgeToFeed";
|
|
import { useOnboarding } from "@/lib/hooks/useOnboarding";
|
|
|
|
type FeedBrainProps = {
|
|
brainId: UUID;
|
|
chatId: UUID;
|
|
};
|
|
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
export const useFeedBrainHandler = () => {
|
|
const { files, urls } = useKnowledgeToFeedFilesAndUrls();
|
|
const { crawlWebsiteHandler, uploadFileHandler } = useKnowledgeToFeedInput();
|
|
const { updateOnboarding, onboarding } = useOnboarding();
|
|
|
|
const updateOnboardingA = async () => {
|
|
if (onboarding.onboarding_a) {
|
|
await updateOnboarding({
|
|
onboarding_a: false,
|
|
});
|
|
}
|
|
};
|
|
|
|
const handleFeedBrain = async ({
|
|
brainId,
|
|
chatId,
|
|
}: FeedBrainProps): Promise<void> => {
|
|
const uploadPromises = files.map((file) =>
|
|
uploadFileHandler(file, brainId, chatId)
|
|
);
|
|
const crawlPromises = urls.map((url) =>
|
|
crawlWebsiteHandler(url, brainId, chatId)
|
|
);
|
|
|
|
await Promise.all([
|
|
...uploadPromises,
|
|
...crawlPromises,
|
|
updateOnboardingA(),
|
|
]);
|
|
};
|
|
|
|
return {
|
|
handleFeedBrain,
|
|
};
|
|
};
|