Skip to content

Commit 0199682

Browse files
fix(ui): move limited access into Inbox
Make the existing Inbox the canonical limited-access surface across desktop, mobile, and onboarding while preserving the scope-upgrade request lifecycle. Co-authored-by: Tak Hoffman <[email protected]>
1 parent 3b0cad5 commit 0199682

31 files changed

Lines changed: 601 additions & 1278 deletions

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,9 @@ describe("OpenClaw shell update affordance", () => {
557557

558558
for (const navigationSurfaceHidden of [false, true]) {
559559
render(renderFloatingUpdateCard({ ...shared, navigationSurfaceHidden }), container);
560+
expect(
561+
container.querySelector("openclaw-sidebar-attention.sidebar-attention--floating") !== null,
562+
).toBe(navigationSurfaceHidden);
560563
const cards = container.querySelectorAll<HTMLElement & { refreshRequired: boolean }>(
561564
"openclaw-sidebar-update-card",
562565
);

‎ui/src/app/app-shell-view.ts‎

Lines changed: 21 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,11 @@ import {
4141
import { isMobileNavLayout, shouldMergeChatChrome } from "./mobile-nav-layout.ts";
4242
import type { NativeHistoryState } from "./native-web-chrome.ts";
4343
import { isNativeWebChromeHost } from "./native-web-chrome.ts";
44-
import { navigationSurfaceIsHidden, renderFloatingUpdateCard } from "./navigation-surface.ts";
44+
import {
45+
floatingSidebarAttentionVisible,
46+
navigationSurfaceIsHidden,
47+
renderFloatingUpdateCard,
48+
} from "./navigation-surface.ts";
4549
import { readGatewayOperatorAccess } from "./operator-access.ts";
4650
import {
4751
NAV_WIDTH_MAX,
@@ -53,13 +57,10 @@ import {
5357
import { createUpdateProgressWatcher } from "./update-overlay-helpers.ts";
5458

5559
const EMPTY_SESSION_HAS_DRAFT = () => false;
56-
const SCOPE_UPGRADE_SURFACE_ELEMENT = {
57-
tagName: "openclaw-device-scope-upgrade-banner",
58-
label: t("connection.scopeUpgrade.status"),
59-
loadModule: () =>
60-
import("./device-scope-upgrade.runtime.ts").catch(
61-
() => import("./device-scope-upgrade-retry.runtime.ts"),
62-
),
60+
const SIDEBAR_ATTENTION_ELEMENT = {
61+
tagName: "openclaw-sidebar-attention",
62+
label: t("attention.issues"),
63+
loadModule: () => import("../components/sidebar-attention.ts"),
6364
} satisfies OptionalCustomElement;
6465

6566
export interface ShellViewHost {
@@ -275,25 +276,6 @@ export function renderApplicationShell(host: ShellViewHost) {
275276
routeId: activeRoute,
276277
onboarding,
277278
});
278-
const showScopeUpgradeStatus =
279-
gatewayConnected &&
280-
gatewaySnapshot.hello?.auth?.scopes !== undefined &&
281-
!operatorAccess.canAdmin;
282-
if (showScopeUpgradeStatus) {
283-
host.lazyCustomElements.preload(SCOPE_UPGRADE_SURFACE_ELEMENT, { reportError: true });
284-
}
285-
const scopeUpgradeSurface = showScopeUpgradeStatus
286-
? html`<openclaw-device-scope-upgrade-banner
287-
.props=${{
288-
snapshot: gatewaySnapshot,
289-
mobile: mobileNavLayout,
290-
// Device-less clients may not reach a session pane, so the shell
291-
// retains the manual-repair entry until the header can own it.
292-
showTrigger:
293-
!sessionRoute || onboarding || gatewaySnapshot.client?.scopeUpgradeReady !== true,
294-
}}
295-
></openclaw-device-scope-upgrade-banner>`
296-
: null;
297279
// Drawer navigation always opens expanded; the tab's desktop collapse state
298280
// stays in memory for when the viewport returns to the desktop layout.
299281
// The settings sidebar has a fixed width, so the collapse state pauses too.
@@ -308,6 +290,17 @@ export function renderApplicationShell(host: ShellViewHost) {
308290
navDrawerOpen,
309291
mobileNavLayout,
310292
});
293+
if (
294+
floatingSidebarAttentionVisible({
295+
navigationSurfaceHidden,
296+
mobileNavLayout,
297+
onboarding,
298+
settingsTakeover,
299+
compact: mergedChatChrome,
300+
})
301+
) {
302+
host.lazyCustomElements.preload(SIDEBAR_ATTENTION_ELEMENT, { reportError: true });
303+
}
311304
const shellWidth = Math.max(globalThis.innerWidth || 0, NAV_WIDTH_MAX);
312305
// A route query is navigation input, not an owner record. Let it override the
313306
// live selection only after the roster proves that agent exists.
@@ -493,9 +486,6 @@ export function renderApplicationShell(host: ShellViewHost) {
493486
.resourceBasePath=${context.resourceBasePath}
494487
.environment=${config.environment}
495488
.navDrawerOpen=${navDrawerOpen}
496-
.trailingActions=${mobileNavLayout && !onboarding && !mergedChatChrome
497-
? scopeUpgradeSurface
498-
: nothing}
499489
.onOpenPalette=${() => host.openPalette()}
500490
.onToggleDrawer=${(trigger: HTMLElement) => host.toggleNavigationSurface(trigger)}
501491
></openclaw-app-topbar>
@@ -563,7 +553,6 @@ export function renderApplicationShell(host: ShellViewHost) {
563553
</div>
564554
`
565555
: nothing}
566-
${!mobileNavLayout || onboarding || mergedChatChrome ? scopeUpgradeSurface : nothing}
567556
<div class="shell-nav" ?inert=${navigationSurfaceHidden}>
568557
${mobileNavLayout
569558
? html`<openclaw-modal-dialog
@@ -604,6 +593,7 @@ export function renderApplicationShell(host: ShellViewHost) {
604593
navigationSurfaceHidden,
605594
mobileNavLayout,
606595
onboarding,
596+
settingsTakeover,
607597
compact: mergedChatChrome,
608598
updateAvailable: overlaySnapshot.updateAvailable,
609599
updateSchedule: overlaySnapshot.updateSchedule,

‎ui/src/app/bootstrap.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ import type {
4848
} from "./context.ts";
4949
import { applyControlUiAccent } from "./control-ui-presentation.ts";
5050
import { syncCustomThemeStyleTag } from "./custom-theme.ts";
51+
import { createScopeUpgradeCapability } from "./device-scope-upgrade.ts";
5152
import { createApplicationGateway } from "./gateway-store.ts";
5253
import { createInitialUserMessageHandoff } from "./initial-user-message-handoff.ts";
5354
import { createNativeChatDrafts } from "./native-bridge.ts";
@@ -370,6 +371,7 @@ export function bootstrapApplication(
370371
const agentIdentity = createAgentIdentityCapability(gateway);
371372
const agentSelection = createAgentSelectionCapability(gateway, agents);
372373
const channels = createChannelCapability(gateway);
374+
const scopeUpgrade = createScopeUpgradeCapability(gateway);
373375
const config = createApplicationConfigCapability({
374376
resourceBasePath,
375377
auth: {
@@ -532,6 +534,7 @@ export function bootstrapApplication(
532534
agentSelection,
533535
channels,
534536
config,
537+
scopeUpgrade,
535538
runtimeConfig,
536539
sessions,
537540
placementStartup,
@@ -651,6 +654,7 @@ export function bootstrapApplication(
651654
stopPostConnect();
652655
agents.dispose();
653656
channels.dispose();
657+
scopeUpgrade.dispose();
654658
placementStartup.dispose();
655659
sessions.dispose();
656660
workboard.dispose();

‎ui/src/app/context.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import type { SessionCapability } from "../lib/sessions/index.ts";
1010
import type { WorkboardCapability } from "../lib/workboard/capability.ts";
1111
import type { AgentSelectionCapability } from "./agent-selection.ts";
1212
import type { ApplicationConfigCapability } from "./config.ts";
13+
import type { ScopeUpgradeCapability } from "./device-scope-upgrade.ts";
1314
import type { ApplicationGateway } from "./gateway.ts";
1415
import type { ApplicationInitialUserMessageHandoff } from "./initial-user-message-handoff.ts";
1516
import type { NativeChatDrafts } from "./native-bridge.ts";
@@ -92,6 +93,7 @@ export type ApplicationContext<TRouteId extends string = string> = {
9293
readonly agentSelection: AgentSelectionCapability;
9394
readonly channels: ChannelCapability;
9495
readonly config: ApplicationConfigCapability;
96+
readonly scopeUpgrade: ScopeUpgradeCapability;
9597
readonly runtimeConfig: RuntimeConfigCapability;
9698
readonly sessions: SessionCapability;
9799
readonly placementStartup: ApplicationPlacementStartup;
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
import type { GatewayBrowserClient } from "../api/gateway.ts";
2+
import { formatUiError } from "../lib/format-error.ts";
3+
import {
4+
readScopeUpgradeAvailability,
5+
type ScopeUpgradeState,
6+
} from "./device-scope-upgrade-availability.ts";
7+
import type { ApplicationGatewaySnapshot } from "./gateway.ts";
8+
9+
type UpgradeOperation = { client: GatewayBrowserClient };
10+
11+
/** Owns one live upgrade request independently of whichever UI presents it. */
12+
export class ScopeUpgradeController {
13+
private current: ApplicationGatewaySnapshot;
14+
private operation: UpgradeOperation | null = null;
15+
private value: ScopeUpgradeState = { phase: "hidden" };
16+
17+
constructor(
18+
initial: ApplicationGatewaySnapshot,
19+
private readonly onChange: () => void,
20+
) {
21+
this.current = initial;
22+
this.sync(initial);
23+
}
24+
25+
get state(): ScopeUpgradeState {
26+
return this.value;
27+
}
28+
29+
sync(snapshot: ApplicationGatewaySnapshot): void {
30+
this.current = snapshot;
31+
const client = snapshot.client;
32+
const availability = readScopeUpgradeAvailability(snapshot);
33+
if (!client || availability.phase !== "available") {
34+
this.retireOperation();
35+
this.setState(availability);
36+
return;
37+
}
38+
if (this.operation && this.operation.client !== client) {
39+
this.retireOperation();
40+
this.setState({ phase: "available" });
41+
}
42+
if (this.value.phase === "hidden" || this.value.phase === "guidance") {
43+
this.setState({ phase: "available" });
44+
}
45+
}
46+
47+
request(): void {
48+
this.start(false);
49+
}
50+
51+
retry(): void {
52+
this.start(true);
53+
}
54+
55+
cancel(): void {
56+
this.retireOperation();
57+
this.setState(readScopeUpgradeAvailability(this.current));
58+
}
59+
60+
dispose(): void {
61+
this.retireOperation();
62+
}
63+
64+
private start(retry: boolean): void {
65+
const client = this.current.client;
66+
if (!client || readScopeUpgradeAvailability(this.current).phase !== "available") {
67+
return;
68+
}
69+
if (this.operation) {
70+
if (!retry) {
71+
return;
72+
}
73+
this.retireOperation();
74+
}
75+
const operation = { client };
76+
this.operation = operation;
77+
this.setState({ phase: "requesting" });
78+
void client
79+
.requestScopeUpgrade({
80+
onPending: (requestId) => {
81+
if (this.isCurrent(operation)) {
82+
this.setState({ phase: "pending", requestId });
83+
}
84+
},
85+
})
86+
.then((result) => {
87+
if (!this.isCurrent(operation) || result.status === "approved") {
88+
return;
89+
}
90+
this.setState({
91+
phase: "rejected",
92+
requestId: result.requestId,
93+
expired: result.status === "expired",
94+
});
95+
})
96+
.catch((error: unknown) => {
97+
if (!this.isCurrent(operation) || (error instanceof Error && error.name === "AbortError")) {
98+
return;
99+
}
100+
this.setState({ phase: "error", message: formatUiError(error) });
101+
})
102+
.finally(() => {
103+
if (this.isCurrent(operation)) {
104+
this.operation = null;
105+
}
106+
});
107+
}
108+
109+
private isCurrent(operation: UpgradeOperation): boolean {
110+
return this.operation === operation && this.current.client === operation.client;
111+
}
112+
113+
private retireOperation(): void {
114+
const operation = this.operation;
115+
this.operation = null;
116+
operation?.client.cancelScopeUpgrade();
117+
}
118+
119+
private setState(next: ScopeUpgradeState): void {
120+
if (JSON.stringify(this.value) === JSON.stringify(next)) {
121+
return;
122+
}
123+
this.value = next;
124+
this.onChange();
125+
}
126+
}

0 commit comments

Comments
 (0)