tinfoil 0.3.1 → 0.4.1

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.
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Creates an AI SDK provider with the specified repository and enclave.
3
+ *
4
+ * @param repo - The repository identifier
5
+ * @param enclave - The enclave URL/identifier
6
+ * @returns A TinfoilAI instance
7
+ */
8
+ export declare function createTinfoilAI(repo: string, enclave: string): Promise<import("@ai-sdk/openai-compatible").OpenAICompatibleProvider<string, string, string, string>>;
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createTinfoilAI = createTinfoilAI;
4
+ const openai_compatible_1 = require("@ai-sdk/openai-compatible");
5
+ const secure_client_1 = require("./secure-client");
6
+ const undici_1 = require("undici");
7
+ const node_tls_1 = require("node:tls");
8
+ const node_crypto_1 = require("node:crypto");
9
+ /**
10
+ * Creates an AI SDK provider with the specified repository and enclave.
11
+ *
12
+ * @param repo - The repository identifier
13
+ * @param enclave - The enclave URL/identifier
14
+ * @returns A TinfoilAI instance
15
+ */
16
+ async function createTinfoilAI(repo, enclave) {
17
+ const sc = new secure_client_1.SecureClient(enclave, repo);
18
+ const groundTruth = await sc.verify();
19
+ const connect = (0, undici_1.buildConnector)({
20
+ checkServerIdentity: (host, cert) => {
21
+ if (!cert.pubkey) {
22
+ throw new Error('No public key available in certificate');
23
+ }
24
+ const x509 = new node_crypto_1.X509Certificate(cert.raw);
25
+ const publicKeyDer = x509.publicKey.export({
26
+ type: 'spki',
27
+ format: 'der'
28
+ });
29
+ const pubKeyFP = (0, node_crypto_1.createHash)('sha256').update(publicKeyDer).digest('hex');
30
+ if (pubKeyFP !== groundTruth.publicKeyFP) {
31
+ throw new Error(`Certificate public key fingerprint mismatch. Expected: ${groundTruth.publicKeyFP}, Got: ${pubKeyFP}`);
32
+ }
33
+ return (0, node_tls_1.checkServerIdentity)(host, cert);
34
+ }
35
+ });
36
+ const agent = new undici_1.Agent({ connect });
37
+ return (0, openai_compatible_1.createOpenAICompatible)({
38
+ name: "tinfoil",
39
+ baseURL: `https://${enclave}/v1`,
40
+ fetch: (async (input, init) => {
41
+ if (!init) {
42
+ init = {};
43
+ }
44
+ init.dispatcher = agent;
45
+ return await (0, undici_1.fetch)(input, init);
46
+ }),
47
+ });
48
+ }
package/dist/index.d.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  export * from './client';
2
2
  export * from './secure-client';
3
+ export * from './ai-sdk-provider';
package/dist/index.js CHANGED
@@ -16,3 +16,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./client"), exports);
18
18
  __exportStar(require("./secure-client"), exports);
19
+ __exportStar(require("./ai-sdk-provider"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tinfoil",
3
- "version": "0.3.1",
3
+ "version": "0.4.1",
4
4
  "description": "Official Tinfoil secure OpenAI client wrapper",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -28,10 +28,13 @@
28
28
  "author": "Tinfoil",
29
29
  "license": "AGPL-3.0-or-later",
30
30
  "dependencies": {
31
+ "@ai-sdk/openai-compatible": "^0.2.14",
32
+ "ai": "^4.3.15",
31
33
  "dotenv": "^16.4.7",
32
34
  "node-fetch": "^2.7.0",
33
35
  "openai": "^4.87.3",
34
- "ts-node": "^10.9.2"
36
+ "ts-node": "^10.9.2",
37
+ "undici": "^7.9.0"
35
38
  },
36
39
  "devDependencies": {
37
40
  "@types/jest": "^29.5.12",