Skip to content
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

fix(chat): fix automigration icons (Issue #265) #708

Merged
merged 2 commits into from
Feb 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 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,13 @@ 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';
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 +36,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 +50,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 +60,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 +132,7 @@ export class ApiStorage implements DialStorage {
conv,
[...conversations, ...apiConversations],
this._conversationApiStorage,
BackendResourceType.CONVERSATION,
),
),
),
Expand Down Expand Up @@ -169,6 +175,7 @@ export class ApiStorage implements DialStorage {
prompt,
[...prompts, ...apiPrompts],
this._promptApiStorage,
BackendResourceType.PROMPT,
),
),
),
Expand Down
Loading