feat: support uploading pdf in document knowledgebase

This commit is contained in:
Tanmay Deep Sharma
2025-06-26 02:41:19 +05:30
parent c42dd8a23e
commit ea3a84c930
14 changed files with 864 additions and 35 deletions
@@ -18,12 +18,29 @@ const i18nKey = 'CAPTAIN.DOCUMENTS.CREATE';
const handleSubmit = async newDocument => {
try {
await store.dispatch('captainDocuments/create', newDocument);
useAlert(t(`${i18nKey}.SUCCESS_MESSAGE`));
if (newDocument.type === 'pdf') {
// Handle PDF upload
const formData = new FormData();
formData.append('pdf_document', newDocument.pdf_document);
formData.append('assistant_id', newDocument.assistant_id);
await store.dispatch('captainDocuments/uploadPdf', formData);
useAlert('PDF uploaded successfully! Processing will begin shortly.');
} else {
// Handle URL creation
await store.dispatch('captainDocuments/create', {
document: {
external_link: newDocument.external_link,
assistant_id: newDocument.assistant_id,
},
});
useAlert('Document created successfully!');
}
dialogRef.value.close();
} catch (error) {
const errorMessage =
error?.response?.message || t(`${i18nKey}.ERROR_MESSAGE`);
error?.response?.data?.message ||
'Failed to create document. Please try again.';
useAlert(errorMessage);
}
};
@@ -42,8 +59,8 @@ defineExpose({ dialogRef });
<template>
<Dialog
ref="dialogRef"
:title="$t(`${i18nKey}.TITLE`)"
:description="$t('CAPTAIN.DOCUMENTS.FORM_DESCRIPTION')"
title="Create New Document"
description="Add a new document from a website URL or by uploading a PDF file"
:show-cancel-button="false"
:show-confirm-button="false"
@close="handleClose"