trusera-sdk 0.1.0 → 1.0.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,5 +1,7 @@
1
1
  # Trusera SDK for JavaScript/TypeScript
2
2
 
3
+ > **Beta** — This SDK is under active development. Expected GA: April 2026.
4
+
3
5
  [![npm version](https://badge.fury.io/js/trusera-sdk.svg)](https://www.npmjs.com/package/trusera-sdk)
4
6
  [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
5
7
 
@@ -7,9 +9,10 @@ The official TypeScript/JavaScript SDK for monitoring AI agents with [Trusera](h
7
9
 
8
10
  ## Key Features
9
11
 
10
- - **Transparent HTTP Interception**: Zero-code instrumentation of all outbound HTTP calls
12
+ - **Transparent HTTP Interception**: Zero-code instrumentation via `fetch`, `axios`, and `undici`
11
13
  - **Policy Enforcement**: Runtime evaluation against Cedar policies with configurable enforcement modes
12
- - **LangChain.js Integration**: First-class support for LangChain.js callbacks
14
+ - **LangChain.js Integration**: First-class support for LangChain.js callbacks with optional Cedar enforcement
15
+ - **ESM + CJS**: Dual-format output (built with tsup) -- works in any Node.js or Bun environment
13
16
  - **Rich Event Tracking**: Track LLM calls, tool executions, data access, and custom events
14
17
  - **Batched Transmission**: Automatic event batching and retry logic
15
18
  - **Type-Safe**: Full TypeScript support with strict typing
@@ -74,6 +77,54 @@ await model.invoke("What are the top AI security risks?");
74
77
  await client.close();
75
78
  ```
76
79
 
80
+ ### Axios and Undici Interception
81
+
82
+ The interceptor automatically detects and patches `axios` and `undici` if they
83
+ are installed. No additional configuration is needed:
84
+
85
+ ```typescript
86
+ import axios from "axios";
87
+ import { TruseraClient, TruseraInterceptor } from "trusera-sdk";
88
+
89
+ const client = new TruseraClient({ apiKey: "tsk_xxx" });
90
+ const interceptor = new TruseraInterceptor();
91
+ interceptor.install(client, { enforcement: "warn" });
92
+
93
+ // axios requests are now tracked automatically
94
+ await axios.get("https://api.openai.com/v1/models");
95
+
96
+ // undici requests too (if undici is installed)
97
+ // import { request } from "undici";
98
+ // await request("https://api.openai.com/v1/models");
99
+
100
+ await client.close();
101
+ interceptor.uninstall();
102
+ ```
103
+
104
+ Libraries are detected via `require()` at install-time. If a library is not
105
+ installed, it is silently skipped with no errors.
106
+
107
+ ### LangChain.js with Cedar Enforcement
108
+
109
+ Add Cedar policy enforcement to tool and LLM calls:
110
+
111
+ ```typescript
112
+ import { TruseraClient, TruseraLangChainHandler, CedarEvaluator } from "trusera-sdk";
113
+
114
+ const evaluator = new CedarEvaluator();
115
+ await evaluator.loadPolicy(`
116
+ forbid (principal, action == Action::"*", resource)
117
+ when { resource.hostname == "langchain" };
118
+ `);
119
+
120
+ const handler = new TruseraLangChainHandler(client, {
121
+ enforcement: "block",
122
+ cedarEvaluator: evaluator,
123
+ });
124
+
125
+ // Denied tool/LLM calls throw in block mode
126
+ ```
127
+
77
128
  ### Manual Event Tracking
78
129
 
79
130
  For custom instrumentation:
@@ -282,17 +333,28 @@ The SDK tracks six core event types:
282
333
 
283
334
  #### Methods
284
335
 
285
- - `install(client: TruseraClient, options?: InterceptorOptions): void`: Install HTTP interceptor
286
- - `uninstall(): void`: Restore original fetch and remove interceptor
336
+ - `install(client: TruseraClient, options?: InterceptorOptions): void`: Install HTTP interceptor for `fetch`, `axios` (if available), and `undici` (if available)
337
+ - `uninstall(): void`: Restore original fetch, eject axios interceptors, and restore undici functions
287
338
 
288
339
  ### `TruseraLangChainHandler`
289
340
 
290
341
  #### Methods
291
342
 
292
- - `constructor(client: TruseraClient)`: Create handler for LangChain callbacks
343
+ - `constructor(client: TruseraClient, options?: LangChainHandlerOptions)`: Create handler for LangChain callbacks with optional Cedar enforcement
293
344
  - `getPendingEventCount(): number`: Get count of incomplete events
294
345
  - `clearPendingEvents(): void`: Clear all pending events
295
346
 
347
+ #### LangChainHandlerOptions
348
+
349
+ ```typescript
350
+ interface LangChainHandlerOptions {
351
+ enforcement?: "block" | "warn" | "log";
352
+ cedarEvaluator?: CedarEvaluator;
353
+ }
354
+ ```
355
+
356
+ When `enforcement` is `"block"` and a Cedar policy denies a tool/LLM call, the handler throws an `Error`. In `"warn"` mode it logs via `console.warn`. In `"log"` mode (default) violations are tracked silently.
357
+
296
358
  ### Utility Functions
297
359
 
298
360
  - `createEvent(type: EventType, name: string, payload?, metadata?): Event`: Create a well-formed event