From 4b6327120d1219b564473a0e2db0e5ea486a946d Mon Sep 17 00:00:00 2001 From: Justyn Shull Date: Wed, 24 Jul 2024 02:23:31 -0500 Subject: [PATCH] Add system.invokeFunctionOnServer syscall to force proxying syscalls to server --- common/syscalls/system.ts | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/common/syscalls/system.ts b/common/syscalls/system.ts index 9e0f30f28..056739e1b 100644 --- a/common/syscalls/system.ts +++ b/common/syscalls/system.ts @@ -45,6 +45,34 @@ export function systemSyscalls( } return plug.invoke(functionName, args); }, + "system.invokeFunctionOnServer": ( + ctx, + fullName: string, // plug.function + ...args: any[] + ) => { + const [plugName, functionName] = fullName.split("."); + if (!plugName || !functionName) { + throw Error(`Invalid function name ${fullName}`); + } + const plug = system.loadedPlugs.get(plugName); + if (!plug) { + throw Error(`Plug ${plugName} not found`); + } + const functionDef = plug.manifest!.functions[functionName]; + if (!functionDef) { + throw Error(`Function ${functionName} not found`); + } + if (!client) { + throw new Error("Not supported"); + } + // Proxy to system env + return proxySyscall( + ctx, + client.httpSpacePrimitives, + "system.invokeFunction", + [fullName, ...args], + ); + }, "system.invokeCommand": (_ctx, name: string, args?: string[]) => { if (!client) { throw new Error("Not supported");