tinfoil 0.1.2 → 0.2.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.
- package/LICENSE +661 -21
- package/README.md +52 -32
- package/dist/client.d.ts +90 -23
- package/dist/client.js +180 -336
- package/dist/index.d.ts +1 -4
- package/dist/index.js +18 -5
- package/dist/secure-client.d.ts +40 -0
- package/dist/secure-client.js +156 -0
- package/package.json +44 -46
- package/dist/browser.d.ts +0 -3
- package/dist/browser.d.ts.map +0 -1
- package/dist/browser.js +0 -47
- package/dist/browser.js.map +0 -7
- package/dist/client.d.ts.map +0 -1
- package/dist/client.js.map +0 -1
- package/dist/config.d.ts +0 -4
- package/dist/config.d.ts.map +0 -1
- package/dist/config.js +0 -110
- package/dist/config.js.map +0 -1
- package/dist/debugLogger.d.ts +0 -12
- package/dist/debugLogger.d.ts.map +0 -1
- package/dist/debugLogger.js +0 -34
- package/dist/debugLogger.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/script.d.ts +0 -7
- package/dist/script.d.ts.map +0 -1
- package/dist/script.js +0 -20
- package/dist/script.js.map +0 -1
- package/dist/types.d.ts +0 -49
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -2
- package/dist/types.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,57 +1,77 @@
|
|
|
1
|
-
# Tinfoil
|
|
1
|
+
# Tinfoil Node Client
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://github.com/tinfoilsh/tinfoil-node/actions)
|
|
4
|
+
[](https://npmjs.org/package/tinfoil)
|
|
4
5
|
|
|
5
|
-
|
|
6
|
+
A Node.js wrapper around the OpenAI client that verifies enclave attestation and certificate fingerprints when using Tinfoil inference.
|
|
6
7
|
|
|
7
|
-
|
|
8
|
+
## Installation
|
|
8
9
|
|
|
9
|
-
```
|
|
10
|
-
|
|
10
|
+
```bash
|
|
11
|
+
npm install tinfoil
|
|
11
12
|
```
|
|
12
13
|
|
|
13
|
-
|
|
14
|
+
## Quick Start
|
|
15
|
+
|
|
16
|
+
```typescript
|
|
17
|
+
import { TinfoilAI } from 'tinfoil';
|
|
18
|
+
|
|
19
|
+
const client = new TinfoilAI({
|
|
20
|
+
enclave: 'models.default.tinfoil.sh', // or use TINFOIL_ENCLAVE env var
|
|
21
|
+
repo: 'tinfoilsh/default-models-nitro', // or use TINFOIL_REPO env var
|
|
22
|
+
apiKey: 'tinfoil' // or use OPENAI_API_KEY env var
|
|
23
|
+
});
|
|
14
24
|
|
|
15
|
-
|
|
16
|
-
|
|
25
|
+
// Uses identical method calls as the OpenAI client
|
|
26
|
+
const completion = await client.chat.completions.create({
|
|
27
|
+
messages: [{ role: 'user', content: 'Hello!' }],
|
|
28
|
+
model: 'llama3.2:1b'
|
|
29
|
+
});
|
|
17
30
|
```
|
|
18
31
|
|
|
19
|
-
##
|
|
32
|
+
## Running the Chat Example
|
|
20
33
|
|
|
21
|
-
To run the
|
|
34
|
+
To run the streaming chat example:
|
|
35
|
+
|
|
36
|
+
1. Clone the repository
|
|
37
|
+
|
|
38
|
+
2. Install dependencies:
|
|
22
39
|
|
|
23
40
|
```bash
|
|
24
|
-
# Install dependencies
|
|
25
41
|
npm install
|
|
42
|
+
```
|
|
26
43
|
|
|
27
|
-
|
|
28
|
-
|
|
44
|
+
3. Optionally create a `.env` file with your configuration:
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
TINFOIL_ENCLAVE=models.default.tinfoil.sh
|
|
48
|
+
TINFOIL_REPO=tinfoilsh/default-models-nitro
|
|
49
|
+
OPENAI_API_KEY=your_api_key
|
|
50
|
+
```
|
|
29
51
|
|
|
30
|
-
|
|
31
|
-
npm run test
|
|
52
|
+
4. Run the example:
|
|
32
53
|
|
|
33
|
-
|
|
34
|
-
|
|
54
|
+
```bash
|
|
55
|
+
npx ts-node examples/chat/main.ts
|
|
35
56
|
```
|
|
36
57
|
|
|
37
|
-
|
|
58
|
+
The example demonstrates streaming chat completions with the Tinfoil API wrapper.
|
|
38
59
|
|
|
39
|
-
|
|
60
|
+
## Runtime Support
|
|
40
61
|
|
|
41
|
-
|
|
42
|
-
"version": "0.0.XX"
|
|
43
|
-
```
|
|
62
|
+
Supports Node.js 18+, Deno, Bun, Cloudflare Workers, and more. Browser usage is disabled by default for security. See [OpenAI Node.js client](https://github.com/openai/openai-node) for complete runtime compatibility.
|
|
44
63
|
|
|
45
|
-
|
|
64
|
+
## API Documentation
|
|
46
65
|
|
|
47
|
-
|
|
48
|
-
npm run build
|
|
49
|
-
```
|
|
66
|
+
This library is a drop-in replacement for the official OpenAI Node.js client that can be used with Tinfoil. All methods and types are identical. See the [OpenAI client](https://github.com/openai/openai-node) for complete API usage and documentation.
|
|
50
67
|
|
|
51
|
-
3. Publish the package:
|
|
52
68
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
69
|
+
## Reporting Vulnerabilities
|
|
70
|
+
|
|
71
|
+
Please report security vulnerabilities by either:
|
|
72
|
+
|
|
73
|
+
- Emailing [security@tinfoil.sh](mailto:security@tinfoil.sh)
|
|
74
|
+
|
|
75
|
+
- Opening an issue on GitHub on this repository
|
|
56
76
|
|
|
57
|
-
|
|
77
|
+
We aim to respond to security reports within 24 hours and will keep you updated on our progress.
|
package/dist/client.d.ts
CHANGED
|
@@ -1,24 +1,91 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
private
|
|
15
|
-
|
|
16
|
-
private
|
|
17
|
-
private
|
|
18
|
-
private
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
1
|
+
import OpenAI from 'openai';
|
|
2
|
+
import type { Chat, Files, FineTuning, Images, Audio, Embeddings, Models, Moderations, Beta } from 'openai/resources';
|
|
3
|
+
/**
|
|
4
|
+
* TinfoilAI is a wrapper around the OpenAI API client that adds additional
|
|
5
|
+
* security measures through enclave verification and certificate fingerprint validation.
|
|
6
|
+
*
|
|
7
|
+
* It provides:
|
|
8
|
+
* - Automatic verification of Tinfoil secure enclaves
|
|
9
|
+
* - Certificate fingerprint validation for each request
|
|
10
|
+
* - Type-safe access to OpenAI's chat completion APIs
|
|
11
|
+
*/
|
|
12
|
+
export declare class TinfoilAI {
|
|
13
|
+
private client?;
|
|
14
|
+
private enclave;
|
|
15
|
+
private repo;
|
|
16
|
+
private groundTruth?;
|
|
17
|
+
private clientPromise;
|
|
18
|
+
private readyPromise?;
|
|
19
|
+
/**
|
|
20
|
+
* Creates a new TinfoilAI instance using environment variables.
|
|
21
|
+
* @param options - Optional OpenAI client configuration options
|
|
22
|
+
* @throws Error if TINFOIL_ENCLAVE or TINFOIL_REPO environment variables are not set
|
|
23
|
+
*/
|
|
24
|
+
constructor(options?: ConstructorParameters<typeof OpenAI>[0]);
|
|
25
|
+
/**
|
|
26
|
+
* Creates a new TinfoilAI instance with explicit enclave and repo values.
|
|
27
|
+
* @param enclave - The enclave URL/identifier
|
|
28
|
+
* @param repo - The repository identifier
|
|
29
|
+
* @param options - Optional OpenAI client configuration options
|
|
30
|
+
*/
|
|
31
|
+
constructor(enclave: string, repo: string, options?: ConstructorParameters<typeof OpenAI>[0]);
|
|
32
|
+
/**
|
|
33
|
+
* Ensures the client is ready to use.
|
|
34
|
+
* @returns Promise that resolves when the client is initialized
|
|
35
|
+
*/
|
|
36
|
+
ready(): Promise<void>;
|
|
37
|
+
private initClient;
|
|
38
|
+
private createOpenAIClient;
|
|
39
|
+
/**
|
|
40
|
+
* Helper method to ensure the OpenAI client is initialized before use.
|
|
41
|
+
* Automatically calls ready() if needed.
|
|
42
|
+
* @returns The initialized OpenAI client
|
|
43
|
+
* @private
|
|
44
|
+
*/
|
|
45
|
+
private ensureReady;
|
|
46
|
+
/**
|
|
47
|
+
* Access to OpenAI's chat completions API for creating chat conversations.
|
|
48
|
+
* Automatically initializes the client if needed.
|
|
49
|
+
*/
|
|
50
|
+
get chat(): Chat;
|
|
51
|
+
/**
|
|
52
|
+
* Access to OpenAI's files API for managing files used with the API.
|
|
53
|
+
* Automatically initializes the client if needed.
|
|
54
|
+
*/
|
|
55
|
+
get files(): Files;
|
|
56
|
+
/**
|
|
57
|
+
* Access to OpenAI's fine-tuning API for creating and managing fine-tuned models.
|
|
58
|
+
* Automatically initializes the client if needed.
|
|
59
|
+
*/
|
|
60
|
+
get fineTuning(): FineTuning;
|
|
61
|
+
/**
|
|
62
|
+
* Access to OpenAI's image generation and editing API.
|
|
63
|
+
* Automatically initializes the client if needed.
|
|
64
|
+
*/
|
|
65
|
+
get images(): Images;
|
|
66
|
+
/**
|
|
67
|
+
* Access to OpenAI's audio API for speech-to-text and text-to-speech.
|
|
68
|
+
* Automatically initializes the client if needed.
|
|
69
|
+
*/
|
|
70
|
+
get audio(): Audio;
|
|
71
|
+
/**
|
|
72
|
+
* Access to OpenAI's embeddings API for creating vector embeddings of text.
|
|
73
|
+
* Automatically initializes the client if needed.
|
|
74
|
+
*/
|
|
75
|
+
get embeddings(): Embeddings;
|
|
76
|
+
/**
|
|
77
|
+
* Access to OpenAI's models API for listing and managing available models.
|
|
78
|
+
* Automatically initializes the client if needed.
|
|
79
|
+
*/
|
|
80
|
+
get models(): Models;
|
|
81
|
+
/**
|
|
82
|
+
* Access to OpenAI's content moderation API.
|
|
83
|
+
* Automatically initializes the client if needed.
|
|
84
|
+
*/
|
|
85
|
+
get moderations(): Moderations;
|
|
86
|
+
/**
|
|
87
|
+
* Access to OpenAI's beta features.
|
|
88
|
+
* Automatically initializes the client if needed.
|
|
89
|
+
*/
|
|
90
|
+
get beta(): Beta;
|
|
23
91
|
}
|
|
24
|
-
//# sourceMappingURL=client.d.ts.map
|