refactor(characters): drive shared UI from active character
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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: {
|
||||
|
||||
@@ -17,6 +17,7 @@ import type { ChatState } from "../chat-state";
|
||||
|
||||
export interface ChatMachineInput {
|
||||
characterId?: string;
|
||||
emptyChatGreeting?: string;
|
||||
}
|
||||
|
||||
export const baseChatMachineSetup = setup({
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user