-
-
Notifications
You must be signed in to change notification settings - Fork 18
feat: add chat name update functionality and improve AI response handling #1548
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -32,4 +32,12 @@ export const userAiChatRepositoryExtension: IUserAiChatRepository = { | |||||||||||||||||||||
| }); | ||||||||||||||||||||||
| return await this.save(newChat); | ||||||||||||||||||||||
| }, | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| async updateChatName(chatId: string, name: string): Promise<void> { | ||||||||||||||||||||||
| await this.createQueryBuilder() | ||||||||||||||||||||||
| .update(UserAiChatEntity) | ||||||||||||||||||||||
| .set({ name }) | ||||||||||||||||||||||
| .where('id = :chatId', { chatId }) | ||||||||||||||||||||||
|
Comment on lines
+36
to
+40
|
||||||||||||||||||||||
| async updateChatName(chatId: string, name: string): Promise<void> { | |
| await this.createQueryBuilder() | |
| .update(UserAiChatEntity) | |
| .set({ name }) | |
| .where('id = :chatId', { chatId }) | |
| async updateChatName(chatId: string, userId: string, name: string): Promise<void> { | |
| await this.createQueryBuilder() | |
| .update(UserAiChatEntity) | |
| .set({ name }) | |
| .where('id = :chatId AND user_id = :userId', { chatId, userId }) |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -5,4 +5,5 @@ export interface IUserAiChatRepository { | |||||
| findChatByIdAndUserId(chatId: string, userId: string): Promise<UserAiChatEntity | null>; | ||||||
| findChatWithMessagesByIdAndUserId(chatId: string, userId: string): Promise<UserAiChatEntity | null>; | ||||||
| createChatForUser(userId: string, name?: string): Promise<UserAiChatEntity>; | ||||||
| updateChatName(chatId: string, name: string): Promise<void>; | ||||||
|
||||||
| updateChatName(chatId: string, name: string): Promise<void>; | |
| updateChatName(chatId: string, userId: string, name: string): Promise<void>; |
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -67,6 +67,7 @@ export class RequestInfoFromTableWithAIUseCaseV7 | |||||||||
|
|
||||||||||
| let chatIdForHeader: string | null = null; | ||||||||||
| let foundUserAiChat: UserAiChatEntity | null = null; | ||||||||||
| let isNewChat = false; | ||||||||||
|
|
||||||||||
| if (ai_thread_id) { | ||||||||||
| foundUserAiChat = await this._dbContext.userAiChatRepository.findChatByIdAndUserId(ai_thread_id, user_id); | ||||||||||
|
|
@@ -78,6 +79,7 @@ export class RequestInfoFromTableWithAIUseCaseV7 | |||||||||
| if (!foundUserAiChat) { | ||||||||||
| foundUserAiChat = await this._dbContext.userAiChatRepository.createChatForUser(user_id); | ||||||||||
| chatIdForHeader = foundUserAiChat.id; | ||||||||||
| isNewChat = true; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| if (chatIdForHeader) { | ||||||||||
|
|
@@ -86,6 +88,12 @@ export class RequestInfoFromTableWithAIUseCaseV7 | |||||||||
|
|
||||||||||
| await this._dbContext.aiChatMessageRepository.saveMessage(foundUserAiChat.id, user_message, MessageRole.user); | ||||||||||
|
|
||||||||||
| if (isNewChat) { | ||||||||||
| this.generateAndUpdateChatName(foundUserAiChat.id, user_message).catch((error) => { | ||||||||||
| Sentry.captureException(error); | ||||||||||
| }); | ||||||||||
|
Comment on lines
+92
to
+94
|
||||||||||
| this.generateAndUpdateChatName(foundUserAiChat.id, user_message).catch((error) => { | |
| Sentry.captureException(error); | |
| }); | |
| void this.generateAndUpdateChatName(foundUserAiChat.id, user_message); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The block-comment stripping regex (
/\/\*[\s\S]*?\*\//g) will also remove/* ... */sequences that appear inside valid JSON string values, mutating otherwise-correct AI responses (e.g., a description containing those characters). Consider using a comment-tolerant parser (e.g., JSON5) or implementing a small scanner that removes comments only when not inside quoted strings.