Skip to content

Commit

Permalink
fix(chat): fix automigration icons (Issue #265)
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander-Kezik committed Feb 14, 2024
1 parent bf250fd commit 13d5560
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions apps/chat/src/utils/app/data/storages/api-storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ import {
throwError,
} from 'rxjs';

import { regenerateConversationId } from '@/src/utils/app/conversation';
import { ApiEntityStorage } from '@/src/utils/app/data/storages/api/api-entity-storage';
import { constructPath } from '@/src/utils/app/file';

Check failure on line 12 in apps/chat/src/utils/app/data/storages/api-storage.ts

View workflow job for this annotation

GitHub Actions / run_tests / style_checks

'constructPath' is defined but never used. Allowed unused vars must match /^__/u
import { generateNextName } from '@/src/utils/app/folders';
import { addGeneratedPromptId } from '@/src/utils/app/prompts';

import { Conversation, ConversationInfo } from '@/src/types/chat';
import { Entity } from '@/src/types/common';
import { BackendResourceType, Entity } from '@/src/types/common';
import { FolderInterface, FoldersAndEntities } from '@/src/types/folder';
import { Prompt, PromptInfo } from '@/src/types/prompt';
import { DialStorage } from '@/src/types/storage';
Expand All @@ -35,12 +37,12 @@ export class ApiStorage implements DialStorage {
entity: T,
entities: T[],
apiStorage: ApiEntityStorage<T, T>,
entityType: BackendResourceType,
): Observable<void> {
let retries = 0;

const retry = (
entity: T,
entities: T[],
apiStorage: ApiEntityStorage<T, T>,
): Observable<void> =>
apiStorage.createEntity(entity).pipe(
Expand All @@ -49,7 +51,7 @@ export class ApiStorage implements DialStorage {
retries++;

const defaultName =
'messages' in entity
entityType === BackendResourceType.CONVERSATION
? DEFAULT_CONVERSATION_NAME
: DEFAULT_PROMPT_NAME;
const newName = generateNextName(
Expand All @@ -59,18 +61,22 @@ export class ApiStorage implements DialStorage {
);
const updatedEntity = {
...entity,
id: constructPath(entity.folderId, newName),
name: newName,
};

return retry(updatedEntity, entities, apiStorage);
const updatedEntityWithRegeneratedId =
entityType === BackendResourceType.CONVERSATION
? regenerateConversationId(updatedEntity as Conversation)
: addGeneratedPromptId(updatedEntity as Prompt);

return retry(updatedEntityWithRegeneratedId as T, apiStorage);
}

return throwError(() => err);
}),
);

return retry(entity, entities, apiStorage);
return retry(entity, apiStorage);
}

getConversationsFolders(path?: string): Observable<FolderInterface[]> {
Expand Down Expand Up @@ -127,6 +133,7 @@ export class ApiStorage implements DialStorage {
conv,
[...conversations, ...apiConversations],
this._conversationApiStorage,
BackendResourceType.CONVERSATION,
),
),
),
Expand Down Expand Up @@ -169,6 +176,7 @@ export class ApiStorage implements DialStorage {
prompt,
[...prompts, ...apiPrompts],
this._promptApiStorage,
BackendResourceType.PROMPT,
),
),
),
Expand Down

0 comments on commit 13d5560

Please sign in to comment.