feat(characters): support character-scoped conversations

This commit is contained in:
2026-07-17 11:42:31 +08:00
parent 93efcb6604
commit 2796010971
85 changed files with 1645 additions and 251 deletions
+12 -6
View File
@@ -1,7 +1,7 @@
import { fromPromise } from "xstate";
import { loadChatRepository } from "@/data/repositories/chat_repository_loader";
import { resolveChatCacheOwnerKey } from "@/data/repositories/chat_cache_identity";
import { resolveChatConversationKey } from "@/data/repositories/chat_cache_identity";
import { Logger } from "@/utils/logger";
import { Result } from "@/utils/result";
@@ -22,9 +22,12 @@ export interface UnlockHistoryOutput {
messages: UiMessage[];
}
export const unlockHistoryActor = fromPromise<UnlockHistoryOutput>(async () => {
export const unlockHistoryActor = fromPromise<
UnlockHistoryOutput,
{ characterId: string }
>(async ({ input }) => {
const chatRepo = await loadChatRepository();
const unlockResult = await chatRepo.unlockHistory();
const unlockResult = await chatRepo.unlockHistory(input.characterId);
if (Result.isErr(unlockResult)) {
log.error("[chat-machine] unlockHistoryActor failed", {
error: unlockResult.error,
@@ -32,7 +35,7 @@ export const unlockHistoryActor = fromPromise<UnlockHistoryOutput>(async () => {
throw unlockResult.error;
}
const history = await readAndSyncHistory();
const history = await readAndSyncHistory(input.characterId);
return {
unlocked: unlockResult.data.unlocked,
reason: unlockResult.data.reason,
@@ -43,11 +46,14 @@ export const unlockHistoryActor = fromPromise<UnlockHistoryOutput>(async () => {
export const unlockMessageActor = fromPromise<
UnlockMessageOutput,
UnlockMessageRequest
UnlockMessageRequest & { characterId: string }
>(async ({ input }) => {
const chatRepo = await loadChatRepository();
const cacheIdentityResult = await resolveChatCacheOwnerKey();
const cacheIdentityResult = await resolveChatConversationKey(
input.characterId,
);
const unlockResult = await chatRepo.unlockPrivateMessage({
characterId: input.characterId,
...(input.messageId ? { messageId: input.messageId } : {}),
...(input.lockType ? { lockType: input.lockType } : {}),
...(input.clientLockId ? { clientLockId: input.clientLockId } : {}),