tinfoil 0.4.3 → 0.5.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/README.md CHANGED
@@ -17,15 +17,13 @@ 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
+ apiKey: '<YOUR_API_KEY>' // or use TINFOIL_API_KEY env var
23
21
  });
24
22
 
25
23
  // Uses identical method calls as the OpenAI client
26
24
  const completion = await client.chat.completions.create({
27
25
  messages: [{ role: 'user', content: 'Hello!' }],
28
- model: 'llama3.2:1b'
26
+ model: 'llama3-3-70b'
29
27
  });
30
28
  ```
31
29
 
@@ -44,15 +42,14 @@ npm install
44
42
  3. Optionally create a `.env` file with your configuration:
45
43
 
46
44
  ```bash
47
- TINFOIL_ENCLAVE=models.default.tinfoil.sh
48
- TINFOIL_REPO=tinfoilsh/default-models-nitro
49
- OPENAI_API_KEY=your_api_key
45
+ TINFOIL_API_KEY=<YOUR_API_KEY>
50
46
  ```
51
47
 
52
48
  4. Run the example:
53
49
 
54
50
  ```bash
55
- npx ts-node examples/chat/main.ts
51
+ cd examples/chat
52
+ npx ts-node main.ts
56
53
  ```
57
54
 
58
55
  The example demonstrates streaming chat completions with the Tinfoil API wrapper.
@@ -1,9 +1,7 @@
1
1
  /**
2
- * Creates an AI SDK provider with the specified repository and enclave.
2
+ * Creates an AI SDK provider with the specified API key.
3
3
  *
4
- * @param repo - The repository identifier
5
- * @param enclave - The enclave URL/identifier
6
4
  * @param apiKey - The API key for the Tinfoil API
7
5
  * @returns A TinfoilAI instance
8
6
  */
9
- export declare function createTinfoilAI(repo: string, enclave: string, apiKey: string): Promise<import("@ai-sdk/openai-compatible").OpenAICompatibleProvider<string, string, string, string>>;
7
+ export declare function createTinfoilAI(apiKey: string): Promise<import("@ai-sdk/openai-compatible").OpenAICompatibleProvider<string, string, string, string>>;
@@ -3,19 +3,18 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createTinfoilAI = createTinfoilAI;
4
4
  const openai_compatible_1 = require("@ai-sdk/openai-compatible");
5
5
  const secure_client_1 = require("./secure-client");
6
+ const config_1 = require("./config");
6
7
  const undici_1 = require("undici");
7
8
  const node_tls_1 = require("node:tls");
8
9
  const node_crypto_1 = require("node:crypto");
9
10
  /**
10
- * Creates an AI SDK provider with the specified repository and enclave.
11
+ * Creates an AI SDK provider with the specified API key.
11
12
  *
12
- * @param repo - The repository identifier
13
- * @param enclave - The enclave URL/identifier
14
13
  * @param apiKey - The API key for the Tinfoil API
15
14
  * @returns A TinfoilAI instance
16
15
  */
17
- async function createTinfoilAI(repo, enclave, apiKey) {
18
- const sc = new secure_client_1.SecureClient(enclave, repo);
16
+ async function createTinfoilAI(apiKey) {
17
+ const sc = new secure_client_1.SecureClient();
19
18
  const groundTruth = await sc.verify();
20
19
  const connect = (0, undici_1.buildConnector)({
21
20
  checkServerIdentity: (host, cert) => {
@@ -37,7 +36,7 @@ async function createTinfoilAI(repo, enclave, apiKey) {
37
36
  const agent = new undici_1.Agent({ connect });
38
37
  return (0, openai_compatible_1.createOpenAICompatible)({
39
38
  name: "tinfoil",
40
- baseURL: `https://${enclave}/v1`,
39
+ baseURL: config_1.TINFOIL_CONFIG.INFERENCE_BASE_URL.replace(/\/$/, ''),
41
40
  apiKey: apiKey,
42
41
  fetch: (async (input, init) => {
43
42
  if (!init) {
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,26 +8,20 @@ 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
+ apiKey?: string;
13
+ [key: string]: any;
14
+ }
12
15
  export declare class TinfoilAI {
13
16
  private client?;
14
- private enclave;
15
- private repo;
16
17
  private groundTruth?;
17
18
  private clientPromise;
18
19
  private readyPromise?;
19
20
  /**
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
21
+ * Creates a new TinfoilAI instance.
22
+ * @param options - Configuration options including apiKey and other OpenAI client options
30
23
  */
31
- constructor(enclave: string, repo: string, options?: ConstructorParameters<typeof OpenAI>[0]);
24
+ constructor(options?: TinfoilAIOptions);
32
25
  /**
33
26
  * Ensures the client is ready to use.
34
27
  * @returns Promise that resolves when the client is initialized
@@ -89,3 +82,4 @@ export declare class TinfoilAI {
89
82
  */
90
83
  get beta(): Beta;
91
84
  }
85
+ export {};
package/dist/client.js CHANGED
@@ -8,6 +8,7 @@ const openai_1 = __importDefault(require("openai"));
8
8
  const crypto_1 = require("crypto");
9
9
  const secure_client_1 = require("./secure-client");
10
10
  const https_1 = __importDefault(require("https"));
11
+ const config_1 = require("./config");
11
12
  /**
12
13
  * Creates a proxy that allows property access and method calls on a Promise before it resolves.
13
14
  * This enables a more ergonomic API where you can chain properties and methods without explicitly
@@ -47,30 +48,18 @@ function createAsyncProxy(promise) {
47
48
  }
48
49
  });
49
50
  }
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
51
  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);
65
- }
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);
52
+ /**
53
+ * Creates a new TinfoilAI instance.
54
+ * @param options - Configuration options including apiKey and other OpenAI client options
55
+ */
56
+ constructor(options = {}) {
57
+ // Set apiKey from options or environment variable
58
+ const openAIOptions = { ...options };
59
+ if (options.apiKey || process.env.TINFOIL_API_KEY) {
60
+ openAIOptions.apiKey = options.apiKey || process.env.TINFOIL_API_KEY;
73
61
  }
62
+ this.clientPromise = this.initClient(openAIOptions);
74
63
  }
75
64
  /**
76
65
  * Ensures the client is ready to use.
@@ -89,7 +78,7 @@ class TinfoilAI {
89
78
  }
90
79
  async createOpenAIClient(options = {}) {
91
80
  // Verify the enclave and get the certificate fingerprint
92
- const secureClient = new secure_client_1.SecureClient(this.enclave, this.repo);
81
+ const secureClient = new secure_client_1.SecureClient();
93
82
  try {
94
83
  this.groundTruth = await secureClient.verify();
95
84
  }
@@ -118,10 +107,10 @@ class TinfoilAI {
118
107
  }
119
108
  });
120
109
  // Create the OpenAI client with our custom configuration
110
+ // Note: baseURL will need to be determined by the verification process
121
111
  return new openai_1.default({
122
112
  ...options,
123
- baseURL: `https://${this.enclave}/v1/`,
124
- httpAgent: httpsAgent,
113
+ baseURL: config_1.TINFOIL_CONFIG.INFERENCE_BASE_URL,
125
114
  });
126
115
  }
127
116
  /**
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Configuration constants for the Tinfoil Node SDK
3
+ */
4
+ export declare const TINFOIL_CONFIG: {
5
+ /**
6
+ * The full base URL for the inference API
7
+ */
8
+ readonly INFERENCE_BASE_URL: "https://inference.tinfoil.sh/v1/";
9
+ /**
10
+ * The GitHub repository for the confidential inference proxy
11
+ */
12
+ readonly INFERENCE_PROXY_REPO: "tinfoilsh/confidential-inference-proxy";
13
+ };
package/dist/config.js ADDED
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TINFOIL_CONFIG = void 0;
4
+ /**
5
+ * Configuration constants for the Tinfoil Node SDK
6
+ */
7
+ exports.TINFOIL_CONFIG = {
8
+ /**
9
+ * The full base URL for the inference API
10
+ */
11
+ INFERENCE_BASE_URL: 'https://inference.tinfoil.sh/v1/',
12
+ /**
13
+ * The GitHub repository for the confidential inference proxy
14
+ */
15
+ INFERENCE_PROXY_REPO: 'tinfoilsh/confidential-inference-proxy',
16
+ };
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from './client';
2
2
  export * from './secure-client';
3
3
  export * from './ai-sdk-provider';
4
+ export * from './config';
package/dist/index.js CHANGED
@@ -17,3 +17,4 @@ Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./client"), exports);
18
18
  __exportStar(require("./secure-client"), exports);
19
19
  __exportStar(require("./ai-sdk-provider"), exports);
20
+ __exportStar(require("./config"), exports);
@@ -9,11 +9,11 @@ export interface GroundTruth {
9
9
  * SecureClient handles verification of code and runtime measurements using WebAssembly
10
10
  */
11
11
  export declare class SecureClient {
12
- private enclave;
13
- private repo;
14
12
  private static goInstance;
15
13
  private static initializationPromise;
16
- constructor(enclave: string, repo: string);
14
+ private readonly enclave;
15
+ private readonly repo;
16
+ constructor();
17
17
  /**
18
18
  * Static method to initialize WASM module
19
19
  * This starts automatically when the class is loaded
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.SecureClient = void 0;
7
7
  const node_fetch_1 = __importDefault(require("node-fetch"));
8
8
  const util_1 = require("util");
9
+ const config_1 = require("./config");
9
10
  // Set up browser-like globals that the Go WASM runtime expects
10
11
  const globalThis = global;
11
12
  // Performance API
@@ -62,9 +63,10 @@ require('./wasm-exec.js');
62
63
  * SecureClient handles verification of code and runtime measurements using WebAssembly
63
64
  */
64
65
  class SecureClient {
65
- constructor(enclave, repo) {
66
- this.enclave = enclave;
67
- this.repo = repo;
66
+ constructor() {
67
+ // Values for the Tinfoil inference proxy from config
68
+ this.enclave = new URL(config_1.TINFOIL_CONFIG.INFERENCE_BASE_URL).hostname;
69
+ this.repo = config_1.TINFOIL_CONFIG.INFERENCE_PROXY_REPO;
68
70
  }
69
71
  /**
70
72
  * Static method to initialize WASM module
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.5.0",
4
+ "description": "Tinfoil secure OpenAI client wrapper",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "scripts": {