feat(webui): refine composer slash, skill, and mention palettes (#6738)
This commit is contained in:
1 parent
cd75dbfaac
commit
16e573fe18
9 files changed
+993
-534
No files matched your search
@@ -4,7 +4,7 @@ import { MessageBubble } from "@/components/MessageBubble";
|
||||
import { ThreadComposer } from "@/components/thread/ThreadComposer";
|
||||
import { ThemeProvider, useTheme } from "@/hooks/useTheme";
|
||||
import { useReadingTypography } from "@/hooks/useReadingTypography";
|
||||
import type { ChatSummary, CliAppInfo, McpPresetInfo, SlashCommand, UIMessage } from "@/lib/types";
|
||||
import type { ChatSummary, CliAppInfo, McpPresetInfo, SkillSummary, SlashCommand, UIMessage } from "@/lib/types";
|
||||
|
||||
const session: ChatSummary = {
|
||||
key: "websocket:typography", channel: "websocket", chatId: "typography",
|
||||
@@ -28,10 +28,46 @@ const linearPreset: McpPresetInfo = {
|
||||
connection_summary: "", logo_url: logo,
|
||||
};
|
||||
const mcpPresets = [linearPreset, { ...linearPreset, name: "adobe-express-docs", display_name: "Adobe Express Developer" }];
|
||||
const commands: SlashCommand[] = [{
|
||||
command: "/goal", title: "Start a goal", description: "Start a sustained goal.",
|
||||
icon: "activity", lifecycle: "agent_turn_with_args", acceptsArgs: true,
|
||||
}];
|
||||
const commands: SlashCommand[] = [
|
||||
{
|
||||
command: "/goal", title: "Start a goal", description: "Start a sustained goal.",
|
||||
icon: "activity", lifecycle: "agent_turn_with_args", acceptsArgs: true,
|
||||
},
|
||||
{
|
||||
command: "/compact", title: "Compact context", description: "Compact context and continue chatting.",
|
||||
icon: "archive", lifecycle: "finalize_active_turn", acceptsArgs: false,
|
||||
},
|
||||
{
|
||||
command: "/model", title: "Model", description: "View or switch the current model preset.",
|
||||
icon: "brain", argHint: "[preset]", lifecycle: "side_channel", acceptsArgs: true,
|
||||
},
|
||||
{
|
||||
command: "/status", title: "Show status", description: "Check runtime, provider, and channel status.",
|
||||
icon: "activity", lifecycle: "side_channel", acceptsArgs: false,
|
||||
},
|
||||
{
|
||||
command: "/pairing", title: "Pairing", description: "Manage pairing requests.",
|
||||
icon: "shield", argHint: "[list|approve <code>|deny <code>|revoke <user_id>]",
|
||||
lifecycle: "side_channel", acceptsArgs: true,
|
||||
},
|
||||
];
|
||||
const skills: SkillSummary[] = [
|
||||
{
|
||||
name: "frontend-design",
|
||||
description: "Build polished interfaces with balanced typography, motion, and responsive layout across light and dark themes.",
|
||||
source: "workspace", enabled: true, available: true,
|
||||
},
|
||||
{
|
||||
name: "nanobot-document",
|
||||
description: "Look up nanobot configuration, architecture, and troubleshooting guides.",
|
||||
source: "builtin", enabled: true, available: true,
|
||||
},
|
||||
{
|
||||
name: "skill-creator",
|
||||
description: "Create or update reusable AgentSkills in the workspace.",
|
||||
source: "builtin", enabled: true, available: true,
|
||||
},
|
||||
];
|
||||
const answer: UIMessage = {
|
||||
id: "reference-answer", role: "assistant", createdAt: 1,
|
||||
content: "[相关会话](#session/websocket%3Atypography) · [外部文档](https://example.com/reference)",
|
||||
@@ -44,7 +80,7 @@ export function InlineReferencesFixture() {
|
||||
return <ThemeProvider theme={theme}>
|
||||
<main className="mx-auto h-full max-w-[var(--content-column-width)] space-y-6 overflow-y-auto p-4">
|
||||
{[answer, ...sent].map(message => <MessageBubble key={message.id} message={message} slashCommands={commands} />)}
|
||||
<ThreadComposer compactWhenIdle sessions={[session, longSession]} cliApps={cliApps} mcpPresets={mcpPresets} modelLabel="Fixture" persistDraft={false} slashCommands={commands}
|
||||
<ThreadComposer compactWhenIdle sessions={[session, longSession]} cliApps={cliApps} mcpPresets={mcpPresets} modelLabel="Fixture" persistDraft={false} slashCommands={commands} skills={skills}
|
||||
onSend={(text, _media, options) => setSent(current => [...current, {
|
||||
id: `sent-${current.length}`, role: "user", content: text, createdAt: current.length + 2,
|
||||
}, ...(options?.userShell ? [{
|
||||
|
||||
@@ -157,6 +157,52 @@ for (const narrow of [false, true]) {
|
||||
await expectMatchingInputLayers(input);
|
||||
});
|
||||
|
||||
test(`slash and skill palettes match composer width with split preview on desktop: ${narrow ? "narrow" : "desktop"}, ${theme}`, async ({ page }, info) => {
|
||||
await page.setViewportSize(narrow ? { width: 320, height: 844 } : { width: 1440, height: 1000 });
|
||||
await page.addInitScript(theme => {
|
||||
localStorage.setItem("nanobot.locale", "en");
|
||||
localStorage.setItem("nanobot-webui.theme", theme);
|
||||
}, theme);
|
||||
await page.goto("/browser/fixture.html?case=inline-references");
|
||||
const input = page.getByRole("textbox", { name: "Message input", exact: true });
|
||||
const surface = page.locator(".thread-composer-surface");
|
||||
const settledBox = async (locator: Locator) => {
|
||||
await locator.evaluate(async (node) => {
|
||||
await Promise.all(node.getAnimations().map((animation) => animation.finished.catch(() => {})));
|
||||
});
|
||||
return (await locator.boundingBox())!;
|
||||
};
|
||||
|
||||
await input.fill("/");
|
||||
const slashPalette = page.getByRole("listbox", { name: "Slash commands" });
|
||||
await expect(slashPalette).toBeVisible();
|
||||
const slashBox = await settledBox(slashPalette);
|
||||
const surfaceBox = (await surface.boundingBox())!;
|
||||
expect(Math.abs(slashBox.x - surfaceBox.x)).toBeLessThanOrEqual(2);
|
||||
expect(Math.abs(slashBox.width - surfaceBox.width)).toBeLessThanOrEqual(2);
|
||||
const slashPreview = slashPalette.locator("[data-palette-preview]");
|
||||
if (narrow) await expect(slashPreview).toBeHidden();
|
||||
else await expect(slashPreview).toBeVisible();
|
||||
expect(await slashPalette.evaluate(node => node.scrollWidth <= node.clientWidth)).toBe(true);
|
||||
expect(await slashPalette.locator(":scope > div").first().evaluate(node => node.scrollWidth <= node.clientWidth)).toBe(true);
|
||||
await page.screenshot({ path: info.outputPath("slash-palette.png") });
|
||||
|
||||
await input.fill("$");
|
||||
const skillPalette = page.getByRole("listbox", { name: "Skills" });
|
||||
await expect(skillPalette).toBeVisible();
|
||||
await expect(skillPalette.getByRole("group", { name: "Custom" })).toBeVisible();
|
||||
await expect(skillPalette.getByRole("group", { name: "Built-in" })).toBeVisible();
|
||||
const skillBox = await settledBox(skillPalette);
|
||||
expect(Math.abs(skillBox.x - surfaceBox.x)).toBeLessThanOrEqual(2);
|
||||
expect(Math.abs(skillBox.width - surfaceBox.width)).toBeLessThanOrEqual(2);
|
||||
const skillPreview = skillPalette.locator("[data-palette-preview]");
|
||||
if (narrow) await expect(skillPreview).toBeHidden();
|
||||
else await expect(skillPreview).toBeVisible();
|
||||
expect(await skillPalette.evaluate(node => node.scrollWidth <= node.clientWidth)).toBe(true);
|
||||
expect(await skillPalette.locator(":scope > div").first().evaluate(node => node.scrollWidth <= node.clientWidth)).toBe(true);
|
||||
await page.screenshot({ path: info.outputPath("skill-palette.png") });
|
||||
});
|
||||
|
||||
test(`inline references preserve native editing: ${narrow ? "narrow" : "desktop"}, ${theme}`, async ({ page }, info) => {
|
||||
await page.setViewportSize(narrow ? { width: 390, height: 844 } : { width: 1440, height: 1000 });
|
||||
await page.context().grantPermissions(["clipboard-read", "clipboard-write"]);
|
||||
|
||||
Reference in new issue
Block a user