Skip to content

Commit f278991

Browse files
authored
feat(ui): add composer capability menu (#115800)
* feat(ui): composer capability menu with per-session overrides * refactor(ui): keep chat render within lint ceiling * fix(ui): preserve loaded capability overrides * fix(ui): remove stale capability menu field * fix(ui): gate capability menu on runtime-config readiness
1 parent 77e9ee0 commit f278991

20 files changed

Lines changed: 1600 additions & 25 deletions

‎ui/src/api/types.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,7 @@ export type GatewaySessionRow = {
565565
thinkingOptions?: string[];
566566
thinkingDefault?: string;
567567
fastMode?: FastMode;
568+
toolOverrides?: import("../lib/sessions/patch.js").SessionToolOverrides;
568569
effectiveFastMode?: FastMode;
569570
effectiveFastModeSource?: FastModeSource;
570571
fastAutoOnSeconds?: number;

‎ui/src/e2e/chat-composer-capability-menu.e2e.test.ts‎

Lines changed: 398 additions & 0 deletions
Large diffs are not rendered by default.

‎ui/src/i18n/locales/en.ts‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4994,6 +4994,34 @@ export const en: TranslationMap = {
49944994
attachPhoto: "Photo",
49954995
attachFile: "Attach file",
49964996
attachFileOption: "File",
4997+
menu: {
4998+
back: "Back",
4999+
skills: "Skills",
5000+
connectors: "Connectors",
5001+
webSearch: "Web search",
5002+
managePlugins: "Manage plugins",
5003+
manageSkills: "Manage skills",
5004+
browseConnectors: "Browse connectors",
5005+
addMcpServer: "Add MCP server…",
5006+
toolAccess: "Tool access",
5007+
enabledCount: "{count} on",
5008+
loadingSkills: "Loading skills…",
5009+
skillsLoadFailed: "Couldn’t load skills.",
5010+
noSkills: "No skills available.",
5011+
noConnectors: "No MCP servers configured.",
5012+
depsMissing: "deps missing",
5013+
skillBlocked: "not available for this agent",
5014+
sessionTag: "session",
5015+
offlineBlocked: "Connect to the gateway to change session capabilities.",
5016+
readOnlyBlocked: "Write access is required to change session capabilities.",
5017+
adminBlocked: "Admin access is required to manage connectors.",
5018+
savingBlocked: "Wait for the current session capability change to finish.",
5019+
},
5020+
overrides: {
5021+
count: "{count} session overrides",
5022+
countOne: "{count} session override",
5023+
clear: "Clear session overrides",
5024+
},
49975025
contextUsage: {
49985026
title: "Context usage details",
49995027
open: "Open context usage details",

‎ui/src/lib/sessions/patch.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
import type { FastMode, SessionsPatchResult } from "../../api/types.ts";
22

3+
export type SessionToolOverrides = {
4+
mcpServers?: Record<string, boolean>;
5+
mcpToolsDeny?: Record<string, string[]>;
6+
skills?: Record<string, boolean>;
7+
webSearch?: boolean;
8+
};
9+
310
export type SessionPatch = {
411
label?: string | null;
512
category?: string | null;
@@ -10,6 +17,7 @@ export type SessionPatch = {
1017
fastMode?: FastMode | null;
1118
verboseLevel?: string | null;
1219
reasoningLevel?: string | null;
20+
toolOverrides?: SessionToolOverrides | null;
1321
archived?: boolean;
1422
pinned?: boolean;
1523
unread?: boolean;
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import { describe, expect, it } from "vitest";
2+
import {
3+
countSessionToolOverrides,
4+
nextBooleanToolOverrides,
5+
nextWebSearchToolOverrides,
6+
resolveToolOverrideState,
7+
sessionToolOverrideNames,
8+
} from "./tool-overrides.ts";
9+
10+
describe("session tool overrides", () => {
11+
it("resolves sparse booleans against their base state", () => {
12+
expect(resolveToolOverrideState(true, undefined)).toBe(true);
13+
expect(resolveToolOverrideState(false, undefined)).toBe(false);
14+
expect(resolveToolOverrideState(true, false)).toBe(false);
15+
expect(resolveToolOverrideState(false, true)).toBe(true);
16+
});
17+
18+
it("adds and removes named overrides without disturbing sibling groups", () => {
19+
const current = {
20+
mcpServers: { github: false },
21+
mcpToolsDeny: { notion: ["delete_page"] },
22+
webSearch: false,
23+
};
24+
expect(nextBooleanToolOverrides(current, "skills", "release", false, true)).toEqual({
25+
...current,
26+
skills: { release: false },
27+
});
28+
expect(nextBooleanToolOverrides(current, "mcpServers", "github", true, true)).toEqual({
29+
mcpToolsDeny: { notion: ["delete_page"] },
30+
webSearch: false,
31+
});
32+
expect(current).toEqual({
33+
mcpServers: { github: false },
34+
mcpToolsDeny: { notion: ["delete_page"] },
35+
webSearch: false,
36+
});
37+
});
38+
39+
it("restores default-on web search by removing the key", () => {
40+
const off = nextWebSearchToolOverrides({ skills: { docs: true } }, false);
41+
expect(off).toEqual({ skills: { docs: true }, webSearch: false });
42+
expect(nextWebSearchToolOverrides(off, true)).toEqual({ skills: { docs: true } });
43+
expect(nextWebSearchToolOverrides({}, true, false)).toEqual({ webSearch: true });
44+
expect(nextWebSearchToolOverrides({ webSearch: true }, false, false)).toEqual({});
45+
});
46+
47+
it("counts override categories and returns deterministic tooltip names", () => {
48+
const overrides = {
49+
mcpServers: { zeta: false, alpha: true },
50+
mcpToolsDeny: { tools: ["danger"] },
51+
skills: { beta: false },
52+
webSearch: false,
53+
};
54+
expect(countSessionToolOverrides(overrides)).toBe(5);
55+
expect(sessionToolOverrideNames(overrides, "Web search")).toEqual([
56+
"alpha",
57+
"beta",
58+
"tools",
59+
"Web search",
60+
"zeta",
61+
]);
62+
});
63+
});
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import type { SessionToolOverrides } from "./patch.ts";
2+
3+
type BooleanOverrideGroup = "mcpServers" | "skills";
4+
5+
function copyOverrides(overrides: SessionToolOverrides | null | undefined): SessionToolOverrides {
6+
return {
7+
...(overrides?.mcpServers ? { mcpServers: { ...overrides.mcpServers } } : {}),
8+
...(overrides?.mcpToolsDeny
9+
? {
10+
mcpToolsDeny: Object.fromEntries(
11+
Object.entries(overrides.mcpToolsDeny).map(([name, tools]) => [name, [...tools]]),
12+
),
13+
}
14+
: {}),
15+
...(overrides?.skills ? { skills: { ...overrides.skills } } : {}),
16+
...(overrides?.webSearch !== undefined ? { webSearch: overrides.webSearch } : {}),
17+
};
18+
}
19+
20+
export function resolveToolOverrideState(baseEnabled: boolean, override: boolean | undefined) {
21+
return override ?? baseEnabled;
22+
}
23+
24+
export function nextBooleanToolOverrides(
25+
current: SessionToolOverrides | null | undefined,
26+
group: BooleanOverrideGroup,
27+
name: string,
28+
nextEnabled: boolean,
29+
baseEnabled: boolean,
30+
): SessionToolOverrides {
31+
const next = copyOverrides(current);
32+
const values = { ...next[group] };
33+
if (nextEnabled === baseEnabled) {
34+
delete values[name];
35+
} else {
36+
values[name] = nextEnabled;
37+
}
38+
if (Object.keys(values).length === 0) {
39+
delete next[group];
40+
} else {
41+
next[group] = values;
42+
}
43+
return next;
44+
}
45+
46+
export function nextWebSearchToolOverrides(
47+
current: SessionToolOverrides | null | undefined,
48+
nextEnabled: boolean,
49+
baseEnabled = true,
50+
): SessionToolOverrides {
51+
const next = copyOverrides(current);
52+
if (nextEnabled === baseEnabled) {
53+
delete next.webSearch;
54+
} else {
55+
next.webSearch = nextEnabled;
56+
}
57+
return next;
58+
}
59+
60+
export function countSessionToolOverrides(
61+
overrides: SessionToolOverrides | null | undefined,
62+
): number {
63+
return (
64+
Object.keys(overrides?.mcpServers ?? {}).length +
65+
Object.keys(overrides?.skills ?? {}).length +
66+
Object.keys(overrides?.mcpToolsDeny ?? {}).length +
67+
(overrides?.webSearch !== undefined ? 1 : 0)
68+
);
69+
}
70+
71+
export function sessionToolOverrideNames(
72+
overrides: SessionToolOverrides | null | undefined,
73+
webSearchLabel: string,
74+
): string[] {
75+
return [
76+
...Object.keys(overrides?.mcpServers ?? {}),
77+
...Object.keys(overrides?.skills ?? {}),
78+
...Object.keys(overrides?.mcpToolsDeny ?? {}),
79+
...(overrides?.webSearch !== undefined ? [webSearchLabel] : []),
80+
].toSorted((left, right) => left.localeCompare(right));
81+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import { describe, expect, it, vi } from "vitest";
2+
import type { GatewayBrowserClient } from "../../api/gateway.ts";
3+
import type { ConfigSnapshot, GatewaySessionRow } from "../../api/types.ts";
4+
import type { ApplicationContext } from "../../app/context.ts";
5+
import { ChatComposerCapabilityHost } from "./chat-composer-capability-host.ts";
6+
import type { ChatPageHost } from "./chat-state-host.ts";
7+
8+
function createContext(configSnapshot: ConfigSnapshot | null): ApplicationContext {
9+
return {
10+
gateway: { snapshot: { hello: null } },
11+
navigate: vi.fn(),
12+
runtimeConfig: {
13+
ensureLoaded: vi.fn(async () => undefined),
14+
state: { configLoading: false, configSnapshot },
15+
},
16+
} as unknown as ApplicationContext;
17+
}
18+
19+
function createState(): ChatPageHost {
20+
return {
21+
basePath: "",
22+
client: {} as GatewayBrowserClient,
23+
connected: true,
24+
sessionKey: "main",
25+
} as ChatPageHost;
26+
}
27+
28+
describe("ChatComposerCapabilityHost", () => {
29+
it("blocks session mutations until the row and runtime config have loaded", () => {
30+
const host = new ChatComposerCapabilityHost(vi.fn());
31+
const context = createContext(null);
32+
const state = createState();
33+
const session = { key: "main" } as GatewaySessionRow;
34+
35+
expect(host.props(context, state, undefined, "main").mutationBlockedReason).toBe("Loading…");
36+
expect(host.props(context, state, session, "main").mutationBlockedReason).toBe("Loading…");
37+
38+
context.runtimeConfig.state.configSnapshot = {
39+
runtimeConfig: { tools: { web: { search: { enabled: false } } } },
40+
};
41+
const props = host.props(context, state, session, "main");
42+
expect(props.mutationBlockedReason).toBeNull();
43+
expect(props.webSearchBaseEnabled).toBe(false);
44+
});
45+
46+
it("derives capability defaults from the active runtime snapshot", () => {
47+
const host = new ChatComposerCapabilityHost(vi.fn());
48+
const props = host.props(
49+
createContext({
50+
sourceConfig: {
51+
mcp: { servers: { source: { command: "source-mcp", enabled: true } } },
52+
tools: { web: { search: { enabled: false } } },
53+
},
54+
runtimeConfig: {
55+
mcp: { servers: { runtime: { command: "runtime-mcp", enabled: false } } },
56+
tools: { web: { search: { enabled: true } } },
57+
},
58+
}),
59+
createState(),
60+
{ key: "main" } as GatewaySessionRow,
61+
"main",
62+
);
63+
64+
expect(props.mcpServers.map(({ name, enabled }) => ({ name, enabled }))).toEqual([
65+
{ name: "runtime", enabled: false },
66+
]);
67+
expect(props.webSearchBaseEnabled).toBe(true);
68+
});
69+
});

0 commit comments

Comments
 (0)