diff --git a/docs/progress.md b/docs/progress.md
index 7e7388d..fb4d404 100644
--- a/docs/progress.md
+++ b/docs/progress.md
@@ -308,3 +308,40 @@ Still not claimed complete: automatic startup activation, real Tauri multi-windo
- Added responsive runtime metadata and chat layout refinements; preserved the existing pet event bus for Q13 state synchronization.
- Updated frontend test mocks for runtime status schema changes.
- Validation: Vitest (6), TypeScript, ESLint, and targeted Prettier checks pass.
+## 2026-07-21: frontend UI audit and chat-page visual increment
+
+- Completed the Impeccable audit and recorded the P0-P3 findings in `docs/reports/ui-audit-2026-07-21.md`.
+- Recorded the P0-P2 redesign queue and preserved contracts in `docs/ui-redesign-plan.md`.
+- Refined the chat page visual layer in `src/styles.css` only: added shared UI tokens, visible focus states, clearer slot/runtime hierarchy, calmer surfaces, responsive composer layout, and reduced-motion fallback.
+- No IPC command, event name, route key, profile/slot/session/message schema, or security boundary changed.
+- Frontend validation after the increment: typecheck passed, lint passed, Vitest 6 passed, Vite build passed; build still reports the existing large JS chunk warning.
+- Browser preview at 1280x720 confirmed no horizontal overflow on the chat page. In-browser IPC fallback remains expected outside Tauri.
+
+## 2026-07-21: chat page accessibility and polish increment
+
+- Added chat slot tab relationships, keyboard left/right switching, selected-tab focus order, message tabpanel semantics, busy state, and alert semantics for send/runtime errors.
+- Kept the existing chat state, invoke/listen calls, session switching, attachment upload, voice input, retry, copy, read-aloud, and stop-generation interactions unchanged.
+- Refined chat-only typography, scroll behavior, focus treatment, disabled states, voice active state, file input focusability, touch targets, and narrow-window layout without adding motion.
+- Frontend validation passed: Prettier on `src/features/chat/ChatPanel.tsx`, typecheck, lint, Vitest 6 tests, and Vite production build.
+- Browser preview passed at 1280x720 with no horizontal overflow; slot arrow-key switching selected the adjacent tab. Existing pet overlay/navigation overlap remains outside this batch.
+
+## 2026-07-21: P1-P3 frontend hardening increment
+
+- Added lazy-loaded chunks for ProfileManager and PetPackImporter, with a status fallback and async test waiting.
+- Added visible diagnostic field labels, global IPC alert semantics, and a safe desktop-pet left boundary that keeps the main navigation clear on desktop widths.
+- Consolidated the visual layer through shared UI tokens, Windows-native typography, reduced card shadows, calmer surfaces, consistent focus/disabled/error states, and narrow-window session layout.
+- Preserved existing routes, page keys, IPC command/event names, connection slots, profile/session/message data, and security boundaries.
+- Validation: typecheck, lint, Vitest 6 tests, targeted Prettier checks, Vite build, and 1280x720 browser preview passed. Build now emits ProfileManager and PetPackImporter async chunks; the existing large main JS chunk warning remains.
+- Normalized persisted in-app pet coordinates on mount and window resize so stale positions cannot remain over the sidebar after an upgrade or window-size change.
+- Final frontend validation after the normalization: targeted Prettier, typecheck, lint, Vitest 6, `git diff --check`, and Vite production build passed. Node 24.14.0 still emits the repository's existing engine warning for the `>=24.17.0` requirement.
+
+## 2026-07-22: complete frontend UI redesign queue P1-P3
+
+- Completed P1 core-page work: ProfileManager credential form labels and feedback, StatusBubble semantic status tones, DesktopBehaviorPage grouping, DiagnosticsPage field labels and async feedback.
+- Completed P2 code splitting: moved DesktopBehaviorPage and DiagnosticsPage to `src/pages/SettingsPages.tsx`; moved DesktopPetView and sprite loading to `src/features/pet/DesktopPetView.tsx`; kept ProfileManager and PetPackImporter lazy-loaded.
+- Reduced the initial JavaScript chunk from approximately 5.54 MB raw / 4.02 MB gzip to approximately 305.93 kB raw / 91.43 kB gzip. The pet renderer remains an intentional lazy chunk because its inline sprite asset is approximately 5.23 MB.
+- Completed P2 consistency work: added shared status colors, numeric typography, responsive 1280/1024/680px rules, reduced-motion fallback, async diagnostic status feedback, visible focus and disabled states, and bounded diagnostic result rendering.
+- Added `tests/e2e/ui-polish.spec.ts` for desktop shell overflow checks at 1280px, 1024px, and 680px plus diagnostic keyboard accessibility.
+- Completed P3 polish pass for desktop shell hierarchy, status messaging, profile credentials, diagnostics, desktop pet boundary, empty/error/loading states, and dark/light token usage without adding marketing-style animation.
+- Validation: targeted Prettier, ESLint, TypeScript, Vitest 6/6, Vite production build, Playwright 5/5, Rust fmt, Clippy with warnings denied, Rust workspace tests (67), and Rust workspace check all passed.
+- Known non-blocking warnings: Node is `24.14.0` while the package requires `>=24.17.0`; Vite reports the intentional lazy `DesktopPetView` chunk above 500 kB.
diff --git a/docs/reports/ui-audit-2026-07-21.md b/docs/reports/ui-audit-2026-07-21.md
new file mode 100644
index 0000000..bd76119
--- /dev/null
+++ b/docs/reports/ui-audit-2026-07-21.md
@@ -0,0 +1,62 @@
+# AstrBot Desktop 前端 UI 审计
+
+日期:2026-07-21
+范围:`src/App.tsx`、`src/styles.css`、`src/features/**`、前端测试与构建配置
+
+## 审计方式
+
+- 读取 `docs/01_Architecture_Design.md`、`docs/02_Codex_Implementation_Tasks.md` 和现有前端实现。
+- 按 Impeccable technical audit 的 Accessibility、Performance、Theming、Responsive、Anti-patterns 五个维度检查。
+- 运行本地 detector:`node C:\Users\Administrator\.agents\skills\impeccable\scripts\detect.mjs --json src/App.tsx src/styles.css src/features`;未返回结构化命中项,因此以下结论以源码和基线检查为准。
+- 基线:`pnpm run typecheck`、`pnpm run lint`、`pnpm run test`、`pnpm run build` 均通过;Node 版本有 `24.14.0` vs 要求 `>=24.17.0` 的警告。
+
+## Health score
+
+| 维度 | 分数 | 结论 |
+| ------------- | --------: | --------------------------------------------------------------------------------------- |
+| Accessibility | 2/4 | 已有主导航、部分 ARIA 和 live region,但焦点、键盘 tab 语义、表单标签及窗口控件仍不完整 |
+| Performance | 2/4 | 聊天状态集中在大组件,生产 JS gzip 约 4.0 MB,存在按页面拆分和减少无关重渲染空间 |
+| Theming | 2/4 | 有 dark/light 主题,但大量颜色、渐变和阴影直接写在 CSS,主题 token 未形成单一来源 |
+| Responsive | 2/4 | 有 900/760/680px 断点,但聊天会话列表、工具栏、桌面窗口尺寸和 44px 触控目标仍需验证 |
+| Anti-patterns | 2/4 | 不是营销页式 AI slop,但存在渐变背景、重复卡片、过度圆角/阴影和全局大标题层级偏重 |
+| **总分** | **10/20** | **Acceptable:需要系统性重构,但不需要改写业务架构** |
+
+## P0:阻塞项
+
+当前没有确认会阻塞任务完成的 P0 功能问题。
+
+## P1:发布前必须处理
+
+1. **聊天页信息层级不稳定** — `src/features/chat/ChatPanel.tsx:577`;运行时状态、槽位切换、会话列表、消息流和输入区堆在同一面板,主任务入口不够突出。
+2. **主题令牌不完整** — `src/styles.css:1`、`src/styles.css:1804`;深浅色主题依赖大量重复选择器和硬编码色值,新增页面容易产生视觉漂移。
+3. **焦点和键盘状态不完整** — `src/styles.css:246` 只覆盖输入框/选择框;导航按钮、槽位 tab、消息操作和窗口控件缺少统一 `:focus-visible` 样式。
+4. **表单标签与可读性不一致** — `src/App.tsx:945`、`src/App.tsx:950`、`src/App.tsx:973` 使用 `aria-label` 代替可见标签;`CredentialEnrollmentCard` 的 label 结构也需要统一间距和错误提示。
+5. **聊天构建体积过大** — `pnpm run build` 输出 `index-D8Ql9rJN.js` 约 5.6 MB(gzip 约 4.0 MB);页面级懒加载和资源边界应纳入 P2,若继续增加桌宠/诊断功能则应提前拆分。
+6. **状态反馈缺少统一视觉语义** — 连接、加载、错误、空会话和上传状态分散在多个 class,颜色和文案没有统一 token/状态等级。
+7. **桌宠浮层遮挡主导航** — 浏览器预览中 pp-pet-overlay 覆盖左侧导航项,桌宠可见时会降低页面可操作性;应限制浮层层级/停靠区,或提供不遮挡导航的安全边界。
+
+## P2:下一批处理
+
+1. 统一桌面工作区的密度、间距、圆角和阴影,减少重复 `card` 包裹。
+2. 修正 680px 以下布局:会话列表、聊天工具条、输入框按钮和长文本溢出。
+3. 给所有异步按钮补充进行中、失败、恢复动作和 `aria-live` 反馈。
+4. 给聊天消息操作、附件移除、窗口控制补充 tooltip/可见焦点,不依赖符号字符表达含义。
+5. 引入 `text-wrap: balance/pretty`、`font-variant-numeric: tabular-nums` 和统一字体回退链。
+6. 增加 `prefers-reduced-motion` 覆盖,保留桌宠状态动画但避免普通 UI 无限动画扩散。
+
+## 不可改变的产品边界
+
+- 技术栈继续使用 Tauri 2、React、TypeScript、Vite、Rust、SQLite、REST + SSE。
+- 保留页面 key:`chat`、`connections`、`desktop`、`pet`、`diagnostics`。
+- 不改变 Tauri IPC command/event 名称、Rust 权限边界、profile/slot/session/message 数据结构。
+- 不改变 `companion` 与 `operations` 两个槽位的隔离规则,不把 `conversation_id` 单独作为本地唯一键。
+- 不让 React 直接读取凭据、任意文件或执行 Shell;不修改后端协议和数据库迁移。
+
+## 首批建议
+
+先重构 `ChatPage` / `ChatPanel` 的视觉层:保留所有 state、invoke/listen、session、attachment、voice 和发送逻辑,只调整信息分组、CSS token、状态展示和响应式布局。
+
+## 外部技能可用性
+
+- 已使用本地 Impeccable audit 规范与 detector。
+- 已读取本机 `redesign-existing-projects` 与 `design-taste-frontend` 技能说明,并将其约束应用于方案;它们没有独立可执行命令或额外 CLI。
diff --git a/docs/ui-redesign-plan.md b/docs/ui-redesign-plan.md
new file mode 100644
index 0000000..c206c4b
--- /dev/null
+++ b/docs/ui-redesign-plan.md
@@ -0,0 +1,65 @@
+# AstrBot Desktop UI 重构方案
+
+## Design read
+
+这是一个 Windows 桌面工具型应用,面向需要同时管理陪伴实例和运维实例的用户;视觉应偏安静、可信、信息密度可控的工作台,而不是营销网站或 SaaS 落地页。
+
+## 设计原则
+
+- 保留业务逻辑和交互路径,先重构视觉层和布局层。
+- 采用单一冷色中性 token 系统,蓝色只承担交互和连接状态,不使用紫蓝渐变。
+- 主任务优先:聊天输入和当前槽位最突出,诊断/连接元信息作为次级层。
+- 让错误、离线、空会话、上传中、重连中都能在同一位置理解和恢复。
+- 桌面优先,窄窗口可收缩;不把移动端营销布局套进桌面工具。
+- 普通 UI 不增加动画;桌宠既有状态动画保留,并加入 reduced-motion 兜底。
+
+## 不变合同
+
+| 范畴 | 保留内容 |
+| ---- | ---------------------------------------------------------------------- |
+| 页面 | `chat`、`connections`、`desktop`、`pet`、`diagnostics` |
+| 连接 | `companion` / `operations` 独立 REST、SSE、Token、会话、消息、未读状态 |
+| 数据 | `profile_id`、`server_instance_id`、`conversation_id` 及现有 schema |
+| IPC | 现有 `invoke()` commands 和 `listen()` event names |
+| 安全 | Rust 持有凭据和本机权限;React 不获得任意文件/命令执行能力 |
+| 测试 | 保留现有 Vitest、Playwright、Rust workspace 检查入口 |
+
+## 分阶段队列
+
+### P0 — 先稳定工作台骨架
+
+- `src/styles.css`:抽取颜色、边框、间距、状态和 z-index tokens;补全统一 `:focus-visible`、disabled、error、loading 语义。
+- `src/App.tsx`:保持页面 key 和事件逻辑不变,清理页面头部层级与导航可读性。
+- `src/features/chat/ChatPanel.tsx`:把运行时状态、槽位 tabs、会话列表、消息流、composer 分成明确的语义区域。
+- 验证:Vitest、typecheck、lint、Vite build;聊天页新增关键交互回归断言。
+
+### P1 — 完善核心页面
+
+- `src/features/profiles/ProfileManager.tsx`、`CredentialEnrollmentCard.tsx`:统一表单布局、字段标签、错误/成功反馈和敏感信息说明。
+- `src/features/chat/StatusBubble.tsx`:统一连接状态颜色、读屏文本和小窗口窄尺寸。
+- `src/App.tsx` 的 `DesktopBehaviorPage`、`DiagnosticsPage`:减少重复卡片,建立明确的设置/诊断分组。
+- 验证:表单与槽位隔离测试、键盘导航检查、窄窗口 Playwright。
+
+### P2 — 性能与一致性
+
+- 页面级拆分 `App.tsx` 中非聊天视图,降低首屏 JS 体积。
+- 清理重复主题覆盖,保留 dark/light 两套可验证 token。
+- 统一消息、状态、按钮、表单的可访问名称与 tooltip;补齐 reduced motion。
+- 验证:生产构建体积对比、Playwright 截图/溢出检查、完整 Rust + frontend gate。
+
+## 首批实施范围
+
+只改聊天页视觉层,具体文件:
+
+- `src/features/chat/ChatPanel.tsx`:仅在需要时补充语义属性或可见标签,不改变数据处理。
+- `src/styles.css`:新增/调整 chat 相关 token 与布局规则,保留现有 class 兼容。
+- `src/App.tsx`:如需调整聊天页外壳,只改 `ChatPage` 的呈现结构,不改导航和 IPC。
+- `src/App.test.tsx`:补充聊天页视觉相关的可访问名称/状态回归,不重写现有业务测试。
+
+## 完成标准
+
+- 聊天发送、切槽位、切会话、附件、语音、重连、停止生成、打开快捷窗口行为不变。
+- 主聊天区域在 1280px、1024px、680px 窗口下无横向溢出。
+- 键盘能到达导航、槽位 tabs、会话、消息操作、输入和发送按钮,焦点可见。
+- 深浅色主题对比度满足 WCAG AA;错误和连接状态不只依赖颜色。
+- 前端 typecheck、lint、unit test、build 通过。
diff --git a/src/App.test.tsx b/src/App.test.tsx
index 439c7d1..4bd6cad 100644
--- a/src/App.test.tsx
+++ b/src/App.test.tsx
@@ -1,4 +1,4 @@
-import { invoke } from "@tauri-apps/api/core";
+import { invoke } from "@tauri-apps/api/core";
import { fireEvent, render, screen, waitFor } from "@testing-library/react";
import { beforeEach, describe, expect, it, vi } from "vitest";
@@ -46,12 +46,13 @@ const emptyPolicy: ConnectionPolicyStatus = {
duplicateServerInstanceWarnings: [],
};
-function openConnectionsPage() {
- fireEvent.click(screen.getByRole("button", { name: /连接/ }));
+async function openConnectionsPage() {
+ fireEvent.click(screen.getByRole("button", { name: /◎连接/ }));
+ await screen.findByRole("heading", { level: 2 }, { timeout: 5000 });
}
function openDiagnosticsPage() {
- fireEvent.click(screen.getByRole("button", { name: /诊断与设置/ }));
+ fireEvent.click(screen.getByRole("button", { name: /⚙诊断与设置/ }));
}
function mockBaseCommands(options?: {
@@ -140,7 +141,7 @@ describe("App", () => {
openDiagnosticsPage();
expect(await screen.findByText("ready")).toBeInTheDocument();
expect(screen.getByText("desktop-v1alpha1")).toBeInTheDocument();
- openConnectionsPage();
+ await openConnectionsPage();
expect(screen.getByText("连接 Profile")).toBeInTheDocument();
});
@@ -223,7 +224,7 @@ describe("App", () => {
vi.spyOn(window, "confirm").mockReturnValue(true);
render( );
- openConnectionsPage();
+ await openConnectionsPage();
expect(await screen.findByText("尚未保存 Profile。")).toBeInTheDocument();
fireEvent.change(screen.getByLabelText("显示名称"), {
@@ -310,7 +311,7 @@ describe("App", () => {
mockBaseCommands({ profiles });
render( );
- openConnectionsPage();
+ await openConnectionsPage();
fireEvent.change(await screen.findByLabelText("陪伴 Profile"), {
target: { value: profiles[0].id },
@@ -364,7 +365,7 @@ describe("App", () => {
});
render( );
- openConnectionsPage();
+ await openConnectionsPage();
expect(await screen.findByText("尚未保存 Profile。")).toBeInTheDocument();
fireEvent.change(screen.getByLabelText("显示名称"), {
@@ -465,7 +466,7 @@ describe("App", () => {
});
render( );
- openConnectionsPage();
+ await openConnectionsPage();
expect(
await screen.findByLabelText("重复服务器实例提示"),
diff --git a/src/App.tsx b/src/App.tsx
index 6b0a126..f4ec5ca 100644
--- a/src/App.tsx
+++ b/src/App.tsx
@@ -1,17 +1,42 @@
import { invoke } from "@tauri-apps/api/core";
import { listen } from "@tauri-apps/api/event";
import { getCurrentWindow } from "@tauri-apps/api/window";
-import { useCallback, useEffect, useRef, useState } from "react";
+import {
+ lazy,
+ Suspense,
+ useCallback,
+ useEffect,
+ useRef,
+ useState,
+} from "react";
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 {
- boundRuntimeEventSchema,
- connectionRuntimeStatusSchema,
-} from "./features/chat/types";
-import aemeathSpritesheet from "./features/pet/assets/aemeath/aemeath-spritesheet.png?inline";
+const ProfileManager = lazy(() =>
+ import("./features/profiles/ProfileManager").then(({ ProfileManager }) => ({
+ default: ProfileManager,
+ })),
+);
+const PetPackImporter = lazy(() =>
+ import("./features/pet/PetPackImporter").then(({ PetPackImporter }) => ({
+ default: PetPackImporter,
+ })),
+);
+const DesktopBehaviorPage = lazy(() =>
+ import("./pages/SettingsPages").then(({ DesktopBehaviorPage }) => ({
+ default: DesktopBehaviorPage,
+ })),
+);
+const DesktopPetView = lazy(() =>
+ import("./features/pet/DesktopPetView").then(({ DesktopPetView }) => ({
+ default: DesktopPetView,
+ })),
+);
+const DiagnosticsPage = lazy(() =>
+ import("./pages/SettingsPages").then(({ DiagnosticsPage }) => ({
+ default: DiagnosticsPage,
+ })),
+);
import { bootstrapStatusSchema, type BootstrapStatus } from "./types/bootstrap";
type PageKey = "chat" | "connections" | "desktop" | "pet" | "diagnostics";
@@ -27,22 +52,6 @@ const initialStatus: BootstrapStatus = {
databaseSchemaVersion: 4,
};
-const AEMEATH_SPRITESHEET = aemeathSpritesheet;
-const PET_TARGET_SLOT = "companion" as const;
-
-const AEMEATH_FRAMES: Record<
- "idle" | "working" | "resting" | "speaking" | "error",
- number[]
-> = {
- idle: [0, 1, 2, 3, 4, 5],
- working: [
- 80, 81, 82, 83, 84, 85, 86, 87, 104, 105, 106, 107, 108, 109, 110, 111,
- ],
- resting: [48, 49, 50, 51, 52, 53],
- speaking: [72, 73, 74, 75, 76, 77, 78, 79],
- error: [40, 41, 42, 43, 44, 45, 46, 47],
-};
-
const navigation: Array<{ key: PageKey; label: string; description: string }> =
[
{ key: "chat", label: "聊天", description: "陪伴与运维对话" },
@@ -179,44 +188,54 @@ export function App() {
}
>
{page === "chat" ? null : }
- {error ?
IPC 暂不可用:{error}
: null}
- {page === "chat" ? : null}
- {page === "connections" ? : null}
- {page === "desktop" ? (
- {
- setBubbleTarget(value);
- localStorage.setItem("astrbot.bubbleTarget", value);
- }}
- onQuickTargetChange={(value) => {
- setQuickTarget(value);
- localStorage.setItem("astrbot.quickTarget", value);
- }}
- onOpenQuickChat={() =>
- void invoke("open_quick_chat_window", { slot: quickTarget })
- }
- />
- ) : null}
- {page === "pet" ? (
- {
- setPetDisplayMode(value);
- localStorage.setItem("astrbot.petDisplayMode", value);
- }}
- />
- ) : null}
- {page === "diagnostics" ? (
- void refreshStatus()}
- />
+ {error ? (
+
+ IPC 暂不可用:{error}
+
) : null}
+ }>
+ {page === "chat" ? : null}
+ {page === "connections" ? : null}
+ {page === "desktop" ? (
+ {
+ setBubbleTarget(value);
+ localStorage.setItem("astrbot.bubbleTarget", value);
+ }}
+ onQuickTargetChange={(value) => {
+ setQuickTarget(value);
+ localStorage.setItem("astrbot.quickTarget", value);
+ }}
+ onOpenQuickChat={() =>
+ void invoke("open_quick_chat_window", { slot: quickTarget })
+ }
+ />
+ ) : null}
+ {page === "pet" ? (
+ {
+ setPetDisplayMode(value);
+ localStorage.setItem("astrbot.petDisplayMode", value);
+ }}
+ />
+ ) : null}
+ {page === "diagnostics" ? (
+ void refreshStatus()}
+ />
+ ) : null}
+
- {petDisplayMode === "app-ui" ? : null}
+ {petDisplayMode === "app-ui" ? (
+
+
+
+ ) : null}
);
}
@@ -323,9 +342,9 @@ function InAppPetOverlay() {
);
return saved && typeof saved.x === "number" && typeof saved.y === "number"
? saved
- : { x: 24, y: 96 };
+ : { x: window.innerWidth >= 720 ? 280 : 24, y: 96 };
} catch {
- return { x: 24, y: 96 };
+ return { x: window.innerWidth >= 720 ? 280 : 24, y: 96 };
}
});
const dragRef = useRef<{
@@ -334,15 +353,34 @@ function InAppPetOverlay() {
offsetY: number;
} | null>(null);
- const savePosition = (x: number, y: number) => {
- const next = {
- x: Math.max(0, Math.min(x, window.innerWidth - 188)),
+ const clampPosition = useCallback((x: number, y: number) => {
+ const safeLeft = window.innerWidth >= 720 ? 248 : 0;
+ const maxX = Math.max(safeLeft, window.innerWidth - 188);
+ return {
+ x: Math.max(safeLeft, Math.min(x, maxX)),
y: Math.max(0, Math.min(y, window.innerHeight - 226)),
};
+ }, []);
+
+ const savePosition = (x: number, y: number) => {
+ const next = clampPosition(x, y);
setPosition(next);
localStorage.setItem("astrbot.petPosition", JSON.stringify(next));
};
+ useEffect(() => {
+ const normalizePosition = () => {
+ const next = clampPosition(position.x, position.y);
+ if (next.x === position.x && next.y === position.y) return;
+ setPosition(next);
+ localStorage.setItem("astrbot.petPosition", JSON.stringify(next));
+ };
+
+ normalizePosition();
+ window.addEventListener("resize", normalizePosition);
+ return () => window.removeEventListener("resize", normalizePosition);
+ }, [clampPosition, position.x, position.y]);
+
useEffect(() => {
let unlisten: (() => void) | undefined;
void listen("pet-hide-requested", () => setVisible(false)).then(
@@ -400,6 +438,14 @@ function navIcon(page: PageKey) {
}[page];
}
+function PageLoading() {
+ return (
+
+ Loading?
+
+ );
+}
+
function PageHeader({ page }: { page: PageKey }) {
const current = navigation.find((item) => item.key === page) ?? navigation[0];
return (
@@ -427,103 +473,6 @@ function ChatPage() {
);
}
-function DesktopBehaviorPage({
- bubbleTarget,
- quickTarget,
- onBubbleTargetChange,
- onQuickTargetChange,
- onOpenQuickChat,
-}: {
- bubbleTarget: "main" | "quick";
- quickTarget: ChatSlot;
- onBubbleTargetChange: (value: "main" | "quick") => void;
- onQuickTargetChange: (value: ChatSlot) => void;
- onOpenQuickChat: () => void;
-}) {
- const [quietHours, setQuietHours] = useState(
- () => localStorage.getItem("astrbot.quietHours") ?? "off",
- );
- return (
-
-
-
-
- 默认目标槽位
-
- onQuickTargetChange(event.target.value as ChatSlot)
- }
- >
- 陪伴实例
- 运维实例
-
-
-
- 立即打开快速聊天
-
-
-
-
- 点击气泡时
-
- onBubbleTargetChange(event.target.value as "main" | "quick")
- }
- >
- 打开主界面
- 打开快速聊天
-
-
-
-
- 气泡状态显示已预留
-
-
-
-
- Desktop companion
- 后续桌面能力
-
- 托盘与单实例
- 窗口置顶开关
- 多显示器策略
- 游戏模式靠边活动
-
-
- 这些能力先保留为独立设置区,后续接入 Rust
- 本机能力层,不会与聊天状态混在一起。
-
-
-
-
- {
- const next = event.target.value;
- setQuietHours(next);
- localStorage.setItem("astrbot.quietHours", next);
- }}
- >
- 关闭
- 每天 22:00–07:00
-
-
-
-
- );
-}
-
function PetPage({
displayMode,
onDisplayModeChange,
@@ -691,343 +640,6 @@ function PetPage({
);
}
-function DesktopPetView({ embedded = false }: { embedded?: boolean }) {
- const [state, setState] = useState<
- "idle" | "working" | "resting" | "speaking" | "error"
- >("idle");
- const [frameIndex, setFrameIndex] = useState(0);
- const [spriteReady, setSpriteReady] = useState(false);
- const [spriteError, setSpriteError] = useState(null);
- const [gameMode, setGameMode] = useState(false);
- const spriteImageRef = useRef(null);
- const spriteCanvasRef = useRef(null);
-
- useEffect(() => {
- if (embedded) return;
- document.documentElement.classList.add("pet-view");
- return () => document.documentElement.classList.remove("pet-view");
- }, [embedded]);
-
- const completionTimerRef = useRef(null);
-
- useEffect(() => {
- let unlisten: (() => void) | undefined;
- let unlistenRuntime: (() => void) | undefined;
- void listen("pet-game-mode-toggle", () =>
- setGameMode((current) => !current),
- ).then((cleanup) => {
- unlisten = cleanup;
- });
- void listen("connection-runtime-event", (event) => {
- const parsed = boundRuntimeEventSchema.safeParse(event.payload);
- if (!parsed.success || parsed.data.slot !== PET_TARGET_SLOT) return;
- if (completionTimerRef.current !== null) {
- window.clearTimeout(completionTimerRef.current);
- completionTimerRef.current = null;
- }
- if (parsed.data.eventType === "message.delta") setState("working");
- if (parsed.data.eventType === "message.proactive") setState("speaking");
- if (parsed.data.eventType === "message.completed") {
- setState("speaking");
- completionTimerRef.current = window.setTimeout(() => {
- completionTimerRef.current = null;
- setState("idle");
- }, 2200);
- }
- if (parsed.data.eventType === "error") setState("error");
- }).then((cleanup) => {
- unlistenRuntime = cleanup;
- });
- return () => {
- unlisten?.();
- unlistenRuntime?.();
- if (completionTimerRef.current !== null) {
- window.clearTimeout(completionTimerRef.current);
- completionTimerRef.current = null;
- }
- };
- }, []);
-
- useEffect(() => {
- const image = new Image();
- image.onload = () => {
- spriteImageRef.current = image;
- setSpriteError(null);
- setSpriteReady(true);
- };
- image.onerror = () => {
- setSpriteError("????????");
- };
- image.src = AEMEATH_SPRITESHEET;
- return () => {
- image.onload = null;
- };
- }, []);
-
- useEffect(() => {
- let cancelled = false;
- void invoke("connection_runtime_status")
- .then((value) => {
- if (cancelled) return;
- try {
- const result = connectionRuntimeStatusSchema.parse(value);
- const state = result.companion.state;
- if (
- state === "authExpired" ||
- state === "fatalError" ||
- state === "incompatible"
- ) {
- setState("error");
- } else if (
- state === "syncing" ||
- state === "connecting" ||
- state === "authenticating"
- ) {
- setState("working");
- } else if (state === "reconnecting") {
- setState("speaking");
- } else if (state === "disconnected" || state === "offline") {
- setState("resting");
- } else {
- setState("idle");
- }
- } catch {
- setState("idle");
- }
- })
- .catch(() => {
- if (!cancelled) setState("idle");
- });
- return () => {
- cancelled = true;
- };
- }, []);
-
- useEffect(() => {
- void invoke("set_pet_window_preferences", {
- preferences: {
- positionMode: "edge",
- monitorIndex: 0,
- alwaysOnTop: true,
- gameMode,
- },
- }).catch(() => undefined);
- }, [gameMode]);
-
- useEffect(() => {
- setFrameIndex(0);
- const frames = AEMEATH_FRAMES[state];
- const timer = window.setInterval(
- () => {
- setFrameIndex((current) => (current + 1) % frames.length);
- },
- state === "resting" ? 180 : 125,
- );
- return () => window.clearInterval(timer);
- }, [state]);
-
- const frame =
- AEMEATH_FRAMES[state][frameIndex % AEMEATH_FRAMES[state].length];
- const frameRow = Math.floor(frame / 8);
- const frameColumn = frame % 8;
-
- useEffect(() => {
- const canvas = spriteCanvasRef.current;
- const image = spriteImageRef.current;
- if (!canvas || !image || !spriteReady) return;
- const context = canvas.getContext("2d");
- if (!context) {
- setSpriteError("???? Canvas ?????");
- return;
- }
- try {
- context.clearRect(0, 0, 192, 208);
- context.imageSmoothingEnabled = false;
- context.drawImage(
- image,
- frameColumn * 192,
- frameRow * 208,
- 192,
- 208,
- 0,
- 0,
- 192,
- 208,
- );
- } catch (reason) {
- setSpriteError(reason instanceof Error ? reason.message : "??????");
- }
- }, [frameColumn, frameRow, spriteReady]);
-
- return (
- {
- if (embedded || event.button !== 0) return;
- void getCurrentWindow().startDragging();
- }}
- onContextMenu={(event) => {
- event.preventDefault();
- void invoke("show_pet_context_menu");
- }}
- >
-
-
-
- {spriteError ? (
- {spriteError}
- ) : null}
- {!spriteReady && !spriteError ? (
- Loading pet...
- ) : null}
-
- {state === "working"
- ? "正在写写画画"
- : state === "resting"
- ? "休息中"
- : state === "speaking"
- ? "正在回应"
- : state === "error"
- ? "需要重新登录或检查连接"
- : "陪伴中"}
-
-
- );
-}
-
-function DiagnosticsTools() {
- const [result, setResult] = useState("");
- const [host, setHost] = useState("127.0.0.1");
- const [port, setPort] = useState("80");
- const [processId, setProcessId] = useState("0");
- const run = async (command: string, request?: Record) => {
- try {
- const value = await invoke(
- command,
- request ? { request } : undefined,
- );
- setResult(JSON.stringify(value, null, 2));
- } catch (reason) {
- setResult(reason instanceof Error ? reason.message : String(reason));
- }
- };
- return (
- <>
-
- {result ? {result} : null}
- >
- );
-}
-
-function DiagnosticsPage({
- status,
- onRefresh,
-}: {
- status: BootstrapStatus;
- onRefresh: () => void;
-}) {
- return (
-
-
-
-
- Security boundary
- 本机能力保持可审计
-
- 凭据只在 Rust 与 Windows 安全存储之间流动。
- 两个 REST/SSE 槽位保持独立状态、会话、消息与未读数。
- 本机操作必须经过白名单、角色、路径和用户授权。
- 文件事务默认保留源文件,不静默覆盖目标。
-
-
-
- 刷新 IPC 状态
-
-
- );
-}
-
function SettingCard({
title,
description,
@@ -1048,16 +660,3 @@ function SettingCard({
);
}
-
-interface StatusCardProps {
- label: string;
- value: string;
-}
-function StatusCard({ label, value }: StatusCardProps) {
- return (
-
- {label}
- {value}
-
- );
-}
diff --git a/src/features/chat/ChatPanel.tsx b/src/features/chat/ChatPanel.tsx
index 3a1a538..5aa03c9 100644
--- a/src/features/chat/ChatPanel.tsx
+++ b/src/features/chat/ChatPanel.tsx
@@ -592,6 +592,22 @@ export function ChatPanel({ fixedSlot }: ChatPanelProps) {
onClick={() => setActiveSlot(slot)}
role="tab"
aria-selected={activeSlot === slot}
+
+ aria-controls={`chat-panel-${slot}`}
+
+ tabIndex={fixedSlot || activeSlot === slot ? 0 : -1}
+
+ onKeyDown={(event) => {
+ if (event.key !== "ArrowRight" && event.key !== "ArrowLeft")
+ return;
+
+ event.preventDefault();
+
+ setActiveSlot(
+ slot === "companion" ? "operations" : "companion",
+ );
+ }}
+
type="button"
>
{slot === "companion" ? "陪伴" : "运维"}
@@ -682,7 +698,14 @@ export function ChatPanel({ fixedSlot }: ChatPanelProps) {
))}
) : null}
-
+
{visibleMessages.length === 0 ? (
No messages in this slot yet. Connect a Profile to start chatting.
@@ -756,11 +779,16 @@ export function ChatPanel({ fixedSlot }: ChatPanelProps) {
})
)}
- {error ?
{error}
: null}
+ {error ? (
+
+ {error}
+
+ ) : null}
添加图片/文件
{
@@ -776,6 +804,7 @@ export function ChatPanel({ fixedSlot }: ChatPanelProps) {
type="button"
onClick={toggleVoiceInput}
className={voiceListening ? "voice-button active" : "voice-button"}
+ aria-pressed={voiceListening}
>
{voiceListening ? "停止录音" : "语音输入"}
diff --git a/src/features/chat/StatusBubble.tsx b/src/features/chat/StatusBubble.tsx
index c5cbb65..9bf0e20 100644
--- a/src/features/chat/StatusBubble.tsx
+++ b/src/features/chat/StatusBubble.tsx
@@ -56,6 +56,7 @@ export function StatusBubble() {
const companion = status.companion.state;
const operations = status.operations.state;
const active = companion === "connected" || operations === "connected";
+ const statusDescription = `${slotLabel(companion, "陪伴实例")};${slotLabel(operations, "运维实例")}`;
const visibleState = quiet
? "静默中"
: active
@@ -64,7 +65,9 @@ export function StatusBubble() {
return (
{
const target =
@@ -82,16 +85,45 @@ export function StatusBubble() {
}
}}
>
-
+
{visibleState}
{unread > 0 && !quiet ? (
{unread}
) : null}
+
+ {statusDescription}
+ {quiet
+ ? ",当前处于静默时段"
+ : unread > 0
+ ? `,${unread} 条未读消息`
+ : ""}
+
);
}
+function slotLabel(
+ state: ConnectionRuntimeStatus["companion"]["state"],
+ name: string,
+) {
+ return `${name}${state === "connected" ? "在线" : stateLabel(state, state)}`;
+}
+
+function statusTone(
+ companion: ConnectionRuntimeStatus["companion"]["state"],
+ operations: ConnectionRuntimeStatus["operations"]["state"],
+) {
+ if (companion === "connected" || operations === "connected") return "online";
+ if (companion === "connecting" || operations === "connecting")
+ return "pending";
+ if (companion === "authExpired" || operations === "authExpired")
+ return "auth";
+ if (companion === "serverUnavailable" || operations === "serverUnavailable")
+ return "error";
+ return "offline";
+}
+
function stateLabel(
companion: ConnectionRuntimeStatus["companion"]["state"],
operations: ConnectionRuntimeStatus["operations"]["state"],
diff --git a/src/features/pet/DesktopPetView.tsx b/src/features/pet/DesktopPetView.tsx
new file mode 100644
index 0000000..554b8aa
--- /dev/null
+++ b/src/features/pet/DesktopPetView.tsx
@@ -0,0 +1,242 @@
+import { invoke } from "@tauri-apps/api/core";
+import { listen } from "@tauri-apps/api/event";
+import { getCurrentWindow } from "@tauri-apps/api/window";
+import { useEffect, useRef, useState } from "react";
+
+import {
+ boundRuntimeEventSchema,
+ connectionRuntimeStatusSchema,
+} from "../chat/types";
+import aemeathSpritesheet from "./assets/aemeath/aemeath-spritesheet.png?inline";
+
+const AEMEATH_SPRITESHEET = aemeathSpritesheet;
+const PET_TARGET_SLOT = "companion" as const;
+const AEMEATH_FRAMES: Record<
+ "idle" | "working" | "resting" | "speaking" | "error",
+ number[]
+> = {
+ idle: [0, 1, 2, 3, 4, 5],
+ working: [
+ 80, 81, 82, 83, 84, 85, 86, 87, 104, 105, 106, 107, 108, 109, 110, 111,
+ ],
+ resting: [48, 49, 50, 51, 52, 53],
+ speaking: [72, 73, 74, 75, 76, 77, 78, 79],
+ error: [40, 41, 42, 43, 44, 45, 46, 47],
+};
+
+export function DesktopPetView({ embedded = false }: { embedded?: boolean }) {
+ const [state, setState] = useState<
+ "idle" | "working" | "resting" | "speaking" | "error"
+ >("idle");
+ const [frameIndex, setFrameIndex] = useState(0);
+ const [spriteReady, setSpriteReady] = useState(false);
+ const [spriteError, setSpriteError] = useState(null);
+ const [gameMode, setGameMode] = useState(false);
+ const spriteImageRef = useRef(null);
+ const spriteCanvasRef = useRef(null);
+
+ useEffect(() => {
+ if (embedded) return;
+ document.documentElement.classList.add("pet-view");
+ return () => document.documentElement.classList.remove("pet-view");
+ }, [embedded]);
+
+ const completionTimerRef = useRef(null);
+
+ useEffect(() => {
+ let unlisten: (() => void) | undefined;
+ let unlistenRuntime: (() => void) | undefined;
+ void listen("pet-game-mode-toggle", () =>
+ setGameMode((current) => !current),
+ ).then((cleanup) => {
+ unlisten = cleanup;
+ });
+ void listen("connection-runtime-event", (event) => {
+ const parsed = boundRuntimeEventSchema.safeParse(event.payload);
+ if (!parsed.success || parsed.data.slot !== PET_TARGET_SLOT) return;
+ if (completionTimerRef.current !== null) {
+ window.clearTimeout(completionTimerRef.current);
+ completionTimerRef.current = null;
+ }
+ if (parsed.data.eventType === "message.delta") setState("working");
+ if (parsed.data.eventType === "message.proactive") setState("speaking");
+ if (parsed.data.eventType === "message.completed") {
+ setState("speaking");
+ completionTimerRef.current = window.setTimeout(() => {
+ completionTimerRef.current = null;
+ setState("idle");
+ }, 2200);
+ }
+ if (parsed.data.eventType === "error") setState("error");
+ }).then((cleanup) => {
+ unlistenRuntime = cleanup;
+ });
+ return () => {
+ unlisten?.();
+ unlistenRuntime?.();
+ if (completionTimerRef.current !== null) {
+ window.clearTimeout(completionTimerRef.current);
+ completionTimerRef.current = null;
+ }
+ };
+ }, []);
+
+ useEffect(() => {
+ const image = new Image();
+ image.onload = () => {
+ spriteImageRef.current = image;
+ setSpriteError(null);
+ setSpriteReady(true);
+ };
+ image.onerror = () => {
+ setSpriteError("????????");
+ };
+ image.src = AEMEATH_SPRITESHEET;
+ return () => {
+ image.onload = null;
+ };
+ }, []);
+
+ useEffect(() => {
+ let cancelled = false;
+ void invoke("connection_runtime_status")
+ .then((value) => {
+ if (cancelled) return;
+ try {
+ const result = connectionRuntimeStatusSchema.parse(value);
+ const state = result.companion.state;
+ if (
+ state === "authExpired" ||
+ state === "fatalError" ||
+ state === "incompatible"
+ ) {
+ setState("error");
+ } else if (
+ state === "syncing" ||
+ state === "connecting" ||
+ state === "authenticating"
+ ) {
+ setState("working");
+ } else if (state === "reconnecting") {
+ setState("speaking");
+ } else if (state === "disconnected" || state === "offline") {
+ setState("resting");
+ } else {
+ setState("idle");
+ }
+ } catch {
+ setState("idle");
+ }
+ })
+ .catch(() => {
+ if (!cancelled) setState("idle");
+ });
+ return () => {
+ cancelled = true;
+ };
+ }, []);
+
+ useEffect(() => {
+ void invoke("set_pet_window_preferences", {
+ preferences: {
+ positionMode: "edge",
+ monitorIndex: 0,
+ alwaysOnTop: true,
+ gameMode,
+ },
+ }).catch(() => undefined);
+ }, [gameMode]);
+
+ useEffect(() => {
+ setFrameIndex(0);
+ const frames = AEMEATH_FRAMES[state];
+ const timer = window.setInterval(
+ () => {
+ setFrameIndex((current) => (current + 1) % frames.length);
+ },
+ state === "resting" ? 180 : 125,
+ );
+ return () => window.clearInterval(timer);
+ }, [state]);
+
+ const frame =
+ AEMEATH_FRAMES[state][frameIndex % AEMEATH_FRAMES[state].length];
+ const frameRow = Math.floor(frame / 8);
+ const frameColumn = frame % 8;
+
+ useEffect(() => {
+ const canvas = spriteCanvasRef.current;
+ const image = spriteImageRef.current;
+ if (!canvas || !image || !spriteReady) return;
+ const context = canvas.getContext("2d");
+ if (!context) {
+ setSpriteError("???? Canvas ?????");
+ return;
+ }
+ try {
+ context.clearRect(0, 0, 192, 208);
+ context.imageSmoothingEnabled = false;
+ context.drawImage(
+ image,
+ frameColumn * 192,
+ frameRow * 208,
+ 192,
+ 208,
+ 0,
+ 0,
+ 192,
+ 208,
+ );
+ } catch (reason) {
+ setSpriteError(reason instanceof Error ? reason.message : "??????");
+ }
+ }, [frameColumn, frameRow, spriteReady]);
+
+ return (
+ {
+ if (embedded || event.button !== 0) return;
+ void getCurrentWindow().startDragging();
+ }}
+ onContextMenu={(event) => {
+ event.preventDefault();
+ void invoke("show_pet_context_menu");
+ }}
+ >
+
+
+
+ {spriteError ? (
+ {spriteError}
+ ) : null}
+ {!spriteReady && !spriteError ? (
+ Loading pet...
+ ) : null}
+
+ {state === "working"
+ ? "正在写写画画"
+ : state === "resting"
+ ? "休息中"
+ : state === "speaking"
+ ? "正在回应"
+ : state === "error"
+ ? "需要重新登录或检查连接"
+ : "陪伴中"}
+
+
+ );
+}
diff --git a/src/features/pet/PetPackImporter.tsx b/src/features/pet/PetPackImporter.tsx
index d961781..861531d 100644
--- a/src/features/pet/PetPackImporter.tsx
+++ b/src/features/pet/PetPackImporter.tsx
@@ -12,14 +12,18 @@ export function PetPackImporter() {
setManifest(null);
setError(null);
if (!file.name.toLowerCase().endsWith(".json") || file.size > 256 * 1024) {
- setError("文件必须是 256 KiB 以内的 JSON manifest。若要导入图片,请先放入素材包目录。 ");
+ setError(
+ "文件必须是 256 KiB 以内的 JSON manifest。若要导入图片,请先放入素材包目录。 ",
+ );
return;
}
try {
const parsed = petPackManifestSchema.parse(JSON.parse(await file.text()));
setManifest(parsed);
} catch (reason) {
- setError(reason instanceof Error ? reason.message : "无法读取桌宠 manifest。 ");
+ setError(
+ reason instanceof Error ? reason.message : "无法读取桌宠 manifest。 ",
+ );
}
};
@@ -42,7 +46,11 @@ export function PetPackImporter() {
}}
/>
{fileName ? 已选择:{fileName}
: null}
- {error ? {error}
: null}
+ {error ? (
+
+ {error}
+
+ ) : null}
{manifest ? (
{manifest.name}
@@ -52,7 +60,12 @@ export function PetPackImporter() {
{manifest.animations.length} 个动作片段
- {manifest.animations.filter((animation) => animation.movement !== "stationary").length} 个移动动作
+ {
+ manifest.animations.filter(
+ (animation) => animation.movement !== "stationary",
+ ).length
+ }{" "}
+ 个移动动作
) : null}
diff --git a/src/features/profiles/CredentialEnrollmentCard.tsx b/src/features/profiles/CredentialEnrollmentCard.tsx
index 47d98d3..8b340e8 100644
--- a/src/features/profiles/CredentialEnrollmentCard.tsx
+++ b/src/features/profiles/CredentialEnrollmentCard.tsx
@@ -1,11 +1,26 @@
import { useState } from "react";
import { invoke } from "@tauri-apps/api/core";
-import type { AuthenticationType, ConnectionProfile } from "../../types/profile";
+import type {
+ AuthenticationType,
+ ConnectionProfile,
+} from "../../types/profile";
-interface CredentialEnrollmentResult { profileId: string; credentialReference: string; authenticationType: AuthenticationType; }
-interface JwtLoginResult { profileId: string; credentialReference: string; dashboardUsername: string; authenticationType: "jwt"; }
-interface Props { profile: ConnectionProfile; onChanged: () => Promise | void; }
+interface CredentialEnrollmentResult {
+ profileId: string;
+ credentialReference: string;
+ authenticationType: AuthenticationType;
+}
+interface JwtLoginResult {
+ profileId: string;
+ credentialReference: string;
+ dashboardUsername: string;
+ authenticationType: "jwt";
+}
+interface Props {
+ profile: ConnectionProfile;
+ onChanged: () => Promise | void;
+}
export function CredentialEnrollmentCard({ profile, onChanged }: Props) {
const [secret, setSecret] = useState("");
@@ -17,51 +32,163 @@ export function CredentialEnrollmentCard({ profile, onChanged }: Props) {
const [message, setMessage] = useState(null);
async function enroll() {
- setBusy(true); setMessage(null);
+ setBusy(true);
+ setMessage(null);
try {
- const result = await invoke("enroll_profile_credential", { request: { profileId: profile.id, authenticationType: profile.authenticationType, secret, username: remoteId.trim() || undefined } });
- setSecret(""); setMessage(`已登记凭据引用 ${result.credentialReference}`); await onChanged();
- } catch (error) { setMessage(error instanceof Error ? error.message : "凭据登记失败。"); }
- finally { setBusy(false); }
+ const result = await invoke(
+ "enroll_profile_credential",
+ {
+ request: {
+ profileId: profile.id,
+ authenticationType: profile.authenticationType,
+ secret,
+ username: remoteId.trim() || undefined,
+ },
+ },
+ );
+ setSecret("");
+ setMessage(`已登记凭据引用 ${result.credentialReference}`);
+ await onChanged();
+ } catch (error) {
+ setMessage(error instanceof Error ? error.message : "凭据登记失败。");
+ } finally {
+ setBusy(false);
+ }
}
async function loginJwt() {
- setBusy(true); setMessage(null);
+ setBusy(true);
+ setMessage(null);
try {
- const result = await invoke("login_profile_jwt", { request: { profileId: profile.id, username: dashboardUsername.trim(), password: dashboardPassword, totp: totp.trim() || undefined } });
- setDashboardPassword(""); setTotp(""); setMessage(`JWT 登录成功,凭据引用 ${result.credentialReference}`); await onChanged();
- } catch (error) { setMessage(error instanceof Error ? error.message : "JWT 登录失败。"); }
- finally { setBusy(false); }
+ const result = await invoke("login_profile_jwt", {
+ request: {
+ profileId: profile.id,
+ username: dashboardUsername.trim(),
+ password: dashboardPassword,
+ totp: totp.trim() || undefined,
+ },
+ });
+ setDashboardPassword("");
+ setTotp("");
+ setMessage(`JWT 登录成功,凭据引用 ${result.credentialReference}`);
+ await onChanged();
+ } catch (error) {
+ setMessage(error instanceof Error ? error.message : "JWT 登录失败。");
+ } finally {
+ setBusy(false);
+ }
}
async function clearCredential() {
- setBusy(true); setMessage(null);
- try { await invoke("clear_profile_credential", { profileId: profile.id }); setMessage("已清除凭据引用"); await onChanged(); }
- catch (error) { setMessage(error instanceof Error ? error.message : "清除凭据失败。"); }
- finally { setBusy(false); }
+ setBusy(true);
+ setMessage(null);
+ try {
+ await invoke("clear_profile_credential", { profileId: profile.id });
+ setMessage("已清除凭据引用");
+ await onChanged();
+ } catch (error) {
+ setMessage(error instanceof Error ? error.message : "清除凭据失败。");
+ } finally {
+ setBusy(false);
+ }
}
return (
-
+
);
}
diff --git a/src/pages/SettingsPages.tsx b/src/pages/SettingsPages.tsx
new file mode 100644
index 0000000..f187afd
--- /dev/null
+++ b/src/pages/SettingsPages.tsx
@@ -0,0 +1,277 @@
+import { invoke } from "@tauri-apps/api/core";
+import { useState } from "react";
+
+import type { BootstrapStatus } from "../types/bootstrap";
+
+export type SettingsChatSlot = "companion" | "operations";
+
+export function DesktopBehaviorPage({
+ bubbleTarget,
+ quickTarget,
+ onBubbleTargetChange,
+ onQuickTargetChange,
+ onOpenQuickChat,
+}: {
+ bubbleTarget: "main" | "quick";
+ quickTarget: SettingsChatSlot;
+ onBubbleTargetChange: (value: "main" | "quick") => void;
+ onQuickTargetChange: (value: SettingsChatSlot) => void;
+ onOpenQuickChat: () => void;
+}) {
+ const [quietHours, setQuietHours] = useState(
+ () => localStorage.getItem("astrbot.quietHours") ?? "off",
+ );
+ return (
+
+
+
+
+ 默认目标槽位
+
+ onQuickTargetChange(event.target.value as SettingsChatSlot)
+ }
+ >
+ 陪伴实例
+ 运维实例
+
+
+
+ 立即打开快速聊天
+
+
+
+
+ 点击气泡时
+
+ onBubbleTargetChange(event.target.value as "main" | "quick")
+ }
+ >
+ 打开主界面
+ 打开快速聊天
+
+
+
+
+ 气泡状态显示已预留
+
+
+
+
+ Desktop companion
+ 后续桌面能力
+
+ 托盘与单实例
+ 窗口置顶开关
+ 多显示器策略
+ 游戏模式靠边活动
+
+
+ 这些能力先保留为独立设置区,后续接入 Rust
+ 本机能力层,不会与聊天状态混在一起。
+
+
+
+
+ {
+ const next = event.target.value;
+ setQuietHours(next);
+ localStorage.setItem("astrbot.quietHours", next);
+ }}
+ >
+ 关闭
+ 每天 22:00–07:00
+
+
+
+
+ );
+}
+
+function DiagnosticsTools() {
+ const [result, setResult] = useState("");
+ const [busy, setBusy] = useState(false);
+ const [host, setHost] = useState("127.0.0.1");
+ const [port, setPort] = useState("80");
+ const [processId, setProcessId] = useState("0");
+ const run = async (command: string, request?: Record) => {
+ setBusy(true);
+ try {
+ const value = await invoke(
+ command,
+ request ? { request } : undefined,
+ );
+ setResult(JSON.stringify(value, null, 2));
+ } catch (reason) {
+ setResult(reason instanceof Error ? reason.message : String(reason));
+ } finally {
+ setBusy(false);
+ }
+ };
+ return (
+ <>
+
+ {result ? (
+
+ {result}
+
+ ) : null}
+ >
+ );
+}
+
+export function DiagnosticsPage({
+ status,
+ onRefresh,
+}: {
+ status: BootstrapStatus;
+ onRefresh: () => void;
+}) {
+ return (
+
+
+
+
+ Security boundary
+ 本机能力保持可审计
+
+ 凭据只在 Rust 与 Windows 安全存储之间流动。
+ 两个 REST/SSE 槽位保持独立状态、会话、消息与未读数。
+ 本机操作必须经过白名单、角色、路径和用户授权。
+ 文件事务默认保留源文件,不静默覆盖目标。
+
+
+
+ 刷新 IPC 状态
+
+
+ );
+}
+
+export function SettingCard({
+ title,
+ description,
+ children,
+}: {
+ title: string;
+ description: string;
+ children: React.ReactNode;
+}) {
+ return (
+
+
+
Settings
+
{title}
+
{description}
+
+ {children}
+
+ );
+}
+
+interface StatusCardProps {
+ label: string;
+ value: string;
+}
+function StatusCard({ label, value }: StatusCardProps) {
+ return (
+
+ {label}
+ {value}
+
+ );
+}
diff --git a/src/styles.css b/src/styles.css
index b10f69f..eb00f34 100644
--- a/src/styles.css
+++ b/src/styles.css
@@ -2295,3 +2295,794 @@ body,
font-size: 12px;
padding: 8px 10px;
}
+
+:root {
+ --ui-bg: #091321;
+ --ui-surface: #101e30;
+ --ui-surface-raised: #15263c;
+ --ui-surface-soft: #0d1929;
+ --ui-line: rgb(151 180 218 / 22%);
+ --ui-line-strong: rgb(151 194 255 / 48%);
+ --ui-ink: #eef4ff;
+ --ui-muted: #9fb2ce;
+ --ui-subtle: #71849f;
+ --ui-accent: #8bbaff;
+ --ui-accent-strong: #b7d5ff;
+ --ui-success: #8bd3a6;
+ --ui-warning: #f2c078;
+ --ui-danger: #ffb3b3;
+ --ui-radius-sm: 0.55rem;
+ --ui-radius-md: 0.8rem;
+ --ui-radius-lg: 1rem;
+ --ui-shadow: 0 0.75rem 2rem rgb(2 10 21 / 26%);
+}
+
+:root[data-theme="light"] {
+ --ui-bg: #edf3fa;
+ --ui-surface: #f8fbff;
+ --ui-surface-raised: #ffffff;
+ --ui-surface-soft: #eaf1f9;
+ --ui-line: rgb(48 83 126 / 18%);
+ --ui-line-strong: rgb(44 105 178 / 44%);
+ --ui-ink: #1b2c43;
+ --ui-muted: #526987;
+ --ui-subtle: #6d819c;
+ --ui-accent: #2c6eae;
+ --ui-accent-strong: #1f5287;
+ --ui-success: #2f7d4f;
+ --ui-warning: #9a661b;
+ --ui-danger: #a53f4c;
+ --ui-shadow: 0 0.75rem 2rem rgb(53 86 123 / 12%);
+}
+
+:root,
+button,
+input,
+select,
+textarea {
+ font-variant-numeric: tabular-nums;
+}
+
+button:focus-visible,
+input:focus-visible,
+select:focus-visible,
+textarea:focus-visible,
+[tabindex]:focus-visible {
+ outline: 2px solid var(--ui-accent);
+ outline-offset: 2px;
+}
+
+.chat-panel {
+ gap: 0.8rem;
+ padding: clamp(0.9rem, 1.5vw, 1.35rem);
+ border: 1px solid var(--ui-line);
+ border-radius: var(--ui-radius-lg);
+ background: var(--ui-surface);
+ box-shadow: var(--ui-shadow);
+}
+
+.chat-heading {
+ display: flex;
+ align-items: flex-start;
+ justify-content: space-between;
+ gap: 1.25rem;
+ padding-bottom: 0.15rem;
+}
+
+.chat-heading h2 {
+ max-width: 32rem;
+ color: var(--ui-ink);
+ font-size: clamp(1.15rem, 1.7vw, 1.45rem);
+ letter-spacing: -0.02em;
+ text-wrap: balance;
+}
+
+.chat-note,
+.chat-empty,
+.chat-error {
+ color: var(--ui-muted);
+}
+
+.chat-note {
+ max-width: 48rem;
+ line-height: 1.55;
+}
+
+.chat-slot-tabs {
+ flex: 0 0 auto;
+ align-items: stretch;
+ padding: 0.25rem;
+ border: 1px solid var(--ui-line);
+ border-radius: var(--ui-radius-md);
+ background: var(--ui-surface-soft);
+}
+
+.chat-slot {
+ min-width: 7.2rem;
+ min-height: 3.25rem;
+ border: 1px solid transparent;
+ border-radius: var(--ui-radius-sm);
+ color: var(--ui-muted);
+ background: transparent;
+ box-shadow: none;
+}
+
+.chat-slot:hover:not(:disabled) {
+ color: var(--ui-ink);
+ background: rgb(139 186 255 / 10%);
+}
+
+.chat-slot.active {
+ border-color: var(--ui-line-strong);
+ color: var(--ui-ink);
+ background: var(--ui-surface-raised);
+ box-shadow: 0 0.2rem 0.7rem rgb(2 10 21 / 16%);
+}
+
+.chat-slot span {
+ color: var(--ui-subtle);
+}
+
+.chat-slot.active span {
+ color: var(--ui-accent);
+}
+
+.chat-runtime-strip {
+ display: grid;
+ grid-template-columns: repeat(3, minmax(0, 1fr)) auto;
+ gap: 0.75rem;
+ align-items: center;
+ padding: 0.7rem 0.85rem;
+ border: 1px solid var(--ui-line);
+ border-radius: var(--ui-radius-md);
+ color: var(--ui-muted);
+ background: var(--ui-surface-soft);
+}
+
+.chat-runtime-strip span {
+ color: var(--ui-subtle);
+ font-size: 0.7rem;
+ letter-spacing: 0.04em;
+ text-transform: uppercase;
+}
+
+.chat-runtime-strip strong {
+ color: var(--ui-ink);
+ font-size: 0.8rem;
+}
+
+.chat-runtime-actions {
+ justify-content: flex-end;
+}
+
+.chat-runtime-actions button,
+.chat-message-actions button,
+.chat-stop-button {
+ min-height: 2rem;
+ border: 1px solid var(--ui-line);
+ border-radius: 999px;
+ color: var(--ui-muted);
+ background: transparent;
+}
+
+.chat-runtime-actions button:hover,
+.chat-message-actions button:hover,
+.chat-stop-button:hover {
+ border-color: var(--ui-line-strong);
+ color: var(--ui-ink);
+ background: rgb(139 186 255 / 10%);
+}
+
+.chat-message-list {
+ gap: 0.9rem;
+ padding: clamp(0.8rem, 1.8vw, 1.25rem);
+ border: 1px solid var(--ui-line);
+ border-radius: var(--ui-radius-md);
+ background: var(--ui-surface-soft);
+ scrollbar-color: var(--ui-line-strong) transparent;
+}
+
+.chat-empty {
+ max-width: 26rem;
+ margin-inline: auto;
+ line-height: 1.6;
+}
+
+.chat-message-row {
+ width: min(78%, 48rem);
+ gap: 0.7rem;
+}
+
+.chat-avatar {
+ flex-basis: 2rem;
+ width: 2rem;
+ height: 2rem;
+ color: var(--ui-ink);
+ background: var(--ui-surface-raised);
+ box-shadow: none;
+}
+
+.chat-message-row.user .chat-avatar {
+ color: var(--ui-accent-strong);
+ background: #254c78;
+}
+
+.chat-bubble {
+ padding: 0.7rem 0.85rem 0.8rem;
+ border: 1px solid var(--ui-line);
+ border-radius: var(--ui-radius-md);
+ color: var(--ui-ink);
+ background: var(--ui-surface-raised);
+ box-shadow: none;
+}
+
+.chat-message-row.user .chat-bubble {
+ border-color: var(--ui-line-strong);
+ color: var(--ui-ink);
+ background: rgb(67 120 181 / 28%);
+}
+
+.chat-bubble-header {
+ margin-bottom: 0.35rem;
+ color: var(--ui-accent);
+}
+
+.chat-message-row.user .chat-bubble-header {
+ color: var(--ui-accent-strong);
+}
+
+.chat-composer-toolbar {
+ gap: 0.55rem;
+ padding-top: 0.1rem;
+}
+
+.chat-composer {
+ grid-template-columns: minmax(0, 1fr) auto;
+ gap: 0.7rem;
+ align-items: end;
+ padding: 0.75rem;
+ border: 1px solid var(--ui-line-strong);
+ border-radius: var(--ui-radius-md);
+ background: var(--ui-surface-raised);
+}
+
+.chat-composer textarea {
+ min-height: 4.25rem;
+ padding: 0.8rem 0.85rem;
+ border: 1px solid var(--ui-line);
+ border-radius: var(--ui-radius-sm);
+ color: var(--ui-ink);
+ background: var(--ui-surface-soft);
+ line-height: 1.5;
+}
+
+.chat-composer > button[type="submit"] {
+ min-width: 5rem;
+ min-height: 2.75rem;
+ border-color: var(--ui-accent);
+ color: #071321;
+ background: var(--ui-accent);
+ font-weight: 700;
+}
+
+.chat-composer > button[type="submit"]:hover:not(:disabled) {
+ background: var(--ui-accent-strong);
+}
+
+.attachment-list {
+ gap: 0.45rem;
+ padding: 0.1rem 0;
+}
+
+.attachment-list > span {
+ border: 1px solid var(--ui-line);
+ border-radius: 999px;
+ color: var(--ui-muted);
+ background: var(--ui-surface-soft);
+}
+
+@media (max-width: 900px) {
+ .chat-heading {
+ flex-direction: column;
+ }
+
+ .chat-slot-tabs {
+ width: 100%;
+ }
+
+ .chat-slot {
+ flex: 1 1 0;
+ }
+
+ .chat-runtime-strip {
+ grid-template-columns: repeat(3, minmax(0, 1fr));
+ }
+
+ .chat-runtime-actions {
+ grid-column: 1 / -1;
+ justify-content: flex-start;
+ }
+}
+
+@media (max-width: 680px) {
+ .chat-panel {
+ padding: 0.7rem;
+ }
+
+ .chat-runtime-strip {
+ grid-template-columns: 1fr 1fr;
+ }
+
+ .chat-runtime-strip > div:nth-child(3) {
+ grid-column: 1 / -1;
+ }
+
+ .chat-message-row {
+ width: 94%;
+ }
+
+ .chat-composer {
+ grid-template-columns: 1fr;
+ }
+
+ .chat-composer > button[type="submit"] {
+ width: 100%;
+ }
+}
+
+@media (prefers-reduced-motion: reduce) {
+ *,
+ *::before,
+ *::after {
+ animation-duration: 0.01ms !important;
+ animation-iteration-count: 1 !important;
+ scroll-behavior: auto !important;
+ transition-duration: 0.01ms !important;
+ }
+}
+
+.chat-panel {
+ font-family:
+ "Segoe UI Variable", "Segoe UI", ui-sans-serif, system-ui, sans-serif;
+}
+
+.chat-slot[role="tab"] {
+ min-height: 2.75rem;
+ touch-action: manipulation;
+}
+
+.chat-slot[role="tab"][aria-selected="true"] {
+ color: var(--ui-ink);
+}
+
+.chat-runtime-actions button,
+.chat-message-actions button,
+.chat-stop-button,
+.voice-button,
+.file-picker,
+.chat-composer > button[type="submit"] {
+ min-height: 2.5rem;
+ touch-action: manipulation;
+}
+
+.chat-runtime-actions button:disabled {
+ border-color: var(--ui-line);
+ color: var(--ui-subtle);
+ background: transparent;
+}
+
+.chat-message-list {
+ overflow: auto;
+ overscroll-behavior: contain;
+ scrollbar-gutter: stable;
+}
+
+.chat-error {
+ margin: 0;
+ padding: 0.7rem 0.85rem;
+ border: 1px solid rgb(255 179 179 / 42%);
+ border-radius: var(--ui-radius-sm);
+ color: var(--ui-danger);
+ background: rgb(165 63 76 / 12%);
+}
+
+.file-picker {
+ position: relative;
+ min-width: 8rem;
+ justify-content: center;
+}
+
+.file-picker:focus-within {
+ outline: 2px solid var(--ui-accent);
+ outline-offset: 2px;
+}
+
+.file-picker-input {
+ position: absolute;
+ width: 1px;
+ height: 1px;
+ padding: 0;
+ margin: -1px;
+ overflow: hidden;
+ clip: rect(0, 0, 0, 0);
+ white-space: nowrap;
+ border: 0;
+}
+
+.file-picker:has(.file-picker-input:disabled) {
+ cursor: not-allowed;
+ opacity: 0.55;
+}
+
+.voice-button.active {
+ border-color: var(--ui-accent);
+ color: var(--ui-ink);
+ background: rgb(139 186 255 / 18%);
+}
+
+@media (max-width: 520px) {
+ .chat-runtime-strip {
+ grid-template-columns: 1fr;
+ }
+
+ .chat-runtime-strip > div:nth-child(3) {
+ grid-column: auto;
+ }
+
+ .chat-runtime-actions {
+ display: grid;
+ grid-template-columns: repeat(2, minmax(0, 1fr));
+ }
+
+ .chat-runtime-actions button,
+ .chat-message-actions button,
+ .chat-stop-button,
+ .voice-button,
+ .file-picker {
+ width: 100%;
+ }
+
+ .chat-message-actions {
+ display: grid;
+ grid-template-columns: repeat(3, minmax(0, 1fr));
+ }
+}
+
+:root {
+ --ui-shadow: 0 0.35rem 0.75rem rgb(2 10 21 / 22%);
+ font-family:
+ "Segoe UI Variable", "Segoe UI", ui-sans-serif, system-ui, sans-serif;
+ font-variant-numeric: tabular-nums;
+}
+
+:root[data-theme="light"] {
+ --ui-shadow: 0 0.35rem 0.75rem rgb(53 86 123 / 12%);
+}
+
+html,
+body,
+#root {
+ background: var(--ui-bg);
+ color: var(--ui-ink);
+}
+
+body {
+ background-image: none;
+}
+
+h1,
+h2,
+h3 {
+ text-wrap: balance;
+}
+
+p,
+li {
+ text-wrap: pretty;
+}
+
+.eyebrow,
+.section-kicker {
+ letter-spacing: 0.04em;
+ text-transform: none;
+}
+
+.app-shell {
+ border-color: var(--ui-line);
+ border-radius: var(--ui-radius-lg);
+ background: var(--ui-surface);
+ box-shadow: var(--ui-shadow);
+}
+
+.app-sidebar,
+.window-chrome {
+ border-color: var(--ui-line);
+ background: var(--ui-surface-soft);
+}
+
+.window-chrome,
+.window-chrome-title,
+.window-theme-toggle {
+ color: var(--ui-ink);
+}
+
+.brand-lockup span,
+.nav-item small,
+.page-header .subtitle,
+.section-heading > p,
+.form-note,
+.empty-state {
+ color: var(--ui-muted);
+}
+
+.brand-mark {
+ border-color: var(--ui-accent);
+ color: var(--ui-bg);
+ background: var(--ui-accent);
+}
+
+.nav-item {
+ border-color: transparent;
+ color: var(--ui-muted);
+ background: transparent;
+}
+
+.nav-item:hover,
+.nav-item.active {
+ border-color: var(--ui-line-strong);
+ color: var(--ui-ink);
+ background: var(--ui-surface-raised);
+}
+
+.nav-item-icon {
+ color: var(--ui-accent);
+ background: rgb(139 186 255 / 10%);
+}
+
+button {
+ border-color: var(--ui-line-strong);
+ color: var(--ui-ink);
+ background: var(--ui-surface-raised);
+}
+
+button:hover:not(:disabled) {
+ background: var(--ui-surface-soft);
+}
+
+input,
+select,
+textarea {
+ border-color: var(--ui-line);
+ color: var(--ui-ink);
+ background: var(--ui-surface-raised);
+}
+
+.status-card,
+.boundaries,
+.error-banner,
+.profile-manager,
+.profile-form,
+.profile-list,
+.slot-card,
+.setting-card,
+.pet-pack-importer,
+.pet-inline-preview,
+.welcome-card,
+.info-card {
+ border-color: var(--ui-line);
+ background: var(--ui-surface);
+ box-shadow: none;
+}
+
+.status-card span,
+.profile-card span,
+.profile-form label > span,
+.setting-card-controls label span,
+.slot-card > div span,
+.slot-card label > span {
+ color: var(--ui-muted);
+}
+
+.status-card strong,
+.profile-card code,
+.slot-card strong {
+ color: var(--ui-ink);
+}
+
+.page-header h1,
+.boundaries h2,
+.setting-card h2,
+.profile-manager h2,
+.profile-manager h3 {
+ color: var(--ui-ink);
+}
+
+.error-banner,
+.chat-runtime-error {
+ border-color: rgb(255 179 179 / 42%);
+ color: var(--ui-danger);
+ background: rgb(165 63 76 / 12%);
+}
+
+.diagnostic-field {
+ display: grid;
+ gap: 0.4rem;
+}
+
+.diagnostic-field span {
+ color: var(--ui-muted);
+ font-size: 0.8rem;
+ font-weight: 600;
+}
+
+.loading-state {
+ margin: 0;
+ padding: 1rem;
+ color: var(--ui-muted);
+}
+
+.sr-only {
+ position: absolute;
+ width: 1px;
+ height: 1px;
+ padding: 0;
+ margin: -1px;
+ overflow: hidden;
+ clip: rect(0, 0, 0, 0);
+ white-space: nowrap;
+ border: 0;
+}
+
+.status-bubble-online .status-bubble-orb {
+ background: var(--ui-success);
+}
+
+.status-bubble-pending .status-bubble-orb {
+ background: var(--ui-warning);
+}
+
+.status-bubble-auth .status-bubble-orb,
+.status-bubble-error .status-bubble-orb {
+ background: var(--ui-danger);
+}
+
+.status-bubble-offline .status-bubble-orb {
+ background: var(--ui-muted);
+}
+
+.credential-card {
+ display: grid;
+ gap: 0.75rem;
+ padding: 1rem;
+ border: 1px solid var(--ui-line);
+ border-radius: var(--ui-radius-md);
+ background: var(--ui-surface-soft);
+}
+
+.credential-card label {
+ display: grid;
+ gap: 0.4rem;
+}
+
+.credential-card label > span {
+ color: var(--ui-muted);
+ font-size: 0.8rem;
+ font-weight: 600;
+}
+
+.credential-card button {
+ min-height: 2.5rem;
+}
+
+.diagnostic-result {
+ max-height: 18rem;
+ overflow: auto;
+ white-space: pre-wrap;
+ overflow-wrap: anywhere;
+}
+
+button:disabled {
+ cursor: not-allowed;
+}
+
+.app-pet-overlay {
+ z-index: 10;
+}
+
+.chat-session-list {
+ scrollbar-color: var(--ui-line-strong) transparent;
+}
+
+@media (max-width: 680px) {
+ .chat-session-list {
+ display: grid;
+ grid-template-columns: repeat(2, minmax(0, 1fr));
+ max-height: 8rem;
+ overflow-x: hidden;
+ overflow-y: auto;
+ }
+
+ .chat-session {
+ min-width: 0;
+ }
+}
+
+@media (max-width: 1024px) {
+ .app-shell {
+ grid-template-columns: 13rem minmax(0, 1fr);
+ }
+
+ .app-sidebar {
+ padding: 1rem 0.75rem;
+ }
+
+ .page-header,
+ .page-stack,
+ .chat-page {
+ padding-inline: 1.25rem;
+ }
+}
+
+@media (max-width: 680px) {
+ .app-shell {
+ grid-template-columns: 1fr;
+ }
+
+ .app-sidebar {
+ display: flex;
+ gap: 0.75rem;
+ overflow-x: auto;
+ padding: 0.75rem;
+ }
+
+ .brand-lockup,
+ .sidebar-footer {
+ display: none;
+ }
+
+ .primary-nav {
+ display: flex;
+ min-width: max-content;
+ gap: 0.5rem;
+ }
+
+ .nav-item {
+ min-width: 7.5rem;
+ }
+
+ .page-header,
+ .page-stack,
+ .chat-page {
+ padding-inline: 0.9rem;
+ }
+
+ .page-header {
+ align-items: flex-start;
+ flex-direction: column;
+ gap: 0.75rem;
+ }
+
+ .settings-grid,
+ .status-grid {
+ grid-template-columns: 1fr;
+ }
+
+ .window-chrome-actions {
+ gap: 0.25rem;
+ }
+}
+
+@media (prefers-reduced-motion: reduce) {
+ *,
+ *::before,
+ *::after {
+ scroll-behavior: auto !important;
+ transition-duration: 0.01ms !important;
+ animation-duration: 0.01ms !important;
+ animation-iteration-count: 1 !important;
+ }
+
+ .aemeath-pet-sprite {
+ animation: none !important;
+ }
+}
diff --git a/tests/e2e/bootstrap.spec.ts b/tests/e2e/bootstrap.spec.ts
index 856ebfa..fccdc69 100644
--- a/tests/e2e/bootstrap.spec.ts
+++ b/tests/e2e/bootstrap.spec.ts
@@ -1,4 +1,4 @@
-import { expect, test } from "@playwright/test";
+import { expect, test } from "@playwright/test";
test("renders the bootstrap shell and safe browser fallback", async ({
page,
@@ -6,19 +6,17 @@ test("renders the bootstrap shell and safe browser fallback", async ({
await page.goto("/");
await expect(
- page.getByRole("heading", { name: "AstrBot Desktop" }),
+ page.getByText("AstrBot Desktop", { exact: true }).first(),
).toBeVisible();
- await expect(page.getByText("desktop-v1alpha1")).toBeVisible();
await expect(
- page.getByText("IPC unavailable:", { exact: false }),
+ page.getByRole("heading", { name: "统一聊天运行时" }),
).toBeVisible();
+ await expect(
+ page.getByText("IPC 暂不可用:", { exact: false }),
+ ).toBeVisible();
+
+ await page.getByRole("button", { name: "◎ 连接 实例与槽位管理" }).click();
await expect(
page.getByRole("heading", { name: "连接 Profile" }),
).toBeVisible();
- await expect(
- page.getByText("Profile storage unavailable:", { exact: false }),
- ).toBeVisible();
- await expect(
- page.getByRole("button", { name: "重新检查 IPC" }),
- ).toBeEnabled();
});
diff --git a/tests/e2e/ui-polish.spec.ts b/tests/e2e/ui-polish.spec.ts
new file mode 100644
index 0000000..421d657
--- /dev/null
+++ b/tests/e2e/ui-polish.spec.ts
@@ -0,0 +1,43 @@
+import { expect, test } from "@playwright/test";
+
+const viewports = [
+ { width: 1280, height: 720 },
+ { width: 1024, height: 720 },
+ { width: 680, height: 720 },
+];
+
+for (const viewport of viewports) {
+ test(`keeps the desktop shell usable at ${viewport.width}px`, async ({
+ page,
+ }) => {
+ await page.setViewportSize(viewport);
+ await page.goto("/");
+
+ await expect(
+ page.getByText("AstrBot Desktop", { exact: true }).first(),
+ ).toBeVisible();
+ await expect(page.getByRole("button", { name: /⌁ 聊天/ })).toBeVisible();
+
+ const dimensions = (await page.evaluate(
+ "({ clientWidth: document.documentElement.clientWidth, scrollWidth: document.documentElement.scrollWidth })",
+ )) as { clientWidth: number; scrollWidth: number };
+ expect(dimensions.scrollWidth).toBeLessThanOrEqual(
+ dimensions.clientWidth + 1,
+ );
+ });
+}
+
+test("keeps page navigation and diagnostic fields accessible", async ({
+ page,
+}) => {
+ await page.goto("/");
+ await page.getByRole("button", { name: /诊断与设置/ }).click();
+
+ await expect(page.getByText("Rust Core")).toBeVisible();
+ await expect(page.getByLabel("主机")).toBeVisible();
+ await expect(page.getByLabel("端口")).toBeVisible();
+ await expect(page.getByLabel("进程 ID")).toBeVisible();
+
+ await page.keyboard.press("Tab");
+ await expect(page.locator(":focus")).toBeVisible();
+});