@sauravpanda/flare 0.1.0

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,2790 @@
1
+ /* @ts-self-types="./flare_web.d.ts" */
2
+
3
+ /**
4
+ * Flare LLM inference engine, exported to JS.
5
+ *
6
+ * Holds a loaded model and runs greedy/sampled token generation.
7
+ * The detected chat template is available via `chat_template_name` and
8
+ * `apply_chat_template` so the browser demo can format prompts correctly
9
+ * for instruction-tuned models.
10
+ */
11
+ export class FlareEngine {
12
+ static __wrap(ptr) {
13
+ ptr = ptr >>> 0;
14
+ const obj = Object.create(FlareEngine.prototype);
15
+ obj.__wbg_ptr = ptr;
16
+ FlareEngineFinalization.register(obj, obj.__wbg_ptr, obj);
17
+ return obj;
18
+ }
19
+ __destroy_into_raw() {
20
+ const ptr = this.__wbg_ptr;
21
+ this.__wbg_ptr = 0;
22
+ FlareEngineFinalization.unregister(this);
23
+ return ptr;
24
+ }
25
+ free() {
26
+ const ptr = this.__destroy_into_raw();
27
+ wasm.__wbg_flareengine_free(ptr, 0);
28
+ }
29
+ /**
30
+ * Whether the model requests automatic BOS token prepending.
31
+ *
32
+ * Sourced from `tokenizer.ggml.add_bos_token` in the GGUF metadata.
33
+ * When `true`, all generation methods (`generate_tokens`, `begin_stream`,
34
+ * `generate_text`, `generate_stream`) automatically prepend the BOS token
35
+ * to the input token sequence unless it is already the first token.
36
+ * @returns {boolean}
37
+ */
38
+ get add_bos_token() {
39
+ const ret = wasm.flareengine_add_bos_token(this.__wbg_ptr);
40
+ return ret !== 0;
41
+ }
42
+ /**
43
+ * Register a stop sequence.
44
+ *
45
+ * Generation halts (without emitting the matched tokens) as soon as the
46
+ * decoded output ends with `sequence`. Call once per stop string before
47
+ * `begin_stream` or `generate_with_params`.
48
+ *
49
+ * Stop sequences are cleared by `reset()` or `clear_stop_sequences()`.
50
+ *
51
+ * ```javascript
52
+ * engine.add_stop_sequence("<|im_end|>");
53
+ * engine.add_stop_sequence("</s>");
54
+ * engine.begin_stream_with_params(promptIds, 200, 0.8, 0.95, 40, 1.1);
55
+ * ```
56
+ * @param {string} sequence
57
+ */
58
+ add_stop_sequence(sequence) {
59
+ const ptr0 = passStringToWasm0(sequence, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
60
+ const len0 = WASM_VECTOR_LEN;
61
+ wasm.flareengine_add_stop_sequence(this.__wbg_ptr, ptr0, len0);
62
+ }
63
+ /**
64
+ * Format a user message (and optional system prompt) using the model's
65
+ * auto-detected chat template. Returns the formatted prompt string ready
66
+ * to be passed to `FlareTokenizer.encode()`.
67
+ *
68
+ * Pass an empty string for `system_message` to omit the system turn.
69
+ *
70
+ * # JS example
71
+ * ```javascript
72
+ * const prompt = engine.apply_chat_template(
73
+ * 'Explain quantum computing in simple terms.',
74
+ * 'You are a helpful assistant.'
75
+ * );
76
+ * const ids = tokenizer.encode(prompt);
77
+ * const output = engine.generate_tokens(ids, 128);
78
+ * ```
79
+ * @param {string} user_message
80
+ * @param {string} system_message
81
+ * @returns {string}
82
+ */
83
+ apply_chat_template(user_message, system_message) {
84
+ let deferred3_0;
85
+ let deferred3_1;
86
+ try {
87
+ const ptr0 = passStringToWasm0(user_message, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
88
+ const len0 = WASM_VECTOR_LEN;
89
+ const ptr1 = passStringToWasm0(system_message, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
90
+ const len1 = WASM_VECTOR_LEN;
91
+ const ret = wasm.flareengine_apply_chat_template(this.__wbg_ptr, ptr0, len0, ptr1, len1);
92
+ deferred3_0 = ret[0];
93
+ deferred3_1 = ret[1];
94
+ return getStringFromWasm0(ret[0], ret[1]);
95
+ } finally {
96
+ wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
97
+ }
98
+ }
99
+ /**
100
+ * Model architecture name from `general.architecture` in the GGUF metadata.
101
+ *
102
+ * Returns a lowercase string such as `"llama"`, `"mistral"`, `"gemma2"`,
103
+ * `"phi3"`, or `"qwen2"`. Returns `"unknown"` if the field is absent.
104
+ * @returns {string}
105
+ */
106
+ get architecture() {
107
+ let deferred1_0;
108
+ let deferred1_1;
109
+ try {
110
+ const ret = wasm.flareengine_architecture(this.__wbg_ptr);
111
+ deferred1_0 = ret[0];
112
+ deferred1_1 = ret[1];
113
+ return getStringFromWasm0(ret[0], ret[1]);
114
+ } finally {
115
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
116
+ }
117
+ }
118
+ /**
119
+ * Prepare for token-by-token streaming.
120
+ *
121
+ * Runs the prefill pass on `prompt_tokens`, then initialises internal
122
+ * state so that subsequent calls to `next_token()` each produce one
123
+ * output token. Call `engine.reset()` before `begin_stream()` to start
124
+ * a fresh conversation.
125
+ *
126
+ * # JS example
127
+ * ```javascript
128
+ * engine.reset();
129
+ * engine.begin_stream(promptIds, 128);
130
+ * function tick() {
131
+ * const id = engine.next_token();
132
+ * if (id === undefined) { /* done */ return; }
133
+ * output.textContent += tokenizer.decode_one(id);
134
+ * requestAnimationFrame(tick); // yield to browser, then continue
135
+ * }
136
+ * requestAnimationFrame(tick);
137
+ * ```
138
+ * @param {Uint32Array} prompt_tokens
139
+ * @param {number} max_tokens
140
+ */
141
+ begin_stream(prompt_tokens, max_tokens) {
142
+ const ptr0 = passArray32ToWasm0(prompt_tokens, wasm.__wbindgen_malloc);
143
+ const len0 = WASM_VECTOR_LEN;
144
+ wasm.flareengine_begin_stream(this.__wbg_ptr, ptr0, len0, max_tokens);
145
+ }
146
+ /**
147
+ * Begin a token-by-token stream, healing the last prompt token.
148
+ *
149
+ * Identical to `begin_stream` but avoids double-processing the final prompt
150
+ * token: the prefill runs only tokens `[0 .. n-2]`, then the first
151
+ * `next_token()` call processes the last prompt token at its correct
152
+ * position `n-1` and produces the first output token. This keeps RoPE
153
+ * positional embeddings consistent and is recommended when the prompt
154
+ * ends at a natural token boundary (e.g. when encoding a user turn in a
155
+ * chat template).
156
+ *
157
+ * Falls back to `begin_stream` for prompts shorter than 2 tokens.
158
+ *
159
+ * # JS example
160
+ * ```javascript
161
+ * engine.reset();
162
+ * const ids = engine.encode_text(engine.apply_chat_template(userMsg, sysMsg));
163
+ * engine.begin_stream_healed(ids, 256);
164
+ * requestAnimationFrame(function tick() {
165
+ * const id = engine.next_token();
166
+ * if (id !== undefined) output.textContent += tokenizer.decode_one(id);
167
+ * if (!engine.stream_done) requestAnimationFrame(tick);
168
+ * });
169
+ * ```
170
+ * @param {Uint32Array} prompt_tokens
171
+ * @param {number} max_tokens
172
+ */
173
+ begin_stream_healed(prompt_tokens, max_tokens) {
174
+ const ptr0 = passArray32ToWasm0(prompt_tokens, wasm.__wbindgen_malloc);
175
+ const len0 = WASM_VECTOR_LEN;
176
+ wasm.flareengine_begin_stream_healed(this.__wbg_ptr, ptr0, len0, max_tokens);
177
+ }
178
+ /**
179
+ * Like `begin_stream_healed` but with full sampling parameters.
180
+ *
181
+ * Combines position-consistent prefill (see `begin_stream_healed`) with
182
+ * the same temperature / top-p / top-k / repeat-penalty / min-p controls
183
+ * available in `begin_stream_with_params`.
184
+ *
185
+ * # JS example
186
+ * ```javascript
187
+ * engine.reset();
188
+ * const ids = engine.encode_text(engine.apply_chat_template(userMsg, sysMsg));
189
+ * engine.begin_stream_healed_with_params(ids, 256, 0.8, 0.95, 40, 1.1, 0.0);
190
+ * requestAnimationFrame(function tick() {
191
+ * const id = engine.next_token();
192
+ * if (id !== undefined) output.textContent += tokenizer.decode_one(id);
193
+ * if (!engine.stream_done) requestAnimationFrame(tick);
194
+ * });
195
+ * ```
196
+ * @param {Uint32Array} prompt_tokens
197
+ * @param {number} max_tokens
198
+ * @param {number} temperature
199
+ * @param {number} top_p
200
+ * @param {number} top_k
201
+ * @param {number} repeat_penalty
202
+ * @param {number} min_p
203
+ */
204
+ begin_stream_healed_with_params(prompt_tokens, max_tokens, temperature, top_p, top_k, repeat_penalty, min_p) {
205
+ const ptr0 = passArray32ToWasm0(prompt_tokens, wasm.__wbindgen_malloc);
206
+ const len0 = WASM_VECTOR_LEN;
207
+ wasm.flareengine_begin_stream_healed_with_params(this.__wbg_ptr, ptr0, len0, max_tokens, temperature, top_p, top_k, repeat_penalty, min_p);
208
+ }
209
+ /**
210
+ * Like `begin_stream` but with temperature / top-p sampling.
211
+ *
212
+ * `temperature`: 0.0 = greedy, 0.7–1.0 = typical creative range.
213
+ * `top_p`: nucleus sampling threshold (0.0–1.0); 0.9 is a good default.
214
+ *
215
+ * # JS example
216
+ * ```javascript
217
+ * engine.reset();
218
+ * engine.begin_stream_with_params(promptIds, 128, 0.8, 0.9);
219
+ * function tick() {
220
+ * const id = engine.next_token();
221
+ * if (id === undefined) return;
222
+ * output.textContent += tokenizer.decode_one(id);
223
+ * requestAnimationFrame(tick);
224
+ * }
225
+ * requestAnimationFrame(tick);
226
+ * ```
227
+ * Begin a token-by-token stream with sampling parameters including top-k.
228
+ *
229
+ * - `temperature`: controls randomness (0 = greedy, higher = more random)
230
+ * - `top_p`: nucleus sampling — keep the smallest token set whose cumulative
231
+ * probability ≥ `top_p` (1.0 = disabled; applied when < 1.0)
232
+ * - `top_k`: keep only the `top_k` highest-probability tokens before sampling
233
+ * (0 = disabled; applied when `top_p` is 1.0 and `top_k` > 0)
234
+ * - `repeat_penalty`: penalty applied to logits of recently-seen tokens to
235
+ * reduce repetition (1.0 = disabled, 1.1–1.3 = typical range)
236
+ *
237
+ * ```javascript
238
+ * engine.begin_stream_with_params(promptIds, 200, 0.8, 0.95, 40, 1.1, 0.0);
239
+ * ```
240
+ * @param {Uint32Array} prompt_tokens
241
+ * @param {number} max_tokens
242
+ * @param {number} temperature
243
+ * @param {number} top_p
244
+ * @param {number} top_k
245
+ * @param {number} repeat_penalty
246
+ * @param {number} min_p
247
+ */
248
+ begin_stream_with_params(prompt_tokens, max_tokens, temperature, top_p, top_k, repeat_penalty, min_p) {
249
+ const ptr0 = passArray32ToWasm0(prompt_tokens, wasm.__wbindgen_malloc);
250
+ const len0 = WASM_VECTOR_LEN;
251
+ wasm.flareengine_begin_stream_with_params(this.__wbg_ptr, ptr0, len0, max_tokens, temperature, top_p, top_k, repeat_penalty, min_p);
252
+ }
253
+ /**
254
+ * BOS (beginning of sequence) token ID from the GGUF model metadata, if present.
255
+ * Some models require this to be prepended to the input token sequence.
256
+ * @returns {number | undefined}
257
+ */
258
+ get bos_token_id() {
259
+ const ret = wasm.flareengine_bos_token_id(this.__wbg_ptr);
260
+ return ret === 0x100000001 ? undefined : ret;
261
+ }
262
+ /**
263
+ * Name of the auto-detected chat template (e.g. `"ChatML"`, `"Llama3"`,
264
+ * `"Alpaca"`, `"Raw"`). Use this to display the template in the UI and
265
+ * decide whether to call `apply_chat_template` before encoding.
266
+ * @returns {string}
267
+ */
268
+ get chat_template_name() {
269
+ let deferred1_0;
270
+ let deferred1_1;
271
+ try {
272
+ const ret = wasm.flareengine_chat_template_name(this.__wbg_ptr);
273
+ deferred1_0 = ret[0];
274
+ deferred1_1 = ret[1];
275
+ return getStringFromWasm0(ret[0], ret[1]);
276
+ } finally {
277
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
278
+ }
279
+ }
280
+ /**
281
+ * Clear any previously loaded raw quantized weights.
282
+ *
283
+ * After calling this the engine uses the f32 dequantized path for all
284
+ * matrix operations until `load_raw_weights` is called again.
285
+ */
286
+ clear_raw_weights() {
287
+ wasm.flareengine_clear_raw_weights(this.__wbg_ptr);
288
+ }
289
+ /**
290
+ * Remove all registered stop sequences.
291
+ */
292
+ clear_stop_sequences() {
293
+ wasm.flareengine_clear_stop_sequences(this.__wbg_ptr);
294
+ }
295
+ /**
296
+ * Compute the perplexity of `text` under the loaded model.
297
+ *
298
+ * Encodes `text` with the embedded GGUF vocabulary, runs one forward pass
299
+ * per token, and measures the log-probability of each correct next-token
300
+ * prediction. Perplexity = exp(−mean(log_probs)).
301
+ *
302
+ * The KV cache is reset **before and after** the evaluation so the engine
303
+ * returns to a clean state.
304
+ *
305
+ * Returns `f32::INFINITY` if the text encodes to fewer than 2 tokens or if
306
+ * no GGUF vocabulary is available.
307
+ *
308
+ * # JS example
309
+ * ```javascript
310
+ * const ppl = engine.compute_perplexity("The quick brown fox");
311
+ * console.log("Perplexity:", ppl);
312
+ * ```
313
+ * @param {string} text
314
+ * @returns {number}
315
+ */
316
+ compute_perplexity(text) {
317
+ const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
318
+ const len0 = WASM_VECTOR_LEN;
319
+ const ret = wasm.flareengine_compute_perplexity(this.__wbg_ptr, ptr0, len0);
320
+ return ret;
321
+ }
322
+ /**
323
+ * Fraction of the context window consumed (0.0 = empty, 1.0 = full).
324
+ *
325
+ * Equivalent to `tokens_used / max_seq_len`. Returns 0.0 if `max_seq_len` is 0.
326
+ * @returns {number}
327
+ */
328
+ get context_window_pct() {
329
+ const ret = wasm.flareengine_context_window_pct(this.__wbg_ptr);
330
+ return ret;
331
+ }
332
+ /**
333
+ * Count the number of tokens in `text` using the model's embedded GGUF vocabulary.
334
+ *
335
+ * Returns 0 if the model was not loaded from a GGUF file (e.g. SafeTensors only).
336
+ *
337
+ * # JS example
338
+ * ```javascript
339
+ * const n = engine.count_tokens(textarea.value);
340
+ * counter.textContent = `${n} / ${engine.max_seq_len} tokens`;
341
+ * ```
342
+ * @param {string} text
343
+ * @returns {number}
344
+ */
345
+ count_tokens(text) {
346
+ const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
347
+ const len0 = WASM_VECTOR_LEN;
348
+ const ret = wasm.flareengine_count_tokens(this.__wbg_ptr, ptr0, len0);
349
+ return ret >>> 0;
350
+ }
351
+ /**
352
+ * Decode token IDs to text using the embedded GGUF vocabulary.
353
+ *
354
+ * Returns an empty string if no GGUF vocab is available.
355
+ *
356
+ * # JS example
357
+ * ```javascript
358
+ * const text = engine.decode_ids(generatedIds);
359
+ * ```
360
+ * @param {Uint32Array} ids
361
+ * @returns {string}
362
+ */
363
+ decode_ids(ids) {
364
+ let deferred2_0;
365
+ let deferred2_1;
366
+ try {
367
+ const ptr0 = passArray32ToWasm0(ids, wasm.__wbindgen_malloc);
368
+ const len0 = WASM_VECTOR_LEN;
369
+ const ret = wasm.flareengine_decode_ids(this.__wbg_ptr, ptr0, len0);
370
+ deferred2_0 = ret[0];
371
+ deferred2_1 = ret[1];
372
+ return getStringFromWasm0(ret[0], ret[1]);
373
+ } finally {
374
+ wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
375
+ }
376
+ }
377
+ /**
378
+ * Decode a single token ID to its text piece.
379
+ *
380
+ * Convenience wrapper around `decode_ids` for use directly inside a
381
+ * `next_token()` loop so callers don't need a separate `FlareTokenizer`.
382
+ *
383
+ * Returns an empty string if no GGUF vocab is loaded.
384
+ *
385
+ * # JS example
386
+ * ```javascript
387
+ * engine.begin_stream(promptIds, 128);
388
+ * requestAnimationFrame(function tick() {
389
+ * const id = engine.next_token();
390
+ * if (id !== undefined) output.textContent += engine.decode_token(id);
391
+ * if (!engine.stream_done) requestAnimationFrame(tick);
392
+ * });
393
+ * ```
394
+ * @param {number} id
395
+ * @returns {string}
396
+ */
397
+ decode_token(id) {
398
+ let deferred1_0;
399
+ let deferred1_1;
400
+ try {
401
+ const ret = wasm.flareengine_decode_token(this.__wbg_ptr, id);
402
+ deferred1_0 = ret[0];
403
+ deferred1_1 = ret[1];
404
+ return getStringFromWasm0(ret[0], ret[1]);
405
+ } finally {
406
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
407
+ }
408
+ }
409
+ /**
410
+ * Decode a single token ID, correctly handling multi-byte UTF-8 sequences.
411
+ *
412
+ * SentencePiece tokenizers encode non-ASCII characters as consecutive
413
+ * byte-level tokens such as `<0xE4>`, `<0xB8>`, `<0xAD>` (the UTF-8
414
+ * encoding of `中`). The basic `decode_token` function returns incorrect
415
+ * Latin-1 characters in these cases because it treats each byte as an
416
+ * independent Unicode scalar.
417
+ *
418
+ * `decode_token_chunk` accumulates bytes in an internal buffer until a
419
+ * complete, valid UTF-8 sequence is assembled, then returns it as a
420
+ * `String`. While the sequence is incomplete it returns an empty string,
421
+ * and when a regular (non-byte) token is encountered it flushes any
422
+ * buffered bytes (replacing invalid sequences with U+FFFD) before
423
+ * returning the decoded text.
424
+ *
425
+ * **Use this instead of `decode_token` whenever you are streaming tokens
426
+ * that may include non-Latin characters.**
427
+ *
428
+ * ```javascript
429
+ * engine.begin_stream(prompt, 256);
430
+ * function tick() {
431
+ * const id = engine.next_token();
432
+ * if (id !== undefined) output.textContent += engine.decode_token_chunk(id);
433
+ * if (!engine.stream_done) requestAnimationFrame(tick);
434
+ * }
435
+ * requestAnimationFrame(tick);
436
+ * ```
437
+ * @param {number} id
438
+ * @returns {string}
439
+ */
440
+ decode_token_chunk(id) {
441
+ let deferred1_0;
442
+ let deferred1_1;
443
+ try {
444
+ const ret = wasm.flareengine_decode_token_chunk(this.__wbg_ptr, id);
445
+ deferred1_0 = ret[0];
446
+ deferred1_1 = ret[1];
447
+ return getStringFromWasm0(ret[0], ret[1]);
448
+ } finally {
449
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
450
+ }
451
+ }
452
+ /**
453
+ * Look up the token embedding row for `token_id` as a flat `Float32Array`.
454
+ *
455
+ * The length of the returned vector is `hidden_dim`. See also
456
+ * [`FlareEngine::output_projection`] for the inverse tail step.
457
+ * @param {number} token_id
458
+ * @returns {Float32Array}
459
+ */
460
+ embed_token(token_id) {
461
+ const ret = wasm.flareengine_embed_token(this.__wbg_ptr, token_id);
462
+ var v1 = getArrayF32FromWasm0(ret[0], ret[1]).slice();
463
+ wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
464
+ return v1;
465
+ }
466
+ /**
467
+ * # JS example
468
+ * ```javascript
469
+ * const ids = engine.encode_text("Hello, world!");
470
+ * const output = engine.generate_tokens(ids, 64);
471
+ * ```
472
+ * @param {string} text
473
+ * @returns {Uint32Array}
474
+ */
475
+ encode_text(text) {
476
+ const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
477
+ const len0 = WASM_VECTOR_LEN;
478
+ const ret = wasm.flareengine_encode_text(this.__wbg_ptr, ptr0, len0);
479
+ var v2 = getArrayU32FromWasm0(ret[0], ret[1]).slice();
480
+ wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
481
+ return v2;
482
+ }
483
+ /**
484
+ * EOS (end of sequence) token ID from the GGUF model metadata, if present.
485
+ * Generation stops automatically when this token is produced.
486
+ * @returns {number | undefined}
487
+ */
488
+ get eos_token_id() {
489
+ const ret = wasm.flareengine_eos_token_id(this.__wbg_ptr);
490
+ return ret === 0x100000001 ? undefined : ret;
491
+ }
492
+ /**
493
+ * Streaming text-in / text-out generation with a per-token JS callback.
494
+ *
495
+ * Encodes `prompt` with the embedded GGUF vocabulary, generates up to
496
+ * `max_tokens` tokens, and calls `on_token(token_str)` with the decoded
497
+ * text for each token as it is produced. Returns the number of tokens
498
+ * generated (excluding any EOS token).
499
+ *
500
+ * Returns 0 if no GGUF vocab is available.
501
+ *
502
+ * # Note on browser streaming
503
+ * `on_token` is called synchronously inside WASM, so the browser will
504
+ * not visually update between tokens. For visible character-by-character
505
+ * output, use `begin_stream` + `next_token` with `requestAnimationFrame`.
506
+ *
507
+ * # JS example
508
+ * ```javascript
509
+ * engine.reset();
510
+ * let out = '';
511
+ * const count = engine.generate_stream("What is Rust?", 128, (token) => {
512
+ * out += token;
513
+ * });
514
+ * output.textContent = out;
515
+ * ```
516
+ * @param {string} prompt
517
+ * @param {number} max_tokens
518
+ * @param {Function} on_token
519
+ * @returns {number}
520
+ */
521
+ generate_stream(prompt, max_tokens, on_token) {
522
+ const ptr0 = passStringToWasm0(prompt, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
523
+ const len0 = WASM_VECTOR_LEN;
524
+ const ret = wasm.flareengine_generate_stream(this.__wbg_ptr, ptr0, len0, max_tokens, on_token);
525
+ return ret >>> 0;
526
+ }
527
+ /**
528
+ * Streaming text-in / text-out with explicit sampling parameters.
529
+ *
530
+ * Like `generate_stream` but with the full set of sampling controls:
531
+ *
532
+ * - `temperature`: 0 = greedy, higher = more diverse
533
+ * - `top_p`: nucleus sampling (1.0 = disabled)
534
+ * - `top_k`: top-k sampling, applied when `top_p` is 1.0 and `min_p` is 0.0 (0 = disabled)
535
+ * - `repeat_penalty`: repetition penalty (1.0 = disabled, 1.1–1.3 = typical)
536
+ * - `min_p`: min-p threshold (0.0 = disabled)
537
+ *
538
+ * Encodes `prompt` with the embedded GGUF vocabulary, generates up to
539
+ * `max_tokens` tokens, and calls `on_token(token_str)` with the decoded
540
+ * text for each token. Respects stop sequences registered via
541
+ * `add_stop_sequence`. Returns the number of tokens generated.
542
+ *
543
+ * Returns 0 if no GGUF vocab is available.
544
+ *
545
+ * # JS example
546
+ * ```javascript
547
+ * engine.add_stop_sequence("<|im_end|>");
548
+ * engine.reset();
549
+ * let out = '';
550
+ * const count = engine.generate_stream_with_params(
551
+ * prompt, 200, 0.8, 0.95, 40, 1.1, 0.0,
552
+ * (token) => { out += token; }
553
+ * );
554
+ * ```
555
+ * @param {string} prompt
556
+ * @param {number} max_tokens
557
+ * @param {number} temperature
558
+ * @param {number} top_p
559
+ * @param {number} top_k
560
+ * @param {number} repeat_penalty
561
+ * @param {number} min_p
562
+ * @param {Function} on_token
563
+ * @returns {number}
564
+ */
565
+ generate_stream_with_params(prompt, max_tokens, temperature, top_p, top_k, repeat_penalty, min_p, on_token) {
566
+ const ptr0 = passStringToWasm0(prompt, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
567
+ const len0 = WASM_VECTOR_LEN;
568
+ const ret = wasm.flareengine_generate_stream_with_params(this.__wbg_ptr, ptr0, len0, max_tokens, temperature, top_p, top_k, repeat_penalty, min_p, on_token);
569
+ return ret >>> 0;
570
+ }
571
+ /**
572
+ * Full text-in / text-out generation using the embedded GGUF vocabulary.
573
+ *
574
+ * Encodes `prompt` with the embedded vocab, runs greedy generation for up
575
+ * to `max_tokens` steps, then decodes the output back to text. Stops
576
+ * automatically at EOS.
577
+ *
578
+ * Returns an empty string if no GGUF vocab is available.
579
+ *
580
+ * # JS example
581
+ * ```javascript
582
+ * engine.reset();
583
+ * const response = engine.generate_text("What is Rust?", 128);
584
+ * output.textContent = response;
585
+ * ```
586
+ * @param {string} prompt
587
+ * @param {number} max_tokens
588
+ * @returns {string}
589
+ */
590
+ generate_text(prompt, max_tokens) {
591
+ let deferred2_0;
592
+ let deferred2_1;
593
+ try {
594
+ const ptr0 = passStringToWasm0(prompt, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
595
+ const len0 = WASM_VECTOR_LEN;
596
+ const ret = wasm.flareengine_generate_text(this.__wbg_ptr, ptr0, len0, max_tokens);
597
+ deferred2_0 = ret[0];
598
+ deferred2_1 = ret[1];
599
+ return getStringFromWasm0(ret[0], ret[1]);
600
+ } finally {
601
+ wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
602
+ }
603
+ }
604
+ /**
605
+ * Full text-in / text-out generation with explicit sampling parameters.
606
+ *
607
+ * Like `generate_text` but with the full set of sampling controls:
608
+ *
609
+ * - `temperature`: 0 = greedy, higher = more diverse
610
+ * - `top_p`: nucleus sampling (1.0 = disabled)
611
+ * - `top_k`: top-k sampling, applied when `top_p` is 1.0 and `min_p` is 0.0 (0 = disabled)
612
+ * - `repeat_penalty`: repetition penalty (1.0 = disabled)
613
+ * - `min_p`: min-p threshold (0.0 = disabled)
614
+ *
615
+ * Returns the decoded generated text. Returns an empty string if no GGUF vocab is available.
616
+ * Respects stop sequences registered via `add_stop_sequence`.
617
+ *
618
+ * # JS example
619
+ * ```javascript
620
+ * engine.reset();
621
+ * const response = engine.generate_text_with_params(
622
+ * "What is Rust?", 128, 0.8, 0.95, 40, 1.1, 0.0
623
+ * );
624
+ * output.textContent = response;
625
+ * ```
626
+ * @param {string} prompt
627
+ * @param {number} max_tokens
628
+ * @param {number} temperature
629
+ * @param {number} top_p
630
+ * @param {number} top_k
631
+ * @param {number} repeat_penalty
632
+ * @param {number} min_p
633
+ * @returns {string}
634
+ */
635
+ generate_text_with_params(prompt, max_tokens, temperature, top_p, top_k, repeat_penalty, min_p) {
636
+ let deferred2_0;
637
+ let deferred2_1;
638
+ try {
639
+ const ptr0 = passStringToWasm0(prompt, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
640
+ const len0 = WASM_VECTOR_LEN;
641
+ const ret = wasm.flareengine_generate_text_with_params(this.__wbg_ptr, ptr0, len0, max_tokens, temperature, top_p, top_k, repeat_penalty, min_p);
642
+ deferred2_0 = ret[0];
643
+ deferred2_1 = ret[1];
644
+ return getStringFromWasm0(ret[0], ret[1]);
645
+ } finally {
646
+ wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
647
+ }
648
+ }
649
+ /**
650
+ * Generate `max_tokens` tokens starting from `prompt_tokens` (greedy).
651
+ * Stops early at EOS. Returns a Uint32Array of generated token IDs.
652
+ * @param {Uint32Array} prompt_tokens
653
+ * @param {number} max_tokens
654
+ * @returns {Uint32Array}
655
+ */
656
+ generate_tokens(prompt_tokens, max_tokens) {
657
+ const ptr0 = passArray32ToWasm0(prompt_tokens, wasm.__wbindgen_malloc);
658
+ const len0 = WASM_VECTOR_LEN;
659
+ const ret = wasm.flareengine_generate_tokens(this.__wbg_ptr, ptr0, len0, max_tokens);
660
+ var v2 = getArrayU32FromWasm0(ret[0], ret[1]).slice();
661
+ wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
662
+ return v2;
663
+ }
664
+ /**
665
+ * Generate a batch of tokens with explicit sampling parameters.
666
+ *
667
+ * - `temperature`: 0 = greedy, higher = more diverse
668
+ * - `top_p`: nucleus sampling (1.0 = disabled)
669
+ * - `top_k`: top-k sampling, applied when `top_p` is 1.0 and `min_p` is 0.0 (0 = disabled)
670
+ * - `repeat_penalty`: repetition penalty applied to recently-seen tokens (1.0 = disabled)
671
+ * - `min_p`: min-p threshold (0.0 = disabled); applied after `top_p`, before `top_k`
672
+ *
673
+ * Stops early at EOS. Uses a fixed LCG RNG seed for reproducibility.
674
+ * @param {Uint32Array} prompt_tokens
675
+ * @param {number} max_tokens
676
+ * @param {number} temperature
677
+ * @param {number} top_p
678
+ * @param {number} top_k
679
+ * @param {number} repeat_penalty
680
+ * @param {number} min_p
681
+ * @returns {Uint32Array}
682
+ */
683
+ generate_with_params(prompt_tokens, max_tokens, temperature, top_p, top_k, repeat_penalty, min_p) {
684
+ const ptr0 = passArray32ToWasm0(prompt_tokens, wasm.__wbindgen_malloc);
685
+ const len0 = WASM_VECTOR_LEN;
686
+ const ret = wasm.flareengine_generate_with_params(this.__wbg_ptr, ptr0, len0, max_tokens, temperature, top_p, top_k, repeat_penalty, min_p);
687
+ var v2 = getArrayU32FromWasm0(ret[0], ret[1]).slice();
688
+ wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
689
+ return v2;
690
+ }
691
+ /**
692
+ * Returns `true` if raw quantized weights are currently loaded.
693
+ * @returns {boolean}
694
+ */
695
+ get has_raw_weights() {
696
+ const ret = wasm.flareengine_has_raw_weights(this.__wbg_ptr);
697
+ return ret !== 0;
698
+ }
699
+ /**
700
+ * Get the hidden dimension.
701
+ * @returns {number}
702
+ */
703
+ get hidden_dim() {
704
+ const ret = wasm.flareengine_hidden_dim(this.__wbg_ptr);
705
+ return ret >>> 0;
706
+ }
707
+ /**
708
+ * Try to initialise the WebGPU compute backend.
709
+ *
710
+ * Call this after `load()` to enable GPU-accelerated matrix operations
711
+ * (matvec, matmul, silu_mul). Falls back silently to CPU if WebGPU is
712
+ * unavailable or adapter request fails.
713
+ *
714
+ * Returns `true` if a GPU backend was successfully initialised.
715
+ *
716
+ * ```javascript
717
+ * const engine = FlareEngine.load(bytes);
718
+ * const gpuEnabled = await engine.init_gpu();
719
+ * console.log('GPU:', gpuEnabled);
720
+ * ```
721
+ * @returns {Promise<boolean>}
722
+ */
723
+ init_gpu() {
724
+ const ret = wasm.flareengine_init_gpu(this.__wbg_ptr);
725
+ return ret;
726
+ }
727
+ /**
728
+ * Initialise the WebGPU backend using previously serialised pipeline cache
729
+ * bytes (from `engine.pipeline_cache_data()`).
730
+ *
731
+ * On backends that support driver-managed pipeline caches (Vulkan native),
732
+ * this allows the driver to reuse compiled GPU machine code from a previous
733
+ * run, eliminating cold-start shader recompilation (typically 100ms–2s).
734
+ *
735
+ * On unsupported backends (WebGPU, Metal, DX12) this behaves identically to
736
+ * `init_gpu()` — the cache bytes are silently ignored.
737
+ *
738
+ * ```javascript
739
+ * const cached = localStorage.getItem('flare-pipeline-cache');
740
+ * const cacheBytes = cached ? new Uint8Array(JSON.parse(cached)) : new Uint8Array();
741
+ * await engine.init_gpu_with_cache(cacheBytes);
742
+ * // After inference, persist the cache:
743
+ * const data = engine.pipeline_cache_data();
744
+ * if (data.length > 0) {
745
+ * localStorage.setItem('flare-pipeline-cache', JSON.stringify(Array.from(data)));
746
+ * }
747
+ * ```
748
+ * @param {Uint8Array} cache_data
749
+ * @returns {Promise<boolean>}
750
+ */
751
+ init_gpu_with_cache(cache_data) {
752
+ const ptr0 = passArray8ToWasm0(cache_data, wasm.__wbindgen_malloc);
753
+ const len0 = WASM_VECTOR_LEN;
754
+ const ret = wasm.flareengine_init_gpu_with_cache(this.__wbg_ptr, ptr0, len0);
755
+ return ret;
756
+ }
757
+ /**
758
+ * Milliseconds spent in decode steps of the last generation call.
759
+ *
760
+ * For batch generation (`generate_tokens` etc.) this is always 0 — see
761
+ * `last_prefill_ms` for the total time. For the streaming API this
762
+ * accumulates across all `next_token()` calls since the last
763
+ * `begin_stream()`.
764
+ * @returns {number}
765
+ */
766
+ get last_decode_ms() {
767
+ const ret = wasm.flareengine_last_decode_ms(this.__wbg_ptr);
768
+ return ret;
769
+ }
770
+ /**
771
+ * Raw pre-temperature logits from the most recent forward pass.
772
+ *
773
+ * Returns the full vocabulary logit vector as a `Float32Array`. These
774
+ * are the raw values *before* temperature scaling, repetition penalty,
775
+ * or any sampling filter — equivalent to the model's raw next-token
776
+ * distribution.
777
+ *
778
+ * Useful for:
779
+ * - Scoring candidate continuations (classification, ranking)
780
+ * - Computing perplexity / cross-entropy
781
+ * - Inspecting the model's "confidence" about the next token
782
+ *
783
+ * Returns an empty array before any inference has been run, and is
784
+ * cleared by `reset()`.
785
+ *
786
+ * ```javascript
787
+ * engine.begin_stream(promptIds, 1); // one token prefill+decode
788
+ * engine.next_token();
789
+ * const logits = engine.last_logits; // Float32Array of vocab_size
790
+ * const topTokenId = logits.indexOf(Math.max(...logits));
791
+ * ```
792
+ * @returns {Float32Array}
793
+ */
794
+ get last_logits() {
795
+ const ret = wasm.flareengine_last_logits(this.__wbg_ptr);
796
+ var v1 = getArrayF32FromWasm0(ret[0], ret[1]).slice();
797
+ wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
798
+ return v1;
799
+ }
800
+ /**
801
+ * Milliseconds spent in the last prefill (prompt processing) phase.
802
+ *
803
+ * For `generate_tokens` / `generate_text` / `generate_with_params` this
804
+ * covers the entire call (prefill + decode are not separated internally).
805
+ * For the streaming API (`begin_stream` + `next_token`) this covers only
806
+ * the `begin_stream()` call.
807
+ * @returns {number}
808
+ */
809
+ get last_prefill_ms() {
810
+ const ret = wasm.flareengine_last_prefill_ms(this.__wbg_ptr);
811
+ return ret;
812
+ }
813
+ /**
814
+ * Number of tokens generated by the last generation call (excludes prompt
815
+ * tokens and the EOS token itself).
816
+ * @returns {number}
817
+ */
818
+ get last_tokens_generated() {
819
+ const ret = wasm.flareengine_last_tokens_generated(this.__wbg_ptr);
820
+ return ret >>> 0;
821
+ }
822
+ /**
823
+ * Load a GGUF model from a Uint8Array of bytes (e.g. from `fetch`).
824
+ * @param {Uint8Array} gguf_bytes
825
+ * @returns {FlareEngine}
826
+ */
827
+ static load(gguf_bytes) {
828
+ const ptr0 = passArray8ToWasm0(gguf_bytes, wasm.__wbindgen_malloc);
829
+ const len0 = WASM_VECTOR_LEN;
830
+ const ret = wasm.flareengine_load(ptr0, len0);
831
+ if (ret[2]) {
832
+ throw takeFromExternrefTable0(ret[1]);
833
+ }
834
+ return FlareEngine.__wrap(ret[0]);
835
+ }
836
+ /**
837
+ * Load raw quantized weights from GGUF bytes so the GPU fused
838
+ * dequant+matvec kernels can be used during inference.
839
+ *
840
+ * Call this **after** `init_gpu()` so the backend is set before the raw
841
+ * weights are attached. The method is a no-op (returns `false`) if a
842
+ * layer's weights are in an unsupported quantization format — the engine
843
+ * continues to work using the f32 path loaded at `FlareEngine.load()`.
844
+ *
845
+ * Returns `true` if all layers were loaded successfully, `false` if any
846
+ * layer fell back to the f32 path.
847
+ *
848
+ * ```javascript
849
+ * const engine = FlareEngine.load(bytes);
850
+ * await engine.init_gpu();
851
+ * const ok = engine.load_raw_weights(bytes);
852
+ * console.log('Raw weights loaded:', ok);
853
+ * ```
854
+ * @param {Uint8Array} gguf_bytes
855
+ * @returns {boolean}
856
+ */
857
+ load_raw_weights(gguf_bytes) {
858
+ const ptr0 = passArray8ToWasm0(gguf_bytes, wasm.__wbindgen_malloc);
859
+ const len0 = WASM_VECTOR_LEN;
860
+ const ret = wasm.flareengine_load_raw_weights(this.__wbg_ptr, ptr0, len0);
861
+ return ret !== 0;
862
+ }
863
+ /**
864
+ * Maximum sequence length (context window size) of the loaded model.
865
+ *
866
+ * Use this to warn users when their prompt is approaching the limit.
867
+ * @returns {number}
868
+ */
869
+ get max_seq_len() {
870
+ const ret = wasm.flareengine_max_seq_len(this.__wbg_ptr);
871
+ return ret >>> 0;
872
+ }
873
+ /**
874
+ * Merge a LoRA adapter (SafeTensors format) into the model weights.
875
+ *
876
+ * Pass the raw bytes of a `.safetensors` file containing LoRA A/B matrices.
877
+ * After merging, the adapter's effect is permanent for this engine instance;
878
+ * call `FlareEngine.load()` again to restore the base model.
879
+ *
880
+ * ```javascript
881
+ * const resp = await fetch('lora-adapter.safetensors');
882
+ * const bytes = new Uint8Array(await resp.arrayBuffer());
883
+ * engine.merge_lora(bytes);
884
+ * ```
885
+ * @param {Uint8Array} adapter_bytes
886
+ */
887
+ merge_lora(adapter_bytes) {
888
+ const ptr0 = passArray8ToWasm0(adapter_bytes, wasm.__wbindgen_malloc);
889
+ const len0 = WASM_VECTOR_LEN;
890
+ const ret = wasm.flareengine_merge_lora(this.__wbg_ptr, ptr0, len0);
891
+ if (ret[1]) {
892
+ throw takeFromExternrefTable0(ret[0]);
893
+ }
894
+ }
895
+ /**
896
+ * Merge a LoRA adapter with a custom alpha scaling factor.
897
+ *
898
+ * Same as `merge_lora` but overrides the alpha value embedded in the
899
+ * adapter file. The effective scaling is `alpha / rank`.
900
+ * @param {Uint8Array} adapter_bytes
901
+ * @param {number} alpha
902
+ */
903
+ merge_lora_with_alpha(adapter_bytes, alpha) {
904
+ const ptr0 = passArray8ToWasm0(adapter_bytes, wasm.__wbindgen_malloc);
905
+ const len0 = WASM_VECTOR_LEN;
906
+ const ret = wasm.flareengine_merge_lora_with_alpha(this.__wbg_ptr, ptr0, len0, alpha);
907
+ if (ret[1]) {
908
+ throw takeFromExternrefTable0(ret[0]);
909
+ }
910
+ }
911
+ /**
912
+ * All GGUF model metadata as a JSON string.
913
+ *
914
+ * Returns a JSON object mapping each metadata key to its value.
915
+ * Large vocabulary arrays (`tokenizer.ggml.tokens`, `.merges`, `.scores`,
916
+ * `.added_tokens`) are omitted to keep the payload practical.
917
+ * Small arrays (≤ 64 entries) are included as JSON arrays.
918
+ *
919
+ * Returns `"{}"` if the model was not loaded from a GGUF file.
920
+ *
921
+ * ```javascript
922
+ * const meta = JSON.parse(engine.metadata_json);
923
+ * console.log(meta["llama.context_length"]); // e.g. 4096
924
+ * ```
925
+ * @returns {string}
926
+ */
927
+ get metadata_json() {
928
+ let deferred1_0;
929
+ let deferred1_1;
930
+ try {
931
+ const ret = wasm.flareengine_metadata_json(this.__wbg_ptr);
932
+ deferred1_0 = ret[0];
933
+ deferred1_1 = ret[1];
934
+ return getStringFromWasm0(ret[0], ret[1]);
935
+ } finally {
936
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
937
+ }
938
+ }
939
+ /**
940
+ * Model display name from `general.name` in the GGUF metadata.
941
+ *
942
+ * Returns the human-readable name embedded by the model author (e.g.
943
+ * `"Llama 3.2 1B Instruct"`). Returns an empty string if the field is absent.
944
+ * @returns {string}
945
+ */
946
+ get model_name() {
947
+ let deferred1_0;
948
+ let deferred1_1;
949
+ try {
950
+ const ret = wasm.flareengine_model_name(this.__wbg_ptr);
951
+ deferred1_0 = ret[0];
952
+ deferred1_1 = ret[1];
953
+ return getStringFromWasm0(ret[0], ret[1]);
954
+ } finally {
955
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
956
+ }
957
+ }
958
+ /**
959
+ * Generate and return the next token ID, or `undefined` when the stream
960
+ * is complete (EOS reached, `max_tokens` exhausted, or `stop_stream()`
961
+ * was called).
962
+ *
963
+ * Sampling parameters are those set by the most recent `begin_stream` or
964
+ * `begin_stream_with_params` call. Call this inside
965
+ * `requestAnimationFrame` so the browser can update the DOM between
966
+ * tokens and the page remains responsive.
967
+ * @returns {number | undefined}
968
+ */
969
+ next_token() {
970
+ const ret = wasm.flareengine_next_token(this.__wbg_ptr);
971
+ return ret === 0x100000001 ? undefined : ret;
972
+ }
973
+ /**
974
+ * Get the number of attention heads.
975
+ * @returns {number}
976
+ */
977
+ get num_heads() {
978
+ const ret = wasm.flareengine_num_heads(this.__wbg_ptr);
979
+ return ret >>> 0;
980
+ }
981
+ /**
982
+ * Get the number of layers.
983
+ * @returns {number}
984
+ */
985
+ get num_layers() {
986
+ const ret = wasm.flareengine_num_layers(this.__wbg_ptr);
987
+ return ret >>> 0;
988
+ }
989
+ /**
990
+ * Apply final RMSNorm + output projection to a hidden state and
991
+ * return logits over the vocabulary.
992
+ *
993
+ * `hidden` must have length `hidden_dim`. The returned vector has
994
+ * length `vocab_size`.
995
+ * @param {Float32Array} hidden
996
+ * @returns {Float32Array}
997
+ */
998
+ output_projection(hidden) {
999
+ const ptr0 = passArrayF32ToWasm0(hidden, wasm.__wbindgen_malloc);
1000
+ const len0 = WASM_VECTOR_LEN;
1001
+ const ret = wasm.flareengine_output_projection(this.__wbg_ptr, ptr0, len0);
1002
+ var v2 = getArrayF32FromWasm0(ret[0], ret[1]).slice();
1003
+ wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
1004
+ return v2;
1005
+ }
1006
+ /**
1007
+ * Return a JSON string summarising the performance metrics from the last
1008
+ * generation call.
1009
+ *
1010
+ * ```javascript
1011
+ * const perf = JSON.parse(engine.performance_summary());
1012
+ * console.log(`TTFT: ${perf.prefill_ms.toFixed(1)} ms`);
1013
+ * console.log(`Decode: ${perf.tokens_per_second.toFixed(1)} tok/s`);
1014
+ * ```
1015
+ * @returns {string}
1016
+ */
1017
+ performance_summary() {
1018
+ let deferred1_0;
1019
+ let deferred1_1;
1020
+ try {
1021
+ const ret = wasm.flareengine_performance_summary(this.__wbg_ptr);
1022
+ deferred1_0 = ret[0];
1023
+ deferred1_1 = ret[1];
1024
+ return getStringFromWasm0(ret[0], ret[1]);
1025
+ } finally {
1026
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
1027
+ }
1028
+ }
1029
+ /**
1030
+ * Serialise the driver-managed GPU pipeline cache to bytes.
1031
+ *
1032
+ * Returns an opaque blob that can be passed to `init_gpu_with_cache()` on
1033
+ * the next startup to skip shader recompilation. Store it in
1034
+ * `localStorage` or `IndexedDB` between page loads.
1035
+ *
1036
+ * Returns an empty `Uint8Array` if no GPU is active, or if the current
1037
+ * backend does not support pipeline caching (WebGPU, Metal, DX12).
1038
+ * @returns {Uint8Array}
1039
+ */
1040
+ get pipeline_cache_data() {
1041
+ const ret = wasm.flareengine_pipeline_cache_data(this.__wbg_ptr);
1042
+ var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
1043
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
1044
+ return v1;
1045
+ }
1046
+ /**
1047
+ * Raw Jinja2 chat template string from the GGUF model metadata, if present.
1048
+ *
1049
+ * This is the `tokenizer.chat_template` field embedded by the model author.
1050
+ * Use this with a JavaScript Jinja2 renderer (e.g. `nunjucks`) for accurate
1051
+ * prompt formatting across all model families, rather than relying on the
1052
+ * simplified built-in `apply_chat_template`.
1053
+ *
1054
+ * Returns `undefined` if the GGUF file did not include a chat template.
1055
+ * @returns {string | undefined}
1056
+ */
1057
+ get raw_chat_template() {
1058
+ const ret = wasm.flareengine_raw_chat_template(this.__wbg_ptr);
1059
+ let v1;
1060
+ if (ret[0] !== 0) {
1061
+ v1 = getStringFromWasm0(ret[0], ret[1]).slice();
1062
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
1063
+ }
1064
+ return v1;
1065
+ }
1066
+ /**
1067
+ * Current repetition-penalty window size (0 = disabled).
1068
+ * @returns {number}
1069
+ */
1070
+ get repeat_last_n() {
1071
+ const ret = wasm.flareengine_repeat_last_n(this.__wbg_ptr);
1072
+ return ret >>> 0;
1073
+ }
1074
+ /**
1075
+ * Reset the KV cache (start a new conversation).
1076
+ *
1077
+ * Also clears stop sequences, the internal text accumulator, and
1078
+ * restores the RNG seed to the default `0x12345678`.
1079
+ */
1080
+ reset() {
1081
+ wasm.flareengine_reset(this.__wbg_ptr);
1082
+ }
1083
+ /**
1084
+ * Set the repetition-penalty look-back window (number of recent tokens to
1085
+ * penalise). Use `0` to disable repetition penalty entirely. Default: 64.
1086
+ *
1087
+ * Takes effect on the next `begin_stream*` call.
1088
+ *
1089
+ * # JS example
1090
+ * ```javascript
1091
+ * engine.set_repeat_last_n(128); // wider window for creative writing
1092
+ * engine.set_repeat_last_n(0); // disable repeat penalty
1093
+ * ```
1094
+ * @param {number} n
1095
+ */
1096
+ set_repeat_last_n(n) {
1097
+ wasm.flareengine_set_repeat_last_n(this.__wbg_ptr, n);
1098
+ }
1099
+ /**
1100
+ * Set the LCG RNG seed used for the next sampled generation call.
1101
+ *
1102
+ * Controls the random state passed to `begin_stream_with_params` and
1103
+ * `generate_with_params`, enabling reproducible outputs. The seed is
1104
+ * applied on the next call and then *not* automatically reset, so the
1105
+ * same seed will be reused on subsequent calls unless `set_rng_seed` or
1106
+ * `reset()` is called again.
1107
+ *
1108
+ * `reset()` restores the seed to the default `0x12345678`.
1109
+ *
1110
+ * ```javascript
1111
+ * engine.set_rng_seed(42);
1112
+ * const out1 = engine.generate_text("Hello", 50);
1113
+ * engine.set_rng_seed(42);
1114
+ * const out2 = engine.generate_text("Hello", 50);
1115
+ * // out1 === out2
1116
+ * ```
1117
+ * @param {number} seed
1118
+ */
1119
+ set_rng_seed(seed) {
1120
+ wasm.flareengine_set_rng_seed(this.__wbg_ptr, seed);
1121
+ }
1122
+ /**
1123
+ * Set how many top log-probability entries to capture after each forward
1124
+ * pass. Pass `0` (the default) to disable and save the computation.
1125
+ *
1126
+ * When enabled, `top_logprobs` is populated after every `next_token()`
1127
+ * call and after every token in `generate_stream_with_params`.
1128
+ *
1129
+ * # JS example
1130
+ * ```javascript
1131
+ * engine.set_top_logprobs(5);
1132
+ * engine.begin_stream(promptIds, 64);
1133
+ * while (!engine.stream_done) {
1134
+ * engine.next_token();
1135
+ * const lp = engine.top_logprobs; // Float32Array [id0, lp0, id1, lp1, ...]
1136
+ * }
1137
+ * ```
1138
+ * @param {number} n
1139
+ */
1140
+ set_top_logprobs(n) {
1141
+ wasm.flareengine_set_top_logprobs(this.__wbg_ptr, n);
1142
+ }
1143
+ /**
1144
+ * Signal the current stream to stop after the next `next_token()` call.
1145
+ * The JS Stop button should call this, then wait for `next_token()` to
1146
+ * return `undefined` before updating the UI.
1147
+ */
1148
+ stop_stream() {
1149
+ wasm.flareengine_stop_stream(this.__wbg_ptr);
1150
+ }
1151
+ /**
1152
+ * Whether the current stream has finished.
1153
+ * @returns {boolean}
1154
+ */
1155
+ get stream_done() {
1156
+ const ret = wasm.flareengine_stream_done(this.__wbg_ptr);
1157
+ return ret !== 0;
1158
+ }
1159
+ /**
1160
+ * Why the most-recent stream stopped.
1161
+ *
1162
+ * Returns one of:
1163
+ * - `"eos"` — the model emitted the EOS token
1164
+ * - `"length"` — `max_tokens` budget was exhausted
1165
+ * - `"stop_sequence"` — a registered stop sequence was matched
1166
+ * - `"user"` — `stop_stream()` was called
1167
+ * - `""` (empty) — stream not yet started or still running
1168
+ *
1169
+ * # JS example
1170
+ * ```javascript
1171
+ * while (!engine.stream_done) engine.next_token();
1172
+ * console.log("Stopped because:", engine.stream_stop_reason);
1173
+ * ```
1174
+ * @returns {string}
1175
+ */
1176
+ get stream_stop_reason() {
1177
+ let deferred1_0;
1178
+ let deferred1_1;
1179
+ try {
1180
+ const ret = wasm.flareengine_stream_stop_reason(this.__wbg_ptr);
1181
+ deferred1_0 = ret[0];
1182
+ deferred1_1 = ret[1];
1183
+ return getStringFromWasm0(ret[0], ret[1]);
1184
+ } finally {
1185
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
1186
+ }
1187
+ }
1188
+ /**
1189
+ * Decode throughput in tokens per second for the last generation call.
1190
+ *
1191
+ * For the streaming API this is calculated from `last_decode_ms`.
1192
+ * For batch generation this is calculated from `last_prefill_ms`
1193
+ * (the total call duration).
1194
+ *
1195
+ * Returns 0.0 if no generation has been run or if timing data is
1196
+ * unavailable.
1197
+ * @returns {number}
1198
+ */
1199
+ get tokens_per_second() {
1200
+ const ret = wasm.flareengine_tokens_per_second(this.__wbg_ptr);
1201
+ return ret;
1202
+ }
1203
+ /**
1204
+ * How many tokens of context space remain before the window is full.
1205
+ *
1206
+ * Equivalent to `max_seq_len - tokens_used`. Returns 0 when the context is
1207
+ * already full or `max_seq_len` is 0.
1208
+ *
1209
+ * # JS example
1210
+ * ```javascript
1211
+ * if (engine.tokens_remaining < 64) {
1212
+ * console.warn("Context window almost full — consider resetting.");
1213
+ * }
1214
+ * ```
1215
+ * @returns {number}
1216
+ */
1217
+ get tokens_remaining() {
1218
+ const ret = wasm.flareengine_tokens_remaining(this.__wbg_ptr);
1219
+ return ret >>> 0;
1220
+ }
1221
+ /**
1222
+ * Number of tokens currently consumed in the KV-cache session (prompt + generated).
1223
+ *
1224
+ * Updated after every generation call; reset to 0 by `engine.reset()`.
1225
+ * Use with `max_seq_len` to build a context-usage progress bar.
1226
+ * @returns {number}
1227
+ */
1228
+ get tokens_used() {
1229
+ const ret = wasm.flareengine_tokens_used(this.__wbg_ptr);
1230
+ return ret >>> 0;
1231
+ }
1232
+ /**
1233
+ * Interleaved top-N log-probabilities from the last forward pass.
1234
+ *
1235
+ * Layout: `[token_id_0 as f32, log_prob_0, token_id_1 as f32, log_prob_1, ...]`
1236
+ * sorted by descending log-probability. Length is `top_logprobs_n * 2`.
1237
+ *
1238
+ * Returns an empty array if `set_top_logprobs(0)` (default) or before
1239
+ * any inference has been run.
1240
+ * @returns {Float32Array}
1241
+ */
1242
+ get top_logprobs() {
1243
+ const ret = wasm.flareengine_top_logprobs(this.__wbg_ptr);
1244
+ var v1 = getArrayF32FromWasm0(ret[0], ret[1]).slice();
1245
+ wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
1246
+ return v1;
1247
+ }
1248
+ /**
1249
+ * Truncate `text` so that it fits within `budget` tokens when encoded.
1250
+ *
1251
+ * Encodes `text` with the embedded GGUF vocabulary, keeps the **last**
1252
+ * `budget` tokens (tail of the text is preferred, so recent context is
1253
+ * preserved), and decodes them back to a string. Returns `text` unchanged
1254
+ * if it already fits or if no vocab is available.
1255
+ *
1256
+ * A typical call reserves space for the system prompt + generated output:
1257
+ *
1258
+ * ```javascript
1259
+ * // Keep only the tail of the conversation that fits in the context
1260
+ * const budget = engine.max_seq_len - 256; // leave 256 tokens for output
1261
+ * const trimmed = engine.truncate_to_context(conversationText, budget);
1262
+ * ```
1263
+ * @param {string} text
1264
+ * @param {number} budget
1265
+ * @returns {string}
1266
+ */
1267
+ truncate_to_context(text, budget) {
1268
+ let deferred2_0;
1269
+ let deferred2_1;
1270
+ try {
1271
+ const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1272
+ const len0 = WASM_VECTOR_LEN;
1273
+ const ret = wasm.flareengine_truncate_to_context(this.__wbg_ptr, ptr0, len0, budget);
1274
+ deferred2_0 = ret[0];
1275
+ deferred2_1 = ret[1];
1276
+ return getStringFromWasm0(ret[0], ret[1]);
1277
+ } finally {
1278
+ wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
1279
+ }
1280
+ }
1281
+ /**
1282
+ * Get the vocabulary size of the loaded model.
1283
+ * @returns {number}
1284
+ */
1285
+ get vocab_size() {
1286
+ const ret = wasm.flareengine_vocab_size(this.__wbg_ptr);
1287
+ return ret >>> 0;
1288
+ }
1289
+ /**
1290
+ * Run a single dummy forward pass to pre-compile WebGPU shader pipelines.
1291
+ *
1292
+ * WebGPU (and wgpu on native) compiles shader pipelines lazily on the
1293
+ * first dispatch. This causes a noticeable latency spike — often 100ms
1294
+ * to several seconds — when the user makes their first inference request.
1295
+ *
1296
+ * Call `warmup()` once after `init_gpu()` completes to trigger all shader
1297
+ * compilations in the background so the first real request feels fast.
1298
+ * The KV cache is reset after the warmup so the engine is in a clean state.
1299
+ *
1300
+ * Returns `true` if the warmup forward pass ran without error, `false` if
1301
+ * the model has not been loaded.
1302
+ *
1303
+ * # JS example
1304
+ * ```javascript
1305
+ * const engine = FlareEngine.load(bytes);
1306
+ * await engine.init_gpu();
1307
+ * engine.warmup(); // trigger shader compilation
1308
+ * // First real inference is now fast
1309
+ * engine.begin_stream(promptIds, 128);
1310
+ * ```
1311
+ * @returns {boolean}
1312
+ */
1313
+ warmup() {
1314
+ const ret = wasm.flareengine_warmup(this.__wbg_ptr);
1315
+ return ret !== 0;
1316
+ }
1317
+ }
1318
+ if (Symbol.dispose) FlareEngine.prototype[Symbol.dispose] = FlareEngine.prototype.free;
1319
+
1320
+ /**
1321
+ * Progressive loader that fetches a GGUF model from a URL with streaming
1322
+ * download progress.
1323
+ *
1324
+ * This enables the browser demo to show download progress as the model
1325
+ * arrives over the network, then layer-loading progress as the model is
1326
+ * parsed. For a 500MB Q4 model the download phase dominates; displaying
1327
+ * progress prevents the page from appearing frozen.
1328
+ *
1329
+ * # JS example
1330
+ *
1331
+ * ```javascript
1332
+ * const loader = new FlareProgressiveLoader('https://example.com/model.gguf');
1333
+ * const engine = await loader.load((loaded, total) => {
1334
+ * const pct = total > 0 ? Math.round(loaded / total * 100) : 0;
1335
+ * progressBar.value = pct / 100;
1336
+ * statusText.textContent = `Downloading… ${pct}%`;
1337
+ * });
1338
+ * ```
1339
+ */
1340
+ export class FlareProgressiveLoader {
1341
+ __destroy_into_raw() {
1342
+ const ptr = this.__wbg_ptr;
1343
+ this.__wbg_ptr = 0;
1344
+ FlareProgressiveLoaderFinalization.unregister(this);
1345
+ return ptr;
1346
+ }
1347
+ free() {
1348
+ const ptr = this.__destroy_into_raw();
1349
+ wasm.__wbg_flareprogressiveloader_free(ptr, 0);
1350
+ }
1351
+ /**
1352
+ * Fetch the model from the URL, calling `on_progress(loaded_bytes, total_bytes)`
1353
+ * as each chunk arrives, then parse and return a `FlareEngine`.
1354
+ *
1355
+ * `total_bytes` is 0 when the server does not send a `Content-Length` header
1356
+ * (e.g. when the response is gzip-compressed or chunked).
1357
+ * @param {Function} on_progress
1358
+ * @returns {Promise<FlareEngine>}
1359
+ */
1360
+ load(on_progress) {
1361
+ const ret = wasm.flareprogressiveloader_load(this.__wbg_ptr, on_progress);
1362
+ return ret;
1363
+ }
1364
+ /**
1365
+ * Create a loader for the given model URL.
1366
+ * @param {string} url
1367
+ */
1368
+ constructor(url) {
1369
+ const ptr0 = passStringToWasm0(url, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1370
+ const len0 = WASM_VECTOR_LEN;
1371
+ const ret = wasm.flareprogressiveloader_new(ptr0, len0);
1372
+ this.__wbg_ptr = ret >>> 0;
1373
+ FlareProgressiveLoaderFinalization.register(this, this.__wbg_ptr, this);
1374
+ return this;
1375
+ }
1376
+ }
1377
+ if (Symbol.dispose) FlareProgressiveLoader.prototype[Symbol.dispose] = FlareProgressiveLoader.prototype.free;
1378
+
1379
+ /**
1380
+ * BPE tokenizer exported to JS for encoding prompts and decoding generated tokens.
1381
+ *
1382
+ * Load from a HuggingFace `tokenizer.json` string, then use `encode` / `decode`
1383
+ * in coordination with `FlareEngine` to run full text-in / text-out inference.
1384
+ *
1385
+ * # JS example
1386
+ *
1387
+ * ```javascript
1388
+ * const resp = await fetch('tokenizer.json');
1389
+ * const json = await resp.text();
1390
+ * const tok = FlareTokenizer.from_json(json);
1391
+ *
1392
+ * const ids = tok.encode("Hello, world!");
1393
+ * const engine = FlareEngine.load(modelBytes);
1394
+ * const out = engine.generate_tokens(ids, 64);
1395
+ * console.log(tok.decode(out));
1396
+ * ```
1397
+ */
1398
+ export class FlareTokenizer {
1399
+ static __wrap(ptr) {
1400
+ ptr = ptr >>> 0;
1401
+ const obj = Object.create(FlareTokenizer.prototype);
1402
+ obj.__wbg_ptr = ptr;
1403
+ FlareTokenizerFinalization.register(obj, obj.__wbg_ptr, obj);
1404
+ return obj;
1405
+ }
1406
+ __destroy_into_raw() {
1407
+ const ptr = this.__wbg_ptr;
1408
+ this.__wbg_ptr = 0;
1409
+ FlareTokenizerFinalization.unregister(this);
1410
+ return ptr;
1411
+ }
1412
+ free() {
1413
+ const ptr = this.__destroy_into_raw();
1414
+ wasm.__wbg_flaretokenizer_free(ptr, 0);
1415
+ }
1416
+ /**
1417
+ * BOS (beginning of sequence) token ID, if defined.
1418
+ * @returns {number | undefined}
1419
+ */
1420
+ get bos_token_id() {
1421
+ const ret = wasm.flaretokenizer_bos_token_id(this.__wbg_ptr);
1422
+ return ret === 0x100000001 ? undefined : ret;
1423
+ }
1424
+ /**
1425
+ * Decode a sequence of token IDs to text.
1426
+ * @param {Uint32Array} tokens
1427
+ * @returns {string}
1428
+ */
1429
+ decode(tokens) {
1430
+ let deferred3_0;
1431
+ let deferred3_1;
1432
+ try {
1433
+ const ptr0 = passArray32ToWasm0(tokens, wasm.__wbindgen_malloc);
1434
+ const len0 = WASM_VECTOR_LEN;
1435
+ const ret = wasm.flaretokenizer_decode(this.__wbg_ptr, ptr0, len0);
1436
+ var ptr2 = ret[0];
1437
+ var len2 = ret[1];
1438
+ if (ret[3]) {
1439
+ ptr2 = 0; len2 = 0;
1440
+ throw takeFromExternrefTable0(ret[2]);
1441
+ }
1442
+ deferred3_0 = ptr2;
1443
+ deferred3_1 = len2;
1444
+ return getStringFromWasm0(ptr2, len2);
1445
+ } finally {
1446
+ wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
1447
+ }
1448
+ }
1449
+ /**
1450
+ * Decode a single token ID to text (useful for streaming output).
1451
+ * @param {number} token_id
1452
+ * @returns {string}
1453
+ */
1454
+ decode_one(token_id) {
1455
+ let deferred2_0;
1456
+ let deferred2_1;
1457
+ try {
1458
+ const ret = wasm.flaretokenizer_decode_one(this.__wbg_ptr, token_id);
1459
+ var ptr1 = ret[0];
1460
+ var len1 = ret[1];
1461
+ if (ret[3]) {
1462
+ ptr1 = 0; len1 = 0;
1463
+ throw takeFromExternrefTable0(ret[2]);
1464
+ }
1465
+ deferred2_0 = ptr1;
1466
+ deferred2_1 = len1;
1467
+ return getStringFromWasm0(ptr1, len1);
1468
+ } finally {
1469
+ wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
1470
+ }
1471
+ }
1472
+ /**
1473
+ * Encode text to a sequence of token IDs.
1474
+ * @param {string} text
1475
+ * @returns {Uint32Array}
1476
+ */
1477
+ encode(text) {
1478
+ const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1479
+ const len0 = WASM_VECTOR_LEN;
1480
+ const ret = wasm.flaretokenizer_encode(this.__wbg_ptr, ptr0, len0);
1481
+ if (ret[3]) {
1482
+ throw takeFromExternrefTable0(ret[2]);
1483
+ }
1484
+ var v2 = getArrayU32FromWasm0(ret[0], ret[1]).slice();
1485
+ wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
1486
+ return v2;
1487
+ }
1488
+ /**
1489
+ * EOS (end of sequence) token ID, if defined.
1490
+ * @returns {number | undefined}
1491
+ */
1492
+ get eos_token_id() {
1493
+ const ret = wasm.flaretokenizer_eos_token_id(this.__wbg_ptr);
1494
+ return ret === 0x100000001 ? undefined : ret;
1495
+ }
1496
+ /**
1497
+ * Load a tokenizer from the text of a HuggingFace `tokenizer.json` file.
1498
+ * @param {string} json
1499
+ * @returns {FlareTokenizer}
1500
+ */
1501
+ static from_json(json) {
1502
+ const ptr0 = passStringToWasm0(json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1503
+ const len0 = WASM_VECTOR_LEN;
1504
+ const ret = wasm.flaretokenizer_from_json(ptr0, len0);
1505
+ if (ret[2]) {
1506
+ throw takeFromExternrefTable0(ret[1]);
1507
+ }
1508
+ return FlareTokenizer.__wrap(ret[0]);
1509
+ }
1510
+ /**
1511
+ * Vocabulary size.
1512
+ * @returns {number}
1513
+ */
1514
+ get vocab_size() {
1515
+ const ret = wasm.flaretokenizer_vocab_size(this.__wbg_ptr);
1516
+ return ret >>> 0;
1517
+ }
1518
+ }
1519
+ if (Symbol.dispose) FlareTokenizer.prototype[Symbol.dispose] = FlareTokenizer.prototype.free;
1520
+
1521
+ /**
1522
+ * Save model bytes to OPFS.
1523
+ *
1524
+ * Creates the `flare-models` directory if it does not exist. Overwrites any
1525
+ * existing file with the same name.
1526
+ * @param {string} model_name
1527
+ * @param {Uint8Array} data
1528
+ * @returns {Promise<void>}
1529
+ */
1530
+ export function cache_model(model_name, data) {
1531
+ const ptr0 = passStringToWasm0(model_name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1532
+ const len0 = WASM_VECTOR_LEN;
1533
+ const ptr1 = passArray8ToWasm0(data, wasm.__wbindgen_malloc);
1534
+ const len1 = WASM_VECTOR_LEN;
1535
+ const ret = wasm.cache_model(ptr0, len0, ptr1, len1);
1536
+ return ret;
1537
+ }
1538
+
1539
+ /**
1540
+ * Delete a cached model from OPFS.
1541
+ * @param {string} model_name
1542
+ * @returns {Promise<void>}
1543
+ */
1544
+ export function delete_cached_model(model_name) {
1545
+ const ptr0 = passStringToWasm0(model_name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1546
+ const len0 = WASM_VECTOR_LEN;
1547
+ const ret = wasm.delete_cached_model(ptr0, len0);
1548
+ return ret;
1549
+ }
1550
+
1551
+ /**
1552
+ * Get basic device info as a JSON string.
1553
+ * @returns {string}
1554
+ */
1555
+ export function device_info() {
1556
+ let deferred1_0;
1557
+ let deferred1_1;
1558
+ try {
1559
+ const ret = wasm.device_info();
1560
+ deferred1_0 = ret[0];
1561
+ deferred1_1 = ret[1];
1562
+ return getStringFromWasm0(ret[0], ret[1]);
1563
+ } finally {
1564
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
1565
+ }
1566
+ }
1567
+
1568
+ /**
1569
+ * Check if a model is cached in OPFS by name.
1570
+ *
1571
+ * Returns `false` if OPFS is unavailable or the model is not found.
1572
+ * @param {string} model_name
1573
+ * @returns {Promise<boolean>}
1574
+ */
1575
+ export function is_model_cached(model_name) {
1576
+ const ptr0 = passStringToWasm0(model_name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1577
+ const len0 = WASM_VECTOR_LEN;
1578
+ const ret = wasm.is_model_cached(ptr0, len0);
1579
+ return ret;
1580
+ }
1581
+
1582
+ /**
1583
+ * List all cached models with their sizes (in bytes).
1584
+ *
1585
+ * Returns a JSON-serialised array of objects: `[{name: string, size: number}, ...]`.
1586
+ * Returns `"[]"` if OPFS is unavailable or the models directory does not exist.
1587
+ * @returns {Promise<any>}
1588
+ */
1589
+ export function list_cached_models() {
1590
+ const ret = wasm.list_cached_models();
1591
+ return ret;
1592
+ }
1593
+
1594
+ /**
1595
+ * Load model bytes from OPFS.
1596
+ *
1597
+ * Returns `null` (JS) / `None` (Rust) if the model is not cached or OPFS is
1598
+ * unavailable.
1599
+ * @param {string} model_name
1600
+ * @returns {Promise<any>}
1601
+ */
1602
+ export function load_cached_model(model_name) {
1603
+ const ptr0 = passStringToWasm0(model_name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1604
+ const len0 = WASM_VECTOR_LEN;
1605
+ const ret = wasm.load_cached_model(ptr0, len0);
1606
+ return ret;
1607
+ }
1608
+
1609
+ /**
1610
+ * Set up better panic messages in the browser console.
1611
+ */
1612
+ export function start() {
1613
+ wasm.start();
1614
+ }
1615
+
1616
+ /**
1617
+ * Get storage usage and quota estimate.
1618
+ *
1619
+ * Returns a JSON string: `{usage: number, quota: number}`.
1620
+ * Returns `"{}"` if the Storage API is unavailable.
1621
+ * @returns {Promise<any>}
1622
+ */
1623
+ export function storage_estimate() {
1624
+ const ret = wasm.storage_estimate();
1625
+ return ret;
1626
+ }
1627
+
1628
+ /**
1629
+ * Check if this WASM build was compiled with relaxed SIMD support.
1630
+ *
1631
+ * Relaxed SIMD provides hardware-specific faster operations like fused
1632
+ * multiply-add (`f32x4_relaxed_madd`) that map directly to ARM NEON and
1633
+ * x86 SSE/AVX FMA instructions. When enabled, matvec operations use FMA
1634
+ * for ~15-30% speedup.
1635
+ *
1636
+ * This is a compile-time feature: the WASM binary either includes relaxed
1637
+ * SIMD instructions or it does not. The browser validates them at module
1638
+ * load time, so if this module loaded successfully and returns `true`,
1639
+ * relaxed SIMD is active.
1640
+ * @returns {boolean}
1641
+ */
1642
+ export function supports_relaxed_simd() {
1643
+ const ret = wasm.supports_relaxed_simd();
1644
+ return ret !== 0;
1645
+ }
1646
+
1647
+ /**
1648
+ * Check if the browser exposes the Web Speech API for speech recognition.
1649
+ *
1650
+ * This probes `window.SpeechRecognition` and the WebKit-prefixed
1651
+ * `window.webkitSpeechRecognition`. Returning `true` means the demo voice
1652
+ * mode can capture microphone input and produce transcripts through the
1653
+ * platform speech engine. This is a foundation for the voice pipeline
1654
+ * (issue #395); a fully offline path will eventually run Whisper in WASM.
1655
+ * @returns {boolean}
1656
+ */
1657
+ export function supports_speech_recognition() {
1658
+ const ret = wasm.supports_speech_recognition();
1659
+ return ret !== 0;
1660
+ }
1661
+
1662
+ /**
1663
+ * Check if the browser exposes the Web Speech API for speech synthesis.
1664
+ *
1665
+ * Returns `true` when `window.speechSynthesis` is available, enabling the
1666
+ * demo voice mode to speak model responses. A fully offline path will
1667
+ * eventually run a neural TTS model in WASM.
1668
+ * @returns {boolean}
1669
+ */
1670
+ export function supports_speech_synthesis() {
1671
+ const ret = wasm.supports_speech_synthesis();
1672
+ return ret !== 0;
1673
+ }
1674
+
1675
+ /**
1676
+ * Check if WebNN is available in the current browser.
1677
+ *
1678
+ * WebNN (`navigator.ml`) exposes neural-network acceleration through
1679
+ * platform NPUs/DSPs. This is a foundation check so JS code can decide
1680
+ * whether to build a WebNN graph from exported weights.
1681
+ * @returns {boolean}
1682
+ */
1683
+ export function supports_webnn() {
1684
+ const ret = wasm.supports_webnn();
1685
+ return ret !== 0;
1686
+ }
1687
+
1688
+ /**
1689
+ * Check if WebTransport is available in the current browser.
1690
+ *
1691
+ * WebTransport (`window.WebTransport`) is a modern transport API built on
1692
+ * HTTP/3 QUIC streams. It allows opening multiple parallel bidirectional
1693
+ * streams to the same origin with lower head-of-line blocking than fetch().
1694
+ * Useful for progressive model loading where different byte ranges of the
1695
+ * GGUF file can be downloaded concurrently.
1696
+ *
1697
+ * Note: actually using WebTransport for parallel range downloads requires
1698
+ * server-side support (HTTP/3 endpoint that accepts byte-range requests
1699
+ * on streams). This check only reports browser capability — the JS loader
1700
+ * will fall back to `fetch()` when the server does not cooperate.
1701
+ * @returns {boolean}
1702
+ */
1703
+ export function supports_webtransport() {
1704
+ const ret = wasm.supports_webtransport();
1705
+ return ret !== 0;
1706
+ }
1707
+
1708
+ /**
1709
+ * Check if WebGPU is available in the current browser.
1710
+ * @returns {boolean}
1711
+ */
1712
+ export function webgpu_available() {
1713
+ const ret = wasm.webgpu_available();
1714
+ return ret !== 0;
1715
+ }
1716
+
1717
+ function __wbg_get_imports() {
1718
+ const import0 = {
1719
+ __proto__: null,
1720
+ __wbg_Error_2e59b1b37a9a34c3: function(arg0, arg1) {
1721
+ const ret = Error(getStringFromWasm0(arg0, arg1));
1722
+ return ret;
1723
+ },
1724
+ __wbg_Window_412fe051c1aa1519: function(arg0) {
1725
+ const ret = arg0.Window;
1726
+ return ret;
1727
+ },
1728
+ __wbg_WorkerGlobalScope_349300f9b277afe1: function(arg0) {
1729
+ const ret = arg0.WorkerGlobalScope;
1730
+ return ret;
1731
+ },
1732
+ __wbg___wbindgen_boolean_get_a86c216575a75c30: function(arg0) {
1733
+ const v = arg0;
1734
+ const ret = typeof(v) === 'boolean' ? v : undefined;
1735
+ return isLikeNone(ret) ? 0xFFFFFF : ret ? 1 : 0;
1736
+ },
1737
+ __wbg___wbindgen_debug_string_dd5d2d07ce9e6c57: function(arg0, arg1) {
1738
+ const ret = debugString(arg1);
1739
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1740
+ const len1 = WASM_VECTOR_LEN;
1741
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
1742
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
1743
+ },
1744
+ __wbg___wbindgen_is_function_49868bde5eb1e745: function(arg0) {
1745
+ const ret = typeof(arg0) === 'function';
1746
+ return ret;
1747
+ },
1748
+ __wbg___wbindgen_is_null_344c8750a8525473: function(arg0) {
1749
+ const ret = arg0 === null;
1750
+ return ret;
1751
+ },
1752
+ __wbg___wbindgen_is_undefined_c0cca72b82b86f4d: function(arg0) {
1753
+ const ret = arg0 === undefined;
1754
+ return ret;
1755
+ },
1756
+ __wbg___wbindgen_string_get_914df97fcfa788f2: function(arg0, arg1) {
1757
+ const obj = arg1;
1758
+ const ret = typeof(obj) === 'string' ? obj : undefined;
1759
+ var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1760
+ var len1 = WASM_VECTOR_LEN;
1761
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
1762
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
1763
+ },
1764
+ __wbg___wbindgen_throw_81fc77679af83bc6: function(arg0, arg1) {
1765
+ throw new Error(getStringFromWasm0(arg0, arg1));
1766
+ },
1767
+ __wbg__wbg_cb_unref_3c3b4f651835fbcb: function(arg0) {
1768
+ arg0._wbg_cb_unref();
1769
+ },
1770
+ __wbg_arrayBuffer_7bba74066875530e: function(arg0) {
1771
+ const ret = arg0.arrayBuffer();
1772
+ return ret;
1773
+ },
1774
+ __wbg_beginComputePass_097033d61ef8af0f: function(arg0, arg1) {
1775
+ const ret = arg0.beginComputePass(arg1);
1776
+ return ret;
1777
+ },
1778
+ __wbg_body_9a25d64338506fbe: function(arg0) {
1779
+ const ret = arg0.body;
1780
+ return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
1781
+ },
1782
+ __wbg_buffer_a77cc90da4bdb503: function(arg0) {
1783
+ const ret = arg0.buffer;
1784
+ return ret;
1785
+ },
1786
+ __wbg_call_368fa9c372d473ba: function() { return handleError(function (arg0, arg1, arg2, arg3) {
1787
+ const ret = arg0.call(arg1, arg2, arg3);
1788
+ return ret;
1789
+ }, arguments); },
1790
+ __wbg_call_d578befcc3145dee: function() { return handleError(function (arg0, arg1, arg2) {
1791
+ const ret = arg0.call(arg1, arg2);
1792
+ return ret;
1793
+ }, arguments); },
1794
+ __wbg_close_37e34297940956fd: function(arg0) {
1795
+ const ret = arg0.close();
1796
+ return ret;
1797
+ },
1798
+ __wbg_copyBufferToBuffer_99ba10ae51f20b8a: function() { return handleError(function (arg0, arg1, arg2, arg3, arg4, arg5) {
1799
+ arg0.copyBufferToBuffer(arg1, arg2, arg3, arg4, arg5);
1800
+ }, arguments); },
1801
+ __wbg_createBindGroupLayout_1d37ac0dabfbed28: function() { return handleError(function (arg0, arg1) {
1802
+ const ret = arg0.createBindGroupLayout(arg1);
1803
+ return ret;
1804
+ }, arguments); },
1805
+ __wbg_createBindGroup_3bccbd7517f0708e: function(arg0, arg1) {
1806
+ const ret = arg0.createBindGroup(arg1);
1807
+ return ret;
1808
+ },
1809
+ __wbg_createBuffer_24b346170c9f54c8: function() { return handleError(function (arg0, arg1) {
1810
+ const ret = arg0.createBuffer(arg1);
1811
+ return ret;
1812
+ }, arguments); },
1813
+ __wbg_createCommandEncoder_48a406baaa084912: function(arg0, arg1) {
1814
+ const ret = arg0.createCommandEncoder(arg1);
1815
+ return ret;
1816
+ },
1817
+ __wbg_createComputePipeline_4efb4ca205a4b557: function(arg0, arg1) {
1818
+ const ret = arg0.createComputePipeline(arg1);
1819
+ return ret;
1820
+ },
1821
+ __wbg_createPipelineLayout_f668b6fbdf877ab3: function(arg0, arg1) {
1822
+ const ret = arg0.createPipelineLayout(arg1);
1823
+ return ret;
1824
+ },
1825
+ __wbg_createShaderModule_1b0812f3a4503221: function(arg0, arg1) {
1826
+ const ret = arg0.createShaderModule(arg1);
1827
+ return ret;
1828
+ },
1829
+ __wbg_createWritable_d5314165379c13be: function(arg0) {
1830
+ const ret = arg0.createWritable();
1831
+ return ret;
1832
+ },
1833
+ __wbg_dispatchWorkgroups_1b750cb68e2eb693: function(arg0, arg1, arg2, arg3) {
1834
+ arg0.dispatchWorkgroups(arg1 >>> 0, arg2 >>> 0, arg3 >>> 0);
1835
+ },
1836
+ __wbg_end_fd65a01a19361ec7: function(arg0) {
1837
+ arg0.end();
1838
+ },
1839
+ __wbg_entries_69b67e91e74ba327: function(arg0) {
1840
+ const ret = arg0.entries();
1841
+ return ret;
1842
+ },
1843
+ __wbg_error_a6fa202b58aa1cd3: function(arg0, arg1) {
1844
+ let deferred0_0;
1845
+ let deferred0_1;
1846
+ try {
1847
+ deferred0_0 = arg0;
1848
+ deferred0_1 = arg1;
1849
+ console.error(getStringFromWasm0(arg0, arg1));
1850
+ } finally {
1851
+ wasm.__wbindgen_free(deferred0_0, deferred0_1, 1);
1852
+ }
1853
+ },
1854
+ __wbg_estimate_790345f187f17044: function() { return handleError(function (arg0) {
1855
+ const ret = arg0.estimate();
1856
+ return ret;
1857
+ }, arguments); },
1858
+ __wbg_eval_db8671e4e6469929: function() { return handleError(function (arg0, arg1) {
1859
+ const ret = eval(getStringFromWasm0(arg0, arg1));
1860
+ return ret;
1861
+ }, arguments); },
1862
+ __wbg_features_205df3dd891b74bf: function(arg0) {
1863
+ const ret = arg0.features;
1864
+ return ret;
1865
+ },
1866
+ __wbg_features_efadd23951712b29: function(arg0) {
1867
+ const ret = arg0.features;
1868
+ return ret;
1869
+ },
1870
+ __wbg_fetch_ca19a9480623b9a8: function(arg0, arg1, arg2) {
1871
+ const ret = arg0.fetch(getStringFromWasm0(arg1, arg2));
1872
+ return ret;
1873
+ },
1874
+ __wbg_finish_2440fb64e53f7d5a: function(arg0, arg1) {
1875
+ const ret = arg0.finish(arg1);
1876
+ return ret;
1877
+ },
1878
+ __wbg_finish_4b40810f0b577bc2: function(arg0) {
1879
+ const ret = arg0.finish();
1880
+ return ret;
1881
+ },
1882
+ __wbg_flareengine_new: function(arg0) {
1883
+ const ret = FlareEngine.__wrap(arg0);
1884
+ return ret;
1885
+ },
1886
+ __wbg_from_741da0f916ab74aa: function(arg0) {
1887
+ const ret = Array.from(arg0);
1888
+ return ret;
1889
+ },
1890
+ __wbg_getDirectoryHandle_a38f7b2c1aa52af4: function(arg0, arg1, arg2, arg3) {
1891
+ const ret = arg0.getDirectoryHandle(getStringFromWasm0(arg1, arg2), arg3);
1892
+ return ret;
1893
+ },
1894
+ __wbg_getDirectory_3af764c18446017f: function(arg0) {
1895
+ const ret = arg0.getDirectory();
1896
+ return ret;
1897
+ },
1898
+ __wbg_getFileHandle_029e7a3c6dee72cb: function(arg0, arg1, arg2) {
1899
+ const ret = arg0.getFileHandle(getStringFromWasm0(arg1, arg2));
1900
+ return ret;
1901
+ },
1902
+ __wbg_getFileHandle_326ca47811ae37a1: function(arg0, arg1, arg2, arg3) {
1903
+ const ret = arg0.getFileHandle(getStringFromWasm0(arg1, arg2), arg3);
1904
+ return ret;
1905
+ },
1906
+ __wbg_getFile_0e25dfe508c6bd0a: function(arg0) {
1907
+ const ret = arg0.getFile();
1908
+ return ret;
1909
+ },
1910
+ __wbg_getMappedRange_55878eb97535ca19: function() { return handleError(function (arg0, arg1, arg2) {
1911
+ const ret = arg0.getMappedRange(arg1, arg2);
1912
+ return ret;
1913
+ }, arguments); },
1914
+ __wbg_getReader_3bcb712b2f3b80aa: function(arg0) {
1915
+ const ret = arg0.getReader();
1916
+ return ret;
1917
+ },
1918
+ __wbg_get_4848e350b40afc16: function(arg0, arg1) {
1919
+ const ret = arg0[arg1 >>> 0];
1920
+ return ret;
1921
+ },
1922
+ __wbg_get_5caaa5a9aae7e0b1: function() { return handleError(function (arg0, arg1, arg2, arg3) {
1923
+ const ret = arg1.get(getStringFromWasm0(arg2, arg3));
1924
+ var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1925
+ var len1 = WASM_VECTOR_LEN;
1926
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
1927
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
1928
+ }, arguments); },
1929
+ __wbg_get_f96702c6245e4ef9: function() { return handleError(function (arg0, arg1) {
1930
+ const ret = Reflect.get(arg0, arg1);
1931
+ return ret;
1932
+ }, arguments); },
1933
+ __wbg_get_quota_945897ba0f160371: function(arg0, arg1) {
1934
+ const ret = arg1.quota;
1935
+ getDataViewMemory0().setFloat64(arg0 + 8 * 1, isLikeNone(ret) ? 0 : ret, true);
1936
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, !isLikeNone(ret), true);
1937
+ },
1938
+ __wbg_get_usage_2ea0330cfaeab2c1: function(arg0, arg1) {
1939
+ const ret = arg1.usage;
1940
+ getDataViewMemory0().setFloat64(arg0 + 8 * 1, isLikeNone(ret) ? 0 : ret, true);
1941
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, !isLikeNone(ret), true);
1942
+ },
1943
+ __wbg_gpu_bafbc1407fe850fb: function(arg0) {
1944
+ const ret = arg0.gpu;
1945
+ return ret;
1946
+ },
1947
+ __wbg_has_dc80aa6186153231: function(arg0, arg1, arg2) {
1948
+ const ret = arg0.has(getStringFromWasm0(arg1, arg2));
1949
+ return ret;
1950
+ },
1951
+ __wbg_headers_e08dcb5aa09b9a63: function(arg0) {
1952
+ const ret = arg0.headers;
1953
+ return ret;
1954
+ },
1955
+ __wbg_instanceof_GpuAdapter_aff4b0f95a6c1c3e: function(arg0) {
1956
+ let result;
1957
+ try {
1958
+ result = arg0 instanceof GPUAdapter;
1959
+ } catch (_) {
1960
+ result = false;
1961
+ }
1962
+ const ret = result;
1963
+ return ret;
1964
+ },
1965
+ __wbg_instanceof_ReadableStreamDefaultReader_10d3f15a012b70d7: function(arg0) {
1966
+ let result;
1967
+ try {
1968
+ result = arg0 instanceof ReadableStreamDefaultReader;
1969
+ } catch (_) {
1970
+ result = false;
1971
+ }
1972
+ const ret = result;
1973
+ return ret;
1974
+ },
1975
+ __wbg_instanceof_Response_06795eab66cc4036: function(arg0) {
1976
+ let result;
1977
+ try {
1978
+ result = arg0 instanceof Response;
1979
+ } catch (_) {
1980
+ result = false;
1981
+ }
1982
+ const ret = result;
1983
+ return ret;
1984
+ },
1985
+ __wbg_instanceof_Window_c0fee4c064502536: function(arg0) {
1986
+ let result;
1987
+ try {
1988
+ result = arg0 instanceof Window;
1989
+ } catch (_) {
1990
+ result = false;
1991
+ }
1992
+ const ret = result;
1993
+ return ret;
1994
+ },
1995
+ __wbg_label_4b6427d9045e3926: function(arg0, arg1) {
1996
+ const ret = arg1.label;
1997
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1998
+ const len1 = WASM_VECTOR_LEN;
1999
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
2000
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
2001
+ },
2002
+ __wbg_length_0c32cb8543c8e4c8: function(arg0) {
2003
+ const ret = arg0.length;
2004
+ return ret;
2005
+ },
2006
+ __wbg_mapAsync_f7fe2e4825742580: function(arg0, arg1, arg2, arg3) {
2007
+ const ret = arg0.mapAsync(arg1 >>> 0, arg2, arg3);
2008
+ return ret;
2009
+ },
2010
+ __wbg_navigator_9b09ea705d03d227: function(arg0) {
2011
+ const ret = arg0.navigator;
2012
+ return ret;
2013
+ },
2014
+ __wbg_navigator_af52153252bdf29d: function(arg0) {
2015
+ const ret = arg0.navigator;
2016
+ return ret;
2017
+ },
2018
+ __wbg_new_227d7c05414eb861: function() {
2019
+ const ret = new Error();
2020
+ return ret;
2021
+ },
2022
+ __wbg_new_4f9fafbb3909af72: function() {
2023
+ const ret = new Object();
2024
+ return ret;
2025
+ },
2026
+ __wbg_new_a560378ea1240b14: function(arg0) {
2027
+ const ret = new Uint8Array(arg0);
2028
+ return ret;
2029
+ },
2030
+ __wbg_new_f3c9df4f38f3f798: function() {
2031
+ const ret = new Array();
2032
+ return ret;
2033
+ },
2034
+ __wbg_new_from_slice_2580ff33d0d10520: function(arg0, arg1) {
2035
+ const ret = new Uint8Array(getArrayU8FromWasm0(arg0, arg1));
2036
+ return ret;
2037
+ },
2038
+ __wbg_new_typed_14d7cc391ce53d2c: function(arg0, arg1) {
2039
+ try {
2040
+ var state0 = {a: arg0, b: arg1};
2041
+ var cb0 = (arg0, arg1) => {
2042
+ const a = state0.a;
2043
+ state0.a = 0;
2044
+ try {
2045
+ return wasm_bindgen__convert__closures_____invoke__hcdfd434894ba1863(a, state0.b, arg0, arg1);
2046
+ } finally {
2047
+ state0.a = a;
2048
+ }
2049
+ };
2050
+ const ret = new Promise(cb0);
2051
+ return ret;
2052
+ } finally {
2053
+ state0.a = 0;
2054
+ }
2055
+ },
2056
+ __wbg_new_with_byte_offset_and_length_6bfc75833d6170c8: function(arg0, arg1, arg2) {
2057
+ const ret = new Uint8Array(arg0, arg1 >>> 0, arg2 >>> 0);
2058
+ return ret;
2059
+ },
2060
+ __wbg_next_072e78dcf497124d: function() { return handleError(function (arg0) {
2061
+ const ret = arg0.next();
2062
+ return ret;
2063
+ }, arguments); },
2064
+ __wbg_now_2c44418ca0623664: function(arg0) {
2065
+ const ret = arg0.now();
2066
+ return ret;
2067
+ },
2068
+ __wbg_ok_36f7b13b74596c24: function(arg0) {
2069
+ const ret = arg0.ok;
2070
+ return ret;
2071
+ },
2072
+ __wbg_performance_5ed3f6a3bbe36d0d: function(arg0) {
2073
+ const ret = arg0.performance;
2074
+ return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
2075
+ },
2076
+ __wbg_prototypesetcall_3e05eb9545565046: function(arg0, arg1, arg2) {
2077
+ Uint8Array.prototype.set.call(getArrayU8FromWasm0(arg0, arg1), arg2);
2078
+ },
2079
+ __wbg_push_6bdbc990be5ac37b: function(arg0, arg1) {
2080
+ const ret = arg0.push(arg1);
2081
+ return ret;
2082
+ },
2083
+ __wbg_queueMicrotask_abaf92f0bd4e80a4: function(arg0) {
2084
+ const ret = arg0.queueMicrotask;
2085
+ return ret;
2086
+ },
2087
+ __wbg_queueMicrotask_df5a6dac26d818f3: function(arg0) {
2088
+ queueMicrotask(arg0);
2089
+ },
2090
+ __wbg_queue_3e40156d83b9183e: function(arg0) {
2091
+ const ret = arg0.queue;
2092
+ return ret;
2093
+ },
2094
+ __wbg_read_316bf844c93a6ccc: function(arg0) {
2095
+ const ret = arg0.read();
2096
+ return ret;
2097
+ },
2098
+ __wbg_removeEntry_f038ab74448d1824: function(arg0, arg1, arg2) {
2099
+ const ret = arg0.removeEntry(getStringFromWasm0(arg1, arg2));
2100
+ return ret;
2101
+ },
2102
+ __wbg_requestAdapter_245da40985c2fdc5: function(arg0, arg1) {
2103
+ const ret = arg0.requestAdapter(arg1);
2104
+ return ret;
2105
+ },
2106
+ __wbg_requestDevice_28434913a23418c4: function(arg0, arg1) {
2107
+ const ret = arg0.requestDevice(arg1);
2108
+ return ret;
2109
+ },
2110
+ __wbg_resolve_0a79de24e9d2267b: function(arg0) {
2111
+ const ret = Promise.resolve(arg0);
2112
+ return ret;
2113
+ },
2114
+ __wbg_setBindGroup_98f0303f15c3cfb4: function() { return handleError(function (arg0, arg1, arg2, arg3, arg4, arg5, arg6) {
2115
+ arg0.setBindGroup(arg1 >>> 0, arg2, getArrayU32FromWasm0(arg3, arg4), arg5, arg6 >>> 0);
2116
+ }, arguments); },
2117
+ __wbg_setBindGroup_bc67abae8c962082: function(arg0, arg1, arg2) {
2118
+ arg0.setBindGroup(arg1 >>> 0, arg2);
2119
+ },
2120
+ __wbg_setPipeline_0c34cc40ab8d6499: function(arg0, arg1) {
2121
+ arg0.setPipeline(arg1);
2122
+ },
2123
+ __wbg_set_62f340d5d135b4db: function(arg0, arg1, arg2) {
2124
+ arg0.set(arg1, arg2 >>> 0);
2125
+ },
2126
+ __wbg_set_8ee2d34facb8466e: function() { return handleError(function (arg0, arg1, arg2) {
2127
+ const ret = Reflect.set(arg0, arg1, arg2);
2128
+ return ret;
2129
+ }, arguments); },
2130
+ __wbg_set_access_1cc7ab8607a9643c: function(arg0, arg1) {
2131
+ arg0.access = __wbindgen_enum_GpuStorageTextureAccess[arg1];
2132
+ },
2133
+ __wbg_set_beginning_of_pass_write_index_ac45c363336c24c7: function(arg0, arg1) {
2134
+ arg0.beginningOfPassWriteIndex = arg1 >>> 0;
2135
+ },
2136
+ __wbg_set_bind_group_layouts_b4667372bdcee99f: function(arg0, arg1) {
2137
+ arg0.bindGroupLayouts = arg1;
2138
+ },
2139
+ __wbg_set_binding_0a48264269982c5e: function(arg0, arg1) {
2140
+ arg0.binding = arg1 >>> 0;
2141
+ },
2142
+ __wbg_set_binding_15ab1e2c74990b25: function(arg0, arg1) {
2143
+ arg0.binding = arg1 >>> 0;
2144
+ },
2145
+ __wbg_set_buffer_3b3e4c4a884d1610: function(arg0, arg1) {
2146
+ arg0.buffer = arg1;
2147
+ },
2148
+ __wbg_set_buffer_ff433f6fc0bcc260: function(arg0, arg1) {
2149
+ arg0.buffer = arg1;
2150
+ },
2151
+ __wbg_set_code_c616b86ce504e24a: function(arg0, arg1, arg2) {
2152
+ arg0.code = getStringFromWasm0(arg1, arg2);
2153
+ },
2154
+ __wbg_set_compute_7c274f1347709d07: function(arg0, arg1) {
2155
+ arg0.compute = arg1;
2156
+ },
2157
+ __wbg_set_create_0654e513e8ccb2be: function(arg0, arg1) {
2158
+ arg0.create = arg1 !== 0;
2159
+ },
2160
+ __wbg_set_create_4b5cddb7e7c14744: function(arg0, arg1) {
2161
+ arg0.create = arg1 !== 0;
2162
+ },
2163
+ __wbg_set_end_of_pass_write_index_c60088bc589e6882: function(arg0, arg1) {
2164
+ arg0.endOfPassWriteIndex = arg1 >>> 0;
2165
+ },
2166
+ __wbg_set_entries_bfc700c1f97eec0b: function(arg0, arg1) {
2167
+ arg0.entries = arg1;
2168
+ },
2169
+ __wbg_set_entries_f07df780e3613292: function(arg0, arg1) {
2170
+ arg0.entries = arg1;
2171
+ },
2172
+ __wbg_set_entry_point_aa503b3bb9fed987: function(arg0, arg1, arg2) {
2173
+ arg0.entryPoint = getStringFromWasm0(arg1, arg2);
2174
+ },
2175
+ __wbg_set_format_b8158198b657d617: function(arg0, arg1) {
2176
+ arg0.format = __wbindgen_enum_GpuTextureFormat[arg1];
2177
+ },
2178
+ __wbg_set_has_dynamic_offset_4d5601049080763e: function(arg0, arg1) {
2179
+ arg0.hasDynamicOffset = arg1 !== 0;
2180
+ },
2181
+ __wbg_set_label_392dc66ad76d942d: function(arg0, arg1, arg2) {
2182
+ arg0.label = getStringFromWasm0(arg1, arg2);
2183
+ },
2184
+ __wbg_set_label_3e06143ad04772ae: function(arg0, arg1, arg2) {
2185
+ arg0.label = getStringFromWasm0(arg1, arg2);
2186
+ },
2187
+ __wbg_set_label_50f397060b5b5610: function(arg0, arg1, arg2) {
2188
+ arg0.label = getStringFromWasm0(arg1, arg2);
2189
+ },
2190
+ __wbg_set_label_68e2953cfd33a5a5: function(arg0, arg1, arg2) {
2191
+ arg0.label = getStringFromWasm0(arg1, arg2);
2192
+ },
2193
+ __wbg_set_label_76c4f74a38ff9bcd: function(arg0, arg1, arg2) {
2194
+ arg0.label = getStringFromWasm0(arg1, arg2);
2195
+ },
2196
+ __wbg_set_label_79484ec4d6d85bbf: function(arg0, arg1, arg2) {
2197
+ arg0.label = getStringFromWasm0(arg1, arg2);
2198
+ },
2199
+ __wbg_set_label_861c8e348e26599d: function(arg0, arg1, arg2) {
2200
+ arg0.label = getStringFromWasm0(arg1, arg2);
2201
+ },
2202
+ __wbg_set_label_d1b6a326332d0520: function(arg0, arg1, arg2) {
2203
+ arg0.label = getStringFromWasm0(arg1, arg2);
2204
+ },
2205
+ __wbg_set_label_d687cfb9a30329c8: function(arg0, arg1, arg2) {
2206
+ arg0.label = getStringFromWasm0(arg1, arg2);
2207
+ },
2208
+ __wbg_set_label_e345704005fb385b: function(arg0, arg1, arg2) {
2209
+ arg0.label = getStringFromWasm0(arg1, arg2);
2210
+ },
2211
+ __wbg_set_layout_b9b36c291ee7f2e1: function(arg0, arg1) {
2212
+ arg0.layout = arg1;
2213
+ },
2214
+ __wbg_set_layout_cccbb8f794df887c: function(arg0, arg1) {
2215
+ arg0.layout = arg1;
2216
+ },
2217
+ __wbg_set_mapped_at_creation_34da9d6bf64b78d6: function(arg0, arg1) {
2218
+ arg0.mappedAtCreation = arg1 !== 0;
2219
+ },
2220
+ __wbg_set_min_binding_size_9389ad67218af140: function(arg0, arg1) {
2221
+ arg0.minBindingSize = arg1;
2222
+ },
2223
+ __wbg_set_module_5f33a55198ad797f: function(arg0, arg1) {
2224
+ arg0.module = arg1;
2225
+ },
2226
+ __wbg_set_multisampled_b526741755338725: function(arg0, arg1) {
2227
+ arg0.multisampled = arg1 !== 0;
2228
+ },
2229
+ __wbg_set_offset_1a0f95ffb7dd6f40: function(arg0, arg1) {
2230
+ arg0.offset = arg1;
2231
+ },
2232
+ __wbg_set_power_preference_915480f4b9565dc2: function(arg0, arg1) {
2233
+ arg0.powerPreference = __wbindgen_enum_GpuPowerPreference[arg1];
2234
+ },
2235
+ __wbg_set_query_set_0a78c3dcb3650b2b: function(arg0, arg1) {
2236
+ arg0.querySet = arg1;
2237
+ },
2238
+ __wbg_set_required_features_42347bf311233eb6: function(arg0, arg1) {
2239
+ arg0.requiredFeatures = arg1;
2240
+ },
2241
+ __wbg_set_resource_f2d72f59cc9308fc: function(arg0, arg1) {
2242
+ arg0.resource = arg1;
2243
+ },
2244
+ __wbg_set_sample_type_6d1e240a417bdf44: function(arg0, arg1) {
2245
+ arg0.sampleType = __wbindgen_enum_GpuTextureSampleType[arg1];
2246
+ },
2247
+ __wbg_set_sampler_f864a162bad4f66f: function(arg0, arg1) {
2248
+ arg0.sampler = arg1;
2249
+ },
2250
+ __wbg_set_size_6b2fc4a0e39e4d07: function(arg0, arg1) {
2251
+ arg0.size = arg1;
2252
+ },
2253
+ __wbg_set_size_c78ae8d2e2181815: function(arg0, arg1) {
2254
+ arg0.size = arg1;
2255
+ },
2256
+ __wbg_set_storage_texture_c3919f22b211c542: function(arg0, arg1) {
2257
+ arg0.storageTexture = arg1;
2258
+ },
2259
+ __wbg_set_texture_bf820de044f0d291: function(arg0, arg1) {
2260
+ arg0.texture = arg1;
2261
+ },
2262
+ __wbg_set_timestamp_writes_b9e1d87e2f057bd1: function(arg0, arg1) {
2263
+ arg0.timestampWrites = arg1;
2264
+ },
2265
+ __wbg_set_type_40f4ae4fa32946cd: function(arg0, arg1) {
2266
+ arg0.type = __wbindgen_enum_GpuBufferBindingType[arg1];
2267
+ },
2268
+ __wbg_set_type_4f1cd48d79f4d6dc: function(arg0, arg1) {
2269
+ arg0.type = __wbindgen_enum_GpuSamplerBindingType[arg1];
2270
+ },
2271
+ __wbg_set_usage_9aa23fa1e13799a8: function(arg0, arg1) {
2272
+ arg0.usage = arg1 >>> 0;
2273
+ },
2274
+ __wbg_set_view_dimension_36c0bf530395d014: function(arg0, arg1) {
2275
+ arg0.viewDimension = __wbindgen_enum_GpuTextureViewDimension[arg1];
2276
+ },
2277
+ __wbg_set_view_dimension_553cd9fa176d06ca: function(arg0, arg1) {
2278
+ arg0.viewDimension = __wbindgen_enum_GpuTextureViewDimension[arg1];
2279
+ },
2280
+ __wbg_set_visibility_eef2d8e9608a8981: function(arg0, arg1) {
2281
+ arg0.visibility = arg1 >>> 0;
2282
+ },
2283
+ __wbg_size_7306c9406e13bf29: function(arg0) {
2284
+ const ret = arg0.size;
2285
+ return ret;
2286
+ },
2287
+ __wbg_stack_3b0d974bbf31e44f: function(arg0, arg1) {
2288
+ const ret = arg1.stack;
2289
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
2290
+ const len1 = WASM_VECTOR_LEN;
2291
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
2292
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
2293
+ },
2294
+ __wbg_static_accessor_GLOBAL_THIS_a1248013d790bf5f: function() {
2295
+ const ret = typeof globalThis === 'undefined' ? null : globalThis;
2296
+ return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
2297
+ },
2298
+ __wbg_static_accessor_GLOBAL_f2e0f995a21329ff: function() {
2299
+ const ret = typeof global === 'undefined' ? null : global;
2300
+ return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
2301
+ },
2302
+ __wbg_static_accessor_SELF_24f78b6d23f286ea: function() {
2303
+ const ret = typeof self === 'undefined' ? null : self;
2304
+ return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
2305
+ },
2306
+ __wbg_static_accessor_WINDOW_59fd959c540fe405: function() {
2307
+ const ret = typeof window === 'undefined' ? null : window;
2308
+ return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
2309
+ },
2310
+ __wbg_status_44ecb0ac1da253f4: function(arg0) {
2311
+ const ret = arg0.status;
2312
+ return ret;
2313
+ },
2314
+ __wbg_storage_8f8e63186ec77353: function(arg0) {
2315
+ const ret = arg0.storage;
2316
+ return ret;
2317
+ },
2318
+ __wbg_submit_2521bdd9a232bca7: function(arg0, arg1) {
2319
+ arg0.submit(arg1);
2320
+ },
2321
+ __wbg_then_00eed3ac0b8e82cb: function(arg0, arg1, arg2) {
2322
+ const ret = arg0.then(arg1, arg2);
2323
+ return ret;
2324
+ },
2325
+ __wbg_then_479d77cb064907ee: function(arg0, arg1, arg2) {
2326
+ const ret = arg0.then(arg1, arg2);
2327
+ return ret;
2328
+ },
2329
+ __wbg_then_a0c8db0381c8994c: function(arg0, arg1) {
2330
+ const ret = arg0.then(arg1);
2331
+ return ret;
2332
+ },
2333
+ __wbg_unmap_815a075fd850cb73: function(arg0) {
2334
+ arg0.unmap();
2335
+ },
2336
+ __wbg_userAgent_d58193cc32293b16: function() { return handleError(function (arg0, arg1) {
2337
+ const ret = arg1.userAgent;
2338
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
2339
+ const len1 = WASM_VECTOR_LEN;
2340
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
2341
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
2342
+ }, arguments); },
2343
+ __wbg_writeBuffer_e8b792fb0962f30d: function() { return handleError(function (arg0, arg1, arg2, arg3, arg4, arg5) {
2344
+ arg0.writeBuffer(arg1, arg2, arg3, arg4, arg5);
2345
+ }, arguments); },
2346
+ __wbg_write_fc53b37dcc29642e: function() { return handleError(function (arg0, arg1, arg2) {
2347
+ const ret = arg0.write(getArrayU8FromWasm0(arg1, arg2));
2348
+ return ret;
2349
+ }, arguments); },
2350
+ __wbindgen_cast_0000000000000001: function(arg0, arg1) {
2351
+ // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx: 155, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
2352
+ const ret = makeMutClosure(arg0, arg1, wasm_bindgen__convert__closures_____invoke__h235e00bf230ad8a4);
2353
+ return ret;
2354
+ },
2355
+ __wbindgen_cast_0000000000000002: function(arg0, arg1) {
2356
+ // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx: 177, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`.
2357
+ const ret = makeMutClosure(arg0, arg1, wasm_bindgen__convert__closures_____invoke__h7ed8ea06cc0c8ca5);
2358
+ return ret;
2359
+ },
2360
+ __wbindgen_cast_0000000000000003: function(arg0) {
2361
+ // Cast intrinsic for `F64 -> Externref`.
2362
+ const ret = arg0;
2363
+ return ret;
2364
+ },
2365
+ __wbindgen_cast_0000000000000004: function(arg0, arg1) {
2366
+ // Cast intrinsic for `Ref(Slice(U8)) -> NamedExternref("Uint8Array")`.
2367
+ const ret = getArrayU8FromWasm0(arg0, arg1);
2368
+ return ret;
2369
+ },
2370
+ __wbindgen_cast_0000000000000005: function(arg0, arg1) {
2371
+ // Cast intrinsic for `Ref(String) -> Externref`.
2372
+ const ret = getStringFromWasm0(arg0, arg1);
2373
+ return ret;
2374
+ },
2375
+ __wbindgen_init_externref_table: function() {
2376
+ const table = wasm.__wbindgen_externrefs;
2377
+ const offset = table.grow(4);
2378
+ table.set(0, undefined);
2379
+ table.set(offset + 0, undefined);
2380
+ table.set(offset + 1, null);
2381
+ table.set(offset + 2, true);
2382
+ table.set(offset + 3, false);
2383
+ },
2384
+ };
2385
+ return {
2386
+ __proto__: null,
2387
+ "./flare_web_bg.js": import0,
2388
+ };
2389
+ }
2390
+
2391
+ function wasm_bindgen__convert__closures_____invoke__h235e00bf230ad8a4(arg0, arg1, arg2) {
2392
+ wasm.wasm_bindgen__convert__closures_____invoke__h235e00bf230ad8a4(arg0, arg1, arg2);
2393
+ }
2394
+
2395
+ function wasm_bindgen__convert__closures_____invoke__h7ed8ea06cc0c8ca5(arg0, arg1, arg2) {
2396
+ const ret = wasm.wasm_bindgen__convert__closures_____invoke__h7ed8ea06cc0c8ca5(arg0, arg1, arg2);
2397
+ if (ret[1]) {
2398
+ throw takeFromExternrefTable0(ret[0]);
2399
+ }
2400
+ }
2401
+
2402
+ function wasm_bindgen__convert__closures_____invoke__hcdfd434894ba1863(arg0, arg1, arg2, arg3) {
2403
+ wasm.wasm_bindgen__convert__closures_____invoke__hcdfd434894ba1863(arg0, arg1, arg2, arg3);
2404
+ }
2405
+
2406
+
2407
+ const __wbindgen_enum_GpuBufferBindingType = ["uniform", "storage", "read-only-storage"];
2408
+
2409
+
2410
+ const __wbindgen_enum_GpuPowerPreference = ["low-power", "high-performance"];
2411
+
2412
+
2413
+ const __wbindgen_enum_GpuSamplerBindingType = ["filtering", "non-filtering", "comparison"];
2414
+
2415
+
2416
+ const __wbindgen_enum_GpuStorageTextureAccess = ["write-only", "read-only", "read-write"];
2417
+
2418
+
2419
+ const __wbindgen_enum_GpuTextureFormat = ["r8unorm", "r8snorm", "r8uint", "r8sint", "r16uint", "r16sint", "r16float", "rg8unorm", "rg8snorm", "rg8uint", "rg8sint", "r32uint", "r32sint", "r32float", "rg16uint", "rg16sint", "rg16float", "rgba8unorm", "rgba8unorm-srgb", "rgba8snorm", "rgba8uint", "rgba8sint", "bgra8unorm", "bgra8unorm-srgb", "rgb9e5ufloat", "rgb10a2uint", "rgb10a2unorm", "rg11b10ufloat", "rg32uint", "rg32sint", "rg32float", "rgba16uint", "rgba16sint", "rgba16float", "rgba32uint", "rgba32sint", "rgba32float", "stencil8", "depth16unorm", "depth24plus", "depth24plus-stencil8", "depth32float", "depth32float-stencil8", "bc1-rgba-unorm", "bc1-rgba-unorm-srgb", "bc2-rgba-unorm", "bc2-rgba-unorm-srgb", "bc3-rgba-unorm", "bc3-rgba-unorm-srgb", "bc4-r-unorm", "bc4-r-snorm", "bc5-rg-unorm", "bc5-rg-snorm", "bc6h-rgb-ufloat", "bc6h-rgb-float", "bc7-rgba-unorm", "bc7-rgba-unorm-srgb", "etc2-rgb8unorm", "etc2-rgb8unorm-srgb", "etc2-rgb8a1unorm", "etc2-rgb8a1unorm-srgb", "etc2-rgba8unorm", "etc2-rgba8unorm-srgb", "eac-r11unorm", "eac-r11snorm", "eac-rg11unorm", "eac-rg11snorm", "astc-4x4-unorm", "astc-4x4-unorm-srgb", "astc-5x4-unorm", "astc-5x4-unorm-srgb", "astc-5x5-unorm", "astc-5x5-unorm-srgb", "astc-6x5-unorm", "astc-6x5-unorm-srgb", "astc-6x6-unorm", "astc-6x6-unorm-srgb", "astc-8x5-unorm", "astc-8x5-unorm-srgb", "astc-8x6-unorm", "astc-8x6-unorm-srgb", "astc-8x8-unorm", "astc-8x8-unorm-srgb", "astc-10x5-unorm", "astc-10x5-unorm-srgb", "astc-10x6-unorm", "astc-10x6-unorm-srgb", "astc-10x8-unorm", "astc-10x8-unorm-srgb", "astc-10x10-unorm", "astc-10x10-unorm-srgb", "astc-12x10-unorm", "astc-12x10-unorm-srgb", "astc-12x12-unorm", "astc-12x12-unorm-srgb"];
2420
+
2421
+
2422
+ const __wbindgen_enum_GpuTextureSampleType = ["float", "unfilterable-float", "depth", "sint", "uint"];
2423
+
2424
+
2425
+ const __wbindgen_enum_GpuTextureViewDimension = ["1d", "2d", "2d-array", "cube", "cube-array", "3d"];
2426
+ const FlareEngineFinalization = (typeof FinalizationRegistry === 'undefined')
2427
+ ? { register: () => {}, unregister: () => {} }
2428
+ : new FinalizationRegistry(ptr => wasm.__wbg_flareengine_free(ptr >>> 0, 1));
2429
+ const FlareProgressiveLoaderFinalization = (typeof FinalizationRegistry === 'undefined')
2430
+ ? { register: () => {}, unregister: () => {} }
2431
+ : new FinalizationRegistry(ptr => wasm.__wbg_flareprogressiveloader_free(ptr >>> 0, 1));
2432
+ const FlareTokenizerFinalization = (typeof FinalizationRegistry === 'undefined')
2433
+ ? { register: () => {}, unregister: () => {} }
2434
+ : new FinalizationRegistry(ptr => wasm.__wbg_flaretokenizer_free(ptr >>> 0, 1));
2435
+
2436
+ function addToExternrefTable0(obj) {
2437
+ const idx = wasm.__externref_table_alloc();
2438
+ wasm.__wbindgen_externrefs.set(idx, obj);
2439
+ return idx;
2440
+ }
2441
+
2442
+ const CLOSURE_DTORS = (typeof FinalizationRegistry === 'undefined')
2443
+ ? { register: () => {}, unregister: () => {} }
2444
+ : new FinalizationRegistry(state => wasm.__wbindgen_destroy_closure(state.a, state.b));
2445
+
2446
+ function debugString(val) {
2447
+ // primitive types
2448
+ const type = typeof val;
2449
+ if (type == 'number' || type == 'boolean' || val == null) {
2450
+ return `${val}`;
2451
+ }
2452
+ if (type == 'string') {
2453
+ return `"${val}"`;
2454
+ }
2455
+ if (type == 'symbol') {
2456
+ const description = val.description;
2457
+ if (description == null) {
2458
+ return 'Symbol';
2459
+ } else {
2460
+ return `Symbol(${description})`;
2461
+ }
2462
+ }
2463
+ if (type == 'function') {
2464
+ const name = val.name;
2465
+ if (typeof name == 'string' && name.length > 0) {
2466
+ return `Function(${name})`;
2467
+ } else {
2468
+ return 'Function';
2469
+ }
2470
+ }
2471
+ // objects
2472
+ if (Array.isArray(val)) {
2473
+ const length = val.length;
2474
+ let debug = '[';
2475
+ if (length > 0) {
2476
+ debug += debugString(val[0]);
2477
+ }
2478
+ for(let i = 1; i < length; i++) {
2479
+ debug += ', ' + debugString(val[i]);
2480
+ }
2481
+ debug += ']';
2482
+ return debug;
2483
+ }
2484
+ // Test for built-in
2485
+ const builtInMatches = /\[object ([^\]]+)\]/.exec(toString.call(val));
2486
+ let className;
2487
+ if (builtInMatches && builtInMatches.length > 1) {
2488
+ className = builtInMatches[1];
2489
+ } else {
2490
+ // Failed to match the standard '[object ClassName]'
2491
+ return toString.call(val);
2492
+ }
2493
+ if (className == 'Object') {
2494
+ // we're a user defined class or Object
2495
+ // JSON.stringify avoids problems with cycles, and is generally much
2496
+ // easier than looping through ownProperties of `val`.
2497
+ try {
2498
+ return 'Object(' + JSON.stringify(val) + ')';
2499
+ } catch (_) {
2500
+ return 'Object';
2501
+ }
2502
+ }
2503
+ // errors
2504
+ if (val instanceof Error) {
2505
+ return `${val.name}: ${val.message}\n${val.stack}`;
2506
+ }
2507
+ // TODO we could test for more things here, like `Set`s and `Map`s.
2508
+ return className;
2509
+ }
2510
+
2511
+ function getArrayF32FromWasm0(ptr, len) {
2512
+ ptr = ptr >>> 0;
2513
+ return getFloat32ArrayMemory0().subarray(ptr / 4, ptr / 4 + len);
2514
+ }
2515
+
2516
+ function getArrayU32FromWasm0(ptr, len) {
2517
+ ptr = ptr >>> 0;
2518
+ return getUint32ArrayMemory0().subarray(ptr / 4, ptr / 4 + len);
2519
+ }
2520
+
2521
+ function getArrayU8FromWasm0(ptr, len) {
2522
+ ptr = ptr >>> 0;
2523
+ return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
2524
+ }
2525
+
2526
+ let cachedDataViewMemory0 = null;
2527
+ function getDataViewMemory0() {
2528
+ if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
2529
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
2530
+ }
2531
+ return cachedDataViewMemory0;
2532
+ }
2533
+
2534
+ let cachedFloat32ArrayMemory0 = null;
2535
+ function getFloat32ArrayMemory0() {
2536
+ if (cachedFloat32ArrayMemory0 === null || cachedFloat32ArrayMemory0.byteLength === 0) {
2537
+ cachedFloat32ArrayMemory0 = new Float32Array(wasm.memory.buffer);
2538
+ }
2539
+ return cachedFloat32ArrayMemory0;
2540
+ }
2541
+
2542
+ function getStringFromWasm0(ptr, len) {
2543
+ ptr = ptr >>> 0;
2544
+ return decodeText(ptr, len);
2545
+ }
2546
+
2547
+ let cachedUint32ArrayMemory0 = null;
2548
+ function getUint32ArrayMemory0() {
2549
+ if (cachedUint32ArrayMemory0 === null || cachedUint32ArrayMemory0.byteLength === 0) {
2550
+ cachedUint32ArrayMemory0 = new Uint32Array(wasm.memory.buffer);
2551
+ }
2552
+ return cachedUint32ArrayMemory0;
2553
+ }
2554
+
2555
+ let cachedUint8ArrayMemory0 = null;
2556
+ function getUint8ArrayMemory0() {
2557
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
2558
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
2559
+ }
2560
+ return cachedUint8ArrayMemory0;
2561
+ }
2562
+
2563
+ function handleError(f, args) {
2564
+ try {
2565
+ return f.apply(this, args);
2566
+ } catch (e) {
2567
+ const idx = addToExternrefTable0(e);
2568
+ wasm.__wbindgen_exn_store(idx);
2569
+ }
2570
+ }
2571
+
2572
+ function isLikeNone(x) {
2573
+ return x === undefined || x === null;
2574
+ }
2575
+
2576
+ function makeMutClosure(arg0, arg1, f) {
2577
+ const state = { a: arg0, b: arg1, cnt: 1 };
2578
+ const real = (...args) => {
2579
+
2580
+ // First up with a closure we increment the internal reference
2581
+ // count. This ensures that the Rust closure environment won't
2582
+ // be deallocated while we're invoking it.
2583
+ state.cnt++;
2584
+ const a = state.a;
2585
+ state.a = 0;
2586
+ try {
2587
+ return f(a, state.b, ...args);
2588
+ } finally {
2589
+ state.a = a;
2590
+ real._wbg_cb_unref();
2591
+ }
2592
+ };
2593
+ real._wbg_cb_unref = () => {
2594
+ if (--state.cnt === 0) {
2595
+ wasm.__wbindgen_destroy_closure(state.a, state.b);
2596
+ state.a = 0;
2597
+ CLOSURE_DTORS.unregister(state);
2598
+ }
2599
+ };
2600
+ CLOSURE_DTORS.register(real, state, state);
2601
+ return real;
2602
+ }
2603
+
2604
+ function passArray32ToWasm0(arg, malloc) {
2605
+ const ptr = malloc(arg.length * 4, 4) >>> 0;
2606
+ getUint32ArrayMemory0().set(arg, ptr / 4);
2607
+ WASM_VECTOR_LEN = arg.length;
2608
+ return ptr;
2609
+ }
2610
+
2611
+ function passArray8ToWasm0(arg, malloc) {
2612
+ const ptr = malloc(arg.length * 1, 1) >>> 0;
2613
+ getUint8ArrayMemory0().set(arg, ptr / 1);
2614
+ WASM_VECTOR_LEN = arg.length;
2615
+ return ptr;
2616
+ }
2617
+
2618
+ function passArrayF32ToWasm0(arg, malloc) {
2619
+ const ptr = malloc(arg.length * 4, 4) >>> 0;
2620
+ getFloat32ArrayMemory0().set(arg, ptr / 4);
2621
+ WASM_VECTOR_LEN = arg.length;
2622
+ return ptr;
2623
+ }
2624
+
2625
+ function passStringToWasm0(arg, malloc, realloc) {
2626
+ if (realloc === undefined) {
2627
+ const buf = cachedTextEncoder.encode(arg);
2628
+ const ptr = malloc(buf.length, 1) >>> 0;
2629
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
2630
+ WASM_VECTOR_LEN = buf.length;
2631
+ return ptr;
2632
+ }
2633
+
2634
+ let len = arg.length;
2635
+ let ptr = malloc(len, 1) >>> 0;
2636
+
2637
+ const mem = getUint8ArrayMemory0();
2638
+
2639
+ let offset = 0;
2640
+
2641
+ for (; offset < len; offset++) {
2642
+ const code = arg.charCodeAt(offset);
2643
+ if (code > 0x7F) break;
2644
+ mem[ptr + offset] = code;
2645
+ }
2646
+ if (offset !== len) {
2647
+ if (offset !== 0) {
2648
+ arg = arg.slice(offset);
2649
+ }
2650
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
2651
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
2652
+ const ret = cachedTextEncoder.encodeInto(arg, view);
2653
+
2654
+ offset += ret.written;
2655
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
2656
+ }
2657
+
2658
+ WASM_VECTOR_LEN = offset;
2659
+ return ptr;
2660
+ }
2661
+
2662
+ function takeFromExternrefTable0(idx) {
2663
+ const value = wasm.__wbindgen_externrefs.get(idx);
2664
+ wasm.__externref_table_dealloc(idx);
2665
+ return value;
2666
+ }
2667
+
2668
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
2669
+ cachedTextDecoder.decode();
2670
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
2671
+ let numBytesDecoded = 0;
2672
+ function decodeText(ptr, len) {
2673
+ numBytesDecoded += len;
2674
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
2675
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
2676
+ cachedTextDecoder.decode();
2677
+ numBytesDecoded = len;
2678
+ }
2679
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
2680
+ }
2681
+
2682
+ const cachedTextEncoder = new TextEncoder();
2683
+
2684
+ if (!('encodeInto' in cachedTextEncoder)) {
2685
+ cachedTextEncoder.encodeInto = function (arg, view) {
2686
+ const buf = cachedTextEncoder.encode(arg);
2687
+ view.set(buf);
2688
+ return {
2689
+ read: arg.length,
2690
+ written: buf.length
2691
+ };
2692
+ };
2693
+ }
2694
+
2695
+ let WASM_VECTOR_LEN = 0;
2696
+
2697
+ let wasmModule, wasm;
2698
+ function __wbg_finalize_init(instance, module) {
2699
+ wasm = instance.exports;
2700
+ wasmModule = module;
2701
+ cachedDataViewMemory0 = null;
2702
+ cachedFloat32ArrayMemory0 = null;
2703
+ cachedUint32ArrayMemory0 = null;
2704
+ cachedUint8ArrayMemory0 = null;
2705
+ wasm.__wbindgen_start();
2706
+ return wasm;
2707
+ }
2708
+
2709
+ async function __wbg_load(module, imports) {
2710
+ if (typeof Response === 'function' && module instanceof Response) {
2711
+ if (typeof WebAssembly.instantiateStreaming === 'function') {
2712
+ try {
2713
+ return await WebAssembly.instantiateStreaming(module, imports);
2714
+ } catch (e) {
2715
+ const validResponse = module.ok && expectedResponseType(module.type);
2716
+
2717
+ if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
2718
+ 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);
2719
+
2720
+ } else { throw e; }
2721
+ }
2722
+ }
2723
+
2724
+ const bytes = await module.arrayBuffer();
2725
+ return await WebAssembly.instantiate(bytes, imports);
2726
+ } else {
2727
+ const instance = await WebAssembly.instantiate(module, imports);
2728
+
2729
+ if (instance instanceof WebAssembly.Instance) {
2730
+ return { instance, module };
2731
+ } else {
2732
+ return instance;
2733
+ }
2734
+ }
2735
+
2736
+ function expectedResponseType(type) {
2737
+ switch (type) {
2738
+ case 'basic': case 'cors': case 'default': return true;
2739
+ }
2740
+ return false;
2741
+ }
2742
+ }
2743
+
2744
+ function initSync(module) {
2745
+ if (wasm !== undefined) return wasm;
2746
+
2747
+
2748
+ if (module !== undefined) {
2749
+ if (Object.getPrototypeOf(module) === Object.prototype) {
2750
+ ({module} = module)
2751
+ } else {
2752
+ console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
2753
+ }
2754
+ }
2755
+
2756
+ const imports = __wbg_get_imports();
2757
+ if (!(module instanceof WebAssembly.Module)) {
2758
+ module = new WebAssembly.Module(module);
2759
+ }
2760
+ const instance = new WebAssembly.Instance(module, imports);
2761
+ return __wbg_finalize_init(instance, module);
2762
+ }
2763
+
2764
+ async function __wbg_init(module_or_path) {
2765
+ if (wasm !== undefined) return wasm;
2766
+
2767
+
2768
+ if (module_or_path !== undefined) {
2769
+ if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
2770
+ ({module_or_path} = module_or_path)
2771
+ } else {
2772
+ console.warn('using deprecated parameters for the initialization function; pass a single object instead')
2773
+ }
2774
+ }
2775
+
2776
+ if (module_or_path === undefined) {
2777
+ module_or_path = new URL('flare_web_bg.wasm', import.meta.url);
2778
+ }
2779
+ const imports = __wbg_get_imports();
2780
+
2781
+ if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
2782
+ module_or_path = fetch(module_or_path);
2783
+ }
2784
+
2785
+ const { instance, module } = await __wbg_load(await module_or_path, imports);
2786
+
2787
+ return __wbg_finalize_init(instance, module);
2788
+ }
2789
+
2790
+ export { initSync, __wbg_init as default };