feat(chat): migrate chat protocol to lock detail

This commit is contained in:
2026-06-24 14:06:30 +08:00
parent c280a3c1ea
commit 42c03f8901
34 changed files with 609 additions and 373 deletions
+9 -8
View File
@@ -68,7 +68,7 @@ export const loadHistoryActor = fromPromise<{
* HTTP 发送消息(一次发送 = 一次返回)
* - 后端响应就是 AI 回复(`ChatSendResponse.reply: string`
* - 不再调 `getLocalMessages()`(多此一举)
* - 返回完整 response + 可追加的 reply,方便处理后端 paywall blocked 响应
* - 返回完整 response + 可追加的 reply,方便处理后端 lockDetail 响应
*/
export const sendMessageHttpActor = fromPromise<
{ response: ChatSendResponse; reply: UiMessage | null },
@@ -79,9 +79,13 @@ export const sendMessageHttpActor = fromPromise<
log.error("[chat-machine] sendMessageHttpActor failed", { error: result.error });
throw result.error;
}
const isDailyLimit =
result.data.lockDetail.locked &&
result.data.lockDetail.showUpgrade &&
result.data.lockDetail.reason === "daily_limit";
return {
response: result.data,
reply: result.data.blocked ? null : sendResponseToUiMessage(result.data),
reply: isDailyLimit ? null : sendResponseToUiMessage(result.data),
};
});
@@ -170,16 +174,13 @@ export const chatWebSocketActor = fromCallback<ChatEvent, { token: string }>(
done: p.done,
});
};
ws.onImage = (imageUrl) => {
sendBack({ type: "ChatImageReceived", imageUrl });
ws.onImage = (url) => {
sendBack({ type: "ChatImageReceived", url });
};
ws.onPaywallStatus = (p) => {
sendBack({
type: "ChatPaywallStatusReceived",
paywallTriggered: p.paywallTriggered,
showUpgrade: p.showUpgrade,
imageType: p.imageType,
imageUrl: p.imageUrl,
lockDetail: p,
});
};
ws.onError = (msg) => {