@desert-ant-labs/core

中文文档
4.3.0发布于 2026/11/06SEE LICENSE IN LICENSE.mdTypeScriptES Module零依赖近 30 天下载 3.1万

Shared JavaScript runtime for Desert Ant Labs on-device model SDKs: the LiteRT.js host session, the koffi native loader, and the FFI buffer reader that the per-model node packages build on.

原始使用文档
文档目录3 节
  1. What it provides
  2. Tests
  3. License

@desert-ant-labs/core

Shared JavaScript runtime for Desert Ant Labs on-device model SDKs. The per-model node packages (@desert-ant-labs/shapes, @desert-ant-labs/emo, @desert-ant-labs/redact, ...) build their browser and Node entries on these model-agnostic pieces, so each model ships only its payload codecs and its public class - both entry points are a couple of lines of wiring.

Not meant to be used directly; it is the common core the model packages depend on.

What it provides

Browser-safe entry (@desert-ant-labs/core, no node:*):

  • createWasmSdk({ platform, packageName }) - the whole browser/WebAssembly half of a model package: instantiate the core through the package's #platform seam, set up the LiteRT.js session, then open(options) either downloads the model from Hugging Face or adopts the files a modelBaseUrl serves, and returns a ready LoadedModel.
  • LoadedModel - a loaded model behind an opaque core handle: run(text, options, { deviceId }) returning an FfiReader, plus isDownloaded, flushTelemetry, and dispose. The same object on both runtimes, so a package writes its public class once. flushTelemetry waits for the license requests in flight. withCallGroup and the group call option are still accepted and have no effect.
  • makeModelHostSeam() / makeLiteRtHost(...) - the model host a wasm core is instantiated with (dalModelHost in its generated Imports, from Sources/JSHost/Host.swift) and the LiteRT.js implementation of it: named-tensor createSessionFrom* / run with the correct dtype marshalling and LiteRT.js manual memory management. The seam is late-bound, so a core can instantiate before its session exists, and nothing is installed on globalThis.
  • loadLiteRt(...) / assertBrowserRuntime(...) - load @litertjs/core once per process (with an install hint) and guard against running the wasm runtime in plain Node.
  • fetchSelfHostedModel(baseUrl, files) - fetch the files a modelBaseUrl serves: sidecars keyed by catalog name, artifact bytes for the host to compile.
  • browserSetup / browserWasmDir / browserReadModelSource / browserCacheRoot - the browser half of a model's #platform seam.
  • The wasm ABI itself (create, createSelfHosted, isDownloaded, download, run, endCallGroup, destroy, flushTelemetry), the twin of the native dal_* symbols, is what BridgeJS generates from the @JS entry points in the model's Web/main.swift; its types live in the package's own generated dist/bridge-js.d.ts. Both setups return it, so a model package writes no wasm glue: options and results cross as FFIBuffer payloads it encodes with the codecs it already needs for the native entry.
  • FfiReader / FfiWriter - big-endian cursor over the length-prefixed FFIBuffer payloads both cores speak (the JS counterpart of Kotlin's FfiReader).

Node entry (@desert-ant-labs/core/node, uses node:* + koffi):

  • createNativeSdk({ here, packageName, modelId, coreName }) - the native half of a model package, mirroring createWasmSdk: binds the prebuilt core and returns an SDK whose open(options) yields the same LoadedModel.

  • loadNative({ here, packageName, coreName, modelId }) - the loader under it: resolves the prebuilt Swift core under native/<platform>-<arch>, loads the LiteRT runtime first, binds the C ABI with koffi (generic dal_* calls plus the model's own <modelId>_create), and returns callAsync + decodeResult + cache-path helpers. SSR-safe node seam (@desert-ant-labs/core/platform-node, uses node:*, no koffi):

  • nodeSetup / nodeWasmDir / nodeReadModelSource / nodeCacheRoot - the Node half of the #platform seam, reached when a framework renders the universal wasm entry in Node (Next.js's Client-Component SSR pass).

The two node entries stay apart on purpose. koffi ships native .node addons, and bundlers statically trace the require("koffi") inside the loader even though it only runs lazily, so a package's #platform seam importing /node makes an SSR build fail with Turbopack's "non-ecmascript placeable asset" (or webpack's equivalent). A model package imports /node from its /native entry only, and /platform-node from platform-node.js.

Audio models use the separate @desert-ant-labs/core/audio browser entry or @desert-ant-labs/core/audio/node on Node. Text-model imports never traverse the audio host or WAV codec.

@litertjs/core and koffi are optional peer dependencies: the browser path needs @litertjs/core, the native Node path needs koffi, and neither is required just to import the package.

Tests

mise run test:js        # unit tests + the SSR module-graph guard (no network)
mise run test:bundles   # the bundle matrix: real bundlers, real tarballs

The packages are isomorphic, so most of what can break lives in a bundler rather than in a function. Two layers cover it:

  • test/ssr-graph.test.mjs walks the static import graph the way a bundler does and fails if the browser or SSR seam reaches koffi or a node: builtin. Fast, offline, runs on every change.
  • test/bundle/ packs the core and every model package and builds them with esbuild, vite, webpack, and Next (Turbopack + webpack), plus plain Node imports of both entries. It reproduces consumer build failures exactly; see js/test/bundle/README.md.

License

Desert Ant Labs Source-Available License. Free for most apps, and a commercial license is required at scale. Full terms are at the link. Licensing: [email protected].

Third-party notices for the SDK: THIRD_PARTY_NOTICES.md.

版本与发布记录

@desert-ant-labs/core 共发布 24 个版本,首次发布于 2026/07/25;过去 12 个月发布了 24 个版本。

版本发布日期距今
4.3.0latest2026/11/066 天前
4.2.32026/10/3112 天前
4.2.22026/10/3112 天前
4.2.12026/10/2815 天前
4.2.02026/10/2716 天前
4.1.02026/10/2023 天前

关于 @desert-ant-labs/core 的常见问题

@desert-ant-labs/core 是什么?

Shared JavaScript runtime for Desert Ant Labs on-device model SDKs: the LiteRT.js host session, the koffi native loader, and the FFI buffer reader that the per-model node packages build on.

如何安装 @desert-ant-labs/core?

在项目目录运行 npm install @desert-ant-labs/core,或使用 pnpm add / yarn add / bun add。

@desert-ant-labs/core 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@desert-ant-labs/core 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@desert-ant-labs/core 可以商用吗?

@desert-ant-labs/core 使用 SEE LICENSE IN LICENSE.md 许可。许可条款写在包内的独立文件中,请阅读该文件确认可否商用。以上为概括,不构成法律意见,请以许可原文为准。

@desert-ant-labs/core 的下载量有多少?

根据 npm 官方下载统计,@desert-ant-labs/core 在 2026/10/12 – 2026/11/10 这 30 天内被下载 31,007 次,日均约 1,034 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@desert-ant-labs/core 还在维护吗?

最新版本 4.3.0 发布于 2026/11/06(6 天前);至今共发布 24 个版本,其中过去 12 个月发布了 24 个;首次发布于 2026/07/25。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。