diff --git a/apps/chat/src/store/conversations/conversations.epics.ts b/apps/chat/src/store/conversations/conversations.epics.ts index 0db8718cdf..de32d8053f 100644 --- a/apps/chat/src/store/conversations/conversations.epics.ts +++ b/apps/chat/src/store/conversations/conversations.epics.ts @@ -777,6 +777,7 @@ const migrateConversationsIfRequiredEpic: AppEpic = (action$, state$) => { const preparedConversations = getPreparedConversations({ conversations: notMigratedConversations, conversationsFolders, + addRoot: true, }); let migratedConversationsCount = 0; diff --git a/apps/chat/src/store/prompts/prompts.epics.ts b/apps/chat/src/store/prompts/prompts.epics.ts index a88d012952..0ce29e7c7b 100644 --- a/apps/chat/src/store/prompts/prompts.epics.ts +++ b/apps/chat/src/store/prompts/prompts.epics.ts @@ -574,6 +574,7 @@ const migratePromptsIfRequiredEpic: AppEpic = (action$, state$) => { const preparedPrompts: Prompt[] = getPreparedPrompts({ prompts: notMigratedPrompts, folders: promptsFolders, + addRoot: true, }); // to send prompts with proper parentPath let migratedPromptsCount = 0; diff --git a/apps/chat/src/utils/app/data/prompt-service.ts b/apps/chat/src/utils/app/data/prompt-service.ts index 3768e2ef06..d2a17dc69a 100644 --- a/apps/chat/src/utils/app/data/prompt-service.ts +++ b/apps/chat/src/utils/app/data/prompt-service.ts @@ -1,6 +1,8 @@ import { Observable } from 'rxjs'; import { constructPath, notAllowedSymbolsRegex } from '@/src/utils/app/file'; +import { getRootId } from '@/src/utils/app/id'; +import { ApiKeys } from '@/src/utils/server/api'; import { FolderInterface } from '@/src/types/folder'; import { Prompt, PromptInfo } from '@/src/types/prompt'; @@ -48,9 +50,11 @@ export class PromptService { export const getPreparedPrompts = ({ prompts, folders, + addRoot = false, }: { prompts: Prompt[]; folders: FolderInterface[]; + addRoot?: boolean; }) => prompts.map((prompt) => { const { path } = getPathToFolderById(folders, prompt.folderId, true); @@ -58,8 +62,12 @@ export const getPreparedPrompts = ({ return { ...prompt, - id: constructPath(...[path, newName]), + id: addRoot + ? constructPath(getRootId({ apiKey: ApiKeys.Prompts }), path, newName) + : constructPath(path, newName), name: newName, - folderId: path, + folderId: addRoot + ? constructPath(getRootId({ apiKey: ApiKeys.Prompts }), path) + : path, }; }); // to send prompts with proper parentPath diff --git a/apps/chat/src/utils/app/data/storages/api/api-entity-storage.ts b/apps/chat/src/utils/app/data/storages/api/api-entity-storage.ts index 76d9a208cb..9bd3d3181b 100644 --- a/apps/chat/src/utils/app/data/storages/api/api-entity-storage.ts +++ b/apps/chat/src/utils/app/data/storages/api/api-entity-storage.ts @@ -151,7 +151,7 @@ export abstract class ApiEntityStorage< 'Content-Type': 'application/json', }, body: JSON.stringify(this.cleanUpEntity(entity)), - }).pipe(catchError(() => of())); // TODO: handle error it in https://github.com/epam/ai-dial-chat/issues/663 + }) // TODO: handle error it in https://github.com/epam/ai-dial-chat/issues/663 } updateEntity(entity: TEntity): Observable { diff --git a/apps/chat/src/utils/app/data/storages/api/conversation-api-storage.ts b/apps/chat/src/utils/app/data/storages/api/conversation-api-storage.ts index f98f3efa61..d70d5e63d2 100644 --- a/apps/chat/src/utils/app/data/storages/api/conversation-api-storage.ts +++ b/apps/chat/src/utils/app/data/storages/api/conversation-api-storage.ts @@ -1,5 +1,6 @@ import { Observable, forkJoin, of } from 'rxjs'; +import { getRootId } from '@/src/utils/app/id'; import { ApiKeys, getConversationApiKey, @@ -14,7 +15,7 @@ import { ConversationsSelectors } from '@/src/store/conversations/conversations. import { cleanConversation } from '../../../clean'; import { getGeneratedConversationId } from '../../../conversation'; -import { notAllowedSymbolsRegex } from '../../../file'; +import { constructPath, notAllowedSymbolsRegex } from '../../../file'; import { getPathToFolderById } from '../../../folders'; import { ConversationService } from '../../conversation-service'; import { ApiEntityStorage } from './api-entity-storage'; @@ -33,15 +34,19 @@ export class ConversationApiStorage extends ApiEntityStorage< model: entity.model, }; } + cleanUpEntity(conversation: Conversation): Conversation { return cleanConversation(conversation); } + getEntityKey(info: ConversationInfo): string { return getConversationApiKey(info); } + parseEntityKey(key: string): Omit { return parseConversationApiKey(key); } + getStorageKey(): ApiKeys { return ApiKeys.Conversations; } @@ -75,9 +80,11 @@ export const getOrUploadConversation = ( export const getPreparedConversations = ({ conversations, conversationsFolders, + addRoot = false, }: { conversations: Conversation[]; conversationsFolders: FolderInterface[]; + addRoot?: boolean; }) => conversations.map((conv) => { const { path } = getPathToFolderById( @@ -85,6 +92,7 @@ export const getPreparedConversations = ({ conv.folderId, true, ); + const newName = conv.name.replace(notAllowedSymbolsRegex, ''); return { @@ -95,6 +103,8 @@ export const getPreparedConversations = ({ folderId: path, }), name: newName, - folderId: path, + folderId: addRoot + ? constructPath(getRootId({ apiKey: ApiKeys.Conversations }), path) + : path, }; }); // to send conversation with proper parentPath and lastActivityDate order