fix(chat): migrate legacy cache to Elio conversation
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
import type { ChatMediaKind } from "@/data/schemas/chat";
|
||||
|
||||
const CHARACTER_NAMESPACE = "::character:";
|
||||
const LEGACY_OWNER_KEY_PATTERN = /^(?:user|device):.+$/u;
|
||||
|
||||
export function buildChatConversationKey(
|
||||
ownerKey: string,
|
||||
characterId: string,
|
||||
): string {
|
||||
if (ownerKey.trim().length === 0 || characterId.trim().length === 0) {
|
||||
throw new Error("Chat owner and character identities must not be empty.");
|
||||
}
|
||||
return `${ownerKey}${CHARACTER_NAMESPACE}${encodeURIComponent(characterId)}`;
|
||||
}
|
||||
|
||||
export function buildChatMediaCacheKey(input: {
|
||||
ownerKey: string;
|
||||
messageId: string;
|
||||
kind: ChatMediaKind;
|
||||
}): string {
|
||||
return `${input.ownerKey}:${input.messageId}:${input.kind}`;
|
||||
}
|
||||
|
||||
export function isLegacyChatCacheOwnerKey(ownerKey: string): boolean {
|
||||
return (
|
||||
!ownerKey.includes(CHARACTER_NAMESPACE) &&
|
||||
LEGACY_OWNER_KEY_PATTERN.test(ownerKey)
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user