diff --git a/docs/implementation-queue.md b/docs/implementation-queue.md index 5dd38a4..7d467cb 100644 --- a/docs/implementation-queue.md +++ b/docs/implementation-queue.md @@ -142,6 +142,7 @@ otification`、`offline`。 - 远端身份已拆分为协议 ID(`remote_username`)与 BOT 称呼昵称(`remote_display_name`),两者不再共用字段。 - 2D 纸片人桌宠已从 manifest 基础推进到可运行窗口:透明、无边框、跳过任务栏、关闭后回托盘,并预留状态动作循环。 - JWT 运行时已支持 `exp` 过期识别、401/403 状态映射和聊天界面重新登录提示。 +- 桌宠窗口已接入双槽位运行状态:连接中工作、重连回应、断开休息、认证过期/致命错误提示。 - 不复制 Hermes 或 Codex 的私有实现;只参考交互模式和资源组织方式。 - 不在首轮实现 Live2D、Spine、3D 桌宠或用户脚本插件。 diff --git a/docs/progress.md b/docs/progress.md index 793a199..218f4dd 100644 --- a/docs/progress.md +++ b/docs/progress.md @@ -198,4 +198,5 @@ Still not claimed complete: automatic startup activation, real Tauri multi-windo - Rust checks the JWT `exp` claim before activation and maps expired credentials to `AuthExpired` without logging or returning the token. - AstrBot 401/403 responses during probe or chat now preserve the affected slot and expose an `authExpired` runtime error. - Chat UI shows a re-login warning for the affected slot; credentials remain managed by Windows Credential Manager. +- The floating 2D pet now polls the dual-slot runtime and switches between idle, work, reply, rest, and error states instead of running an isolated demo loop. - Validation: Rust workspace tests (65), Clippy, TypeScript, ESLint, Vitest (6), and Vite build pass. diff --git a/src/App.tsx b/src/App.tsx index b0bd3b9..e11cf12 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -6,6 +6,7 @@ import { ChatPanel } from "./features/chat/ChatPanel"; import { StatusBubble } from "./features/chat/StatusBubble"; import { ProfileManager } from "./features/profiles/ProfileManager"; import { PetPackImporter } from "./features/pet/PetPackImporter"; +import { connectionRuntimeStatusSchema } from "./features/chat/types"; import { bootstrapStatusSchema, type BootstrapStatus } from "./types/bootstrap"; type PageKey = "chat" | "connections" | "desktop" | "pet" | "diagnostics"; @@ -390,14 +391,42 @@ function PetPage() { } function DesktopPetView() { - const [state, setState] = useState<"idle" | "working" | "resting" | "speaking">("idle"); + const [state, setState] = useState<"idle" | "working" | "resting" | "speaking" | "error">("idle"); useEffect(() => { - const states: Array = ["idle", "working", "resting", "speaking"]; + let cancelled = false; + const refreshPetState = async () => { + try { + const result = connectionRuntimeStatusSchema.parse( + await invoke("connection_runtime_status"), + ); + if (cancelled) return; + const states = [result.companion.state, result.operations.state]; + if (states.includes("authExpired") || states.includes("fatalError")) { + setState("error"); + } else if (states.includes("syncing")) { + setState("working"); + } else if (states.includes("reconnecting")) { + setState("speaking"); + } else if (states.every((value) => value === "disconnected" || value === "offline")) { + setState("resting"); + } else { + setState("idle"); + } + } catch { + if (!cancelled) setState("idle"); + } + }; + void refreshPetState(); + const refreshTimer = window.setInterval(() => void refreshPetState(), 2000); const timer = window.setInterval(() => { - setState((current) => states[(states.indexOf(current) + 1) % states.length]); + setState((current) => (current === "idle" ? "resting" : current === "resting" ? "idle" : current)); }, 4200); - return () => window.clearInterval(timer); + return () => { + cancelled = true; + window.clearInterval(refreshTimer); + window.clearInterval(timer); + }; }, []); return ( @@ -425,7 +454,7 @@ function DesktopPetView() { - {state === "working" ? "正在写写画画" : state === "resting" ? "休息中" : state === "speaking" ? "正在回应" : "陪伴中"} + {state === "working" ? "正在写写画画" : state === "resting" ? "休息中" : state === "speaking" ? "正在回应" : state === "error" ? "需要重新登录或检查连接" : "陪伴中"} ); } diff --git a/src/styles.css b/src/styles.css index 105b467..b3edde2 100644 --- a/src/styles.css +++ b/src/styles.css @@ -1153,6 +1153,8 @@ select:focus { .paper-pet-arm.left { left: -17px; transform: rotate(35deg); } .paper-pet-arm.right { right: -17px; transform: rotate(-35deg); } .pet-window-working .paper-pet { animation: pet-work .8s ease-in-out infinite alternate; } .pet-window-working .paper-pet-book { opacity: 1; } .pet-window-resting .paper-pet { animation: pet-rest 3s ease-in-out infinite; } .pet-window-speaking .paper-pet-mouth { height: 10px; background: #263454; } +.pet-window-error .paper-pet { animation: pet-error 1.2s ease-in-out infinite alternate; filter: saturate(.65); } @keyframes pet-idle { 50% { transform: translateY(-5px); } } @keyframes pet-work { from { transform: translateY(0) rotate(-2deg); } to { transform: translateY(-4px) rotate(2deg); } } @keyframes pet-rest { 50% { transform: translateY(8px) rotate(8deg); } } +@keyframes pet-error { from { transform: translateX(-3px); } to { transform: translateX(3px); } }