feat(chat): handle daily message paywall

This commit is contained in:
2026-06-22 10:46:17 +08:00
parent df7f673855
commit 61fd4ca916
10 changed files with 162 additions and 44 deletions
+8 -4
View File
@@ -5,6 +5,7 @@
import { fromPromise, fromCallback } from "xstate";
import { createChatWebSocket, ChatWebSocket } from "@/core/net/chat-websocket";
import type { ChatSendResponse } from "@/data/dto/chat";
import { Result, Logger } from "@/utils";
import {
@@ -83,10 +84,10 @@ export const loadHistoryActor = fromPromise<{
* HTTP 发送消息(一次发送 = 一次返回)
* - 后端响应就是 AI 回复(`ChatSendResponse.reply: string`
* - 不再调 `getLocalMessages()`(多此一举)
* - 返回 `{ reply: UiMessage }` —— `sending.onDone` 把它追加到 `context.messages`
* - 返回完整 response + 可追加的 reply,方便处理后端 paywall blocked 响应
*/
export const sendMessageHttpActor = fromPromise<
{ reply: UiMessage },
{ response: ChatSendResponse; reply: UiMessage | null },
{ content: string }
>(async ({ input }) => {
const result = await chatRepo.sendMessage(input.content);
@@ -94,7 +95,10 @@ export const sendMessageHttpActor = fromPromise<
log.error("[chat-machine] sendMessageHttpActor failed", { error: result.error });
throw result.error;
}
return { reply: sendResponseToUiMessage(result.data) };
return {
response: result.data,
reply: result.data.blocked ? null : sendResponseToUiMessage(result.data),
};
});
/** 翻历史(pagination)—— 不走 local-first,纯 server fetch */
@@ -198,4 +202,4 @@ export const sendMessageWsActor = fromPromise<void, { content: string }>(
);
// Re-export `UiMessage` type for the chat-machine.ts public API
type UiMessage = import("@/data/dto/chat").UiMessage;
type UiMessage = import("@/data/dto/chat").UiMessage;