@lockllm/sdk 1.1.0 → 1.3.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/CHANGELOG.md +156 -2
- package/README.md +74 -18
- package/dist/errors.d.ts +11 -1
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +29 -1
- package/dist/errors.js.map +1 -1
- package/dist/errors.mjs +27 -0
- package/dist/index.d.ts +4 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/scan.d.ts.map +1 -1
- package/dist/scan.js +12 -0
- package/dist/scan.js.map +1 -1
- package/dist/scan.mjs +12 -0
- package/dist/types/common.d.ts +46 -1
- package/dist/types/common.d.ts.map +1 -1
- package/dist/types/errors.d.ts +6 -0
- package/dist/types/errors.d.ts.map +1 -1
- package/dist/types/scan.d.ts +37 -0
- package/dist/types/scan.d.ts.map +1 -1
- package/dist/utils/proxy-headers.d.ts +1 -1
- package/dist/utils/proxy-headers.d.ts.map +1 -1
- package/dist/utils/proxy-headers.js +80 -2
- package/dist/utils/proxy-headers.js.map +1 -1
- package/dist/utils/proxy-headers.mjs +80 -2
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,159 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [1.3.0] - 2026-02-27
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
|
|
7
|
+
#### Prompt Compression
|
|
8
|
+
Reduce token usage and costs by compressing prompts before sending them to AI providers. Three compression methods are available:
|
|
9
|
+
|
|
10
|
+
- **`toon`** (Free) - Converts JSON data to a compact notation format, achieving 30-60% token savings on structured data. Only activates when the prompt starts with `{` or `[` (pure JSON). Non-JSON input is returned unchanged.
|
|
11
|
+
- **`compact`** ($0.0001/use) - Advanced compression that intelligently reduces prompt length while preserving meaning. Works on any text type. Supports configurable compression rate (0.3-0.7, default 0.5).
|
|
12
|
+
- **`combined`** ($0.0001/use) - Applies TOON first, then runs Compact on the result for maximum token reduction. For non-JSON input, behaves identically to `compact`. Best when you want maximum compression.
|
|
13
|
+
|
|
14
|
+
Prompt compression is opt-in and disabled by default. Security scanning always runs on the original text before compression is applied.
|
|
15
|
+
|
|
16
|
+
**Proxy mode:**
|
|
17
|
+
```typescript
|
|
18
|
+
// TOON - compress structured JSON prompts (free)
|
|
19
|
+
const openai = createOpenAI({
|
|
20
|
+
apiKey: process.env.LOCKLLM_API_KEY,
|
|
21
|
+
proxyOptions: {
|
|
22
|
+
compressionAction: 'toon'
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
// Compact - compress any text with configurable rate
|
|
27
|
+
const openai2 = createOpenAI({
|
|
28
|
+
apiKey: process.env.LOCKLLM_API_KEY,
|
|
29
|
+
proxyOptions: {
|
|
30
|
+
compressionAction: 'compact',
|
|
31
|
+
compressionRate: 0.4 // Lower = more aggressive compression (0.3-0.7, default: 0.5)
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
// Combined - TOON then Compact for maximum compression
|
|
36
|
+
const openai3 = createOpenAI({
|
|
37
|
+
apiKey: process.env.LOCKLLM_API_KEY,
|
|
38
|
+
proxyOptions: {
|
|
39
|
+
compressionAction: 'combined',
|
|
40
|
+
compressionRate: 0.5
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
**Scan API:**
|
|
46
|
+
```typescript
|
|
47
|
+
const result = await lockllm.scan(
|
|
48
|
+
{ input: '{"users": [{"name": "Alice"}, {"name": "Bob"}]}' },
|
|
49
|
+
{ compressionAction: 'combined', compressionRate: 0.5 }
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
if (result.compression_result) {
|
|
53
|
+
console.log(result.compression_result.method); // 'combined'
|
|
54
|
+
console.log(result.compression_result.compressed_input); // Compressed text
|
|
55
|
+
console.log(result.compression_result.compression_ratio); // e.g., 0.35
|
|
56
|
+
}
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
#### Compression Response Metadata
|
|
60
|
+
Proxy responses now include compression metadata in response headers:
|
|
61
|
+
- `X-LockLLM-Compression-Method` - Compression method used (`toon`, `compact`, or `combined`)
|
|
62
|
+
- `X-LockLLM-Compression-Applied` - Whether compression was applied (`true` or `false`)
|
|
63
|
+
- `X-LockLLM-Compression-Ratio` - Ratio of compressed to original length (lower = better)
|
|
64
|
+
|
|
65
|
+
Parse these with `parseProxyMetadata()`:
|
|
66
|
+
```typescript
|
|
67
|
+
const metadata = parseProxyMetadata(response.headers);
|
|
68
|
+
console.log(metadata.compression);
|
|
69
|
+
// { method: 'combined', applied: true, ratio: 0.35 }
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### Notes
|
|
73
|
+
- Prompt compression is opt-in. Existing integrations continue to work without changes.
|
|
74
|
+
- All new types (`CompressionAction`, `CompressionResult`) are fully exported for TypeScript users.
|
|
75
|
+
- Security scanning always runs on the original (uncompressed) text for maximum protection.
|
|
76
|
+
- TOON compression is free. Compact and Combined cost $0.0001 per request.
|
|
77
|
+
|
|
78
|
+
---
|
|
79
|
+
|
|
80
|
+
## [1.2.0] - 2026-02-21
|
|
81
|
+
|
|
82
|
+
### Added
|
|
83
|
+
|
|
84
|
+
#### PII Detection and Redaction
|
|
85
|
+
Protect sensitive personal information in prompts before they reach AI providers. When enabled, LockLLM detects emails, phone numbers, SSNs, credit card numbers, and other PII entities. Choose how to handle detected PII with the `piiAction` option:
|
|
86
|
+
|
|
87
|
+
- **`block`** - Reject requests containing PII entirely. Throws a `PIIDetectedError` with entity types and count.
|
|
88
|
+
- **`strip`** - Automatically redact PII from prompts before forwarding to the AI provider. The redacted text is available via `redacted_input` in the scan response.
|
|
89
|
+
- **`allow_with_warning`** - Allow requests through but include PII metadata in the response for logging.
|
|
90
|
+
|
|
91
|
+
PII detection is opt-in and disabled by default.
|
|
92
|
+
|
|
93
|
+
```typescript
|
|
94
|
+
// Block requests containing PII
|
|
95
|
+
const openai = createOpenAI({
|
|
96
|
+
apiKey: process.env.LOCKLLM_API_KEY,
|
|
97
|
+
proxyOptions: {
|
|
98
|
+
piiAction: 'strip' // Automatically redact PII before sending to AI
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
// Handle PII errors when using block mode
|
|
103
|
+
try {
|
|
104
|
+
await openai.chat.completions.create({ ... });
|
|
105
|
+
} catch (error) {
|
|
106
|
+
if (error instanceof PIIDetectedError) {
|
|
107
|
+
console.log(error.pii_details.entity_types); // ['email', 'phone_number']
|
|
108
|
+
console.log(error.pii_details.entity_count); // 3
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
#### Scan API PII Support
|
|
114
|
+
The scan endpoint now accepts a `piiAction` option alongside existing scan options:
|
|
115
|
+
|
|
116
|
+
```typescript
|
|
117
|
+
const result = await lockllm.scan(
|
|
118
|
+
{ input: 'My email is test@example.com' },
|
|
119
|
+
{ piiAction: 'block', scanAction: 'block' }
|
|
120
|
+
);
|
|
121
|
+
|
|
122
|
+
if (result.pii_result) {
|
|
123
|
+
console.log(result.pii_result.detected); // true
|
|
124
|
+
console.log(result.pii_result.entity_types); // ['email']
|
|
125
|
+
console.log(result.pii_result.entity_count); // 1
|
|
126
|
+
console.log(result.pii_result.redacted_input); // 'My email is [EMAIL]' (strip mode only)
|
|
127
|
+
}
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
#### Enhanced Proxy Response Metadata
|
|
131
|
+
Proxy responses now include additional fields for better observability:
|
|
132
|
+
|
|
133
|
+
- **PII detection metadata** - `pii_detected` object with detection status, entity types, count, and action taken
|
|
134
|
+
- **Blocked status** - `blocked` flag when a request was rejected by security checks
|
|
135
|
+
- **Sensitivity and label** - `sensitivity` level used and numeric `label` (0 = safe, 1 = unsafe)
|
|
136
|
+
- **Decoded detail fields** - `scan_detail`, `policy_detail`, and `abuse_detail` automatically decoded from base64 response headers
|
|
137
|
+
- **Extended routing metadata** - `estimated_original_cost`, `estimated_routed_cost`, `estimated_input_tokens`, `estimated_output_tokens`, and `routing_fee_reason`
|
|
138
|
+
|
|
139
|
+
#### Sensitivity Header Support
|
|
140
|
+
You can now set the detection sensitivity level via `proxyOptions` or `buildLockLLMHeaders`:
|
|
141
|
+
|
|
142
|
+
```typescript
|
|
143
|
+
const openai = createOpenAI({
|
|
144
|
+
apiKey: process.env.LOCKLLM_API_KEY,
|
|
145
|
+
proxyOptions: {
|
|
146
|
+
sensitivity: 'high' // 'low', 'medium', or 'high'
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
### Notes
|
|
152
|
+
- PII detection is opt-in. Existing integrations continue to work without changes.
|
|
153
|
+
- All new types (`PIIAction`, `PIIResult`, `PIIDetectedError`, `PIIDetectedErrorData`) are fully exported for TypeScript users.
|
|
154
|
+
|
|
155
|
+
---
|
|
156
|
+
|
|
3
157
|
## [1.1.0] - 2026-02-18
|
|
4
158
|
|
|
5
159
|
### Added
|
|
@@ -57,14 +211,14 @@ const openai = createOpenAI({
|
|
|
57
211
|
scanMode: 'combined',
|
|
58
212
|
scanAction: 'block',
|
|
59
213
|
policyAction: 'block',
|
|
60
|
-
routeAction: 'auto', // Enable
|
|
214
|
+
routeAction: 'auto', // Enable smart routing
|
|
61
215
|
cacheResponse: true, // Enable response caching
|
|
62
216
|
cacheTTL: 3600 // Cache for 1 hour
|
|
63
217
|
}
|
|
64
218
|
});
|
|
65
219
|
```
|
|
66
220
|
|
|
67
|
-
####
|
|
221
|
+
#### Smart Routing
|
|
68
222
|
Let LockLLM automatically select the best model for each request based on task type and complexity. Set `routeAction: 'auto'` to enable, or `routeAction: 'custom'` to use your own routing rules from the dashboard.
|
|
69
223
|
|
|
70
224
|
#### Response Caching
|
package/README.md
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
|
|
11
11
|
**All-in-One AI Security for LLM Applications**
|
|
12
12
|
|
|
13
|
-
*Keep control of your AI. Detect prompt injection, jailbreaks, and adversarial attacks in real-time across 17+ providers with zero code changes.*
|
|
13
|
+
*Keep control of your AI. Detect prompt injection, jailbreaks, PII leakage, and adversarial attacks in real-time across 17+ providers with zero code changes.*
|
|
14
14
|
|
|
15
15
|
[Quick Start](#quick-start) · [Documentation](https://www.lockllm.com/docs) · [Examples](#examples) · [Benchmarks](https://www.lockllm.com) · [API Reference](#api-reference)
|
|
16
16
|
|
|
@@ -81,7 +81,9 @@ LockLLM provides production-ready AI security that integrates seamlessly into yo
|
|
|
81
81
|
| **Custom Endpoints** | Configure custom URLs for any provider (self-hosted, Azure, private clouds) |
|
|
82
82
|
| **Custom Content Policies** | Define your own content rules in the dashboard and enforce them automatically across all providers |
|
|
83
83
|
| **AI Abuse Detection** | Detect bot-generated content, repetition attacks, and resource exhaustion from your end-users |
|
|
84
|
-
| **
|
|
84
|
+
| **Smart Routing** | Automatically select the optimal model for each request based on task type and complexity to save costs |
|
|
85
|
+
| **PII Detection & Redaction** | Detect and automatically redact emails, phone numbers, SSNs, credit cards, and other personal information before they reach AI providers |
|
|
86
|
+
| **Prompt Compression** | Reduce token usage with TOON (JSON-to-compact-notation, free), Compact (advanced compression, $0.0001/use), or Combined (TOON then Compact for maximum reduction, $0.0001/use) methods |
|
|
85
87
|
| **Response Caching** | Cache identical LLM responses to reduce costs and latency on repeated queries |
|
|
86
88
|
| **Enterprise Privacy** | Provider keys encrypted at rest, prompts never stored |
|
|
87
89
|
| **Production Ready** | Battle-tested with automatic retries, timeouts, and error handling |
|
|
@@ -406,6 +408,7 @@ import {
|
|
|
406
408
|
PromptInjectionError,
|
|
407
409
|
PolicyViolationError,
|
|
408
410
|
AbuseDetectedError,
|
|
411
|
+
PIIDetectedError,
|
|
409
412
|
InsufficientCreditsError,
|
|
410
413
|
AuthenticationError,
|
|
411
414
|
RateLimitError,
|
|
@@ -433,6 +436,11 @@ try {
|
|
|
433
436
|
console.log("Abuse detected:", error.abuse_details.abuse_types);
|
|
434
437
|
console.log("Confidence:", error.abuse_details.confidence);
|
|
435
438
|
|
|
439
|
+
} else if (error instanceof PIIDetectedError) {
|
|
440
|
+
// Personal information detected (when piiAction is 'block')
|
|
441
|
+
console.log("PII found:", error.pii_details.entity_types);
|
|
442
|
+
console.log("Entity count:", error.pii_details.entity_count);
|
|
443
|
+
|
|
436
444
|
} else if (error instanceof InsufficientCreditsError) {
|
|
437
445
|
// Not enough credits
|
|
438
446
|
console.log("Balance:", error.current_balance);
|
|
@@ -548,7 +556,7 @@ LockLLM Security Gateway
|
|
|
548
556
|
3. **Error Response** - Detailed error returned with threat classification and confidence scores
|
|
549
557
|
4. **Logging** - Incident automatically logged in [dashboard](https://www.lockllm.com/dashboard) for review and monitoring
|
|
550
558
|
|
|
551
|
-
###
|
|
559
|
+
### Privacy & Security
|
|
552
560
|
|
|
553
561
|
LockLLM is built with privacy and security as core principles. Your data stays yours.
|
|
554
562
|
|
|
@@ -617,6 +625,9 @@ interface ScanOptions {
|
|
|
617
625
|
scanAction?: 'block' | 'allow_with_warning'; // Core injection behavior
|
|
618
626
|
policyAction?: 'block' | 'allow_with_warning'; // Custom policy behavior
|
|
619
627
|
abuseAction?: 'block' | 'allow_with_warning'; // Abuse detection (opt-in)
|
|
628
|
+
piiAction?: 'strip' | 'block' | 'allow_with_warning'; // PII detection (opt-in)
|
|
629
|
+
compressionAction?: 'toon' | 'compact' | 'combined'; // Prompt compression (opt-in)
|
|
630
|
+
compressionRate?: number; // Compact/combined compression rate (0.3-0.7)
|
|
620
631
|
}
|
|
621
632
|
```
|
|
622
633
|
|
|
@@ -649,8 +660,27 @@ interface ScanResponse {
|
|
|
649
660
|
scan_warning?: ScanWarning;
|
|
650
661
|
// Present when abuse detection is enabled and abuse found
|
|
651
662
|
abuse_warnings?: AbuseWarning;
|
|
652
|
-
// Present when
|
|
663
|
+
// Present when smart routing is enabled
|
|
653
664
|
routing?: { task_type: string; complexity: number; selected_model?: string; };
|
|
665
|
+
// Present when PII detection is enabled
|
|
666
|
+
pii_result?: PIIResult;
|
|
667
|
+
// Present when prompt compression is enabled
|
|
668
|
+
compression_result?: CompressionResult;
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
interface CompressionResult {
|
|
672
|
+
method: 'toon' | 'compact' | 'combined'; // Compression method used
|
|
673
|
+
compressed_input: string; // The compressed text
|
|
674
|
+
original_length: number; // Original text length
|
|
675
|
+
compressed_length: number; // Compressed text length
|
|
676
|
+
compression_ratio: number; // Ratio (compressed/original, lower = better)
|
|
677
|
+
}
|
|
678
|
+
|
|
679
|
+
interface PIIResult {
|
|
680
|
+
detected: boolean; // Whether PII was detected
|
|
681
|
+
entity_types: string[]; // Types of PII entities found (e.g., 'email', 'phone_number')
|
|
682
|
+
entity_count: number; // Number of PII entities found
|
|
683
|
+
redacted_input?: string; // Redacted text (only present when piiAction is 'strip')
|
|
654
684
|
}
|
|
655
685
|
```
|
|
656
686
|
|
|
@@ -676,7 +706,11 @@ interface GenericClientConfig {
|
|
|
676
706
|
scanAction?: 'block' | 'allow_with_warning';
|
|
677
707
|
policyAction?: 'block' | 'allow_with_warning';
|
|
678
708
|
abuseAction?: 'block' | 'allow_with_warning' | null;
|
|
709
|
+
piiAction?: 'strip' | 'block' | 'allow_with_warning' | null;
|
|
710
|
+
compressionAction?: 'toon' | 'compact' | 'combined' | null;
|
|
711
|
+
compressionRate?: number;
|
|
679
712
|
routeAction?: 'disabled' | 'auto' | 'custom';
|
|
713
|
+
sensitivity?: 'low' | 'medium' | 'high';
|
|
680
714
|
cacheResponse?: boolean;
|
|
681
715
|
cacheTTL?: number;
|
|
682
716
|
};
|
|
@@ -727,9 +761,11 @@ const headers = buildLockLLMHeaders({
|
|
|
727
761
|
scanAction: 'block',
|
|
728
762
|
policyAction: 'allow_with_warning',
|
|
729
763
|
abuseAction: 'block',
|
|
764
|
+
piiAction: 'strip',
|
|
765
|
+
compressionAction: 'toon',
|
|
730
766
|
routeAction: 'auto'
|
|
731
767
|
});
|
|
732
|
-
// Returns: { 'x-lockllm-scan-mode': 'combined', ... }
|
|
768
|
+
// Returns: { 'x-lockllm-scan-mode': 'combined', 'x-lockllm-compression': 'toon', ... }
|
|
733
769
|
```
|
|
734
770
|
|
|
735
771
|
**Parse proxy response metadata:**
|
|
@@ -743,6 +779,8 @@ console.log(metadata.safe); // true/false
|
|
|
743
779
|
console.log(metadata.scan_mode); // 'combined'
|
|
744
780
|
console.log(metadata.cache_status); // 'HIT' or 'MISS'
|
|
745
781
|
console.log(metadata.routing); // { task_type, complexity, selected_model, ... }
|
|
782
|
+
console.log(metadata.pii_detected); // { detected, entity_types, entity_count, action }
|
|
783
|
+
console.log(metadata.compression); // { method, applied, ratio }
|
|
746
784
|
```
|
|
747
785
|
|
|
748
786
|
## Error Types
|
|
@@ -758,6 +796,7 @@ LockLLMError (base)
|
|
|
758
796
|
├── PromptInjectionError (400)
|
|
759
797
|
├── PolicyViolationError (403)
|
|
760
798
|
├── AbuseDetectedError (400)
|
|
799
|
+
├── PIIDetectedError (403)
|
|
761
800
|
├── InsufficientCreditsError (402)
|
|
762
801
|
├── UpstreamError (502)
|
|
763
802
|
├── ConfigurationError (400)
|
|
@@ -803,6 +842,13 @@ class AbuseDetectedError extends LockLLMError {
|
|
|
803
842
|
};
|
|
804
843
|
}
|
|
805
844
|
|
|
845
|
+
class PIIDetectedError extends LockLLMError {
|
|
846
|
+
pii_details: {
|
|
847
|
+
entity_types: string[]; // PII types found (e.g., 'email', 'phone_number')
|
|
848
|
+
entity_count: number; // Number of PII entities detected
|
|
849
|
+
};
|
|
850
|
+
}
|
|
851
|
+
|
|
806
852
|
class InsufficientCreditsError extends LockLLMError {
|
|
807
853
|
current_balance: number; // Current credit balance
|
|
808
854
|
estimated_cost: number; // Estimated cost of the request
|
|
@@ -843,16 +889,16 @@ LockLLM uses a 10-tier progressive system based on monthly usage. Higher tiers u
|
|
|
843
889
|
|
|
844
890
|
| Tier | Max RPM | Monthly Spending Requirement |
|
|
845
891
|
|------|---------|----------------------------|
|
|
846
|
-
| **Tier 1** (Free) |
|
|
847
|
-
| **Tier 2** |
|
|
848
|
-
| **Tier 3** |
|
|
849
|
-
| **Tier 4** |
|
|
850
|
-
| **Tier 5** |
|
|
851
|
-
| **Tier 6** |
|
|
852
|
-
| **Tier 7** |
|
|
853
|
-
| **Tier 8** |
|
|
854
|
-
| **Tier 9** |
|
|
855
|
-
| **Tier 10** |
|
|
892
|
+
| **Tier 1** (Free) | 300 RPM | $0 |
|
|
893
|
+
| **Tier 2** | 500 RPM | $10/month |
|
|
894
|
+
| **Tier 3** | 1,000 RPM | $50/month |
|
|
895
|
+
| **Tier 4** | 2,000 RPM | $100/month |
|
|
896
|
+
| **Tier 5** | 5,000 RPM | $250/month |
|
|
897
|
+
| **Tier 6** | 10,000 RPM | $500/month |
|
|
898
|
+
| **Tier 7** | 20,000 RPM | $1,000/month |
|
|
899
|
+
| **Tier 8** | 50,000 RPM | $3,000/month |
|
|
900
|
+
| **Tier 9** | 100,000 RPM | $5,000/month |
|
|
901
|
+
| **Tier 10** | 200,000 RPM | $10,000/month |
|
|
856
902
|
|
|
857
903
|
See [pricing](https://www.lockllm.com/pricing) for full tier details and free monthly credits.
|
|
858
904
|
|
|
@@ -908,7 +954,9 @@ const result = await lockllm.scan(
|
|
|
908
954
|
{
|
|
909
955
|
scanAction: 'block', // Block core injection attacks
|
|
910
956
|
policyAction: 'allow_with_warning', // Allow but warn on policy violations
|
|
911
|
-
abuseAction: 'block'
|
|
957
|
+
abuseAction: 'block', // Enable abuse detection (opt-in)
|
|
958
|
+
piiAction: 'strip', // Redact PII from input (opt-in)
|
|
959
|
+
compressionAction: 'combined' // Compress prompts (opt-in: 'toon' | 'compact' | 'combined')
|
|
912
960
|
}
|
|
913
961
|
);
|
|
914
962
|
|
|
@@ -920,7 +968,10 @@ const openai = createOpenAI({
|
|
|
920
968
|
scanAction: 'block', // Block injection attacks
|
|
921
969
|
policyAction: 'block', // Block policy violations
|
|
922
970
|
abuseAction: 'allow_with_warning', // Detect abuse, don't block
|
|
923
|
-
|
|
971
|
+
piiAction: 'strip', // Automatically redact PII
|
|
972
|
+
compressionAction: 'compact', // Compress prompts (free: 'toon', paid: 'compact' | 'combined')
|
|
973
|
+
compressionRate: 0.5, // Compression rate 0.3-0.7 (compact/combined only)
|
|
974
|
+
routeAction: 'auto' // Enable smart routing
|
|
924
975
|
}
|
|
925
976
|
});
|
|
926
977
|
```
|
|
@@ -939,13 +990,18 @@ const openai = createOpenAI({
|
|
|
939
990
|
- `scanAction` - Controls core injection detection: `'block'` | `'allow_with_warning'`
|
|
940
991
|
- `policyAction` - Controls custom policy violations: `'block'` | `'allow_with_warning'`
|
|
941
992
|
- `abuseAction` - Controls abuse detection (opt-in): `'block'` | `'allow_with_warning'` | `null`
|
|
942
|
-
- `
|
|
993
|
+
- `piiAction` - Controls PII detection (opt-in): `'strip'` | `'block'` | `'allow_with_warning'` | `null`
|
|
994
|
+
- `compressionAction` - Controls prompt compression (opt-in): `'toon'` | `'compact'` | `'combined'` | `null`
|
|
995
|
+
- `compressionRate` - Compression rate for compact/combined method: `0.3` - `0.7` (default: `0.5`)
|
|
996
|
+
- `routeAction` - Controls smart routing: `'disabled'` | `'auto'` | `'custom'`
|
|
943
997
|
|
|
944
998
|
**Default Behavior (no headers):**
|
|
945
999
|
- Scan Mode: `combined` (check both core + policies)
|
|
946
1000
|
- Scan Action: `allow_with_warning` (detect but don't block)
|
|
947
1001
|
- Policy Action: `allow_with_warning` (detect but don't block)
|
|
948
1002
|
- Abuse Action: `null` (disabled, opt-in only)
|
|
1003
|
+
- PII Action: `null` (disabled, opt-in only)
|
|
1004
|
+
- Compression Action: `null` (disabled, opt-in only)
|
|
949
1005
|
- Route Action: `disabled` (no routing)
|
|
950
1006
|
|
|
951
1007
|
See [examples/advanced-options.ts](examples/advanced-options.ts) for complete examples.
|
package/dist/errors.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Custom error classes for LockLLM SDK
|
|
3
3
|
*/
|
|
4
|
-
import type { ScanResult, LockLLMErrorData, PromptInjectionErrorData, PolicyViolationErrorData, AbuseDetectedErrorData, InsufficientCreditsErrorData } from './types/errors';
|
|
4
|
+
import type { ScanResult, LockLLMErrorData, PromptInjectionErrorData, PolicyViolationErrorData, AbuseDetectedErrorData, InsufficientCreditsErrorData, PIIDetectedErrorData } from './types/errors';
|
|
5
5
|
/**
|
|
6
6
|
* Base error class for all LockLLM errors
|
|
7
7
|
*/
|
|
@@ -83,6 +83,16 @@ export declare class AbuseDetectedError extends LockLLMError {
|
|
|
83
83
|
};
|
|
84
84
|
constructor(data: AbuseDetectedErrorData);
|
|
85
85
|
}
|
|
86
|
+
/**
|
|
87
|
+
* Error thrown when PII (personal information) is detected and action is block
|
|
88
|
+
*/
|
|
89
|
+
export declare class PIIDetectedError extends LockLLMError {
|
|
90
|
+
readonly pii_details: {
|
|
91
|
+
entity_types: string[];
|
|
92
|
+
entity_count: number;
|
|
93
|
+
};
|
|
94
|
+
constructor(data: PIIDetectedErrorData);
|
|
95
|
+
}
|
|
86
96
|
/**
|
|
87
97
|
* Error thrown when user has insufficient credits
|
|
88
98
|
*/
|
package/dist/errors.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EACV,UAAU,EACV,gBAAgB,EAChB,wBAAwB,EACxB,wBAAwB,EACxB,sBAAsB,EACtB,4BAA4B,
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EACV,UAAU,EACV,gBAAgB,EAChB,wBAAwB,EACxB,wBAAwB,EACxB,sBAAsB,EACtB,4BAA4B,EAC5B,oBAAoB,EACrB,MAAM,gBAAgB,CAAC;AAEx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AAE,GAAG,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,YAAY,CA0H1E"}
|
package/dist/errors.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Custom error classes for LockLLM SDK
|
|
4
4
|
*/
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.NetworkError = exports.InsufficientCreditsError = exports.AbuseDetectedError = exports.PolicyViolationError = exports.ConfigurationError = exports.UpstreamError = exports.PromptInjectionError = exports.RateLimitError = exports.AuthenticationError = exports.LockLLMError = void 0;
|
|
6
|
+
exports.NetworkError = exports.InsufficientCreditsError = exports.PIIDetectedError = exports.AbuseDetectedError = exports.PolicyViolationError = exports.ConfigurationError = exports.UpstreamError = exports.PromptInjectionError = exports.RateLimitError = exports.AuthenticationError = exports.LockLLMError = void 0;
|
|
7
7
|
exports.parseError = parseError;
|
|
8
8
|
/**
|
|
9
9
|
* Base error class for all LockLLM errors
|
|
@@ -140,6 +140,23 @@ class AbuseDetectedError extends LockLLMError {
|
|
|
140
140
|
}
|
|
141
141
|
}
|
|
142
142
|
exports.AbuseDetectedError = AbuseDetectedError;
|
|
143
|
+
/**
|
|
144
|
+
* Error thrown when PII (personal information) is detected and action is block
|
|
145
|
+
*/
|
|
146
|
+
class PIIDetectedError extends LockLLMError {
|
|
147
|
+
constructor(data) {
|
|
148
|
+
super({
|
|
149
|
+
message: data.message,
|
|
150
|
+
type: 'lockllm_pii_error',
|
|
151
|
+
code: 'pii_detected',
|
|
152
|
+
status: 403,
|
|
153
|
+
requestId: data.requestId,
|
|
154
|
+
});
|
|
155
|
+
this.name = 'PIIDetectedError';
|
|
156
|
+
this.pii_details = data.pii_details;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
exports.PIIDetectedError = PIIDetectedError;
|
|
143
160
|
/**
|
|
144
161
|
* Error thrown when user has insufficient credits
|
|
145
162
|
*/
|
|
@@ -209,6 +226,17 @@ function parseError(response, requestId) {
|
|
|
209
226
|
violated_policies: error.violated_policies,
|
|
210
227
|
});
|
|
211
228
|
}
|
|
229
|
+
// PII detected error
|
|
230
|
+
if (error.code === 'pii_detected' && error.pii_details) {
|
|
231
|
+
return new PIIDetectedError({
|
|
232
|
+
message: error.message,
|
|
233
|
+
type: error.type,
|
|
234
|
+
code: error.code,
|
|
235
|
+
status: 403,
|
|
236
|
+
requestId: error.request_id || requestId,
|
|
237
|
+
pii_details: error.pii_details,
|
|
238
|
+
});
|
|
239
|
+
}
|
|
212
240
|
// Abuse detected error
|
|
213
241
|
if (error.code === 'abuse_detected' && error.abuse_details) {
|
|
214
242
|
return new AbuseDetectedError({
|
package/dist/errors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;GAEG;
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AAYH;;GAEG;AACH,MAAM,OAAO,YAAa,SAAQ,KAAK;IAMrC,YAAY,IAAsB;QAChC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACpB,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC;QAC3B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC;QACtB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC;QACtB,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;QAC1B,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC;QAEhC,qFAAqF;QACrF,IAAI,KAAK,CAAC,iBAAiB,EAAE,CAAC;YAC5B,KAAK,CAAC,iBAAiB,CAAC,IAAI,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC;QAClD,CAAC;IACH,CAAC;CACF;AAED;;GAEG;AACH,MAAM,OAAO,mBAAoB,SAAQ,YAAY;IACnD,YAAY,OAAe,EAAE,SAAk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C,KAAK,CAAC,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,CAAC,CAAC;IAC3E,CAAC;IAED,yBAAyB;IACzB,IACE,KAAK,CAAC,IAAI,KAAK,YAAY;QAC3B,KAAK,CAAC,IAAI,KAAK,sBAAsB;QACrC,KAAK,CAAC,IAAI,KAAK,qBAAqB;QACpC,KAAK,CAAC,IAAI,KAAK,mCAAmC,EAClD,CAAC;QACD,OAAO,IAAI,wBAAwB,CAAC;YAClC,OAAO,EAAE,KAAK,CAAC,OAAO;YACtB,IAAI,EAAE,KAAK,CAAC,IAAI;YAChB,IAAI,EAAE,KAAK,CAAC,IAAI;YAChB,MAAM,EAAE,GAAG;YACX,SAAS,EAAE,KAAK,CAAC,UAAU,IAAI,SAAS;YACxC,eAAe,EAAE,KAAK,CAAC,eAAe,IAAI,CAAC;YAC3C,cAAc,EAAE,KAAK,CAAC,cAAc,IAAI,CAAC;SAC1C,CAAC,CAAC;IACL,CAAC;IAED,sBAAsB;IACtB,IACE,KAAK,CAAC,IAAI,KAAK,qBAAqB;QACpC,KAAK,CAAC,IAAI,KAAK,sBAAsB;QACrC,KAAK,CAAC,IAAI,KAAK,iBAAiB;QAChC,KAAK,CAAC,IAAI,KAAK,aAAa,EAC5B,CAAC;QACD,OAAO,IAAI,kBAAkB,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IAC/C,CAAC;IAED,gBAAgB;IAChB,OAAO,IAAI,YAAY,CAAC;QACtB,OAAO,EAAE,KAAK,CAAC,OAAO,IAAI,mBAAmB;QAC7C,IAAI,EAAE,KAAK,CAAC,IAAI,IAAI,eAAe;QACnC,IAAI,EAAE,KAAK,CAAC,IAAI;QAChB,SAAS;KACV,CAAC,CAAC;AACL,CAAC"}
|
package/dist/errors.mjs
CHANGED
|
@@ -128,6 +128,22 @@ export class AbuseDetectedError extends LockLLMError {
|
|
|
128
128
|
this.abuse_details = data.abuse_details;
|
|
129
129
|
}
|
|
130
130
|
}
|
|
131
|
+
/**
|
|
132
|
+
* Error thrown when PII (personal information) is detected and action is block
|
|
133
|
+
*/
|
|
134
|
+
export class PIIDetectedError extends LockLLMError {
|
|
135
|
+
constructor(data) {
|
|
136
|
+
super({
|
|
137
|
+
message: data.message,
|
|
138
|
+
type: 'lockllm_pii_error',
|
|
139
|
+
code: 'pii_detected',
|
|
140
|
+
status: 403,
|
|
141
|
+
requestId: data.requestId,
|
|
142
|
+
});
|
|
143
|
+
this.name = 'PIIDetectedError';
|
|
144
|
+
this.pii_details = data.pii_details;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
131
147
|
/**
|
|
132
148
|
* Error thrown when user has insufficient credits
|
|
133
149
|
*/
|
|
@@ -195,6 +211,17 @@ export function parseError(response, requestId) {
|
|
|
195
211
|
violated_policies: error.violated_policies,
|
|
196
212
|
});
|
|
197
213
|
}
|
|
214
|
+
// PII detected error
|
|
215
|
+
if (error.code === 'pii_detected' && error.pii_details) {
|
|
216
|
+
return new PIIDetectedError({
|
|
217
|
+
message: error.message,
|
|
218
|
+
type: error.type,
|
|
219
|
+
code: error.code,
|
|
220
|
+
status: 403,
|
|
221
|
+
requestId: error.request_id || requestId,
|
|
222
|
+
pii_details: error.pii_details,
|
|
223
|
+
});
|
|
224
|
+
}
|
|
198
225
|
// Abuse detected error
|
|
199
226
|
if (error.code === 'abuse_detected' && error.abuse_details) {
|
|
200
227
|
return new AbuseDetectedError({
|
package/dist/index.d.ts
CHANGED
|
@@ -7,10 +7,10 @@
|
|
|
7
7
|
* @packageDocumentation
|
|
8
8
|
*/
|
|
9
9
|
export { LockLLM } from './client';
|
|
10
|
-
export { LockLLMError, AuthenticationError, RateLimitError, PromptInjectionError, PolicyViolationError, AbuseDetectedError, InsufficientCreditsError, UpstreamError, ConfigurationError, NetworkError, } from './errors';
|
|
11
|
-
export type { LockLLMConfig, RequestOptions, Provider, ScanMode, ScanAction, RouteAction, ProxyRequestOptions, ProxyResponseMetadata, } from './types/common';
|
|
12
|
-
export type { ScanRequest, ScanResponse, ScanOptions, Sensitivity, PolicyViolation, ScanWarning, AbuseWarning, } from './types/scan';
|
|
13
|
-
export type { ScanResult, LockLLMErrorData, PromptInjectionErrorData, PolicyViolationErrorData, AbuseDetectedErrorData, InsufficientCreditsErrorData, } from './types/errors';
|
|
10
|
+
export { LockLLMError, AuthenticationError, RateLimitError, PromptInjectionError, PolicyViolationError, AbuseDetectedError, PIIDetectedError, InsufficientCreditsError, UpstreamError, ConfigurationError, NetworkError, } from './errors';
|
|
11
|
+
export type { LockLLMConfig, RequestOptions, Provider, ScanMode, ScanAction, RouteAction, PIIAction, CompressionAction, ProxyRequestOptions, ProxyResponseMetadata, } from './types/common';
|
|
12
|
+
export type { ScanRequest, ScanResponse, ScanOptions, Sensitivity, PolicyViolation, ScanWarning, AbuseWarning, PIIResult, CompressionResult, } from './types/scan';
|
|
13
|
+
export type { ScanResult, LockLLMErrorData, PromptInjectionErrorData, PolicyViolationErrorData, AbuseDetectedErrorData, PIIDetectedErrorData, InsufficientCreditsErrorData, } from './types/errors';
|
|
14
14
|
export type { ProviderName } from './types/providers';
|
|
15
15
|
export { getProxyURL, getAllProxyURLs, getUniversalProxyURL } from './utils';
|
|
16
16
|
export { buildLockLLMHeaders, parseProxyMetadata, decodeDetailField } from './utils/proxy-headers';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAGnC,OAAO,EACL,YAAY,EACZ,mBAAmB,EACnB,cAAc,EACd,oBAAoB,EACpB,oBAAoB,EACpB,kBAAkB,EAClB,wBAAwB,EACxB,aAAa,EACb,kBAAkB,EAClB,YAAY,GACb,MAAM,UAAU,CAAC;AAGlB,YAAY,EACV,aAAa,EACb,cAAc,EACd,QAAQ,EACR,QAAQ,EACR,UAAU,EACV,WAAW,EACX,mBAAmB,EACnB,qBAAqB,GACtB,MAAM,gBAAgB,CAAC;AAExB,YAAY,EACV,WAAW,EACX,YAAY,EACZ,WAAW,EACX,WAAW,EACX,eAAe,EACf,WAAW,EACX,YAAY,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAGnC,OAAO,EACL,YAAY,EACZ,mBAAmB,EACnB,cAAc,EACd,oBAAoB,EACpB,oBAAoB,EACpB,kBAAkB,EAClB,gBAAgB,EAChB,wBAAwB,EACxB,aAAa,EACb,kBAAkB,EAClB,YAAY,GACb,MAAM,UAAU,CAAC;AAGlB,YAAY,EACV,aAAa,EACb,cAAc,EACd,QAAQ,EACR,QAAQ,EACR,UAAU,EACV,WAAW,EACX,SAAS,EACT,iBAAiB,EACjB,mBAAmB,EACnB,qBAAqB,GACtB,MAAM,gBAAgB,CAAC;AAExB,YAAY,EACV,WAAW,EACX,YAAY,EACZ,WAAW,EACX,WAAW,EACX,eAAe,EACf,WAAW,EACX,YAAY,EACZ,SAAS,EACT,iBAAiB,GAClB,MAAM,cAAc,CAAC;AAEtB,YAAY,EACV,UAAU,EACV,gBAAgB,EAChB,wBAAwB,EACxB,wBAAwB,EACxB,sBAAsB,EACtB,oBAAoB,EACpB,4BAA4B,GAC7B,MAAM,gBAAgB,CAAC;AAExB,YAAY,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAGtD,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAC7E,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAGnG,OAAO,EACL,YAAY,EACZ,eAAe,EACf,YAAY,EACZ,sBAAsB,EACtB,UAAU,EACV,cAAc,EACd,gBAAgB,EAChB,aAAa,EACb,gBAAgB,EAChB,cAAc,EACd,SAAS,EACT,eAAe,EACf,cAAc,EACd,iBAAiB,EACjB,YAAY,EACZ,YAAY,EACZ,WAAW,EACX,aAAa,EACb,cAAc,GACf,MAAM,YAAY,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* @packageDocumentation
|
|
9
9
|
*/
|
|
10
10
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
-
exports.createVertexAI = exports.createBedrock = exports.createAzure = exports.createCohere = exports.createGemini = exports.createHuggingFace = exports.createAnyscale = exports.createFireworks = exports.createXAI = exports.createTogether = exports.createOpenRouter = exports.createMistral = exports.createPerplexity = exports.createDeepSeek = exports.createGroq = exports.createOpenAICompatible = exports.createClient = exports.createAnthropic = exports.createOpenAI = exports.decodeDetailField = exports.parseProxyMetadata = exports.buildLockLLMHeaders = exports.getUniversalProxyURL = exports.getAllProxyURLs = exports.getProxyURL = exports.NetworkError = exports.ConfigurationError = exports.UpstreamError = exports.InsufficientCreditsError = exports.AbuseDetectedError = exports.PolicyViolationError = exports.PromptInjectionError = exports.RateLimitError = exports.AuthenticationError = exports.LockLLMError = exports.LockLLM = void 0;
|
|
11
|
+
exports.createVertexAI = exports.createBedrock = exports.createAzure = exports.createCohere = exports.createGemini = exports.createHuggingFace = exports.createAnyscale = exports.createFireworks = exports.createXAI = exports.createTogether = exports.createOpenRouter = exports.createMistral = exports.createPerplexity = exports.createDeepSeek = exports.createGroq = exports.createOpenAICompatible = exports.createClient = exports.createAnthropic = exports.createOpenAI = exports.decodeDetailField = exports.parseProxyMetadata = exports.buildLockLLMHeaders = exports.getUniversalProxyURL = exports.getAllProxyURLs = exports.getProxyURL = exports.NetworkError = exports.ConfigurationError = exports.UpstreamError = exports.InsufficientCreditsError = exports.PIIDetectedError = exports.AbuseDetectedError = exports.PolicyViolationError = exports.PromptInjectionError = exports.RateLimitError = exports.AuthenticationError = exports.LockLLMError = exports.LockLLM = void 0;
|
|
12
12
|
// Main client
|
|
13
13
|
var client_1 = require("./client");
|
|
14
14
|
Object.defineProperty(exports, "LockLLM", { enumerable: true, get: function () { return client_1.LockLLM; } });
|
|
@@ -20,6 +20,7 @@ Object.defineProperty(exports, "RateLimitError", { enumerable: true, get: functi
|
|
|
20
20
|
Object.defineProperty(exports, "PromptInjectionError", { enumerable: true, get: function () { return errors_1.PromptInjectionError; } });
|
|
21
21
|
Object.defineProperty(exports, "PolicyViolationError", { enumerable: true, get: function () { return errors_1.PolicyViolationError; } });
|
|
22
22
|
Object.defineProperty(exports, "AbuseDetectedError", { enumerable: true, get: function () { return errors_1.AbuseDetectedError; } });
|
|
23
|
+
Object.defineProperty(exports, "PIIDetectedError", { enumerable: true, get: function () { return errors_1.PIIDetectedError; } });
|
|
23
24
|
Object.defineProperty(exports, "InsufficientCreditsError", { enumerable: true, get: function () { return errors_1.InsufficientCreditsError; } });
|
|
24
25
|
Object.defineProperty(exports, "UpstreamError", { enumerable: true, get: function () { return errors_1.UpstreamError; } });
|
|
25
26
|
Object.defineProperty(exports, "ConfigurationError", { enumerable: true, get: function () { return errors_1.ConfigurationError; } });
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,cAAc;AACd,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAEnC,gBAAgB;AAChB,OAAO,EACL,YAAY,EACZ,mBAAmB,EACnB,cAAc,EACd,oBAAoB,EACpB,oBAAoB,EACpB,kBAAkB,EAClB,wBAAwB,EACxB,aAAa,EACb,kBAAkB,EAClB,YAAY,GACb,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,cAAc;AACd,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAEnC,gBAAgB;AAChB,OAAO,EACL,YAAY,EACZ,mBAAmB,EACnB,cAAc,EACd,oBAAoB,EACpB,oBAAoB,EACpB,kBAAkB,EAClB,gBAAgB,EAChB,wBAAwB,EACxB,aAAa,EACb,kBAAkB,EAClB,YAAY,GACb,MAAM,UAAU,CAAC;AAwClB,YAAY;AACZ,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAC7E,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAEnG,yCAAyC;AACzC,OAAO,EACL,YAAY,EACZ,eAAe,EACf,YAAY,EACZ,sBAAsB,EACtB,UAAU,EACV,cAAc,EACd,gBAAgB,EAChB,aAAa,EACb,gBAAgB,EAChB,cAAc,EACd,SAAS,EACT,eAAe,EACf,cAAc,EACd,iBAAiB,EACjB,YAAY,EACZ,YAAY,EACZ,WAAW,EACX,aAAa,EACb,cAAc,GACf,MAAM,YAAY,CAAC"}
|
package/dist/index.mjs
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
// Main client
|
|
10
10
|
export { LockLLM } from './client';
|
|
11
11
|
// Error classes
|
|
12
|
-
export { LockLLMError, AuthenticationError, RateLimitError, PromptInjectionError, PolicyViolationError, AbuseDetectedError, InsufficientCreditsError, UpstreamError, ConfigurationError, NetworkError, } from './errors';
|
|
12
|
+
export { LockLLMError, AuthenticationError, RateLimitError, PromptInjectionError, PolicyViolationError, AbuseDetectedError, PIIDetectedError, InsufficientCreditsError, UpstreamError, ConfigurationError, NetworkError, } from './errors';
|
|
13
13
|
// Utilities
|
|
14
14
|
export { getProxyURL, getAllProxyURLs, getUniversalProxyURL } from './utils';
|
|
15
15
|
export { buildLockLLMHeaders, parseProxyMetadata, decodeDetailField } from './utils/proxy-headers';
|
package/dist/scan.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scan.d.ts","sourceRoot":"","sources":["../src/scan.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAG3E,qBAAa,UAAU;IACrB,OAAO,CAAC,IAAI,CAAa;gBAEb,IAAI,EAAE,UAAU;IAI5B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAmCG;IACG,IAAI,CACR,OAAO,EAAE,WAAW,EACpB,OAAO,CAAC,EAAE,WAAW,GACpB,OAAO,CAAC,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"scan.d.ts","sourceRoot":"","sources":["../src/scan.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAG3E,qBAAa,UAAU;IACrB,OAAO,CAAC,IAAI,CAAa;gBAEb,IAAI,EAAE,UAAU;IAI5B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAmCG;IACG,IAAI,CACR,OAAO,EAAE,WAAW,EACpB,OAAO,CAAC,EAAE,WAAW,GACpB,OAAO,CAAC,YAAY,CAAC;CAqEzB"}
|
package/dist/scan.js
CHANGED
|
@@ -74,6 +74,18 @@ class ScanClient {
|
|
|
74
74
|
if (options?.abuseAction !== undefined && options?.abuseAction !== null) {
|
|
75
75
|
headers['x-lockllm-abuse-action'] = options.abuseAction;
|
|
76
76
|
}
|
|
77
|
+
// PII action: opt-in PII detection (null/undefined means disabled)
|
|
78
|
+
if (options?.piiAction !== undefined && options?.piiAction !== null) {
|
|
79
|
+
headers['x-lockllm-pii-action'] = options.piiAction;
|
|
80
|
+
}
|
|
81
|
+
// Compression action: opt-in prompt compression (null/undefined means disabled)
|
|
82
|
+
if (options?.compressionAction !== undefined && options?.compressionAction !== null) {
|
|
83
|
+
headers['x-lockllm-compression'] = options.compressionAction;
|
|
84
|
+
}
|
|
85
|
+
// Compression rate for compact method
|
|
86
|
+
if (options?.compressionRate !== undefined) {
|
|
87
|
+
headers['x-lockllm-compression-rate'] = String(options.compressionRate);
|
|
88
|
+
}
|
|
77
89
|
// Build request body
|
|
78
90
|
const body = {
|
|
79
91
|
input: request.input,
|
package/dist/scan.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scan.js","sourceRoot":"","sources":["../src/scan.ts"],"names":[],"mappings":"AAAA;;GAEG;AAMH,MAAM,OAAO,UAAU;IAGrB,YAAY,IAAgB;QAC1B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAmCG;IACH,KAAK,CAAC,IAAI,CACR,OAAoB,EACpB,OAAqB;QAErB,kCAAkC;QAClC,MAAM,OAAO,GAA2B;YACtC,GAAG,CAAC,OAAO,EAAE,OAAO,IAAI,EAAE,CAAC;SAC5B,CAAC;QAEF,mBAAmB;QACnB,IAAI,OAAO,CAAC,IAAI,EAAE,CAAC;YACjB,OAAO,CAAC,qBAAqB,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;QAChD,CAAC;QAED,qBAAqB;QACrB,IAAI,OAAO,CAAC,WAAW,EAAE,CAAC;YACxB,OAAO,CAAC,uBAAuB,CAAC,GAAG,OAAO,CAAC,WAAW,CAAC;QACzD,CAAC;QAED,eAAe;QACf,IAAI,OAAO,CAAC,KAAK,KAAK,SAAS,EAAE,CAAC;YAChC,OAAO,CAAC,iBAAiB,CAAC,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC;QAChE,CAAC;QAED,iCAAiC;QACjC,0DAA0D;QAC1D,IAAI,OAAO,EAAE,UAAU,EAAE,CAAC;YACxB,OAAO,CAAC,uBAAuB,CAAC,GAAG,OAAO,CAA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Ae,CAAC,CAAC;QAC1E,CAAC;QAED,qBAAqB;QACrB,MAAM,IAAI,GAAwB;YAChC,KAAK,EAAE,OAAO,CAAC,KAAK;SACrB,CAAC;QAEF,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,IAAI,CACnC,UAAU,EACV,IAAI,EACJ;YACE,OAAO;YACP,OAAO,EAAE,OAAO,EAAE,OAAO;YACzB,MAAM,EAAE,OAAO,EAAE,MAAM;SACxB,CACF,CAAC;QAEF,OAAO,IAAI,CAAC;IACd,CAAC;CACF"}
|
package/dist/scan.mjs
CHANGED
|
@@ -71,6 +71,18 @@ export class ScanClient {
|
|
|
71
71
|
if (options?.abuseAction !== undefined && options?.abuseAction !== null) {
|
|
72
72
|
headers['x-lockllm-abuse-action'] = options.abuseAction;
|
|
73
73
|
}
|
|
74
|
+
// PII action: opt-in PII detection (null/undefined means disabled)
|
|
75
|
+
if (options?.piiAction !== undefined && options?.piiAction !== null) {
|
|
76
|
+
headers['x-lockllm-pii-action'] = options.piiAction;
|
|
77
|
+
}
|
|
78
|
+
// Compression action: opt-in prompt compression (null/undefined means disabled)
|
|
79
|
+
if (options?.compressionAction !== undefined && options?.compressionAction !== null) {
|
|
80
|
+
headers['x-lockllm-compression'] = options.compressionAction;
|
|
81
|
+
}
|
|
82
|
+
// Compression rate for compact method
|
|
83
|
+
if (options?.compressionRate !== undefined) {
|
|
84
|
+
headers['x-lockllm-compression-rate'] = String(options.compressionRate);
|
|
85
|
+
}
|
|
74
86
|
// Build request body
|
|
75
87
|
const body = {
|
|
76
88
|
input: request.input,
|
package/dist/types/common.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Common types used throughout the SDK
|
|
3
3
|
*/
|
|
4
|
+
import type { Sensitivity } from './scan';
|
|
4
5
|
export interface LockLLMConfig {
|
|
5
6
|
/** Your LockLLM API key */
|
|
6
7
|
apiKey: string;
|
|
@@ -34,6 +35,10 @@ export type ScanMode = 'normal' | 'policy_only' | 'combined';
|
|
|
34
35
|
export type ScanAction = 'block' | 'allow_with_warning';
|
|
35
36
|
/** Routing action for intelligent model selection */
|
|
36
37
|
export type RouteAction = 'disabled' | 'auto' | 'custom';
|
|
38
|
+
/** PII detection action (opt-in) */
|
|
39
|
+
export type PIIAction = 'strip' | 'block' | 'allow_with_warning';
|
|
40
|
+
/** Prompt compression method (opt-in) */
|
|
41
|
+
export type CompressionAction = 'toon' | 'compact' | 'combined';
|
|
37
42
|
/** Proxy request options with advanced headers */
|
|
38
43
|
export interface ProxyRequestOptions extends RequestOptions {
|
|
39
44
|
/** Scan mode (default: combined) - Check both core security and custom policies */
|
|
@@ -44,12 +49,22 @@ export interface ProxyRequestOptions extends RequestOptions {
|
|
|
44
49
|
policyAction?: ScanAction;
|
|
45
50
|
/** Abuse detection action (opt-in, default: null) - When null, abuse detection is disabled */
|
|
46
51
|
abuseAction?: ScanAction | null;
|
|
47
|
-
/** Routing action (default: disabled) - No
|
|
52
|
+
/** Routing action (default: disabled) - No smart routing unless explicitly enabled */
|
|
48
53
|
routeAction?: RouteAction;
|
|
54
|
+
/** PII detection action (opt-in, default: null) - When null, PII detection is disabled */
|
|
55
|
+
piiAction?: PIIAction | null;
|
|
56
|
+
/** Detection sensitivity level (default: medium) - Controls injection detection threshold */
|
|
57
|
+
sensitivity?: Sensitivity;
|
|
49
58
|
/** Response caching (default: enabled). Set false to disable. */
|
|
50
59
|
cacheResponse?: boolean;
|
|
51
60
|
/** Cache TTL in seconds (default: 3600) */
|
|
52
61
|
cacheTTL?: number;
|
|
62
|
+
/** Prompt compression method (opt-in, default: null) - When null, compression is disabled.
|
|
63
|
+
* "toon" converts JSON to compact notation (free). "compact" uses advanced compression ($0.0001/use).
|
|
64
|
+
* "combined" applies TOON first then Compact for maximum compression ($0.0001/use). */
|
|
65
|
+
compressionAction?: CompressionAction | null;
|
|
66
|
+
/** Compression rate for compact method (0.3-0.7, default: 0.5) - Lower = more compression */
|
|
67
|
+
compressionRate?: number;
|
|
53
68
|
}
|
|
54
69
|
/** Response metadata from proxy */
|
|
55
70
|
export interface ProxyResponseMetadata {
|
|
@@ -67,6 +82,12 @@ export interface ProxyResponseMetadata {
|
|
|
67
82
|
provider: string;
|
|
68
83
|
/** Model used */
|
|
69
84
|
model?: string;
|
|
85
|
+
/** Detection sensitivity level used */
|
|
86
|
+
sensitivity?: string;
|
|
87
|
+
/** Safety label (0 = safe, 1 = unsafe) */
|
|
88
|
+
label?: number;
|
|
89
|
+
/** Whether the request was blocked */
|
|
90
|
+
blocked?: boolean;
|
|
70
91
|
/** Scan warning details */
|
|
71
92
|
scan_warning?: {
|
|
72
93
|
injection_score: number;
|
|
@@ -85,6 +106,13 @@ export interface ProxyResponseMetadata {
|
|
|
85
106
|
types: string;
|
|
86
107
|
detail: string;
|
|
87
108
|
};
|
|
109
|
+
/** PII detection metadata */
|
|
110
|
+
pii_detected?: {
|
|
111
|
+
detected: boolean;
|
|
112
|
+
entity_types: string;
|
|
113
|
+
entity_count: number;
|
|
114
|
+
action: string;
|
|
115
|
+
};
|
|
88
116
|
/** Routing metadata */
|
|
89
117
|
routing?: {
|
|
90
118
|
enabled: boolean;
|
|
@@ -95,6 +123,11 @@ export interface ProxyResponseMetadata {
|
|
|
95
123
|
original_provider: string;
|
|
96
124
|
original_model: string;
|
|
97
125
|
estimated_savings: number;
|
|
126
|
+
estimated_original_cost: number;
|
|
127
|
+
estimated_routed_cost: number;
|
|
128
|
+
estimated_input_tokens: number;
|
|
129
|
+
estimated_output_tokens: number;
|
|
130
|
+
routing_fee_reason: string;
|
|
98
131
|
};
|
|
99
132
|
/** Credits reserved for this request */
|
|
100
133
|
credits_reserved?: number;
|
|
@@ -112,5 +145,17 @@ export interface ProxyResponseMetadata {
|
|
|
112
145
|
tokens_saved?: number;
|
|
113
146
|
/** Cost saved from cache hit */
|
|
114
147
|
cost_saved?: number;
|
|
148
|
+
/** Decoded scan detail (from base64 header) */
|
|
149
|
+
scan_detail?: any;
|
|
150
|
+
/** Decoded policy warning detail (from base64 header) */
|
|
151
|
+
policy_detail?: any;
|
|
152
|
+
/** Decoded abuse detail (from base64 header) */
|
|
153
|
+
abuse_detail?: any;
|
|
154
|
+
/** Compression metadata */
|
|
155
|
+
compression?: {
|
|
156
|
+
method: string;
|
|
157
|
+
applied: boolean;
|
|
158
|
+
ratio: number;
|
|
159
|
+
};
|
|
115
160
|
}
|
|
116
161
|
//# sourceMappingURL=common.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../src/types/common.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,WAAW,aAAa;IAC5B,2BAA2B;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,kEAAkE;IAClE,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,uDAAuD;IACvD,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,uEAAuE;IACvE,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,cAAc;IAC7B,+CAA+C;IAC/C,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,sCAAsC;IACtC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,2CAA2C;IAC3C,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB;AAED,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE;QACL,OAAO,EAAE,MAAM,CAAC;QAChB,IAAI,EAAE,MAAM,CAAC;QACb,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;KACpB,CAAC;CACH;AAED,MAAM,MAAM,QAAQ,GAChB,QAAQ,GACR,WAAW,GACX,QAAQ,GACR,QAAQ,GACR,YAAY,GACZ,YAAY,GACZ,SAAS,GACT,MAAM,GACN,UAAU,GACV,UAAU,GACV,KAAK,GACL,WAAW,GACX,UAAU,GACV,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EAAE,MAAM,CAAC;KACf,CAAC;CACH"}
|
package/dist/types/errors.d.ts
CHANGED
|
@@ -52,4 +52,10 @@ export interface InsufficientCreditsErrorData extends LockLLMErrorData {
|
|
|
52
52
|
current_balance: number;
|
|
53
53
|
estimated_cost: number;
|
|
54
54
|
}
|
|
55
|
+
export interface PIIDetectedErrorData extends LockLLMErrorData {
|
|
56
|
+
pii_details: {
|
|
57
|
+
entity_types: string[];
|
|
58
|
+
entity_count: number;
|
|
59
|
+
};
|
|
60
|
+
}
|
|
55
61
|
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/types/errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,OAAO,CAAC;IACd,KAAK,EAAE,CAAC,GAAG,CAAC,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,KAAK,GAAG,QAAQ,GAAG,MAAM,CAAC;CACxC;AAED,MAAM,WAAW,gBAAgB;IAC/B,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB;AAED,MAAM,WAAW,wBAAyB,SAAQ,gBAAgB;IAChE,UAAU,EAAE,UAAU,CAAC;CACxB;AAED,MAAM,WAAW,wBAAyB,SAAQ,gBAAgB;IAChE,iBAAiB,EAAE,KAAK,CAAC;QACvB,WAAW,EAAE,MAAM,CAAC;QACpB,mBAAmB,EAAE,KAAK,CAAC;YAAE,IAAI,EAAE,MAAM,CAAA;SAAE,CAAC,CAAC;QAC7C,iBAAiB,CAAC,EAAE,MAAM,CAA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1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Scan API types
|
|
3
3
|
*/
|
|
4
|
+
import type { PIIAction, CompressionAction } from './common';
|
|
4
5
|
export type Sensitivity = 'low' | 'medium' | 'high';
|
|
5
6
|
/** Scan mode determines which security checks are performed */
|
|
6
7
|
export type ScanMode = 'normal' | 'policy_only' | 'combined';
|
|
@@ -16,6 +17,30 @@ export interface ScanRequest {
|
|
|
16
17
|
/** Force chunking for large inputs */
|
|
17
18
|
chunk?: boolean;
|
|
18
19
|
}
|
|
20
|
+
/** Compression result */
|
|
21
|
+
export interface CompressionResult {
|
|
22
|
+
/** Compression method used */
|
|
23
|
+
method: 'toon' | 'compact' | 'combined';
|
|
24
|
+
/** Compressed text */
|
|
25
|
+
compressed_input: string;
|
|
26
|
+
/** Original text length */
|
|
27
|
+
original_length: number;
|
|
28
|
+
/** Compressed text length */
|
|
29
|
+
compressed_length: number;
|
|
30
|
+
/** Compression ratio (compressed/original, lower = better) */
|
|
31
|
+
compression_ratio: number;
|
|
32
|
+
}
|
|
33
|
+
/** PII detection result */
|
|
34
|
+
export interface PIIResult {
|
|
35
|
+
/** Whether PII was detected */
|
|
36
|
+
detected: boolean;
|
|
37
|
+
/** Types of PII entities found (user-friendly names) */
|
|
38
|
+
entity_types: string[];
|
|
39
|
+
/** Number of PII entities found */
|
|
40
|
+
entity_count: number;
|
|
41
|
+
/** Redacted input text (only present when piiAction is "strip") */
|
|
42
|
+
redacted_input?: string;
|
|
43
|
+
}
|
|
19
44
|
/** Scan request options with action headers */
|
|
20
45
|
export interface ScanOptions {
|
|
21
46
|
/** Scan action for core injection (default: allow_with_warning) - Threats detected but not blocked */
|
|
@@ -24,6 +49,14 @@ export interface ScanOptions {
|
|
|
24
49
|
policyAction?: ScanAction;
|
|
25
50
|
/** Abuse detection action (opt-in, default: null) - When null, abuse detection is disabled */
|
|
26
51
|
abuseAction?: ScanAction | null;
|
|
52
|
+
/** PII detection action (opt-in, default: null) - When null, PII detection is disabled */
|
|
53
|
+
piiAction?: PIIAction | null;
|
|
54
|
+
/** Prompt compression method (opt-in, default: null) - When null, compression is disabled.
|
|
55
|
+
* "toon" converts JSON to compact notation (free). "compact" uses advanced compression ($0.0001/use).
|
|
56
|
+
* "combined" applies TOON first then Compact for maximum compression ($0.0001/use). */
|
|
57
|
+
compressionAction?: CompressionAction | null;
|
|
58
|
+
/** Compression rate for compact method (0.3-0.7, default: 0.5) - Lower = more compression */
|
|
59
|
+
compressionRate?: number;
|
|
27
60
|
/** Custom headers to include in the request */
|
|
28
61
|
headers?: Record<string, string>;
|
|
29
62
|
/** Request timeout in milliseconds */
|
|
@@ -131,5 +164,9 @@ export interface ScanResponse {
|
|
|
131
164
|
/** Estimated cost */
|
|
132
165
|
estimated_cost?: number;
|
|
133
166
|
};
|
|
167
|
+
/** PII detection result (present when PII detection is enabled) */
|
|
168
|
+
pii_result?: PIIResult;
|
|
169
|
+
/** Compression result (present when compression is enabled) */
|
|
170
|
+
compression_result?: CompressionResult;
|
|
134
171
|
}
|
|
135
172
|
//# sourceMappingURL=scan.d.ts.map
|
package/dist/types/scan.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scan.d.ts","sourceRoot":"","sources":["../../src/types/scan.ts"],"names":[],"mappings":"AAAA;;GAEG;
|
|
1
|
+
{"version":3,"file":"scan.d.ts","sourceRoot":"","sources":["../../src/types/scan.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,KAAK,EAAE,SAAS,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAE7D,MAAM,MAAM,WAAW,GAAG,KAAK,GAAG,QAAQ,GAAG,MAAM,CAAC;AAEpD,+DAA+D;AAC/D,MAAM,MAAM,QAAQ,GAAG,QAAQ,GAAG,aAAa,GAAG,UAAU,CAAC;AAE7D,gEAAgE;AAChE,MAAM,MAAM,UAAU,GAAG,OAAO,GAAG,oBAAoB,CAAC;AAExD,MAAM,WAAW,WAAW;IAC1B,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with_warning (detect threats but don't block)
|
|
11
11
|
* - Policy Action: allow_with_warning (detect violations but don't block)
|
|
12
12
|
* - Abuse Action: null (abuse detection disabled, opt-in only)
|
|
13
|
-
* - Route Action: disabled (no
|
|
13
|
+
* - Route Action: disabled (no smart routing)
|
|
14
14
|
*/
|
|
15
15
|
export declare function buildLockLLMHeaders(options?: ProxyRequestOptions): Record<string, string>;
|
|
16
16
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"proxy-headers.d.ts","sourceRoot":"","sources":["../../src/utils/proxy-headers.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AAElF;;;;;;;;;GASG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,CAAC,EAAE,mBAAmB,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,
|
|
1
|
+
{"version":3,"file":"proxy-headers.d.ts","sourceRoot":"","sources":["../../src/utils/proxy-headers.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AAElF;;;;;;;;;GASG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,CAAC,EAAE,mBAAmB,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CA2DzF;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,qBAAqB,CAuMnG;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,GAAG,GAAG,CAOrD"}
|
|
@@ -14,7 +14,7 @@ exports.decodeDetailField = decodeDetailField;
|
|
|
14
14
|
* - Scan Action: allow_with_warning (detect threats but don't block)
|
|
15
15
|
* - Policy Action: allow_with_warning (detect violations but don't block)
|
|
16
16
|
* - Abuse Action: null (abuse detection disabled, opt-in only)
|
|
17
|
-
* - Route Action: disabled (no
|
|
17
|
+
* - Route Action: disabled (no smart routing)
|
|
18
18
|
*/
|
|
19
19
|
function buildLockLLMHeaders(options) {
|
|
20
20
|
const headers = {};
|
|
@@ -34,10 +34,18 @@ function buildLockLLMHeaders(options) {
|
|
|
34
34
|
if (options?.abuseAction !== undefined && options?.abuseAction !== null) {
|
|
35
35
|
headers['x-lockllm-abuse-action'] = options.abuseAction;
|
|
36
36
|
}
|
|
37
|
-
// Route action header (controls
|
|
37
|
+
// Route action header (controls smart routing)
|
|
38
38
|
if (options?.routeAction) {
|
|
39
39
|
headers['x-lockllm-route-action'] = options.routeAction;
|
|
40
40
|
}
|
|
41
|
+
// PII action header (opt-in, null means disabled)
|
|
42
|
+
if (options?.piiAction !== undefined && options?.piiAction !== null) {
|
|
43
|
+
headers['x-lockllm-pii-action'] = options.piiAction;
|
|
44
|
+
}
|
|
45
|
+
// Sensitivity header (controls injection detection threshold)
|
|
46
|
+
if (options?.sensitivity) {
|
|
47
|
+
headers['x-lockllm-sensitivity'] = options.sensitivity;
|
|
48
|
+
}
|
|
41
49
|
// Response caching control
|
|
42
50
|
if (options?.cacheResponse === false) {
|
|
43
51
|
headers['x-lockllm-cache-response'] = 'false';
|
|
@@ -46,6 +54,14 @@ function buildLockLLMHeaders(options) {
|
|
|
46
54
|
if (options?.cacheTTL !== undefined) {
|
|
47
55
|
headers['x-lockllm-cache-ttl'] = String(options.cacheTTL);
|
|
48
56
|
}
|
|
57
|
+
// Compression header (opt-in, null means disabled)
|
|
58
|
+
if (options?.compressionAction !== undefined && options?.compressionAction !== null) {
|
|
59
|
+
headers['x-lockllm-compression'] = options.compressionAction;
|
|
60
|
+
}
|
|
61
|
+
// Compression rate (compact method only, 0.3-0.7)
|
|
62
|
+
if (options?.compressionRate !== undefined) {
|
|
63
|
+
headers['x-lockllm-compression-rate'] = String(options.compressionRate);
|
|
64
|
+
}
|
|
49
65
|
return headers;
|
|
50
66
|
}
|
|
51
67
|
/**
|
|
@@ -67,6 +83,21 @@ function parseProxyMetadata(headers) {
|
|
|
67
83
|
provider: getHeader('x-lockllm-provider') || '',
|
|
68
84
|
model: getHeader('x-lockllm-model') || undefined,
|
|
69
85
|
};
|
|
86
|
+
// Parse sensitivity
|
|
87
|
+
const sensitivity = getHeader('x-lockllm-sensitivity');
|
|
88
|
+
if (sensitivity) {
|
|
89
|
+
metadata.sensitivity = sensitivity;
|
|
90
|
+
}
|
|
91
|
+
// Parse label
|
|
92
|
+
const label = getHeader('x-lockllm-label');
|
|
93
|
+
if (label) {
|
|
94
|
+
metadata.label = parseInt(label, 10);
|
|
95
|
+
}
|
|
96
|
+
// Parse blocked status
|
|
97
|
+
const blocked = getHeader('x-lockllm-blocked');
|
|
98
|
+
if (blocked === 'true') {
|
|
99
|
+
metadata.blocked = true;
|
|
100
|
+
}
|
|
70
101
|
// Parse scan warning
|
|
71
102
|
const scanWarning = getHeader('x-lockllm-scan-warning');
|
|
72
103
|
if (scanWarning === 'true') {
|
|
@@ -103,6 +134,19 @@ function parseProxyMetadata(headers) {
|
|
|
103
134
|
detail: detail || '',
|
|
104
135
|
};
|
|
105
136
|
}
|
|
137
|
+
// Parse PII detection
|
|
138
|
+
const piiDetected = getHeader('x-lockllm-pii-detected');
|
|
139
|
+
if (piiDetected) {
|
|
140
|
+
const piiTypes = getHeader('x-lockllm-pii-types');
|
|
141
|
+
const piiCount = getHeader('x-lockllm-pii-count');
|
|
142
|
+
const piiAction = getHeader('x-lockllm-pii-action');
|
|
143
|
+
metadata.pii_detected = {
|
|
144
|
+
detected: piiDetected === 'true',
|
|
145
|
+
entity_types: piiTypes || '',
|
|
146
|
+
entity_count: piiCount ? parseInt(piiCount, 10) : 0,
|
|
147
|
+
action: piiAction || '',
|
|
148
|
+
};
|
|
149
|
+
}
|
|
106
150
|
// Parse routing metadata
|
|
107
151
|
const routeEnabled = getHeader('x-lockllm-route-enabled');
|
|
108
152
|
if (routeEnabled === 'true') {
|
|
@@ -113,6 +157,11 @@ function parseProxyMetadata(headers) {
|
|
|
113
157
|
const originalProvider = getHeader('x-lockllm-original-provider');
|
|
114
158
|
const originalModel = getHeader('x-lockllm-original-model');
|
|
115
159
|
const estimatedSavings = getHeader('x-lockllm-estimated-savings');
|
|
160
|
+
const estimatedOriginalCost = getHeader('x-lockllm-estimated-original-cost');
|
|
161
|
+
const estimatedRoutedCost = getHeader('x-lockllm-estimated-routed-cost');
|
|
162
|
+
const estimatedInputTokens = getHeader('x-lockllm-estimated-input-tokens');
|
|
163
|
+
const estimatedOutputTokens = getHeader('x-lockllm-estimated-output-tokens');
|
|
164
|
+
const routingFeeReason = getHeader('x-lockllm-routing-fee-reason');
|
|
116
165
|
metadata.routing = {
|
|
117
166
|
enabled: true,
|
|
118
167
|
task_type: taskType || '',
|
|
@@ -122,6 +171,11 @@ function parseProxyMetadata(headers) {
|
|
|
122
171
|
original_provider: originalProvider || '',
|
|
123
172
|
original_model: originalModel || '',
|
|
124
173
|
estimated_savings: estimatedSavings ? parseFloat(estimatedSavings) : 0,
|
|
174
|
+
estimated_original_cost: estimatedOriginalCost ? parseFloat(estimatedOriginalCost) : 0,
|
|
175
|
+
estimated_routed_cost: estimatedRoutedCost ? parseFloat(estimatedRoutedCost) : 0,
|
|
176
|
+
estimated_input_tokens: estimatedInputTokens ? parseInt(estimatedInputTokens, 10) : 0,
|
|
177
|
+
estimated_output_tokens: estimatedOutputTokens ? parseInt(estimatedOutputTokens, 10) : 0,
|
|
178
|
+
routing_fee_reason: routingFeeReason || '',
|
|
125
179
|
};
|
|
126
180
|
}
|
|
127
181
|
// Parse credit tracking
|
|
@@ -158,6 +212,30 @@ function parseProxyMetadata(headers) {
|
|
|
158
212
|
if (balanceAfter) {
|
|
159
213
|
metadata.balance_after = parseFloat(balanceAfter);
|
|
160
214
|
}
|
|
215
|
+
// Parse compression metadata
|
|
216
|
+
const compressionMethod = getHeader('x-lockllm-compression-method');
|
|
217
|
+
if (compressionMethod) {
|
|
218
|
+
const compressionApplied = getHeader('x-lockllm-compression-applied');
|
|
219
|
+
const compressionRatio = getHeader('x-lockllm-compression-ratio');
|
|
220
|
+
metadata.compression = {
|
|
221
|
+
method: compressionMethod,
|
|
222
|
+
applied: compressionApplied === 'true',
|
|
223
|
+
ratio: compressionRatio ? parseFloat(compressionRatio) : 1.0,
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
// Parse base64-encoded detail fields
|
|
227
|
+
const scanDetail = getHeader('x-lockllm-scan-detail');
|
|
228
|
+
if (scanDetail) {
|
|
229
|
+
metadata.scan_detail = decodeDetailField(scanDetail);
|
|
230
|
+
}
|
|
231
|
+
const policyDetail = getHeader('x-lockllm-warning-detail');
|
|
232
|
+
if (policyDetail) {
|
|
233
|
+
metadata.policy_detail = decodeDetailField(policyDetail);
|
|
234
|
+
}
|
|
235
|
+
const abuseDetail = getHeader('x-lockllm-abuse-detail');
|
|
236
|
+
if (abuseDetail) {
|
|
237
|
+
metadata.abuse_detail = decodeDetailField(abuseDetail);
|
|
238
|
+
}
|
|
161
239
|
return metadata;
|
|
162
240
|
}
|
|
163
241
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"proxy-headers.js","sourceRoot":"","sources":["../../src/utils/proxy-headers.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH;;;;;;;;;GASG;AACH,MAAM,UAAU,mBAAmB,CAAC,OAA6B;IAC/D,MAAM,OAAO,GAA2B,EAAE,CAAC;IAE3C,kEAAkE;IAClE,IAAI,OAAO,EAAE,QAAQ,EAAE,CAAC;QACtB,OAAO,CAAC,qBAAqB,CAAC,GAAG,OAAO,CAAC,QAAQ,CAAC;IACpD,CAAC;IAED,qEAAqE;IACrE,IAAI,OAAO,EAAE,UAAU,EAAE,CAAC;QACxB,OAAO,CAAC,uBAAuB,CAAC,GAAG,OAAO,CAAC,UAAU,CAAC;IACxD,CAAC;IAED,0EAA0E;IAC1E,IAAI,OAAO,EAAE,YAAY,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M,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC"}
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* - Scan Action: allow_with_warning (detect threats but don't block)
|
|
10
10
|
* - Policy Action: allow_with_warning (detect violations but don't block)
|
|
11
11
|
* - Abuse Action: null (abuse detection disabled, opt-in only)
|
|
12
|
-
* - Route Action: disabled (no
|
|
12
|
+
* - Route Action: disabled (no smart routing)
|
|
13
13
|
*/
|
|
14
14
|
export function buildLockLLMHeaders(options) {
|
|
15
15
|
const headers = {};
|
|
@@ -29,10 +29,18 @@ export function buildLockLLMHeaders(options) {
|
|
|
29
29
|
if (options?.abuseAction !== undefined && options?.abuseAction !== null) {
|
|
30
30
|
headers['x-lockllm-abuse-action'] = options.abuseAction;
|
|
31
31
|
}
|
|
32
|
-
// Route action header (controls
|
|
32
|
+
// Route action header (controls smart routing)
|
|
33
33
|
if (options?.routeAction) {
|
|
34
34
|
headers['x-lockllm-route-action'] = options.routeAction;
|
|
35
35
|
}
|
|
36
|
+
// PII action header (opt-in, null means disabled)
|
|
37
|
+
if (options?.piiAction !== undefined && options?.piiAction !== null) {
|
|
38
|
+
headers['x-lockllm-pii-action'] = options.piiAction;
|
|
39
|
+
}
|
|
40
|
+
// Sensitivity header (controls injection detection threshold)
|
|
41
|
+
if (options?.sensitivity) {
|
|
42
|
+
headers['x-lockllm-sensitivity'] = options.sensitivity;
|
|
43
|
+
}
|
|
36
44
|
// Response caching control
|
|
37
45
|
if (options?.cacheResponse === false) {
|
|
38
46
|
headers['x-lockllm-cache-response'] = 'false';
|
|
@@ -41,6 +49,14 @@ export function buildLockLLMHeaders(options) {
|
|
|
41
49
|
if (options?.cacheTTL !== undefined) {
|
|
42
50
|
headers['x-lockllm-cache-ttl'] = String(options.cacheTTL);
|
|
43
51
|
}
|
|
52
|
+
// Compression header (opt-in, null means disabled)
|
|
53
|
+
if (options?.compressionAction !== undefined && options?.compressionAction !== null) {
|
|
54
|
+
headers['x-lockllm-compression'] = options.compressionAction;
|
|
55
|
+
}
|
|
56
|
+
// Compression rate (compact method only, 0.3-0.7)
|
|
57
|
+
if (options?.compressionRate !== undefined) {
|
|
58
|
+
headers['x-lockllm-compression-rate'] = String(options.compressionRate);
|
|
59
|
+
}
|
|
44
60
|
return headers;
|
|
45
61
|
}
|
|
46
62
|
/**
|
|
@@ -62,6 +78,21 @@ export function parseProxyMetadata(headers) {
|
|
|
62
78
|
provider: getHeader('x-lockllm-provider') || '',
|
|
63
79
|
model: getHeader('x-lockllm-model') || undefined,
|
|
64
80
|
};
|
|
81
|
+
// Parse sensitivity
|
|
82
|
+
const sensitivity = getHeader('x-lockllm-sensitivity');
|
|
83
|
+
if (sensitivity) {
|
|
84
|
+
metadata.sensitivity = sensitivity;
|
|
85
|
+
}
|
|
86
|
+
// Parse label
|
|
87
|
+
const label = getHeader('x-lockllm-label');
|
|
88
|
+
if (label) {
|
|
89
|
+
metadata.label = parseInt(label, 10);
|
|
90
|
+
}
|
|
91
|
+
// Parse blocked status
|
|
92
|
+
const blocked = getHeader('x-lockllm-blocked');
|
|
93
|
+
if (blocked === 'true') {
|
|
94
|
+
metadata.blocked = true;
|
|
95
|
+
}
|
|
65
96
|
// Parse scan warning
|
|
66
97
|
const scanWarning = getHeader('x-lockllm-scan-warning');
|
|
67
98
|
if (scanWarning === 'true') {
|
|
@@ -98,6 +129,19 @@ export function parseProxyMetadata(headers) {
|
|
|
98
129
|
detail: detail || '',
|
|
99
130
|
};
|
|
100
131
|
}
|
|
132
|
+
// Parse PII detection
|
|
133
|
+
const piiDetected = getHeader('x-lockllm-pii-detected');
|
|
134
|
+
if (piiDetected) {
|
|
135
|
+
const piiTypes = getHeader('x-lockllm-pii-types');
|
|
136
|
+
const piiCount = getHeader('x-lockllm-pii-count');
|
|
137
|
+
const piiAction = getHeader('x-lockllm-pii-action');
|
|
138
|
+
metadata.pii_detected = {
|
|
139
|
+
detected: piiDetected === 'true',
|
|
140
|
+
entity_types: piiTypes || '',
|
|
141
|
+
entity_count: piiCount ? parseInt(piiCount, 10) : 0,
|
|
142
|
+
action: piiAction || '',
|
|
143
|
+
};
|
|
144
|
+
}
|
|
101
145
|
// Parse routing metadata
|
|
102
146
|
const routeEnabled = getHeader('x-lockllm-route-enabled');
|
|
103
147
|
if (routeEnabled === 'true') {
|
|
@@ -108,6 +152,11 @@ export function parseProxyMetadata(headers) {
|
|
|
108
152
|
const originalProvider = getHeader('x-lockllm-original-provider');
|
|
109
153
|
const originalModel = getHeader('x-lockllm-original-model');
|
|
110
154
|
const estimatedSavings = getHeader('x-lockllm-estimated-savings');
|
|
155
|
+
const estimatedOriginalCost = getHeader('x-lockllm-estimated-original-cost');
|
|
156
|
+
const estimatedRoutedCost = getHeader('x-lockllm-estimated-routed-cost');
|
|
157
|
+
const estimatedInputTokens = getHeader('x-lockllm-estimated-input-tokens');
|
|
158
|
+
const estimatedOutputTokens = getHeader('x-lockllm-estimated-output-tokens');
|
|
159
|
+
const routingFeeReason = getHeader('x-lockllm-routing-fee-reason');
|
|
111
160
|
metadata.routing = {
|
|
112
161
|
enabled: true,
|
|
113
162
|
task_type: taskType || '',
|
|
@@ -117,6 +166,11 @@ export function parseProxyMetadata(headers) {
|
|
|
117
166
|
original_provider: originalProvider || '',
|
|
118
167
|
original_model: originalModel || '',
|
|
119
168
|
estimated_savings: estimatedSavings ? parseFloat(estimatedSavings) : 0,
|
|
169
|
+
estimated_original_cost: estimatedOriginalCost ? parseFloat(estimatedOriginalCost) : 0,
|
|
170
|
+
estimated_routed_cost: estimatedRoutedCost ? parseFloat(estimatedRoutedCost) : 0,
|
|
171
|
+
estimated_input_tokens: estimatedInputTokens ? parseInt(estimatedInputTokens, 10) : 0,
|
|
172
|
+
estimated_output_tokens: estimatedOutputTokens ? parseInt(estimatedOutputTokens, 10) : 0,
|
|
173
|
+
routing_fee_reason: routingFeeReason || '',
|
|
120
174
|
};
|
|
121
175
|
}
|
|
122
176
|
// Parse credit tracking
|
|
@@ -153,6 +207,30 @@ export function parseProxyMetadata(headers) {
|
|
|
153
207
|
if (balanceAfter) {
|
|
154
208
|
metadata.balance_after = parseFloat(balanceAfter);
|
|
155
209
|
}
|
|
210
|
+
// Parse compression metadata
|
|
211
|
+
const compressionMethod = getHeader('x-lockllm-compression-method');
|
|
212
|
+
if (compressionMethod) {
|
|
213
|
+
const compressionApplied = getHeader('x-lockllm-compression-applied');
|
|
214
|
+
const compressionRatio = getHeader('x-lockllm-compression-ratio');
|
|
215
|
+
metadata.compression = {
|
|
216
|
+
method: compressionMethod,
|
|
217
|
+
applied: compressionApplied === 'true',
|
|
218
|
+
ratio: compressionRatio ? parseFloat(compressionRatio) : 1.0,
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
// Parse base64-encoded detail fields
|
|
222
|
+
const scanDetail = getHeader('x-lockllm-scan-detail');
|
|
223
|
+
if (scanDetail) {
|
|
224
|
+
metadata.scan_detail = decodeDetailField(scanDetail);
|
|
225
|
+
}
|
|
226
|
+
const policyDetail = getHeader('x-lockllm-warning-detail');
|
|
227
|
+
if (policyDetail) {
|
|
228
|
+
metadata.policy_detail = decodeDetailField(policyDetail);
|
|
229
|
+
}
|
|
230
|
+
const abuseDetail = getHeader('x-lockllm-abuse-detail');
|
|
231
|
+
if (abuseDetail) {
|
|
232
|
+
metadata.abuse_detail = decodeDetailField(abuseDetail);
|
|
233
|
+
}
|
|
156
234
|
return metadata;
|
|
157
235
|
}
|
|
158
236
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lockllm/sdk",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "Enterprise-grade AI security SDK providing real-time protection against prompt injection, jailbreaks, and adversarial attacks. Drop-in replacement for OpenAI, Anthropic, and 17+ providers with zero code changes. Includes REST API, proxy mode, browser extension, and webhook support. Free BYOK model with unlimited scanning.",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|