feat: Enhance document processing notifications and refactor related services

- Introduced a new DocumentProcessingNotificationHandler to manage notifications for document processing stages.
- Updated existing notification methods to include detailed progress updates for various stages (queued, parsing, chunking, embedding, storing, completed, failed).
- Refactored NotificationService to support the new document processing notification type and metadata schema.
- Updated multiple document processing tasks to create and manage notifications throughout the processing lifecycle.
- Adjusted UI components to reflect changes in notification types and improve user experience during document uploads and processing.
This commit is contained in:
Anish Sarkar 2026-01-13 19:09:12 +05:30
parent 59a8ef5d64
commit 12671ede0e
7 changed files with 534 additions and 79 deletions

View file

@ -357,7 +357,7 @@ export const ComposerAddAttachment: FC = () => {
</DropdownMenuItem>
<DropdownMenuItem onClick={handleFileUpload} className="cursor-pointer">
<Upload className="size-4" />
<span>Upload Files</span>
<span>Upload Documents</span>
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>

View file

@ -1,12 +1,13 @@
import { z } from "zod";
import { searchSourceConnectorTypeEnum } from "./connector.types";
import { documentTypeEnum } from "./document.types";
/**
* Notification type enum - matches backend notification types
*/
export const notificationTypeEnum = z.enum([
"connector_indexing",
"document_processed",
"document_processing",
]);
/**
@ -18,6 +19,19 @@ export const notificationStatusEnum = z.enum([
"failed",
]);
/**
* Document processing stage enum
*/
export const documentProcessingStageEnum = z.enum([
"queued",
"parsing",
"chunking",
"embedding",
"storing",
"completed",
"failed",
]);
/**
* Base metadata schema shared across notification types
*/
@ -49,11 +63,16 @@ export const connectorIndexingMetadata = baseNotificationMetadata.extend({
});
/**
* Document processed metadata schema
* Document processing metadata schema
*/
export const documentProcessedMetadata = baseNotificationMetadata.extend({
document_id: z.number(),
status: z.string(),
export const documentProcessingMetadata = baseNotificationMetadata.extend({
document_type: documentTypeEnum,
document_name: z.string(),
processing_stage: documentProcessingStageEnum,
file_size: z.number().optional(),
chunks_count: z.number().optional(),
document_id: z.number().optional(),
error_message: z.string().nullable().optional(),
});
/**
@ -62,7 +81,7 @@ export const documentProcessedMetadata = baseNotificationMetadata.extend({
*/
export const notificationMetadata = z.union([
connectorIndexingMetadata,
documentProcessedMetadata,
documentProcessingMetadata,
baseNotificationMetadata,
]);
@ -90,19 +109,20 @@ export const connectorIndexingNotification = notification.extend({
metadata: connectorIndexingMetadata,
});
export const documentProcessedNotification = notification.extend({
type: z.literal("document_processed"),
metadata: documentProcessedMetadata,
export const documentProcessingNotification = notification.extend({
type: z.literal("document_processing"),
metadata: documentProcessingMetadata,
});
// Inferred types
export type NotificationTypeEnum = z.infer<typeof notificationTypeEnum>;
export type NotificationStatusEnum = z.infer<typeof notificationStatusEnum>;
export type DocumentProcessingStageEnum = z.infer<typeof documentProcessingStageEnum>;
export type BaseNotificationMetadata = z.infer<typeof baseNotificationMetadata>;
export type ConnectorIndexingMetadata = z.infer<typeof connectorIndexingMetadata>;
export type DocumentProcessedMetadata = z.infer<typeof documentProcessedMetadata>;
export type DocumentProcessingMetadata = z.infer<typeof documentProcessingMetadata>;
export type NotificationMetadata = z.infer<typeof notificationMetadata>;
export type Notification = z.infer<typeof notification>;
export type ConnectorIndexingNotification = z.infer<typeof connectorIndexingNotification>;
export type DocumentProcessedNotification = z.infer<typeof documentProcessedNotification>;
export type DocumentProcessingNotification = z.infer<typeof documentProcessingNotification>;