tinfoil 0.4.4 → 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,9 +17,7 @@ npm install tinfoil
17
17
  import { TinfoilAI } from 'tinfoil';
18
18
 
19
19
  const client = new TinfoilAI({
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
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
@@ -44,9 +42,7 @@ npm install
44
42
  3. Optionally create a `.env` file with your configuration:
45
43
 
46
44
  ```bash
47
- TINFOIL_ENCLAVE=enclave.example.com
48
- TINFOIL_REPO=org/model-repo
49
- OPENAI_API_KEY=your-api-key
45
+ TINFOIL_API_KEY=<YOUR_API_KEY>
50
46
  ```
51
47
 
52
48
  4. Run the example:
@@ -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
@@ -9,22 +9,17 @@ import type { Chat, Files, FineTuning, Images, Audio, Embeddings, Models, Modera
9
9
  * - Type-safe access to OpenAI's chat completion APIs
10
10
  */
11
11
  interface TinfoilAIOptions {
12
- enclave?: string;
13
- repo?: string;
14
12
  apiKey?: string;
15
13
  [key: string]: any;
16
14
  }
17
15
  export declare class TinfoilAI {
18
16
  private client?;
19
- private enclave;
20
- private repo;
21
17
  private groundTruth?;
22
18
  private clientPromise;
23
19
  private readyPromise?;
24
20
  /**
25
21
  * 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
22
+ * @param options - Configuration options including apiKey and other OpenAI client options
28
23
  */
29
24
  constructor(options?: TinfoilAIOptions);
30
25
  /**
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
@@ -50,21 +51,13 @@ function createAsyncProxy(promise) {
50
51
  class TinfoilAI {
51
52
  /**
52
53
  * 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
54
+ * @param options - Configuration options including apiKey and other OpenAI client options
55
55
  */
56
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');
62
- }
63
- // Prepare OpenAI client options
64
- const { enclave: _, repo: __, ...openAIOptions } = options;
65
57
  // 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;
58
+ const openAIOptions = { ...options };
59
+ if (options.apiKey || process.env.TINFOIL_API_KEY) {
60
+ openAIOptions.apiKey = options.apiKey || process.env.TINFOIL_API_KEY;
68
61
  }
69
62
  this.clientPromise = this.initClient(openAIOptions);
70
63
  }
@@ -85,7 +78,7 @@ class TinfoilAI {
85
78
  }
86
79
  async createOpenAIClient(options = {}) {
87
80
  // Verify the enclave and get the certificate fingerprint
88
- const secureClient = new secure_client_1.SecureClient(this.enclave, this.repo);
81
+ const secureClient = new secure_client_1.SecureClient();
89
82
  try {
90
83
  this.groundTruth = await secureClient.verify();
91
84
  }
@@ -114,10 +107,10 @@ class TinfoilAI {
114
107
  }
115
108
  });
116
109
  // Create the OpenAI client with our custom configuration
110
+ // Note: baseURL will need to be determined by the verification process
117
111
  return new openai_1.default({
118
112
  ...options,
119
- baseURL: `https://${this.enclave}/v1/`,
120
- httpAgent: httpsAgent,
113
+ baseURL: config_1.TINFOIL_CONFIG.INFERENCE_BASE_URL,
121
114
  });
122
115
  }
123
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,6 +1,6 @@
1
1
  {
2
2
  "name": "tinfoil",
3
- "version": "0.4.4",
3
+ "version": "0.5.0",
4
4
  "description": "Tinfoil secure OpenAI client wrapper",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",