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/README.md CHANGED
@@ -1,57 +1,77 @@
1
- # Tinfoil Analytics Client
1
+ # Tinfoil Node Client
2
2
 
3
- A privacy-preserving web analytics solution using the Distributed Aggregation Protocol (DAP). Collects anonymous metrics while ensuring user privacy through secure aggregation.
3
+ [![Build Status](https://github.com/tinfoilsh/tinfoil-node/actions/workflows/test.yml/badge.svg)](https://github.com/tinfoilsh/tinfoil-node/actions)
4
+ [![NPM version](https://img.shields.io/npm/v/tinfoil.svg)](https://npmjs.org/package/tinfoil)
4
5
 
5
- ## Quick Start
6
+ A Node.js wrapper around the OpenAI client that verifies enclave attestation and certificate fingerprints when using Tinfoil inference.
6
7
 
7
- Add the script tag to your HTML:
8
+ ## Installation
8
9
 
9
- ```html
10
- <script async src="https://js.tinfoil.sh" data-param="your.domain.com"></script>
10
+ ```bash
11
+ npm install tinfoil
11
12
  ```
12
13
 
13
- For custom event tracking, add the `tinfoil-event-name` class:
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
- ```html
16
- <button class="tinfoil-event-name=Button+Click">Click Me</button>
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
- ## Development
32
+ ## Running the Chat Example
20
33
 
21
- To run the project locally, use the following commands:
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
- # Build the project
28
- npm run build
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
- # Run unit tests
31
- npm run test
52
+ 4. Run the example:
32
53
 
33
- # Run end-to-end tests
34
- npm run test:e2e
54
+ ```bash
55
+ npx ts-node examples/chat/main.ts
35
56
  ```
36
57
 
37
- ## Publishing
58
+ The example demonstrates streaming chat completions with the Tinfoil API wrapper.
38
59
 
39
- 1. Bump the version in `package.json`:
60
+ ## Runtime Support
40
61
 
41
- ```json
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
- 2. Build the package:
64
+ ## API Documentation
46
65
 
47
- ```bash
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
- ```bash
54
- npm publish
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
- 4. Go to the [jsdelivr repo](https://github.com/tinfoilanalytics/jsdelivr) and follow the README there to update the hosted version at js.tinfoil.sh.
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 type { AnalyticsConfig } from './types';
2
- export declare class AnalyticsClient {
3
- private config;
4
- private globalConfig;
5
- private tasks;
6
- constructor(config: AnalyticsConfig);
7
- init(): Promise<void>;
8
- private initTracking;
9
- private refreshConfig;
10
- private getTask;
11
- private createTask;
12
- trackEvent(eventName: string, value?: number | boolean): Promise<void>;
13
- trackPageVisit(): Promise<void>;
14
- private trackCountry;
15
- trackTelemetry(): Promise<void>;
16
- private sendOSType;
17
- private sendBrowserType;
18
- private sendDeviceType;
19
- startSessionTracking(): void;
20
- private bucketTime;
21
- private setupCustomEventTracking;
22
- private setupBounceTracking;
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