Skip to content

Commit 699315e

Browse files
authored
feat(ui): redesign Ask OpenClaw — mascot, shared surface, dockable panel (#115123)
* refactor(ui): share custodian chat surface * feat(ui): add dockable custodian panel * refactor(ui): drop write-only panel-close latch from custodian store * feat(ui): demo custodian in mock gateway * chore(ui): update raw-copy baseline for custodian strings * fix(ui): clean custodian surface/page/mock lint debris
1 parent 0f188c8 commit 699315e

23 files changed

Lines changed: 1810 additions & 663 deletions

‎scripts/control-ui-mock-dev.ts‎

Lines changed: 171 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,14 @@ import path from "node:path";
44
import { fileURLToPath } from "node:url";
55
import qrcode from "qrcode";
66
import { createServer, type Plugin, type ViteDevServer } from "vite";
7-
import type { UserProfile } from "../packages/gateway-protocol/src/index.js";
7+
import type {
8+
RequestFrame,
9+
SystemAgentChatHistoryResult,
10+
SystemAgentChatQuestion,
11+
SystemAgentChatResult,
12+
SystemChangesListResult,
13+
UserProfile,
14+
} from "../packages/gateway-protocol/src/index.js";
815
import { expectDefined } from "../packages/normalization-core/src/expect.js";
916
import { applySharedChannelFieldHelp } from "../src/config/schema.channel-field-help.js";
1017
import { applyConfigTierHints, applyResolvedConfigTierHints } from "../src/config/schema.tiers.js";
@@ -65,6 +72,7 @@ const NARRATION_DEMO_SESSION_KEY = "agent:main:sidebar-narration-demo";
6572
const NARRATION_DEMO_RUN_ID = "mock-sidebar-narration-run";
6673
const OBSERVER_DEMO_SESSION_KEY = "agent:main:session-observer-demo";
6774
const OBSERVER_DEMO_RUN_ID = "mock-session-observer-run";
75+
const CUSTODIAN_CHAT_REPLY_DELAY_MS = 600;
6876

6977
const repoRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
7078
const uiRoot = path.join(repoRoot, "ui");
@@ -1343,6 +1351,53 @@ async function createChatPickerScenario(
13431351
const cronMocks = buildCronMocks(Date.now());
13441352
const channelWizard = buildChannelWizardMocks();
13451353
const configMocks = buildConfigMocks({ swarmEnabled: fixture === "swarm" });
1354+
const custodianHistory = {
1355+
turns: [
1356+
{
1357+
role: "user",
1358+
text: "Can you check whether this system is ready?",
1359+
at: baseTime - 18 * 60_000,
1360+
},
1361+
{
1362+
role: "assistant",
1363+
text: "Everything important is connected. I’ll keep watching for changes.",
1364+
at: baseTime - 17 * 60_000,
1365+
},
1366+
{
1367+
role: "user",
1368+
text: "Please remember that I prefer concise updates.",
1369+
at: baseTime - 16 * 60_000,
1370+
},
1371+
],
1372+
} satisfies SystemAgentChatHistoryResult;
1373+
const custodianChanges = {
1374+
entries: [
1375+
{
1376+
id: "mock-system-agent-model",
1377+
at: baseTime - 6 * 60_000,
1378+
kind: "operation",
1379+
source: "system-agent",
1380+
summary: "Updated the default model for the main agent",
1381+
changedPaths: ["agents.defaults.model"],
1382+
},
1383+
{
1384+
id: "mock-plugin-install",
1385+
at: baseTime - 42 * 60_000,
1386+
kind: "config-write",
1387+
source: "plugin-install",
1388+
summary: "Enabled the Telegram plugin",
1389+
changedPaths: ["plugins.entries.telegram.enabled"],
1390+
},
1391+
{
1392+
id: "mock-doctor-repair",
1393+
at: baseTime - 2 * 60 * 60_000,
1394+
kind: "config-write",
1395+
source: "doctor",
1396+
summary: "Repaired a stale channel account reference",
1397+
changedPaths: ["channels.whatsapp.defaultAccount"],
1398+
},
1399+
],
1400+
} satisfies SystemChangesListResult;
13461401
return {
13471402
assistantAgentId: "main",
13481403
assistantName: "Molty",
@@ -1351,6 +1406,9 @@ async function createChatPickerScenario(
13511406
"chat.metadata",
13521407
"chat.startup",
13531408
"question.list",
1409+
"openclaw.changes.list",
1410+
"openclaw.chat",
1411+
"openclaw.chat.history",
13541412
"sessions.diff",
13551413
"sessions.files.set",
13561414
"system.info",
@@ -1473,6 +1531,8 @@ async function createChatPickerScenario(
14731531
// (raw persists, hash advances) because config.get ships a raw fixture.
14741532
"config.get": configMocks.get,
14751533
"config.schema": configMocks.schema,
1534+
"openclaw.chat.history": custodianHistory,
1535+
"openclaw.changes.list": custodianChanges,
14761536
// The sidebar recovers pending questions through question.list after the
14771537
// hello handshake, so this remains visible after a mock-page refresh.
14781538
"question.list": {
@@ -1997,8 +2057,117 @@ function escapeScriptContent(script: string): string {
19972057
return script.replaceAll("</script", "<\\/script");
19982058
}
19992059

2060+
/** Adds the one stateful mock surface the generic scenario fixture cannot express. */
2061+
function installControlUiCustodianMock(replyDelayMs: number): void {
2062+
type MockGatewayControls = {
2063+
deferNext: (method: string) => void;
2064+
resolveDeferred: (method: string, payload: unknown) => void;
2065+
};
2066+
type MockWindow = Window & {
2067+
openclawControlUiE2eGateway?: MockGatewayControls;
2068+
};
2069+
2070+
const gateway = (window as MockWindow).openclawControlUiE2eGateway;
2071+
const MockWebSocket = window.WebSocket;
2072+
if (!gateway || !MockWebSocket) {
2073+
return;
2074+
}
2075+
const sendDescriptor = Object.getOwnPropertyDescriptor(MockWebSocket.prototype, "send");
2076+
const originalSend = sendDescriptor?.value as WebSocket["send"] | undefined;
2077+
if (typeof originalSend !== "function") {
2078+
return;
2079+
}
2080+
const sendOriginal = (socket: WebSocket, data: Parameters<WebSocket["send"]>[0]): void => {
2081+
Reflect.apply(originalSend, socket, [data]);
2082+
};
2083+
const sessionTurns = new Map<string, number>();
2084+
MockWebSocket.prototype.send = function (data): void {
2085+
let frame: RequestFrame | null = null;
2086+
if (typeof data === "string") {
2087+
try {
2088+
frame = JSON.parse(data) as RequestFrame;
2089+
} catch {
2090+
frame = null;
2091+
}
2092+
}
2093+
if (frame?.type !== "req" || frame.method !== "openclaw.chat") {
2094+
sendOriginal(this, data);
2095+
return;
2096+
}
2097+
2098+
const params =
2099+
frame.params && typeof frame.params === "object"
2100+
? (frame.params as { message?: unknown; sessionId?: unknown })
2101+
: {};
2102+
const sessionId =
2103+
typeof params.sessionId === "string" && params.sessionId.trim()
2104+
? params.sessionId
2105+
: "control-ui-custodian-mock";
2106+
const message = typeof params.message === "string" ? params.message : undefined;
2107+
const turn = sessionTurns.get(sessionId) ?? 0;
2108+
sessionTurns.set(sessionId, turn + 1);
2109+
const channelQuestion = {
2110+
id: "mock-channel-choice",
2111+
header: "Channel setup",
2112+
question: "Which channel would you like to work on?",
2113+
options: [
2114+
{
2115+
label: "WhatsApp",
2116+
reply: "help me connect WhatsApp",
2117+
description: "Review linking and account status.",
2118+
recommended: true,
2119+
},
2120+
{
2121+
label: "Telegram",
2122+
reply: "help me connect Telegram",
2123+
description: "Review the bot token and delivery status.",
2124+
},
2125+
{
2126+
label: "Discord",
2127+
reply: "help me connect Discord",
2128+
description: "Review the bot and server connection.",
2129+
},
2130+
],
2131+
isOther: true,
2132+
} satisfies SystemAgentChatQuestion;
2133+
const response: SystemAgentChatResult = message
2134+
? message.toLowerCase().includes("channel")
2135+
? {
2136+
sessionId,
2137+
reply: "I can help with that.\n\nChoose a channel to continue.",
2138+
action: "none",
2139+
question: channelQuestion,
2140+
}
2141+
: {
2142+
sessionId,
2143+
reply: `I checked the mock system. Everything looks healthy.\n\nThat was demo turn ${turn}.`,
2144+
action: "none",
2145+
}
2146+
: {
2147+
sessionId,
2148+
reply:
2149+
"Hi — I’m OpenClaw, your system caretaker.\n\nAsk me about setup, channels, or recent changes.",
2150+
action: "none",
2151+
};
2152+
2153+
// Defer before forwarding so the generic gateway records the request but
2154+
// cannot race its normal immediate response against this stateful reply.
2155+
gateway.deferNext("openclaw.chat");
2156+
sendOriginal(this, data);
2157+
window.setTimeout(
2158+
() => gateway.resolveDeferred("openclaw.chat", response),
2159+
message === undefined ? 0 : replyDelayMs,
2160+
);
2161+
};
2162+
}
2163+
2164+
function createCustodianMockInitScript(): string {
2165+
return `(() => { const __name = (target) => target; (${installControlUiCustodianMock.toString()})(${CUSTODIAN_CHAT_REPLY_DELAY_MS}); })();`;
2166+
}
2167+
20002168
function createMockGatewayPlugin(scenario: ControlUiMockGatewayScenario): Plugin {
20012169
const initScript = escapeScriptContent(createControlUiMockGatewayInitScript(scenario));
2170+
const custodianInitScript = escapeScriptContent(createCustodianMockInitScript());
20022171
const bootstrapBody = JSON.stringify(createControlUiMockBootstrapConfig(scenario));
20032172
return {
20042173
configureServer(server) {
@@ -2012,7 +2181,7 @@ function createMockGatewayPlugin(scenario: ControlUiMockGatewayScenario): Plugin
20122181
transformIndexHtml(html) {
20132182
return html.replace(
20142183
"</head>",
2015-
` <script data-openclaw-control-ui-mock-gateway>\n${initScript}\n </script>\n </head>`,
2184+
` <script data-openclaw-control-ui-mock-gateway>\n${initScript}\n${custodianInitScript}\n </script>\n </head>`,
20162185
);
20172186
},
20182187
};

‎ui/src/app/app-host.dock-suppression.test.ts‎

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ afterEach(() => {
2121
});
2222

2323
describe("OpenClaw shell dock suppression", () => {
24-
it("suppresses docked panels only while a settings route owns the viewport", () => {
24+
it("keeps Ask OpenClaw on settings pages and suppresses it only on its full page", () => {
2525
vi.stubGlobal("localStorage", createStorageMock());
2626
vi.stubGlobal(
2727
"matchMedia",
@@ -38,7 +38,7 @@ describe("OpenClaw shell dock suppression", () => {
3838
assistantAgentId: "main",
3939
hello: {
4040
auth: { role: "operator", scopes: ["operator.admin"] },
41-
features: { methods: ["terminal.open", "browser.request"] },
41+
features: { methods: ["terminal.open", "browser.request", "openclaw.chat"] },
4242
},
4343
lastError: null,
4444
offlineStable: false,
@@ -101,6 +101,23 @@ describe("OpenClaw shell dock suppression", () => {
101101
}
102102
).suppressed,
103103
).toBe(true);
104+
expect(
105+
(
106+
container.querySelector("openclaw-custodian-panel") as HTMLElement & {
107+
suppressed: boolean;
108+
}
109+
).suppressed,
110+
).toBe(false);
111+
112+
shell.routeState = { routeId: "custodian" };
113+
renderLit(shell.render(), container);
114+
expect(
115+
(
116+
container.querySelector("openclaw-custodian-panel") as HTMLElement & {
117+
suppressed: boolean;
118+
}
119+
).suppressed,
120+
).toBe(true);
104121

105122
shell.routeState = { routeId: "chat" };
106123
renderLit(shell.render(), container);

‎ui/src/app/app-host.test.ts‎

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
} from "../components/command-palette-contract.ts";
1212
import {
1313
BROWSER_PANEL_TOGGLE_EVENT,
14+
CUSTODIAN_PANEL_TOGGLE_EVENT,
1415
TERMINAL_PANEL_TOGGLE_EVENT,
1516
UI_COMMAND_EVENT,
1617
} from "../components/panel-toggle-contract.ts";
@@ -86,7 +87,9 @@ type TestOptionalCustomElement = {
8687
type ShellLazySurfaceState = ShellKeyboardState & {
8788
browserPanelElement: TestOptionalCustomElement;
8889
commandPaletteElement: TestOptionalCustomElement;
90+
custodianPanelElement: TestOptionalCustomElement;
8991
handleDeferredBrowserToggle: (event: Event) => void;
92+
handleDeferredCustodianToggle: (event: Event) => void;
9093
handleDeferredTerminalToggle: (event: Event) => void;
9194
terminalPanelElement: TestOptionalCustomElement;
9295
};
@@ -217,6 +220,11 @@ type ShellRouteCommitState = {
217220
updateRouteState: (state: ReturnType<typeof selectShellRouteState>) => void;
218221
};
219222

223+
type ShellCustodianRouteState = {
224+
custodianMinimizeRequestId: number;
225+
updateRouteState: (state: { routeId?: RouteId }) => void;
226+
};
227+
220228
type ShellSessionNavigationState = {
221229
runtime: { context: ApplicationContext };
222230
activeSessionKey: string;
@@ -517,6 +525,19 @@ describe("OpenClaw shell route session commits", () => {
517525
expect(setSessionKey).toHaveBeenCalledExactlyOnceWith("agent:main:session-b");
518526
expect(calls).toEqual(["agent:main", "session:agent:main:session-b"]);
519527
});
528+
529+
it("retains the custodian leave transition through an unresolved route state", () => {
530+
const shell = document.createElement(
531+
"openclaw-app-shell",
532+
) as unknown as ShellCustodianRouteState;
533+
534+
shell.updateRouteState({ routeId: "custodian" });
535+
shell.updateRouteState({});
536+
expect(shell.custodianMinimizeRequestId).toBe(0);
537+
538+
shell.updateRouteState({ routeId: "config" });
539+
expect(shell.custodianMinimizeRequestId).toBe(1);
540+
});
520541
});
521542

522543
describe("OpenClaw shell server preferences", () => {
@@ -780,19 +801,22 @@ describe("OpenClaw shell keyboard shortcuts", () => {
780801
it("delivers first panel toggles after their lazy modules load", async () => {
781802
const terminalElement = createLazyElementSpec("terminal panel");
782803
const browserElement = createLazyElementSpec("browser panel");
804+
const custodianElement = createLazyElementSpec("custodian panel");
783805
const terminalToggle = vi.fn();
784806
const browserToggle = vi.fn();
807+
const custodianToggle = vi.fn();
785808
const shell = document.createElement("openclaw-app-shell") as unknown as ShellLazySurfaceState;
786809
shell.terminalPanelElement = terminalElement;
787810
shell.browserPanelElement = browserElement;
811+
shell.custodianPanelElement = custodianElement;
788812
shell.runtime = {
789813
context: {
790814
gateway: {
791815
snapshot: {
792816
phase: "connected",
793817
hello: {
794818
auth: { role: "operator", scopes: ["operator.admin"] },
795-
features: { methods: ["terminal.open", "browser.request"] },
819+
features: { methods: ["terminal.open", "browser.request", "openclaw.chat"] },
796820
},
797821
},
798822
},
@@ -812,20 +836,26 @@ describe("OpenClaw shell keyboard shortcuts", () => {
812836
if (selector === browserElement.tagName) {
813837
return { handleToggleRequest: browserToggle };
814838
}
839+
if (selector === custodianElement.tagName) {
840+
return { handleToggleRequest: custodianToggle };
841+
}
815842
return null;
816843
},
817844
});
818845
const terminalEvent = new CustomEvent(TERMINAL_PANEL_TOGGLE_EVENT, {
819846
detail: { dock: "right", open: true },
820847
});
821848
const browserEvent = new CustomEvent(BROWSER_PANEL_TOGGLE_EVENT);
849+
const custodianEvent = new CustomEvent(CUSTODIAN_PANEL_TOGGLE_EVENT);
822850

823851
shell.handleDeferredTerminalToggle(terminalEvent);
824852
shell.handleDeferredBrowserToggle(browserEvent);
853+
shell.handleDeferredCustodianToggle(custodianEvent);
825854

826855
await vi.waitFor(() => {
827856
expect(terminalToggle).toHaveBeenCalledWith(terminalEvent);
828857
expect(browserToggle).toHaveBeenCalledWith(browserEvent);
858+
expect(custodianToggle).toHaveBeenCalledWith(custodianEvent);
829859
});
830860
});
831861

0 commit comments

Comments
 (0)