MCPcopy
hub / github.com/TanStack/ai / probeIsolatedVm

Function probeIsolatedVm

packages/ai-isolate-node/src/isolate-driver.ts:42–75  ·  view source on GitHub ↗

* Probe isolated-vm in a subprocess to detect native addon incompatibilities. * An incompatible build (e.g. compiled for a different Node.js version) will * segfault the process — a crash that no JS error handling can catch. * Running the probe in a child process lets us detect this safely.

()

Source from the content-addressed store, hash-verified

40 * Running the probe in a child process lets us detect this safely.
41 */
42function probeIsolatedVm(): { compatible: boolean; error?: string } {
43 if (_probeResult) return _probeResult
44
45 try {
46 const esmRequire = createRequire(import.meta.url)
47 const ivmPath = esmRequire.resolve('isolated-vm')
48 const result = spawnSync(
49 process.execPath,
50 [
51 '-e',
52 `const ivm = require(${JSON.stringify(ivmPath)}); new ivm.Isolate({ memoryLimit: 8 }).dispose(); process.exit(0)`,
53 ],
54 { timeout: 10_000, encoding: 'utf8' },
55 )
56
57 if (result.status === 0) {
58 _probeResult = { compatible: true }
59 } else {
60 const signal = result.signal ? ` (signal: ${result.signal})` : ''
61 const stderr = result.stderr.trim() ? `\n${result.stderr.trim()}` : ''
62 _probeResult = {
63 compatible: false,
64 error: `isolated-vm probe exited with code ${result.status}${signal}${stderr}`,
65 }
66 }
67 } catch (err) {
68 _probeResult = {
69 compatible: false,
70 error: `Failed to probe isolated-vm: ${err instanceof Error ? err.message : String(err)}`,
71 }
72 }
73
74 return _probeResult
75}
76
77export { probeIsolatedVm }
78

Callers 3

createNodeIsolateDriverFunction · 0.85

Calls 1

resolveMethod · 0.80

Tested by

no test coverage detected