tinfoil 0.9.1 → 0.10.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/README.md +34 -0
  2. package/dist/ai-sdk-provider.js +8 -3
  3. package/dist/config.d.ts +4 -11
  4. package/dist/config.js +4 -11
  5. package/dist/encrypted-body-fetch.d.ts +3 -5
  6. package/dist/encrypted-body-fetch.js +34 -93
  7. package/dist/esm/{ai-sdk-provider.js → ai-sdk-provider.mjs} +10 -5
  8. package/dist/esm/config.d.ts +4 -11
  9. package/dist/esm/config.mjs +13 -0
  10. package/dist/esm/encrypted-body-fetch.d.ts +3 -5
  11. package/dist/esm/{encrypted-body-fetch.js → encrypted-body-fetch.mjs} +29 -54
  12. package/dist/esm/index.browser.mjs +8 -0
  13. package/dist/esm/index.d.ts +1 -0
  14. package/dist/esm/{index.js → index.mjs} +8 -7
  15. package/dist/esm/router.d.ts +11 -0
  16. package/dist/esm/router.mjs +33 -0
  17. package/dist/esm/secure-client.d.ts +3 -2
  18. package/dist/esm/secure-client.mjs +153 -0
  19. package/dist/esm/{secure-fetch.browser.js → secure-fetch.browser.mjs} +1 -1
  20. package/dist/esm/{secure-fetch.js → secure-fetch.mjs} +3 -3
  21. package/dist/esm/{tinfoilai.js → tinfoilai.mjs} +8 -6
  22. package/dist/esm/unverified-client.d.ts +2 -2
  23. package/dist/esm/unverified-client.mjs +61 -0
  24. package/dist/esm/verifier.d.ts +4 -1
  25. package/dist/esm/{verifier.js → verifier.mjs} +18 -6
  26. package/dist/esm/wasm-exec.mjs +668 -0
  27. package/dist/index.d.ts +1 -0
  28. package/dist/index.js +3 -1
  29. package/dist/router.d.ts +11 -0
  30. package/dist/router.js +36 -0
  31. package/dist/secure-client.d.ts +3 -2
  32. package/dist/secure-client.js +116 -13
  33. package/dist/tinfoilai.js +5 -3
  34. package/dist/unverified-client.d.ts +2 -2
  35. package/dist/unverified-client.js +30 -2
  36. package/dist/verifier.d.ts +4 -1
  37. package/dist/verifier.js +16 -4
  38. package/package.json +15 -15
  39. package/dist/esm/config.js +0 -20
  40. package/dist/esm/index.browser.js +0 -8
  41. package/dist/esm/secure-client.js +0 -50
  42. package/dist/esm/unverified-client.js +0 -33
  43. /package/dist/esm/__tests__/{test-utils.js → test-utils.mjs} +0 -0
  44. /package/dist/esm/{env.js → env.mjs} +0 -0
  45. /package/dist/esm/{pinned-tls-fetch.js → pinned-tls-fetch.mjs} +0 -0
@@ -0,0 +1,668 @@
1
+ // Copyright 2018 The Go Authors. All rights reserved.
2
+ // Use of this source code is governed by a BSD-style
3
+ // license that can be found in the LICENSE file.
4
+
5
+ "use strict";
6
+
7
+ (() => {
8
+ const enosys = () => {
9
+ const err = new Error("not implemented");
10
+ err.code = "ENOSYS";
11
+ return err;
12
+ };
13
+
14
+ if (!globalThis.fs) {
15
+ let outputBuf = "";
16
+ globalThis.fs = {
17
+ constants: {
18
+ O_WRONLY: -1,
19
+ O_RDWR: -1,
20
+ O_CREAT: -1,
21
+ O_TRUNC: -1,
22
+ O_APPEND: -1,
23
+ O_EXCL: -1,
24
+ }, // unused
25
+ writeSync(fd, buf) {
26
+ outputBuf += decoder.decode(buf);
27
+ const nl = outputBuf.lastIndexOf("\n");
28
+ if (nl != -1) {
29
+ console.log(outputBuf.substring(0, nl));
30
+ outputBuf = outputBuf.substring(nl + 1);
31
+ }
32
+ return buf.length;
33
+ },
34
+ write(fd, buf, offset, length, position, callback) {
35
+ if (offset !== 0 || length !== buf.length || position !== null) {
36
+ callback(enosys());
37
+ return;
38
+ }
39
+ const n = this.writeSync(fd, buf);
40
+ callback(null, n);
41
+ },
42
+ chmod(path, mode, callback) {
43
+ callback(enosys());
44
+ },
45
+ chown(path, uid, gid, callback) {
46
+ callback(enosys());
47
+ },
48
+ close(fd, callback) {
49
+ callback(enosys());
50
+ },
51
+ fchmod(fd, mode, callback) {
52
+ callback(enosys());
53
+ },
54
+ fchown(fd, uid, gid, callback) {
55
+ callback(enosys());
56
+ },
57
+ fstat(fd, callback) {
58
+ callback(enosys());
59
+ },
60
+ fsync(fd, callback) {
61
+ callback(null);
62
+ },
63
+ ftruncate(fd, length, callback) {
64
+ callback(enosys());
65
+ },
66
+ lchown(path, uid, gid, callback) {
67
+ callback(enosys());
68
+ },
69
+ link(path, link, callback) {
70
+ callback(enosys());
71
+ },
72
+ lstat(path, callback) {
73
+ callback(enosys());
74
+ },
75
+ mkdir(path, perm, callback) {
76
+ callback(enosys());
77
+ },
78
+ open(path, flags, mode, callback) {
79
+ callback(enosys());
80
+ },
81
+ read(fd, buffer, offset, length, position, callback) {
82
+ callback(enosys());
83
+ },
84
+ readdir(path, callback) {
85
+ callback(enosys());
86
+ },
87
+ readlink(path, callback) {
88
+ callback(enosys());
89
+ },
90
+ rename(from, to, callback) {
91
+ callback(enosys());
92
+ },
93
+ rmdir(path, callback) {
94
+ callback(enosys());
95
+ },
96
+ stat(path, callback) {
97
+ callback(enosys());
98
+ },
99
+ symlink(path, link, callback) {
100
+ callback(enosys());
101
+ },
102
+ truncate(path, length, callback) {
103
+ callback(enosys());
104
+ },
105
+ unlink(path, callback) {
106
+ callback(enosys());
107
+ },
108
+ utimes(path, atime, mtime, callback) {
109
+ callback(enosys());
110
+ },
111
+ };
112
+ }
113
+
114
+ if (!globalThis.process) {
115
+ globalThis.process = {
116
+ getuid() {
117
+ return -1;
118
+ },
119
+ getgid() {
120
+ return -1;
121
+ },
122
+ geteuid() {
123
+ return -1;
124
+ },
125
+ getegid() {
126
+ return -1;
127
+ },
128
+ getgroups() {
129
+ throw enosys();
130
+ },
131
+ pid: -1,
132
+ ppid: -1,
133
+ umask() {
134
+ throw enosys();
135
+ },
136
+ cwd() {
137
+ throw enosys();
138
+ },
139
+ chdir() {
140
+ throw enosys();
141
+ },
142
+ };
143
+ }
144
+
145
+ if (!globalThis.crypto) {
146
+ throw new Error(
147
+ "globalThis.crypto is not available, polyfill required (crypto.getRandomValues only)",
148
+ );
149
+ }
150
+
151
+ if (!globalThis.performance) {
152
+ throw new Error(
153
+ "globalThis.performance is not available, polyfill required (performance.now only)",
154
+ );
155
+ }
156
+
157
+ if (!globalThis.TextEncoder) {
158
+ throw new Error(
159
+ "globalThis.TextEncoder is not available, polyfill required",
160
+ );
161
+ }
162
+
163
+ if (!globalThis.TextDecoder) {
164
+ throw new Error(
165
+ "globalThis.TextDecoder is not available, polyfill required",
166
+ );
167
+ }
168
+
169
+ const encoder = new TextEncoder("utf-8");
170
+ const decoder = new TextDecoder("utf-8");
171
+
172
+ globalThis.Go = class {
173
+ constructor() {
174
+ this.argv = ["js"];
175
+ this.env = {};
176
+ this.exit = (code) => {
177
+ if (code !== 0) {
178
+ console.warn("exit code:", code);
179
+ }
180
+ };
181
+ this._exitPromise = new Promise((resolve) => {
182
+ this._resolveExitPromise = resolve;
183
+ });
184
+ this._pendingEvent = null;
185
+ this._scheduledTimeouts = new Map();
186
+ this._nextCallbackTimeoutID = 1;
187
+
188
+ const setInt64 = (addr, v) => {
189
+ this.mem.setUint32(addr + 0, v, true);
190
+ this.mem.setUint32(addr + 4, Math.floor(v / 4294967296), true);
191
+ };
192
+
193
+ const setInt32 = (addr, v) => {
194
+ this.mem.setUint32(addr + 0, v, true);
195
+ };
196
+
197
+ const getInt64 = (addr) => {
198
+ const low = this.mem.getUint32(addr + 0, true);
199
+ const high = this.mem.getInt32(addr + 4, true);
200
+ return low + high * 4294967296;
201
+ };
202
+
203
+ const loadValue = (addr) => {
204
+ const f = this.mem.getFloat64(addr, true);
205
+ if (f === 0) {
206
+ return undefined;
207
+ }
208
+ if (!isNaN(f)) {
209
+ return f;
210
+ }
211
+
212
+ const id = this.mem.getUint32(addr, true);
213
+ return this._values[id];
214
+ };
215
+
216
+ const storeValue = (addr, v) => {
217
+ const nanHead = 0x7ff80000;
218
+
219
+ if (typeof v === "number" && v !== 0) {
220
+ if (isNaN(v)) {
221
+ this.mem.setUint32(addr + 4, nanHead, true);
222
+ this.mem.setUint32(addr, 0, true);
223
+ return;
224
+ }
225
+ this.mem.setFloat64(addr, v, true);
226
+ return;
227
+ }
228
+
229
+ if (v === undefined) {
230
+ this.mem.setFloat64(addr, 0, true);
231
+ return;
232
+ }
233
+
234
+ let id = this._ids.get(v);
235
+ if (id === undefined) {
236
+ id = this._idPool.pop();
237
+ if (id === undefined) {
238
+ id = this._values.length;
239
+ }
240
+ this._values[id] = v;
241
+ this._goRefCounts[id] = 0;
242
+ this._ids.set(v, id);
243
+ }
244
+ this._goRefCounts[id]++;
245
+ let typeFlag = 0;
246
+ switch (typeof v) {
247
+ case "object":
248
+ if (v !== null) {
249
+ typeFlag = 1;
250
+ }
251
+ break;
252
+ case "string":
253
+ typeFlag = 2;
254
+ break;
255
+ case "symbol":
256
+ typeFlag = 3;
257
+ break;
258
+ case "function":
259
+ typeFlag = 4;
260
+ break;
261
+ }
262
+ this.mem.setUint32(addr + 4, nanHead | typeFlag, true);
263
+ this.mem.setUint32(addr, id, true);
264
+ };
265
+
266
+ const loadSlice = (addr) => {
267
+ const array = getInt64(addr + 0);
268
+ const len = getInt64(addr + 8);
269
+ return new Uint8Array(this._inst.exports.mem.buffer, array, len);
270
+ };
271
+
272
+ const loadSliceOfValues = (addr) => {
273
+ const array = getInt64(addr + 0);
274
+ const len = getInt64(addr + 8);
275
+ const a = new Array(len);
276
+ for (let i = 0; i < len; i++) {
277
+ a[i] = loadValue(array + i * 8);
278
+ }
279
+ return a;
280
+ };
281
+
282
+ const loadString = (addr) => {
283
+ const saddr = getInt64(addr + 0);
284
+ const len = getInt64(addr + 8);
285
+ return decoder.decode(
286
+ new DataView(this._inst.exports.mem.buffer, saddr, len),
287
+ );
288
+ };
289
+
290
+ const timeOrigin = Date.now() - performance.now();
291
+ this.importObject = {
292
+ _gotest: {
293
+ add: (a, b) => a + b,
294
+ },
295
+ gojs: {
296
+ // Go's SP does not change as long as no Go code is running. Some operations (e.g. calls, getters and setters)
297
+ // may synchronously trigger a Go event handler. This makes Go code get executed in the middle of the imported
298
+ // function. A goroutine can switch to a new stack if the current stack is too small (see morestack function).
299
+ // This changes the SP, thus we have to update the SP used by the imported function.
300
+
301
+ // func wasmExit(code int32)
302
+ "runtime.wasmExit": (sp) => {
303
+ sp >>>= 0;
304
+ const code = this.mem.getInt32(sp + 8, true);
305
+ this.exited = true;
306
+ delete this._inst;
307
+ delete this._values;
308
+ delete this._goRefCounts;
309
+ delete this._ids;
310
+ delete this._idPool;
311
+ this.exit(code);
312
+ },
313
+
314
+ // func wasmWrite(fd uintptr, p unsafe.Pointer, n int32)
315
+ "runtime.wasmWrite": (sp) => {
316
+ sp >>>= 0;
317
+ const fd = getInt64(sp + 8);
318
+ const p = getInt64(sp + 16);
319
+ const n = this.mem.getInt32(sp + 24, true);
320
+ fs.writeSync(
321
+ fd,
322
+ new Uint8Array(this._inst.exports.mem.buffer, p, n),
323
+ );
324
+ },
325
+
326
+ // func resetMemoryDataView()
327
+ "runtime.resetMemoryDataView": (sp) => {
328
+ sp >>>= 0;
329
+ this.mem = new DataView(this._inst.exports.mem.buffer);
330
+ },
331
+
332
+ // func nanotime1() int64
333
+ "runtime.nanotime1": (sp) => {
334
+ sp >>>= 0;
335
+ setInt64(sp + 8, (timeOrigin + performance.now()) * 1000000);
336
+ },
337
+
338
+ // func walltime() (sec int64, nsec int32)
339
+ "runtime.walltime": (sp) => {
340
+ sp >>>= 0;
341
+ const msec = new Date().getTime();
342
+ setInt64(sp + 8, msec / 1000);
343
+ this.mem.setInt32(sp + 16, (msec % 1000) * 1000000, true);
344
+ },
345
+
346
+ // func scheduleTimeoutEvent(delay int64) int32
347
+ "runtime.scheduleTimeoutEvent": (sp) => {
348
+ sp >>>= 0;
349
+ const id = this._nextCallbackTimeoutID;
350
+ this._nextCallbackTimeoutID++;
351
+ this._scheduledTimeouts.set(
352
+ id,
353
+ setTimeout(
354
+ () => {
355
+ this._resume();
356
+ while (this._scheduledTimeouts.has(id)) {
357
+ // for some reason Go failed to register the timeout event, log and try again
358
+ // (temporary workaround for https://github.com/golang/go/issues/28975)
359
+ console.warn("scheduleTimeoutEvent: missed timeout event");
360
+ this._resume();
361
+ }
362
+ },
363
+ getInt64(sp + 8),
364
+ ),
365
+ );
366
+ this.mem.setInt32(sp + 16, id, true);
367
+ },
368
+
369
+ // func clearTimeoutEvent(id int32)
370
+ "runtime.clearTimeoutEvent": (sp) => {
371
+ sp >>>= 0;
372
+ const id = this.mem.getInt32(sp + 8, true);
373
+ clearTimeout(this._scheduledTimeouts.get(id));
374
+ this._scheduledTimeouts.delete(id);
375
+ },
376
+
377
+ // func getRandomData(r []byte)
378
+ "runtime.getRandomData": (sp) => {
379
+ sp >>>= 0;
380
+ crypto.getRandomValues(loadSlice(sp + 8));
381
+ },
382
+
383
+ // func finalizeRef(v ref)
384
+ "syscall/js.finalizeRef": (sp) => {
385
+ sp >>>= 0;
386
+ const id = this.mem.getUint32(sp + 8, true);
387
+ this._goRefCounts[id]--;
388
+ if (this._goRefCounts[id] === 0) {
389
+ const v = this._values[id];
390
+ this._values[id] = null;
391
+ this._ids.delete(v);
392
+ this._idPool.push(id);
393
+ }
394
+ },
395
+
396
+ // func stringVal(value string) ref
397
+ "syscall/js.stringVal": (sp) => {
398
+ sp >>>= 0;
399
+ storeValue(sp + 24, loadString(sp + 8));
400
+ },
401
+
402
+ // func valueGet(v ref, p string) ref
403
+ "syscall/js.valueGet": (sp) => {
404
+ sp >>>= 0;
405
+ const result = Reflect.get(loadValue(sp + 8), loadString(sp + 16));
406
+ sp = this._inst.exports.getsp() >>> 0; // see comment above
407
+ storeValue(sp + 32, result);
408
+ },
409
+
410
+ // func valueSet(v ref, p string, x ref)
411
+ "syscall/js.valueSet": (sp) => {
412
+ sp >>>= 0;
413
+ Reflect.set(
414
+ loadValue(sp + 8),
415
+ loadString(sp + 16),
416
+ loadValue(sp + 32),
417
+ );
418
+ },
419
+
420
+ // func valueDelete(v ref, p string)
421
+ "syscall/js.valueDelete": (sp) => {
422
+ sp >>>= 0;
423
+ Reflect.deleteProperty(loadValue(sp + 8), loadString(sp + 16));
424
+ },
425
+
426
+ // func valueIndex(v ref, i int) ref
427
+ "syscall/js.valueIndex": (sp) => {
428
+ sp >>>= 0;
429
+ storeValue(
430
+ sp + 24,
431
+ Reflect.get(loadValue(sp + 8), getInt64(sp + 16)),
432
+ );
433
+ },
434
+
435
+ // valueSetIndex(v ref, i int, x ref)
436
+ "syscall/js.valueSetIndex": (sp) => {
437
+ sp >>>= 0;
438
+ Reflect.set(
439
+ loadValue(sp + 8),
440
+ getInt64(sp + 16),
441
+ loadValue(sp + 24),
442
+ );
443
+ },
444
+
445
+ // func valueCall(v ref, m string, args []ref) (ref, bool)
446
+ "syscall/js.valueCall": (sp) => {
447
+ sp >>>= 0;
448
+ try {
449
+ const v = loadValue(sp + 8);
450
+ const m = Reflect.get(v, loadString(sp + 16));
451
+ const args = loadSliceOfValues(sp + 32);
452
+ const result = Reflect.apply(m, v, args);
453
+ sp = this._inst.exports.getsp() >>> 0; // see comment above
454
+ storeValue(sp + 56, result);
455
+ this.mem.setUint8(sp + 64, 1);
456
+ } catch (err) {
457
+ sp = this._inst.exports.getsp() >>> 0; // see comment above
458
+ storeValue(sp + 56, err);
459
+ this.mem.setUint8(sp + 64, 0);
460
+ }
461
+ },
462
+
463
+ // func valueInvoke(v ref, args []ref) (ref, bool)
464
+ "syscall/js.valueInvoke": (sp) => {
465
+ sp >>>= 0;
466
+ try {
467
+ const v = loadValue(sp + 8);
468
+ const args = loadSliceOfValues(sp + 16);
469
+ const result = Reflect.apply(v, undefined, args);
470
+ sp = this._inst.exports.getsp() >>> 0; // see comment above
471
+ storeValue(sp + 40, result);
472
+ this.mem.setUint8(sp + 48, 1);
473
+ } catch (err) {
474
+ sp = this._inst.exports.getsp() >>> 0; // see comment above
475
+ storeValue(sp + 40, err);
476
+ this.mem.setUint8(sp + 48, 0);
477
+ }
478
+ },
479
+
480
+ // func valueNew(v ref, args []ref) (ref, bool)
481
+ "syscall/js.valueNew": (sp) => {
482
+ sp >>>= 0;
483
+ try {
484
+ const v = loadValue(sp + 8);
485
+ const args = loadSliceOfValues(sp + 16);
486
+ const result = Reflect.construct(v, args);
487
+ sp = this._inst.exports.getsp() >>> 0; // see comment above
488
+ storeValue(sp + 40, result);
489
+ this.mem.setUint8(sp + 48, 1);
490
+ } catch (err) {
491
+ sp = this._inst.exports.getsp() >>> 0; // see comment above
492
+ storeValue(sp + 40, err);
493
+ this.mem.setUint8(sp + 48, 0);
494
+ }
495
+ },
496
+
497
+ // func valueLength(v ref) int
498
+ "syscall/js.valueLength": (sp) => {
499
+ sp >>>= 0;
500
+ setInt64(sp + 16, parseInt(loadValue(sp + 8).length));
501
+ },
502
+
503
+ // valuePrepareString(v ref) (ref, int)
504
+ "syscall/js.valuePrepareString": (sp) => {
505
+ sp >>>= 0;
506
+ const str = encoder.encode(String(loadValue(sp + 8)));
507
+ storeValue(sp + 16, str);
508
+ setInt64(sp + 24, str.length);
509
+ },
510
+
511
+ // valueLoadString(v ref, b []byte)
512
+ "syscall/js.valueLoadString": (sp) => {
513
+ sp >>>= 0;
514
+ const str = loadValue(sp + 8);
515
+ loadSlice(sp + 16).set(str);
516
+ },
517
+
518
+ // func valueInstanceOf(v ref, t ref) bool
519
+ "syscall/js.valueInstanceOf": (sp) => {
520
+ sp >>>= 0;
521
+ this.mem.setUint8(
522
+ sp + 24,
523
+ loadValue(sp + 8) instanceof loadValue(sp + 16) ? 1 : 0,
524
+ );
525
+ },
526
+
527
+ // func copyBytesToGo(dst []byte, src ref) (int, bool)
528
+ "syscall/js.copyBytesToGo": (sp) => {
529
+ sp >>>= 0;
530
+ const dst = loadSlice(sp + 8);
531
+ const src = loadValue(sp + 32);
532
+ if (
533
+ !(src instanceof Uint8Array || src instanceof Uint8ClampedArray)
534
+ ) {
535
+ this.mem.setUint8(sp + 48, 0);
536
+ return;
537
+ }
538
+ const toCopy = src.subarray(0, dst.length);
539
+ dst.set(toCopy);
540
+ setInt64(sp + 40, toCopy.length);
541
+ this.mem.setUint8(sp + 48, 1);
542
+ },
543
+
544
+ // func copyBytesToJS(dst ref, src []byte) (int, bool)
545
+ "syscall/js.copyBytesToJS": (sp) => {
546
+ sp >>>= 0;
547
+ const dst = loadValue(sp + 8);
548
+ const src = loadSlice(sp + 16);
549
+ if (
550
+ !(dst instanceof Uint8Array || dst instanceof Uint8ClampedArray)
551
+ ) {
552
+ this.mem.setUint8(sp + 48, 0);
553
+ return;
554
+ }
555
+ const toCopy = src.subarray(0, dst.length);
556
+ dst.set(toCopy);
557
+ setInt64(sp + 40, toCopy.length);
558
+ this.mem.setUint8(sp + 48, 1);
559
+ },
560
+
561
+ debug: (value) => {
562
+ console.log(value);
563
+ },
564
+ },
565
+ };
566
+ }
567
+
568
+ async run(instance) {
569
+ if (!(instance instanceof WebAssembly.Instance)) {
570
+ throw new Error("Go.run: WebAssembly.Instance expected");
571
+ }
572
+ this._inst = instance;
573
+ this.mem = new DataView(this._inst.exports.mem.buffer);
574
+ this._values = [
575
+ // JS values that Go currently has references to, indexed by reference id
576
+ NaN,
577
+ 0,
578
+ null,
579
+ true,
580
+ false,
581
+ globalThis,
582
+ this,
583
+ ];
584
+ this._goRefCounts = new Array(this._values.length).fill(Infinity); // number of references that Go has to a JS value, indexed by reference id
585
+ this._ids = new Map([
586
+ // mapping from JS values to reference ids
587
+ [0, 1],
588
+ [null, 2],
589
+ [true, 3],
590
+ [false, 4],
591
+ [globalThis, 5],
592
+ [this, 6],
593
+ ]);
594
+ this._idPool = []; // unused ids that have been garbage collected
595
+ this.exited = false; // whether the Go program has exited
596
+
597
+ // Pass command line arguments and environment variables to WebAssembly by writing them to the linear memory.
598
+ let offset = 4096;
599
+
600
+ const strPtr = (str) => {
601
+ const ptr = offset;
602
+ const bytes = encoder.encode(str + "\0");
603
+ new Uint8Array(this.mem.buffer, offset, bytes.length).set(bytes);
604
+ offset += bytes.length;
605
+ if (offset % 8 !== 0) {
606
+ offset += 8 - (offset % 8);
607
+ }
608
+ return ptr;
609
+ };
610
+
611
+ const argc = this.argv.length;
612
+
613
+ const argvPtrs = [];
614
+ this.argv.forEach((arg) => {
615
+ argvPtrs.push(strPtr(arg));
616
+ });
617
+ argvPtrs.push(0);
618
+
619
+ const keys = Object.keys(this.env).sort();
620
+ keys.forEach((key) => {
621
+ argvPtrs.push(strPtr(`${key}=${this.env[key]}`));
622
+ });
623
+ argvPtrs.push(0);
624
+
625
+ const argv = offset;
626
+ argvPtrs.forEach((ptr) => {
627
+ this.mem.setUint32(offset, ptr, true);
628
+ this.mem.setUint32(offset + 4, 0, true);
629
+ offset += 8;
630
+ });
631
+
632
+ // The linker guarantees global data starts from at least wasmMinDataAddr.
633
+ // Keep in sync with cmd/link/internal/ld/data.go:wasmMinDataAddr.
634
+ const wasmMinDataAddr = 4096 + 8192;
635
+ if (offset >= wasmMinDataAddr) {
636
+ throw new Error(
637
+ "total length of command line and environment variables exceeds limit",
638
+ );
639
+ }
640
+
641
+ this._inst.exports.run(argc, argv);
642
+ if (this.exited) {
643
+ this._resolveExitPromise();
644
+ }
645
+ await this._exitPromise;
646
+ }
647
+
648
+ _resume() {
649
+ if (this.exited) {
650
+ throw new Error("Go program has already exited");
651
+ }
652
+ this._inst.exports.resume();
653
+ if (this.exited) {
654
+ this._resolveExitPromise();
655
+ }
656
+ }
657
+
658
+ _makeFuncWrapper(id) {
659
+ const go = this;
660
+ return function () {
661
+ const event = { id: id, this: this, args: arguments };
662
+ go._pendingEvent = event;
663
+ go._resume();
664
+ return event.result;
665
+ };
666
+ }
667
+ };
668
+ })();
package/dist/index.d.ts CHANGED
@@ -5,4 +5,5 @@ export * from "./ai-sdk-provider";
5
5
  export * from "./config";
6
6
  export { SecureClient } from "./secure-client";
7
7
  export { UnverifiedClient } from "./unverified-client";
8
+ export { fetchRouter } from "./router";
8
9
  export { type Uploadable, toFile, APIPromise, PagePromise, OpenAIError, APIError, APIConnectionError, APIConnectionTimeoutError, APIUserAbortError, NotFoundError, ConflictError, RateLimitError, BadRequestError, AuthenticationError, InternalServerError, PermissionDeniedError, UnprocessableEntityError, } from "openai";
package/dist/index.js CHANGED
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.UnprocessableEntityError = exports.PermissionDeniedError = exports.InternalServerError = exports.AuthenticationError = exports.BadRequestError = exports.RateLimitError = exports.ConflictError = exports.NotFoundError = exports.APIUserAbortError = exports.APIConnectionTimeoutError = exports.APIConnectionError = exports.APIError = exports.OpenAIError = exports.PagePromise = exports.APIPromise = exports.toFile = exports.UnverifiedClient = exports.SecureClient = exports.default = exports.TinfoilAI = void 0;
17
+ exports.UnprocessableEntityError = exports.PermissionDeniedError = exports.InternalServerError = exports.AuthenticationError = exports.BadRequestError = exports.RateLimitError = exports.ConflictError = exports.NotFoundError = exports.APIUserAbortError = exports.APIConnectionTimeoutError = exports.APIConnectionError = exports.APIError = exports.OpenAIError = exports.PagePromise = exports.APIPromise = exports.toFile = exports.fetchRouter = exports.UnverifiedClient = exports.SecureClient = exports.default = exports.TinfoilAI = void 0;
18
18
  // Re-export the TinfoilAI class
19
19
  var tinfoilai_1 = require("./tinfoilai");
20
20
  Object.defineProperty(exports, "TinfoilAI", { enumerable: true, get: function () { return tinfoilai_1.TinfoilAI; } });
@@ -28,6 +28,8 @@ var secure_client_1 = require("./secure-client");
28
28
  Object.defineProperty(exports, "SecureClient", { enumerable: true, get: function () { return secure_client_1.SecureClient; } });
29
29
  var unverified_client_1 = require("./unverified-client");
30
30
  Object.defineProperty(exports, "UnverifiedClient", { enumerable: true, get: function () { return unverified_client_1.UnverifiedClient; } });
31
+ var router_1 = require("./router");
32
+ Object.defineProperty(exports, "fetchRouter", { enumerable: true, get: function () { return router_1.fetchRouter; } });
31
33
  // Re-export OpenAI utility types and classes that users might need
32
34
  // Using public exports from the main OpenAI package instead of deep imports
33
35
  var openai_1 = require("openai");
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Router utilities for fetching available Tinfoil routers
3
+ */
4
+ /**
5
+ * Fetches the list of available routers from the ATC API
6
+ * and returns a randomly selected address.
7
+ *
8
+ * @returns Promise<string> A randomly selected router address
9
+ * @throws Error if no routers are found or if the request fails
10
+ */
11
+ export declare function fetchRouter(): Promise<string>;