Skip to content

Commit ba204a0

Browse files
committed
feat: implement version 4 of AI table request and add message saving functionality
1 parent 5902822 commit ba204a0

8 files changed

Lines changed: 413 additions & 0 deletions

File tree

backend/src/common/data-injection.tokens.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ export enum UseCaseType {
159159

160160
REQUEST_INFO_FROM_TABLE_WITH_AI_V2 = 'REQUEST_INFO_FROM_TABLE_WITH_AI_V2',
161161
REQUEST_INFO_FROM_TABLE_WITH_AI_V3 = 'REQUEST_INFO_FROM_TABLE_WITH_AI_V3',
162+
REQUEST_INFO_FROM_TABLE_WITH_AI_V4 = 'REQUEST_INFO_FROM_TABLE_WITH_AI_V4',
162163
REQUEST_AI_SETTINGS_AND_WIDGETS_CREATION = 'REQUEST_AI_SETTINGS_AND_WIDGETS_CREATION',
163164
FIND_USER_AI_CHATS = 'FIND_USER_AI_CHATS',
164165
FIND_USER_AI_CHAT_BY_ID = 'FIND_USER_AI_CHAT_BY_ID',

backend/src/entities/ai/ai-conversation-history/ai-chat-messages/repository/ai-chat-message-repository.extension.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { IAiChatMessageRepository } from './ai-chat-message-repository.interface.js';
22
import { AiChatMessageEntity } from '../ai-chat-message.entity.js';
3+
import { MessageRole } from '../message-role.enum.js';
34

45
export const aiChatMessageRepositoryExtension: IAiChatMessageRepository = {
56
async findMessagesForChat(chatId: string): Promise<AiChatMessageEntity[]> {
@@ -16,4 +17,13 @@ export const aiChatMessageRepositoryExtension: IAiChatMessageRepository = {
1617
.where('ai_chat_id = :chatId', { chatId })
1718
.execute();
1819
},
20+
21+
async saveMessage(chatId: string, message: string, role: MessageRole): Promise<AiChatMessageEntity> {
22+
const newMessage = this.create({
23+
ai_chat_id: chatId,
24+
message,
25+
role,
26+
});
27+
return await this.save(newMessage);
28+
},
1929
};
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { AiChatMessageEntity } from '../ai-chat-message.entity.js';
2+
import { MessageRole } from '../message-role.enum.js';
23

34
export interface IAiChatMessageRepository {
45
findMessagesForChat(chatId: string): Promise<AiChatMessageEntity[]>;
56
deleteMessagesForChat(chatId: string): Promise<void>;
7+
saveMessage(chatId: string, message: string, role: MessageRole): Promise<AiChatMessageEntity>;
68
}

backend/src/entities/ai/ai-conversation-history/user-ai-chat/repository/user-ai-chat-repository.extension.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,12 @@ export const userAiChatRepositoryExtension: IUserAiChatRepository = {
2424
.orderBy('messages.created_at', 'ASC')
2525
.getOne();
2626
},
27+
28+
async createChatForUser(userId: string, name?: string): Promise<UserAiChatEntity> {
29+
const newChat = this.create({
30+
user_id: userId,
31+
name: name || null,
32+
});
33+
return await this.save(newChat);
34+
},
2735
};

backend/src/entities/ai/ai-conversation-history/user-ai-chat/repository/user-ai-chat-repository.interface.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ export interface IUserAiChatRepository {
44
findAllChatsForUser(userId: string): Promise<UserAiChatEntity[]>;
55
findChatByIdAndUserId(chatId: string, userId: string): Promise<UserAiChatEntity | null>;
66
findChatWithMessagesByIdAndUserId(chatId: string, userId: string): Promise<UserAiChatEntity | null>;
7+
createChatForUser(userId: string, name?: string): Promise<UserAiChatEntity>;
78
}

backend/src/entities/ai/ai.module.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { AiService } from './ai.service.js';
99
import { RequestAISettingsAndWidgetsCreationUseCase } from './use-cases/request-ai-settings-and-widgets-creation.use.case.js';
1010
import { RequestInfoFromTableWithAIUseCaseV5 } from './use-cases/request-info-from-table-with-ai-v5.use.case.js';
1111
import { RequestInfoFromTableWithAIUseCaseV6 } from './use-cases/request-info-from-table-with-ai-v6.use.case.js';
12+
import { RequestInfoFromTableWithAIUseCaseV7 } from './use-cases/request-info-from-table-with-ai-v7.use.case.js';
1213
import { UserAIRequestsControllerV2 } from './user-ai-requests-v2.controller.js';
1314
import { UserAiChatController } from './ai-conversation-history/user-ai-chat.controller.js';
1415
import { FindUserAiChatsUseCase } from './ai-conversation-history/use-cases/find-user-ai-chats.use.case.js';
@@ -33,6 +34,10 @@ import { AiChatMessageEntity } from './ai-conversation-history/ai-chat-messages/
3334
provide: UseCaseType.REQUEST_INFO_FROM_TABLE_WITH_AI_V3,
3435
useClass: RequestInfoFromTableWithAIUseCaseV6,
3536
},
37+
{
38+
provide: UseCaseType.REQUEST_INFO_FROM_TABLE_WITH_AI_V4,
39+
useClass: RequestInfoFromTableWithAIUseCaseV7,
40+
},
3641
{
3742
provide: UseCaseType.REQUEST_AI_SETTINGS_AND_WIDGETS_CREATION,
3843
useClass: RequestAISettingsAndWidgetsCreationUseCase,
@@ -61,6 +66,7 @@ export class AIModule implements NestModule {
6166
.forRoutes(
6267
{ path: '/ai/v2/request/:connectionId', method: RequestMethod.POST },
6368
{ path: '/ai/v3/request/:connectionId', method: RequestMethod.POST },
69+
{ path: '/ai/v4/request/:connectionId', method: RequestMethod.POST },
6470
{ path: '/ai/v2/setup/:connectionId', method: RequestMethod.GET },
6571
{ path: '/ai/chats', method: RequestMethod.GET },
6672
{ path: '/ai/chats/:chatId', method: RequestMethod.GET },

0 commit comments

Comments
 (0)