@turnstileai/sdk 0.1.7 → 0.1.8

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/dist/index.d.ts CHANGED
@@ -1,3 +1,63 @@
1
- export { TurnstileAI } from "./client";
2
- export { TurnstileError, TurnstileAuthError, TurnstileRequestError, TurnstileVerificationError, } from "./errors";
3
- export type { TurnstileConfig, InferenceOptions, RunRecord, LedgerCheckpoint, VerificationResult, ProviderHealth, UsageOverview, RouteMode, LedgerMode, TurnstileApiErrorBody, } from "./types";
1
+ export interface TurnstileAIConfig {
2
+ apiKey: string;
3
+ baseURL?: string;
4
+ defaultPolicy?: string;
5
+ defaultAnchor?: string;
6
+ }
7
+ export interface ChatMessage {
8
+ role: "system" | "user" | "assistant";
9
+ content: string;
10
+ }
11
+ export interface ChatCompletionRequest {
12
+ model: string;
13
+ messages: ChatMessage[];
14
+ extra_body?: {
15
+ receipt?: boolean;
16
+ policy?: string;
17
+ anchor?: string;
18
+ };
19
+ }
20
+ export interface ComputeReceipt {
21
+ id: string;
22
+ model: string;
23
+ provider: string;
24
+ tokens: number;
25
+ latencySeconds: number;
26
+ costUsd: number;
27
+ signature: string;
28
+ verified: boolean;
29
+ anchor?: {
30
+ chain: string;
31
+ transactionId: string;
32
+ explorerUrl?: string;
33
+ } | null;
34
+ }
35
+ export interface ChatCompletionResponse {
36
+ choices: Array<{
37
+ message: {
38
+ role: "assistant";
39
+ content: string;
40
+ };
41
+ }>;
42
+ compute_receipt?: ComputeReceipt;
43
+ }
44
+ export declare class TurnstileAI {
45
+ private apiKey;
46
+ private baseURL;
47
+ private defaultPolicy?;
48
+ private defaultAnchor?;
49
+ constructor(config: TurnstileAIConfig);
50
+ chat: {
51
+ completions: {
52
+ create: (body: ChatCompletionRequest) => Promise<ChatCompletionResponse>;
53
+ };
54
+ };
55
+ receipts: {
56
+ get: (id: string) => Promise<ComputeReceipt>;
57
+ verify: (id: string) => Promise<{
58
+ status: string;
59
+ signatureValid: boolean;
60
+ anchorMatched: boolean;
61
+ }>;
62
+ };
63
+ }
package/dist/index.js CHANGED
@@ -1,10 +1,62 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TurnstileVerificationError = exports.TurnstileRequestError = exports.TurnstileAuthError = exports.TurnstileError = exports.TurnstileAI = void 0;
4
- var client_1 = require("./client");
5
- Object.defineProperty(exports, "TurnstileAI", { enumerable: true, get: function () { return client_1.TurnstileAI; } });
6
- var errors_1 = require("./errors");
7
- Object.defineProperty(exports, "TurnstileError", { enumerable: true, get: function () { return errors_1.TurnstileError; } });
8
- Object.defineProperty(exports, "TurnstileAuthError", { enumerable: true, get: function () { return errors_1.TurnstileAuthError; } });
9
- Object.defineProperty(exports, "TurnstileRequestError", { enumerable: true, get: function () { return errors_1.TurnstileRequestError; } });
10
- Object.defineProperty(exports, "TurnstileVerificationError", { enumerable: true, get: function () { return errors_1.TurnstileVerificationError; } });
3
+ exports.TurnstileAI = void 0;
4
+ class TurnstileAI {
5
+ constructor(config) {
6
+ this.chat = {
7
+ completions: {
8
+ create: async (body) => {
9
+ const response = await fetch(`${this.baseURL}/chat/completions`, {
10
+ method: "POST",
11
+ headers: {
12
+ "Content-Type": "application/json",
13
+ Authorization: `Bearer ${this.apiKey}`
14
+ },
15
+ body: JSON.stringify({
16
+ ...body,
17
+ extra_body: {
18
+ ...body.extra_body,
19
+ policy: body.extra_body?.policy ?? this.defaultPolicy,
20
+ anchor: body.extra_body?.anchor ?? this.defaultAnchor
21
+ }
22
+ })
23
+ });
24
+ if (!response.ok) {
25
+ throw new Error(`TurnstileAI API error: ${response.status}`);
26
+ }
27
+ return response.json();
28
+ }
29
+ }
30
+ };
31
+ this.receipts = {
32
+ get: async (id) => {
33
+ const response = await fetch(`${this.baseURL}/receipts/${id}`, {
34
+ headers: {
35
+ Authorization: `Bearer ${this.apiKey}`
36
+ }
37
+ });
38
+ if (!response.ok) {
39
+ throw new Error(`TurnstileAI receipt error: ${response.status}`);
40
+ }
41
+ return response.json();
42
+ },
43
+ verify: async (id) => {
44
+ const response = await fetch(`${this.baseURL}/receipts/${id}/verify`, {
45
+ method: "POST",
46
+ headers: {
47
+ Authorization: `Bearer ${this.apiKey}`
48
+ }
49
+ });
50
+ if (!response.ok) {
51
+ throw new Error(`TurnstileAI verification error: ${response.status}`);
52
+ }
53
+ return response.json();
54
+ }
55
+ };
56
+ this.apiKey = config.apiKey;
57
+ this.baseURL = config.baseURL || "https://api.turnstileai.com/v1";
58
+ this.defaultPolicy = config.defaultPolicy;
59
+ this.defaultAnchor = config.defaultAnchor;
60
+ }
61
+ }
62
+ exports.TurnstileAI = TurnstileAI;
package/package.json CHANGED
@@ -1,29 +1,34 @@
1
1
  {
2
2
  "name": "@turnstileai/sdk",
3
- "version": "0.1.7",
4
- "description": "TypeScript SDK for TurnstileAI, a verification-first AI gateway",
3
+ "version": "0.1.8",
4
+ "description": "TypeScript SDK for verified AI inference, routing, and signed compute receipts.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
- "bin": {
8
- "turnstileai": "dist/cli.js"
7
+ "exports": {
8
+ ".": {
9
+ "types": "./dist/index.d.ts",
10
+ "default": "./dist/index.js"
11
+ }
9
12
  },
10
13
  "files": [
11
14
  "dist",
12
- "README.md"
15
+ "README.md",
16
+ "LICENSE"
13
17
  ],
14
18
  "scripts": {
15
19
  "build": "tsc",
16
- "test": "npm run build && node --test dist/test/**/*.test.js",
17
20
  "prepublishOnly": "npm run build"
18
21
  },
19
22
  "keywords": [
20
23
  "ai",
21
24
  "sdk",
22
- "solana",
23
- "verification",
24
- "llm",
25
25
  "typescript",
26
- "turnstileai"
26
+ "openai",
27
+ "inference",
28
+ "verification",
29
+ "receipt",
30
+ "solana",
31
+ "routing"
27
32
  ],
28
33
  "author": "TurnstileAI",
29
34
  "license": "MIT",