tinfoil 0.8.4 → 0.8.6

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 (39) hide show
  1. package/dist/ai-sdk-provider.d.ts +1 -1
  2. package/dist/ai-sdk-provider.js +3 -3
  3. package/dist/config.d.ts +4 -3
  4. package/dist/config.js +4 -3
  5. package/dist/encrypted-body-fetch.d.ts +2 -2
  6. package/dist/encrypted-body-fetch.js +4 -4
  7. package/dist/esm/ai-sdk-provider.d.ts +1 -1
  8. package/dist/esm/ai-sdk-provider.js +3 -3
  9. package/dist/esm/config.d.ts +4 -3
  10. package/dist/esm/config.js +4 -3
  11. package/dist/esm/encrypted-body-fetch.d.ts +2 -2
  12. package/dist/esm/encrypted-body-fetch.js +4 -4
  13. package/dist/esm/index.browser.d.ts +3 -3
  14. package/dist/esm/index.browser.js +3 -3
  15. package/dist/esm/index.d.ts +3 -3
  16. package/dist/esm/index.js +3 -3
  17. package/dist/esm/secure-client.browser.d.ts +2 -2
  18. package/dist/esm/secure-client.browser.js +3 -3
  19. package/dist/esm/secure-client.d.ts +2 -2
  20. package/dist/esm/secure-client.js +5 -4
  21. package/dist/{client.browser.d.ts → esm/tinfoilai.d.ts} +2 -2
  22. package/dist/esm/{client.browser.js → tinfoilai.js} +12 -7
  23. package/dist/esm/verifier.js +2 -2
  24. package/dist/index.browser.d.ts +3 -3
  25. package/dist/index.browser.js +7 -6
  26. package/dist/index.d.ts +3 -3
  27. package/dist/index.js +5 -5
  28. package/dist/secure-client.browser.d.ts +2 -2
  29. package/dist/secure-client.browser.js +3 -3
  30. package/dist/secure-client.d.ts +2 -2
  31. package/dist/secure-client.js +5 -4
  32. package/dist/{esm/client.browser.d.ts → tinfoilai.d.ts} +2 -2
  33. package/dist/{client.browser.js → tinfoilai.js} +13 -8
  34. package/dist/verifier.js +2 -2
  35. package/package.json +2 -3
  36. package/dist/client.d.ts +0 -123
  37. package/dist/client.js +0 -218
  38. package/dist/esm/client.d.ts +0 -123
  39. package/dist/esm/client.js +0 -211
@@ -2,9 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SecureClient = void 0;
4
4
  const verifier_1 = require("./verifier");
5
- const config_1 = require("./config");
6
5
  const encrypted_body_fetch_1 = require("./encrypted-body-fetch");
7
6
  const pinned_tls_fetch_1 = require("./pinned-tls-fetch");
7
+ const config_1 = require("./config");
8
8
  const env_1 = require("./env");
9
9
  class SecureClient {
10
10
  constructor(options = {}) {
@@ -12,7 +12,7 @@ class SecureClient {
12
12
  this.verificationDocument = null;
13
13
  this._fetch = null;
14
14
  this.baseURL = options.baseURL || config_1.TINFOIL_CONFIG.INFERENCE_BASE_URL;
15
- this.hpkeKeyURL = options.hpkeKeyURL || config_1.TINFOIL_CONFIG.HPKE_KEY_URL;
15
+ this.enclaveURL = options.enclaveURL || config_1.TINFOIL_CONFIG.ENCLAVE_URL;
16
16
  this.configRepo = options.configRepo || config_1.TINFOIL_CONFIG.INFERENCE_PROXY_REPO;
17
17
  }
18
18
  async ready() {
@@ -23,7 +23,7 @@ class SecureClient {
23
23
  }
24
24
  async initSecureClient() {
25
25
  const verifier = new verifier_1.Verifier({
26
- serverURL: this.baseURL,
26
+ serverURL: this.enclaveURL,
27
27
  configRepo: this.configRepo,
28
28
  });
29
29
  await verifier.verify();
@@ -32,11 +32,12 @@ class SecureClient {
32
32
  throw new Error("Verification document not available after successful verification");
33
33
  }
34
34
  this.verificationDocument = doc;
35
+ // Extract keys from the verification document
35
36
  const { hpkePublicKey, tlsPublicKeyFingerprint } = this.verificationDocument.enclaveMeasurement;
36
37
  let fetchFunction;
37
38
  if (hpkePublicKey) {
38
39
  // HPKE available: use encrypted body fetch
39
- fetchFunction = (0, encrypted_body_fetch_1.createEncryptedBodyFetch)(this.baseURL, hpkePublicKey, this.hpkeKeyURL);
40
+ fetchFunction = (0, encrypted_body_fetch_1.createEncryptedBodyFetch)(this.baseURL, hpkePublicKey, this.enclaveURL);
40
41
  }
41
42
  else {
42
43
  // HPKE not available: check if we're in a browser
@@ -4,7 +4,7 @@ import type { VerificationDocument } from "./verifier";
4
4
  interface TinfoilAIOptions {
5
5
  apiKey?: string;
6
6
  baseURL?: string;
7
- hpkeKeyURL?: string;
7
+ enclaveURL?: string;
8
8
  configRepo?: string;
9
9
  [key: string]: any;
10
10
  }
@@ -17,7 +17,7 @@ export declare class TinfoilAI {
17
17
  private verificationDocument?;
18
18
  apiKey?: string;
19
19
  baseURL?: string;
20
- hpkeKeyURL?: string;
20
+ enclaveURL?: string;
21
21
  constructor(options?: TinfoilAIOptions);
22
22
  ready(): Promise<void>;
23
23
  private initClient;
@@ -5,8 +5,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.TinfoilAI = void 0;
7
7
  const openai_1 = __importDefault(require("openai"));
8
- const secure_client_browser_1 = require("./secure-client.browser");
8
+ const secure_client_1 = require("tinfoil/secure-client");
9
9
  const config_1 = require("./config");
10
+ const env_1 = require("./env");
10
11
  function createAsyncProxy(promise) {
11
12
  return new Proxy({}, {
12
13
  get(target, prop) {
@@ -34,17 +35,19 @@ class TinfoilAI {
34
35
  const openAIOptions = { ...options };
35
36
  // In browser builds, never read secrets from process.env to avoid
36
37
  // leaking credentials into client bundles. Require explicit apiKey.
37
- if (typeof options.apiKey === "string") {
38
+ if (options.apiKey) {
38
39
  openAIOptions.apiKey = options.apiKey;
39
40
  }
41
+ else if (!(0, env_1.isRealBrowser)() && process.env.TINFOIL_API_KEY) {
42
+ openAIOptions.apiKey = process.env.TINFOIL_API_KEY;
43
+ }
40
44
  this.apiKey = openAIOptions.apiKey;
41
45
  this.baseURL = options.baseURL || config_1.TINFOIL_CONFIG.INFERENCE_BASE_URL;
42
- this.hpkeKeyURL = options.hpkeKeyURL || config_1.TINFOIL_CONFIG.HPKE_KEY_URL;
46
+ this.enclaveURL = options.enclaveURL || config_1.TINFOIL_CONFIG.ENCLAVE_URL;
43
47
  this.configRepo = options.configRepo || config_1.TINFOIL_CONFIG.INFERENCE_PROXY_REPO;
44
- // Create the secure client for handling transport security
45
- this.secureClient = new secure_client_browser_1.SecureClient({
48
+ this.secureClient = new secure_client_1.SecureClient({
46
49
  baseURL: this.baseURL,
47
- hpkeKeyURL: this.hpkeKeyURL,
50
+ enclaveURL: this.enclaveURL,
48
51
  configRepo: this.configRepo,
49
52
  });
50
53
  this.clientPromise = this.initClient(openAIOptions);
@@ -71,8 +74,9 @@ class TinfoilAI {
71
74
  baseURL: this.baseURL,
72
75
  fetch: this.secureClient.fetch,
73
76
  };
74
- // In browser usage, OpenAI SDK typically needs dangerouslyAllowBrowser
75
- clientOptions.dangerouslyAllowBrowser = true;
77
+ if ((0, env_1.isRealBrowser)() || options.dangerouslyAllowBrowser === true) {
78
+ clientOptions.dangerouslyAllowBrowser = true;
79
+ }
76
80
  return new openai_1.default(clientOptions);
77
81
  }
78
82
  async ensureReady() {
@@ -118,6 +122,7 @@ class TinfoilAI {
118
122
  }
119
123
  }
120
124
  exports.TinfoilAI = TinfoilAI;
125
+ // Namespace declaration merge to add OpenAI types to TinfoilAI
121
126
  (function (TinfoilAI) {
122
127
  TinfoilAI.Chat = openai_1.default.Chat;
123
128
  TinfoilAI.Audio = openai_1.default.Audio;
package/dist/verifier.js CHANGED
@@ -456,8 +456,8 @@ class Verifier {
456
456
  // Compare measurements using platform-specific logic
457
457
  const measurementsMatchError = compareMeasurementsError(codeMeasurement, attestation.measurement);
458
458
  if (measurementsMatchError) {
459
- throw new Error(`Measurement verification failed: Code measurement (${codeMeasurement.type}) ` +
460
- `does not match runtime measurement (${attestation.measurement.type}): ${measurementsMatchError.message}`);
459
+ throw new Error(`Verification failed: measurements did not match.\nCode measurement (${codeMeasurement.type}: ${codeMeasurement.registers})\n` +
460
+ `Runtime measurement (${attestation.measurement.type}: ${attestation.measurement.registers}:)\n ${measurementsMatchError.message}`);
461
461
  }
462
462
  // Persist a full verification document for later retrieval by clients
463
463
  this.lastVerificationDocument = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tinfoil",
3
- "version": "0.8.4",
3
+ "version": "0.8.6",
4
4
  "description": "Tinfoil secure OpenAI client wrapper",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -19,7 +19,6 @@
19
19
  },
20
20
  "./client": {
21
21
  "types": "./dist/client.d.ts",
22
- "browser": "./dist/esm/client.browser.js",
23
22
  "import": "./dist/esm/client.js",
24
23
  "require": "./dist/client.js"
25
24
  },
@@ -54,7 +53,7 @@
54
53
  "build": "npm run build:cjs && npm run build:esm",
55
54
  "build:cjs": "tsc && cp src/wasm-exec.js dist/",
56
55
  "build:esm": "tsc -p tsconfig.esm.json && cp src/wasm-exec.js dist/esm/",
57
- "test": "bash -lc 'rm -rf .node-tests && tsc -p tsconfig.node-test.json && cp src/wasm-exec.js .node-tests/ && node --test $(find .node-tests -name \"*.test.js\" -print)'",
56
+ "test": "bash -lc 'rm -rf dist .node-tests && npm run build:cjs && tsc -p tsconfig.node-test.json && cp src/wasm-exec.js .node-tests/ && node --test $(find .node-tests -name \"*.test.js\" -print)'",
58
57
  "lint": "eslint src/**/*.ts",
59
58
  "prepublishOnly": "npm run build"
60
59
  },
package/dist/client.d.ts DELETED
@@ -1,123 +0,0 @@
1
- import OpenAI from "openai";
2
- import type { Audio, Beta, Chat, Embeddings, Files, FineTuning, Images, Models, Moderations, Responses } from "openai/resources";
3
- import type { VerificationDocument } from "./verifier";
4
- /**
5
- * TinfoilAI is a wrapper around the OpenAI API client that adds additional
6
- * security measures through enclave verification and an EHBP-secured transport.
7
- *
8
- * It provides:
9
- * - Automatic verification of Tinfoil secure enclaves
10
- * - EHBP-enforced transport security for each request
11
- * - Type-safe access to OpenAI's chat completion APIs
12
- */
13
- interface TinfoilAIOptions {
14
- apiKey?: string;
15
- /** Override the inference API base URL */
16
- baseURL?: string;
17
- /** Override the URL used to fetch the HPKE key (defaults to baseURL) */
18
- hpkeKeyURL?: string;
19
- /** Override the config GitHub repository */
20
- configRepo?: string;
21
- [key: string]: any;
22
- }
23
- export declare class TinfoilAI {
24
- private client?;
25
- private clientPromise;
26
- private readyPromise?;
27
- private configRepo?;
28
- private secureClient;
29
- private verificationDocument?;
30
- apiKey?: string;
31
- baseURL?: string;
32
- hpkeKeyURL?: string;
33
- /**
34
- * Creates a new TinfoilAI instance.
35
- * @param options - Configuration options including apiKey and other OpenAI client options
36
- */
37
- constructor(options?: TinfoilAIOptions);
38
- /**
39
- * Ensures the client is ready to use.
40
- * @returns Promise that resolves when the client is initialized
41
- */
42
- ready(): Promise<void>;
43
- private initClient;
44
- private createOpenAIClient;
45
- /**
46
- * Helper method to ensure the OpenAI client is initialized before use.
47
- * Automatically calls ready() if needed.
48
- * @returns The initialized OpenAI client
49
- * @private
50
- */
51
- private ensureReady;
52
- /**
53
- * Returns the full verification document produced during client initialization.
54
- */
55
- getVerificationDocument(): Promise<VerificationDocument>;
56
- /**
57
- * Access to OpenAI's chat completions API for creating chat conversations.
58
- * Automatically initializes the client if needed.
59
- */
60
- get chat(): Chat;
61
- /**
62
- * Access to OpenAI's files API for managing files used with the API.
63
- * Automatically initializes the client if needed.
64
- */
65
- get files(): Files;
66
- /**
67
- * Access to OpenAI's fine-tuning API for creating and managing fine-tuned models.
68
- * Automatically initializes the client if needed.
69
- */
70
- get fineTuning(): FineTuning;
71
- /**
72
- * Access to OpenAI's image generation and editing API.
73
- * Automatically initializes the client if needed.
74
- */
75
- get images(): Images;
76
- /**
77
- * Access to OpenAI's audio API for speech-to-text and text-to-speech.
78
- * Automatically initializes the client if needed.
79
- */
80
- get audio(): Audio;
81
- /**
82
- * Access to the Responses API, supporting response creation, streaming, and parsing.
83
- * Automatically initializes the client if needed.
84
- */
85
- get responses(): Responses;
86
- /**
87
- * Access to OpenAI's embeddings API for creating vector embeddings of text.
88
- * Automatically initializes the client if needed.
89
- */
90
- get embeddings(): Embeddings;
91
- /**
92
- * Access to OpenAI's models API for listing and managing available models.
93
- * Automatically initializes the client if needed.
94
- */
95
- get models(): Models;
96
- /**
97
- * Access to OpenAI's content moderation API.
98
- * Automatically initializes the client if needed.
99
- */
100
- get moderations(): Moderations;
101
- /**
102
- * Access to OpenAI's beta features.
103
- * Automatically initializes the client if needed.
104
- */
105
- get beta(): Beta;
106
- }
107
- export declare namespace TinfoilAI {
108
- export import Chat = OpenAI.Chat;
109
- export import Audio = OpenAI.Audio;
110
- export import Beta = OpenAI.Beta;
111
- export import Batches = OpenAI.Batches;
112
- export import Completions = OpenAI.Completions;
113
- export import Embeddings = OpenAI.Embeddings;
114
- export import Files = OpenAI.Files;
115
- export import FineTuning = OpenAI.FineTuning;
116
- export import Images = OpenAI.Images;
117
- export import Models = OpenAI.Models;
118
- export import Moderations = OpenAI.Moderations;
119
- export import Responses = OpenAI.Responses;
120
- export import Uploads = OpenAI.Uploads;
121
- export import VectorStores = OpenAI.VectorStores;
122
- }
123
- export {};
package/dist/client.js DELETED
@@ -1,218 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.TinfoilAI = void 0;
7
- const openai_1 = __importDefault(require("openai"));
8
- const secure_client_1 = require("./secure-client");
9
- const config_1 = require("./config");
10
- const env_1 = require("./env");
11
- /**
12
- * Creates a proxy that allows property access and method calls on a Promise before it resolves.
13
- * This enables a more ergonomic API where you can chain properties and methods without explicitly
14
- * awaiting the promise first.
15
- *
16
- * @param promise - A Promise that will resolve to an object
17
- * @returns A proxied version of the promised object that allows immediate property/method access
18
- *
19
- * @example
20
- * // Instead of:
21
- * const client = await getClient();
22
- * const result = await client.someProperty.someMethod();
23
- *
24
- * // You can write:
25
- * const client = createAsyncProxy(getClient());
26
- * const result = await client.someProperty.someMethod();
27
- *
28
- * @template T - The type of object that the promise resolves to
29
- */
30
- function createAsyncProxy(promise) {
31
- return new Proxy({}, {
32
- get(target, prop) {
33
- return new Proxy(() => { }, {
34
- get(_, nestedProp) {
35
- return (...args) => promise.then((obj) => {
36
- const value = obj[prop][nestedProp];
37
- return typeof value === "function"
38
- ? value.apply(obj[prop], args)
39
- : value;
40
- });
41
- },
42
- apply(_, __, args) {
43
- return promise.then((obj) => {
44
- const value = obj[prop];
45
- return typeof value === "function" ? value.apply(obj, args) : value;
46
- });
47
- },
48
- });
49
- },
50
- });
51
- }
52
- class TinfoilAI {
53
- /**
54
- * Creates a new TinfoilAI instance.
55
- * @param options - Configuration options including apiKey and other OpenAI client options
56
- */
57
- constructor(options = {}) {
58
- // Set apiKey from options or environment variable
59
- const openAIOptions = { ...options };
60
- if (options.apiKey || process.env.TINFOIL_API_KEY) {
61
- openAIOptions.apiKey = options.apiKey || process.env.TINFOIL_API_KEY;
62
- }
63
- // Store properties for compatibility
64
- this.apiKey = openAIOptions.apiKey;
65
- this.baseURL = options.baseURL || config_1.TINFOIL_CONFIG.INFERENCE_BASE_URL;
66
- this.hpkeKeyURL = options.hpkeKeyURL || config_1.TINFOIL_CONFIG.HPKE_KEY_URL;
67
- this.configRepo = options.configRepo || config_1.TINFOIL_CONFIG.INFERENCE_PROXY_REPO;
68
- this.secureClient = new secure_client_1.SecureClient({
69
- baseURL: this.baseURL,
70
- hpkeKeyURL: this.hpkeKeyURL,
71
- configRepo: this.configRepo,
72
- });
73
- this.clientPromise = this.initClient(openAIOptions);
74
- }
75
- /**
76
- * Ensures the client is ready to use.
77
- * @returns Promise that resolves when the client is initialized
78
- */
79
- async ready() {
80
- if (!this.readyPromise) {
81
- this.readyPromise = (async () => {
82
- this.client = await this.clientPromise;
83
- })();
84
- }
85
- return this.readyPromise;
86
- }
87
- async initClient(options) {
88
- return this.createOpenAIClient(options);
89
- }
90
- async createOpenAIClient(options = {}) {
91
- await this.secureClient.ready();
92
- this.verificationDocument = await this.secureClient.getVerificationDocument();
93
- if (!this.verificationDocument) {
94
- throw new Error("Verification document not available after successful verification");
95
- }
96
- const clientOptions = {
97
- ...options,
98
- baseURL: this.baseURL,
99
- fetch: this.secureClient.fetch,
100
- };
101
- // Enable dangerouslyAllowBrowser in Node.js with WASM (which makes OpenAI SDK think we're in a browser)
102
- // OR if explicitly set by the user (for legitimate browser usage like playgrounds)
103
- if (!(0, env_1.isRealBrowser)() || options.dangerouslyAllowBrowser === true) {
104
- clientOptions.dangerouslyAllowBrowser = true;
105
- }
106
- return new openai_1.default(clientOptions);
107
- }
108
- /**
109
- * Helper method to ensure the OpenAI client is initialized before use.
110
- * Automatically calls ready() if needed.
111
- * @returns The initialized OpenAI client
112
- * @private
113
- */
114
- async ensureReady() {
115
- await this.ready();
116
- // We can safely assert this now because ready() must have completed
117
- return this.client;
118
- }
119
- /**
120
- * Returns the full verification document produced during client initialization.
121
- */
122
- async getVerificationDocument() {
123
- await this.ready();
124
- if (!this.verificationDocument) {
125
- throw new Error("Verification document unavailable: client not verified yet");
126
- }
127
- return this.verificationDocument;
128
- }
129
- /**
130
- * Access to OpenAI's chat completions API for creating chat conversations.
131
- * Automatically initializes the client if needed.
132
- */
133
- get chat() {
134
- return createAsyncProxy(this.ensureReady().then((client) => client.chat));
135
- }
136
- /**
137
- * Access to OpenAI's files API for managing files used with the API.
138
- * Automatically initializes the client if needed.
139
- */
140
- get files() {
141
- return createAsyncProxy(this.ensureReady().then((client) => client.files));
142
- }
143
- /**
144
- * Access to OpenAI's fine-tuning API for creating and managing fine-tuned models.
145
- * Automatically initializes the client if needed.
146
- */
147
- get fineTuning() {
148
- return createAsyncProxy(this.ensureReady().then((client) => client.fineTuning));
149
- }
150
- /**
151
- * Access to OpenAI's image generation and editing API.
152
- * Automatically initializes the client if needed.
153
- */
154
- get images() {
155
- return createAsyncProxy(this.ensureReady().then((client) => client.images));
156
- }
157
- /**
158
- * Access to OpenAI's audio API for speech-to-text and text-to-speech.
159
- * Automatically initializes the client if needed.
160
- */
161
- get audio() {
162
- return createAsyncProxy(this.ensureReady().then((client) => client.audio));
163
- }
164
- /**
165
- * Access to the Responses API, supporting response creation, streaming, and parsing.
166
- * Automatically initializes the client if needed.
167
- */
168
- get responses() {
169
- return createAsyncProxy(this.ensureReady().then((client) => client.responses));
170
- }
171
- /**
172
- * Access to OpenAI's embeddings API for creating vector embeddings of text.
173
- * Automatically initializes the client if needed.
174
- */
175
- get embeddings() {
176
- return createAsyncProxy(this.ensureReady().then((client) => client.embeddings));
177
- }
178
- /**
179
- * Access to OpenAI's models API for listing and managing available models.
180
- * Automatically initializes the client if needed.
181
- */
182
- get models() {
183
- return createAsyncProxy(this.ensureReady().then((client) => client.models));
184
- }
185
- /**
186
- * Access to OpenAI's content moderation API.
187
- * Automatically initializes the client if needed.
188
- */
189
- get moderations() {
190
- return createAsyncProxy(this.ensureReady().then((client) => client.moderations));
191
- }
192
- /**
193
- * Access to OpenAI's beta features.
194
- * Automatically initializes the client if needed.
195
- */
196
- get beta() {
197
- return createAsyncProxy(this.ensureReady().then((client) => client.beta));
198
- }
199
- }
200
- exports.TinfoilAI = TinfoilAI;
201
- // Namespace declaration merge to add OpenAI types to TinfoilAI
202
- (function (TinfoilAI) {
203
- // Re-export all OpenAI namespace types
204
- TinfoilAI.Chat = openai_1.default.Chat;
205
- TinfoilAI.Audio = openai_1.default.Audio;
206
- TinfoilAI.Beta = openai_1.default.Beta;
207
- TinfoilAI.Batches = openai_1.default.Batches;
208
- TinfoilAI.Completions = openai_1.default.Completions;
209
- TinfoilAI.Embeddings = openai_1.default.Embeddings;
210
- TinfoilAI.Files = openai_1.default.Files;
211
- TinfoilAI.FineTuning = openai_1.default.FineTuning;
212
- TinfoilAI.Images = openai_1.default.Images;
213
- TinfoilAI.Models = openai_1.default.Models;
214
- TinfoilAI.Moderations = openai_1.default.Moderations;
215
- TinfoilAI.Responses = openai_1.default.Responses;
216
- TinfoilAI.Uploads = openai_1.default.Uploads;
217
- TinfoilAI.VectorStores = openai_1.default.VectorStores;
218
- })(TinfoilAI || (exports.TinfoilAI = TinfoilAI = {}));
@@ -1,123 +0,0 @@
1
- import OpenAI from "openai";
2
- import type { Audio, Beta, Chat, Embeddings, Files, FineTuning, Images, Models, Moderations, Responses } from "openai/resources";
3
- import type { VerificationDocument } from "./verifier";
4
- /**
5
- * TinfoilAI is a wrapper around the OpenAI API client that adds additional
6
- * security measures through enclave verification and an EHBP-secured transport.
7
- *
8
- * It provides:
9
- * - Automatic verification of Tinfoil secure enclaves
10
- * - EHBP-enforced transport security for each request
11
- * - Type-safe access to OpenAI's chat completion APIs
12
- */
13
- interface TinfoilAIOptions {
14
- apiKey?: string;
15
- /** Override the inference API base URL */
16
- baseURL?: string;
17
- /** Override the URL used to fetch the HPKE key (defaults to baseURL) */
18
- hpkeKeyURL?: string;
19
- /** Override the config GitHub repository */
20
- configRepo?: string;
21
- [key: string]: any;
22
- }
23
- export declare class TinfoilAI {
24
- private client?;
25
- private clientPromise;
26
- private readyPromise?;
27
- private configRepo?;
28
- private secureClient;
29
- private verificationDocument?;
30
- apiKey?: string;
31
- baseURL?: string;
32
- hpkeKeyURL?: string;
33
- /**
34
- * Creates a new TinfoilAI instance.
35
- * @param options - Configuration options including apiKey and other OpenAI client options
36
- */
37
- constructor(options?: TinfoilAIOptions);
38
- /**
39
- * Ensures the client is ready to use.
40
- * @returns Promise that resolves when the client is initialized
41
- */
42
- ready(): Promise<void>;
43
- private initClient;
44
- private createOpenAIClient;
45
- /**
46
- * Helper method to ensure the OpenAI client is initialized before use.
47
- * Automatically calls ready() if needed.
48
- * @returns The initialized OpenAI client
49
- * @private
50
- */
51
- private ensureReady;
52
- /**
53
- * Returns the full verification document produced during client initialization.
54
- */
55
- getVerificationDocument(): Promise<VerificationDocument>;
56
- /**
57
- * Access to OpenAI's chat completions API for creating chat conversations.
58
- * Automatically initializes the client if needed.
59
- */
60
- get chat(): Chat;
61
- /**
62
- * Access to OpenAI's files API for managing files used with the API.
63
- * Automatically initializes the client if needed.
64
- */
65
- get files(): Files;
66
- /**
67
- * Access to OpenAI's fine-tuning API for creating and managing fine-tuned models.
68
- * Automatically initializes the client if needed.
69
- */
70
- get fineTuning(): FineTuning;
71
- /**
72
- * Access to OpenAI's image generation and editing API.
73
- * Automatically initializes the client if needed.
74
- */
75
- get images(): Images;
76
- /**
77
- * Access to OpenAI's audio API for speech-to-text and text-to-speech.
78
- * Automatically initializes the client if needed.
79
- */
80
- get audio(): Audio;
81
- /**
82
- * Access to the Responses API, supporting response creation, streaming, and parsing.
83
- * Automatically initializes the client if needed.
84
- */
85
- get responses(): Responses;
86
- /**
87
- * Access to OpenAI's embeddings API for creating vector embeddings of text.
88
- * Automatically initializes the client if needed.
89
- */
90
- get embeddings(): Embeddings;
91
- /**
92
- * Access to OpenAI's models API for listing and managing available models.
93
- * Automatically initializes the client if needed.
94
- */
95
- get models(): Models;
96
- /**
97
- * Access to OpenAI's content moderation API.
98
- * Automatically initializes the client if needed.
99
- */
100
- get moderations(): Moderations;
101
- /**
102
- * Access to OpenAI's beta features.
103
- * Automatically initializes the client if needed.
104
- */
105
- get beta(): Beta;
106
- }
107
- export declare namespace TinfoilAI {
108
- export import Chat = OpenAI.Chat;
109
- export import Audio = OpenAI.Audio;
110
- export import Beta = OpenAI.Beta;
111
- export import Batches = OpenAI.Batches;
112
- export import Completions = OpenAI.Completions;
113
- export import Embeddings = OpenAI.Embeddings;
114
- export import Files = OpenAI.Files;
115
- export import FineTuning = OpenAI.FineTuning;
116
- export import Images = OpenAI.Images;
117
- export import Models = OpenAI.Models;
118
- export import Moderations = OpenAI.Moderations;
119
- export import Responses = OpenAI.Responses;
120
- export import Uploads = OpenAI.Uploads;
121
- export import VectorStores = OpenAI.VectorStores;
122
- }
123
- export {};