tinfoil 0.4.3 → 0.4.4

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/README.md CHANGED
@@ -17,15 +17,15 @@ npm install tinfoil
17
17
  import { TinfoilAI } from 'tinfoil';
18
18
 
19
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
20
+ enclave: 'enclave.example.com', // or use TINFOIL_ENCLAVE env var
21
+ repo: 'org/model-repo', // or use TINFOIL_REPO env var
22
+ apiKey: 'your-api-key' // or use OPENAI_API_KEY env var
23
23
  });
24
24
 
25
25
  // Uses identical method calls as the OpenAI client
26
26
  const completion = await client.chat.completions.create({
27
27
  messages: [{ role: 'user', content: 'Hello!' }],
28
- model: 'llama3.2:1b'
28
+ model: 'llama3-3-70b'
29
29
  });
30
30
  ```
31
31
 
@@ -44,15 +44,16 @@ npm install
44
44
  3. Optionally create a `.env` file with your configuration:
45
45
 
46
46
  ```bash
47
- TINFOIL_ENCLAVE=models.default.tinfoil.sh
48
- TINFOIL_REPO=tinfoilsh/default-models-nitro
49
- OPENAI_API_KEY=your_api_key
47
+ TINFOIL_ENCLAVE=enclave.example.com
48
+ TINFOIL_REPO=org/model-repo
49
+ OPENAI_API_KEY=your-api-key
50
50
  ```
51
51
 
52
52
  4. Run the example:
53
53
 
54
54
  ```bash
55
- npx ts-node examples/chat/main.ts
55
+ cd examples/chat
56
+ npx ts-node main.ts
56
57
  ```
57
58
 
58
59
  The example demonstrates streaming chat completions with the Tinfoil API wrapper.
package/dist/client.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- import OpenAI from 'openai';
2
1
  import type { Chat, Files, FineTuning, Images, Audio, Embeddings, Models, Moderations, Beta } from 'openai/resources';
3
2
  /**
4
3
  * TinfoilAI is a wrapper around the OpenAI API client that adds additional
@@ -9,6 +8,12 @@ import type { Chat, Files, FineTuning, Images, Audio, Embeddings, Models, Modera
9
8
  * - Certificate fingerprint validation for each request
10
9
  * - Type-safe access to OpenAI's chat completion APIs
11
10
  */
11
+ interface TinfoilAIOptions {
12
+ enclave?: string;
13
+ repo?: string;
14
+ apiKey?: string;
15
+ [key: string]: any;
16
+ }
12
17
  export declare class TinfoilAI {
13
18
  private client?;
14
19
  private enclave;
@@ -17,18 +22,11 @@ export declare class TinfoilAI {
17
22
  private clientPromise;
18
23
  private readyPromise?;
19
24
  /**
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
25
+ * Creates a new TinfoilAI instance.
26
+ * @param options - Configuration options including enclave, repo, apiKey, and other OpenAI client options
27
+ * @throws Error if enclave or repo are not provided either in options or environment variables
30
28
  */
31
- constructor(enclave: string, repo: string, options?: ConstructorParameters<typeof OpenAI>[0]);
29
+ constructor(options?: TinfoilAIOptions);
32
30
  /**
33
31
  * Ensures the client is ready to use.
34
32
  * @returns Promise that resolves when the client is initialized
@@ -89,3 +87,4 @@ export declare class TinfoilAI {
89
87
  */
90
88
  get beta(): Beta;
91
89
  }
90
+ export {};
package/dist/client.js CHANGED
@@ -47,30 +47,26 @@ function createAsyncProxy(promise) {
47
47
  }
48
48
  });
49
49
  }
50
- /**
51
- * TinfoilAI is a wrapper around the OpenAI API client that adds additional
52
- * security measures through enclave verification and certificate fingerprint validation.
53
- *
54
- * It provides:
55
- * - Automatic verification of Tinfoil secure enclaves
56
- * - Certificate fingerprint validation for each request
57
- * - Type-safe access to OpenAI's chat completion APIs
58
- */
59
50
  class TinfoilAI {
60
- constructor(enclaveOrOptions, repoOrNothing, options) {
61
- if (typeof enclaveOrOptions === 'string' && typeof repoOrNothing === 'string') {
62
- this.enclave = enclaveOrOptions;
63
- this.repo = repoOrNothing;
64
- this.clientPromise = this.initClient(options);
51
+ /**
52
+ * Creates a new TinfoilAI instance.
53
+ * @param options - Configuration options including enclave, repo, apiKey, and other OpenAI client options
54
+ * @throws Error if enclave or repo are not provided either in options or environment variables
55
+ */
56
+ constructor(options = {}) {
57
+ // Extract TinfoilAI-specific options with environment variable fallbacks
58
+ this.enclave = options.enclave || process.env.TINFOIL_ENCLAVE || '';
59
+ this.repo = options.repo || process.env.TINFOIL_REPO || '';
60
+ if (!this.enclave || !this.repo) {
61
+ throw new Error('tinfoil: enclave and repo must be specified either in options or via TINFOIL_ENCLAVE and TINFOIL_REPO environment variables');
65
62
  }
66
- else {
67
- this.enclave = process.env.TINFOIL_ENCLAVE || '';
68
- this.repo = process.env.TINFOIL_REPO || '';
69
- if (!this.enclave || !this.repo) {
70
- throw new Error('tinfoil: TINFOIL_ENCLAVE and TINFOIL_REPO environment variables must be specified');
71
- }
72
- this.clientPromise = this.initClient(enclaveOrOptions);
63
+ // Prepare OpenAI client options
64
+ const { enclave: _, repo: __, ...openAIOptions } = options;
65
+ // Set apiKey from options or environment variable
66
+ if (options.apiKey || process.env.OPENAI_API_KEY) {
67
+ openAIOptions.apiKey = options.apiKey || process.env.OPENAI_API_KEY;
73
68
  }
69
+ this.clientPromise = this.initClient(openAIOptions);
74
70
  }
75
71
  /**
76
72
  * Ensures the client is ready to use.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "tinfoil",
3
- "version": "0.4.3",
4
- "description": "Official Tinfoil secure OpenAI client wrapper",
3
+ "version": "0.4.4",
4
+ "description": "Tinfoil secure OpenAI client wrapper",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "scripts": {