mesh-llm/sdk/node
2026-07-28 13:31:59 -04:00
..
console feat: native rust SDK for rust consumers. (#736) 2026-06-03 12:39:19 +10:00
example feat: native rust SDK for rust consumers. (#736) 2026-06-03 12:39:19 +10:00
scripts Hand npm publishing to mesh-packaging 2026-07-27 19:39:09 -04:00
test feat: native rust SDK for rust consumers. (#736) 2026-06-03 12:39:19 +10:00
index.d.ts feat: native rust SDK for rust consumers. (#736) 2026-06-03 12:39:19 +10:00
index.js feat: native rust SDK for rust consumers. (#736) 2026-06-03 12:39:19 +10:00
native-runtime.js feat: native rust SDK for rust consumers. (#736) 2026-06-03 12:39:19 +10:00
package.json Rename the Node SDK npm package scope (#1101) 2026-07-28 13:31:59 -04:00
README.md Rename the Node SDK npm package scope (#1101) 2026-07-28 13:31:59 -04:00

MeshLLM Node SDK

Node.js bindings for MeshLLM client mode, model management, local serving, and Electron-style desktop packaging.

The package uses a native N-API addon built from crates/mesh-llm-nodejs. It is not a mock wrapper around the CLI. Local serving uses the same embedded runtime path as the Swift and Kotlin SDKs.

Install

npm install @mesh-llm/sdk

Release packages include prebuilt addons for macOS arm64/x64, Linux arm64/x64, and Windows x64.

Build From Source

cd sdk/node
npm run build:native

The build copies the platform addon to:

sdk/node/native/<platform>-<arch>/mesh_llm_nodejs.node

On Windows, the source binary is target/release/mesh_llm_nodejs.dll and the packaged Node addon is renamed to mesh_llm_nodejs.node.

Client Mode

const { Client, generateOwnerKeypairHex } = require('@mesh-llm/sdk')

const client = Client.create({
  ownerKeypairHex: generateOwnerKeypairHex(),
  inviteToken: 'your-invite-token'
})

await client.start()
const models = await client.inference.listModels()
await client.stop()

Local Serving Mode

Resolve or install a native runtime before loading a local model. The SDK can use a packaged artifact directory, or download the recommended runtime when MESH_SDK_RUNTIME_ALLOW_DOWNLOAD=1 is set:

MESHLLM_NATIVE_RUNTIME_ARTIFACT_DIR=dist/native-runtimes/meshllm-native-runtime-linux-x86_64-cuda \
MESH_SDK_MODEL_REF=Qwen2.5-3B-Instruct-Q4_K_M \
node sdk/node/example/local-inference.js

Use Node instead of Client when the app needs local model management or serving:

const {
  Node,
  generateOwnerKeypairHex,
  resolveNativeRuntime
} = require('@mesh-llm/sdk')

const runtime = await resolveNativeRuntime({
  artifactDir: process.env.MESHLLM_NATIVE_RUNTIME_ARTIFACT_DIR,
  allowDownload: process.env.MESH_SDK_RUNTIME_ALLOW_DOWNLOAD === '1'
})
console.log(`using ${runtime.nativeRuntimeId} from ${runtime.path}`)

const node = Node.create({
  ownerKeypairHex: generateOwnerKeypairHex(),
  inviteToken: 'local-electron-app',
  servingEnabled: true
})

In an Electron app, package both:

  • native/<platform>-<arch>/mesh_llm_nodejs.node
  • the selected meshllm-native-runtime-* runtime artifact directory
  • optional console/ assets when using node.startConsole()

Then pass the packaged artifact directory to resolveNativeRuntime() before creating a serving-enabled node.

Optional Console

Console assets are not embedded in the default native addon. A package that includes the built console under console/ can start the static console server without asking the application for a raw path:

const consoleHandle = await node.startConsole()
console.log(consoleHandle.url)

For development builds, pass an explicit asset directory:

await node.startConsole({ assetDir: 'crates/mesh-llm-ui/dist', port: 3131 })

Release packages prepare that directory with:

scripts/package-sdk-console-assets.sh --sdk node
scripts/verify-sdk-console-assets.sh --sdk node

Windows

Windows is supported through the same N-API addon shape:

  • addon: mesh_llm_nodejs.node
  • native runtime library: meshllm_ffi.dll
  • target triple: x86_64-pc-windows-msvc
  • runtime artifact names: meshllm-native-windows-x86_64-cpu, meshllm-native-windows-x86_64-cuda, meshllm-native-windows-x86_64-rocm, or meshllm-native-windows-x86_64-vulkan

The Windows release pipeline already builds CPU, CUDA, ROCm, and Vulkan runtime bundles. The Node SDK should publish matching prebuilt addon/runtime packages for Electron consumers instead of requiring local Visual Studio/CUDA/ROCm/Vulkan toolchains.