MCPcopy Create free account
hub / github.com/dylan-sutton-chavez/edge-python / loadHostModule

Function loadHostModule

runtime/src/index.js:36–49  ·  view source on GitHub ↗
(name)

Source from the content-addressed store, hash-verified

34 const hostUrls = { ...(opts?.defaults !== false ? DEFAULT_HOST : {}), ...(opts?.hostModules || {}) };
35 const loadedHosts = new Map(); // name -> export names, memoized across runs
36 const loadHostModule = async (name) => {
37 if (loadedHosts.has(name)) return loadedHosts.get(name);
38 const url = hostUrls[name];
39 if (!url) throw new Error(`no host module registered for '${name}'`);
40 const mod = await import(url);
41 const factory = mod[name] ?? mod.default;
42 const handlers = typeof factory === 'function' ? factory({ pushEvent }) : factory;
43 for (const [fnName, handler] of Object.entries(handlers)) {
44 mainThreadHandlers[`${name}:${fnName}`] = handler;
45 }
46 const exports = Object.keys(handlers);
47 loadedHosts.set(name, exports);
48 return exports;
49 };
50
51 worker.onmessage = async ({ data }) => {
52 if (data.type === 'line') {

Callers 1

createWorkerFunction · 0.85

Calls 3

keysMethod · 0.80
setMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected