Skip to content

Commit

Permalink
fix(chat): fix ids (Issue #265)
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander-Kezik committed Feb 14, 2024
1 parent 8d68df1 commit 47db4dd
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 5 deletions.
1 change: 1 addition & 0 deletions apps/chat/src/store/conversations/conversations.epics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -777,6 +777,7 @@ const migrateConversationsIfRequiredEpic: AppEpic = (action$, state$) => {
const preparedConversations = getPreparedConversations({
conversations: notMigratedConversations,
conversationsFolders,
addRoot: true,
});

let migratedConversationsCount = 0;
Expand Down
1 change: 1 addition & 0 deletions apps/chat/src/store/prompts/prompts.epics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 10 additions & 2 deletions apps/chat/src/utils/app/data/prompt-service.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -48,18 +50,24 @@ 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);
const newName = prompt.name.replace(notAllowedSymbolsRegex, '');

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
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Observable, forkJoin, of } from 'rxjs';

import { getRootId } from '@/src/utils/app/id';
import {
ApiKeys,
getConversationApiKey,
Expand All @@ -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';
Expand All @@ -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<ConversationInfo, 'folderId'> {
return parseConversationApiKey(key);
}

getStorageKey(): ApiKeys {
return ApiKeys.Conversations;
}
Expand Down Expand Up @@ -75,16 +80,19 @@ export const getOrUploadConversation = (
export const getPreparedConversations = ({
conversations,
conversationsFolders,
addRoot = false,
}: {
conversations: Conversation[];
conversationsFolders: FolderInterface[];
addRoot?: boolean;
}) =>
conversations.map((conv) => {
const { path } = getPathToFolderById(
conversationsFolders,
conv.folderId,
true,
);

const newName = conv.name.replace(notAllowedSymbolsRegex, '');

return {
Expand All @@ -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

0 comments on commit 47db4dd

Please sign in to comment.