Files
webmail/lib/plugin-sandbox/assistant/index.ts
T
Linus Rath f7ff8212a3 refactor: give the AI assistant's host APIs one set of files per area
The assistant's new host calls come in four areas (context, actions,
Files, the panel in every view), built side by side. Each area gets its
own files under lib/plugin-sandbox/assistant for its permissions, method
table, dispatcher, host feature flags and sandbox methods; the shared
files only read the merged result. No area adds anything yet. The host
features test now compares against the core flags plus the areas' flags.
2026-11-02 21:21:06 +01:00

30 lines
1.1 KiB
TypeScript

// The assistant's host API areas, merged, host side (see README.md).
import type { InstalledPlugin, Permission } from '../../plugin-types';
import { NOT_MINE } from './not-mine';
import * as b from './b';
import * as c from './c';
import * as d from './d';
import * as f from './f';
import type { AssistantHostFeatures } from './types';
export { NOT_MINE };
const AREAS = [b, c, d, f];
/** Method → permission of every area, joined into PERM_PER_METHOD. */
export const ASSISTANT_PERMS: Readonly<Record<string, Permission | null>> = Object.assign({}, ...AREAS.map((a) => a.PERMS));
/** Runs an area's method; NOT_MINE when no area owns it. The permission is checked before. */
export async function dispatchAssistant(plugin: InstalledPlugin, method: string, args: unknown[]): Promise<unknown> {
for (const area of AREAS) {
if (!(method in area.PERMS)) continue;
return area.dispatch(plugin, method, args);
}
return NOT_MINE;
}
/** Every area's api.host.features flags, right now. */
export function assistantFeatures(): AssistantHostFeatures {
return Object.assign({}, ...AREAS.map((a) => a.features()));
}