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
+3 -10
View File
@@ -1,8 +1,11 @@
import { LoginStatus } from "@/data/schemas/auth";
import { AuthStorage, type IAuthStorage } from "@/data/storage/auth";
import { UserStorage, type IUserStorage } from "@/data/storage/user";
import { buildChatConversationKey } from "@/lib/chat/chat_cache_keys";
import { Result, type Result as ResultT } from "@/utils/result";
export { buildChatConversationKey } from "@/lib/chat/chat_cache_keys";
export type ChatCacheIdentityResolver = () => Promise<ResultT<string>>;
export type ChatConversationKeyResolver = (
characterId: string,
@@ -53,16 +56,6 @@ export async function resolveChatCacheOwnerKey(
return Result.err(new Error("Chat cache identity is unavailable."));
}
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:${encodeURIComponent(characterId)}`;
}
export async function resolveChatConversationKey(
characterId: string,
): Promise<ResultT<string>> {
@@ -5,16 +5,9 @@ import type {
} from "@/data/schemas/chat";
import type { CacheRemoteChatMediaInput } from "@/data/repositories/interfaces";
import { isCacheableRemoteChatMediaUrl } from "@/lib/chat/chat_media_url";
import { buildChatMediaCacheKey } from "@/lib/chat/chat_cache_keys";
export { isCacheableRemoteChatMediaUrl };
export function buildChatMediaCacheKey(input: {
ownerKey: string;
messageId: string;
kind: ChatMediaKind;
}): string {
return `${input.ownerKey}:${input.messageId}:${input.kind}`;
}
export { buildChatMediaCacheKey, isCacheableRemoteChatMediaUrl };
export function getMessageMediaTargets(
message: ChatMessage,