nanocodex 0.1.1

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.
@@ -0,0 +1,745 @@
1
+ /* @ts-self-types="./nanocodex.d.ts" */
2
+
3
+ /**
4
+ * Persistent WASM agent handle hosted by Node.js or a browser Worker.
5
+ */
6
+ export class Nanocodex {
7
+ static __wrap(ptr) {
8
+ const obj = Object.create(Nanocodex.prototype);
9
+ obj.__wbg_ptr = ptr;
10
+ NanocodexFinalization.register(obj, obj.__wbg_ptr, obj);
11
+ return obj;
12
+ }
13
+ __destroy_into_raw() {
14
+ const ptr = this.__wbg_ptr;
15
+ this.__wbg_ptr = 0;
16
+ NanocodexFinalization.unregister(this);
17
+ return ptr;
18
+ }
19
+ free() {
20
+ const ptr = this.__destroy_into_raw();
21
+ wasm.__wbg_nanocodex_free(ptr, 0);
22
+ }
23
+ /**
24
+ * Fork the latest safe committed model boundary.
25
+ *
26
+ * # Errors
27
+ *
28
+ * Rejects before the first safe boundary or after the driver stops.
29
+ * @returns {Promise<Nanocodex>}
30
+ */
31
+ fork() {
32
+ const ret = wasm.nanocodex_fork(this.__wbg_ptr);
33
+ return ret;
34
+ }
35
+ /**
36
+ * Fork from the exact checkpoint retained by a completed historical turn.
37
+ *
38
+ * # Errors
39
+ *
40
+ * Rejects if the turn is incomplete, belongs to another lineage, or the
41
+ * driver stops.
42
+ * @param {Turn} turn
43
+ * @returns {Promise<Nanocodex>}
44
+ */
45
+ forkFrom(turn) {
46
+ _assertClass(turn, Turn);
47
+ const ret = wasm.nanocodex_forkFrom(this.__wbg_ptr, turn.__wbg_ptr);
48
+ return ret;
49
+ }
50
+ /**
51
+ * Build a persistent agent from a JSON configuration object.
52
+ *
53
+ * # Errors
54
+ *
55
+ * Throws when the JSON or required configuration is invalid.
56
+ * @param {string} config_json
57
+ */
58
+ constructor(config_json) {
59
+ const ptr0 = passStringToWasm0(config_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
60
+ const len0 = WASM_VECTOR_LEN;
61
+ const ret = wasm.nanocodex_new(ptr0, len0);
62
+ if (ret[2]) {
63
+ throw takeFromExternrefTable0(ret[1]);
64
+ }
65
+ this.__wbg_ptr = ret[0];
66
+ NanocodexFinalization.register(this, this.__wbg_ptr, this);
67
+ return this;
68
+ }
69
+ /**
70
+ * Accept a prompt immediately and return its independently awaitable turn.
71
+ *
72
+ * # Errors
73
+ *
74
+ * Throws when the prompt is empty or the agent driver has stopped.
75
+ * @param {string} instruction
76
+ * @returns {Turn}
77
+ */
78
+ prompt(instruction) {
79
+ const ptr0 = passStringToWasm0(instruction, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
80
+ const len0 = WASM_VECTOR_LEN;
81
+ const ret = wasm.nanocodex_prompt(this.__wbg_ptr, ptr0, len0);
82
+ if (ret[2]) {
83
+ throw takeFromExternrefTable0(ret[1]);
84
+ }
85
+ return Turn.__wrap(ret[0]);
86
+ }
87
+ /**
88
+ * Accept ordered browser-safe text, image, or audio input encoded as JSON.
89
+ *
90
+ * # Errors
91
+ *
92
+ * Throws for malformed or empty content, local filesystem inputs, or a
93
+ * stopped driver.
94
+ * @param {string} content_json
95
+ * @returns {Turn}
96
+ */
97
+ promptContent(content_json) {
98
+ const ptr0 = passStringToWasm0(content_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
99
+ const len0 = WASM_VECTOR_LEN;
100
+ const ret = wasm.nanocodex_promptContent(this.__wbg_ptr, ptr0, len0);
101
+ if (ret[2]) {
102
+ throw takeFromExternrefTable0(ret[1]);
103
+ }
104
+ return Turn.__wrap(ret[0]);
105
+ }
106
+ /**
107
+ * Stable session identifier used to route this agent's event stream.
108
+ * @returns {string}
109
+ */
110
+ get sessionId() {
111
+ let deferred1_0;
112
+ let deferred1_1;
113
+ try {
114
+ const ret = wasm.nanocodex_sessionId(this.__wbg_ptr);
115
+ deferred1_0 = ret[0];
116
+ deferred1_1 = ret[1];
117
+ return getStringFromWasm0(ret[0], ret[1]);
118
+ } finally {
119
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
120
+ }
121
+ }
122
+ /**
123
+ * Start a clean sibling with the same configuration and tools.
124
+ *
125
+ * # Errors
126
+ *
127
+ * Rejects after the driver stops.
128
+ * @returns {Promise<Nanocodex>}
129
+ */
130
+ spawn() {
131
+ const ret = wasm.nanocodex_spawn(this.__wbg_ptr);
132
+ return ret;
133
+ }
134
+ }
135
+ if (Symbol.dispose) Nanocodex.prototype[Symbol.dispose] = Nanocodex.prototype.free;
136
+
137
+ /**
138
+ * Completion and control handle for one accepted WASM turn.
139
+ */
140
+ export class Turn {
141
+ static __wrap(ptr) {
142
+ const obj = Object.create(Turn.prototype);
143
+ obj.__wbg_ptr = ptr;
144
+ TurnFinalization.register(obj, obj.__wbg_ptr, obj);
145
+ return obj;
146
+ }
147
+ __destroy_into_raw() {
148
+ const ptr = this.__wbg_ptr;
149
+ this.__wbg_ptr = 0;
150
+ TurnFinalization.unregister(this);
151
+ return ptr;
152
+ }
153
+ free() {
154
+ const ptr = this.__destroy_into_raw();
155
+ wasm.__wbg_turn_free(ptr, 0);
156
+ }
157
+ /**
158
+ * Cancel this exact active or queued turn.
159
+ *
160
+ * # Errors
161
+ *
162
+ * Rejects if the turn is already terminal or the driver stops.
163
+ * @returns {Promise<void>}
164
+ */
165
+ cancel() {
166
+ const ret = wasm.turn_cancel(this.__wbg_ptr);
167
+ return ret;
168
+ }
169
+ /**
170
+ * Wait for the turn and return its final assistant message.
171
+ *
172
+ * # Errors
173
+ *
174
+ * Rejects when the model run fails, the driver stops, or two consumers
175
+ * await the same pending turn concurrently.
176
+ * @returns {Promise<string>}
177
+ */
178
+ result() {
179
+ const ret = wasm.turn_result(this.__wbg_ptr);
180
+ return ret;
181
+ }
182
+ /**
183
+ * Inject input at this active turn's next safe model boundary.
184
+ *
185
+ * # Errors
186
+ *
187
+ * Rejects for empty input, a queued or terminal turn, a full steer queue,
188
+ * or a stopped driver.
189
+ * @param {string} instruction
190
+ * @returns {Promise<void>}
191
+ */
192
+ steer(instruction) {
193
+ const ptr0 = passStringToWasm0(instruction, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
194
+ const len0 = WASM_VECTOR_LEN;
195
+ const ret = wasm.turn_steer(this.__wbg_ptr, ptr0, len0);
196
+ return ret;
197
+ }
198
+ /**
199
+ * Inject ordered browser-safe text, image, or audio input at this active
200
+ * turn's next safe model boundary.
201
+ *
202
+ * # Errors
203
+ *
204
+ * Rejects for malformed or empty content, local filesystem inputs, a
205
+ * queued or terminal turn, a full steer queue, or a stopped driver.
206
+ * @param {string} content_json
207
+ * @returns {Promise<void>}
208
+ */
209
+ steerContent(content_json) {
210
+ const ptr0 = passStringToWasm0(content_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
211
+ const len0 = WASM_VECTOR_LEN;
212
+ const ret = wasm.turn_steerContent(this.__wbg_ptr, ptr0, len0);
213
+ return ret;
214
+ }
215
+ }
216
+ if (Symbol.dispose) Turn.prototype[Symbol.dispose] = Turn.prototype.free;
217
+ function __wbg_get_imports() {
218
+ const import0 = {
219
+ __proto__: null,
220
+ __wbg___wbindgen_debug_string_c25d447a39f5578f: function(arg0, arg1) {
221
+ const ret = debugString(arg1);
222
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
223
+ const len1 = WASM_VECTOR_LEN;
224
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
225
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
226
+ },
227
+ __wbg___wbindgen_is_function_1ff95bcc5517c252: function(arg0) {
228
+ const ret = typeof(arg0) === 'function';
229
+ return ret;
230
+ },
231
+ __wbg___wbindgen_is_undefined_c05833b95a3cf397: function(arg0) {
232
+ const ret = arg0 === undefined;
233
+ return ret;
234
+ },
235
+ __wbg___wbindgen_string_get_b0ca35b86a603356: function(arg0, arg1) {
236
+ const obj = arg1;
237
+ const ret = typeof(obj) === 'string' ? obj : undefined;
238
+ var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
239
+ var len1 = WASM_VECTOR_LEN;
240
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
241
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
242
+ },
243
+ __wbg___wbindgen_throw_344f42d3211c4765: function(arg0, arg1) {
244
+ throw new Error(getStringFromWasm0(arg0, arg1));
245
+ },
246
+ __wbg__wbg_cb_unref_fffb441def202758: function(arg0) {
247
+ arg0._wbg_cb_unref();
248
+ },
249
+ __wbg_call_a6e5c5dce5018821: function() { return handleError(function (arg0, arg1, arg2) {
250
+ const ret = arg0.call(arg1, arg2);
251
+ return ret;
252
+ }, arguments); },
253
+ __wbg_close_b36455f162d504cf: function(arg0) {
254
+ globalThis.nanocodexHost.close(arg0 >>> 0);
255
+ },
256
+ __wbg_connect_82a82e999c6dad2f: function() { return handleError(function (arg0, arg1, arg2, arg3, arg4, arg5) {
257
+ const ret = globalThis.nanocodexHost.connect(getStringFromWasm0(arg0, arg1), getStringFromWasm0(arg2, arg3), getStringFromWasm0(arg4, arg5));
258
+ return ret;
259
+ }, arguments); },
260
+ __wbg_emitEvent_fe69df479c60b4dc: function(arg0, arg1) {
261
+ globalThis.nanocodexHost.emitEvent(getStringFromWasm0(arg0, arg1));
262
+ },
263
+ __wbg_executeCode_1b0871b5adb65342: function() { return handleError(function (arg0, arg1, arg2, arg3, arg4, arg5) {
264
+ const ret = globalThis.nanocodexHost.executeCode(getStringFromWasm0(arg0, arg1), getStringFromWasm0(arg2, arg3), getStringFromWasm0(arg4, arg5));
265
+ return ret;
266
+ }, arguments); },
267
+ __wbg_getDate_a1a40c1c5f40fe3b: function(arg0) {
268
+ const ret = arg0.getDate();
269
+ return ret;
270
+ },
271
+ __wbg_getFullYear_6af8b229792ae254: function(arg0) {
272
+ const ret = arg0.getFullYear();
273
+ return ret;
274
+ },
275
+ __wbg_getMonth_fffe29d654d5eb69: function(arg0) {
276
+ const ret = arg0.getMonth();
277
+ return ret;
278
+ },
279
+ __wbg_get_78f252d074a84d0b: function() { return handleError(function (arg0, arg1) {
280
+ const ret = Reflect.get(arg0, arg1);
281
+ return ret;
282
+ }, arguments); },
283
+ __wbg_nanocodex_new: function(arg0) {
284
+ const ret = Nanocodex.__wrap(arg0);
285
+ return ret;
286
+ },
287
+ __wbg_new_0_3da9e97f24fc69be: function() {
288
+ const ret = new Date();
289
+ return ret;
290
+ },
291
+ __wbg_new_32b398fb48b6d94a: function() {
292
+ const ret = new Array();
293
+ return ret;
294
+ },
295
+ __wbg_new_b667d279fd5aa943: function(arg0, arg1) {
296
+ const ret = new Error(getStringFromWasm0(arg0, arg1));
297
+ return ret;
298
+ },
299
+ __wbg_new_cbb95886ce0eb0cb: function(arg0, arg1) {
300
+ const ret = new Intl.DateTimeFormat(arg0, arg1);
301
+ return ret;
302
+ },
303
+ __wbg_new_da52cf8fe3429cb2: function() {
304
+ const ret = new Object();
305
+ return ret;
306
+ },
307
+ __wbg_new_typed_1824d93f294193e5: function(arg0, arg1) {
308
+ try {
309
+ var state0 = {a: arg0, b: arg1};
310
+ var cb0 = (arg0, arg1) => {
311
+ const a = state0.a;
312
+ state0.a = 0;
313
+ try {
314
+ return wasm_bindgen__convert__closures_____invoke__h179cb8eb2e8755ae(a, state0.b, arg0, arg1);
315
+ } finally {
316
+ state0.a = a;
317
+ }
318
+ };
319
+ const ret = new Promise(cb0);
320
+ return ret;
321
+ } finally {
322
+ state0.a = 0;
323
+ }
324
+ },
325
+ __wbg_next_9da746b48109347a: function() { return handleError(function (arg0, arg1) {
326
+ const ret = globalThis.nanocodexHost.next(arg0 >>> 0, arg1 >>> 0);
327
+ return ret;
328
+ }, arguments); },
329
+ __wbg_now_86c0d4ba3fa605b8: function() {
330
+ const ret = Date.now();
331
+ return ret;
332
+ },
333
+ __wbg_now_e7c6795a7f81e10f: function(arg0) {
334
+ const ret = arg0.now();
335
+ return ret;
336
+ },
337
+ __wbg_performance_3fcf6e32a7e1ed0a: function(arg0) {
338
+ const ret = arg0.performance;
339
+ return ret;
340
+ },
341
+ __wbg_queueMicrotask_0ab5b2d2393e99b9: function(arg0) {
342
+ const ret = arg0.queueMicrotask;
343
+ return ret;
344
+ },
345
+ __wbg_queueMicrotask_6a09b7bc46549209: function(arg0) {
346
+ queueMicrotask(arg0);
347
+ },
348
+ __wbg_resolve_2191a4dfe481c25b: function(arg0) {
349
+ const ret = Promise.resolve(arg0);
350
+ return ret;
351
+ },
352
+ __wbg_resolvedOptions_ce0ede387898d6bd: function(arg0) {
353
+ const ret = arg0.resolvedOptions();
354
+ return ret;
355
+ },
356
+ __wbg_send_211e498fb0677de2: function() { return handleError(function (arg0, arg1, arg2) {
357
+ const ret = globalThis.nanocodexHost.send(arg0 >>> 0, getStringFromWasm0(arg1, arg2));
358
+ return ret;
359
+ }, arguments); },
360
+ __wbg_sleep_03cdb40ace612b9f: function(arg0) {
361
+ const ret = globalThis.nanocodexHost.sleep(arg0 >>> 0);
362
+ return ret;
363
+ },
364
+ __wbg_static_accessor_GLOBAL_4ef717fb391d88b7: function() {
365
+ const ret = typeof global === 'undefined' ? null : global;
366
+ return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
367
+ },
368
+ __wbg_static_accessor_GLOBAL_THIS_8d1badc68b5a74f4: function() {
369
+ const ret = typeof globalThis === 'undefined' ? null : globalThis;
370
+ return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
371
+ },
372
+ __wbg_static_accessor_SELF_146583524fe1469b: function() {
373
+ const ret = typeof self === 'undefined' ? null : self;
374
+ return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
375
+ },
376
+ __wbg_static_accessor_WINDOW_f2829a2234d7819e: function() {
377
+ const ret = typeof window === 'undefined' ? null : window;
378
+ return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
379
+ },
380
+ __wbg_then_16d107c451e9905d: function(arg0, arg1, arg2) {
381
+ const ret = arg0.then(arg1, arg2);
382
+ return ret;
383
+ },
384
+ __wbg_then_6ec10ae38b3e92f7: function(arg0, arg1) {
385
+ const ret = arg0.then(arg1);
386
+ return ret;
387
+ },
388
+ __wbg_toolDefinitions_976a998d8a17c04c: function(arg0, arg1, arg2) {
389
+ const ret = globalThis.nanocodexHost.toolDefinitions(getStringFromWasm0(arg1, arg2));
390
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
391
+ const len1 = WASM_VECTOR_LEN;
392
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
393
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
394
+ },
395
+ __wbindgen_cast_0000000000000001: function(arg0, arg1) {
396
+ // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx: 57, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`.
397
+ const ret = makeMutClosure(arg0, arg1, wasm_bindgen__convert__closures_____invoke__h02eb5eea4c10a535);
398
+ return ret;
399
+ },
400
+ __wbindgen_cast_0000000000000002: function(arg0, arg1) {
401
+ // Cast intrinsic for `Ref(String) -> Externref`.
402
+ const ret = getStringFromWasm0(arg0, arg1);
403
+ return ret;
404
+ },
405
+ __wbindgen_init_externref_table: function() {
406
+ const table = wasm.__wbindgen_externrefs;
407
+ const offset = table.grow(4);
408
+ table.set(0, undefined);
409
+ table.set(offset + 0, undefined);
410
+ table.set(offset + 1, null);
411
+ table.set(offset + 2, true);
412
+ table.set(offset + 3, false);
413
+ },
414
+ };
415
+ return {
416
+ __proto__: null,
417
+ "./nanocodex_bg.js": import0,
418
+ };
419
+ }
420
+
421
+ function wasm_bindgen__convert__closures_____invoke__h02eb5eea4c10a535(arg0, arg1, arg2) {
422
+ const ret = wasm.wasm_bindgen__convert__closures_____invoke__h02eb5eea4c10a535(arg0, arg1, arg2);
423
+ if (ret[1]) {
424
+ throw takeFromExternrefTable0(ret[0]);
425
+ }
426
+ }
427
+
428
+ function wasm_bindgen__convert__closures_____invoke__h179cb8eb2e8755ae(arg0, arg1, arg2, arg3) {
429
+ wasm.wasm_bindgen__convert__closures_____invoke__h179cb8eb2e8755ae(arg0, arg1, arg2, arg3);
430
+ }
431
+
432
+ const NanocodexFinalization = (typeof FinalizationRegistry === 'undefined')
433
+ ? { register: () => {}, unregister: () => {} }
434
+ : new FinalizationRegistry(ptr => wasm.__wbg_nanocodex_free(ptr, 1));
435
+ const TurnFinalization = (typeof FinalizationRegistry === 'undefined')
436
+ ? { register: () => {}, unregister: () => {} }
437
+ : new FinalizationRegistry(ptr => wasm.__wbg_turn_free(ptr, 1));
438
+
439
+ function addToExternrefTable0(obj) {
440
+ const idx = wasm.__externref_table_alloc();
441
+ wasm.__wbindgen_externrefs.set(idx, obj);
442
+ return idx;
443
+ }
444
+
445
+ function _assertClass(instance, klass) {
446
+ if (!(instance instanceof klass)) {
447
+ throw new Error(`expected instance of ${klass.name}`);
448
+ }
449
+ }
450
+
451
+ const CLOSURE_DTORS = (typeof FinalizationRegistry === 'undefined')
452
+ ? { register: () => {}, unregister: () => {} }
453
+ : new FinalizationRegistry(state => wasm.__wbindgen_destroy_closure(state.a, state.b));
454
+
455
+ function debugString(val) {
456
+ // primitive types
457
+ const type = typeof val;
458
+ if (type == 'number' || type == 'boolean' || val == null) {
459
+ return `${val}`;
460
+ }
461
+ if (type == 'string') {
462
+ return `"${val}"`;
463
+ }
464
+ if (type == 'symbol') {
465
+ const description = val.description;
466
+ if (description == null) {
467
+ return 'Symbol';
468
+ } else {
469
+ return `Symbol(${description})`;
470
+ }
471
+ }
472
+ if (type == 'function') {
473
+ const name = val.name;
474
+ if (typeof name == 'string' && name.length > 0) {
475
+ return `Function(${name})`;
476
+ } else {
477
+ return 'Function';
478
+ }
479
+ }
480
+ // objects
481
+ if (Array.isArray(val)) {
482
+ const length = val.length;
483
+ let debug = '[';
484
+ if (length > 0) {
485
+ debug += debugString(val[0]);
486
+ }
487
+ for(let i = 1; i < length; i++) {
488
+ debug += ', ' + debugString(val[i]);
489
+ }
490
+ debug += ']';
491
+ return debug;
492
+ }
493
+ // Test for built-in
494
+ const builtInMatches = /\[object ([^\]]+)\]/.exec(toString.call(val));
495
+ let className;
496
+ if (builtInMatches && builtInMatches.length > 1) {
497
+ className = builtInMatches[1];
498
+ } else {
499
+ // Failed to match the standard '[object ClassName]'
500
+ return toString.call(val);
501
+ }
502
+ if (className == 'Object') {
503
+ // we're a user defined class or Object
504
+ // JSON.stringify avoids problems with cycles, and is generally much
505
+ // easier than looping through ownProperties of `val`.
506
+ try {
507
+ return 'Object(' + JSON.stringify(val) + ')';
508
+ } catch (_) {
509
+ return 'Object';
510
+ }
511
+ }
512
+ // errors
513
+ if (val instanceof Error) {
514
+ return `${val.name}: ${val.message}\n${val.stack}`;
515
+ }
516
+ // TODO we could test for more things here, like `Set`s and `Map`s.
517
+ return className;
518
+ }
519
+
520
+ let cachedDataViewMemory0 = null;
521
+ function getDataViewMemory0() {
522
+ if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
523
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
524
+ }
525
+ return cachedDataViewMemory0;
526
+ }
527
+
528
+ function getStringFromWasm0(ptr, len) {
529
+ return decodeText(ptr >>> 0, len);
530
+ }
531
+
532
+ let cachedUint8ArrayMemory0 = null;
533
+ function getUint8ArrayMemory0() {
534
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
535
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
536
+ }
537
+ return cachedUint8ArrayMemory0;
538
+ }
539
+
540
+ function handleError(f, args) {
541
+ try {
542
+ return f.apply(this, args);
543
+ } catch (e) {
544
+ const idx = addToExternrefTable0(e);
545
+ wasm.__wbindgen_exn_store(idx);
546
+ }
547
+ }
548
+
549
+ function isLikeNone(x) {
550
+ return x === undefined || x === null;
551
+ }
552
+
553
+ function makeMutClosure(arg0, arg1, f) {
554
+ const state = { a: arg0, b: arg1, cnt: 1 };
555
+ const real = (...args) => {
556
+
557
+ // First up with a closure we increment the internal reference
558
+ // count. This ensures that the Rust closure environment won't
559
+ // be deallocated while we're invoking it.
560
+ state.cnt++;
561
+ const a = state.a;
562
+ state.a = 0;
563
+ try {
564
+ return f(a, state.b, ...args);
565
+ } finally {
566
+ state.a = a;
567
+ real._wbg_cb_unref();
568
+ }
569
+ };
570
+ real._wbg_cb_unref = () => {
571
+ if (--state.cnt === 0) {
572
+ wasm.__wbindgen_destroy_closure(state.a, state.b);
573
+ state.a = 0;
574
+ CLOSURE_DTORS.unregister(state);
575
+ }
576
+ };
577
+ CLOSURE_DTORS.register(real, state, state);
578
+ return real;
579
+ }
580
+
581
+ function passStringToWasm0(arg, malloc, realloc) {
582
+ if (realloc === undefined) {
583
+ const buf = cachedTextEncoder.encode(arg);
584
+ const ptr = malloc(buf.length, 1) >>> 0;
585
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
586
+ WASM_VECTOR_LEN = buf.length;
587
+ return ptr;
588
+ }
589
+
590
+ let len = arg.length;
591
+ let ptr = malloc(len, 1) >>> 0;
592
+
593
+ const mem = getUint8ArrayMemory0();
594
+
595
+ let offset = 0;
596
+
597
+ for (; offset < len; offset++) {
598
+ const code = arg.charCodeAt(offset);
599
+ if (code > 0x7F) break;
600
+ mem[ptr + offset] = code;
601
+ }
602
+ if (offset !== len) {
603
+ if (offset !== 0) {
604
+ arg = arg.slice(offset);
605
+ }
606
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
607
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
608
+ const ret = cachedTextEncoder.encodeInto(arg, view);
609
+
610
+ offset += ret.written;
611
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
612
+ }
613
+
614
+ WASM_VECTOR_LEN = offset;
615
+ return ptr;
616
+ }
617
+
618
+ function takeFromExternrefTable0(idx) {
619
+ const value = wasm.__wbindgen_externrefs.get(idx);
620
+ wasm.__externref_table_dealloc(idx);
621
+ return value;
622
+ }
623
+
624
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
625
+ cachedTextDecoder.decode();
626
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
627
+ let numBytesDecoded = 0;
628
+ function decodeText(ptr, len) {
629
+ numBytesDecoded += len;
630
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
631
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
632
+ cachedTextDecoder.decode();
633
+ numBytesDecoded = len;
634
+ }
635
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
636
+ }
637
+
638
+ const cachedTextEncoder = new TextEncoder();
639
+
640
+ if (!('encodeInto' in cachedTextEncoder)) {
641
+ cachedTextEncoder.encodeInto = function (arg, view) {
642
+ const buf = cachedTextEncoder.encode(arg);
643
+ view.set(buf);
644
+ return {
645
+ read: arg.length,
646
+ written: buf.length
647
+ };
648
+ };
649
+ }
650
+
651
+ let WASM_VECTOR_LEN = 0;
652
+
653
+ let wasmModule, wasmInstance, wasm;
654
+ function __wbg_finalize_init(instance, module) {
655
+ wasmInstance = instance;
656
+ wasm = instance.exports;
657
+ wasmModule = module;
658
+ cachedDataViewMemory0 = null;
659
+ cachedUint8ArrayMemory0 = null;
660
+ wasm.__wbindgen_start();
661
+ return wasm;
662
+ }
663
+
664
+ async function __wbg_load(module, imports) {
665
+ if (typeof Response === 'function' && module instanceof Response) {
666
+ if (typeof WebAssembly.instantiateStreaming === 'function') {
667
+ try {
668
+ return await WebAssembly.instantiateStreaming(module, imports);
669
+ } catch (e) {
670
+ const validResponse = module.ok && expectedResponseType(module.type);
671
+
672
+ if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
673
+ console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
674
+
675
+ } else { throw e; }
676
+ }
677
+ }
678
+
679
+ const bytes = await module.arrayBuffer();
680
+ return await WebAssembly.instantiate(bytes, imports);
681
+ } else {
682
+ const instance = await WebAssembly.instantiate(module, imports);
683
+
684
+ if (instance instanceof WebAssembly.Instance) {
685
+ return { instance, module };
686
+ } else {
687
+ return instance;
688
+ }
689
+ }
690
+
691
+ function expectedResponseType(type) {
692
+ switch (type) {
693
+ case 'basic': case 'cors': case 'default': return true;
694
+ }
695
+ return false;
696
+ }
697
+ }
698
+
699
+ function initSync(module) {
700
+ if (wasm !== undefined) return wasm;
701
+
702
+
703
+ if (module !== undefined) {
704
+ if (Object.getPrototypeOf(module) === Object.prototype) {
705
+ ({module} = module)
706
+ } else {
707
+ console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
708
+ }
709
+ }
710
+
711
+ const imports = __wbg_get_imports();
712
+ if (!(module instanceof WebAssembly.Module)) {
713
+ module = new WebAssembly.Module(module);
714
+ }
715
+ const instance = new WebAssembly.Instance(module, imports);
716
+ return __wbg_finalize_init(instance, module);
717
+ }
718
+
719
+ async function __wbg_init(module_or_path) {
720
+ if (wasm !== undefined) return wasm;
721
+
722
+
723
+ if (module_or_path !== undefined) {
724
+ if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
725
+ ({module_or_path} = module_or_path)
726
+ } else {
727
+ console.warn('using deprecated parameters for the initialization function; pass a single object instead')
728
+ }
729
+ }
730
+
731
+ if (module_or_path === undefined) {
732
+ module_or_path = new URL('nanocodex_bg.wasm', import.meta.url);
733
+ }
734
+ const imports = __wbg_get_imports();
735
+
736
+ if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
737
+ module_or_path = fetch(module_or_path);
738
+ }
739
+
740
+ const { instance, module } = await __wbg_load(await module_or_path, imports);
741
+
742
+ return __wbg_finalize_init(instance, module);
743
+ }
744
+
745
+ export { initSync, __wbg_init as default };