Files
webmail/lib/plugin-sandbox/assistant/runtime.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

22 lines
954 B
TypeScript

// The assistant's host API areas, merged, inside the plugin sandbox (see README.md).
import { runtime as b } from './b.runtime';
import { runtime as c } from './c.runtime';
import { runtime as d } from './d.runtime';
import { runtime as f } from './f.runtime';
export type CallApi = (method: string, args: unknown[], timeoutMs?: number) => Promise<unknown>;
/** Methods by namespace: { email: { getThread: (...) => ... } }. */
export type RuntimeAdditions = Record<string, Record<string, (...args: never[]) => unknown>>;
/** Adds every area's methods to the plugin's api, namespace by namespace. */
export function withAssistantRuntime<T extends object>(api: T, callApi: CallApi): T {
const target = api as unknown as Record<string, Record<string, unknown>>;
for (const area of [b, c, d, f]) {
for (const [ns, methods] of Object.entries(area(callApi))) {
target[ns] = Object.assign(target[ns] ?? {}, methods);
}
}
return api;
}