@ailu-ai/napi

中文文档
2.8.5发布于 2026/11/06Apache-2.0TypeScriptCommonJS零依赖近 30 天下载 2916

Node bindings to the Ailu Rust engine (graph validation, DSL compile, run/resume/approve).

原始使用文档
文档目录5 节
  1. Exposed
  2. Dev flow (the one to use day to day)
  3. Release flow ( @napi-rs/cli — for publish pipelines, not de…
  4. SDK integration
  5. CI

ailu-napi — Node bindings for the Rust engine

napi-rs bindings that expose the Rust engine to Node, so the TypeScript SDK and control plane can call the Rust core during the migration (ADR 0002) without a flag day. JSON in / JSON out keeps the boundary trivial.

Published to the pnpm workspace as @ailu-ai/napi (see pnpm-workspace.yaml).

Exposed

  • engineVersion(): string
  • validateGraphJson(definitionJson: string): string — returns a JSON array of validation errors ([] when sound). The drop-in replacement for the TS validateGraph (same GraphDefinition wire shape, same error codes).

Dev flow (the one to use day to day)

From the repo root:

pnpm napi:build        # runs scripts/build-napi.sh

The script runs cargo build -p ailu-napi, detects the platform (.dylib on macOS, .so on Linux, .dll otherwise) and copies the cdylib to crates/bindings/ailu_napi.node — exactly the file the handwritten index.js requires. index.js and index.d.ts are handwritten and checked in; the dev flow never regenerates them.

The script (and the root rust:* scripts) assume cargo is on PATH. rustup's installer arranges that for normal login shells; the script additionally sources "$HOME/.cargo/env" itself if cargo is missing, so it also works from bare non-login shells.

Smoke test:

node crates/bindings/smoke.cjs
# engineVersion: 0.0.1
# valid → []
# dangling edge → [{"code":"INVALID_EDGE_REFERENCE",...}]

Release flow (@napi-rs/cli — for publish pipelines, not dev)

package.json carries a napi config block ("name": "ailu_napi", matching the binary basename) and two scripts, named so turbo ignores them (turbo only picks up build/test/lint/typecheck):

pnpm --filter @ailu-ai/napi run build:napi          # napi build --platform --release
pnpm --filter @ailu-ai/napi run build:napi:debug    # napi build --platform

napi build --platform compiles the crate and emits a platform-suffixed binary (e.g. ailu_napi.darwin-arm64.node) plus regenerated index.js/index.d.ts: the generated loader switch-cases over process.platform/process.arch and requires the suffixed binary (or an @ailu-ai/napi-<platform> sub-package), which is what you want when publishing prebuilds for many targets from CI.

Why dev does not use it: the generated loader never looks at ailu_napi.node, so it silently ignores what scripts/build-napi.sh produces — on a fresh machine, pnpm napi:build would build a binary the loader cannot find. The CLI path was verified locally (build succeeds, generated loader loads, SDK example and tests pass), but the handwritten loader is kept as the committed state so the dev script stays the single source of truth. A real release pipeline should run build:napi per target and ship the generated loader in the published package instead.

SDK integration

packages/graph-sdk/src/rust-validator.ts loads @ailu-ai/napi optionally: if the module (or its .node binary) is absent, the require throws, the SDK catches it and falls back to the pure-TypeScript validateGraph from @ailu-ai/graph-core. Nothing in the SDK hard-depends on the native addon.

pnpm --filter @ailu-ai/graph-sdk exec node --import tsx examples/rust-validation.ts
# Rust validator active: true     (with the .node present; false → TS fallback)

CI

.github/workflows/ci.yml (ready-to-activate; the repo is not under git yet) runs a node lane (pnpm install, typecheck, test, lint) and a rust lane (cargo fmt --check, cargo clippy --all-targets -- -D warnings, cargo test inside crates/). The same gates are wired locally as root scripts: pnpm rust:fmt, pnpm rust:lint, pnpm rust:test, pnpm napi:build.

版本与发布记录

@ailu-ai/napi 共发布 18 个版本,首次发布于 2026/09/29;过去 12 个月发布了 18 个版本。

版本发布日期距今
2.8.5latest2026/11/061 天前
2.8.42026/11/053 天前
2.8.32026/11/053 天前
2.8.22026/10/308 天前
2.8.12026/10/299 天前
2.8.02026/10/299 天前

关于 @ailu-ai/napi 的常见问题

@ailu-ai/napi 是什么?

Node bindings to the Ailu Rust engine (graph validation, DSL compile, run/resume/approve).

如何安装 @ailu-ai/napi?

在项目目录运行 npm install @ailu-ai/napi,或使用 pnpm add / yarn add / bun add。

@ailu-ai/napi 支持 TypeScript 吗?

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

@ailu-ai/napi 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@ailu-ai/napi 可以商用吗?

@ailu-ai/napi 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@ailu-ai/napi 的下载量有多少?

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

@ailu-ai/napi 还在维护吗?

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