refactor(chat): remove unused upgrade state fields
This commit is contained in:
@@ -38,8 +38,6 @@ function makeChatState(overrides: Partial<ChatState> = {}): ChatState {
|
|||||||
pendingReplyCount: 1,
|
pendingReplyCount: 1,
|
||||||
upgradePromptVisible: false,
|
upgradePromptVisible: false,
|
||||||
upgradeReason: null,
|
upgradeReason: null,
|
||||||
upgradeHint: null,
|
|
||||||
upgradeDetail: null,
|
|
||||||
isLoadingMore: false,
|
isLoadingMore: false,
|
||||||
hasMore: true,
|
hasMore: true,
|
||||||
historyOffset: 0,
|
historyOffset: 0,
|
||||||
@@ -169,12 +167,6 @@ describe("applyHttpSendOutput", () => {
|
|||||||
expect(nextState.isReplyingAI).toBe(false);
|
expect(nextState.isReplyingAI).toBe(false);
|
||||||
expect(nextState.upgradePromptVisible).toBe(true);
|
expect(nextState.upgradePromptVisible).toBe(true);
|
||||||
expect(nextState.upgradeReason).toBe("daily_limit");
|
expect(nextState.upgradeReason).toBe("daily_limit");
|
||||||
expect(nextState.upgradeHint).toBeNull();
|
|
||||||
expect(nextState.upgradeDetail).toEqual({
|
|
||||||
type: "daily_msg_limit",
|
|
||||||
usedToday: 3,
|
|
||||||
limit: 3,
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -479,8 +479,6 @@ describe("chatMachine transitions", () => {
|
|||||||
|
|
||||||
expect(actor.getSnapshot().context.upgradePromptVisible).toBe(false);
|
expect(actor.getSnapshot().context.upgradePromptVisible).toBe(false);
|
||||||
expect(actor.getSnapshot().context.upgradeReason).toBeNull();
|
expect(actor.getSnapshot().context.upgradeReason).toBeNull();
|
||||||
expect(actor.getSnapshot().context.upgradeHint).toBeNull();
|
|
||||||
expect(actor.getSnapshot().context.upgradeDetail).toBeNull();
|
|
||||||
|
|
||||||
actor.stop();
|
actor.stop();
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -23,8 +23,6 @@ interface ChatState {
|
|||||||
isReplyingAI: boolean;
|
isReplyingAI: boolean;
|
||||||
upgradePromptVisible: boolean;
|
upgradePromptVisible: boolean;
|
||||||
upgradeReason: MachineContext["upgradeReason"];
|
upgradeReason: MachineContext["upgradeReason"];
|
||||||
upgradeHint: MachineContext["upgradeHint"];
|
|
||||||
upgradeDetail: MachineContext["upgradeDetail"];
|
|
||||||
isLoadingMore: boolean;
|
isLoadingMore: boolean;
|
||||||
hasMore: boolean;
|
hasMore: boolean;
|
||||||
historyOffset: number;
|
historyOffset: number;
|
||||||
@@ -53,8 +51,6 @@ export function ChatProvider({ children }: ChatProviderProps) {
|
|||||||
isReplyingAI: state.context.isReplyingAI,
|
isReplyingAI: state.context.isReplyingAI,
|
||||||
upgradePromptVisible: state.context.upgradePromptVisible,
|
upgradePromptVisible: state.context.upgradePromptVisible,
|
||||||
upgradeReason: state.context.upgradeReason,
|
upgradeReason: state.context.upgradeReason,
|
||||||
upgradeHint: state.context.upgradeHint,
|
|
||||||
upgradeDetail: state.context.upgradeDetail,
|
|
||||||
isLoadingMore: state.context.isLoadingMore,
|
isLoadingMore: state.context.isLoadingMore,
|
||||||
hasMore: state.context.hasMore,
|
hasMore: state.context.hasMore,
|
||||||
historyOffset: state.context.historyOffset,
|
historyOffset: state.context.historyOffset,
|
||||||
|
|||||||
@@ -194,8 +194,6 @@ export function applyHttpSendOutput(
|
|||||||
...finishPendingReply(context),
|
...finishPendingReply(context),
|
||||||
upgradePromptVisible: true,
|
upgradePromptVisible: true,
|
||||||
upgradeReason: "daily_limit",
|
upgradeReason: "daily_limit",
|
||||||
upgradeHint: null,
|
|
||||||
upgradeDetail: normalizeLockDetail(lockDetail.detail),
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -211,8 +209,6 @@ export function applyHttpSendOutput(
|
|||||||
...finishPendingReply(context),
|
...finishPendingReply(context),
|
||||||
upgradePromptVisible: false,
|
upgradePromptVisible: false,
|
||||||
upgradeReason: null,
|
upgradeReason: null,
|
||||||
upgradeHint: null,
|
|
||||||
upgradeDetail: null,
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -221,8 +217,6 @@ export function applyHttpSendOutput(
|
|||||||
...finishPendingReply(context),
|
...finishPendingReply(context),
|
||||||
upgradePromptVisible: false,
|
upgradePromptVisible: false,
|
||||||
upgradeReason: null,
|
upgradeReason: null,
|
||||||
upgradeHint: null,
|
|
||||||
upgradeDetail: null,
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -252,22 +246,6 @@ export function shouldPromptUnlockHistory(messages: readonly UiMessage[]): boole
|
|||||||
return countLockedHistoryMessages(messages) > 1;
|
return countLockedHistoryMessages(messages) > 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function normalizeLockDetail(
|
|
||||||
detail: Record<string, unknown> | null,
|
|
||||||
): ChatState["upgradeDetail"] {
|
|
||||||
if (!detail) return null;
|
|
||||||
return {
|
|
||||||
...(typeof detail.type === "string" ? { type: detail.type } : {}),
|
|
||||||
...(typeof detail.usedToday === "number"
|
|
||||||
? { usedToday: detail.usedToday }
|
|
||||||
: {}),
|
|
||||||
...(typeof detail.usedTotal === "number"
|
|
||||||
? { usedTotal: detail.usedTotal }
|
|
||||||
: {}),
|
|
||||||
...(typeof detail.limit === "number" ? { limit: detail.limit } : {}),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
// ============================================================
|
// ============================================================
|
||||||
// Init 任务 2:history 3 步流(local → network → save)—— `loadHistoryActor` 调
|
// Init 任务 2:history 3 步流(local → network → save)—— `loadHistoryActor` 调
|
||||||
// ============================================================
|
// ============================================================
|
||||||
|
|||||||
@@ -109,8 +109,6 @@ export const chatMachine = setup({
|
|||||||
],
|
],
|
||||||
upgradePromptVisible: false,
|
upgradePromptVisible: false,
|
||||||
upgradeReason: null,
|
upgradeReason: null,
|
||||||
upgradeHint: null,
|
|
||||||
upgradeDetail: null,
|
|
||||||
};
|
};
|
||||||
}),
|
}),
|
||||||
|
|
||||||
@@ -135,8 +133,6 @@ export const chatMachine = setup({
|
|||||||
],
|
],
|
||||||
upgradePromptVisible: false,
|
upgradePromptVisible: false,
|
||||||
upgradeReason: null,
|
upgradeReason: null,
|
||||||
upgradeHint: null,
|
|
||||||
upgradeDetail: null,
|
|
||||||
};
|
};
|
||||||
}),
|
}),
|
||||||
|
|
||||||
@@ -161,8 +157,6 @@ export const chatMachine = setup({
|
|||||||
...beginPendingReply(context),
|
...beginPendingReply(context),
|
||||||
upgradePromptVisible: false,
|
upgradePromptVisible: false,
|
||||||
upgradeReason: null,
|
upgradeReason: null,
|
||||||
upgradeHint: null,
|
|
||||||
upgradeDetail: null,
|
|
||||||
};
|
};
|
||||||
}),
|
}),
|
||||||
|
|
||||||
@@ -187,8 +181,6 @@ export const chatMachine = setup({
|
|||||||
...beginPendingReply(context),
|
...beginPendingReply(context),
|
||||||
upgradePromptVisible: false,
|
upgradePromptVisible: false,
|
||||||
upgradeReason: null,
|
upgradeReason: null,
|
||||||
upgradeHint: null,
|
|
||||||
upgradeDetail: null,
|
|
||||||
};
|
};
|
||||||
}),
|
}),
|
||||||
|
|
||||||
@@ -214,8 +206,6 @@ export const chatMachine = setup({
|
|||||||
clearUpgradePrompt: assign(() => ({
|
clearUpgradePrompt: assign(() => ({
|
||||||
upgradePromptVisible: false,
|
upgradePromptVisible: false,
|
||||||
upgradeReason: null,
|
upgradeReason: null,
|
||||||
upgradeHint: null,
|
|
||||||
upgradeDetail: null,
|
|
||||||
})),
|
})),
|
||||||
|
|
||||||
markPaymentUnlockPending: assign(() => ({
|
markPaymentUnlockPending: assign(() => ({
|
||||||
|
|||||||
@@ -5,16 +5,7 @@ export interface ChatState {
|
|||||||
isReplyingAI: boolean;
|
isReplyingAI: boolean;
|
||||||
pendingReplyCount: number;
|
pendingReplyCount: number;
|
||||||
upgradePromptVisible: boolean;
|
upgradePromptVisible: boolean;
|
||||||
upgradeReason: "daily_limit" | "image" | null;
|
upgradeReason: "daily_limit" | null;
|
||||||
upgradeHint: string | null;
|
|
||||||
upgradeDetail:
|
|
||||||
| {
|
|
||||||
type?: string;
|
|
||||||
usedToday?: number;
|
|
||||||
usedTotal?: number;
|
|
||||||
limit?: number;
|
|
||||||
}
|
|
||||||
| null;
|
|
||||||
isLoadingMore: boolean;
|
isLoadingMore: boolean;
|
||||||
hasMore: boolean;
|
hasMore: boolean;
|
||||||
historyOffset: number;
|
historyOffset: number;
|
||||||
@@ -36,8 +27,6 @@ export const initialState: ChatState = {
|
|||||||
pendingReplyCount: 0,
|
pendingReplyCount: 0,
|
||||||
upgradePromptVisible: false,
|
upgradePromptVisible: false,
|
||||||
upgradeReason: null,
|
upgradeReason: null,
|
||||||
upgradeHint: null,
|
|
||||||
upgradeDetail: null,
|
|
||||||
isLoadingMore: false,
|
isLoadingMore: false,
|
||||||
hasMore: true,
|
hasMore: true,
|
||||||
historyOffset: 0,
|
historyOffset: 0,
|
||||||
|
|||||||
Reference in New Issue
Block a user