refactor(chat): reorganize helper functions and update imports

This commit is contained in:
2026-07-15 10:59:23 +08:00
parent 2b90f90ab0
commit ed3e800245
20 changed files with 27 additions and 29 deletions
@@ -7,7 +7,7 @@ import {
countLockedHistoryMessages,
localMessagesToUi,
sendResponseToUiMessage,
} from "@/stores/chat/chat-machine.helpers";
} from "@/stores/chat/helper";
function makeResponse(
overrides: Partial<Parameters<typeof ChatSendResponse.from>[0]> = {},
@@ -10,7 +10,7 @@ import type { ChatEvent } from "@/stores/chat/chat-events";
import type {
UnlockMessageOutput as MachineUnlockMessageOutput,
UnlockMessageRequest,
} from "@/stores/chat/chat-machine.helpers";
} from "@/stores/chat/helper/unlock";
export interface SendMessageHttpOutput {
response: ChatSendResponse;
@@ -6,7 +6,7 @@ import {
appendPromotionMessage,
applyPromotionUnlockOutput,
createChatPromotionState,
} from "@/stores/chat/chat-promotion";
} from "@/stores/chat/helper/promotion";
const promotion: PendingChatPromotion = {
promotionType: "image",
+1 -1
View File
@@ -6,7 +6,7 @@ import type { SnapshotFrom } from "xstate";
import { chatMachine } from "./chat-machine";
import type { ChatEvent, ChatState as MachineContext } from "./chat-machine";
import { appendPromotionMessage } from "./chat-promotion";
import { appendPromotionMessage } from "./helper/promotion";
/**
* 对外暴露的 State 形状
+1 -1
View File
@@ -57,6 +57,6 @@ export type ChatEvent =
| { type: "ChatQueuedSendStarted" }
| {
type: "ChatQueuedHttpDone";
output: import("./chat-machine.helpers").HttpSendOutput;
output: import("./helper/send-state").HttpSendOutput;
}
| { type: "ChatQueuedSendError"; content: string; errorMessage: string };
+2 -4
View File
@@ -5,10 +5,8 @@ import { Logger } from "@/utils/logger";
import { Result } from "@/utils/result";
import { todayString } from "@/utils/date";
import {
CHAT_HISTORY_LIMIT,
localMessagesToUi,
} from "./chat-machine.helpers";
import { CHAT_HISTORY_LIMIT } from "./helper/history";
import { localMessagesToUi } from "./helper/message-mappers";
const log = new Logger("StoresChatChatHistorySync");
+1 -1
View File
@@ -2,7 +2,7 @@ import type { UiMessage } from "@/data/dto/chat";
import type { PendingChatUnlockKind } from "@/lib/navigation/chat_unlock_session";
import type { ChatLockType } from "@/data/schemas/chat";
import type { PendingChatPromotion } from "@/data/storage/navigation";
import type { ChatPromotionState } from "./chat-promotion";
import type { ChatPromotionState } from "./helper/promotion";
export type ChatUpgradeReason = "insufficient_credits";
@@ -1,15 +1,10 @@
import type { UiMessage } from "@/data/dto/chat";
import type { ChatState } from "./chat-state";
import type { ChatState } from "../chat-state";
// The initial history request remains bounded even though pagination is disabled.
export const CHAT_HISTORY_LIMIT = 50;
export * from "./chat-message-mappers";
export * from "./chat-promotion";
export * from "./chat-send-state";
export * from "./chat-unlock-helpers";
export function applyHistoryLoadedOutput(
output: {
messages: UiMessage[];
+5
View File
@@ -0,0 +1,5 @@
export * from "./history";
export * from "./message-mappers";
export * from "./promotion";
export * from "./send-state";
export * from "./unlock";
@@ -5,7 +5,7 @@ import { todayString } from "@/utils/date";
import {
applySingleUnlockOutput,
type UnlockMessageOutput,
} from "./chat-unlock-helpers";
} from "./unlock";
const PROMOTION_COPY = {
voice: "I left a voice message for you. Unlock it to listen.",
@@ -1,6 +1,6 @@
import { type ChatSendResponse, type UiMessage } from "@/data/dto/chat";
import type { ChatState, ChatUpgradeReason } from "./chat-state";
import type { ChatState, ChatUpgradeReason } from "../chat-state";
export type HttpSendOutput = {
response: ChatSendResponse;
+1 -1
View File
@@ -4,6 +4,6 @@
export * from "./chat-context";
export * from "./chat-events";
export * from "./chat-machine.helpers";
export * from "./helper";
export * from "./chat-machine";
export * from "./chat-state";
+1 -1
View File
@@ -9,7 +9,7 @@ import { Logger } from "@/utils/logger";
import { Result } from "@/utils/result";
import type { ChatEvent } from "../../chat-events";
import { sendResponseToUiMessage } from "../../chat-machine.helpers";
import { sendResponseToUiMessage } from "../../helper/message-mappers";
const log = new Logger("StoresChatChatSendFlow");
+1 -1
View File
@@ -9,7 +9,7 @@ import { readAndSyncHistory } from "../../chat-history-sync";
import {
type UnlockMessageRequest,
type UnlockMessageOutput,
} from "../../chat-machine.helpers";
} from "../../helper/unlock";
const log = new Logger("StoresChatChatUnlockFlow");
+3 -1
View File
@@ -1,9 +1,11 @@
import {
applyHistoryLoadedOutput,
applyNetworkHistoryLoadedOutput,
} from "../helper/history";
import {
countLockedHistoryMessages,
shouldPromptUnlockHistory,
} from "../chat-machine.helpers";
} from "../helper/unlock";
import { baseChatMachineSetup } from "./setup";
const applyLocalHistoryLoadedAction = baseChatMachineSetup.assign(
+1 -1
View File
@@ -8,7 +8,7 @@ import {
beginPendingReply,
finishPendingReply,
type HttpSendOutput,
} from "../chat-machine.helpers";
} from "../helper/send-state";
import { historyMachineSetup } from "./history-flow";
import { createChatActorActionSetup } from "./setup";
+2 -4
View File
@@ -1,7 +1,5 @@
import {
createChatPromotionState,
shouldPromptUnlockHistory,
} from "../chat-machine.helpers";
import { createChatPromotionState } from "../helper/promotion";
import { shouldPromptUnlockHistory } from "../helper/unlock";
import { initialState } from "../chat-state";
import {
guestInitializingState,
+2 -2
View File
@@ -1,11 +1,11 @@
import { type DoneActorEvent } from "xstate";
import { applyPromotionUnlockOutput } from "../helper/promotion";
import {
applyPromotionUnlockOutput,
applySingleUnlockOutput,
countLockedHistoryMessages,
type UnlockMessageOutput,
} from "../chat-machine.helpers";
} from "../helper/unlock";
import type { UnlockHistoryOutput } from "./actors/unlock";
import { sendMachineSetup } from "./send-flow";
import { createChatActorActionSetup } from "./setup";