leap360 1.1.4 โ†’ 1.1.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 +140 -0
  2. package/package.json +2 -2
package/README.md ADDED
@@ -0,0 +1,140 @@
1
+ # ๐Ÿ›ก๏ธ Leap360 SDK: The AI Governance Layer
2
+
3
+ Leap360 is a production-grade governance and observability SDK for AI-native applications. It provides a "belt-and-suspenders" approach to AI safety, combining real-time telemetry, automated policy enforcement, and a global **Kill Switch** that can halt AI operations project-wide in under 2 seconds.
4
+
5
+ ---
6
+
7
+ ## ๐Ÿš€ The Power of Leap360
8
+
9
+ Leap360 isn't just a logger; it's a **Governance Layer**.
10
+
11
+ 1. **Zero-Invasive Integration**: Patch global prototypes to trace every LLM call in your app without changing a single line of your business logic.
12
+ 2. **Hardened Resiliency**: Our "Global Poller" heartbeat ensures that if a project is suspended in the dashboard, the SDK blocks outgoing LLM requests *locally* before they even transit the wire.
13
+ 3. **Contextual Intelligence**: Group calls into "Agents" (e.g., Legal-Bot, Finance-Bot) using `createAgent` to understand cost and risk distribution across your fleet.
14
+ 4. **Universal Compatibility**: Works in **Node.js**, **Browsers**, **ESM**, and **CommonJS** environments.
15
+
16
+ ---
17
+
18
+ ## ๐Ÿ“ฆ Installation
19
+
20
+ ```bash
21
+ npm install leap360
22
+ ```
23
+
24
+ ---
25
+
26
+ ## ๐Ÿ› ๏ธ Integration Styles
27
+
28
+ ### 1. The "Magic" 1-Line Integration (`autoInit`)
29
+ The fastest way to get started. This patches the global `OpenAI` and `GoogleGenerativeAI` prototypes.
30
+
31
+ ```javascript
32
+ import { Leap360 } from 'leap360';
33
+
34
+ Leap360.autoInit({
35
+ apiKey: 'your_leap360_key',
36
+ projectId: 'my-production-app',
37
+ serviceName: 'enterprise-fleet'
38
+ });
39
+
40
+ // Now, any OpenAI or Gemini call anywhere in your app is automatically governed!
41
+ ```
42
+
43
+ ### 2. The "Contextual" Agent Approach (`createAgent`)
44
+ Use this to tag calls with specific agent names. This uses `AsyncLocalStorage` (Node) or a fallback (Browser) to propagate context.
45
+
46
+ ```javascript
47
+ const agent = leap.createAgent({ name: 'Legal-Compliance-Bot' });
48
+
49
+ await agent.run(async () => {
50
+ // All LLM calls inside this block are tagged as 'Legal-Compliance-Bot'
51
+ const model = genAI.getGenerativeModel({ model: 'gemini-1.5-pro' });
52
+ await model.generateContent("Analyze this contract...");
53
+ });
54
+ ```
55
+
56
+ ### 3. Manual Instance Wrapping
57
+ For developers who prefer explicit control over specific client instances.
58
+
59
+ ```javascript
60
+ const openai = leap.wrapOpenAI(new OpenAI());
61
+ const genAI = leap.wrapGemini(new GoogleGenerativeAI(apiKey));
62
+ ```
63
+
64
+ ### 4. Low-Level Manual Tracing (`Leap360Client`)
65
+ For non-standard models or custom wrappers where you want full control over the trace payload.
66
+
67
+ ```javascript
68
+ import { Leap360Client } from 'leap360';
69
+ const client = new Leap360Client({ apiKey: '...' });
70
+
71
+ const result = await client.traceCall({
72
+ provider: 'anthropic',
73
+ model: 'claude-3-opus',
74
+ fn: async () => myCustomCall(),
75
+ extractUsage: (res) => ({ prompt_tokens: 10, completion_tokens: 20, total_tokens: 30 })
76
+ });
77
+ ```
78
+
79
+ ---
80
+
81
+ ## ๐Ÿ” Detailed Functionality
82
+
83
+ ### ๐Ÿ“ก Real-Time Kill Switch (The Heartbeat)
84
+ When `autoInit` is called, the SDK spawns a background poller that hits the Leap360 Governance API every **2 seconds**.
85
+ - **Operation**: If the API returns `SUSPENDED`, the SDK sets a global `isHalted` flag.
86
+ - **Enforcement**: Every wrapped LLM call checks this flag *before* execution. If true, it throws a `GOVERNANCE_HALT` error.
87
+ - **Heartbeat Recovery**: The moment a project is resumed in the dashboard, the 2s heartbeat detects the change and unblocks the SDK instantly.
88
+
89
+ ### ๐Ÿงช Global Prototype Patching
90
+ The SDK uses a sophisticated patching strategy to find AI libraries regardless of how they are imported:
91
+ 1. **Global Search**: Checks `globalThis` for `OpenAI` or `GoogleGenerativeAI`.
92
+ 2. **Dynamic ESM Import**: Uses robust `import()` logic to locate and wrap prototypes after modules have loaded in modern ESM environments.
93
+ 3. **Cross-Platform Storage**: Uses `node:async_hooks` in Node.js for thread-safe context and a browser-safe fallback for frontend apps.
94
+
95
+ ### ๐Ÿ“Š Automated Telemetry
96
+ Every trace captured by Leap360 includes:
97
+ - **Latency**: Precise millisecond timing of the round-trip.
98
+ - **Token Counting**: Automatic extraction of usage stats from OpenAI and Gemini response metadata.
99
+ - **Payload Capture**: Full request/response JSON (sanitized via backend policies).
100
+ - **Error Tracking**: Capture stack traces and error messages for failed AI calls.
101
+
102
+ ---
103
+
104
+ ## ๐Ÿ“– API Reference
105
+
106
+ ### `Leap360.autoInit(config: Leap360Config)`
107
+ | Option | Type | Description |
108
+ | :--- | :--- | :--- |
109
+ | `apiKey` | `string` | Your project-scoped Leap360 API Key. |
110
+ | `projectId` | `string` | The ID of the project in your dashboard. |
111
+ | `serviceName` | `string` | A label for this specific deployment/service. |
112
+ | `baseUrl` | `string` | (Optional) Custom governance API endpoint. |
113
+
114
+ ### `agent.run(fn)`
115
+ Wraps an async function in a context. Every LLM call triggered within the closure of `fn` will inherit the agent's properties.
116
+
117
+ ### `traceCall(options)`
118
+ Low-level wrapper for custom LLM interactions.
119
+ - `fn`: The async function to execute.
120
+ - `extractUsage`: A callback to parse tokens from the result.
121
+ - `metadata`: Any custom JSON to attach to the trace.
122
+
123
+ ---
124
+
125
+ ## ๐Ÿ›ก๏ธ Errors & Handling
126
+
127
+ When the Kill Switch is active, the SDK throws a standard Error:
128
+ ```javascript
129
+ Error: [Leap360] GOVERNANCE_HALT: AI interactions are suspended for this project.
130
+ ```
131
+ You should wrap your LLM calls in `try/catch` and handle this specific error to provide a fallback UX to your users.
132
+
133
+ ---
134
+
135
+ ## ๐Ÿ”’ Security & Privacy
136
+ - **Sanitization**: Sensitive data can be filtered at the SDK level (using `metadata` overrides) or via Backend Policies in the Leap360 dashboard.
137
+ - **No-Proxy Architecture**: Unlike other tools, Leap360 does **not** proxy your traffic through our servers. Your API keys and data transit directly to the provider; we only receive metadata/telemetry out-of-band.
138
+
139
+ ---
140
+ ยฉ 2026 Leap360. Automated AI Governance for the Agentic Era.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "leap360",
3
- "version": "1.1.4",
3
+ "version": "1.1.5",
4
4
  "description": "Leap360 AI Governance SDK โ€” monitor, trace, and govern your AI agents in real-time",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -12,7 +12,7 @@
12
12
  }
13
13
  },
14
14
  "bin": {
15
- "leap360": "./dist/cli.js"
15
+ "leap360": "dist/cli.js"
16
16
  },
17
17
  "scripts": {
18
18
  "build": "tsc && node scripts/make-executable.js",