refactor(chat): consolidate unlock state

This commit is contained in:
2026-07-16 19:49:08 +08:00
parent b5990bca8b
commit acabf165cd
7 changed files with 152 additions and 110 deletions
+16 -20
View File
@@ -117,6 +117,22 @@ const guestSessionState = chatMachineSetup.createStateConfig({
const userReadyState = chatMachineSetup.createStateConfig({
on: {
ChatNetworkHistoryLoaded: [
{
guard: ({ context, event }) =>
event.type === "ChatNetworkHistoryLoaded" &&
context.paymentUnlockPending &&
shouldPromptUnlockHistory(event.output.messages),
actions: "showUnlockHistoryPromptFromNetwork",
},
{
guard: ({ context }) => context.paymentUnlockPending,
actions: "applyNetworkHistoryLoadedAndClearPayment",
},
{
actions: "applyNetworkHistoryLoaded",
},
],
ChatSendMessage: {
guard: ({ context, event }) =>
context.canSendMessage && event.content.trim().length > 0,
@@ -158,26 +174,6 @@ const userSessionState = chatMachineSetup.createStateConfig({
target: "#chat.idle",
actions: "clearChatSession",
},
ChatNetworkHistoryLoaded: [
{
guard: ({ context, event }) =>
event.type === "ChatNetworkHistoryLoaded" &&
context.paymentUnlockPending &&
shouldPromptUnlockHistory(event.output.messages),
target: ".ready",
actions: "showUnlockHistoryPromptFromNetwork",
},
{
guard: ({ context }) => context.paymentUnlockPending,
target: ".ready",
actions: "applyNetworkHistoryLoadedAndClearPayment",
},
{
guard: ({ context }) =>
!context.isUnlockingHistory && !context.isUnlockingMessage,
actions: "applyNetworkHistoryLoaded",
},
],
ChatHistoryLoadFailed: {
actions: "markHistoryLoadFailed",
},