fix(chat): migrate legacy cache to Elio conversation

This commit is contained in:
2026-07-17 19:04:41 +08:00
parent 5bfb71e2b8
commit a30e9937b8
7 changed files with 308 additions and 20 deletions
+29
View File
@@ -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)
);
}