refactor(chat): remove weekly limit flow

This commit is contained in:
2026-07-01 13:12:14 +08:00
parent d1ccf3631e
commit f6e7adbe96
9 changed files with 33 additions and 89 deletions
@@ -143,43 +143,6 @@ describe("sendResponseToUiMessage", () => {
});
describe("applyHttpSendOutput", () => {
it("removes the optimistic user message when the weekly limit is reached", () => {
const context = makeChatState({
messages: [
{
content: "hello",
isFromAI: false,
date: "2026-06-25",
},
],
});
const nextState = applyHttpSendOutput(context, {
response: makeResponse({
reply: "",
messageId: "",
lockDetail: {
locked: true,
showContent: false,
showUpgrade: true,
reason: "weekly_limit",
hint: "Free message limit reached.",
detail: {
type: "weekly_msg_limit",
usedThisWeek: 3,
limit: 3,
},
},
}),
reply: null,
});
expect(nextState.messages).toEqual([]);
expect(nextState.isReplyingAI).toBe(false);
expect(nextState.upgradePromptVisible).toBe(true);
expect(nextState.upgradeReason).toBe("weekly_limit");
});
it("stores insufficient credit state and removes failed optimistic messages", () => {
const context = makeChatState({
messages: [
@@ -363,7 +326,7 @@ describe("countLockedHistoryMessages", () => {
isFromAI: true,
date: "2026-06-29",
locked: true,
lockReason: "weekly_limit",
lockReason: "insufficient_credits",
},
{
content: "user text",
@@ -767,7 +767,7 @@ describe("chatMachine transitions", () => {
actor.stop();
});
it("clears the weekly limit prompt after payment succeeds", async () => {
it("clears the insufficient credits prompt after payment succeeds", async () => {
const actor = createActor(createTestChatMachine()).start();
actor.send({ type: "ChatUserLogin", token: "token" });
@@ -789,12 +789,12 @@ describe("chatMachine transitions", () => {
locked: true,
showContent: false,
showUpgrade: true,
reason: "weekly_limit",
hint: "Free message limit reached.",
reason: "insufficient_credits",
hint: "Insufficient credits.",
detail: {
type: "weekly_msg_limit",
usedThisWeek: 3,
limit: 3,
requiredCredits: 2,
currentCredits: 0,
shortfallCredits: 2,
},
},
canSendMessage: false,
@@ -808,7 +808,9 @@ describe("chatMachine transitions", () => {
});
expect(actor.getSnapshot().context.upgradePromptVisible).toBe(true);
expect(actor.getSnapshot().context.upgradeReason).toBe("weekly_limit");
expect(actor.getSnapshot().context.upgradeReason).toBe(
"insufficient_credits",
);
expect(actor.getSnapshot().context.canSendMessage).toBe(false);
actor.send({ type: "ChatPaymentSucceeded" });
+2 -2
View File
@@ -21,9 +21,9 @@
* - guestSession / userSession:队列串行走 HTTP,限制以后端 `lockDetail` 为准
* - `pendingReplyCount` 跟踪待回复数量,`isReplyingAI` 由计数派生
*
* 配额
* 发送能力
* - 前端不再处理本地消息额度;游客 / 注册用户均以后端响应为准。
* - 后端返回 `lockDetail.reason="weekly_limit"` 且需要升级时展示会员引导。
* - 后端返回 `cannotSendReason="insufficient_credits"` 时展示充值引导。
*
*/
+1 -7
View File
@@ -167,10 +167,6 @@ async function sendMessageViaHttp(content: string): Promise<{
throw result.error;
}
void chatRepo.prefetchMediaForSendResponse(result.data);
const isMessageLimit =
result.data.lockDetail.locked &&
result.data.lockDetail.showUpgrade &&
result.data.lockDetail.reason === "weekly_limit";
const isInsufficientCredits =
result.data.canSendMessage === false &&
result.data.cannotSendReason === "insufficient_credits" &&
@@ -178,9 +174,7 @@ async function sendMessageViaHttp(content: string): Promise<{
return {
response: result.data,
reply:
isMessageLimit || isInsufficientCredits
? null
: sendResponseToUiMessage(result.data),
isInsufficientCredits ? null : sendResponseToUiMessage(result.data),
};
}
+7 -11
View File
@@ -35,19 +35,12 @@ export function applyHttpSendOutput(
): Partial<ChatState> {
const { response, reply } = output;
const lockDetail = response.lockDetail;
const isWeeklyLimitBlocked =
lockDetail.locked &&
lockDetail.showUpgrade &&
lockDetail.reason === "weekly_limit";
const isInsufficientCredits =
response.canSendMessage === false &&
response.cannotSendReason === "insufficient_credits";
const upgradeReason: ChatUpgradeReason | null = isWeeklyLimitBlocked
? "weekly_limit"
: isInsufficientCredits
? "insufficient_credits"
: null;
const upgradeReason: ChatUpgradeReason | null = isInsufficientCredits
? "insufficient_credits"
: null;
const sendCapabilityState = getSendCapabilityState(response);
if (upgradeReason) {
@@ -73,7 +66,10 @@ export function applyHttpSendOutput(
};
}
if (lockDetail.showUpgrade && lockDetail.reason === "private_message") {
if (
response.lockDetail.showUpgrade &&
response.lockDetail.reason === "private_message"
) {
return {
messages: [...context.messages, reply],
...finishPendingReply(context),
+1 -1
View File
@@ -1,7 +1,7 @@
import type { UiMessage } from "@/data/dto/chat";
import type { PendingChatUnlockKind } from "@/lib/navigation/chat_unlock_session";
export type ChatUpgradeReason = "weekly_limit" | "insufficient_credits";
export type ChatUpgradeReason = "insufficient_credits";
export interface ChatUnlockPaywallRequest {
messageId: string;