feat(chat): give the conversation the height the header was using
The chat panel opened with three stacked blocks above the messages: a title and subtitle naming the panel, a strip repeating the profile id, session id and connection state, and the session pills. Only the last carried anything the reader needed. Move the slot tabs into the window title bar and delete the rest. The tabs go there through a portal rather than by lifting state into the shell, which keeps the slot selection and its status polling in the panel that owns them; the quick chat and bubble windows have no title bar, and they are slot-fixed already, so the tabs simply do not render there. The connection actions move onto the session row, which costs no height because that row already exists. 刷新 is dropped: the status refreshes on a 500ms poll, so the button did nothing the panel was not already doing. 重连, 断开 and 新对话 stay, since losing them would leave no way to recover a dropped connection or start a conversation. The panel now puts 82px above the messages instead of three blocks. The title-bar rules carry [role="tab"] on purpose — the panel's own .chat-slot[role=tab] rule sets a 2.75rem minimum and sits later in the sheet, so an unqualified selector loses to it and the tabs overflow a 44px bar. Verified against the real stylesheet: tabs 33px inside a 44px bar, vertically centred, clear of both the title text and the window controls; the removed blocks are absent from the DOM. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
这个提交存在于:
父节点
809f530486
当前提交
1eba70d292
共有 5 个文件被更改,包括 209 次插入 和 111 次删除
12
src/App.tsx
12
src/App.tsx
|
|
@ -40,6 +40,9 @@ const DiagnosticsPage = lazy(() =>
|
|||
);
|
||||
import { bootstrapStatusSchema, type BootstrapStatus } from "./types/bootstrap";
|
||||
|
||||
/// Shared with `ChatPanel`, which portals its slot tabs into this element.
|
||||
export const WINDOW_CHROME_MOUNT_ID = "window-chrome-mount";
|
||||
|
||||
type PageKey = "chat" | "connections" | "desktop" | "pet" | "diagnostics";
|
||||
type ChatSlot = "companion" | "operations";
|
||||
type PetDisplayMode = "app-ui" | "desktop-floating";
|
||||
|
|
@ -302,6 +305,15 @@ function WindowChrome({
|
|||
}}
|
||||
>
|
||||
<span className="window-chrome-title">AstrBot Desktop</span>
|
||||
{/* Mount point for controls that belong to the active page but should sit
|
||||
in the title bar. ChatPanel portals its slot tabs here, which keeps the
|
||||
slot state and its status polling where they already live instead of
|
||||
lifting both into the shell. */}
|
||||
<div
|
||||
className="window-chrome-mount"
|
||||
id={WINDOW_CHROME_MOUNT_ID}
|
||||
data-tauri-drag-region="false"
|
||||
/>
|
||||
<div className="window-chrome-actions" data-tauri-drag-region="false">
|
||||
<button
|
||||
aria-label={
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ import { fireEvent, render, screen, waitFor } from "@testing-library/react";
|
|||
import { StrictMode } from "react";
|
||||
import { beforeEach, expect, it, vi } from "vitest";
|
||||
|
||||
import { WINDOW_CHROME_MOUNT_ID } from "../../App";
|
||||
import {
|
||||
activeListeners,
|
||||
emitTauriEvent,
|
||||
|
|
@ -73,8 +74,15 @@ function mockChatCommands(options?: {
|
|||
);
|
||||
}
|
||||
|
||||
/** Renders with the slot tabs enabled, then waits for the first status poll. */
|
||||
/** Renders with the slot tabs enabled, then waits for the first status poll.
|
||||
*
|
||||
* The tabs are portaled into the shell's title bar, so the mount point has to
|
||||
* exist before the panel renders — outside a test the shell owns it.
|
||||
*/
|
||||
async function renderWithTabs() {
|
||||
const mount = document.createElement("div");
|
||||
mount.id = WINDOW_CHROME_MOUNT_ID;
|
||||
document.body.appendChild(mount);
|
||||
const view = render(<ChatPanel />);
|
||||
await flushListen();
|
||||
await screen.findByRole("tab", { name: /陪伴/ });
|
||||
|
|
|
|||
|
|
@ -1,7 +1,9 @@
|
|||
import { invoke } from "@tauri-apps/api/core";
|
||||
import { listen } from "@tauri-apps/api/event";
|
||||
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
||||
import { createPortal } from "react-dom";
|
||||
|
||||
import { WINDOW_CHROME_MOUNT_ID } from "../../App";
|
||||
import { errorMessage } from "../../lib/errorMessage";
|
||||
import { MessageContent } from "./MessageContent";
|
||||
|
||||
|
|
@ -102,6 +104,16 @@ export function ChatPanel({ fixedSlot }: ChatPanelProps) {
|
|||
companion: false,
|
||||
operations: false,
|
||||
});
|
||||
// Resolved in an effect because the title bar mounts with the shell, which
|
||||
// is not guaranteed to have rendered when this panel first runs. The quick
|
||||
// chat and bubble windows have no title bar at all, so it stays null there
|
||||
// and the tabs simply do not render — those views are already slot-fixed.
|
||||
const [slotTabsMount, setSlotTabsMount] = useState<HTMLElement | null>(null);
|
||||
useEffect(() => {
|
||||
if (fixedSlot) return;
|
||||
setSlotTabsMount(document.getElementById(WINDOW_CHROME_MOUNT_ID));
|
||||
}, [fixedSlot]);
|
||||
|
||||
const messageListRef = useRef<HTMLDivElement | null>(null);
|
||||
/// Whether the view should follow new content.
|
||||
///
|
||||
|
|
@ -592,10 +604,6 @@ export function ChatPanel({ fixedSlot }: ChatPanelProps) {
|
|||
}
|
||||
};
|
||||
|
||||
const refreshConnection = async () => {
|
||||
await refresh();
|
||||
};
|
||||
|
||||
const reconnectConnection = async () => {
|
||||
const slot = selectedSlot;
|
||||
const profileId = status[slot].profileId;
|
||||
|
|
@ -677,82 +685,52 @@ export function ChatPanel({ fixedSlot }: ChatPanelProps) {
|
|||
|
||||
return (
|
||||
<section className="chat-panel" aria-label="聊天面板">
|
||||
<div className="chat-heading">
|
||||
<div>
|
||||
<p className="eyebrow">共享聊天运行时</p>
|
||||
<h2>统一聊天运行时</h2>
|
||||
<p className="chat-note">
|
||||
主界面、快速聊天和气泡共享同一套消息状态。
|
||||
</p>
|
||||
</div>
|
||||
<div className="chat-slot-tabs" role="tablist" aria-label="聊天槽位">
|
||||
{(["companion", "operations"] as const).map((slot) => (
|
||||
<button
|
||||
className={activeSlot === slot ? "chat-slot active" : "chat-slot"}
|
||||
key={slot}
|
||||
disabled={Boolean(fixedSlot)}
|
||||
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"
|
||||
{slotTabsMount
|
||||
? createPortal(
|
||||
<div
|
||||
className="chat-slot-tabs"
|
||||
role="tablist"
|
||||
aria-label="聊天槽位"
|
||||
>
|
||||
{slot === "companion" ? "陪伴" : "运维"}
|
||||
{unreadCounts[slot] > 0 ? (
|
||||
<strong>{unreadCounts[slot]}</strong>
|
||||
) : null}
|
||||
<span>{connectionStateLabel(status[slot].state)}</span>
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
<div className="chat-runtime-strip">
|
||||
<div>
|
||||
<span>配置</span>
|
||||
<strong>{status[selectedSlot].profileId ?? "未连接"}</strong>
|
||||
</div>
|
||||
<div>
|
||||
<span>会话</span>
|
||||
<strong>{status[selectedSlot].activeSessionId ?? "新会话"}</strong>
|
||||
</div>
|
||||
<div>
|
||||
<span>状态</span>
|
||||
<strong>{connectionStateLabel(status[selectedSlot].state)}</strong>
|
||||
</div>
|
||||
<div className="chat-runtime-actions">
|
||||
<button type="button" onClick={() => void refreshConnection()}>
|
||||
刷新
|
||||
</button>
|
||||
<button type="button" onClick={() => void reconnectConnection()}>
|
||||
重连
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => void disconnectConnection()}
|
||||
disabled={status[selectedSlot].state === "disconnected"}
|
||||
>
|
||||
断开
|
||||
</button>
|
||||
<button type="button" onClick={() => void startNewSession()}>
|
||||
新对话
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
{(["companion", "operations"] as const).map((slot) => (
|
||||
<button
|
||||
className={
|
||||
activeSlot === slot ? "chat-slot active" : "chat-slot"
|
||||
}
|
||||
key={slot}
|
||||
disabled={Boolean(fixedSlot)}
|
||||
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" ? "陪伴" : "运维"}
|
||||
{unreadCounts[slot] > 0 ? (
|
||||
<strong>{unreadCounts[slot]}</strong>
|
||||
) : null}
|
||||
<span>{connectionStateLabel(status[slot].state)}</span>
|
||||
</button>
|
||||
))}
|
||||
</div>,
|
||||
slotTabsMount,
|
||||
)
|
||||
: null}
|
||||
{status[selectedSlot].lastError ? (
|
||||
<p className="chat-runtime-error" role="status">
|
||||
{status[selectedSlot].lastError}
|
||||
|
|
@ -769,34 +747,67 @@ export function ChatPanel({ fixedSlot }: ChatPanelProps) {
|
|||
</button>
|
||||
</div>
|
||||
) : null}
|
||||
{displaySessions.length > 0 ? (
|
||||
<div className="chat-session-list" aria-label="Chat sessions">
|
||||
{displaySessions.map((session, index) => (
|
||||
<button
|
||||
className={
|
||||
session.sessionId === status[selectedSlot].activeSessionId
|
||||
? "chat-session active"
|
||||
: "chat-session"
|
||||
}
|
||||
key={session.sessionId}
|
||||
title={`会话标识:${session.sessionId}`}
|
||||
type="button"
|
||||
onClick={() => {
|
||||
void invoke("switch_connection_slot_session", {
|
||||
request: { slot: selectedSlot, sessionId: session.sessionId },
|
||||
})
|
||||
.then(() => void refresh())
|
||||
.catch((reason) =>
|
||||
reportSlotError(selectedSlot, errorMessage(reason)),
|
||||
);
|
||||
}}
|
||||
>
|
||||
<strong>{session.displayName || `会话 ${index + 1}`}</strong>
|
||||
<small>{formatSessionTime(session.updatedAt)}</small>
|
||||
</button>
|
||||
))}
|
||||
{/* Connection actions ride along the session row rather than a strip of
|
||||
their own, so removing that strip cost the chat no controls and gave
|
||||
it the height back. `刷新` is gone: the status already refreshes on a
|
||||
500ms poll, so the button did nothing the panel was not doing. */}
|
||||
<div className="chat-session-bar">
|
||||
<div className="chat-runtime-actions">
|
||||
<button
|
||||
type="button"
|
||||
title="重新连接当前槽位"
|
||||
onClick={() => void reconnectConnection()}
|
||||
>
|
||||
重连
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
title="断开当前槽位"
|
||||
onClick={() => void disconnectConnection()}
|
||||
disabled={status[selectedSlot].state === "disconnected"}
|
||||
>
|
||||
断开
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
title="开始一个新会话"
|
||||
onClick={() => void startNewSession()}
|
||||
>
|
||||
新对话
|
||||
</button>
|
||||
</div>
|
||||
) : null}
|
||||
{displaySessions.length > 0 ? (
|
||||
<div className="chat-session-list" aria-label="Chat sessions">
|
||||
{displaySessions.map((session, index) => (
|
||||
<button
|
||||
className={
|
||||
session.sessionId === status[selectedSlot].activeSessionId
|
||||
? "chat-session active"
|
||||
: "chat-session"
|
||||
}
|
||||
key={session.sessionId}
|
||||
title={`会话标识:${session.sessionId}`}
|
||||
type="button"
|
||||
onClick={() => {
|
||||
void invoke("switch_connection_slot_session", {
|
||||
request: {
|
||||
slot: selectedSlot,
|
||||
sessionId: session.sessionId,
|
||||
},
|
||||
})
|
||||
.then(() => void refresh())
|
||||
.catch((reason) =>
|
||||
reportSlotError(selectedSlot, errorMessage(reason)),
|
||||
);
|
||||
}}
|
||||
>
|
||||
<strong>{session.displayName || `会话 ${index + 1}`}</strong>
|
||||
<small>{formatSessionTime(session.updatedAt)}</small>
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
<div
|
||||
id={`chat-panel-${selectedSlot}`}
|
||||
className="chat-message-list"
|
||||
|
|
|
|||
|
|
@ -265,6 +265,26 @@ select:focus {
|
|||
font-size: 0.9rem;
|
||||
}
|
||||
|
||||
/* The connection actions and the session pills share one row, which is what
|
||||
let the runtime strip above the chat go away entirely. */
|
||||
.chat-session-bar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.6rem;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.chat-session-bar > .chat-runtime-actions {
|
||||
flex: 0 0 auto;
|
||||
display: flex;
|
||||
gap: 0.3rem;
|
||||
}
|
||||
|
||||
.chat-session-bar > .chat-session-list {
|
||||
flex: 1 1 auto;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
/* Everything the AstrBot connection does not need in order to work. Collapsed
|
||||
by default so the common path is four fields. */
|
||||
.profile-advanced {
|
||||
|
|
@ -1667,8 +1687,53 @@ body {
|
|||
-webkit-app-region: drag;
|
||||
}
|
||||
|
||||
/* Holds controls the active page portals into the title bar. Not a drag
|
||||
region, so clicking a tab does not start moving the window. */
|
||||
.window-chrome-mount {
|
||||
display: flex;
|
||||
flex: 0 0 auto;
|
||||
align-items: center;
|
||||
gap: 0.4rem;
|
||||
min-width: 0;
|
||||
margin-inline: auto 0.75rem;
|
||||
-webkit-app-region: no-drag;
|
||||
}
|
||||
|
||||
/* Compact enough to sit in a 44px bar: the label and its connection state on
|
||||
one line instead of stacked.
|
||||
`[role="tab"]` is carried on purpose — the panel's own `.chat-slot[role=tab]`
|
||||
rule sets a 2.75rem minimum and appears later in the sheet, so an unqualified
|
||||
selector here loses to it and the tabs overflow the bar. */
|
||||
.window-chrome-mount .chat-slot-tabs {
|
||||
flex-wrap: nowrap;
|
||||
align-items: center;
|
||||
gap: 0.3rem;
|
||||
width: auto;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.window-chrome-mount .chat-slot[role="tab"] {
|
||||
display: flex;
|
||||
flex: 0 0 auto;
|
||||
align-items: baseline;
|
||||
gap: 0.35rem;
|
||||
min-width: 0;
|
||||
/* Both zeroed: the panel's rules set a 3.25rem and a 2.75rem minimum, and a
|
||||
stretch alignment would otherwise size the button to the row anyway. */
|
||||
min-height: 0;
|
||||
height: 2rem;
|
||||
padding: 0.2rem 0.6rem;
|
||||
font-size: 0.85rem;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.window-chrome-mount .chat-slot[role="tab"] > span {
|
||||
font-size: 0.72rem;
|
||||
opacity: 0.75;
|
||||
}
|
||||
|
||||
.window-chrome-title {
|
||||
flex: 1 1 auto;
|
||||
flex: 0 0 auto;
|
||||
min-width: 0;
|
||||
overflow: hidden;
|
||||
color: #9fb9e3;
|
||||
|
|
|
|||
|
|
@ -8,9 +8,11 @@ test("renders the bootstrap shell and safe browser fallback", async ({
|
|||
await expect(
|
||||
page.getByText("AstrBot Desktop", { exact: true }).first(),
|
||||
).toBeVisible();
|
||||
await expect(
|
||||
page.getByRole("heading", { name: "统一聊天运行时" }),
|
||||
).toBeVisible();
|
||||
// The chat panel's own heading is gone; the slot tabs it portals into the
|
||||
// title bar are what proves the panel rendered and that the portal found its
|
||||
// mount point.
|
||||
await expect(page.getByRole("tab", { name: /陪伴/ })).toBeVisible();
|
||||
await expect(page.getByRole("tab", { name: /运维/ })).toBeVisible();
|
||||
await expect(
|
||||
page.getByText("IPC 暂不可用:", { exact: false }),
|
||||
).toBeVisible();
|
||||
|
|
|
|||
正在加载…
添加表格
在新工单中引用