import { Plug } from "../../plugos/plug.ts"; import { SysCallMapping, System } from "../../plugos/system.ts"; import type { HttpServer } from "../http_server.ts"; export function systemSyscalls( httpServer: HttpServer, system: System, ): SysCallMapping { return { "system.invokeFunction": ( ctx, // Ignored in this context, always assuming server (this place) _env: string, name: string, ...args: any[] ) => { if (!ctx.plug) { throw Error("No plug associated with context"); } let plug: Plug | undefined = ctx.plug; if (name.indexOf(".") !== -1) { // plug name in the name const [plugName, functionName] = name.split("."); plug = system.loadedPlugs.get(plugName); if (!plug) { throw Error(`Plug ${plugName} not found`); } name = functionName; } return plug.invoke(name, args); }, "system.reloadPlugs": () => { return httpServer.reloadPlugs(); }, }; }