-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathkernel-facade.ts
More file actions
47 lines (38 loc) · 1.48 KB
/
kernel-facade.ts
File metadata and controls
47 lines (38 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import { makeDefaultExo } from '@metamask/kernel-utils/exo';
import type { Kernel, ClusterConfig, KRef, VatId } from '@metamask/ocap-kernel';
import type { KernelFacade, LaunchResult } from '../../types.ts';
export type { KernelFacade } from '../../types.ts';
/**
* Create the kernel facade exo that exposes kernel methods via CapTP.
*
* @param kernel - The kernel instance to wrap.
* @returns The kernel facade exo.
*/
export function makeKernelFacade(kernel: Kernel): KernelFacade {
return makeDefaultExo('KernelFacade', {
ping: async () => 'pong' as const,
launchSubcluster: async (config: ClusterConfig): Promise<LaunchResult> => {
const { subclusterId, bootstrapRootKref } =
await kernel.launchSubcluster(config);
return { subclusterId, rootKref: bootstrapRootKref };
},
terminateSubcluster: async (subclusterId: string) => {
return kernel.terminateSubcluster(subclusterId);
},
queueMessage: async (target: KRef, method: string, args: unknown[]) => {
return kernel.queueMessage(target, method, args);
},
getStatus: async () => {
return kernel.getStatus();
},
pingVat: async (vatId: VatId) => {
return kernel.pingVat(vatId);
},
getVatRoot: async (krefString: string) => {
// Return wrapped kref for future CapTP marshalling to presence
// TODO: Enable custom CapTP marshalling tables to convert this to a presence
return { kref: krefString };
},
});
}
harden(makeKernelFacade);