tinfoil 0.8.5 → 0.8.7
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/ai-sdk-provider.js +1 -1
- package/dist/encrypted-body-fetch.js +27 -80
- package/dist/esm/ai-sdk-provider.js +1 -1
- package/dist/esm/encrypted-body-fetch.js +27 -80
- package/dist/esm/index.browser.d.ts +3 -3
- package/dist/esm/index.browser.js +3 -3
- package/dist/esm/index.d.ts +3 -3
- package/dist/esm/index.js +3 -3
- package/dist/esm/secure-client.js +2 -21
- package/dist/esm/secure-fetch.browser.d.ts +1 -0
- package/dist/esm/secure-fetch.browser.js +10 -0
- package/dist/esm/secure-fetch.d.ts +1 -0
- package/dist/esm/secure-fetch.js +22 -0
- package/dist/esm/{client.browser.js → tinfoilai.js} +10 -5
- package/dist/index.browser.d.ts +3 -3
- package/dist/index.browser.js +5 -5
- package/dist/index.d.ts +3 -3
- package/dist/index.js +7 -6
- package/dist/secure-client.js +2 -21
- package/dist/secure-fetch.browser.d.ts +1 -0
- package/dist/secure-fetch.browser.js +13 -0
- package/dist/secure-fetch.d.ts +1 -0
- package/dist/secure-fetch.js +25 -0
- package/dist/{client.browser.js → tinfoilai.js} +10 -5
- package/package.json +7 -3
- package/dist/client.d.ts +0 -123
- package/dist/client.js +0 -218
- package/dist/esm/client.d.ts +0 -123
- package/dist/esm/client.js +0 -211
- package/dist/esm/secure-client.browser.d.ts +0 -20
- package/dist/esm/secure-client.browser.js +0 -57
- package/dist/secure-client.browser.d.ts +0 -20
- package/dist/secure-client.browser.js +0 -61
- /package/dist/{client.browser.d.ts → esm/tinfoilai.d.ts} +0 -0
- /package/dist/{esm/client.browser.d.ts → tinfoilai.d.ts} +0 -0
package/dist/esm/client.js
DELETED
|
@@ -1,211 +0,0 @@
|
|
|
1
|
-
import OpenAI from "openai";
|
|
2
|
-
import { SecureClient } from "tinfoil/secure-client";
|
|
3
|
-
import { TINFOIL_CONFIG } from "./config";
|
|
4
|
-
import { isRealBrowser } from "./env";
|
|
5
|
-
/**
|
|
6
|
-
* Creates a proxy that allows property access and method calls on a Promise before it resolves.
|
|
7
|
-
* This enables a more ergonomic API where you can chain properties and methods without explicitly
|
|
8
|
-
* awaiting the promise first.
|
|
9
|
-
*
|
|
10
|
-
* @param promise - A Promise that will resolve to an object
|
|
11
|
-
* @returns A proxied version of the promised object that allows immediate property/method access
|
|
12
|
-
*
|
|
13
|
-
* @example
|
|
14
|
-
* // Instead of:
|
|
15
|
-
* const client = await getClient();
|
|
16
|
-
* const result = await client.someProperty.someMethod();
|
|
17
|
-
*
|
|
18
|
-
* // You can write:
|
|
19
|
-
* const client = createAsyncProxy(getClient());
|
|
20
|
-
* const result = await client.someProperty.someMethod();
|
|
21
|
-
*
|
|
22
|
-
* @template T - The type of object that the promise resolves to
|
|
23
|
-
*/
|
|
24
|
-
function createAsyncProxy(promise) {
|
|
25
|
-
return new Proxy({}, {
|
|
26
|
-
get(target, prop) {
|
|
27
|
-
return new Proxy(() => { }, {
|
|
28
|
-
get(_, nestedProp) {
|
|
29
|
-
return (...args) => promise.then((obj) => {
|
|
30
|
-
const value = obj[prop][nestedProp];
|
|
31
|
-
return typeof value === "function"
|
|
32
|
-
? value.apply(obj[prop], args)
|
|
33
|
-
: value;
|
|
34
|
-
});
|
|
35
|
-
},
|
|
36
|
-
apply(_, __, args) {
|
|
37
|
-
return promise.then((obj) => {
|
|
38
|
-
const value = obj[prop];
|
|
39
|
-
return typeof value === "function" ? value.apply(obj, args) : value;
|
|
40
|
-
});
|
|
41
|
-
},
|
|
42
|
-
});
|
|
43
|
-
},
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
export class TinfoilAI {
|
|
47
|
-
/**
|
|
48
|
-
* Creates a new TinfoilAI instance.
|
|
49
|
-
* @param options - Configuration options including apiKey and other OpenAI client options
|
|
50
|
-
*/
|
|
51
|
-
constructor(options = {}) {
|
|
52
|
-
// Set apiKey from options or environment variable
|
|
53
|
-
const openAIOptions = { ...options };
|
|
54
|
-
if (options.apiKey || process.env.TINFOIL_API_KEY) {
|
|
55
|
-
openAIOptions.apiKey = options.apiKey || process.env.TINFOIL_API_KEY;
|
|
56
|
-
}
|
|
57
|
-
// Store properties for compatibility
|
|
58
|
-
this.apiKey = openAIOptions.apiKey;
|
|
59
|
-
this.baseURL = options.baseURL || TINFOIL_CONFIG.INFERENCE_BASE_URL;
|
|
60
|
-
this.enclaveURL = options.enclaveURL || TINFOIL_CONFIG.ENCLAVE_URL;
|
|
61
|
-
this.configRepo = options.configRepo || TINFOIL_CONFIG.INFERENCE_PROXY_REPO;
|
|
62
|
-
this.secureClient = new SecureClient({
|
|
63
|
-
baseURL: this.baseURL,
|
|
64
|
-
enclaveURL: this.enclaveURL,
|
|
65
|
-
configRepo: this.configRepo,
|
|
66
|
-
});
|
|
67
|
-
this.clientPromise = this.initClient(openAIOptions);
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* Ensures the client is ready to use.
|
|
71
|
-
* @returns Promise that resolves when the client is initialized
|
|
72
|
-
*/
|
|
73
|
-
async ready() {
|
|
74
|
-
if (!this.readyPromise) {
|
|
75
|
-
this.readyPromise = (async () => {
|
|
76
|
-
this.client = await this.clientPromise;
|
|
77
|
-
})();
|
|
78
|
-
}
|
|
79
|
-
return this.readyPromise;
|
|
80
|
-
}
|
|
81
|
-
async initClient(options) {
|
|
82
|
-
return this.createOpenAIClient(options);
|
|
83
|
-
}
|
|
84
|
-
async createOpenAIClient(options = {}) {
|
|
85
|
-
await this.secureClient.ready();
|
|
86
|
-
this.verificationDocument = await this.secureClient.getVerificationDocument();
|
|
87
|
-
if (!this.verificationDocument) {
|
|
88
|
-
throw new Error("Verification document not available after successful verification");
|
|
89
|
-
}
|
|
90
|
-
const clientOptions = {
|
|
91
|
-
...options,
|
|
92
|
-
baseURL: this.baseURL,
|
|
93
|
-
fetch: this.secureClient.fetch,
|
|
94
|
-
};
|
|
95
|
-
// Enable dangerouslyAllowBrowser in Node.js with WASM (which makes OpenAI SDK think we're in a browser)
|
|
96
|
-
// OR if explicitly set by the user (for legitimate browser usage like playgrounds)
|
|
97
|
-
if (!isRealBrowser() || options.dangerouslyAllowBrowser === true) {
|
|
98
|
-
clientOptions.dangerouslyAllowBrowser = true;
|
|
99
|
-
}
|
|
100
|
-
return new OpenAI(clientOptions);
|
|
101
|
-
}
|
|
102
|
-
/**
|
|
103
|
-
* Helper method to ensure the OpenAI client is initialized before use.
|
|
104
|
-
* Automatically calls ready() if needed.
|
|
105
|
-
* @returns The initialized OpenAI client
|
|
106
|
-
* @private
|
|
107
|
-
*/
|
|
108
|
-
async ensureReady() {
|
|
109
|
-
await this.ready();
|
|
110
|
-
// We can safely assert this now because ready() must have completed
|
|
111
|
-
return this.client;
|
|
112
|
-
}
|
|
113
|
-
/**
|
|
114
|
-
* Returns the full verification document produced during client initialization.
|
|
115
|
-
*/
|
|
116
|
-
async getVerificationDocument() {
|
|
117
|
-
await this.ready();
|
|
118
|
-
if (!this.verificationDocument) {
|
|
119
|
-
throw new Error("Verification document unavailable: client not verified yet");
|
|
120
|
-
}
|
|
121
|
-
return this.verificationDocument;
|
|
122
|
-
}
|
|
123
|
-
/**
|
|
124
|
-
* Access to OpenAI's chat completions API for creating chat conversations.
|
|
125
|
-
* Automatically initializes the client if needed.
|
|
126
|
-
*/
|
|
127
|
-
get chat() {
|
|
128
|
-
return createAsyncProxy(this.ensureReady().then((client) => client.chat));
|
|
129
|
-
}
|
|
130
|
-
/**
|
|
131
|
-
* Access to OpenAI's files API for managing files used with the API.
|
|
132
|
-
* Automatically initializes the client if needed.
|
|
133
|
-
*/
|
|
134
|
-
get files() {
|
|
135
|
-
return createAsyncProxy(this.ensureReady().then((client) => client.files));
|
|
136
|
-
}
|
|
137
|
-
/**
|
|
138
|
-
* Access to OpenAI's fine-tuning API for creating and managing fine-tuned models.
|
|
139
|
-
* Automatically initializes the client if needed.
|
|
140
|
-
*/
|
|
141
|
-
get fineTuning() {
|
|
142
|
-
return createAsyncProxy(this.ensureReady().then((client) => client.fineTuning));
|
|
143
|
-
}
|
|
144
|
-
/**
|
|
145
|
-
* Access to OpenAI's image generation and editing API.
|
|
146
|
-
* Automatically initializes the client if needed.
|
|
147
|
-
*/
|
|
148
|
-
get images() {
|
|
149
|
-
return createAsyncProxy(this.ensureReady().then((client) => client.images));
|
|
150
|
-
}
|
|
151
|
-
/**
|
|
152
|
-
* Access to OpenAI's audio API for speech-to-text and text-to-speech.
|
|
153
|
-
* Automatically initializes the client if needed.
|
|
154
|
-
*/
|
|
155
|
-
get audio() {
|
|
156
|
-
return createAsyncProxy(this.ensureReady().then((client) => client.audio));
|
|
157
|
-
}
|
|
158
|
-
/**
|
|
159
|
-
* Access to the Responses API, supporting response creation, streaming, and parsing.
|
|
160
|
-
* Automatically initializes the client if needed.
|
|
161
|
-
*/
|
|
162
|
-
get responses() {
|
|
163
|
-
return createAsyncProxy(this.ensureReady().then((client) => client.responses));
|
|
164
|
-
}
|
|
165
|
-
/**
|
|
166
|
-
* Access to OpenAI's embeddings API for creating vector embeddings of text.
|
|
167
|
-
* Automatically initializes the client if needed.
|
|
168
|
-
*/
|
|
169
|
-
get embeddings() {
|
|
170
|
-
return createAsyncProxy(this.ensureReady().then((client) => client.embeddings));
|
|
171
|
-
}
|
|
172
|
-
/**
|
|
173
|
-
* Access to OpenAI's models API for listing and managing available models.
|
|
174
|
-
* Automatically initializes the client if needed.
|
|
175
|
-
*/
|
|
176
|
-
get models() {
|
|
177
|
-
return createAsyncProxy(this.ensureReady().then((client) => client.models));
|
|
178
|
-
}
|
|
179
|
-
/**
|
|
180
|
-
* Access to OpenAI's content moderation API.
|
|
181
|
-
* Automatically initializes the client if needed.
|
|
182
|
-
*/
|
|
183
|
-
get moderations() {
|
|
184
|
-
return createAsyncProxy(this.ensureReady().then((client) => client.moderations));
|
|
185
|
-
}
|
|
186
|
-
/**
|
|
187
|
-
* Access to OpenAI's beta features.
|
|
188
|
-
* Automatically initializes the client if needed.
|
|
189
|
-
*/
|
|
190
|
-
get beta() {
|
|
191
|
-
return createAsyncProxy(this.ensureReady().then((client) => client.beta));
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
// Namespace declaration merge to add OpenAI types to TinfoilAI
|
|
195
|
-
(function (TinfoilAI) {
|
|
196
|
-
// Re-export all OpenAI namespace types
|
|
197
|
-
TinfoilAI.Chat = OpenAI.Chat;
|
|
198
|
-
TinfoilAI.Audio = OpenAI.Audio;
|
|
199
|
-
TinfoilAI.Beta = OpenAI.Beta;
|
|
200
|
-
TinfoilAI.Batches = OpenAI.Batches;
|
|
201
|
-
TinfoilAI.Completions = OpenAI.Completions;
|
|
202
|
-
TinfoilAI.Embeddings = OpenAI.Embeddings;
|
|
203
|
-
TinfoilAI.Files = OpenAI.Files;
|
|
204
|
-
TinfoilAI.FineTuning = OpenAI.FineTuning;
|
|
205
|
-
TinfoilAI.Images = OpenAI.Images;
|
|
206
|
-
TinfoilAI.Models = OpenAI.Models;
|
|
207
|
-
TinfoilAI.Moderations = OpenAI.Moderations;
|
|
208
|
-
TinfoilAI.Responses = OpenAI.Responses;
|
|
209
|
-
TinfoilAI.Uploads = OpenAI.Uploads;
|
|
210
|
-
TinfoilAI.VectorStores = OpenAI.VectorStores;
|
|
211
|
-
})(TinfoilAI || (TinfoilAI = {}));
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import type { VerificationDocument } from "./verifier";
|
|
2
|
-
interface SecureClientOptions {
|
|
3
|
-
baseURL?: string;
|
|
4
|
-
enclaveURL?: string;
|
|
5
|
-
configRepo?: string;
|
|
6
|
-
}
|
|
7
|
-
export declare class SecureClient {
|
|
8
|
-
private initPromise;
|
|
9
|
-
private verificationDocument;
|
|
10
|
-
private _fetch;
|
|
11
|
-
private readonly baseURL?;
|
|
12
|
-
private readonly enclaveURL?;
|
|
13
|
-
private readonly configRepo?;
|
|
14
|
-
constructor(options?: SecureClientOptions);
|
|
15
|
-
ready(): Promise<void>;
|
|
16
|
-
private initSecureClient;
|
|
17
|
-
getVerificationDocument(): Promise<VerificationDocument>;
|
|
18
|
-
get fetch(): typeof fetch;
|
|
19
|
-
}
|
|
20
|
-
export {};
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { Verifier } from "./verifier";
|
|
2
|
-
import { TINFOIL_CONFIG } from "./config";
|
|
3
|
-
import { createEncryptedBodyFetch } from "./encrypted-body-fetch";
|
|
4
|
-
import { isRealBrowser } from "./env";
|
|
5
|
-
export class SecureClient {
|
|
6
|
-
constructor(options = {}) {
|
|
7
|
-
this.initPromise = null;
|
|
8
|
-
this.verificationDocument = null;
|
|
9
|
-
this._fetch = null;
|
|
10
|
-
this.baseURL = options.baseURL || TINFOIL_CONFIG.INFERENCE_BASE_URL;
|
|
11
|
-
this.enclaveURL = options.enclaveURL || TINFOIL_CONFIG.ENCLAVE_URL;
|
|
12
|
-
this.configRepo = options.configRepo || TINFOIL_CONFIG.INFERENCE_PROXY_REPO;
|
|
13
|
-
}
|
|
14
|
-
async ready() {
|
|
15
|
-
if (!this.initPromise) {
|
|
16
|
-
this.initPromise = this.initSecureClient();
|
|
17
|
-
}
|
|
18
|
-
return this.initPromise;
|
|
19
|
-
}
|
|
20
|
-
async initSecureClient() {
|
|
21
|
-
const verifier = new Verifier({
|
|
22
|
-
serverURL: this.enclaveURL,
|
|
23
|
-
configRepo: this.configRepo,
|
|
24
|
-
});
|
|
25
|
-
await verifier.verify();
|
|
26
|
-
const doc = verifier.getVerificationDocument();
|
|
27
|
-
if (!doc) {
|
|
28
|
-
throw new Error("Verification document not available after successful verification");
|
|
29
|
-
}
|
|
30
|
-
this.verificationDocument = doc;
|
|
31
|
-
const hpkePublicKey = this.verificationDocument.enclaveMeasurement.hpkePublicKey;
|
|
32
|
-
if (!hpkePublicKey) {
|
|
33
|
-
if (isRealBrowser()) {
|
|
34
|
-
throw new Error("HPKE public key not available and TLS-only verification is not supported in browsers. " +
|
|
35
|
-
"Only HPKE-enabled enclaves can be used in browser environments.");
|
|
36
|
-
}
|
|
37
|
-
throw new Error("HPKE public key is required in browser environments");
|
|
38
|
-
}
|
|
39
|
-
this._fetch = createEncryptedBodyFetch(this.baseURL, hpkePublicKey, this.enclaveURL);
|
|
40
|
-
}
|
|
41
|
-
async getVerificationDocument() {
|
|
42
|
-
if (!this.initPromise) {
|
|
43
|
-
await this.ready();
|
|
44
|
-
}
|
|
45
|
-
await this.initPromise;
|
|
46
|
-
if (!this.verificationDocument) {
|
|
47
|
-
throw new Error("Verification document unavailable: client not verified yet");
|
|
48
|
-
}
|
|
49
|
-
return this.verificationDocument;
|
|
50
|
-
}
|
|
51
|
-
get fetch() {
|
|
52
|
-
return async (input, init) => {
|
|
53
|
-
await this.ready();
|
|
54
|
-
return this._fetch(input, init);
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import type { VerificationDocument } from "./verifier";
|
|
2
|
-
interface SecureClientOptions {
|
|
3
|
-
baseURL?: string;
|
|
4
|
-
enclaveURL?: string;
|
|
5
|
-
configRepo?: string;
|
|
6
|
-
}
|
|
7
|
-
export declare class SecureClient {
|
|
8
|
-
private initPromise;
|
|
9
|
-
private verificationDocument;
|
|
10
|
-
private _fetch;
|
|
11
|
-
private readonly baseURL?;
|
|
12
|
-
private readonly enclaveURL?;
|
|
13
|
-
private readonly configRepo?;
|
|
14
|
-
constructor(options?: SecureClientOptions);
|
|
15
|
-
ready(): Promise<void>;
|
|
16
|
-
private initSecureClient;
|
|
17
|
-
getVerificationDocument(): Promise<VerificationDocument>;
|
|
18
|
-
get fetch(): typeof fetch;
|
|
19
|
-
}
|
|
20
|
-
export {};
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SecureClient = void 0;
|
|
4
|
-
const verifier_1 = require("./verifier");
|
|
5
|
-
const config_1 = require("./config");
|
|
6
|
-
const encrypted_body_fetch_1 = require("./encrypted-body-fetch");
|
|
7
|
-
const env_1 = require("./env");
|
|
8
|
-
class SecureClient {
|
|
9
|
-
constructor(options = {}) {
|
|
10
|
-
this.initPromise = null;
|
|
11
|
-
this.verificationDocument = null;
|
|
12
|
-
this._fetch = null;
|
|
13
|
-
this.baseURL = options.baseURL || config_1.TINFOIL_CONFIG.INFERENCE_BASE_URL;
|
|
14
|
-
this.enclaveURL = options.enclaveURL || config_1.TINFOIL_CONFIG.ENCLAVE_URL;
|
|
15
|
-
this.configRepo = options.configRepo || config_1.TINFOIL_CONFIG.INFERENCE_PROXY_REPO;
|
|
16
|
-
}
|
|
17
|
-
async ready() {
|
|
18
|
-
if (!this.initPromise) {
|
|
19
|
-
this.initPromise = this.initSecureClient();
|
|
20
|
-
}
|
|
21
|
-
return this.initPromise;
|
|
22
|
-
}
|
|
23
|
-
async initSecureClient() {
|
|
24
|
-
const verifier = new verifier_1.Verifier({
|
|
25
|
-
serverURL: this.enclaveURL,
|
|
26
|
-
configRepo: this.configRepo,
|
|
27
|
-
});
|
|
28
|
-
await verifier.verify();
|
|
29
|
-
const doc = verifier.getVerificationDocument();
|
|
30
|
-
if (!doc) {
|
|
31
|
-
throw new Error("Verification document not available after successful verification");
|
|
32
|
-
}
|
|
33
|
-
this.verificationDocument = doc;
|
|
34
|
-
const hpkePublicKey = this.verificationDocument.enclaveMeasurement.hpkePublicKey;
|
|
35
|
-
if (!hpkePublicKey) {
|
|
36
|
-
if ((0, env_1.isRealBrowser)()) {
|
|
37
|
-
throw new Error("HPKE public key not available and TLS-only verification is not supported in browsers. " +
|
|
38
|
-
"Only HPKE-enabled enclaves can be used in browser environments.");
|
|
39
|
-
}
|
|
40
|
-
throw new Error("HPKE public key is required in browser environments");
|
|
41
|
-
}
|
|
42
|
-
this._fetch = (0, encrypted_body_fetch_1.createEncryptedBodyFetch)(this.baseURL, hpkePublicKey, this.enclaveURL);
|
|
43
|
-
}
|
|
44
|
-
async getVerificationDocument() {
|
|
45
|
-
if (!this.initPromise) {
|
|
46
|
-
await this.ready();
|
|
47
|
-
}
|
|
48
|
-
await this.initPromise;
|
|
49
|
-
if (!this.verificationDocument) {
|
|
50
|
-
throw new Error("Verification document unavailable: client not verified yet");
|
|
51
|
-
}
|
|
52
|
-
return this.verificationDocument;
|
|
53
|
-
}
|
|
54
|
-
get fetch() {
|
|
55
|
-
return async (input, init) => {
|
|
56
|
-
await this.ready();
|
|
57
|
-
return this._fetch(input, init);
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
exports.SecureClient = SecureClient;
|
|
File without changes
|
|
File without changes
|