kjarni-wasm 0.1.4

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,1602 @@
1
+ /* @ts-self-types="./kjarni_wasm.d.ts" */
2
+
3
+ /**
4
+ * A local language model running in the browser.
5
+ *
6
+ * Text generation is synchronous here, and deliberately so. The engine's streaming
7
+ * path builds a background task with `tokio::task::spawn_blocking`, and wasm has no
8
+ * blocking pool for that to run on — it compiles but would fail at runtime. Calling
9
+ * the generation loop directly and draining the channel afterwards avoids the
10
+ * problem entirely.
11
+ *
12
+ * The cost is that a call blocks until the whole response is ready, which for a few
13
+ * hundred tokens is seconds, not milliseconds. Run it in a Web Worker; on the main
14
+ * thread it will freeze the tab.
15
+ */
16
+ export class WasmChat {
17
+ static __wrap(ptr) {
18
+ const obj = Object.create(WasmChat.prototype);
19
+ obj.__wbg_ptr = ptr;
20
+ WasmChatFinalization.register(obj, obj.__wbg_ptr, obj);
21
+ return obj;
22
+ }
23
+ __destroy_into_raw() {
24
+ const ptr = this.__wbg_ptr;
25
+ this.__wbg_ptr = 0;
26
+ WasmChatFinalization.unregister(this);
27
+ return ptr;
28
+ }
29
+ free() {
30
+ const ptr = this.__destroy_into_raw();
31
+ wasm.__wbg_wasmchat_free(ptr, 0);
32
+ }
33
+ /**
34
+ * The model's context window, in tokens.
35
+ * @returns {number}
36
+ */
37
+ context_size() {
38
+ const ret = wasm.wasmchat_context_size(this.__wbg_ptr);
39
+ return ret >>> 0;
40
+ }
41
+ /**
42
+ * Generate a completion for `prompt`.
43
+ * @param {string} prompt
44
+ * @param {number} max_new_tokens
45
+ * @param {number} temperature
46
+ * @returns {string}
47
+ */
48
+ generate(prompt, max_new_tokens, temperature) {
49
+ let deferred3_0;
50
+ let deferred3_1;
51
+ try {
52
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
53
+ const ptr0 = passStringToWasm0(prompt, wasm.__wbindgen_export, wasm.__wbindgen_export2);
54
+ const len0 = WASM_VECTOR_LEN;
55
+ wasm.wasmchat_generate(retptr, this.__wbg_ptr, ptr0, len0, max_new_tokens, temperature);
56
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
57
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
58
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
59
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
60
+ var ptr2 = r0;
61
+ var len2 = r1;
62
+ if (r3) {
63
+ ptr2 = 0; len2 = 0;
64
+ throw takeObject(r2);
65
+ }
66
+ deferred3_0 = ptr2;
67
+ deferred3_1 = len2;
68
+ return getStringFromWasm0(ptr2, len2);
69
+ } finally {
70
+ wasm.__wbindgen_add_to_stack_pointer(16);
71
+ wasm.__wbindgen_export4(deferred3_0, deferred3_1, 1);
72
+ }
73
+ }
74
+ /**
75
+ * Generate a completion, invoking `on_token` with each piece as it arrives.
76
+ *
77
+ * The callback runs on whichever thread called this, synchronously between
78
+ * decoding steps. On the main thread that still blocks the page, so this is
79
+ * meant to be driven from a Web Worker; the `kjarni-wasm` npm wrapper does
80
+ * exactly that and turns it into an async iterator.
81
+ *
82
+ * Returning `false` from the callback does not stop generation yet; the
83
+ * value is ignored.
84
+ *
85
+ * Browser-only: `js_sys::Function` has no native equivalent. The streaming
86
+ * itself is in `generate_stream_core`, which builds and is tested natively.
87
+ * @param {string} prompt
88
+ * @param {number} max_new_tokens
89
+ * @param {number} temperature
90
+ * @param {Function} on_token
91
+ * @returns {string}
92
+ */
93
+ generate_stream(prompt, max_new_tokens, temperature, on_token) {
94
+ let deferred3_0;
95
+ let deferred3_1;
96
+ try {
97
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
98
+ const ptr0 = passStringToWasm0(prompt, wasm.__wbindgen_export, wasm.__wbindgen_export2);
99
+ const len0 = WASM_VECTOR_LEN;
100
+ wasm.wasmchat_generate_stream(retptr, this.__wbg_ptr, ptr0, len0, max_new_tokens, temperature, addBorrowedObject(on_token));
101
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
102
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
103
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
104
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
105
+ var ptr2 = r0;
106
+ var len2 = r1;
107
+ if (r3) {
108
+ ptr2 = 0; len2 = 0;
109
+ throw takeObject(r2);
110
+ }
111
+ deferred3_0 = ptr2;
112
+ deferred3_1 = len2;
113
+ return getStringFromWasm0(ptr2, len2);
114
+ } finally {
115
+ wasm.__wbindgen_add_to_stack_pointer(16);
116
+ heap[stack_pointer++] = undefined;
117
+ wasm.__wbindgen_export4(deferred3_0, deferred3_1, 1);
118
+ }
119
+ }
120
+ /**
121
+ * Load a decoder model from a `.kjq` container.
122
+ *
123
+ * `model_id` selects the chat template, e.g. `qwen2.5-0.5b-instruct`. Without
124
+ * one the model still generates, but its turn markers will not be applied.
125
+ * @param {Uint8Array} data
126
+ * @param {string | null} [model_id]
127
+ * @returns {WasmChat}
128
+ */
129
+ static load(data, model_id) {
130
+ try {
131
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
132
+ const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_export);
133
+ const len0 = WASM_VECTOR_LEN;
134
+ var ptr1 = isLikeNone(model_id) ? 0 : passStringToWasm0(model_id, wasm.__wbindgen_export, wasm.__wbindgen_export2);
135
+ var len1 = WASM_VECTOR_LEN;
136
+ wasm.wasmchat_load(retptr, ptr0, len0, ptr1, len1);
137
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
138
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
139
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
140
+ if (r2) {
141
+ throw takeObject(r1);
142
+ }
143
+ return WasmChat.__wrap(r0);
144
+ } finally {
145
+ wasm.__wbindgen_add_to_stack_pointer(16);
146
+ }
147
+ }
148
+ }
149
+ if (Symbol.dispose) WasmChat.prototype[Symbol.dispose] = WasmChat.prototype.free;
150
+
151
+ /**
152
+ * Sequence classification: sentiment, emotion, toxicity.
153
+ *
154
+ * New to the browser. Classification was always in the engine but never had a
155
+ * binding here, because this crate previously carried its own encoder and nobody
156
+ * wrote a second classifier head for it.
157
+ */
158
+ export class WasmClassifier {
159
+ static __wrap(ptr) {
160
+ const obj = Object.create(WasmClassifier.prototype);
161
+ obj.__wbg_ptr = ptr;
162
+ WasmClassifierFinalization.register(obj, obj.__wbg_ptr, obj);
163
+ return obj;
164
+ }
165
+ __destroy_into_raw() {
166
+ const ptr = this.__wbg_ptr;
167
+ this.__wbg_ptr = 0;
168
+ WasmClassifierFinalization.unregister(this);
169
+ return ptr;
170
+ }
171
+ free() {
172
+ const ptr = this.__destroy_into_raw();
173
+ wasm.__wbg_wasmclassifier_free(ptr, 0);
174
+ }
175
+ /**
176
+ * Classify one text, returning every label with its score, highest first.
177
+ *
178
+ * Serializing to a `JsValue` panics outside wasm32, so the work lives in
179
+ * [`WasmClassifier::classify_core`] and this is only the conversion. That is
180
+ * what makes the behaviour testable on the host.
181
+ * @param {string} text
182
+ * @returns {any}
183
+ */
184
+ classify(text) {
185
+ try {
186
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
187
+ const ptr0 = passStringToWasm0(text, wasm.__wbindgen_export, wasm.__wbindgen_export2);
188
+ const len0 = WASM_VECTOR_LEN;
189
+ wasm.wasmclassifier_classify(retptr, this.__wbg_ptr, ptr0, len0);
190
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
191
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
192
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
193
+ if (r2) {
194
+ throw takeObject(r1);
195
+ }
196
+ return takeObject(r0);
197
+ } finally {
198
+ wasm.__wbindgen_add_to_stack_pointer(16);
199
+ }
200
+ }
201
+ /**
202
+ * Classify a batch, returning the single best label for each input.
203
+ *
204
+ * One result per input, in input order, so the caller can line them up with
205
+ * whatever it passed in.
206
+ * @param {string[]} texts
207
+ * @returns {any}
208
+ */
209
+ classify_batch(texts) {
210
+ try {
211
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
212
+ const ptr0 = passArrayJsValueToWasm0(texts, wasm.__wbindgen_export);
213
+ const len0 = WASM_VECTOR_LEN;
214
+ wasm.wasmclassifier_classify_batch(retptr, this.__wbg_ptr, ptr0, len0);
215
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
216
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
217
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
218
+ if (r2) {
219
+ throw takeObject(r1);
220
+ }
221
+ return takeObject(r0);
222
+ } finally {
223
+ wasm.__wbindgen_add_to_stack_pointer(16);
224
+ }
225
+ }
226
+ /**
227
+ * The labels this model predicts, in index order.
228
+ * @returns {string[]}
229
+ */
230
+ labels() {
231
+ try {
232
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
233
+ wasm.wasmclassifier_labels(retptr, this.__wbg_ptr);
234
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
235
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
236
+ var v1 = getArrayJsValueFromWasm0(r0, r1);
237
+ wasm.__wbindgen_export4(r0, r1 * 4, 4);
238
+ return v1;
239
+ } finally {
240
+ wasm.__wbindgen_add_to_stack_pointer(16);
241
+ }
242
+ }
243
+ /**
244
+ * Load a classifier from a `.kjq` container.
245
+ * @param {Uint8Array} data
246
+ * @returns {WasmClassifier}
247
+ */
248
+ static load(data) {
249
+ try {
250
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
251
+ const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_export);
252
+ const len0 = WASM_VECTOR_LEN;
253
+ wasm.wasmclassifier_load(retptr, ptr0, len0);
254
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
255
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
256
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
257
+ if (r2) {
258
+ throw takeObject(r1);
259
+ }
260
+ return WasmClassifier.__wrap(r0);
261
+ } finally {
262
+ wasm.__wbindgen_add_to_stack_pointer(16);
263
+ }
264
+ }
265
+ /**
266
+ * How many labels the model predicts.
267
+ * @returns {number}
268
+ */
269
+ num_labels() {
270
+ const ret = wasm.wasmclassifier_num_labels(this.__wbg_ptr);
271
+ return ret >>> 0;
272
+ }
273
+ }
274
+ if (Symbol.dispose) WasmClassifier.prototype[Symbol.dispose] = WasmClassifier.prototype.free;
275
+
276
+ export class WasmEncoder {
277
+ static __wrap(ptr) {
278
+ const obj = Object.create(WasmEncoder.prototype);
279
+ obj.__wbg_ptr = ptr;
280
+ WasmEncoderFinalization.register(obj, obj.__wbg_ptr, obj);
281
+ return obj;
282
+ }
283
+ __destroy_into_raw() {
284
+ const ptr = this.__wbg_ptr;
285
+ this.__wbg_ptr = 0;
286
+ WasmEncoderFinalization.unregister(this);
287
+ return ptr;
288
+ }
289
+ free() {
290
+ const ptr = this.__destroy_into_raw();
291
+ wasm.__wbg_wasmencoder_free(ptr, 0);
292
+ }
293
+ /**
294
+ * @param {string} text
295
+ * @param {string} source_path
296
+ * @returns {any}
297
+ */
298
+ encode_file(text, source_path) {
299
+ try {
300
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
301
+ const ptr0 = passStringToWasm0(text, wasm.__wbindgen_export, wasm.__wbindgen_export2);
302
+ const len0 = WASM_VECTOR_LEN;
303
+ const ptr1 = passStringToWasm0(source_path, wasm.__wbindgen_export, wasm.__wbindgen_export2);
304
+ const len1 = WASM_VECTOR_LEN;
305
+ wasm.wasmencoder_encode_file(retptr, this.__wbg_ptr, ptr0, len0, ptr1, len1);
306
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
307
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
308
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
309
+ if (r2) {
310
+ throw takeObject(r1);
311
+ }
312
+ return takeObject(r0);
313
+ } finally {
314
+ wasm.__wbindgen_add_to_stack_pointer(16);
315
+ }
316
+ }
317
+ /**
318
+ * @param {Uint8Array} model_data
319
+ * @returns {WasmEncoder}
320
+ */
321
+ static new(model_data) {
322
+ try {
323
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
324
+ const ptr0 = passArray8ToWasm0(model_data, wasm.__wbindgen_export);
325
+ const len0 = WASM_VECTOR_LEN;
326
+ wasm.wasmencoder_new(retptr, ptr0, len0);
327
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
328
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
329
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
330
+ if (r2) {
331
+ throw takeObject(r1);
332
+ }
333
+ return WasmEncoder.__wrap(r0);
334
+ } finally {
335
+ wasm.__wbindgen_add_to_stack_pointer(16);
336
+ }
337
+ }
338
+ }
339
+ if (Symbol.dispose) WasmEncoder.prototype[Symbol.dispose] = WasmEncoder.prototype.free;
340
+
341
+ export class WasmIndexBuilder {
342
+ static __wrap(ptr) {
343
+ const obj = Object.create(WasmIndexBuilder.prototype);
344
+ obj.__wbg_ptr = ptr;
345
+ WasmIndexBuilderFinalization.register(obj, obj.__wbg_ptr, obj);
346
+ return obj;
347
+ }
348
+ __destroy_into_raw() {
349
+ const ptr = this.__wbg_ptr;
350
+ this.__wbg_ptr = 0;
351
+ WasmIndexBuilderFinalization.unregister(this);
352
+ return ptr;
353
+ }
354
+ free() {
355
+ const ptr = this.__destroy_into_raw();
356
+ wasm.__wbg_wasmindexbuilder_free(ptr, 0);
357
+ }
358
+ /**
359
+ * @param {string} text
360
+ * @param {Float32Array} embedding
361
+ * @param {string} source
362
+ * @param {number} chunk_index
363
+ */
364
+ add_chunk(text, embedding, source, chunk_index) {
365
+ try {
366
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
367
+ const ptr0 = passStringToWasm0(text, wasm.__wbindgen_export, wasm.__wbindgen_export2);
368
+ const len0 = WASM_VECTOR_LEN;
369
+ const ptr1 = passArrayF32ToWasm0(embedding, wasm.__wbindgen_export);
370
+ const len1 = WASM_VECTOR_LEN;
371
+ const ptr2 = passStringToWasm0(source, wasm.__wbindgen_export, wasm.__wbindgen_export2);
372
+ const len2 = WASM_VECTOR_LEN;
373
+ wasm.wasmindexbuilder_add_chunk(retptr, this.__wbg_ptr, ptr0, len0, ptr1, len1, ptr2, len2, chunk_index);
374
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
375
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
376
+ if (r1) {
377
+ throw takeObject(r0);
378
+ }
379
+ } finally {
380
+ wasm.__wbindgen_add_to_stack_pointer(16);
381
+ }
382
+ }
383
+ /**
384
+ * @param {string} text
385
+ * @param {string} source_path
386
+ * @returns {number}
387
+ */
388
+ add_file(text, source_path) {
389
+ try {
390
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
391
+ const ptr0 = passStringToWasm0(text, wasm.__wbindgen_export, wasm.__wbindgen_export2);
392
+ const len0 = WASM_VECTOR_LEN;
393
+ const ptr1 = passStringToWasm0(source_path, wasm.__wbindgen_export, wasm.__wbindgen_export2);
394
+ const len1 = WASM_VECTOR_LEN;
395
+ wasm.wasmindexbuilder_add_file(retptr, this.__wbg_ptr, ptr0, len0, ptr1, len1);
396
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
397
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
398
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
399
+ if (r2) {
400
+ throw takeObject(r1);
401
+ }
402
+ return r0 >>> 0;
403
+ } finally {
404
+ wasm.__wbindgen_add_to_stack_pointer(16);
405
+ }
406
+ }
407
+ /**
408
+ * @returns {number}
409
+ */
410
+ doc_count() {
411
+ const ret = wasm.wasmindexbuilder_doc_count(this.__wbg_ptr);
412
+ return ret >>> 0;
413
+ }
414
+ /**
415
+ * @returns {Uint8Array}
416
+ */
417
+ finish() {
418
+ try {
419
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
420
+ wasm.wasmindexbuilder_finish(retptr, this.__wbg_ptr);
421
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
422
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
423
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
424
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
425
+ if (r3) {
426
+ throw takeObject(r2);
427
+ }
428
+ var v1 = getArrayU8FromWasm0(r0, r1).slice();
429
+ wasm.__wbindgen_export4(r0, r1 * 1, 1);
430
+ return v1;
431
+ } finally {
432
+ wasm.__wbindgen_add_to_stack_pointer(16);
433
+ }
434
+ }
435
+ /**
436
+ * @param {Uint8Array} model_data
437
+ * @returns {WasmIndexBuilder}
438
+ */
439
+ static new(model_data) {
440
+ try {
441
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
442
+ const ptr0 = passArray8ToWasm0(model_data, wasm.__wbindgen_export);
443
+ const len0 = WASM_VECTOR_LEN;
444
+ wasm.wasmindexbuilder_new(retptr, ptr0, len0);
445
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
446
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
447
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
448
+ if (r2) {
449
+ throw takeObject(r1);
450
+ }
451
+ return WasmIndexBuilder.__wrap(r0);
452
+ } finally {
453
+ wasm.__wbindgen_add_to_stack_pointer(16);
454
+ }
455
+ }
456
+ }
457
+ if (Symbol.dispose) WasmIndexBuilder.prototype[Symbol.dispose] = WasmIndexBuilder.prototype.free;
458
+
459
+ export class WasmModel {
460
+ static __wrap(ptr) {
461
+ const obj = Object.create(WasmModel.prototype);
462
+ obj.__wbg_ptr = ptr;
463
+ WasmModelFinalization.register(obj, obj.__wbg_ptr, obj);
464
+ return obj;
465
+ }
466
+ __destroy_into_raw() {
467
+ const ptr = this.__wbg_ptr;
468
+ this.__wbg_ptr = 0;
469
+ WasmModelFinalization.unregister(this);
470
+ return ptr;
471
+ }
472
+ free() {
473
+ const ptr = this.__destroy_into_raw();
474
+ wasm.__wbg_wasmmodel_free(ptr, 0);
475
+ }
476
+ /**
477
+ * Encode a batch, returning every vector concatenated into one flat array.
478
+ *
479
+ * The engine's encode is `async` because the GPU path awaits buffer readback.
480
+ * There is no GPU path here, and the wasm CPU implementation contains no await
481
+ * at all, so the future is always ready on its first poll and `block_on`
482
+ * returns without ever parking the browser's main thread.
483
+ * @param {string[]} texts
484
+ * @param {boolean} normalize
485
+ * @returns {Float32Array}
486
+ */
487
+ encode(texts, normalize) {
488
+ try {
489
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
490
+ const ptr0 = passArrayJsValueToWasm0(texts, wasm.__wbindgen_export);
491
+ const len0 = WASM_VECTOR_LEN;
492
+ wasm.wasmmodel_encode(retptr, this.__wbg_ptr, ptr0, len0, normalize);
493
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
494
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
495
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
496
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
497
+ if (r3) {
498
+ throw takeObject(r2);
499
+ }
500
+ var v2 = getArrayF32FromWasm0(r0, r1).slice();
501
+ wasm.__wbindgen_export4(r0, r1 * 4, 4);
502
+ return v2;
503
+ } finally {
504
+ wasm.__wbindgen_add_to_stack_pointer(16);
505
+ }
506
+ }
507
+ /**
508
+ * Load from a `.kjq` container: config, tokenizer and int8 tensors in one file.
509
+ * @param {Uint8Array} data
510
+ * @returns {WasmModel}
511
+ */
512
+ static from_quantized(data) {
513
+ try {
514
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
515
+ const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_export);
516
+ const len0 = WASM_VECTOR_LEN;
517
+ wasm.wasmmodel_from_quantized(retptr, ptr0, len0);
518
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
519
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
520
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
521
+ if (r2) {
522
+ throw takeObject(r1);
523
+ }
524
+ return WasmModel.__wrap(r0);
525
+ } finally {
526
+ wasm.__wbindgen_add_to_stack_pointer(16);
527
+ }
528
+ }
529
+ /**
530
+ * Fetch a model straight from Hugging Face. Browser-only: it uses `fetch`.
531
+ * @param {WasmModelType} model_type
532
+ * @returns {Promise<WasmModel>}
533
+ */
534
+ static from_type(model_type) {
535
+ const ret = wasm.wasmmodel_from_type(model_type);
536
+ return takeObject(ret);
537
+ }
538
+ /**
539
+ * Load from raw safetensors plus its config and tokenizer.
540
+ * @param {Uint8Array} weights_data
541
+ * @param {string} config_json
542
+ * @param {string} tokenizer_json
543
+ */
544
+ constructor(weights_data, config_json, tokenizer_json) {
545
+ try {
546
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
547
+ const ptr0 = passArray8ToWasm0(weights_data, wasm.__wbindgen_export);
548
+ const len0 = WASM_VECTOR_LEN;
549
+ const ptr1 = passStringToWasm0(config_json, wasm.__wbindgen_export, wasm.__wbindgen_export2);
550
+ const len1 = WASM_VECTOR_LEN;
551
+ const ptr2 = passStringToWasm0(tokenizer_json, wasm.__wbindgen_export, wasm.__wbindgen_export2);
552
+ const len2 = WASM_VECTOR_LEN;
553
+ wasm.wasmmodel_new(retptr, ptr0, len0, ptr1, len1, ptr2, len2);
554
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
555
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
556
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
557
+ if (r2) {
558
+ throw takeObject(r1);
559
+ }
560
+ this.__wbg_ptr = r0;
561
+ WasmModelFinalization.register(this, this.__wbg_ptr, this);
562
+ return this;
563
+ } finally {
564
+ wasm.__wbindgen_add_to_stack_pointer(16);
565
+ }
566
+ }
567
+ }
568
+ if (Symbol.dispose) WasmModel.prototype[Symbol.dispose] = WasmModel.prototype.free;
569
+
570
+ /**
571
+ * @enum {0}
572
+ */
573
+ export const WasmModelType = Object.freeze({
574
+ MiniLML6V2: 0, "0": "MiniLML6V2",
575
+ });
576
+
577
+ export class WasmReranker {
578
+ static __wrap(ptr) {
579
+ const obj = Object.create(WasmReranker.prototype);
580
+ obj.__wbg_ptr = ptr;
581
+ WasmRerankerFinalization.register(obj, obj.__wbg_ptr, obj);
582
+ return obj;
583
+ }
584
+ __destroy_into_raw() {
585
+ const ptr = this.__wbg_ptr;
586
+ this.__wbg_ptr = 0;
587
+ WasmRerankerFinalization.unregister(this);
588
+ return ptr;
589
+ }
590
+ free() {
591
+ const ptr = this.__destroy_into_raw();
592
+ wasm.__wbg_wasmreranker_free(ptr, 0);
593
+ }
594
+ /**
595
+ * Load a cross-encoder from a `.kjq` container.
596
+ *
597
+ * The classifier head used to be pulled out of the weights by hand here; the
598
+ * engine's `CrossEncoder` loads it as part of the model.
599
+ * @param {Uint8Array} data
600
+ * @returns {WasmReranker}
601
+ */
602
+ static load(data) {
603
+ try {
604
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
605
+ const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_export);
606
+ const len0 = WASM_VECTOR_LEN;
607
+ wasm.wasmreranker_load(retptr, ptr0, len0);
608
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
609
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
610
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
611
+ if (r2) {
612
+ throw takeObject(r1);
613
+ }
614
+ return WasmReranker.__wrap(r0);
615
+ } finally {
616
+ wasm.__wbindgen_add_to_stack_pointer(16);
617
+ }
618
+ }
619
+ /**
620
+ * Score every document against the query and return the best `limit`,
621
+ * highest first. Scores are raw logits, so negative values are normal.
622
+ * @param {string} query
623
+ * @param {string[]} documents
624
+ * @param {number} limit
625
+ * @returns {any}
626
+ */
627
+ rerank(query, documents, limit) {
628
+ try {
629
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
630
+ const ptr0 = passStringToWasm0(query, wasm.__wbindgen_export, wasm.__wbindgen_export2);
631
+ const len0 = WASM_VECTOR_LEN;
632
+ const ptr1 = passArrayJsValueToWasm0(documents, wasm.__wbindgen_export);
633
+ const len1 = WASM_VECTOR_LEN;
634
+ wasm.wasmreranker_rerank(retptr, this.__wbg_ptr, ptr0, len0, ptr1, len1, limit);
635
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
636
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
637
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
638
+ if (r2) {
639
+ throw takeObject(r1);
640
+ }
641
+ return takeObject(r0);
642
+ } finally {
643
+ wasm.__wbindgen_add_to_stack_pointer(16);
644
+ }
645
+ }
646
+ /**
647
+ * Score a single query-document pair.
648
+ * @param {string} query
649
+ * @param {string} document
650
+ * @returns {number}
651
+ */
652
+ score(query, document) {
653
+ try {
654
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
655
+ const ptr0 = passStringToWasm0(query, wasm.__wbindgen_export, wasm.__wbindgen_export2);
656
+ const len0 = WASM_VECTOR_LEN;
657
+ const ptr1 = passStringToWasm0(document, wasm.__wbindgen_export, wasm.__wbindgen_export2);
658
+ const len1 = WASM_VECTOR_LEN;
659
+ wasm.wasmreranker_score(retptr, this.__wbg_ptr, ptr0, len0, ptr1, len1);
660
+ var r0 = getDataViewMemory0().getFloat32(retptr + 4 * 0, true);
661
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
662
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
663
+ if (r2) {
664
+ throw takeObject(r1);
665
+ }
666
+ return r0;
667
+ } finally {
668
+ wasm.__wbindgen_add_to_stack_pointer(16);
669
+ }
670
+ }
671
+ }
672
+ if (Symbol.dispose) WasmReranker.prototype[Symbol.dispose] = WasmReranker.prototype.free;
673
+
674
+ export class WasmSearch {
675
+ static __wrap(ptr) {
676
+ const obj = Object.create(WasmSearch.prototype);
677
+ obj.__wbg_ptr = ptr;
678
+ WasmSearchFinalization.register(obj, obj.__wbg_ptr, obj);
679
+ return obj;
680
+ }
681
+ __destroy_into_raw() {
682
+ const ptr = this.__wbg_ptr;
683
+ this.__wbg_ptr = 0;
684
+ WasmSearchFinalization.unregister(this);
685
+ return ptr;
686
+ }
687
+ free() {
688
+ const ptr = this.__destroy_into_raw();
689
+ wasm.__wbg_wasmsearch_free(ptr, 0);
690
+ }
691
+ /**
692
+ * @param {string} text
693
+ * @param {Float32Array} embedding
694
+ * @param {string} source
695
+ * @param {number} chunk_index
696
+ */
697
+ add_chunk(text, embedding, source, chunk_index) {
698
+ try {
699
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
700
+ const ptr0 = passStringToWasm0(text, wasm.__wbindgen_export, wasm.__wbindgen_export2);
701
+ const len0 = WASM_VECTOR_LEN;
702
+ const ptr1 = passArrayF32ToWasm0(embedding, wasm.__wbindgen_export);
703
+ const len1 = WASM_VECTOR_LEN;
704
+ const ptr2 = passStringToWasm0(source, wasm.__wbindgen_export, wasm.__wbindgen_export2);
705
+ const len2 = WASM_VECTOR_LEN;
706
+ wasm.wasmsearch_add_chunk(retptr, this.__wbg_ptr, ptr0, len0, ptr1, len1, ptr2, len2, chunk_index);
707
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
708
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
709
+ if (r1) {
710
+ throw takeObject(r0);
711
+ }
712
+ } finally {
713
+ wasm.__wbindgen_add_to_stack_pointer(16);
714
+ }
715
+ }
716
+ /**
717
+ * @returns {number}
718
+ */
719
+ doc_count() {
720
+ const ret = wasm.wasmsearch_doc_count(this.__wbg_ptr);
721
+ return ret >>> 0;
722
+ }
723
+ /**
724
+ * @param {Uint8Array} model_data
725
+ * @param {Uint8Array} index_data
726
+ * @returns {WasmSearch}
727
+ */
728
+ static load(model_data, index_data) {
729
+ try {
730
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
731
+ const ptr0 = passArray8ToWasm0(model_data, wasm.__wbindgen_export);
732
+ const len0 = WASM_VECTOR_LEN;
733
+ const ptr1 = passArray8ToWasm0(index_data, wasm.__wbindgen_export);
734
+ const len1 = WASM_VECTOR_LEN;
735
+ wasm.wasmsearch_load(retptr, ptr0, len0, ptr1, len1);
736
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
737
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
738
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
739
+ if (r2) {
740
+ throw takeObject(r1);
741
+ }
742
+ return WasmSearch.__wrap(r0);
743
+ } finally {
744
+ wasm.__wbindgen_add_to_stack_pointer(16);
745
+ }
746
+ }
747
+ /**
748
+ * @param {string} source_path
749
+ * @returns {number}
750
+ */
751
+ remove_file(source_path) {
752
+ const ptr0 = passStringToWasm0(source_path, wasm.__wbindgen_export, wasm.__wbindgen_export2);
753
+ const len0 = WASM_VECTOR_LEN;
754
+ const ret = wasm.wasmsearch_remove_file(this.__wbg_ptr, ptr0, len0);
755
+ return ret >>> 0;
756
+ }
757
+ /**
758
+ * @returns {Uint8Array}
759
+ */
760
+ save_index() {
761
+ try {
762
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
763
+ wasm.wasmsearch_save_index(retptr, this.__wbg_ptr);
764
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
765
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
766
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
767
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
768
+ if (r3) {
769
+ throw takeObject(r2);
770
+ }
771
+ var v1 = getArrayU8FromWasm0(r0, r1).slice();
772
+ wasm.__wbindgen_export4(r0, r1 * 1, 1);
773
+ return v1;
774
+ } finally {
775
+ wasm.__wbindgen_add_to_stack_pointer(16);
776
+ }
777
+ }
778
+ /**
779
+ * @param {string} query
780
+ * @param {number} limit
781
+ * @returns {any}
782
+ */
783
+ search(query, limit) {
784
+ try {
785
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
786
+ const ptr0 = passStringToWasm0(query, wasm.__wbindgen_export, wasm.__wbindgen_export2);
787
+ const len0 = WASM_VECTOR_LEN;
788
+ wasm.wasmsearch_search(retptr, this.__wbg_ptr, ptr0, len0, limit);
789
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
790
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
791
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
792
+ if (r2) {
793
+ throw takeObject(r1);
794
+ }
795
+ return takeObject(r0);
796
+ } finally {
797
+ wasm.__wbindgen_add_to_stack_pointer(16);
798
+ }
799
+ }
800
+ /**
801
+ * @param {string} query
802
+ * @param {number} limit
803
+ * @returns {any}
804
+ */
805
+ search_keywords(query, limit) {
806
+ try {
807
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
808
+ const ptr0 = passStringToWasm0(query, wasm.__wbindgen_export, wasm.__wbindgen_export2);
809
+ const len0 = WASM_VECTOR_LEN;
810
+ wasm.wasmsearch_search_keywords(retptr, this.__wbg_ptr, ptr0, len0, limit);
811
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
812
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
813
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
814
+ if (r2) {
815
+ throw takeObject(r1);
816
+ }
817
+ return takeObject(r0);
818
+ } finally {
819
+ wasm.__wbindgen_add_to_stack_pointer(16);
820
+ }
821
+ }
822
+ /**
823
+ * @param {string} query
824
+ * @param {number} limit
825
+ * @returns {any}
826
+ */
827
+ search_semantic(query, limit) {
828
+ try {
829
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
830
+ const ptr0 = passStringToWasm0(query, wasm.__wbindgen_export, wasm.__wbindgen_export2);
831
+ const len0 = WASM_VECTOR_LEN;
832
+ wasm.wasmsearch_search_semantic(retptr, this.__wbg_ptr, ptr0, len0, limit);
833
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
834
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
835
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
836
+ if (r2) {
837
+ throw takeObject(r1);
838
+ }
839
+ return takeObject(r0);
840
+ } finally {
841
+ wasm.__wbindgen_add_to_stack_pointer(16);
842
+ }
843
+ }
844
+ /**
845
+ * @param {string} text
846
+ * @param {string} source_path
847
+ * @returns {number}
848
+ */
849
+ update_file(text, source_path) {
850
+ try {
851
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
852
+ const ptr0 = passStringToWasm0(text, wasm.__wbindgen_export, wasm.__wbindgen_export2);
853
+ const len0 = WASM_VECTOR_LEN;
854
+ const ptr1 = passStringToWasm0(source_path, wasm.__wbindgen_export, wasm.__wbindgen_export2);
855
+ const len1 = WASM_VECTOR_LEN;
856
+ wasm.wasmsearch_update_file(retptr, this.__wbg_ptr, ptr0, len0, ptr1, len1);
857
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
858
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
859
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
860
+ if (r2) {
861
+ throw takeObject(r1);
862
+ }
863
+ return r0 >>> 0;
864
+ } finally {
865
+ wasm.__wbindgen_add_to_stack_pointer(16);
866
+ }
867
+ }
868
+ }
869
+ if (Symbol.dispose) WasmSearch.prototype[Symbol.dispose] = WasmSearch.prototype.free;
870
+
871
+ export function init() {
872
+ wasm.init();
873
+ }
874
+
875
+ /**
876
+ * @param {boolean} enabled
877
+ */
878
+ export function set_debug_logging(enabled) {
879
+ wasm.set_debug_logging(enabled);
880
+ }
881
+ function __wbg_get_imports() {
882
+ const import0 = {
883
+ __proto__: null,
884
+ __wbg_Error_408e67f47ca7b58b: function(arg0, arg1) {
885
+ const ret = Error(getStringFromWasm0(arg0, arg1));
886
+ return addHeapObject(ret);
887
+ },
888
+ __wbg_String_8564e559799eccda: function(arg0, arg1) {
889
+ const ret = String(getObject(arg1));
890
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export, wasm.__wbindgen_export2);
891
+ const len1 = WASM_VECTOR_LEN;
892
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
893
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
894
+ },
895
+ __wbg___wbindgen_debug_string_a57024b9c6e4a48b: function(arg0, arg1) {
896
+ const ret = debugString(getObject(arg1));
897
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export, wasm.__wbindgen_export2);
898
+ const len1 = WASM_VECTOR_LEN;
899
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
900
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
901
+ },
902
+ __wbg___wbindgen_is_function_5e4570eb24ffa122: function(arg0) {
903
+ const ret = typeof(getObject(arg0)) === 'function';
904
+ return ret;
905
+ },
906
+ __wbg___wbindgen_is_object_a2790eb24c211ea0: function(arg0) {
907
+ const val = getObject(arg0);
908
+ const ret = typeof(val) === 'object' && val !== null;
909
+ return ret;
910
+ },
911
+ __wbg___wbindgen_is_string_e6f02f0ea5f20a32: function(arg0) {
912
+ const ret = typeof(getObject(arg0)) === 'string';
913
+ return ret;
914
+ },
915
+ __wbg___wbindgen_is_undefined_6cff064c44e0d823: function(arg0) {
916
+ const ret = getObject(arg0) === undefined;
917
+ return ret;
918
+ },
919
+ __wbg___wbindgen_string_get_d154f1e671052120: function(arg0, arg1) {
920
+ const obj = getObject(arg1);
921
+ const ret = typeof(obj) === 'string' ? obj : undefined;
922
+ var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_export, wasm.__wbindgen_export2);
923
+ var len1 = WASM_VECTOR_LEN;
924
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
925
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
926
+ },
927
+ __wbg___wbindgen_throw_bb96b2010945f0bc: function(arg0, arg1) {
928
+ throw new Error(getStringFromWasm0(arg0, arg1));
929
+ },
930
+ __wbg__wbg_cb_unref_be22cc64ae6946a0: function(arg0) {
931
+ getObject(arg0)._wbg_cb_unref();
932
+ },
933
+ __wbg_arrayBuffer_16433f17fbd74397: function() { return handleError(function (arg0) {
934
+ const ret = getObject(arg0).arrayBuffer();
935
+ return addHeapObject(ret);
936
+ }, arguments); },
937
+ __wbg_call_35dba3c747ad7521: function() { return handleError(function (arg0, arg1, arg2) {
938
+ const ret = getObject(arg0).call(getObject(arg1), getObject(arg2));
939
+ return addHeapObject(ret);
940
+ }, arguments); },
941
+ __wbg_crypto_38df2bab126b63dc: function(arg0) {
942
+ const ret = getObject(arg0).crypto;
943
+ return addHeapObject(ret);
944
+ },
945
+ __wbg_error_757e9472f8410341: function(arg0, arg1) {
946
+ let deferred0_0;
947
+ let deferred0_1;
948
+ try {
949
+ deferred0_0 = arg0;
950
+ deferred0_1 = arg1;
951
+ console.error(getStringFromWasm0(arg0, arg1));
952
+ } finally {
953
+ wasm.__wbindgen_export4(deferred0_0, deferred0_1, 1);
954
+ }
955
+ },
956
+ __wbg_fetch_6500a72da8700672: function(arg0, arg1, arg2) {
957
+ const ret = getObject(arg0).fetch(getStringFromWasm0(arg1, arg2));
958
+ return addHeapObject(ret);
959
+ },
960
+ __wbg_fetch_bbfd889b90095876: function(arg0, arg1, arg2) {
961
+ const ret = getObject(arg0).fetch(getStringFromWasm0(arg1, arg2));
962
+ return addHeapObject(ret);
963
+ },
964
+ __wbg_getRandomValues_a608c4436c19407a: function() { return handleError(function (arg0, arg1) {
965
+ globalThis.crypto.getRandomValues(getArrayU8FromWasm0(arg0, arg1));
966
+ }, arguments); },
967
+ __wbg_getRandomValues_c44a50d8cfdaebeb: function() { return handleError(function (arg0, arg1) {
968
+ getObject(arg0).getRandomValues(getObject(arg1));
969
+ }, arguments); },
970
+ __wbg_instanceof_Response_8f49efbd4bfd76d6: function(arg0) {
971
+ let result;
972
+ try {
973
+ result = getObject(arg0) instanceof Response;
974
+ } catch (_) {
975
+ result = false;
976
+ }
977
+ const ret = result;
978
+ return ret;
979
+ },
980
+ __wbg_instanceof_Window_5625ff9937037a38: function(arg0) {
981
+ let result;
982
+ try {
983
+ result = getObject(arg0) instanceof Window;
984
+ } catch (_) {
985
+ result = false;
986
+ }
987
+ const ret = result;
988
+ return ret;
989
+ },
990
+ __wbg_instanceof_WorkerGlobalScope_8c58a6d74926b578: function(arg0) {
991
+ let result;
992
+ try {
993
+ result = getObject(arg0) instanceof WorkerGlobalScope;
994
+ } catch (_) {
995
+ result = false;
996
+ }
997
+ const ret = result;
998
+ return ret;
999
+ },
1000
+ __wbg_length_36bd29c6848c2144: function(arg0) {
1001
+ const ret = getObject(arg0).length;
1002
+ return ret;
1003
+ },
1004
+ __wbg_log_e6372b4fbfc9f81e: function(arg0) {
1005
+ console.log(getObject(arg0));
1006
+ },
1007
+ __wbg_msCrypto_bd5a034af96bcba6: function(arg0) {
1008
+ const ret = getObject(arg0).msCrypto;
1009
+ return addHeapObject(ret);
1010
+ },
1011
+ __wbg_new_116be93542d39019: function() {
1012
+ const ret = new Array();
1013
+ return addHeapObject(ret);
1014
+ },
1015
+ __wbg_new_227d7c05414eb861: function() {
1016
+ const ret = new Error();
1017
+ return addHeapObject(ret);
1018
+ },
1019
+ __wbg_new_77cc4f4f472aeb81: function(arg0) {
1020
+ const ret = new Uint8Array(getObject(arg0));
1021
+ return addHeapObject(ret);
1022
+ },
1023
+ __wbg_new_cdf041679ded4c5f: function() {
1024
+ const ret = new Map();
1025
+ return addHeapObject(ret);
1026
+ },
1027
+ __wbg_new_ebe3e0f6837f0879: function() {
1028
+ const ret = new Object();
1029
+ return addHeapObject(ret);
1030
+ },
1031
+ __wbg_new_typed_cceaf62d8d95e9f2: function(arg0, arg1) {
1032
+ try {
1033
+ var state0 = {a: arg0, b: arg1};
1034
+ var cb0 = (arg0, arg1) => {
1035
+ const a = state0.a;
1036
+ state0.a = 0;
1037
+ try {
1038
+ return __wasm_bindgen_func_elem_5426(a, state0.b, arg0, arg1);
1039
+ } finally {
1040
+ state0.a = a;
1041
+ }
1042
+ };
1043
+ const ret = new Promise(cb0);
1044
+ return addHeapObject(ret);
1045
+ } finally {
1046
+ state0.a = 0;
1047
+ }
1048
+ },
1049
+ __wbg_new_with_length_3ffc1c56427c525c: function(arg0) {
1050
+ const ret = new Uint8Array(arg0 >>> 0);
1051
+ return addHeapObject(ret);
1052
+ },
1053
+ __wbg_node_84ea875411254db1: function(arg0) {
1054
+ const ret = getObject(arg0).node;
1055
+ return addHeapObject(ret);
1056
+ },
1057
+ __wbg_now_8b265300afd5f2b9: function() {
1058
+ const ret = Date.now();
1059
+ return ret;
1060
+ },
1061
+ __wbg_process_44c7a14e11e9f69e: function(arg0) {
1062
+ const ret = getObject(arg0).process;
1063
+ return addHeapObject(ret);
1064
+ },
1065
+ __wbg_prototypesetcall_de8e0d9553586985: function(arg0, arg1, arg2) {
1066
+ Uint8Array.prototype.set.call(getArrayU8FromWasm0(arg0, arg1), getObject(arg2));
1067
+ },
1068
+ __wbg_queueMicrotask_ac694eae12e92dfb: function(arg0) {
1069
+ queueMicrotask(getObject(arg0));
1070
+ },
1071
+ __wbg_queueMicrotask_be5fe34a8f4cad4d: function(arg0) {
1072
+ const ret = getObject(arg0).queueMicrotask;
1073
+ return addHeapObject(ret);
1074
+ },
1075
+ __wbg_randomFillSync_6c25eac9869eb53c: function() { return handleError(function (arg0, arg1) {
1076
+ getObject(arg0).randomFillSync(takeObject(arg1));
1077
+ }, arguments); },
1078
+ __wbg_require_b4edbdcf3e2a1ef0: function() { return handleError(function () {
1079
+ const ret = module.require;
1080
+ return addHeapObject(ret);
1081
+ }, arguments); },
1082
+ __wbg_resolve_020f95d838c6ef25: function(arg0) {
1083
+ const ret = Promise.resolve(getObject(arg0));
1084
+ return addHeapObject(ret);
1085
+ },
1086
+ __wbg_set_014226dfeca53178: function(arg0, arg1, arg2) {
1087
+ const ret = getObject(arg0).set(getObject(arg1), getObject(arg2));
1088
+ return addHeapObject(ret);
1089
+ },
1090
+ __wbg_set_6be42768c690e380: function(arg0, arg1, arg2) {
1091
+ getObject(arg0)[takeObject(arg1)] = takeObject(arg2);
1092
+ },
1093
+ __wbg_set_a80955eb93b145c6: function(arg0, arg1, arg2) {
1094
+ getObject(arg0)[arg1 >>> 0] = takeObject(arg2);
1095
+ },
1096
+ __wbg_stack_3b0d974bbf31e44f: function(arg0, arg1) {
1097
+ const ret = getObject(arg1).stack;
1098
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export, wasm.__wbindgen_export2);
1099
+ const len1 = WASM_VECTOR_LEN;
1100
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
1101
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
1102
+ },
1103
+ __wbg_static_accessor_GLOBAL_THIS_466428f93b4eaa76: function() {
1104
+ const ret = typeof globalThis === 'undefined' ? null : globalThis;
1105
+ return isLikeNone(ret) ? 0 : addHeapObject(ret);
1106
+ },
1107
+ __wbg_static_accessor_GLOBAL_c7aea38d4de089bc: function() {
1108
+ const ret = typeof global === 'undefined' ? null : global;
1109
+ return isLikeNone(ret) ? 0 : addHeapObject(ret);
1110
+ },
1111
+ __wbg_static_accessor_SELF_42d4fae05e59267a: function() {
1112
+ const ret = typeof self === 'undefined' ? null : self;
1113
+ return isLikeNone(ret) ? 0 : addHeapObject(ret);
1114
+ },
1115
+ __wbg_static_accessor_WINDOW_e0db14a0eba6a812: function() {
1116
+ const ret = typeof window === 'undefined' ? null : window;
1117
+ return isLikeNone(ret) ? 0 : addHeapObject(ret);
1118
+ },
1119
+ __wbg_subarray_a4cc58201c7359fd: function(arg0, arg1, arg2) {
1120
+ const ret = getObject(arg0).subarray(arg1 >>> 0, arg2 >>> 0);
1121
+ return addHeapObject(ret);
1122
+ },
1123
+ __wbg_text_9302f33ea8cfce7b: function() { return handleError(function (arg0) {
1124
+ const ret = getObject(arg0).text();
1125
+ return addHeapObject(ret);
1126
+ }, arguments); },
1127
+ __wbg_then_7026b513a94278a8: function(arg0, arg1) {
1128
+ const ret = getObject(arg0).then(getObject(arg1));
1129
+ return addHeapObject(ret);
1130
+ },
1131
+ __wbg_then_72819b8d4e081fb5: function(arg0, arg1, arg2) {
1132
+ const ret = getObject(arg0).then(getObject(arg1), getObject(arg2));
1133
+ return addHeapObject(ret);
1134
+ },
1135
+ __wbg_versions_276b2795b1c6a219: function(arg0) {
1136
+ const ret = getObject(arg0).versions;
1137
+ return addHeapObject(ret);
1138
+ },
1139
+ __wbg_wasmmodel_new: function(arg0) {
1140
+ const ret = WasmModel.__wrap(arg0);
1141
+ return addHeapObject(ret);
1142
+ },
1143
+ __wbindgen_cast_0000000000000001: function(arg0, arg1) {
1144
+ // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx: 2036, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`.
1145
+ const ret = makeMutClosure(arg0, arg1, __wasm_bindgen_func_elem_5410);
1146
+ return addHeapObject(ret);
1147
+ },
1148
+ __wbindgen_cast_0000000000000002: function(arg0) {
1149
+ // Cast intrinsic for `F64 -> Externref`.
1150
+ const ret = arg0;
1151
+ return addHeapObject(ret);
1152
+ },
1153
+ __wbindgen_cast_0000000000000003: function(arg0, arg1) {
1154
+ // Cast intrinsic for `Ref(Slice(U8)) -> NamedExternref("Uint8Array")`.
1155
+ const ret = getArrayU8FromWasm0(arg0, arg1);
1156
+ return addHeapObject(ret);
1157
+ },
1158
+ __wbindgen_cast_0000000000000004: function(arg0, arg1) {
1159
+ // Cast intrinsic for `Ref(String) -> Externref`.
1160
+ const ret = getStringFromWasm0(arg0, arg1);
1161
+ return addHeapObject(ret);
1162
+ },
1163
+ __wbindgen_cast_0000000000000005: function(arg0) {
1164
+ // Cast intrinsic for `U64 -> Externref`.
1165
+ const ret = BigInt.asUintN(64, arg0);
1166
+ return addHeapObject(ret);
1167
+ },
1168
+ __wbindgen_object_clone_ref: function(arg0) {
1169
+ const ret = getObject(arg0);
1170
+ return addHeapObject(ret);
1171
+ },
1172
+ __wbindgen_object_drop_ref: function(arg0) {
1173
+ takeObject(arg0);
1174
+ },
1175
+ };
1176
+ return {
1177
+ __proto__: null,
1178
+ "./kjarni_wasm_bg.js": import0,
1179
+ };
1180
+ }
1181
+
1182
+ function __wasm_bindgen_func_elem_5410(arg0, arg1, arg2) {
1183
+ try {
1184
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1185
+ wasm.__wasm_bindgen_func_elem_5410(retptr, arg0, arg1, addHeapObject(arg2));
1186
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1187
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1188
+ if (r1) {
1189
+ throw takeObject(r0);
1190
+ }
1191
+ } finally {
1192
+ wasm.__wbindgen_add_to_stack_pointer(16);
1193
+ }
1194
+ }
1195
+
1196
+ function __wasm_bindgen_func_elem_5426(arg0, arg1, arg2, arg3) {
1197
+ wasm.__wasm_bindgen_func_elem_5426(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3));
1198
+ }
1199
+
1200
+ const WasmChatFinalization = (typeof FinalizationRegistry === 'undefined')
1201
+ ? { register: () => {}, unregister: () => {} }
1202
+ : new FinalizationRegistry(ptr => wasm.__wbg_wasmchat_free(ptr, 1));
1203
+ const WasmClassifierFinalization = (typeof FinalizationRegistry === 'undefined')
1204
+ ? { register: () => {}, unregister: () => {} }
1205
+ : new FinalizationRegistry(ptr => wasm.__wbg_wasmclassifier_free(ptr, 1));
1206
+ const WasmEncoderFinalization = (typeof FinalizationRegistry === 'undefined')
1207
+ ? { register: () => {}, unregister: () => {} }
1208
+ : new FinalizationRegistry(ptr => wasm.__wbg_wasmencoder_free(ptr, 1));
1209
+ const WasmIndexBuilderFinalization = (typeof FinalizationRegistry === 'undefined')
1210
+ ? { register: () => {}, unregister: () => {} }
1211
+ : new FinalizationRegistry(ptr => wasm.__wbg_wasmindexbuilder_free(ptr, 1));
1212
+ const WasmModelFinalization = (typeof FinalizationRegistry === 'undefined')
1213
+ ? { register: () => {}, unregister: () => {} }
1214
+ : new FinalizationRegistry(ptr => wasm.__wbg_wasmmodel_free(ptr, 1));
1215
+ const WasmRerankerFinalization = (typeof FinalizationRegistry === 'undefined')
1216
+ ? { register: () => {}, unregister: () => {} }
1217
+ : new FinalizationRegistry(ptr => wasm.__wbg_wasmreranker_free(ptr, 1));
1218
+ const WasmSearchFinalization = (typeof FinalizationRegistry === 'undefined')
1219
+ ? { register: () => {}, unregister: () => {} }
1220
+ : new FinalizationRegistry(ptr => wasm.__wbg_wasmsearch_free(ptr, 1));
1221
+
1222
+ function addHeapObject(obj) {
1223
+ if (heap_next === heap.length) heap.push(heap.length + 1);
1224
+ const idx = heap_next;
1225
+ heap_next = heap[idx];
1226
+
1227
+ heap[idx] = obj;
1228
+ return idx;
1229
+ }
1230
+
1231
+ function addBorrowedObject(obj) {
1232
+ if (stack_pointer == 1) throw new Error('out of js stack');
1233
+ heap[--stack_pointer] = obj;
1234
+ return stack_pointer;
1235
+ }
1236
+
1237
+ const CLOSURE_DTORS = (typeof FinalizationRegistry === 'undefined')
1238
+ ? { register: () => {}, unregister: () => {} }
1239
+ : new FinalizationRegistry(state => wasm.__wbindgen_export5(state.a, state.b));
1240
+
1241
+ function debugString(val) {
1242
+ // primitive types
1243
+ const type = typeof val;
1244
+ if (type == 'number' || type == 'boolean' || val == null) {
1245
+ return `${val}`;
1246
+ }
1247
+ if (type == 'string') {
1248
+ return `"${val}"`;
1249
+ }
1250
+ if (type == 'symbol') {
1251
+ const description = val.description;
1252
+ if (description == null) {
1253
+ return 'Symbol';
1254
+ } else {
1255
+ return `Symbol(${description})`;
1256
+ }
1257
+ }
1258
+ if (type == 'function') {
1259
+ const name = val.name;
1260
+ if (typeof name == 'string' && name.length > 0) {
1261
+ return `Function(${name})`;
1262
+ } else {
1263
+ return 'Function';
1264
+ }
1265
+ }
1266
+ // objects
1267
+ if (Array.isArray(val)) {
1268
+ const length = val.length;
1269
+ let debug = '[';
1270
+ if (length > 0) {
1271
+ debug += debugString(val[0]);
1272
+ }
1273
+ for(let i = 1; i < length; i++) {
1274
+ debug += ', ' + debugString(val[i]);
1275
+ }
1276
+ debug += ']';
1277
+ return debug;
1278
+ }
1279
+ // Test for built-in
1280
+ const builtInMatches = /\[object ([^\]]+)\]/.exec(toString.call(val));
1281
+ let className;
1282
+ if (builtInMatches && builtInMatches.length > 1) {
1283
+ className = builtInMatches[1];
1284
+ } else {
1285
+ // Failed to match the standard '[object ClassName]'
1286
+ return toString.call(val);
1287
+ }
1288
+ if (className == 'Object') {
1289
+ // we're a user defined class or Object
1290
+ // JSON.stringify avoids problems with cycles, and is generally much
1291
+ // easier than looping through ownProperties of `val`.
1292
+ try {
1293
+ return 'Object(' + JSON.stringify(val) + ')';
1294
+ } catch (_) {
1295
+ return 'Object';
1296
+ }
1297
+ }
1298
+ // errors
1299
+ if (val instanceof Error) {
1300
+ return `${val.name}: ${val.message}\n${val.stack}`;
1301
+ }
1302
+ // TODO we could test for more things here, like `Set`s and `Map`s.
1303
+ return className;
1304
+ }
1305
+
1306
+ function dropObject(idx) {
1307
+ if (idx < 1028) return;
1308
+ heap[idx] = heap_next;
1309
+ heap_next = idx;
1310
+ }
1311
+
1312
+ function getArrayF32FromWasm0(ptr, len) {
1313
+ ptr = ptr >>> 0;
1314
+ return getFloat32ArrayMemory0().subarray(ptr / 4, ptr / 4 + len);
1315
+ }
1316
+
1317
+ function getArrayJsValueFromWasm0(ptr, len) {
1318
+ ptr = ptr >>> 0;
1319
+ const mem = getDataViewMemory0();
1320
+ const result = [];
1321
+ for (let i = ptr; i < ptr + 4 * len; i += 4) {
1322
+ result.push(takeObject(mem.getUint32(i, true)));
1323
+ }
1324
+ return result;
1325
+ }
1326
+
1327
+ function getArrayU8FromWasm0(ptr, len) {
1328
+ ptr = ptr >>> 0;
1329
+ return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
1330
+ }
1331
+
1332
+ let cachedDataViewMemory0 = null;
1333
+ function getDataViewMemory0() {
1334
+ if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
1335
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
1336
+ }
1337
+ return cachedDataViewMemory0;
1338
+ }
1339
+
1340
+ let cachedFloat32ArrayMemory0 = null;
1341
+ function getFloat32ArrayMemory0() {
1342
+ if (cachedFloat32ArrayMemory0 === null || cachedFloat32ArrayMemory0.byteLength === 0) {
1343
+ cachedFloat32ArrayMemory0 = new Float32Array(wasm.memory.buffer);
1344
+ }
1345
+ return cachedFloat32ArrayMemory0;
1346
+ }
1347
+
1348
+ function getStringFromWasm0(ptr, len) {
1349
+ return decodeText(ptr >>> 0, len);
1350
+ }
1351
+
1352
+ let cachedUint8ArrayMemory0 = null;
1353
+ function getUint8ArrayMemory0() {
1354
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
1355
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
1356
+ }
1357
+ return cachedUint8ArrayMemory0;
1358
+ }
1359
+
1360
+ function getObject(idx) { return heap[idx]; }
1361
+
1362
+ function handleError(f, args) {
1363
+ try {
1364
+ return f.apply(this, args);
1365
+ } catch (e) {
1366
+ wasm.__wbindgen_export3(addHeapObject(e));
1367
+ }
1368
+ }
1369
+
1370
+ let heap = new Array(1024).fill(undefined);
1371
+ heap.push(undefined, null, true, false);
1372
+
1373
+ let heap_next = heap.length;
1374
+
1375
+ function isLikeNone(x) {
1376
+ return x === undefined || x === null;
1377
+ }
1378
+
1379
+ function makeMutClosure(arg0, arg1, f) {
1380
+ const state = { a: arg0, b: arg1, cnt: 1 };
1381
+ const real = (...args) => {
1382
+
1383
+ // First up with a closure we increment the internal reference
1384
+ // count. This ensures that the Rust closure environment won't
1385
+ // be deallocated while we're invoking it.
1386
+ state.cnt++;
1387
+ const a = state.a;
1388
+ state.a = 0;
1389
+ try {
1390
+ return f(a, state.b, ...args);
1391
+ } finally {
1392
+ state.a = a;
1393
+ real._wbg_cb_unref();
1394
+ }
1395
+ };
1396
+ real._wbg_cb_unref = () => {
1397
+ if (--state.cnt === 0) {
1398
+ wasm.__wbindgen_export5(state.a, state.b);
1399
+ state.a = 0;
1400
+ CLOSURE_DTORS.unregister(state);
1401
+ }
1402
+ };
1403
+ CLOSURE_DTORS.register(real, state, state);
1404
+ return real;
1405
+ }
1406
+
1407
+ function passArray8ToWasm0(arg, malloc) {
1408
+ const ptr = malloc(arg.length * 1, 1) >>> 0;
1409
+ getUint8ArrayMemory0().set(arg, ptr / 1);
1410
+ WASM_VECTOR_LEN = arg.length;
1411
+ return ptr;
1412
+ }
1413
+
1414
+ function passArrayF32ToWasm0(arg, malloc) {
1415
+ const ptr = malloc(arg.length * 4, 4) >>> 0;
1416
+ getFloat32ArrayMemory0().set(arg, ptr / 4);
1417
+ WASM_VECTOR_LEN = arg.length;
1418
+ return ptr;
1419
+ }
1420
+
1421
+ function passArrayJsValueToWasm0(array, malloc) {
1422
+ const ptr = malloc(array.length * 4, 4) >>> 0;
1423
+ const mem = getDataViewMemory0();
1424
+ for (let i = 0; i < array.length; i++) {
1425
+ mem.setUint32(ptr + 4 * i, addHeapObject(array[i]), true);
1426
+ }
1427
+ WASM_VECTOR_LEN = array.length;
1428
+ return ptr;
1429
+ }
1430
+
1431
+ function passStringToWasm0(arg, malloc, realloc) {
1432
+ if (realloc === undefined) {
1433
+ const buf = cachedTextEncoder.encode(arg);
1434
+ const ptr = malloc(buf.length, 1) >>> 0;
1435
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
1436
+ WASM_VECTOR_LEN = buf.length;
1437
+ return ptr;
1438
+ }
1439
+
1440
+ let len = arg.length;
1441
+ let ptr = malloc(len, 1) >>> 0;
1442
+
1443
+ const mem = getUint8ArrayMemory0();
1444
+
1445
+ let offset = 0;
1446
+
1447
+ for (; offset < len; offset++) {
1448
+ const code = arg.charCodeAt(offset);
1449
+ if (code > 0x7F) break;
1450
+ mem[ptr + offset] = code;
1451
+ }
1452
+ if (offset !== len) {
1453
+ if (offset !== 0) {
1454
+ arg = arg.slice(offset);
1455
+ }
1456
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
1457
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
1458
+ const ret = cachedTextEncoder.encodeInto(arg, view);
1459
+
1460
+ offset += ret.written;
1461
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
1462
+ }
1463
+
1464
+ WASM_VECTOR_LEN = offset;
1465
+ return ptr;
1466
+ }
1467
+
1468
+ let stack_pointer = 1024;
1469
+
1470
+ function takeObject(idx) {
1471
+ const ret = getObject(idx);
1472
+ dropObject(idx);
1473
+ return ret;
1474
+ }
1475
+
1476
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
1477
+ cachedTextDecoder.decode();
1478
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
1479
+ let numBytesDecoded = 0;
1480
+ function decodeText(ptr, len) {
1481
+ numBytesDecoded += len;
1482
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
1483
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
1484
+ cachedTextDecoder.decode();
1485
+ numBytesDecoded = len;
1486
+ }
1487
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
1488
+ }
1489
+
1490
+ const cachedTextEncoder = new TextEncoder();
1491
+
1492
+ if (!('encodeInto' in cachedTextEncoder)) {
1493
+ cachedTextEncoder.encodeInto = function (arg, view) {
1494
+ const buf = cachedTextEncoder.encode(arg);
1495
+ view.set(buf);
1496
+ return {
1497
+ read: arg.length,
1498
+ written: buf.length
1499
+ };
1500
+ };
1501
+ }
1502
+
1503
+ let WASM_VECTOR_LEN = 0;
1504
+
1505
+ let wasmModule, wasmInstance, wasm;
1506
+ function __wbg_finalize_init(instance, module) {
1507
+ wasmInstance = instance;
1508
+ wasm = instance.exports;
1509
+ wasmModule = module;
1510
+ cachedDataViewMemory0 = null;
1511
+ cachedFloat32ArrayMemory0 = null;
1512
+ cachedUint8ArrayMemory0 = null;
1513
+ wasm.__wbindgen_start();
1514
+ return wasm;
1515
+ }
1516
+
1517
+ async function __wbg_load(module, imports) {
1518
+ if (typeof Response === 'function' && module instanceof Response) {
1519
+ if (!module.ok) {
1520
+ throw new Error(`failed to fetch Wasm: ${module.status} ${module.statusText} fetching '${module.url}'`);
1521
+ }
1522
+
1523
+ if (typeof WebAssembly.instantiateStreaming === 'function') {
1524
+ try {
1525
+ return await WebAssembly.instantiateStreaming(module, imports);
1526
+ } catch (e) {
1527
+ const validResponse = expectedResponseType(module.type);
1528
+
1529
+ if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
1530
+ 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);
1531
+
1532
+ } else { throw e; }
1533
+ }
1534
+ }
1535
+
1536
+ const bytes = await module.arrayBuffer();
1537
+ return await WebAssembly.instantiate(bytes, imports);
1538
+ } else {
1539
+ const instance = await WebAssembly.instantiate(module, imports);
1540
+
1541
+ if (instance instanceof WebAssembly.Instance) {
1542
+ return { instance, module };
1543
+ } else {
1544
+ return instance;
1545
+ }
1546
+ }
1547
+
1548
+ function expectedResponseType(type) {
1549
+ switch (type) {
1550
+ case 'basic': case 'cors': case 'default': return true;
1551
+ }
1552
+ return false;
1553
+ }
1554
+ }
1555
+
1556
+ function initSync(module) {
1557
+ if (wasm !== undefined) return wasm;
1558
+
1559
+
1560
+ if (module !== undefined) {
1561
+ if (Object.getPrototypeOf(module) === Object.prototype) {
1562
+ ({module} = module)
1563
+ } else {
1564
+ console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
1565
+ }
1566
+ }
1567
+
1568
+ const imports = __wbg_get_imports();
1569
+ if (!(module instanceof WebAssembly.Module)) {
1570
+ module = new WebAssembly.Module(module);
1571
+ }
1572
+ const instance = new WebAssembly.Instance(module, imports);
1573
+ return __wbg_finalize_init(instance, module);
1574
+ }
1575
+
1576
+ async function __wbg_init(module_or_path) {
1577
+ if (wasm !== undefined) return wasm;
1578
+
1579
+
1580
+ if (module_or_path !== undefined) {
1581
+ if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
1582
+ ({module_or_path} = module_or_path)
1583
+ } else {
1584
+ console.warn('using deprecated parameters for the initialization function; pass a single object instead')
1585
+ }
1586
+ }
1587
+
1588
+ if (module_or_path === undefined) {
1589
+ module_or_path = new URL('kjarni_wasm_bg.wasm', import.meta.url);
1590
+ }
1591
+ const imports = __wbg_get_imports();
1592
+
1593
+ if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
1594
+ module_or_path = fetch(module_or_path);
1595
+ }
1596
+
1597
+ const { instance, module } = await __wbg_load(await module_or_path, imports);
1598
+
1599
+ return __wbg_finalize_init(instance, module);
1600
+ }
1601
+
1602
+ export { initSync, __wbg_init as default };