@boundaryml/baml-core-node 0.11.2-nightly.20260604.d

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/native.js ADDED
@@ -0,0 +1,619 @@
1
+ /**
2
+ * THIS FILE IS AUTO-GENERATED — DO NOT EDIT BY HAND.
3
+ *
4
+ * Source: baml_language/crates/bridge_nodejs/typescript_src/
5
+ * Proto: baml_language/crates/bridge_ctypes/types/baml_core/cffi/v1/*.proto
6
+ * Build: cd baml_language/crates/bridge_nodejs && pnpm build:debug
7
+ */
8
+ // prettier-ignore
9
+ /* eslint-disable */
10
+ // @ts-nocheck
11
+ /* auto-generated by NAPI-RS */
12
+
13
+ const { readFileSync } = require('node:fs')
14
+ let nativeBinding = null
15
+ const loadErrors = []
16
+
17
+ const isMusl = () => {
18
+ let musl = false
19
+ if (process.platform === 'linux') {
20
+ musl = isMuslFromFilesystem()
21
+ if (musl === null) {
22
+ musl = isMuslFromReport()
23
+ }
24
+ if (musl === null) {
25
+ musl = isMuslFromChildProcess()
26
+ }
27
+ }
28
+ return musl
29
+ }
30
+
31
+ const isFileMusl = (f) => f.includes('libc.musl-') || f.includes('ld-musl-')
32
+
33
+ const isMuslFromFilesystem = () => {
34
+ try {
35
+ return readFileSync('/usr/bin/ldd', 'utf-8').includes('musl')
36
+ } catch {
37
+ return null
38
+ }
39
+ }
40
+
41
+ const isMuslFromReport = () => {
42
+ let report = null
43
+ if (typeof process.report?.getReport === 'function') {
44
+ process.report.excludeNetwork = true
45
+ report = process.report.getReport()
46
+ }
47
+ if (!report) {
48
+ return null
49
+ }
50
+ if (report.header && report.header.glibcVersionRuntime) {
51
+ return false
52
+ }
53
+ if (Array.isArray(report.sharedObjects)) {
54
+ if (report.sharedObjects.some(isFileMusl)) {
55
+ return true
56
+ }
57
+ }
58
+ return false
59
+ }
60
+
61
+ const isMuslFromChildProcess = () => {
62
+ try {
63
+ return require('child_process').execSync('ldd --version', { encoding: 'utf8' }).includes('musl')
64
+ } catch (e) {
65
+ // If we reach this case, we don't know if the system is musl or not, so is better to just fallback to false
66
+ return false
67
+ }
68
+ }
69
+
70
+ function requireNative() {
71
+ if (process.env.NAPI_RS_NATIVE_LIBRARY_PATH) {
72
+ try {
73
+ return require(process.env.NAPI_RS_NATIVE_LIBRARY_PATH);
74
+ } catch (err) {
75
+ loadErrors.push(err)
76
+ }
77
+ } else if (process.platform === 'android') {
78
+ if (process.arch === 'arm64') {
79
+ try {
80
+ return require('./baml_node.android-arm64.node')
81
+ } catch (e) {
82
+ loadErrors.push(e)
83
+ }
84
+ try {
85
+ const binding = require('@boundaryml/baml-core-node-android-arm64')
86
+ const bindingPackageVersion = require('@boundaryml/baml-core-node-android-arm64/package.json').version
87
+ if (bindingPackageVersion !== '0.11.2-nightly.20260604.d' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
88
+ throw new Error(`Native binding package version mismatch, expected 0.11.2-nightly.20260604.d but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
89
+ }
90
+ return binding
91
+ } catch (e) {
92
+ loadErrors.push(e)
93
+ }
94
+ } else if (process.arch === 'arm') {
95
+ try {
96
+ return require('./baml_node.android-arm-eabi.node')
97
+ } catch (e) {
98
+ loadErrors.push(e)
99
+ }
100
+ try {
101
+ const binding = require('@boundaryml/baml-core-node-android-arm-eabi')
102
+ const bindingPackageVersion = require('@boundaryml/baml-core-node-android-arm-eabi/package.json').version
103
+ if (bindingPackageVersion !== '0.11.2-nightly.20260604.d' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
104
+ throw new Error(`Native binding package version mismatch, expected 0.11.2-nightly.20260604.d but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
105
+ }
106
+ return binding
107
+ } catch (e) {
108
+ loadErrors.push(e)
109
+ }
110
+ } else {
111
+ loadErrors.push(new Error(`Unsupported architecture on Android ${process.arch}`))
112
+ }
113
+ } else if (process.platform === 'win32') {
114
+ if (process.arch === 'x64') {
115
+ if (process.config?.variables?.shlib_suffix === 'dll.a' || process.config?.variables?.node_target_type === 'shared_library') {
116
+ try {
117
+ return require('./baml_node.win32-x64-gnu.node')
118
+ } catch (e) {
119
+ loadErrors.push(e)
120
+ }
121
+ try {
122
+ const binding = require('@boundaryml/baml-core-node-win32-x64-gnu')
123
+ const bindingPackageVersion = require('@boundaryml/baml-core-node-win32-x64-gnu/package.json').version
124
+ if (bindingPackageVersion !== '0.11.2-nightly.20260604.d' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
125
+ throw new Error(`Native binding package version mismatch, expected 0.11.2-nightly.20260604.d but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
126
+ }
127
+ return binding
128
+ } catch (e) {
129
+ loadErrors.push(e)
130
+ }
131
+ } else {
132
+ try {
133
+ return require('./baml_node.win32-x64-msvc.node')
134
+ } catch (e) {
135
+ loadErrors.push(e)
136
+ }
137
+ try {
138
+ const binding = require('@boundaryml/baml-core-node-win32-x64-msvc')
139
+ const bindingPackageVersion = require('@boundaryml/baml-core-node-win32-x64-msvc/package.json').version
140
+ if (bindingPackageVersion !== '0.11.2-nightly.20260604.d' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
141
+ throw new Error(`Native binding package version mismatch, expected 0.11.2-nightly.20260604.d but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
142
+ }
143
+ return binding
144
+ } catch (e) {
145
+ loadErrors.push(e)
146
+ }
147
+ }
148
+ } else if (process.arch === 'ia32') {
149
+ try {
150
+ return require('./baml_node.win32-ia32-msvc.node')
151
+ } catch (e) {
152
+ loadErrors.push(e)
153
+ }
154
+ try {
155
+ const binding = require('@boundaryml/baml-core-node-win32-ia32-msvc')
156
+ const bindingPackageVersion = require('@boundaryml/baml-core-node-win32-ia32-msvc/package.json').version
157
+ if (bindingPackageVersion !== '0.11.2-nightly.20260604.d' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
158
+ throw new Error(`Native binding package version mismatch, expected 0.11.2-nightly.20260604.d but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
159
+ }
160
+ return binding
161
+ } catch (e) {
162
+ loadErrors.push(e)
163
+ }
164
+ } else if (process.arch === 'arm64') {
165
+ try {
166
+ return require('./baml_node.win32-arm64-msvc.node')
167
+ } catch (e) {
168
+ loadErrors.push(e)
169
+ }
170
+ try {
171
+ const binding = require('@boundaryml/baml-core-node-win32-arm64-msvc')
172
+ const bindingPackageVersion = require('@boundaryml/baml-core-node-win32-arm64-msvc/package.json').version
173
+ if (bindingPackageVersion !== '0.11.2-nightly.20260604.d' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
174
+ throw new Error(`Native binding package version mismatch, expected 0.11.2-nightly.20260604.d but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
175
+ }
176
+ return binding
177
+ } catch (e) {
178
+ loadErrors.push(e)
179
+ }
180
+ } else {
181
+ loadErrors.push(new Error(`Unsupported architecture on Windows: ${process.arch}`))
182
+ }
183
+ } else if (process.platform === 'darwin') {
184
+ try {
185
+ return require('./baml_node.darwin-universal.node')
186
+ } catch (e) {
187
+ loadErrors.push(e)
188
+ }
189
+ try {
190
+ const binding = require('@boundaryml/baml-core-node-darwin-universal')
191
+ const bindingPackageVersion = require('@boundaryml/baml-core-node-darwin-universal/package.json').version
192
+ if (bindingPackageVersion !== '0.11.2-nightly.20260604.d' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
193
+ throw new Error(`Native binding package version mismatch, expected 0.11.2-nightly.20260604.d but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
194
+ }
195
+ return binding
196
+ } catch (e) {
197
+ loadErrors.push(e)
198
+ }
199
+ if (process.arch === 'x64') {
200
+ try {
201
+ return require('./baml_node.darwin-x64.node')
202
+ } catch (e) {
203
+ loadErrors.push(e)
204
+ }
205
+ try {
206
+ const binding = require('@boundaryml/baml-core-node-darwin-x64')
207
+ const bindingPackageVersion = require('@boundaryml/baml-core-node-darwin-x64/package.json').version
208
+ if (bindingPackageVersion !== '0.11.2-nightly.20260604.d' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
209
+ throw new Error(`Native binding package version mismatch, expected 0.11.2-nightly.20260604.d but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
210
+ }
211
+ return binding
212
+ } catch (e) {
213
+ loadErrors.push(e)
214
+ }
215
+ } else if (process.arch === 'arm64') {
216
+ try {
217
+ return require('./baml_node.darwin-arm64.node')
218
+ } catch (e) {
219
+ loadErrors.push(e)
220
+ }
221
+ try {
222
+ const binding = require('@boundaryml/baml-core-node-darwin-arm64')
223
+ const bindingPackageVersion = require('@boundaryml/baml-core-node-darwin-arm64/package.json').version
224
+ if (bindingPackageVersion !== '0.11.2-nightly.20260604.d' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
225
+ throw new Error(`Native binding package version mismatch, expected 0.11.2-nightly.20260604.d but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
226
+ }
227
+ return binding
228
+ } catch (e) {
229
+ loadErrors.push(e)
230
+ }
231
+ } else {
232
+ loadErrors.push(new Error(`Unsupported architecture on macOS: ${process.arch}`))
233
+ }
234
+ } else if (process.platform === 'freebsd') {
235
+ if (process.arch === 'x64') {
236
+ try {
237
+ return require('./baml_node.freebsd-x64.node')
238
+ } catch (e) {
239
+ loadErrors.push(e)
240
+ }
241
+ try {
242
+ const binding = require('@boundaryml/baml-core-node-freebsd-x64')
243
+ const bindingPackageVersion = require('@boundaryml/baml-core-node-freebsd-x64/package.json').version
244
+ if (bindingPackageVersion !== '0.11.2-nightly.20260604.d' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
245
+ throw new Error(`Native binding package version mismatch, expected 0.11.2-nightly.20260604.d but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
246
+ }
247
+ return binding
248
+ } catch (e) {
249
+ loadErrors.push(e)
250
+ }
251
+ } else if (process.arch === 'arm64') {
252
+ try {
253
+ return require('./baml_node.freebsd-arm64.node')
254
+ } catch (e) {
255
+ loadErrors.push(e)
256
+ }
257
+ try {
258
+ const binding = require('@boundaryml/baml-core-node-freebsd-arm64')
259
+ const bindingPackageVersion = require('@boundaryml/baml-core-node-freebsd-arm64/package.json').version
260
+ if (bindingPackageVersion !== '0.11.2-nightly.20260604.d' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
261
+ throw new Error(`Native binding package version mismatch, expected 0.11.2-nightly.20260604.d but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
262
+ }
263
+ return binding
264
+ } catch (e) {
265
+ loadErrors.push(e)
266
+ }
267
+ } else {
268
+ loadErrors.push(new Error(`Unsupported architecture on FreeBSD: ${process.arch}`))
269
+ }
270
+ } else if (process.platform === 'linux') {
271
+ if (process.arch === 'x64') {
272
+ if (isMusl()) {
273
+ try {
274
+ return require('./baml_node.linux-x64-musl.node')
275
+ } catch (e) {
276
+ loadErrors.push(e)
277
+ }
278
+ try {
279
+ const binding = require('@boundaryml/baml-core-node-linux-x64-musl')
280
+ const bindingPackageVersion = require('@boundaryml/baml-core-node-linux-x64-musl/package.json').version
281
+ if (bindingPackageVersion !== '0.11.2-nightly.20260604.d' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
282
+ throw new Error(`Native binding package version mismatch, expected 0.11.2-nightly.20260604.d but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
283
+ }
284
+ return binding
285
+ } catch (e) {
286
+ loadErrors.push(e)
287
+ }
288
+ } else {
289
+ try {
290
+ return require('./baml_node.linux-x64-gnu.node')
291
+ } catch (e) {
292
+ loadErrors.push(e)
293
+ }
294
+ try {
295
+ const binding = require('@boundaryml/baml-core-node-linux-x64-gnu')
296
+ const bindingPackageVersion = require('@boundaryml/baml-core-node-linux-x64-gnu/package.json').version
297
+ if (bindingPackageVersion !== '0.11.2-nightly.20260604.d' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
298
+ throw new Error(`Native binding package version mismatch, expected 0.11.2-nightly.20260604.d but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
299
+ }
300
+ return binding
301
+ } catch (e) {
302
+ loadErrors.push(e)
303
+ }
304
+ }
305
+ } else if (process.arch === 'arm64') {
306
+ if (isMusl()) {
307
+ try {
308
+ return require('./baml_node.linux-arm64-musl.node')
309
+ } catch (e) {
310
+ loadErrors.push(e)
311
+ }
312
+ try {
313
+ const binding = require('@boundaryml/baml-core-node-linux-arm64-musl')
314
+ const bindingPackageVersion = require('@boundaryml/baml-core-node-linux-arm64-musl/package.json').version
315
+ if (bindingPackageVersion !== '0.11.2-nightly.20260604.d' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
316
+ throw new Error(`Native binding package version mismatch, expected 0.11.2-nightly.20260604.d but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
317
+ }
318
+ return binding
319
+ } catch (e) {
320
+ loadErrors.push(e)
321
+ }
322
+ } else {
323
+ try {
324
+ return require('./baml_node.linux-arm64-gnu.node')
325
+ } catch (e) {
326
+ loadErrors.push(e)
327
+ }
328
+ try {
329
+ const binding = require('@boundaryml/baml-core-node-linux-arm64-gnu')
330
+ const bindingPackageVersion = require('@boundaryml/baml-core-node-linux-arm64-gnu/package.json').version
331
+ if (bindingPackageVersion !== '0.11.2-nightly.20260604.d' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
332
+ throw new Error(`Native binding package version mismatch, expected 0.11.2-nightly.20260604.d but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
333
+ }
334
+ return binding
335
+ } catch (e) {
336
+ loadErrors.push(e)
337
+ }
338
+ }
339
+ } else if (process.arch === 'arm') {
340
+ if (isMusl()) {
341
+ try {
342
+ return require('./baml_node.linux-arm-musleabihf.node')
343
+ } catch (e) {
344
+ loadErrors.push(e)
345
+ }
346
+ try {
347
+ const binding = require('@boundaryml/baml-core-node-linux-arm-musleabihf')
348
+ const bindingPackageVersion = require('@boundaryml/baml-core-node-linux-arm-musleabihf/package.json').version
349
+ if (bindingPackageVersion !== '0.11.2-nightly.20260604.d' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
350
+ throw new Error(`Native binding package version mismatch, expected 0.11.2-nightly.20260604.d but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
351
+ }
352
+ return binding
353
+ } catch (e) {
354
+ loadErrors.push(e)
355
+ }
356
+ } else {
357
+ try {
358
+ return require('./baml_node.linux-arm-gnueabihf.node')
359
+ } catch (e) {
360
+ loadErrors.push(e)
361
+ }
362
+ try {
363
+ const binding = require('@boundaryml/baml-core-node-linux-arm-gnueabihf')
364
+ const bindingPackageVersion = require('@boundaryml/baml-core-node-linux-arm-gnueabihf/package.json').version
365
+ if (bindingPackageVersion !== '0.11.2-nightly.20260604.d' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
366
+ throw new Error(`Native binding package version mismatch, expected 0.11.2-nightly.20260604.d but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
367
+ }
368
+ return binding
369
+ } catch (e) {
370
+ loadErrors.push(e)
371
+ }
372
+ }
373
+ } else if (process.arch === 'loong64') {
374
+ if (isMusl()) {
375
+ try {
376
+ return require('./baml_node.linux-loong64-musl.node')
377
+ } catch (e) {
378
+ loadErrors.push(e)
379
+ }
380
+ try {
381
+ const binding = require('@boundaryml/baml-core-node-linux-loong64-musl')
382
+ const bindingPackageVersion = require('@boundaryml/baml-core-node-linux-loong64-musl/package.json').version
383
+ if (bindingPackageVersion !== '0.11.2-nightly.20260604.d' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
384
+ throw new Error(`Native binding package version mismatch, expected 0.11.2-nightly.20260604.d but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
385
+ }
386
+ return binding
387
+ } catch (e) {
388
+ loadErrors.push(e)
389
+ }
390
+ } else {
391
+ try {
392
+ return require('./baml_node.linux-loong64-gnu.node')
393
+ } catch (e) {
394
+ loadErrors.push(e)
395
+ }
396
+ try {
397
+ const binding = require('@boundaryml/baml-core-node-linux-loong64-gnu')
398
+ const bindingPackageVersion = require('@boundaryml/baml-core-node-linux-loong64-gnu/package.json').version
399
+ if (bindingPackageVersion !== '0.11.2-nightly.20260604.d' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
400
+ throw new Error(`Native binding package version mismatch, expected 0.11.2-nightly.20260604.d but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
401
+ }
402
+ return binding
403
+ } catch (e) {
404
+ loadErrors.push(e)
405
+ }
406
+ }
407
+ } else if (process.arch === 'riscv64') {
408
+ if (isMusl()) {
409
+ try {
410
+ return require('./baml_node.linux-riscv64-musl.node')
411
+ } catch (e) {
412
+ loadErrors.push(e)
413
+ }
414
+ try {
415
+ const binding = require('@boundaryml/baml-core-node-linux-riscv64-musl')
416
+ const bindingPackageVersion = require('@boundaryml/baml-core-node-linux-riscv64-musl/package.json').version
417
+ if (bindingPackageVersion !== '0.11.2-nightly.20260604.d' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
418
+ throw new Error(`Native binding package version mismatch, expected 0.11.2-nightly.20260604.d but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
419
+ }
420
+ return binding
421
+ } catch (e) {
422
+ loadErrors.push(e)
423
+ }
424
+ } else {
425
+ try {
426
+ return require('./baml_node.linux-riscv64-gnu.node')
427
+ } catch (e) {
428
+ loadErrors.push(e)
429
+ }
430
+ try {
431
+ const binding = require('@boundaryml/baml-core-node-linux-riscv64-gnu')
432
+ const bindingPackageVersion = require('@boundaryml/baml-core-node-linux-riscv64-gnu/package.json').version
433
+ if (bindingPackageVersion !== '0.11.2-nightly.20260604.d' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
434
+ throw new Error(`Native binding package version mismatch, expected 0.11.2-nightly.20260604.d but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
435
+ }
436
+ return binding
437
+ } catch (e) {
438
+ loadErrors.push(e)
439
+ }
440
+ }
441
+ } else if (process.arch === 'ppc64') {
442
+ try {
443
+ return require('./baml_node.linux-ppc64-gnu.node')
444
+ } catch (e) {
445
+ loadErrors.push(e)
446
+ }
447
+ try {
448
+ const binding = require('@boundaryml/baml-core-node-linux-ppc64-gnu')
449
+ const bindingPackageVersion = require('@boundaryml/baml-core-node-linux-ppc64-gnu/package.json').version
450
+ if (bindingPackageVersion !== '0.11.2-nightly.20260604.d' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
451
+ throw new Error(`Native binding package version mismatch, expected 0.11.2-nightly.20260604.d but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
452
+ }
453
+ return binding
454
+ } catch (e) {
455
+ loadErrors.push(e)
456
+ }
457
+ } else if (process.arch === 's390x') {
458
+ try {
459
+ return require('./baml_node.linux-s390x-gnu.node')
460
+ } catch (e) {
461
+ loadErrors.push(e)
462
+ }
463
+ try {
464
+ const binding = require('@boundaryml/baml-core-node-linux-s390x-gnu')
465
+ const bindingPackageVersion = require('@boundaryml/baml-core-node-linux-s390x-gnu/package.json').version
466
+ if (bindingPackageVersion !== '0.11.2-nightly.20260604.d' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
467
+ throw new Error(`Native binding package version mismatch, expected 0.11.2-nightly.20260604.d but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
468
+ }
469
+ return binding
470
+ } catch (e) {
471
+ loadErrors.push(e)
472
+ }
473
+ } else {
474
+ loadErrors.push(new Error(`Unsupported architecture on Linux: ${process.arch}`))
475
+ }
476
+ } else if (process.platform === 'openharmony') {
477
+ if (process.arch === 'arm64') {
478
+ try {
479
+ return require('./baml_node.openharmony-arm64.node')
480
+ } catch (e) {
481
+ loadErrors.push(e)
482
+ }
483
+ try {
484
+ const binding = require('@boundaryml/baml-core-node-openharmony-arm64')
485
+ const bindingPackageVersion = require('@boundaryml/baml-core-node-openharmony-arm64/package.json').version
486
+ if (bindingPackageVersion !== '0.11.2-nightly.20260604.d' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
487
+ throw new Error(`Native binding package version mismatch, expected 0.11.2-nightly.20260604.d but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
488
+ }
489
+ return binding
490
+ } catch (e) {
491
+ loadErrors.push(e)
492
+ }
493
+ } else if (process.arch === 'x64') {
494
+ try {
495
+ return require('./baml_node.openharmony-x64.node')
496
+ } catch (e) {
497
+ loadErrors.push(e)
498
+ }
499
+ try {
500
+ const binding = require('@boundaryml/baml-core-node-openharmony-x64')
501
+ const bindingPackageVersion = require('@boundaryml/baml-core-node-openharmony-x64/package.json').version
502
+ if (bindingPackageVersion !== '0.11.2-nightly.20260604.d' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
503
+ throw new Error(`Native binding package version mismatch, expected 0.11.2-nightly.20260604.d but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
504
+ }
505
+ return binding
506
+ } catch (e) {
507
+ loadErrors.push(e)
508
+ }
509
+ } else if (process.arch === 'arm') {
510
+ try {
511
+ return require('./baml_node.openharmony-arm.node')
512
+ } catch (e) {
513
+ loadErrors.push(e)
514
+ }
515
+ try {
516
+ const binding = require('@boundaryml/baml-core-node-openharmony-arm')
517
+ const bindingPackageVersion = require('@boundaryml/baml-core-node-openharmony-arm/package.json').version
518
+ if (bindingPackageVersion !== '0.11.2-nightly.20260604.d' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
519
+ throw new Error(`Native binding package version mismatch, expected 0.11.2-nightly.20260604.d but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
520
+ }
521
+ return binding
522
+ } catch (e) {
523
+ loadErrors.push(e)
524
+ }
525
+ } else {
526
+ loadErrors.push(new Error(`Unsupported architecture on OpenHarmony: ${process.arch}`))
527
+ }
528
+ } else {
529
+ loadErrors.push(new Error(`Unsupported OS: ${process.platform}, architecture: ${process.arch}`))
530
+ }
531
+ }
532
+
533
+ nativeBinding = requireNative()
534
+
535
+ // NAPI_RS_FORCE_WASI is a tri-state flag:
536
+ // unset / any other value → native binding preferred, WASI is only a fallback
537
+ // 'true' → force WASI fallback even if native loaded
538
+ // 'error' → force WASI and throw if no WASI binding is found
539
+ // Treating any non-empty string as truthy (the historical behavior) meant
540
+ // NAPI_RS_FORCE_WASI=false, NAPI_RS_FORCE_WASI=0, etc. inadvertently triggered
541
+ // the WASI path, causing ENOENT for packages shipped without a .wasi.cjs file.
542
+ const forceWasi =
543
+ process.env.NAPI_RS_FORCE_WASI === 'true' || process.env.NAPI_RS_FORCE_WASI === 'error'
544
+
545
+ if (!nativeBinding || forceWasi) {
546
+ let wasiBinding = null
547
+ let wasiBindingError = null
548
+ try {
549
+ wasiBinding = require('./baml_node.wasi.cjs')
550
+ nativeBinding = wasiBinding
551
+ } catch (err) {
552
+ if (forceWasi) {
553
+ wasiBindingError = err
554
+ }
555
+ }
556
+ if (!nativeBinding || forceWasi) {
557
+ try {
558
+ wasiBinding = require('@boundaryml/baml-core-node-wasm32-wasi')
559
+ nativeBinding = wasiBinding
560
+ } catch (err) {
561
+ if (forceWasi) {
562
+ if (!wasiBindingError) {
563
+ wasiBindingError = err
564
+ } else {
565
+ wasiBindingError.cause = err
566
+ }
567
+ loadErrors.push(err)
568
+ }
569
+ }
570
+ }
571
+ if (process.env.NAPI_RS_FORCE_WASI === 'error' && !wasiBinding) {
572
+ const error = new Error('WASI binding not found and NAPI_RS_FORCE_WASI is set to error')
573
+ error.cause = wasiBindingError
574
+ throw error
575
+ }
576
+ }
577
+
578
+ if (!nativeBinding) {
579
+ if (loadErrors.length > 0) {
580
+ throw new Error(
581
+ `Cannot find native binding. ` +
582
+ `npm has a bug related to optional dependencies (https://github.com/npm/cli/issues/4828). ` +
583
+ 'Please try `npm i` again after removing both package-lock.json and node_modules directory.',
584
+ {
585
+ cause: loadErrors.reduce((err, cur) => {
586
+ cur.cause = err
587
+ return cur
588
+ }),
589
+ },
590
+ )
591
+ }
592
+ throw new Error(`Failed to load native binding`)
593
+ }
594
+
595
+ module.exports = nativeBinding
596
+ module.exports.AbortController = nativeBinding.AbortController
597
+ module.exports.BamlAudio = nativeBinding.BamlAudio
598
+ module.exports.BamlHandle = nativeBinding.BamlHandle
599
+ module.exports.BamlImage = nativeBinding.BamlImage
600
+ module.exports.BamlPdf = nativeBinding.BamlPdf
601
+ module.exports.BamlRuntime = nativeBinding.BamlRuntime
602
+ module.exports.BamlVideo = nativeBinding.BamlVideo
603
+ module.exports.Collector = nativeBinding.Collector
604
+ module.exports.FunctionLog = nativeBinding.FunctionLog
605
+ module.exports.HostSpanManager = nativeBinding.HostSpanManager
606
+ module.exports.LlmCall = nativeBinding.LlmCall
607
+ module.exports.LLMCall = nativeBinding.LLMCall
608
+ module.exports.Timing = nativeBinding.Timing
609
+ module.exports.Usage = nativeBinding.Usage
610
+ module.exports._seedFunctionRefHandle = nativeBinding._seedFunctionRefHandle
611
+ module.exports._seedGenericMediaHandle = nativeBinding._seedGenericMediaHandle
612
+ module.exports.completeHostCall = nativeBinding.completeHostCall
613
+ module.exports.flushEvents = nativeBinding.flushEvents
614
+ module.exports.getRuntime = nativeBinding.getRuntime
615
+ module.exports.getVersion = nativeBinding.getVersion
616
+ module.exports.putHandleIntoTable = nativeBinding.putHandleIntoTable
617
+ module.exports.registerHostCallable = nativeBinding.registerHostCallable
618
+ module.exports.releaseHostCallable = nativeBinding.releaseHostCallable
619
+ module.exports.takeHandleFromTable = nativeBinding.takeHandleFromTable