feat(pet): bind companion actions to runtime state
一些检测仍在等待运行
ci / Portable quality checks (push) Waiting to run
ci / Windows Tauri build (push) Waiting to run

这个提交存在于:
YokiiroBW 2026-07-20 17:00:42 +08:00
父节点 74fe19f7e4
当前提交 68614824c0
共有 4 个文件被更改,包括 38 次插入 和 5 次删除

查看文件

@ -142,6 +142,7 @@ otification`、`offline`。
- 远端身份已拆分为协议 ID(`remote_username`)与 BOT 称呼昵称(`remote_display_name`),两者不再共用字段。
- 2D 纸片人桌宠已从 manifest 基础推进到可运行窗口:透明、无边框、跳过任务栏、关闭后回托盘,并预留状态动作循环。
- JWT 运行时已支持 `exp` 过期识别、401/403 状态映射和聊天界面重新登录提示。
- 桌宠窗口已接入双槽位运行状态:连接中工作、重连回应、断开休息、认证过期/致命错误提示。
- 不复制 Hermes 或 Codex 的私有实现;只参考交互模式和资源组织方式。
- 不在首轮实现 Live2D、Spine、3D 桌宠或用户脚本插件。

查看文件

@ -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.

查看文件

@ -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<typeof state> = ["idle", "working", "resting", "speaking"];
let cancelled = false;
const refreshPetState = async () => {
try {
const result = connectionRuntimeStatusSchema.parse(
await invoke<unknown>("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() {
<span className="paper-pet-arm right" />
</div>
</div>
<span className="pet-window-status">{state === "working" ? "正在写写画画" : state === "resting" ? "休息中" : state === "speaking" ? "正在回应" : "陪伴中"}</span>
<span className="pet-window-status">{state === "working" ? "正在写写画画" : state === "resting" ? "休息中" : state === "speaking" ? "正在回应" : state === "error" ? "需要重新登录或检查连接" : "陪伴中"}</span>
</main>
);
}

查看文件

@ -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); } }