Load all plugin types through one short lived PluginLoader

PluginLoader.load takes the plugin type, context, export name and base
class as options and is used by the controller, host, instance, ctl, web
interface and migrations. Module imports go through #plugin_module so the
node variant stays out of the web bundle. loadPlugin.ts and the loading
half of plugin_loader.ts are merged into it.

The loader lives for one load. Plugins reach it through context.plugins,
with waitFor(name, timeoutMs) and checkInstalled(name), replacing the
waitForPlugin methods. Waiting on a plugin that is not in the load list or
failed to load settles right away, as loading can't finish while the
waiting entrypoint is still running.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
bbassieandClaude Opus 5.5 committed 2026-11-20 21:29:23 +00:00
1 parent 7f688d2ed0
commit c1ea4d470b
20 files changed
+500 -522

No files matched your search

+26 -39
View File
@@ -69,49 +69,36 @@ async function loadPlugins(
pluginInfos: lib.PluginWebEnvInfo[],
control: Control
) {
const plugins = new Map<string, WebPlugin.BaseWebPlugin>();
const { loaded, failed } = await lib.PluginLoader.load({
type: "web",
context: (pluginInfo: lib.PluginWebEnvInfo) => ({
control,
container: pluginInfo.container,
package: pluginInfo.package,
}),
logger,
installed: pluginInfos,
load: pluginInfos.filter(pluginInfo => pluginInfo.enabled && pluginInfo.webEntrypoint),
exportName: "WebPlugin",
baseClass: WebPlugin.BaseWebPlugin,
continueOnError: true,
});
for (const pluginInfo of pluginInfos) {
if (!pluginInfo.enabled || !pluginInfo.webEntrypoint) {
continue;
}
try {
const webModule = await pluginInfo.container.get(pluginInfo.webEntrypoint);
const pluginContext: WebPlugin.WebPluginContext = {
control,
plugin: pluginInfo,
container: pluginInfo.container,
package: pluginInfo.package,
logger: logger.child({ plugin: pluginInfo.name }),
};
if (typeof webModule.default === "function") {
await lib.loadPluginEntrypoint(pluginInfo, "web", pluginContext, webModule);
continue;
}
// migrate: accept plugins which export classes
if (webModule.WebPlugin) {
logger.warn(`Plugin ${pluginInfo.name} is using deprecated class hooks`);
plugins.set(pluginInfo.name, await lib.loadPluginClass(
pluginInfo, "web", pluginContext, webModule, "WebPlugin", WebPlugin.BaseWebPlugin
));
continue;
}
throw new Error(`Plugin ${pluginInfo.name} must export either a default function or WebPlugin`);
} catch (err: any) {
pluginInfo.error = `Error loading plugin: ${err.message}`;
logger.error(`Failed to load plugin ${pluginInfo.name}`);
if (err.stack) {
logger.error(err.stack);
}
for (const [pluginInfo, err] of failed) {
const cause = err instanceof lib.PluginError ? err.original : err;
pluginInfo.error = `Error loading plugin: ${cause.message}`;
logger.error(`Failed to load plugin ${pluginInfo.name}`);
if (cause.stack) {
logger.error(cause.stack);
}
}
const plugins = new Map<string, WebPlugin.BaseWebPlugin>();
for (const [pluginInfo, api] of loaded) {
if (api instanceof WebPlugin.BaseWebPlugin) {
plugins.set(pluginInfo.name, api);
}
}
return plugins;
}