diff --git a/packages/api/src/chats/chat-socket.gateway.ts b/packages/api/src/chats/chat-socket.gateway.ts index 043083b..48c6b38 100644 --- a/packages/api/src/chats/chat-socket.gateway.ts +++ b/packages/api/src/chats/chat-socket.gateway.ts @@ -95,6 +95,14 @@ export class ChatSocketGateway { id: data.id, response: aiResponse.output, isAi: true, + ...(aiResponse.document + ? { + source: { + filename: aiResponse.document, + snippets: aiResponse.source.map((source) => source.pageContent), + }, + } + : {}), createdAt: new Date().toISOString(), }) ); diff --git a/packages/api/src/chats/factory/create-socket-message.factory.ts b/packages/api/src/chats/factory/create-socket-message.factory.ts index 0fa2995..6fc1a11 100644 --- a/packages/api/src/chats/factory/create-socket-message.factory.ts +++ b/packages/api/src/chats/factory/create-socket-message.factory.ts @@ -1,3 +1,4 @@ +import { SourceMeta } from '@/common/types/chat'; import { SocketMessageResponseDto } from '@/contract/chats/socket-message.response.dto'; interface CreateSocketMessageResponseFactoryType { @@ -6,6 +7,7 @@ interface CreateSocketMessageResponseFactoryType { isAi: boolean; createdAt: string; userId?: string; + source?: SourceMeta; } export const createSocketMessageResponseFactory = ({ id, @@ -13,6 +15,7 @@ export const createSocketMessageResponseFactory = ({ isAi, createdAt, userId, + source, }: CreateSocketMessageResponseFactoryType): SocketMessageResponseDto => { return { id, @@ -20,5 +23,6 @@ export const createSocketMessageResponseFactory = ({ isAi, createdAt, userId, + source, }; }; diff --git a/packages/contract/chats/socket-message.response.dto.ts b/packages/contract/chats/socket-message.response.dto.ts index add4dc1..aaebcfe 100644 --- a/packages/contract/chats/socket-message.response.dto.ts +++ b/packages/contract/chats/socket-message.response.dto.ts @@ -3,5 +3,6 @@ export interface SocketMessageResponseDto { response: string; isAi: boolean; userId?: string; + source?: { filename: string; snippets: string[] }; createdAt: string; } diff --git a/packages/web-ui/factory/create-chat.factory.ts b/packages/web-ui/factory/create-chat.factory.ts index f970d49..c896d27 100644 --- a/packages/web-ui/factory/create-chat.factory.ts +++ b/packages/web-ui/factory/create-chat.factory.ts @@ -15,6 +15,7 @@ export const createChatMessageFactory = ( id: message.id, content: message.content, response: aiMessage?.content, + source: aiMessage?.meta?.source, createdAt: message.createdAt, user, }; @@ -65,6 +66,7 @@ export const createChatMessagesWithResponseFactory = ( id: message.id, content: message.content, response: response.response, + source: response.source, createdAt: message.createdAt, user: message.user, }; diff --git a/packages/web-ui/types/chat.ts b/packages/web-ui/types/chat.ts index 734db23..7b3a7ad 100644 --- a/packages/web-ui/types/chat.ts +++ b/packages/web-ui/types/chat.ts @@ -3,6 +3,7 @@ export interface ChatMessageType { content: string; response?: string; user?: ChatUserType; + source?: ChatMessageSourceType; createdAt: string; } @@ -20,3 +21,8 @@ export interface SocketMessageType { content: string; userId: string; } + +export interface ChatMessageSourceType { + filename: string; + snippets: string[]; +}