mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-05-05 23:42:21 +00:00
feat: add chat_cloned notification types to inbox schema
This commit is contained in:
parent
0ad59edda0
commit
a42780a2ec
1 changed files with 57 additions and 1 deletions
|
|
@ -9,6 +9,8 @@ export const inboxItemTypeEnum = z.enum([
|
|||
"connector_indexing",
|
||||
"document_processing",
|
||||
"new_mention",
|
||||
"chat_cloned",
|
||||
"chat_clone_failed",
|
||||
]);
|
||||
|
||||
/**
|
||||
|
|
@ -88,6 +90,22 @@ export const newMentionMetadata = z.object({
|
|||
content_preview: z.string(),
|
||||
});
|
||||
|
||||
/**
|
||||
* Chat cloned success metadata schema
|
||||
*/
|
||||
export const chatClonedMetadata = z.object({
|
||||
thread_id: z.number(),
|
||||
search_space_id: z.number(),
|
||||
});
|
||||
|
||||
/**
|
||||
* Chat clone failed metadata schema
|
||||
*/
|
||||
export const chatCloneFailedMetadata = z.object({
|
||||
share_token: z.string(),
|
||||
error: z.string(),
|
||||
});
|
||||
|
||||
/**
|
||||
* Union of all inbox item metadata types
|
||||
* Use this when the inbox item type is unknown
|
||||
|
|
@ -96,6 +114,8 @@ export const inboxItemMetadata = z.union([
|
|||
connectorIndexingMetadata,
|
||||
documentProcessingMetadata,
|
||||
newMentionMetadata,
|
||||
chatClonedMetadata,
|
||||
chatCloneFailedMetadata,
|
||||
baseInboxItemMetadata,
|
||||
]);
|
||||
|
||||
|
|
@ -133,6 +153,16 @@ export const newMentionInboxItem = inboxItem.extend({
|
|||
metadata: newMentionMetadata,
|
||||
});
|
||||
|
||||
export const chatClonedInboxItem = inboxItem.extend({
|
||||
type: z.literal("chat_cloned"),
|
||||
metadata: chatClonedMetadata,
|
||||
});
|
||||
|
||||
export const chatCloneFailedInboxItem = inboxItem.extend({
|
||||
type: z.literal("chat_clone_failed"),
|
||||
metadata: chatCloneFailedMetadata,
|
||||
});
|
||||
|
||||
// =============================================================================
|
||||
// API Request/Response Schemas
|
||||
// =============================================================================
|
||||
|
|
@ -229,13 +259,27 @@ export function isNewMentionMetadata(metadata: unknown): metadata is NewMentionM
|
|||
return newMentionMetadata.safeParse(metadata).success;
|
||||
}
|
||||
|
||||
/**
|
||||
* Type guard for ChatClonedMetadata
|
||||
*/
|
||||
export function isChatClonedMetadata(metadata: unknown): metadata is ChatClonedMetadata {
|
||||
return chatClonedMetadata.safeParse(metadata).success;
|
||||
}
|
||||
|
||||
/**
|
||||
* Type guard for ChatCloneFailedMetadata
|
||||
*/
|
||||
export function isChatCloneFailedMetadata(metadata: unknown): metadata is ChatCloneFailedMetadata {
|
||||
return chatCloneFailedMetadata.safeParse(metadata).success;
|
||||
}
|
||||
|
||||
/**
|
||||
* Safe metadata parser - returns typed metadata or null
|
||||
*/
|
||||
export function parseInboxItemMetadata(
|
||||
type: InboxItemTypeEnum,
|
||||
metadata: unknown
|
||||
): ConnectorIndexingMetadata | DocumentProcessingMetadata | NewMentionMetadata | null {
|
||||
): ConnectorIndexingMetadata | DocumentProcessingMetadata | NewMentionMetadata | ChatClonedMetadata | ChatCloneFailedMetadata | null {
|
||||
switch (type) {
|
||||
case "connector_indexing": {
|
||||
const result = connectorIndexingMetadata.safeParse(metadata);
|
||||
|
|
@ -249,6 +293,14 @@ export function parseInboxItemMetadata(
|
|||
const result = newMentionMetadata.safeParse(metadata);
|
||||
return result.success ? result.data : null;
|
||||
}
|
||||
case "chat_cloned": {
|
||||
const result = chatClonedMetadata.safeParse(metadata);
|
||||
return result.success ? result.data : null;
|
||||
}
|
||||
case "chat_clone_failed": {
|
||||
const result = chatCloneFailedMetadata.safeParse(metadata);
|
||||
return result.success ? result.data : null;
|
||||
}
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
|
|
@ -265,11 +317,15 @@ export type BaseInboxItemMetadata = z.infer<typeof baseInboxItemMetadata>;
|
|||
export type ConnectorIndexingMetadata = z.infer<typeof connectorIndexingMetadata>;
|
||||
export type DocumentProcessingMetadata = z.infer<typeof documentProcessingMetadata>;
|
||||
export type NewMentionMetadata = z.infer<typeof newMentionMetadata>;
|
||||
export type ChatClonedMetadata = z.infer<typeof chatClonedMetadata>;
|
||||
export type ChatCloneFailedMetadata = z.infer<typeof chatCloneFailedMetadata>;
|
||||
export type InboxItemMetadata = z.infer<typeof inboxItemMetadata>;
|
||||
export type InboxItem = z.infer<typeof inboxItem>;
|
||||
export type ConnectorIndexingInboxItem = z.infer<typeof connectorIndexingInboxItem>;
|
||||
export type DocumentProcessingInboxItem = z.infer<typeof documentProcessingInboxItem>;
|
||||
export type NewMentionInboxItem = z.infer<typeof newMentionInboxItem>;
|
||||
export type ChatClonedInboxItem = z.infer<typeof chatClonedInboxItem>;
|
||||
export type ChatCloneFailedInboxItem = z.infer<typeof chatCloneFailedInboxItem>;
|
||||
|
||||
// API Request/Response types
|
||||
export type GetNotificationsRequest = z.infer<typeof getNotificationsRequest>;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue