tinfoil 0.5.0 → 0.6.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.
package/dist/client.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import OpenAI from 'openai';
1
2
  import type { Chat, Files, FineTuning, Images, Audio, Embeddings, Models, Moderations, Beta } from 'openai/resources';
2
3
  /**
3
4
  * TinfoilAI is a wrapper around the OpenAI API client that adds additional
@@ -17,6 +18,8 @@ export declare class TinfoilAI {
17
18
  private groundTruth?;
18
19
  private clientPromise;
19
20
  private readyPromise?;
21
+ apiKey?: string;
22
+ baseURL?: string;
20
23
  /**
21
24
  * Creates a new TinfoilAI instance.
22
25
  * @param options - Configuration options including apiKey and other OpenAI client options
@@ -82,4 +85,19 @@ export declare class TinfoilAI {
82
85
  */
83
86
  get beta(): Beta;
84
87
  }
88
+ export declare namespace TinfoilAI {
89
+ export import Chat = OpenAI.Chat;
90
+ export import Audio = OpenAI.Audio;
91
+ export import Beta = OpenAI.Beta;
92
+ export import Batches = OpenAI.Batches;
93
+ export import Completions = OpenAI.Completions;
94
+ export import Embeddings = OpenAI.Embeddings;
95
+ export import Files = OpenAI.Files;
96
+ export import FineTuning = OpenAI.FineTuning;
97
+ export import Images = OpenAI.Images;
98
+ export import Models = OpenAI.Models;
99
+ export import Moderations = OpenAI.Moderations;
100
+ export import Uploads = OpenAI.Uploads;
101
+ export import VectorStores = OpenAI.VectorStores;
102
+ }
85
103
  export {};
package/dist/client.js CHANGED
@@ -9,6 +9,25 @@ const crypto_1 = require("crypto");
9
9
  const secure_client_1 = require("./secure-client");
10
10
  const https_1 = __importDefault(require("https"));
11
11
  const config_1 = require("./config");
12
+ /**
13
+ * Detects if the code is running in a real browser environment.
14
+ * Returns false for Node.js environments, even with WASM loaded.
15
+ */
16
+ function isRealBrowser() {
17
+ // Check for Node.js-specific globals that wouldn't exist in a real browser
18
+ if (typeof process !== 'undefined' && process.versions && process.versions.node) {
19
+ return false; // Definitely Node.js
20
+ }
21
+ // Check for browser-specific window object AND ensure it's not a Node.js global mock
22
+ if (typeof window !== 'undefined' && typeof window.document !== 'undefined') {
23
+ // Additional check: real browsers have navigator.userAgent
24
+ if (typeof navigator !== 'undefined' && navigator.userAgent) {
25
+ return true; // Likely a real browser
26
+ }
27
+ }
28
+ // Default to safe: assume it's not a browser (Node.js with WASM)
29
+ return false;
30
+ }
12
31
  /**
13
32
  * Creates a proxy that allows property access and method calls on a Promise before it resolves.
14
33
  * This enables a more ergonomic API where you can chain properties and methods without explicitly
@@ -59,6 +78,9 @@ class TinfoilAI {
59
78
  if (options.apiKey || process.env.TINFOIL_API_KEY) {
60
79
  openAIOptions.apiKey = options.apiKey || process.env.TINFOIL_API_KEY;
61
80
  }
81
+ // Store properties for compatibility
82
+ this.apiKey = openAIOptions.apiKey;
83
+ this.baseURL = config_1.TINFOIL_CONFIG.INFERENCE_BASE_URL;
62
84
  this.clientPromise = this.initClient(openAIOptions);
63
85
  }
64
86
  /**
@@ -108,10 +130,17 @@ class TinfoilAI {
108
130
  });
109
131
  // Create the OpenAI client with our custom configuration
110
132
  // Note: baseURL will need to be determined by the verification process
111
- return new openai_1.default({
133
+ const clientOptions = {
112
134
  ...options,
113
135
  baseURL: config_1.TINFOIL_CONFIG.INFERENCE_BASE_URL,
114
- });
136
+ };
137
+ // Only enable dangerouslyAllowBrowser when we're NOT in a real browser
138
+ // This prevents API key exposure if code is ever bundled for browser use
139
+ if (!isRealBrowser()) {
140
+ // We're in Node.js with WASM, which makes OpenAI SDK think we're in a browser
141
+ clientOptions.dangerouslyAllowBrowser = true;
142
+ }
143
+ return new openai_1.default(clientOptions);
115
144
  }
116
145
  /**
117
146
  * Helper method to ensure the OpenAI client is initialized before use.
@@ -189,3 +218,20 @@ class TinfoilAI {
189
218
  }
190
219
  }
191
220
  exports.TinfoilAI = TinfoilAI;
221
+ // Namespace declaration merge to add OpenAI types to TinfoilAI
222
+ (function (TinfoilAI) {
223
+ // Re-export all OpenAI namespace types
224
+ TinfoilAI.Chat = openai_1.default.Chat;
225
+ TinfoilAI.Audio = openai_1.default.Audio;
226
+ TinfoilAI.Beta = openai_1.default.Beta;
227
+ TinfoilAI.Batches = openai_1.default.Batches;
228
+ TinfoilAI.Completions = openai_1.default.Completions;
229
+ TinfoilAI.Embeddings = openai_1.default.Embeddings;
230
+ TinfoilAI.Files = openai_1.default.Files;
231
+ TinfoilAI.FineTuning = openai_1.default.FineTuning;
232
+ TinfoilAI.Images = openai_1.default.Images;
233
+ TinfoilAI.Models = openai_1.default.Models;
234
+ TinfoilAI.Moderations = openai_1.default.Moderations;
235
+ TinfoilAI.Uploads = openai_1.default.Uploads;
236
+ TinfoilAI.VectorStores = openai_1.default.VectorStores;
237
+ })(TinfoilAI || (exports.TinfoilAI = TinfoilAI = {}));
package/dist/index.d.ts CHANGED
@@ -1,4 +1,6 @@
1
- export * from './client';
1
+ export { TinfoilAI } from './client';
2
+ export { TinfoilAI as default } from './client';
2
3
  export * from './secure-client';
3
4
  export * from './ai-sdk-provider';
4
5
  export * from './config';
6
+ 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,32 @@ 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
- __exportStar(require("./client"), exports);
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.default = exports.TinfoilAI = void 0;
18
+ // Re-export the TinfoilAI class
19
+ var client_1 = require("./client");
20
+ Object.defineProperty(exports, "TinfoilAI", { enumerable: true, get: function () { return client_1.TinfoilAI; } });
21
+ var client_2 = require("./client");
22
+ Object.defineProperty(exports, "default", { enumerable: true, get: function () { return client_2.TinfoilAI; } });
23
+ // Export secure client and config
18
24
  __exportStar(require("./secure-client"), exports);
19
25
  __exportStar(require("./ai-sdk-provider"), exports);
20
26
  __exportStar(require("./config"), exports);
27
+ // Re-export OpenAI utility types and classes that users might need
28
+ // Using public exports from the main OpenAI package instead of deep imports
29
+ var openai_1 = require("openai");
30
+ Object.defineProperty(exports, "toFile", { enumerable: true, get: function () { return openai_1.toFile; } });
31
+ Object.defineProperty(exports, "APIPromise", { enumerable: true, get: function () { return openai_1.APIPromise; } });
32
+ Object.defineProperty(exports, "PagePromise", { enumerable: true, get: function () { return openai_1.PagePromise; } });
33
+ Object.defineProperty(exports, "OpenAIError", { enumerable: true, get: function () { return openai_1.OpenAIError; } });
34
+ Object.defineProperty(exports, "APIError", { enumerable: true, get: function () { return openai_1.APIError; } });
35
+ Object.defineProperty(exports, "APIConnectionError", { enumerable: true, get: function () { return openai_1.APIConnectionError; } });
36
+ Object.defineProperty(exports, "APIConnectionTimeoutError", { enumerable: true, get: function () { return openai_1.APIConnectionTimeoutError; } });
37
+ Object.defineProperty(exports, "APIUserAbortError", { enumerable: true, get: function () { return openai_1.APIUserAbortError; } });
38
+ Object.defineProperty(exports, "NotFoundError", { enumerable: true, get: function () { return openai_1.NotFoundError; } });
39
+ Object.defineProperty(exports, "ConflictError", { enumerable: true, get: function () { return openai_1.ConflictError; } });
40
+ Object.defineProperty(exports, "RateLimitError", { enumerable: true, get: function () { return openai_1.RateLimitError; } });
41
+ Object.defineProperty(exports, "BadRequestError", { enumerable: true, get: function () { return openai_1.BadRequestError; } });
42
+ Object.defineProperty(exports, "AuthenticationError", { enumerable: true, get: function () { return openai_1.AuthenticationError; } });
43
+ Object.defineProperty(exports, "InternalServerError", { enumerable: true, get: function () { return openai_1.InternalServerError; } });
44
+ Object.defineProperty(exports, "PermissionDeniedError", { enumerable: true, get: function () { return openai_1.PermissionDeniedError; } });
45
+ Object.defineProperty(exports, "UnprocessableEntityError", { enumerable: true, get: function () { return openai_1.UnprocessableEntityError; } });
@@ -1,10 +1,7 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.SecureClient = void 0;
7
- const node_fetch_1 = __importDefault(require("node-fetch"));
4
+ const undici_1 = require("undici");
8
5
  const util_1 = require("util");
9
6
  const config_1 = require("./config");
10
7
  // Set up browser-like globals that the Go WASM runtime expects
@@ -79,7 +76,7 @@ class SecureClient {
79
76
  SecureClient.initializationPromise = (async () => {
80
77
  try {
81
78
  SecureClient.goInstance = new globalThis.Go();
82
- const wasmResponse = await (0, node_fetch_1.default)('https://tinfoilsh.github.io/verifier-js/tinfoil-verifier.wasm');
79
+ const wasmResponse = await (0, undici_1.fetch)('https://tinfoilsh.github.io/verifier-js/tinfoil-verifier.wasm');
83
80
  const wasmBuffer = await wasmResponse.arrayBuffer();
84
81
  const result = await WebAssembly.instantiate(wasmBuffer, SecureClient.goInstance.importObject);
85
82
  const runPromise = SecureClient.goInstance.run(result.instance);
@@ -119,7 +116,7 @@ class SecureClient {
119
116
  if (typeof globalThis.verifyCode !== 'function' || typeof globalThis.verifyEnclave !== 'function') {
120
117
  throw new Error('WASM functions not available');
121
118
  }
122
- const releaseResponse = await (0, node_fetch_1.default)(`https://api.github.com/repos/${this.repo}/releases/latest`, {
119
+ const releaseResponse = await (0, undici_1.fetch)(`https://api.github.com/repos/${this.repo}/releases/latest`, {
123
120
  headers: {
124
121
  'Accept': 'application/vnd.github.v3+json',
125
122
  'User-Agent': 'tinfoil-node-client'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tinfoil",
3
- "version": "0.5.0",
3
+ "version": "0.6.1",
4
4
  "description": "Tinfoil secure OpenAI client wrapper",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -28,22 +28,21 @@
28
28
  "author": "Tinfoil",
29
29
  "license": "AGPL-3.0-or-later",
30
30
  "dependencies": {
31
- "@ai-sdk/openai-compatible": "^0.2.14",
32
- "ai": "^4.3.15",
33
- "dotenv": "^16.4.7",
34
- "node-fetch": "^2.7.0",
35
- "openai": "^4.87.3",
31
+ "@ai-sdk/openai-compatible": "^1.0.10",
32
+ "ai": "^5.0.19",
33
+ "dotenv": "^17.2.1",
34
+ "openai": "^5.13.1",
36
35
  "ts-node": "^10.9.2",
37
- "undici": "^7.9.0"
36
+ "undici": "^7.14.0"
38
37
  },
39
38
  "devDependencies": {
40
39
  "@types/jest": "^29.5.12",
41
- "@types/node": "^20.11.24",
42
- "@typescript-eslint/eslint-plugin": "^8.26.1",
43
- "@typescript-eslint/parser": "^8.26.1",
40
+ "@types/node": "^24.3.0",
41
+ "@typescript-eslint/eslint-plugin": "^8.40.0",
42
+ "@typescript-eslint/parser": "^8.40.0",
44
43
  "eslint": "^8.57.0",
45
44
  "jest": "^29.7.0",
46
- "ts-jest": "^29.1.2",
47
- "typescript": "~5.5.0"
45
+ "ts-jest": "^29.4.1",
46
+ "typescript": "^5.9.2"
48
47
  }
49
48
  }