needle-rs 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,105 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+
4
+ /**
5
+ * WASM-exposed inference engine handle.
6
+ */
7
+ export class NeedleWasm {
8
+ private constructor();
9
+ free(): void;
10
+ [Symbol.dispose](): void;
11
+ /**
12
+ * Return the contrastive embedding dimension (0 if no contrastive head loaded).
13
+ */
14
+ contrastive_dim(): number;
15
+ /**
16
+ * Encode text to a L2-normalized contrastive embedding.
17
+ *
18
+ * Returns a `Float32Array` of length `contrastive_dim()`, or `null` if the
19
+ * model was loaded without a contrastive head.
20
+ *
21
+ * Cosine similarity between query and tool embeddings equals the dot product
22
+ * (both vectors are already L2-normalized).
23
+ */
24
+ encode_contrastive(text: string): Float32Array | undefined;
25
+ /**
26
+ * Load the engine from raw bytes.
27
+ *
28
+ * `weights_bytes`: ArrayBuffer / Uint8Array containing the .safetensors file.
29
+ * `vocab_text`: String content of vocab.txt (one piece per line).
30
+ */
31
+ static load(weights_bytes: Uint8Array, vocab_text: string): NeedleWasm | undefined;
32
+ /**
33
+ * Rank tool descriptions by contrastive similarity to a query.
34
+ *
35
+ * `tool_descs_json`: JSON array of description strings, e.g.
36
+ * `'["Get current weather", "Search the web", "Send email"]'`
37
+ *
38
+ * Returns a JSON string `[{"index":0,"score":0.95},{"index":2,"score":0.71}]`
39
+ * sorted by descending score, or `"[]"` if the model has no contrastive head.
40
+ *
41
+ * Mirrors Python `retrieve_tools(query, tools, top_k)` from `run.py`.
42
+ */
43
+ retrieve_tools(query: string, tool_descs_json: string, top_k: number): string;
44
+ /**
45
+ * Run inference and return the output JSON string.
46
+ *
47
+ * Returns e.g. `[{"name":"get_weather","arguments":{"location":"Paris"}}]`.
48
+ */
49
+ run(query: string, tools_json: string): string;
50
+ /**
51
+ * Run inference on multiple examples and return a JS Array of output strings.
52
+ *
53
+ * Input: JS Array of `{query: string, tools: string}` objects.
54
+ * Output: JS Array of output strings, one per input.
55
+ */
56
+ run_batch(examples: Array<any>): Array<any>;
57
+ /**
58
+ * Run inference with a per-token streaming callback.
59
+ *
60
+ * `on_token(tokenId: number, piece: string)` fires for each generated token
61
+ * in decode order. Returns the final post-processed output string.
62
+ */
63
+ run_stream(query: string, tools_json: string, on_token: Function): string;
64
+ }
65
+
66
+ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
67
+
68
+ export interface InitOutput {
69
+ readonly memory: WebAssembly.Memory;
70
+ readonly __wbg_needlewasm_free: (a: number, b: number) => void;
71
+ readonly needlewasm_contrastive_dim: (a: number) => number;
72
+ readonly needlewasm_encode_contrastive: (a: number, b: number, c: number, d: number) => void;
73
+ readonly needlewasm_load: (a: number, b: number, c: number, d: number) => number;
74
+ readonly needlewasm_retrieve_tools: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
75
+ readonly needlewasm_run: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
76
+ readonly needlewasm_run_batch: (a: number, b: number) => number;
77
+ readonly needlewasm_run_stream: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
78
+ readonly __wbindgen_export: (a: number, b: number) => number;
79
+ readonly __wbindgen_export2: (a: number, b: number, c: number, d: number) => number;
80
+ readonly __wbindgen_export3: (a: number) => void;
81
+ readonly __wbindgen_add_to_stack_pointer: (a: number) => number;
82
+ readonly __wbindgen_export4: (a: number, b: number, c: number) => void;
83
+ }
84
+
85
+ export type SyncInitInput = BufferSource | WebAssembly.Module;
86
+
87
+ /**
88
+ * Instantiates the given `module`, which can either be bytes or
89
+ * a precompiled `WebAssembly.Module`.
90
+ *
91
+ * @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
92
+ *
93
+ * @returns {InitOutput}
94
+ */
95
+ export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
96
+
97
+ /**
98
+ * If `module_or_path` is {RequestInfo} or {URL}, makes a request and
99
+ * for everything else, calls `WebAssembly.instantiate` directly.
100
+ *
101
+ * @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
102
+ *
103
+ * @returns {Promise<InitOutput>}
104
+ */
105
+ export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
package/needle_wasm.js ADDED
@@ -0,0 +1,500 @@
1
+ /* @ts-self-types="./needle_wasm.d.ts" */
2
+
3
+ /**
4
+ * WASM-exposed inference engine handle.
5
+ */
6
+ export class NeedleWasm {
7
+ static __wrap(ptr) {
8
+ const obj = Object.create(NeedleWasm.prototype);
9
+ obj.__wbg_ptr = ptr;
10
+ NeedleWasmFinalization.register(obj, obj.__wbg_ptr, obj);
11
+ return obj;
12
+ }
13
+ __destroy_into_raw() {
14
+ const ptr = this.__wbg_ptr;
15
+ this.__wbg_ptr = 0;
16
+ NeedleWasmFinalization.unregister(this);
17
+ return ptr;
18
+ }
19
+ free() {
20
+ const ptr = this.__destroy_into_raw();
21
+ wasm.__wbg_needlewasm_free(ptr, 0);
22
+ }
23
+ /**
24
+ * Return the contrastive embedding dimension (0 if no contrastive head loaded).
25
+ * @returns {number}
26
+ */
27
+ contrastive_dim() {
28
+ const ret = wasm.needlewasm_contrastive_dim(this.__wbg_ptr);
29
+ return ret >>> 0;
30
+ }
31
+ /**
32
+ * Encode text to a L2-normalized contrastive embedding.
33
+ *
34
+ * Returns a `Float32Array` of length `contrastive_dim()`, or `null` if the
35
+ * model was loaded without a contrastive head.
36
+ *
37
+ * Cosine similarity between query and tool embeddings equals the dot product
38
+ * (both vectors are already L2-normalized).
39
+ * @param {string} text
40
+ * @returns {Float32Array | undefined}
41
+ */
42
+ encode_contrastive(text) {
43
+ try {
44
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
45
+ const ptr0 = passStringToWasm0(text, wasm.__wbindgen_export, wasm.__wbindgen_export2);
46
+ const len0 = WASM_VECTOR_LEN;
47
+ wasm.needlewasm_encode_contrastive(retptr, this.__wbg_ptr, ptr0, len0);
48
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
49
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
50
+ let v2;
51
+ if (r0 !== 0) {
52
+ v2 = getArrayF32FromWasm0(r0, r1).slice();
53
+ wasm.__wbindgen_export4(r0, r1 * 4, 4);
54
+ }
55
+ return v2;
56
+ } finally {
57
+ wasm.__wbindgen_add_to_stack_pointer(16);
58
+ }
59
+ }
60
+ /**
61
+ * Load the engine from raw bytes.
62
+ *
63
+ * `weights_bytes`: ArrayBuffer / Uint8Array containing the .safetensors file.
64
+ * `vocab_text`: String content of vocab.txt (one piece per line).
65
+ * @param {Uint8Array} weights_bytes
66
+ * @param {string} vocab_text
67
+ * @returns {NeedleWasm | undefined}
68
+ */
69
+ static load(weights_bytes, vocab_text) {
70
+ const ptr0 = passArray8ToWasm0(weights_bytes, wasm.__wbindgen_export);
71
+ const len0 = WASM_VECTOR_LEN;
72
+ const ptr1 = passStringToWasm0(vocab_text, wasm.__wbindgen_export, wasm.__wbindgen_export2);
73
+ const len1 = WASM_VECTOR_LEN;
74
+ const ret = wasm.needlewasm_load(ptr0, len0, ptr1, len1);
75
+ return ret === 0 ? undefined : NeedleWasm.__wrap(ret);
76
+ }
77
+ /**
78
+ * Rank tool descriptions by contrastive similarity to a query.
79
+ *
80
+ * `tool_descs_json`: JSON array of description strings, e.g.
81
+ * `'["Get current weather", "Search the web", "Send email"]'`
82
+ *
83
+ * Returns a JSON string `[{"index":0,"score":0.95},{"index":2,"score":0.71}]`
84
+ * sorted by descending score, or `"[]"` if the model has no contrastive head.
85
+ *
86
+ * Mirrors Python `retrieve_tools(query, tools, top_k)` from `run.py`.
87
+ * @param {string} query
88
+ * @param {string} tool_descs_json
89
+ * @param {number} top_k
90
+ * @returns {string}
91
+ */
92
+ retrieve_tools(query, tool_descs_json, top_k) {
93
+ let deferred3_0;
94
+ let deferred3_1;
95
+ try {
96
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
97
+ const ptr0 = passStringToWasm0(query, wasm.__wbindgen_export, wasm.__wbindgen_export2);
98
+ const len0 = WASM_VECTOR_LEN;
99
+ const ptr1 = passStringToWasm0(tool_descs_json, wasm.__wbindgen_export, wasm.__wbindgen_export2);
100
+ const len1 = WASM_VECTOR_LEN;
101
+ wasm.needlewasm_retrieve_tools(retptr, this.__wbg_ptr, ptr0, len0, ptr1, len1, top_k);
102
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
103
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
104
+ deferred3_0 = r0;
105
+ deferred3_1 = r1;
106
+ return getStringFromWasm0(r0, r1);
107
+ } finally {
108
+ wasm.__wbindgen_add_to_stack_pointer(16);
109
+ wasm.__wbindgen_export4(deferred3_0, deferred3_1, 1);
110
+ }
111
+ }
112
+ /**
113
+ * Run inference and return the output JSON string.
114
+ *
115
+ * Returns e.g. `[{"name":"get_weather","arguments":{"location":"Paris"}}]`.
116
+ * @param {string} query
117
+ * @param {string} tools_json
118
+ * @returns {string}
119
+ */
120
+ run(query, tools_json) {
121
+ let deferred3_0;
122
+ let deferred3_1;
123
+ try {
124
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
125
+ const ptr0 = passStringToWasm0(query, wasm.__wbindgen_export, wasm.__wbindgen_export2);
126
+ const len0 = WASM_VECTOR_LEN;
127
+ const ptr1 = passStringToWasm0(tools_json, wasm.__wbindgen_export, wasm.__wbindgen_export2);
128
+ const len1 = WASM_VECTOR_LEN;
129
+ wasm.needlewasm_run(retptr, this.__wbg_ptr, ptr0, len0, ptr1, len1);
130
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
131
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
132
+ deferred3_0 = r0;
133
+ deferred3_1 = r1;
134
+ return getStringFromWasm0(r0, r1);
135
+ } finally {
136
+ wasm.__wbindgen_add_to_stack_pointer(16);
137
+ wasm.__wbindgen_export4(deferred3_0, deferred3_1, 1);
138
+ }
139
+ }
140
+ /**
141
+ * Run inference on multiple examples and return a JS Array of output strings.
142
+ *
143
+ * Input: JS Array of `{query: string, tools: string}` objects.
144
+ * Output: JS Array of output strings, one per input.
145
+ * @param {Array<any>} examples
146
+ * @returns {Array<any>}
147
+ */
148
+ run_batch(examples) {
149
+ try {
150
+ const ret = wasm.needlewasm_run_batch(this.__wbg_ptr, addBorrowedObject(examples));
151
+ return takeObject(ret);
152
+ } finally {
153
+ heap[stack_pointer++] = undefined;
154
+ }
155
+ }
156
+ /**
157
+ * Run inference with a per-token streaming callback.
158
+ *
159
+ * `on_token(tokenId: number, piece: string)` fires for each generated token
160
+ * in decode order. Returns the final post-processed output string.
161
+ * @param {string} query
162
+ * @param {string} tools_json
163
+ * @param {Function} on_token
164
+ * @returns {string}
165
+ */
166
+ run_stream(query, tools_json, on_token) {
167
+ let deferred3_0;
168
+ let deferred3_1;
169
+ try {
170
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
171
+ const ptr0 = passStringToWasm0(query, wasm.__wbindgen_export, wasm.__wbindgen_export2);
172
+ const len0 = WASM_VECTOR_LEN;
173
+ const ptr1 = passStringToWasm0(tools_json, wasm.__wbindgen_export, wasm.__wbindgen_export2);
174
+ const len1 = WASM_VECTOR_LEN;
175
+ wasm.needlewasm_run_stream(retptr, this.__wbg_ptr, ptr0, len0, ptr1, len1, addBorrowedObject(on_token));
176
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
177
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
178
+ deferred3_0 = r0;
179
+ deferred3_1 = r1;
180
+ return getStringFromWasm0(r0, r1);
181
+ } finally {
182
+ wasm.__wbindgen_add_to_stack_pointer(16);
183
+ heap[stack_pointer++] = undefined;
184
+ wasm.__wbindgen_export4(deferred3_0, deferred3_1, 1);
185
+ }
186
+ }
187
+ }
188
+ if (Symbol.dispose) NeedleWasm.prototype[Symbol.dispose] = NeedleWasm.prototype.free;
189
+ function __wbg_get_imports() {
190
+ const import0 = {
191
+ __proto__: null,
192
+ __wbg___wbindgen_string_get_d109740c0d18f4d7: function(arg0, arg1) {
193
+ const obj = getObject(arg1);
194
+ const ret = typeof(obj) === 'string' ? obj : undefined;
195
+ var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_export, wasm.__wbindgen_export2);
196
+ var len1 = WASM_VECTOR_LEN;
197
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
198
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
199
+ },
200
+ __wbg___wbindgen_throw_9c31b086c2b26051: function(arg0, arg1) {
201
+ throw new Error(getStringFromWasm0(arg0, arg1));
202
+ },
203
+ __wbg_call_faa0a261f288f846: function() { return handleError(function (arg0, arg1, arg2, arg3) {
204
+ const ret = getObject(arg0).call(getObject(arg1), getObject(arg2), getObject(arg3));
205
+ return addHeapObject(ret);
206
+ }, arguments); },
207
+ __wbg_error_f085d7e62279b703: function(arg0) {
208
+ console.error(getObject(arg0));
209
+ },
210
+ __wbg_get_98fdf51d029a75eb: function(arg0, arg1) {
211
+ const ret = getObject(arg0)[arg1 >>> 0];
212
+ return addHeapObject(ret);
213
+ },
214
+ __wbg_get_dcf82ab8aad1a593: function() { return handleError(function (arg0, arg1) {
215
+ const ret = Reflect.get(getObject(arg0), getObject(arg1));
216
+ return addHeapObject(ret);
217
+ }, arguments); },
218
+ __wbg_length_2591a0f4f659a55c: function(arg0) {
219
+ const ret = getObject(arg0).length;
220
+ return ret;
221
+ },
222
+ __wbg_new_310879b66b6e95e1: function() {
223
+ const ret = new Array();
224
+ return addHeapObject(ret);
225
+ },
226
+ __wbg_push_b77c476b01548d0a: function(arg0, arg1) {
227
+ const ret = getObject(arg0).push(getObject(arg1));
228
+ return ret;
229
+ },
230
+ __wbindgen_cast_0000000000000001: function(arg0) {
231
+ // Cast intrinsic for `F64 -> Externref`.
232
+ const ret = arg0;
233
+ return addHeapObject(ret);
234
+ },
235
+ __wbindgen_cast_0000000000000002: function(arg0, arg1) {
236
+ // Cast intrinsic for `Ref(String) -> Externref`.
237
+ const ret = getStringFromWasm0(arg0, arg1);
238
+ return addHeapObject(ret);
239
+ },
240
+ __wbindgen_object_drop_ref: function(arg0) {
241
+ takeObject(arg0);
242
+ },
243
+ };
244
+ return {
245
+ __proto__: null,
246
+ "./needle_wasm_bg.js": import0,
247
+ };
248
+ }
249
+
250
+ const NeedleWasmFinalization = (typeof FinalizationRegistry === 'undefined')
251
+ ? { register: () => {}, unregister: () => {} }
252
+ : new FinalizationRegistry(ptr => wasm.__wbg_needlewasm_free(ptr, 1));
253
+
254
+ function addHeapObject(obj) {
255
+ if (heap_next === heap.length) heap.push(heap.length + 1);
256
+ const idx = heap_next;
257
+ heap_next = heap[idx];
258
+
259
+ heap[idx] = obj;
260
+ return idx;
261
+ }
262
+
263
+ function addBorrowedObject(obj) {
264
+ if (stack_pointer == 1) throw new Error('out of js stack');
265
+ heap[--stack_pointer] = obj;
266
+ return stack_pointer;
267
+ }
268
+
269
+ function dropObject(idx) {
270
+ if (idx < 1028) return;
271
+ heap[idx] = heap_next;
272
+ heap_next = idx;
273
+ }
274
+
275
+ function getArrayF32FromWasm0(ptr, len) {
276
+ ptr = ptr >>> 0;
277
+ return getFloat32ArrayMemory0().subarray(ptr / 4, ptr / 4 + len);
278
+ }
279
+
280
+ let cachedDataViewMemory0 = null;
281
+ function getDataViewMemory0() {
282
+ if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
283
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
284
+ }
285
+ return cachedDataViewMemory0;
286
+ }
287
+
288
+ let cachedFloat32ArrayMemory0 = null;
289
+ function getFloat32ArrayMemory0() {
290
+ if (cachedFloat32ArrayMemory0 === null || cachedFloat32ArrayMemory0.byteLength === 0) {
291
+ cachedFloat32ArrayMemory0 = new Float32Array(wasm.memory.buffer);
292
+ }
293
+ return cachedFloat32ArrayMemory0;
294
+ }
295
+
296
+ function getStringFromWasm0(ptr, len) {
297
+ return decodeText(ptr >>> 0, len);
298
+ }
299
+
300
+ let cachedUint8ArrayMemory0 = null;
301
+ function getUint8ArrayMemory0() {
302
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
303
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
304
+ }
305
+ return cachedUint8ArrayMemory0;
306
+ }
307
+
308
+ function getObject(idx) { return heap[idx]; }
309
+
310
+ function handleError(f, args) {
311
+ try {
312
+ return f.apply(this, args);
313
+ } catch (e) {
314
+ wasm.__wbindgen_export3(addHeapObject(e));
315
+ }
316
+ }
317
+
318
+ let heap = new Array(1024).fill(undefined);
319
+ heap.push(undefined, null, true, false);
320
+
321
+ let heap_next = heap.length;
322
+
323
+ function isLikeNone(x) {
324
+ return x === undefined || x === null;
325
+ }
326
+
327
+ function passArray8ToWasm0(arg, malloc) {
328
+ const ptr = malloc(arg.length * 1, 1) >>> 0;
329
+ getUint8ArrayMemory0().set(arg, ptr / 1);
330
+ WASM_VECTOR_LEN = arg.length;
331
+ return ptr;
332
+ }
333
+
334
+ function passStringToWasm0(arg, malloc, realloc) {
335
+ if (realloc === undefined) {
336
+ const buf = cachedTextEncoder.encode(arg);
337
+ const ptr = malloc(buf.length, 1) >>> 0;
338
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
339
+ WASM_VECTOR_LEN = buf.length;
340
+ return ptr;
341
+ }
342
+
343
+ let len = arg.length;
344
+ let ptr = malloc(len, 1) >>> 0;
345
+
346
+ const mem = getUint8ArrayMemory0();
347
+
348
+ let offset = 0;
349
+
350
+ for (; offset < len; offset++) {
351
+ const code = arg.charCodeAt(offset);
352
+ if (code > 0x7F) break;
353
+ mem[ptr + offset] = code;
354
+ }
355
+ if (offset !== len) {
356
+ if (offset !== 0) {
357
+ arg = arg.slice(offset);
358
+ }
359
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
360
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
361
+ const ret = cachedTextEncoder.encodeInto(arg, view);
362
+
363
+ offset += ret.written;
364
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
365
+ }
366
+
367
+ WASM_VECTOR_LEN = offset;
368
+ return ptr;
369
+ }
370
+
371
+ let stack_pointer = 1024;
372
+
373
+ function takeObject(idx) {
374
+ const ret = getObject(idx);
375
+ dropObject(idx);
376
+ return ret;
377
+ }
378
+
379
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
380
+ cachedTextDecoder.decode();
381
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
382
+ let numBytesDecoded = 0;
383
+ function decodeText(ptr, len) {
384
+ numBytesDecoded += len;
385
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
386
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
387
+ cachedTextDecoder.decode();
388
+ numBytesDecoded = len;
389
+ }
390
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
391
+ }
392
+
393
+ const cachedTextEncoder = new TextEncoder();
394
+
395
+ if (!('encodeInto' in cachedTextEncoder)) {
396
+ cachedTextEncoder.encodeInto = function (arg, view) {
397
+ const buf = cachedTextEncoder.encode(arg);
398
+ view.set(buf);
399
+ return {
400
+ read: arg.length,
401
+ written: buf.length
402
+ };
403
+ };
404
+ }
405
+
406
+ let WASM_VECTOR_LEN = 0;
407
+
408
+ let wasmModule, wasmInstance, wasm;
409
+ function __wbg_finalize_init(instance, module) {
410
+ wasmInstance = instance;
411
+ wasm = instance.exports;
412
+ wasmModule = module;
413
+ cachedDataViewMemory0 = null;
414
+ cachedFloat32ArrayMemory0 = null;
415
+ cachedUint8ArrayMemory0 = null;
416
+ return wasm;
417
+ }
418
+
419
+ async function __wbg_load(module, imports) {
420
+ if (typeof Response === 'function' && module instanceof Response) {
421
+ if (typeof WebAssembly.instantiateStreaming === 'function') {
422
+ try {
423
+ return await WebAssembly.instantiateStreaming(module, imports);
424
+ } catch (e) {
425
+ const validResponse = module.ok && expectedResponseType(module.type);
426
+
427
+ if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
428
+ 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);
429
+
430
+ } else { throw e; }
431
+ }
432
+ }
433
+
434
+ const bytes = await module.arrayBuffer();
435
+ return await WebAssembly.instantiate(bytes, imports);
436
+ } else {
437
+ const instance = await WebAssembly.instantiate(module, imports);
438
+
439
+ if (instance instanceof WebAssembly.Instance) {
440
+ return { instance, module };
441
+ } else {
442
+ return instance;
443
+ }
444
+ }
445
+
446
+ function expectedResponseType(type) {
447
+ switch (type) {
448
+ case 'basic': case 'cors': case 'default': return true;
449
+ }
450
+ return false;
451
+ }
452
+ }
453
+
454
+ function initSync(module) {
455
+ if (wasm !== undefined) return wasm;
456
+
457
+
458
+ if (module !== undefined) {
459
+ if (Object.getPrototypeOf(module) === Object.prototype) {
460
+ ({module} = module)
461
+ } else {
462
+ console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
463
+ }
464
+ }
465
+
466
+ const imports = __wbg_get_imports();
467
+ if (!(module instanceof WebAssembly.Module)) {
468
+ module = new WebAssembly.Module(module);
469
+ }
470
+ const instance = new WebAssembly.Instance(module, imports);
471
+ return __wbg_finalize_init(instance, module);
472
+ }
473
+
474
+ async function __wbg_init(module_or_path) {
475
+ if (wasm !== undefined) return wasm;
476
+
477
+
478
+ if (module_or_path !== undefined) {
479
+ if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
480
+ ({module_or_path} = module_or_path)
481
+ } else {
482
+ console.warn('using deprecated parameters for the initialization function; pass a single object instead')
483
+ }
484
+ }
485
+
486
+ if (module_or_path === undefined) {
487
+ module_or_path = new URL('needle_wasm_bg.wasm', import.meta.url);
488
+ }
489
+ const imports = __wbg_get_imports();
490
+
491
+ if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
492
+ module_or_path = fetch(module_or_path);
493
+ }
494
+
495
+ const { instance, module } = await __wbg_load(await module_or_path, imports);
496
+
497
+ return __wbg_finalize_init(instance, module);
498
+ }
499
+
500
+ export { initSync, __wbg_init as default };
Binary file
@@ -0,0 +1,16 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ export const memory: WebAssembly.Memory;
4
+ export const __wbg_needlewasm_free: (a: number, b: number) => void;
5
+ export const needlewasm_contrastive_dim: (a: number) => number;
6
+ export const needlewasm_encode_contrastive: (a: number, b: number, c: number, d: number) => void;
7
+ export const needlewasm_load: (a: number, b: number, c: number, d: number) => number;
8
+ export const needlewasm_retrieve_tools: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
9
+ export const needlewasm_run: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
10
+ export const needlewasm_run_batch: (a: number, b: number) => number;
11
+ export const needlewasm_run_stream: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
12
+ export const __wbindgen_export: (a: number, b: number) => number;
13
+ export const __wbindgen_export2: (a: number, b: number, c: number, d: number) => number;
14
+ export const __wbindgen_export3: (a: number) => void;
15
+ export const __wbindgen_add_to_stack_pointer: (a: number) => number;
16
+ export const __wbindgen_export4: (a: number, b: number, c: number) => void;
package/package.json ADDED
@@ -0,0 +1,38 @@
1
+ {
2
+ "name": "needle-rs",
3
+ "version": "0.1.0",
4
+ "description": "258 KB WASM runtime for Needle \u2014 a 26M-parameter tool-calling transformer. Runs in the browser, Cloudflare Workers, and Node.js. No backend required.",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/geekgineer/needle-rs"
9
+ },
10
+ "homepage": "https://github.com/geekgineer/needle-rs",
11
+ "keywords": [
12
+ "wasm",
13
+ "webassembly",
14
+ "ai",
15
+ "llm",
16
+ "tool-calling",
17
+ "function-calling",
18
+ "transformer",
19
+ "rust",
20
+ "no-backend",
21
+ "browser-ai"
22
+ ],
23
+ "files": [
24
+ "needle_wasm_bg.wasm",
25
+ "needle_wasm_bg.wasm.d.ts",
26
+ "needle_wasm.js",
27
+ "needle_wasm.d.ts"
28
+ ],
29
+ "module": "needle_wasm.js",
30
+ "types": "needle_wasm.d.ts",
31
+ "exports": {
32
+ ".": {
33
+ "import": "./needle_wasm.js",
34
+ "types": "./needle_wasm.d.ts"
35
+ }
36
+ },
37
+ "sideEffects": false
38
+ }