refactor(characters): drive shared UI from active character

This commit is contained in:
2026-07-17 19:33:59 +08:00
parent 8bb1e21886
commit 7bd5defa5e
42 changed files with 335 additions and 118 deletions
+6 -1
View File
@@ -25,6 +25,7 @@ export interface LoadMoreHistoryActorEvent {
export interface ChatHistoryActorInput {
characterId: string;
emptyChatGreeting: string;
}
export interface LoadMoreHistoryOutput {
@@ -43,7 +44,10 @@ export const loadHistoryActor = fromCallback<
void (async () => {
const cacheIdentity = await resolveHistoryCacheIdentity(input.characterId);
const localSnapshot = await readLocalHistorySnapshot(cacheIdentity);
const localSnapshot = await readLocalHistorySnapshot(
cacheIdentity,
input.emptyChatGreeting,
);
if (cancelled) return;
sendBack({
type: "ChatLocalHistoryLoaded",
@@ -54,6 +58,7 @@ export const loadHistoryActor = fromCallback<
input.characterId,
localSnapshot.localCount,
cacheIdentity,
input.emptyChatGreeting,
controller.signal,
);
if (cancelled || !networkSnapshot) return;
+6 -2
View File
@@ -25,7 +25,7 @@ export interface UnlockHistoryOutput {
export const unlockHistoryActor = fromPromise<
UnlockHistoryOutput,
{ characterId: string }
{ characterId: string; emptyChatGreeting: string }
>(async ({ input, signal }) => {
const chatRepo = await loadChatRepository();
const unlockResult = await chatRepo.unlockHistory(input.characterId, {
@@ -40,7 +40,11 @@ export const unlockHistoryActor = fromPromise<
}
signal.throwIfAborted();
const history = await readAndSyncHistory(input.characterId, signal);
const history = await readAndSyncHistory(
input.characterId,
input.emptyChatGreeting,
signal,
);
return {
unlocked: unlockResult.data.unlocked,
reason: unlockResult.data.reason,
+25 -7
View File
@@ -19,20 +19,26 @@ import {
const startGuestSessionAction = unlockMachineSetup.assign(
({ context }) => ({
...createInitialChatState(context.characterId),
...createInitialChatState(
context.characterId,
context.emptyChatGreeting,
),
promotion: context.promotion,
}),
);
const startUserSessionAction = unlockMachineSetup.assign(
({ context }) => ({
...createInitialChatState(context.characterId),
...createInitialChatState(
context.characterId,
context.emptyChatGreeting,
),
promotion: context.promotion,
}),
);
const clearChatSessionAction = unlockMachineSetup.assign(({ context }) => ({
...createInitialChatState(context.characterId),
...createInitialChatState(context.characterId, context.emptyChatGreeting),
}));
const injectPromotionAction = unlockMachineSetup.assign(({ event }) => {
@@ -80,12 +86,18 @@ const guestSessionState = chatMachineSetup.createStateConfig({
{
id: "loadHistory",
src: "loadHistory",
input: ({ context }) => ({ characterId: context.characterId }),
input: ({ context }) => ({
characterId: context.characterId,
emptyChatGreeting: context.emptyChatGreeting,
}),
},
{
id: "loadMoreHistory",
src: "loadMoreHistory",
input: ({ context }) => ({ characterId: context.characterId }),
input: ({ context }) => ({
characterId: context.characterId,
emptyChatGreeting: context.emptyChatGreeting,
}),
},
],
on: {
@@ -162,12 +174,18 @@ const userSessionState = chatMachineSetup.createStateConfig({
{
id: "loadHistory",
src: "loadHistory",
input: ({ context }) => ({ characterId: context.characterId }),
input: ({ context }) => ({
characterId: context.characterId,
emptyChatGreeting: context.emptyChatGreeting,
}),
},
{
id: "loadMoreHistory",
src: "loadMoreHistory",
input: ({ context }) => ({ characterId: context.characterId }),
input: ({ context }) => ({
characterId: context.characterId,
emptyChatGreeting: context.emptyChatGreeting,
}),
},
],
on: {
+1
View File
@@ -17,6 +17,7 @@ import type { ChatState } from "../chat-state";
export interface ChatMachineInput {
characterId?: string;
emptyChatGreeting?: string;
}
export const baseChatMachineSetup = setup({
+4 -1
View File
@@ -188,7 +188,10 @@ export const unlockingHistoryState = unlockMachineSetup.createStateConfig({
invoke: {
id: "unlockHistory",
src: "unlockHistory",
input: ({ context }) => ({ characterId: context.characterId }),
input: ({ context }) => ({
characterId: context.characterId,
emptyChatGreeting: context.emptyChatGreeting,
}),
onDone: {
target: "ready",
actions: applyUnlockHistoryOutputAction,