refactor(chat): extract XState actors into chat-machine.actors.ts

- Split chat state machine actors (chatInit, sendMessageHttp, loadMoreHistory, chatWebSocket) into a dedicated module
- Add comprehensive console logging across the chat state machine for full trace debugging
- Comment out margin on text bubble CSS for layout adjustment
- Add debug logging to chat input bar send handler
- Clean up redundant comments in auth-screen component
This commit is contained in:
2026-06-12 11:20:19 +08:00
parent 6394c8ba7b
commit 38f060bbd8
7 changed files with 583 additions and 253 deletions
+14 -1
View File
@@ -9,6 +9,12 @@
* - 游客:chat-screen 派 `ChatInit` → readInitData 调 ChatStorage → onDone 条件赋
* - 非游客:**永不被赋值**(业务事实"非游客无消息限制")—— 0 - 1 = max(0, -1) = 0 天然 no-op
* - 0 同时表示"未初始化"和"已耗尽" —— UI 用 `if (isGuest && ...)` 天然过滤
*
* 新增 `wsConnected: boolean`**仅** userSession 期间 true):
* - **WS 已连** → 消息发送走 WS,**不**消耗次数
* - **WS 未连** → 消息发送走 HTTP,消耗次数
* - `ChatWebSocketConnected` 事件 → true
* - `userSession.exit` → falseWS actor cleanup 时**也**会跑 exit
*/
import type { UiMessage } from "@/models/chat/ui-message";
@@ -16,7 +22,13 @@ export interface ChatState {
messages: UiMessage[];
isReplyingAI: boolean;
/**
* 游客剩余配额(次/天)—— **仅**游客业务展示用
* WebSocket 连接状态(**仅** userSession 期间 true
* - 决定消息发送**路径**WS / HTTP)和**是否消耗**次数
* - true:走 WS**不**消耗次数
* - false:走 HTTP,消耗次数
*/
wsConnected: boolean;
/** 游客剩余配额(次/天)—— **仅**游客业务展示用
* - default 0 = "未初始化" / "已耗尽"(同码,靠 `isGuest` 区分)
* - 非游客:永不被赋值(业务事实"无消息限制")
*/
@@ -32,6 +44,7 @@ export interface ChatState {
export const initialState: ChatState = {
messages: [],
isReplyingAI: false,
wsConnected: false,
guestRemainingQuota: 0,
guestTotalQuota: 0,
quotaExceededTrigger: 0,