@usex/ternava 0.0.0-stage → 0.2.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,330 @@
1
+ /* @ts-self-types="./tern_engine.d.ts" */
2
+
3
+ /**
4
+ * Debug helper: returns a human-readable summary of the loaded model's
5
+ * header (format version, embedding format, dimensions, vocab size).
6
+ * @returns {string}
7
+ */
8
+ function config_summary() {
9
+ let deferred1_0;
10
+ let deferred1_1;
11
+ try {
12
+ const ret = wasm.config_summary();
13
+ deferred1_0 = ret[0];
14
+ deferred1_1 = ret[1];
15
+ return getStringFromWasm0(ret[0], ret[1]);
16
+ } finally {
17
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
18
+ }
19
+ }
20
+ exports.config_summary = config_summary;
21
+
22
+ /**
23
+ * Primary entry point: text → 384-dim L2-normalized embedding.
24
+ *
25
+ * Tokenizes via the embedded BERT vocab, runs the full forward pass against
26
+ * the embedded `.bin`, returns the output vector.
27
+ * @param {string} text
28
+ * @returns {Float32Array}
29
+ */
30
+ function embed(text) {
31
+ const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
32
+ const len0 = WASM_VECTOR_LEN;
33
+ const ret = wasm.embed(ptr0, len0);
34
+ var v2 = getArrayF32FromWasm0(ret[0], ret[1]).slice();
35
+ wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
36
+ return v2;
37
+ }
38
+ exports.embed = embed;
39
+
40
+ /**
41
+ * Identity of the exact packed model embedded in this build.
42
+ * @returns {string}
43
+ */
44
+ function model_sha256() {
45
+ let deferred1_0;
46
+ let deferred1_1;
47
+ try {
48
+ const ret = wasm.model_sha256();
49
+ deferred1_0 = ret[0];
50
+ deferred1_1 = ret[1];
51
+ return getStringFromWasm0(ret[0], ret[1]);
52
+ } finally {
53
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
54
+ }
55
+ }
56
+ exports.model_sha256 = model_sha256;
57
+
58
+ /**
59
+ * Debug helper: returns token IDs the tokenizer produced. Used by per-stage
60
+ * parity tests to confirm tokenization matches the Python `tokenizers` library.
61
+ * @param {string} text
62
+ * @returns {Uint32Array}
63
+ */
64
+ function tokenize(text) {
65
+ const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
66
+ const len0 = WASM_VECTOR_LEN;
67
+ const ret = wasm.tokenize(ptr0, len0);
68
+ var v2 = getArrayU32FromWasm0(ret[0], ret[1]).slice();
69
+ wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
70
+ return v2;
71
+ }
72
+ exports.tokenize = tokenize;
73
+
74
+ /**
75
+ * Identity of the exact tokenizer embedded in this build.
76
+ * @returns {string}
77
+ */
78
+ function tokenizer_sha256() {
79
+ let deferred1_0;
80
+ let deferred1_1;
81
+ try {
82
+ const ret = wasm.tokenizer_sha256();
83
+ deferred1_0 = ret[0];
84
+ deferred1_1 = ret[1];
85
+ return getStringFromWasm0(ret[0], ret[1]);
86
+ } finally {
87
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
88
+ }
89
+ }
90
+ exports.tokenizer_sha256 = tokenizer_sha256;
91
+ function __wbg_get_imports() {
92
+ const import0 = {
93
+ __proto__: null,
94
+ __wbg___wbindgen_is_function_754e9f305ff6029e: function(arg0) {
95
+ const ret = typeof(arg0) === 'function';
96
+ return ret;
97
+ },
98
+ __wbg___wbindgen_is_object_56732c2bc353f41d: function(arg0) {
99
+ const val = arg0;
100
+ const ret = typeof(val) === 'object' && val !== null;
101
+ return ret;
102
+ },
103
+ __wbg___wbindgen_is_string_c236cabd84a4d769: function(arg0) {
104
+ const ret = typeof(arg0) === 'string';
105
+ return ret;
106
+ },
107
+ __wbg___wbindgen_is_undefined_67b456be8673d3d7: function(arg0) {
108
+ const ret = arg0 === undefined;
109
+ return ret;
110
+ },
111
+ __wbg___wbindgen_throw_1506f2235d1bdba0: function(arg0, arg1) {
112
+ throw new Error(getStringFromWasm0(arg0, arg1));
113
+ },
114
+ __wbg_call_9c758de292015997: function() { return handleError(function (arg0, arg1, arg2) {
115
+ const ret = arg0.call(arg1, arg2);
116
+ return ret;
117
+ }, arguments); },
118
+ __wbg_crypto_38df2bab126b63dc: function(arg0) {
119
+ const ret = arg0.crypto;
120
+ return ret;
121
+ },
122
+ __wbg_getRandomValues_c44a50d8cfdaebeb: function() { return handleError(function (arg0, arg1) {
123
+ arg0.getRandomValues(arg1);
124
+ }, arguments); },
125
+ __wbg_length_4a591ecaa01354d9: function(arg0) {
126
+ const ret = arg0.length;
127
+ return ret;
128
+ },
129
+ __wbg_msCrypto_bd5a034af96bcba6: function(arg0) {
130
+ const ret = arg0.msCrypto;
131
+ return ret;
132
+ },
133
+ __wbg_new_with_length_36a4998e27b014c5: function(arg0) {
134
+ const ret = new Uint8Array(arg0 >>> 0);
135
+ return ret;
136
+ },
137
+ __wbg_node_84ea875411254db1: function(arg0) {
138
+ const ret = arg0.node;
139
+ return ret;
140
+ },
141
+ __wbg_process_44c7a14e11e9f69e: function(arg0) {
142
+ const ret = arg0.process;
143
+ return ret;
144
+ },
145
+ __wbg_prototypesetcall_3249fc62a0fafa30: function(arg0, arg1, arg2) {
146
+ Uint8Array.prototype.set.call(getArrayU8FromWasm0(arg0, arg1), arg2);
147
+ },
148
+ __wbg_randomFillSync_6c25eac9869eb53c: function() { return handleError(function (arg0, arg1) {
149
+ arg0.randomFillSync(arg1);
150
+ }, arguments); },
151
+ __wbg_require_b4edbdcf3e2a1ef0: function() { return handleError(function () {
152
+ const ret = module.require;
153
+ return ret;
154
+ }, arguments); },
155
+ __wbg_static_accessor_GLOBAL_9d53f2689e622ca1: function() {
156
+ const ret = typeof global === 'undefined' ? null : global;
157
+ return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
158
+ },
159
+ __wbg_static_accessor_GLOBAL_THIS_a1a35cec07001a8a: function() {
160
+ const ret = typeof globalThis === 'undefined' ? null : globalThis;
161
+ return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
162
+ },
163
+ __wbg_static_accessor_SELF_4c59f6c7ea29a144: function() {
164
+ const ret = typeof self === 'undefined' ? null : self;
165
+ return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
166
+ },
167
+ __wbg_static_accessor_WINDOW_e70ae9f2eb052253: function() {
168
+ const ret = typeof window === 'undefined' ? null : window;
169
+ return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
170
+ },
171
+ __wbg_subarray_4aa221f6a4f5ab22: function(arg0, arg1, arg2) {
172
+ const ret = arg0.subarray(arg1 >>> 0, arg2 >>> 0);
173
+ return ret;
174
+ },
175
+ __wbg_versions_276b2795b1c6a219: function(arg0) {
176
+ const ret = arg0.versions;
177
+ return ret;
178
+ },
179
+ __wbindgen_cast_0000000000000001: function(arg0, arg1) {
180
+ // Cast intrinsic for `Ref(Slice(U8)) -> NamedExternref("Uint8Array")`.
181
+ const ret = getArrayU8FromWasm0(arg0, arg1);
182
+ return ret;
183
+ },
184
+ __wbindgen_cast_0000000000000002: function(arg0, arg1) {
185
+ // Cast intrinsic for `Ref(String) -> Externref`.
186
+ const ret = getStringFromWasm0(arg0, arg1);
187
+ return ret;
188
+ },
189
+ __wbindgen_init_externref_table: function() {
190
+ const table = wasm.__wbindgen_externrefs;
191
+ const offset = table.grow(4);
192
+ table.set(0, undefined);
193
+ table.set(offset + 0, undefined);
194
+ table.set(offset + 1, null);
195
+ table.set(offset + 2, true);
196
+ table.set(offset + 3, false);
197
+ },
198
+ };
199
+ return {
200
+ __proto__: null,
201
+ "./tern_engine_bg.js": import0,
202
+ };
203
+ }
204
+
205
+ function addToExternrefTable0(obj) {
206
+ const idx = wasm.__externref_table_alloc();
207
+ wasm.__wbindgen_externrefs.set(idx, obj);
208
+ return idx;
209
+ }
210
+
211
+ function getArrayF32FromWasm0(ptr, len) {
212
+ ptr = ptr >>> 0;
213
+ return getFloat32ArrayMemory0().subarray(ptr / 4, ptr / 4 + len);
214
+ }
215
+
216
+ function getArrayU32FromWasm0(ptr, len) {
217
+ ptr = ptr >>> 0;
218
+ return getUint32ArrayMemory0().subarray(ptr / 4, ptr / 4 + len);
219
+ }
220
+
221
+ function getArrayU8FromWasm0(ptr, len) {
222
+ ptr = ptr >>> 0;
223
+ return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
224
+ }
225
+
226
+ let cachedFloat32ArrayMemory0 = null;
227
+ function getFloat32ArrayMemory0() {
228
+ if (cachedFloat32ArrayMemory0 === null || cachedFloat32ArrayMemory0.byteLength === 0) {
229
+ cachedFloat32ArrayMemory0 = new Float32Array(wasm.memory.buffer);
230
+ }
231
+ return cachedFloat32ArrayMemory0;
232
+ }
233
+
234
+ function getStringFromWasm0(ptr, len) {
235
+ return decodeText(ptr >>> 0, len);
236
+ }
237
+
238
+ let cachedUint32ArrayMemory0 = null;
239
+ function getUint32ArrayMemory0() {
240
+ if (cachedUint32ArrayMemory0 === null || cachedUint32ArrayMemory0.byteLength === 0) {
241
+ cachedUint32ArrayMemory0 = new Uint32Array(wasm.memory.buffer);
242
+ }
243
+ return cachedUint32ArrayMemory0;
244
+ }
245
+
246
+ let cachedUint8ArrayMemory0 = null;
247
+ function getUint8ArrayMemory0() {
248
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
249
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
250
+ }
251
+ return cachedUint8ArrayMemory0;
252
+ }
253
+
254
+ function handleError(f, args) {
255
+ try {
256
+ return f.apply(this, args);
257
+ } catch (e) {
258
+ const idx = addToExternrefTable0(e);
259
+ wasm.__wbindgen_exn_store(idx);
260
+ }
261
+ }
262
+
263
+ function isLikeNone(x) {
264
+ return x === undefined || x === null;
265
+ }
266
+
267
+ function passStringToWasm0(arg, malloc, realloc) {
268
+ if (realloc === undefined) {
269
+ const buf = cachedTextEncoder.encode(arg);
270
+ const ptr = malloc(buf.length, 1) >>> 0;
271
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
272
+ WASM_VECTOR_LEN = buf.length;
273
+ return ptr;
274
+ }
275
+
276
+ let len = arg.length;
277
+ let ptr = malloc(len, 1) >>> 0;
278
+
279
+ const mem = getUint8ArrayMemory0();
280
+
281
+ let offset = 0;
282
+
283
+ for (; offset < len; offset++) {
284
+ const code = arg.charCodeAt(offset);
285
+ if (code > 0x7F) break;
286
+ mem[ptr + offset] = code;
287
+ }
288
+ if (offset !== len) {
289
+ if (offset !== 0) {
290
+ arg = arg.slice(offset);
291
+ }
292
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
293
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
294
+ const ret = cachedTextEncoder.encodeInto(arg, view);
295
+
296
+ offset += ret.written;
297
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
298
+ }
299
+
300
+ WASM_VECTOR_LEN = offset;
301
+ return ptr;
302
+ }
303
+
304
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
305
+ cachedTextDecoder.decode();
306
+ function decodeText(ptr, len) {
307
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
308
+ }
309
+
310
+ const cachedTextEncoder = new TextEncoder();
311
+
312
+ if (!('encodeInto' in cachedTextEncoder)) {
313
+ cachedTextEncoder.encodeInto = function (arg, view) {
314
+ const buf = cachedTextEncoder.encode(arg);
315
+ view.set(buf);
316
+ return {
317
+ read: arg.length,
318
+ written: buf.length
319
+ };
320
+ };
321
+ }
322
+
323
+ let WASM_VECTOR_LEN = 0;
324
+
325
+ const wasmPath = `${__dirname}/tern_engine_bg.wasm`;
326
+ const wasmBytes = require('fs').readFileSync(wasmPath);
327
+ const wasmModule = new WebAssembly.Module(wasmBytes);
328
+ let wasmInstance = new WebAssembly.Instance(wasmModule, __wbg_get_imports());
329
+ let wasm = wasmInstance.exports;
330
+ wasm.__wbindgen_start();
@@ -0,0 +1,320 @@
1
+ /**
2
+ * Debug helper: returns a human-readable summary of the loaded model's
3
+ * header (format version, embedding format, dimensions, vocab size).
4
+ * @returns {string}
5
+ */
6
+ export function config_summary() {
7
+ let deferred1_0;
8
+ let deferred1_1;
9
+ try {
10
+ const ret = wasm.config_summary();
11
+ deferred1_0 = ret[0];
12
+ deferred1_1 = ret[1];
13
+ return getStringFromWasm0(ret[0], ret[1]);
14
+ } finally {
15
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
16
+ }
17
+ }
18
+
19
+ /**
20
+ * Primary entry point: text → 384-dim L2-normalized embedding.
21
+ *
22
+ * Tokenizes via the embedded BERT vocab, runs the full forward pass against
23
+ * the embedded `.bin`, returns the output vector.
24
+ * @param {string} text
25
+ * @returns {Float32Array}
26
+ */
27
+ export function embed(text) {
28
+ const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
29
+ const len0 = WASM_VECTOR_LEN;
30
+ const ret = wasm.embed(ptr0, len0);
31
+ var v2 = getArrayF32FromWasm0(ret[0], ret[1]).slice();
32
+ wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
33
+ return v2;
34
+ }
35
+
36
+ /**
37
+ * Identity of the exact packed model embedded in this build.
38
+ * @returns {string}
39
+ */
40
+ export function model_sha256() {
41
+ let deferred1_0;
42
+ let deferred1_1;
43
+ try {
44
+ const ret = wasm.model_sha256();
45
+ deferred1_0 = ret[0];
46
+ deferred1_1 = ret[1];
47
+ return getStringFromWasm0(ret[0], ret[1]);
48
+ } finally {
49
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
50
+ }
51
+ }
52
+
53
+ /**
54
+ * Debug helper: returns token IDs the tokenizer produced. Used by per-stage
55
+ * parity tests to confirm tokenization matches the Python `tokenizers` library.
56
+ * @param {string} text
57
+ * @returns {Uint32Array}
58
+ */
59
+ export function tokenize(text) {
60
+ const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
61
+ const len0 = WASM_VECTOR_LEN;
62
+ const ret = wasm.tokenize(ptr0, len0);
63
+ var v2 = getArrayU32FromWasm0(ret[0], ret[1]).slice();
64
+ wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
65
+ return v2;
66
+ }
67
+
68
+ /**
69
+ * Identity of the exact tokenizer embedded in this build.
70
+ * @returns {string}
71
+ */
72
+ export function tokenizer_sha256() {
73
+ let deferred1_0;
74
+ let deferred1_1;
75
+ try {
76
+ const ret = wasm.tokenizer_sha256();
77
+ deferred1_0 = ret[0];
78
+ deferred1_1 = ret[1];
79
+ return getStringFromWasm0(ret[0], ret[1]);
80
+ } finally {
81
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
82
+ }
83
+ }
84
+ export function __wbg___wbindgen_is_function_754e9f305ff6029e(arg0) {
85
+ const ret = typeof(arg0) === 'function';
86
+ return ret;
87
+ }
88
+ export function __wbg___wbindgen_is_object_56732c2bc353f41d(arg0) {
89
+ const val = arg0;
90
+ const ret = typeof(val) === 'object' && val !== null;
91
+ return ret;
92
+ }
93
+ export function __wbg___wbindgen_is_string_c236cabd84a4d769(arg0) {
94
+ const ret = typeof(arg0) === 'string';
95
+ return ret;
96
+ }
97
+ export function __wbg___wbindgen_is_undefined_67b456be8673d3d7(arg0) {
98
+ const ret = arg0 === undefined;
99
+ return ret;
100
+ }
101
+ export function __wbg___wbindgen_throw_1506f2235d1bdba0(arg0, arg1) {
102
+ throw new Error(getStringFromWasm0(arg0, arg1));
103
+ }
104
+ export function __wbg_call_9c758de292015997() { return handleError(function (arg0, arg1, arg2) {
105
+ const ret = arg0.call(arg1, arg2);
106
+ return ret;
107
+ }, arguments); }
108
+ export function __wbg_crypto_38df2bab126b63dc(arg0) {
109
+ const ret = arg0.crypto;
110
+ return ret;
111
+ }
112
+ export function __wbg_getRandomValues_c44a50d8cfdaebeb() { return handleError(function (arg0, arg1) {
113
+ arg0.getRandomValues(arg1);
114
+ }, arguments); }
115
+ export function __wbg_length_4a591ecaa01354d9(arg0) {
116
+ const ret = arg0.length;
117
+ return ret;
118
+ }
119
+ export function __wbg_msCrypto_bd5a034af96bcba6(arg0) {
120
+ const ret = arg0.msCrypto;
121
+ return ret;
122
+ }
123
+ export function __wbg_new_with_length_36a4998e27b014c5(arg0) {
124
+ const ret = new Uint8Array(arg0 >>> 0);
125
+ return ret;
126
+ }
127
+ export function __wbg_node_84ea875411254db1(arg0) {
128
+ const ret = arg0.node;
129
+ return ret;
130
+ }
131
+ export function __wbg_process_44c7a14e11e9f69e(arg0) {
132
+ const ret = arg0.process;
133
+ return ret;
134
+ }
135
+ export function __wbg_prototypesetcall_3249fc62a0fafa30(arg0, arg1, arg2) {
136
+ Uint8Array.prototype.set.call(getArrayU8FromWasm0(arg0, arg1), arg2);
137
+ }
138
+ export function __wbg_randomFillSync_6c25eac9869eb53c() { return handleError(function (arg0, arg1) {
139
+ arg0.randomFillSync(arg1);
140
+ }, arguments); }
141
+ export function __wbg_require_b4edbdcf3e2a1ef0() { return handleError(function () {
142
+ const ret = module.require;
143
+ return ret;
144
+ }, arguments); }
145
+ export function __wbg_static_accessor_GLOBAL_9d53f2689e622ca1() {
146
+ const ret = typeof global === 'undefined' ? null : global;
147
+ return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
148
+ }
149
+ export function __wbg_static_accessor_GLOBAL_THIS_a1a35cec07001a8a() {
150
+ const ret = typeof globalThis === 'undefined' ? null : globalThis;
151
+ return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
152
+ }
153
+ export function __wbg_static_accessor_SELF_4c59f6c7ea29a144() {
154
+ const ret = typeof self === 'undefined' ? null : self;
155
+ return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
156
+ }
157
+ export function __wbg_static_accessor_WINDOW_e70ae9f2eb052253() {
158
+ const ret = typeof window === 'undefined' ? null : window;
159
+ return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
160
+ }
161
+ export function __wbg_subarray_4aa221f6a4f5ab22(arg0, arg1, arg2) {
162
+ const ret = arg0.subarray(arg1 >>> 0, arg2 >>> 0);
163
+ return ret;
164
+ }
165
+ export function __wbg_versions_276b2795b1c6a219(arg0) {
166
+ const ret = arg0.versions;
167
+ return ret;
168
+ }
169
+ export function __wbindgen_cast_0000000000000001(arg0, arg1) {
170
+ // Cast intrinsic for `Ref(Slice(U8)) -> NamedExternref("Uint8Array")`.
171
+ const ret = getArrayU8FromWasm0(arg0, arg1);
172
+ return ret;
173
+ }
174
+ export function __wbindgen_cast_0000000000000002(arg0, arg1) {
175
+ // Cast intrinsic for `Ref(String) -> Externref`.
176
+ const ret = getStringFromWasm0(arg0, arg1);
177
+ return ret;
178
+ }
179
+ export function __wbindgen_init_externref_table() {
180
+ const table = wasm.__wbindgen_externrefs;
181
+ const offset = table.grow(4);
182
+ table.set(0, undefined);
183
+ table.set(offset + 0, undefined);
184
+ table.set(offset + 1, null);
185
+ table.set(offset + 2, true);
186
+ table.set(offset + 3, false);
187
+ }
188
+ function addToExternrefTable0(obj) {
189
+ const idx = wasm.__externref_table_alloc();
190
+ wasm.__wbindgen_externrefs.set(idx, obj);
191
+ return idx;
192
+ }
193
+
194
+ function getArrayF32FromWasm0(ptr, len) {
195
+ ptr = ptr >>> 0;
196
+ return getFloat32ArrayMemory0().subarray(ptr / 4, ptr / 4 + len);
197
+ }
198
+
199
+ function getArrayU32FromWasm0(ptr, len) {
200
+ ptr = ptr >>> 0;
201
+ return getUint32ArrayMemory0().subarray(ptr / 4, ptr / 4 + len);
202
+ }
203
+
204
+ function getArrayU8FromWasm0(ptr, len) {
205
+ ptr = ptr >>> 0;
206
+ return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
207
+ }
208
+
209
+ let cachedFloat32ArrayMemory0 = null;
210
+ function getFloat32ArrayMemory0() {
211
+ if (cachedFloat32ArrayMemory0 === null || cachedFloat32ArrayMemory0.byteLength === 0) {
212
+ cachedFloat32ArrayMemory0 = new Float32Array(wasm.memory.buffer);
213
+ }
214
+ return cachedFloat32ArrayMemory0;
215
+ }
216
+
217
+ function getStringFromWasm0(ptr, len) {
218
+ return decodeText(ptr >>> 0, len);
219
+ }
220
+
221
+ let cachedUint32ArrayMemory0 = null;
222
+ function getUint32ArrayMemory0() {
223
+ if (cachedUint32ArrayMemory0 === null || cachedUint32ArrayMemory0.byteLength === 0) {
224
+ cachedUint32ArrayMemory0 = new Uint32Array(wasm.memory.buffer);
225
+ }
226
+ return cachedUint32ArrayMemory0;
227
+ }
228
+
229
+ let cachedUint8ArrayMemory0 = null;
230
+ function getUint8ArrayMemory0() {
231
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
232
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
233
+ }
234
+ return cachedUint8ArrayMemory0;
235
+ }
236
+
237
+ function handleError(f, args) {
238
+ try {
239
+ return f.apply(this, args);
240
+ } catch (e) {
241
+ const idx = addToExternrefTable0(e);
242
+ wasm.__wbindgen_exn_store(idx);
243
+ }
244
+ }
245
+
246
+ function isLikeNone(x) {
247
+ return x === undefined || x === null;
248
+ }
249
+
250
+ function passStringToWasm0(arg, malloc, realloc) {
251
+ if (realloc === undefined) {
252
+ const buf = cachedTextEncoder.encode(arg);
253
+ const ptr = malloc(buf.length, 1) >>> 0;
254
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
255
+ WASM_VECTOR_LEN = buf.length;
256
+ return ptr;
257
+ }
258
+
259
+ let len = arg.length;
260
+ let ptr = malloc(len, 1) >>> 0;
261
+
262
+ const mem = getUint8ArrayMemory0();
263
+
264
+ let offset = 0;
265
+
266
+ for (; offset < len; offset++) {
267
+ const code = arg.charCodeAt(offset);
268
+ if (code > 0x7F) break;
269
+ mem[ptr + offset] = code;
270
+ }
271
+ if (offset !== len) {
272
+ if (offset !== 0) {
273
+ arg = arg.slice(offset);
274
+ }
275
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
276
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
277
+ const ret = cachedTextEncoder.encodeInto(arg, view);
278
+
279
+ offset += ret.written;
280
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
281
+ }
282
+
283
+ WASM_VECTOR_LEN = offset;
284
+ return ptr;
285
+ }
286
+
287
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
288
+ cachedTextDecoder.decode();
289
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
290
+ let numBytesDecoded = 0;
291
+ function decodeText(ptr, len) {
292
+ numBytesDecoded += len;
293
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
294
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
295
+ cachedTextDecoder.decode();
296
+ numBytesDecoded = len;
297
+ }
298
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
299
+ }
300
+
301
+ const cachedTextEncoder = new TextEncoder();
302
+
303
+ if (!('encodeInto' in cachedTextEncoder)) {
304
+ cachedTextEncoder.encodeInto = function (arg, view) {
305
+ const buf = cachedTextEncoder.encode(arg);
306
+ view.set(buf);
307
+ return {
308
+ read: arg.length,
309
+ written: buf.length
310
+ };
311
+ };
312
+ }
313
+
314
+ let WASM_VECTOR_LEN = 0;
315
+
316
+
317
+ let wasm;
318
+ export function __wbg_set_wasm(val) {
319
+ wasm = val;
320
+ }
Binary file
@@ -0,0 +1,15 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ export const memory: WebAssembly.Memory;
4
+ export const config_summary: () => [number, number];
5
+ export const embed: (a: number, b: number) => [number, number];
6
+ export const model_sha256: () => [number, number];
7
+ export const tokenize: (a: number, b: number) => [number, number];
8
+ export const tokenizer_sha256: () => [number, number];
9
+ export const __wbindgen_exn_store: (a: number) => void;
10
+ export const __externref_table_alloc: () => number;
11
+ export const __wbindgen_externrefs: WebAssembly.Table;
12
+ export const __wbindgen_free: (a: number, b: number, c: number) => void;
13
+ export const __wbindgen_malloc: (a: number, b: number) => number;
14
+ export const __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
15
+ export const __wbindgen_start: () => void;
@@ -0,0 +1,16 @@
1
+ /** Initialize once. Defaults to the adjacent WASM file (disk on Node/Bun, HTTP in browsers).
2
+ * A URL, bytes, or compiled module may be supplied instead. Failed loads can be retried.
3
+ * After the first successful initialization this instance keeps the same model.
4
+ */
5
+ export declare function init(source?: URL | BufferSource | WebAssembly.Module): Promise<void>;
6
+ export default init;
7
+ export declare class TernError extends Error {
8
+ code: string;
9
+ constructor(message: string, code: string);
10
+ }
11
+ /** Synchronous inference after await init(); returns a normalized 384-dimensional vector. */
12
+ export declare function embed(text: string): Float32Array;
13
+ /** Dot product; inputs must be L2-normalized and have equal dimensions. */
14
+ export declare function cosineSim(a: ArrayLike<number>, b: ArrayLike<number>): number;
15
+ export declare function similar(query: string, corpus: string[], opts?: { topK?: number }): { text: string; sim: number }[];
16
+ export declare function engineInfo(): string;