import { createCachedPluginBoundaryModuleLoader } from "../../plugins/runtime/runtime-plugin-boundary.js"; type RuntimeSendModule = Record; export type RuntimeSend = { sendMessage: (...args: unknown[]) => Promise; }; function resolveRuntimeExport( module: RuntimeSendModule | null, pluginId: string, exportName: string, ): (...args: unknown[]) => Promise { const candidate = module?.[exportName]; if (typeof candidate !== "function") { throw new Error(`${pluginId} plugin runtime is unavailable: missing export '${exportName}'`); } return candidate as (...args: unknown[]) => Promise; } export function createPluginBoundaryRuntimeSend(params: { pluginId: string; exportName: string; missingLabel: string; }): RuntimeSend { const loadRuntimeModuleSync = createCachedPluginBoundaryModuleLoader({ pluginId: params.pluginId, entryBaseName: "runtime-api", required: true, missingLabel: params.missingLabel, }); return { sendMessage: (...args) => resolveRuntimeExport(loadRuntimeModuleSync(), params.pluginId, params.exportName)(...args), }; }