Dashboard › opencode-lore › Distillation
dcce1e62-efbd-4ef4-a10c-73fc5a996737["lore_tm_v1_B7ZTz-mjjT7gTJAHC5oW6biDIW-gMk-HJZPUlqSrdkc"]
Date: Sep 16, 2026
/home/byk/Code/opencode-lore-embedding-runtime/packages/gateway/script/ort-npm-plugin.ts implements npm-runtime backend selection: it prefers native onnxruntime-node when the matching @loreai/onnxruntime-<os>-<arch> package is installed and otherwise uses bundled onnxruntime-web as the dist-only WASM fallback for issue #763./home/byk/Code/opencode-lore-embedding-runtime/packages/gateway/script/ort-npm-plugin.ts resolves the real native entry with require2.resolve("onnxruntime-node") and uses an absolute path so loading it does not retrigger the plugin’s /^onnxruntime-node$/ interception./home/byk/Code/opencode-lore-embedding-runtime/packages/gateway/script/ort-npm-plugin.ts uses a 4-part bundling strategy: 1. handles the preceding transformer/runtime wiring described by the plugin, 2. redirects onnxruntime-node to a native-or-web runtime shim, 3. redirects onnxruntime-web to its Node WASM entry for transformers’ own otherwise-unused import, and 4. patches the real onnxruntime-node/dist/binding.js native-addon require; a binding patch mismatch reports that onnxruntime-node likely changed binding.js./home/byk/Code/opencode-lore-embedding-runtime/packages/gateway/script/ort-native-plugin.ts is the standalone SEA-binary plugin and bundles the real native onnxruntime-node, not onnxruntime-web; it has no onnxruntime-node→web redirect and no transformers CDN fallback./home/byk/Code/opencode-lore-embedding-runtime/packages/gateway/script/ort-native-plugin.ts stubs both sharp and onnxruntime-web as empty modules because transformers.js imports the web backend unconditionally even when Node uses the native backend./home/byk/Code/opencode-lore-embedding-runtime/packages/gateway/script/ort-native-plugin.ts rewrites the native-addon load in onnxruntime-node/dist/binding.js to the exact expression require((globalThis.__LORE_ORT_BINDING_PATH__ ?? (() => { throw new Error("lore: __LORE_ORT_BINDING_PATH__ is unset — the native onnxruntime-node addon was not extracted from SEA assets (native-loader.cjs did not run?)"); })())); this confirms the binding path is expected to be populated by the SEA native loader before the patched require executes./home/byk/Code/opencode-lore-embedding-runtime/packages/gateway/script/pack-ort-npm.ts builds the @loreai/onnxruntime-<target> platform packages and wires them into the gateway tarball as optionalDependencies; CI runs it in the release branch “Pack tarballs” step, and Craft publishes the resulting loreai-onnxruntime-<target>-<version>.tgz archives.pack-ort-npm.ts constructs optional dependencies with Object.fromEntries(ORT_NPM_PLATFORMS.map((p) => [ortPackageName(p.target), version])), merges them into any existing pkg.optionalDependencies, and pins every platform package to the exact gateway version.pack-ort-npm.ts logs ✓ injected ${Object.keys(optionalDependencies).length} optionalDependencies into ${gatewayTarball} after injection and → pack ${ORT_NPM_PLATFORMS.length} @loreai/onnxruntime-* packages @ ${version} → ${tarballsDir} before packing; with the defined platform list, this represents exactly 5 optional dependencies and 5 platform packages.pack-ort-npm.ts lists generated files whose names start with loreai-onnxruntime-./home/byk/Code/opencode-lore-embedding-runtime/packages/gateway/script/vendor-ort-native.ts vendors the native onnxruntime-node runtime for every build target because a fossilize SEA binary has no node_modules; unlike the generated platform packages, the installed onnxruntime-node package carries binaries for every supported platform.vendor-ort-native.ts resolves onnxruntime-node/package.json to locate the package root and determine the installed runtime version, preserving ABI compatibility between the embedded libraries and addon; failure to determine the version throws vendor-ort-native: could not determine onnxruntime-node version.vendor-ort-native.ts discovers the bin/napi-v<N> directory dynamically rather than hard-coding a N-API level because releases may move among directories such as napi-v3 and napi-v6; its ambiguity/error reporting includes the discovered directory names in found [${napiDirs.join(", ")}].vendor-ort-native.ts maps each build target into onnxruntime-node’s bin/napi-v<N>/<platform>/<arch> tree, checks that each platform directory exists, and emits vendor-ort-native: onnxruntime-node bin dir missing: ${dir} when absent.vendor-ort-native.ts accounts for the onnxruntime-node >= 1.27 macOS native library name libonnxruntime.1.dylib./home/byk/Code/opencode-lore-embedding-runtime/packages/gateway/script/bundle.ts resolves onnxruntime-node/package.json via createRequire, identifies .node native binaries as unsupported by ordinary esbuild handling, and defines external = ["node:*", "onnxruntime-node", "sharp", "sqlite-vec"].bundle.ts describe dual npm backends: bundle the real onnxruntime-node with a graceful binding patch plus onnxruntime-web, prefer the native addon from the per-platform @loreai/onnxruntime-<target> optional dependency at runtime, and fall back to WASM.bundle.ts also contains older comments saying worker bundles redirect onnxruntime-node to onnxruntime-web; these coexist with the newer dual-backend comments and the script still copies the onnxruntime-web WASM runtime beside worker bundles./home/byk/Code/opencode-lore-embedding-runtime/packages/gateway/script/ort-web-plugin.ts implements the WASM-only alternative: it resolves onnxruntime-web through transformers’ dependency tree, redirects both onnxruntime-node and onnxruntime-web to the same Node-targeted onnxruntime-web .mjs package entry, avoids the dist error Cannot find module 'onnxruntime-node', and is distinguished from SEA builds that embed native per-target assets through ort-native-plugin.ts.