@tenova/swt3-ai 0.3.3 → 0.3.5

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.
Files changed (2) hide show
  1. package/README.md +77 -2
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -8,7 +8,7 @@ Witness your AI. Prove it followed the rules. Cryptographic accountability for e
8
8
 
9
9
  **SWT3 AI Witness SDK for TypeScript**: tamper-proof evidence that your AI is doing what you say it does. Every inference hashed. Every tool call recorded. Every resource access checked against scope. No prompts or responses ever leave your infrastructure.
10
10
 
11
- Works with OpenAI, Anthropic, Vercel AI SDK, and any OpenAI-compatible endpoint (vLLM, Ollama, Azure, Llama.cpp).
11
+ Works with OpenAI, Anthropic, AWS Bedrock, Vercel AI SDK, and any OpenAI-compatible endpoint (vLLM, Ollama, Azure, Llama.cpp).
12
12
 
13
13
  The EU AI Act takes effect **August 2, 2026**. When regulators ask "prove your AI followed the rules," you need more than logs. You need cryptographic proof.
14
14
 
@@ -178,6 +178,75 @@ The `agentId` survives all clearing levels. The `signingKey` produces a cryptogr
178
178
  - Fleet-wide governance dashboards
179
179
  - Agent-scoped evidence packages for auditors
180
180
 
181
+ ## Gatekeeper Mode (Pre-Call Enforcement)
182
+
183
+ New in v0.3.4. Require guardrails to be active *before* the model is called, not just observed after:
184
+
185
+ ```typescript
186
+ import { Witness, GatekeeperError } from "@tenova/swt3-ai";
187
+
188
+ const witness = new Witness({
189
+ endpoint: "...",
190
+ apiKey: "axm_...",
191
+ tenantId: "...",
192
+ strict: true,
193
+ guardrailsRequired: 2,
194
+ guardrailNames: ["content-filter", "pii-scanner"],
195
+ });
196
+
197
+ const client = witness.wrap(new OpenAI()) as OpenAI;
198
+
199
+ // If fewer than 2 guardrails are active, this throws GatekeeperError
200
+ // BEFORE the model call happens. No inference runs without safeguards.
201
+ try {
202
+ const response = await client.chat.completions.create({
203
+ model: "gpt-4o",
204
+ messages: [{ role: "user", content: "..." }],
205
+ });
206
+ } catch (e) {
207
+ if (e instanceof GatekeeperError) {
208
+ console.log(`Blocked: ${e.message}`);
209
+ // An AI-GRD.3 FAIL anchor is minted recording the gate failure
210
+ }
211
+ }
212
+ ```
213
+
214
+ Gatekeeper mode mints an **AI-GRD.3** anchor with:
215
+ - **factor_a** = required guardrail count
216
+ - **factor_b** = actual guardrail count
217
+ - **factor_c** = 1 if gate passed, 0 if blocked
218
+
219
+ ## Multi-Agent Chain Linking
220
+
221
+ New in v0.3.4. Link anchors across agents in a multi-step pipeline using `cycleId`:
222
+
223
+ ```typescript
224
+ const witness = new Witness({
225
+ endpoint: "...",
226
+ apiKey: "axm_...",
227
+ tenantId: "...",
228
+ agentId: "step-1-classifier",
229
+ cycleId: "txn-review-abc123", // shared across all agents in the chain
230
+ });
231
+ ```
232
+
233
+ The `cycleId` survives all clearing levels and appears in every anchor. An auditor can reconstruct the full decision chain by filtering on a single cycle ID.
234
+
235
+ ## Policy Version Binding
236
+
237
+ New in v0.3.4. Tie every anchor to the specific policy configuration that was in effect:
238
+
239
+ ```typescript
240
+ const witness = new Witness({
241
+ endpoint: "...",
242
+ apiKey: "axm_...",
243
+ tenantId: "...",
244
+ policyVersion: "v2.1.0-prod-2026-04-20",
245
+ });
246
+ ```
247
+
248
+ The SDK hashes the policy version string (SHA-256, first 12 characters) and includes it in every payload. When policies change between audit periods, the hash changes — proving which rules were in effect for each inference.
249
+
181
250
  ## What Gets Witnessed
182
251
 
183
252
  Each inference produces anchors for these checks. Every check maps to a regulation.
@@ -249,6 +318,7 @@ Translation: "Access attempt occurred. Target was outside declared scope. Access
249
318
  | AI-MDL.2 | 1 (required) | 1 if version recorded | 0 | PASS if b >= a |
250
319
  | AI-GRD.1 | Required count | Active count | 1 if all passed | PASS if b >= a |
251
320
  | AI-GRD.2 | 1 (clean expected) | 0 if refusal | 0 | PASS if b >= a |
321
+ | AI-GRD.3 | Required count | Active count | 1=passed, 0=blocked | PASS if b >= a AND c == 1 |
252
322
  | AI-TOOL.1 | 1 (called) | Latency (ms) | 1=success, 0=error | PASS if b >= a |
253
323
  | AI-ACC.1 | 1 (accessed) | 1=in scope, 0=out | 1=granted, 0=denied | PASS if b >= a |
254
324
  | AI-ID.1 | 1 (required) | 1 if identity present | 0 | PASS if b >= a |
@@ -372,6 +442,11 @@ const witness = new Witness({
372
442
  | `guardrailNames` | [] | Active guardrail names |
373
443
  | `agentId` | - | Agent identity (survives all clearing levels) |
374
444
  | `signingKey` | - | HMAC-SHA256 key for payload signing |
445
+ | `cycleId` | - | Multi-agent chain link (survives all clearing levels) |
446
+ | `policyVersion` | - | Policy config identifier (hashed in payloads) |
447
+ | `strict` | false | Gatekeeper mode: block inference if guardrails insufficient |
448
+ | `latencyThresholdMs` | 30000 | AI-INF.2 latency limit (ms) |
449
+ | `guardrailsRequired` | 0 | AI-GRD.1 minimum guardrail count |
375
450
  | `factorHandoff` | - | "file" for local factor export |
376
451
  | `factorHandoffPath` | - | Directory for handoff files |
377
452
 
@@ -379,7 +454,7 @@ const witness = new Witness({
379
454
 
380
455
  | Method | Description |
381
456
  |--------|-------------|
382
- | `witness.wrap(client)` | Returns a Proxy that behaves identically to the original client. Supports OpenAI and Anthropic. |
457
+ | `witness.wrap(client)` | Returns a Proxy that behaves identically to the original client. Supports OpenAI, Anthropic, and AWS Bedrock. |
383
458
  | `witness.wrapTool(fn, name?)` | Wraps a function for tool call witnessing (AI-TOOL.1). |
384
459
  | `witness.wrapAccess(fn, resource?, scope?)` | Wraps a function for resource access witnessing (AI-ACC.1). |
385
460
  | `witness.vercelOnFinish(opts?)` | Returns an onFinish callback for Vercel AI SDK streamText/generateText. |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tenova/swt3-ai",
3
- "version": "0.3.3",
3
+ "version": "0.3.5",
4
4
  "description": "SWT3 AI Witness SDK: cryptographic attestation for AI inference",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",