@lockllm/sdk 1.0.1 → 1.2.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 +223 -5
- package/README.md +272 -40
- package/dist/client.d.ts +1 -1
- package/dist/client.d.ts.map +1 -1
- package/dist/errors.d.ts +56 -1
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +132 -2
- package/dist/errors.js.map +1 -1
- package/dist/errors.mjs +127 -1
- package/dist/index.d.ts +6 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +3 -2
- package/dist/scan.d.ts +20 -5
- package/dist/scan.d.ts.map +1 -1
- package/dist/scan.js +59 -5
- package/dist/scan.js.map +1 -1
- package/dist/scan.mjs +59 -5
- package/dist/types/common.d.ts +116 -0
- package/dist/types/common.d.ts.map +1 -1
- package/dist/types/errors.d.ts +39 -0
- package/dist/types/errors.d.ts.map +1 -1
- package/dist/types/scan.d.ts +118 -3
- package/dist/types/scan.d.ts.map +1 -1
- package/dist/utils/proxy-headers.d.ts +24 -0
- package/dist/utils/proxy-headers.d.ts.map +1 -0
- package/dist/utils/proxy-headers.js +234 -0
- package/dist/utils/proxy-headers.js.map +1 -0
- package/dist/utils/proxy-headers.mjs +229 -0
- package/dist/utils.d.ts +24 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +28 -0
- package/dist/utils.js.map +1 -1
- package/dist/utils.mjs +27 -0
- package/dist/wrappers/anthropic-wrapper.d.ts +10 -1
- package/dist/wrappers/anthropic-wrapper.d.ts.map +1 -1
- package/dist/wrappers/anthropic-wrapper.js +17 -2
- package/dist/wrappers/anthropic-wrapper.js.map +1 -1
- package/dist/wrappers/anthropic-wrapper.mjs +17 -2
- package/dist/wrappers/generic-wrapper.d.ts +5 -0
- package/dist/wrappers/generic-wrapper.d.ts.map +1 -1
- package/dist/wrappers/generic-wrapper.js +12 -1
- package/dist/wrappers/generic-wrapper.js.map +1 -1
- package/dist/wrappers/generic-wrapper.mjs +12 -1
- package/dist/wrappers/openai-wrapper.d.ts +10 -1
- package/dist/wrappers/openai-wrapper.d.ts.map +1 -1
- package/dist/wrappers/openai-wrapper.js +17 -2
- package/dist/wrappers/openai-wrapper.js.map +1 -1
- package/dist/wrappers/openai-wrapper.mjs +17 -2
- package/package.json +2 -2
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.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
|
|
@@ -106,6 +106,75 @@ class ConfigurationError extends LockLLMError {
|
|
|
106
106
|
}
|
|
107
107
|
}
|
|
108
108
|
exports.ConfigurationError = ConfigurationError;
|
|
109
|
+
/**
|
|
110
|
+
* Error thrown when custom policy violations are detected
|
|
111
|
+
*/
|
|
112
|
+
class PolicyViolationError extends LockLLMError {
|
|
113
|
+
constructor(data) {
|
|
114
|
+
super({
|
|
115
|
+
message: data.message,
|
|
116
|
+
type: 'lockllm_policy_error',
|
|
117
|
+
code: 'policy_violation',
|
|
118
|
+
status: 403,
|
|
119
|
+
requestId: data.requestId,
|
|
120
|
+
});
|
|
121
|
+
this.name = 'PolicyViolationError';
|
|
122
|
+
this.violated_policies = data.violated_policies;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
exports.PolicyViolationError = PolicyViolationError;
|
|
126
|
+
/**
|
|
127
|
+
* Error thrown when AI abuse is detected
|
|
128
|
+
*/
|
|
129
|
+
class AbuseDetectedError extends LockLLMError {
|
|
130
|
+
constructor(data) {
|
|
131
|
+
super({
|
|
132
|
+
message: data.message,
|
|
133
|
+
type: 'lockllm_abuse_error',
|
|
134
|
+
code: 'abuse_detected',
|
|
135
|
+
status: 400,
|
|
136
|
+
requestId: data.requestId,
|
|
137
|
+
});
|
|
138
|
+
this.name = 'AbuseDetectedError';
|
|
139
|
+
this.abuse_details = data.abuse_details;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
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;
|
|
160
|
+
/**
|
|
161
|
+
* Error thrown when user has insufficient credits
|
|
162
|
+
*/
|
|
163
|
+
class InsufficientCreditsError extends LockLLMError {
|
|
164
|
+
constructor(data) {
|
|
165
|
+
super({
|
|
166
|
+
message: data.message,
|
|
167
|
+
type: 'lockllm_balance_error',
|
|
168
|
+
code: 'insufficient_credits',
|
|
169
|
+
status: 402,
|
|
170
|
+
requestId: data.requestId,
|
|
171
|
+
});
|
|
172
|
+
this.name = 'InsufficientCreditsError';
|
|
173
|
+
this.current_balance = data.current_balance;
|
|
174
|
+
this.estimated_cost = data.estimated_cost;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
exports.InsufficientCreditsError = InsufficientCreditsError;
|
|
109
178
|
/**
|
|
110
179
|
* Error thrown when network request fails
|
|
111
180
|
*/
|
|
@@ -146,6 +215,51 @@ function parseError(response, requestId) {
|
|
|
146
215
|
scanResult: error.scan_result,
|
|
147
216
|
});
|
|
148
217
|
}
|
|
218
|
+
// Policy violation error
|
|
219
|
+
if (error.code === 'policy_violation' && error.violated_policies) {
|
|
220
|
+
return new PolicyViolationError({
|
|
221
|
+
message: error.message,
|
|
222
|
+
type: error.type,
|
|
223
|
+
code: error.code,
|
|
224
|
+
status: 403,
|
|
225
|
+
requestId: error.request_id || requestId,
|
|
226
|
+
violated_policies: error.violated_policies,
|
|
227
|
+
});
|
|
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
|
+
}
|
|
240
|
+
// Abuse detected error
|
|
241
|
+
if (error.code === 'abuse_detected' && error.abuse_details) {
|
|
242
|
+
return new AbuseDetectedError({
|
|
243
|
+
message: error.message,
|
|
244
|
+
type: error.type,
|
|
245
|
+
code: error.code,
|
|
246
|
+
status: 400,
|
|
247
|
+
requestId: error.request_id || requestId,
|
|
248
|
+
abuse_details: error.abuse_details,
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
// Insufficient credits error
|
|
252
|
+
if (error.code === 'insufficient_credits' || error.code === 'insufficient_routing_credits') {
|
|
253
|
+
return new InsufficientCreditsError({
|
|
254
|
+
message: error.message,
|
|
255
|
+
type: error.type,
|
|
256
|
+
code: error.code,
|
|
257
|
+
status: 402,
|
|
258
|
+
requestId: error.request_id || requestId,
|
|
259
|
+
current_balance: error.current_balance || 0,
|
|
260
|
+
estimated_cost: error.estimated_cost || 0,
|
|
261
|
+
});
|
|
262
|
+
}
|
|
149
263
|
// Authentication error
|
|
150
264
|
if (error.type === 'authentication_error' || error.code === 'unauthorized') {
|
|
151
265
|
return new AuthenticationError(error.message, requestId);
|
|
@@ -158,10 +272,26 @@ function parseError(response, requestId) {
|
|
|
158
272
|
if (error.type === 'upstream_error' || error.code === 'provider_error') {
|
|
159
273
|
return new UpstreamError(error.message, undefined, undefined, requestId);
|
|
160
274
|
}
|
|
275
|
+
// Balance/credits errors
|
|
276
|
+
if (error.code === 'no_balance' ||
|
|
277
|
+
error.code === 'balance_check_failed' ||
|
|
278
|
+
error.code === 'credits_unavailable' ||
|
|
279
|
+
error.code === 'invalid_provider_for_credits_mode') {
|
|
280
|
+
return new InsufficientCreditsError({
|
|
281
|
+
message: error.message,
|
|
282
|
+
type: error.type,
|
|
283
|
+
code: error.code,
|
|
284
|
+
status: 402,
|
|
285
|
+
requestId: error.request_id || requestId,
|
|
286
|
+
current_balance: error.current_balance || 0,
|
|
287
|
+
estimated_cost: error.estimated_cost || 0,
|
|
288
|
+
});
|
|
289
|
+
}
|
|
161
290
|
// Configuration error
|
|
162
291
|
if (error.type === 'configuration_error' ||
|
|
163
292
|
error.type === 'lockllm_config_error' ||
|
|
164
|
-
error.code === 'no_upstream_key'
|
|
293
|
+
error.code === 'no_upstream_key' ||
|
|
294
|
+
error.code === 'no_byok_key') {
|
|
165
295
|
return new ConfigurationError(error.message);
|
|
166
296
|
}
|
|
167
297
|
// Generic error
|
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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BAAsB;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
|
@@ -96,6 +96,71 @@ export class ConfigurationError extends LockLLMError {
|
|
|
96
96
|
this.name = 'ConfigurationError';
|
|
97
97
|
}
|
|
98
98
|
}
|
|
99
|
+
/**
|
|
100
|
+
* Error thrown when custom policy violations are detected
|
|
101
|
+
*/
|
|
102
|
+
export class PolicyViolationError extends LockLLMError {
|
|
103
|
+
constructor(data) {
|
|
104
|
+
super({
|
|
105
|
+
message: data.message,
|
|
106
|
+
type: 'lockllm_policy_error',
|
|
107
|
+
code: 'policy_violation',
|
|
108
|
+
status: 403,
|
|
109
|
+
requestId: data.requestId,
|
|
110
|
+
});
|
|
111
|
+
this.name = 'PolicyViolationError';
|
|
112
|
+
this.violated_policies = data.violated_policies;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Error thrown when AI abuse is detected
|
|
117
|
+
*/
|
|
118
|
+
export class AbuseDetectedError extends LockLLMError {
|
|
119
|
+
constructor(data) {
|
|
120
|
+
super({
|
|
121
|
+
message: data.message,
|
|
122
|
+
type: 'lockllm_abuse_error',
|
|
123
|
+
code: 'abuse_detected',
|
|
124
|
+
status: 400,
|
|
125
|
+
requestId: data.requestId,
|
|
126
|
+
});
|
|
127
|
+
this.name = 'AbuseDetectedError';
|
|
128
|
+
this.abuse_details = data.abuse_details;
|
|
129
|
+
}
|
|
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
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Error thrown when user has insufficient credits
|
|
149
|
+
*/
|
|
150
|
+
export class InsufficientCreditsError extends LockLLMError {
|
|
151
|
+
constructor(data) {
|
|
152
|
+
super({
|
|
153
|
+
message: data.message,
|
|
154
|
+
type: 'lockllm_balance_error',
|
|
155
|
+
code: 'insufficient_credits',
|
|
156
|
+
status: 402,
|
|
157
|
+
requestId: data.requestId,
|
|
158
|
+
});
|
|
159
|
+
this.name = 'InsufficientCreditsError';
|
|
160
|
+
this.current_balance = data.current_balance;
|
|
161
|
+
this.estimated_cost = data.estimated_cost;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
99
164
|
/**
|
|
100
165
|
* Error thrown when network request fails
|
|
101
166
|
*/
|
|
@@ -135,6 +200,51 @@ export function parseError(response, requestId) {
|
|
|
135
200
|
scanResult: error.scan_result,
|
|
136
201
|
});
|
|
137
202
|
}
|
|
203
|
+
// Policy violation error
|
|
204
|
+
if (error.code === 'policy_violation' && error.violated_policies) {
|
|
205
|
+
return new PolicyViolationError({
|
|
206
|
+
message: error.message,
|
|
207
|
+
type: error.type,
|
|
208
|
+
code: error.code,
|
|
209
|
+
status: 403,
|
|
210
|
+
requestId: error.request_id || requestId,
|
|
211
|
+
violated_policies: error.violated_policies,
|
|
212
|
+
});
|
|
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
|
+
}
|
|
225
|
+
// Abuse detected error
|
|
226
|
+
if (error.code === 'abuse_detected' && error.abuse_details) {
|
|
227
|
+
return new AbuseDetectedError({
|
|
228
|
+
message: error.message,
|
|
229
|
+
type: error.type,
|
|
230
|
+
code: error.code,
|
|
231
|
+
status: 400,
|
|
232
|
+
requestId: error.request_id || requestId,
|
|
233
|
+
abuse_details: error.abuse_details,
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
// Insufficient credits error
|
|
237
|
+
if (error.code === 'insufficient_credits' || error.code === 'insufficient_routing_credits') {
|
|
238
|
+
return new InsufficientCreditsError({
|
|
239
|
+
message: error.message,
|
|
240
|
+
type: error.type,
|
|
241
|
+
code: error.code,
|
|
242
|
+
status: 402,
|
|
243
|
+
requestId: error.request_id || requestId,
|
|
244
|
+
current_balance: error.current_balance || 0,
|
|
245
|
+
estimated_cost: error.estimated_cost || 0,
|
|
246
|
+
});
|
|
247
|
+
}
|
|
138
248
|
// Authentication error
|
|
139
249
|
if (error.type === 'authentication_error' || error.code === 'unauthorized') {
|
|
140
250
|
return new AuthenticationError(error.message, requestId);
|
|
@@ -147,10 +257,26 @@ export function parseError(response, requestId) {
|
|
|
147
257
|
if (error.type === 'upstream_error' || error.code === 'provider_error') {
|
|
148
258
|
return new UpstreamError(error.message, undefined, undefined, requestId);
|
|
149
259
|
}
|
|
260
|
+
// Balance/credits errors
|
|
261
|
+
if (error.code === 'no_balance' ||
|
|
262
|
+
error.code === 'balance_check_failed' ||
|
|
263
|
+
error.code === 'credits_unavailable' ||
|
|
264
|
+
error.code === 'invalid_provider_for_credits_mode') {
|
|
265
|
+
return new InsufficientCreditsError({
|
|
266
|
+
message: error.message,
|
|
267
|
+
type: error.type,
|
|
268
|
+
code: error.code,
|
|
269
|
+
status: 402,
|
|
270
|
+
requestId: error.request_id || requestId,
|
|
271
|
+
current_balance: error.current_balance || 0,
|
|
272
|
+
estimated_cost: error.estimated_cost || 0,
|
|
273
|
+
});
|
|
274
|
+
}
|
|
150
275
|
// Configuration error
|
|
151
276
|
if (error.type === 'configuration_error' ||
|
|
152
277
|
error.type === 'lockllm_config_error' ||
|
|
153
|
-
error.code === 'no_upstream_key'
|
|
278
|
+
error.code === 'no_upstream_key' ||
|
|
279
|
+
error.code === 'no_byok_key') {
|
|
154
280
|
return new ConfigurationError(error.message);
|
|
155
281
|
}
|
|
156
282
|
// Generic error
|
package/dist/index.d.ts
CHANGED
|
@@ -7,11 +7,12 @@
|
|
|
7
7
|
* @packageDocumentation
|
|
8
8
|
*/
|
|
9
9
|
export { LockLLM } from './client';
|
|
10
|
-
export { LockLLMError, AuthenticationError, RateLimitError, PromptInjectionError, UpstreamError, ConfigurationError, NetworkError, } from './errors';
|
|
11
|
-
export type { LockLLMConfig, RequestOptions, Provider } from './types/common';
|
|
12
|
-
export type { ScanRequest, ScanResponse, Sensitivity } from './types/scan';
|
|
13
|
-
export type { ScanResult, LockLLMErrorData, PromptInjectionErrorData, } 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, ProxyRequestOptions, ProxyResponseMetadata, } from './types/common';
|
|
12
|
+
export type { ScanRequest, ScanResponse, ScanOptions, Sensitivity, PolicyViolation, ScanWarning, AbuseWarning, PIIResult, } 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
|
-
export { getProxyURL, getAllProxyURLs } from './utils';
|
|
15
|
+
export { getProxyURL, getAllProxyURLs, getUniversalProxyURL } from './utils';
|
|
16
|
+
export { buildLockLLMHeaders, parseProxyMetadata, decodeDetailField } from './utils/proxy-headers';
|
|
16
17
|
export { createOpenAI, createAnthropic, createClient, createOpenAICompatible, createGroq, createDeepSeek, createPerplexity, createMistral, createOpenRouter, createTogether, createXAI, createFireworks, createAnyscale, createHuggingFace, createGemini, createCohere, createAzure, createBedrock, createVertexAI, } from './wrappers';
|
|
17
18
|
//# sourceMappingURL=index.d.ts.map
|
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,aAAa,EACb,kBAAkB,EAClB,YAAY,GACb,MAAM,UAAU,CAAC;AAGlB,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,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,GACV,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.getAllProxyURLs = exports.getProxyURL = exports.NetworkError = exports.ConfigurationError = exports.UpstreamError = 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; } });
|
|
@@ -18,6 +18,10 @@ Object.defineProperty(exports, "LockLLMError", { enumerable: true, get: function
|
|
|
18
18
|
Object.defineProperty(exports, "AuthenticationError", { enumerable: true, get: function () { return errors_1.AuthenticationError; } });
|
|
19
19
|
Object.defineProperty(exports, "RateLimitError", { enumerable: true, get: function () { return errors_1.RateLimitError; } });
|
|
20
20
|
Object.defineProperty(exports, "PromptInjectionError", { enumerable: true, get: function () { return errors_1.PromptInjectionError; } });
|
|
21
|
+
Object.defineProperty(exports, "PolicyViolationError", { enumerable: true, get: function () { return errors_1.PolicyViolationError; } });
|
|
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; } });
|
|
24
|
+
Object.defineProperty(exports, "InsufficientCreditsError", { enumerable: true, get: function () { return errors_1.InsufficientCreditsError; } });
|
|
21
25
|
Object.defineProperty(exports, "UpstreamError", { enumerable: true, get: function () { return errors_1.UpstreamError; } });
|
|
22
26
|
Object.defineProperty(exports, "ConfigurationError", { enumerable: true, get: function () { return errors_1.ConfigurationError; } });
|
|
23
27
|
Object.defineProperty(exports, "NetworkError", { enumerable: true, get: function () { return errors_1.NetworkError; } });
|
|
@@ -25,6 +29,11 @@ Object.defineProperty(exports, "NetworkError", { enumerable: true, get: function
|
|
|
25
29
|
var utils_1 = require("./utils");
|
|
26
30
|
Object.defineProperty(exports, "getProxyURL", { enumerable: true, get: function () { return utils_1.getProxyURL; } });
|
|
27
31
|
Object.defineProperty(exports, "getAllProxyURLs", { enumerable: true, get: function () { return utils_1.getAllProxyURLs; } });
|
|
32
|
+
Object.defineProperty(exports, "getUniversalProxyURL", { enumerable: true, get: function () { return utils_1.getUniversalProxyURL; } });
|
|
33
|
+
var proxy_headers_1 = require("./utils/proxy-headers");
|
|
34
|
+
Object.defineProperty(exports, "buildLockLLMHeaders", { enumerable: true, get: function () { return proxy_headers_1.buildLockLLMHeaders; } });
|
|
35
|
+
Object.defineProperty(exports, "parseProxyMetadata", { enumerable: true, get: function () { return proxy_headers_1.parseProxyMetadata; } });
|
|
36
|
+
Object.defineProperty(exports, "decodeDetailField", { enumerable: true, get: function () { return proxy_headers_1.decodeDetailField; } });
|
|
28
37
|
// Wrappers (re-exported for convenience)
|
|
29
38
|
var wrappers_1 = require("./wrappers");
|
|
30
39
|
Object.defineProperty(exports, "createOpenAI", { enumerable: true, get: function () { return wrappers_1.createOpenAI; } });
|
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,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;AAsClB,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,9 +9,10 @@
|
|
|
9
9
|
// Main client
|
|
10
10
|
export { LockLLM } from './client';
|
|
11
11
|
// Error classes
|
|
12
|
-
export { LockLLMError, AuthenticationError, RateLimitError, PromptInjectionError, UpstreamError, ConfigurationError, NetworkError, } from './errors';
|
|
12
|
+
export { LockLLMError, AuthenticationError, RateLimitError, PromptInjectionError, PolicyViolationError, AbuseDetectedError, PIIDetectedError, InsufficientCreditsError, UpstreamError, ConfigurationError, NetworkError, } from './errors';
|
|
13
13
|
// Utilities
|
|
14
|
-
export { getProxyURL, getAllProxyURLs } from './utils';
|
|
14
|
+
export { getProxyURL, getAllProxyURLs, getUniversalProxyURL } from './utils';
|
|
15
|
+
export { buildLockLLMHeaders, parseProxyMetadata, decodeDetailField } from './utils/proxy-headers';
|
|
15
16
|
// Wrappers (re-exported for convenience)
|
|
16
17
|
export { createOpenAI, createAnthropic, createClient, createOpenAICompatible, createGroq, createDeepSeek, createPerplexity, createMistral, createOpenRouter, createTogether, createXAI, createFireworks, createAnyscale, createHuggingFace, createGemini, createCohere, createAzure, createBedrock, createVertexAI, } from './wrappers';
|
|
17
18
|
//# sourceMappingURL=index.js.map
|
package/dist/scan.d.ts
CHANGED
|
@@ -2,8 +2,7 @@
|
|
|
2
2
|
* Scan API implementation
|
|
3
3
|
*/
|
|
4
4
|
import { HttpClient } from './utils';
|
|
5
|
-
import type { ScanRequest, ScanResponse } from './types/scan';
|
|
6
|
-
import type { RequestOptions } from './types/common';
|
|
5
|
+
import type { ScanRequest, ScanResponse, ScanOptions } from './types/scan';
|
|
7
6
|
export declare class ScanClient {
|
|
8
7
|
private http;
|
|
9
8
|
constructor(http: HttpClient);
|
|
@@ -11,22 +10,38 @@ export declare class ScanClient {
|
|
|
11
10
|
* Scan a prompt for injection attacks
|
|
12
11
|
*
|
|
13
12
|
* @param request - Scan request parameters
|
|
14
|
-
* @param options -
|
|
13
|
+
* @param options - Scan options with action headers
|
|
15
14
|
* @returns Scan result with safety information
|
|
16
15
|
*
|
|
17
16
|
* @example
|
|
18
17
|
* ```typescript
|
|
18
|
+
* // Basic scan with combined mode (default)
|
|
19
19
|
* const result = await client.scan({
|
|
20
20
|
* input: "Ignore previous instructions and...",
|
|
21
|
-
* sensitivity: "medium"
|
|
21
|
+
* sensitivity: "medium",
|
|
22
|
+
* mode: "combined" // Check both core security + custom policies
|
|
23
|
+
* }, {
|
|
24
|
+
* scanAction: "block", // Block core injection attacks
|
|
25
|
+
* policyAction: "allow_with_warning", // Allow but warn on policy violations
|
|
26
|
+
* abuseAction: "block" // Opt-in abuse detection
|
|
22
27
|
* });
|
|
23
28
|
*
|
|
24
29
|
* if (!result.safe) {
|
|
25
30
|
* console.log("Malicious prompt detected!");
|
|
26
31
|
* console.log("Injection score:", result.injection);
|
|
32
|
+
*
|
|
33
|
+
* // Check for policy violations
|
|
34
|
+
* if (result.policy_warnings) {
|
|
35
|
+
* console.log("Policy violations:", result.policy_warnings);
|
|
36
|
+
* }
|
|
37
|
+
*
|
|
38
|
+
* // Check for abuse warnings
|
|
39
|
+
* if (result.abuse_warnings) {
|
|
40
|
+
* console.log("Abuse detected:", result.abuse_warnings);
|
|
41
|
+
* }
|
|
27
42
|
* }
|
|
28
43
|
* ```
|
|
29
44
|
*/
|
|
30
|
-
scan(request: ScanRequest, options?:
|
|
45
|
+
scan(request: ScanRequest, options?: ScanOptions): Promise<ScanResponse>;
|
|
31
46
|
}
|
|
32
47
|
//# sourceMappingURL=scan.d.ts.map
|
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,
|
|
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;CA2DzB"}
|
package/dist/scan.js
CHANGED
|
@@ -12,27 +12,81 @@ class ScanClient {
|
|
|
12
12
|
* Scan a prompt for injection attacks
|
|
13
13
|
*
|
|
14
14
|
* @param request - Scan request parameters
|
|
15
|
-
* @param options -
|
|
15
|
+
* @param options - Scan options with action headers
|
|
16
16
|
* @returns Scan result with safety information
|
|
17
17
|
*
|
|
18
18
|
* @example
|
|
19
19
|
* ```typescript
|
|
20
|
+
* // Basic scan with combined mode (default)
|
|
20
21
|
* const result = await client.scan({
|
|
21
22
|
* input: "Ignore previous instructions and...",
|
|
22
|
-
* sensitivity: "medium"
|
|
23
|
+
* sensitivity: "medium",
|
|
24
|
+
* mode: "combined" // Check both core security + custom policies
|
|
25
|
+
* }, {
|
|
26
|
+
* scanAction: "block", // Block core injection attacks
|
|
27
|
+
* policyAction: "allow_with_warning", // Allow but warn on policy violations
|
|
28
|
+
* abuseAction: "block" // Opt-in abuse detection
|
|
23
29
|
* });
|
|
24
30
|
*
|
|
25
31
|
* if (!result.safe) {
|
|
26
32
|
* console.log("Malicious prompt detected!");
|
|
27
33
|
* console.log("Injection score:", result.injection);
|
|
34
|
+
*
|
|
35
|
+
* // Check for policy violations
|
|
36
|
+
* if (result.policy_warnings) {
|
|
37
|
+
* console.log("Policy violations:", result.policy_warnings);
|
|
38
|
+
* }
|
|
39
|
+
*
|
|
40
|
+
* // Check for abuse warnings
|
|
41
|
+
* if (result.abuse_warnings) {
|
|
42
|
+
* console.log("Abuse detected:", result.abuse_warnings);
|
|
43
|
+
* }
|
|
28
44
|
* }
|
|
29
45
|
* ```
|
|
30
46
|
*/
|
|
31
47
|
async scan(request, options) {
|
|
32
|
-
|
|
48
|
+
// Build headers from scan options
|
|
49
|
+
const headers = {
|
|
50
|
+
...(options?.headers || {}),
|
|
51
|
+
};
|
|
52
|
+
// Scan mode header
|
|
53
|
+
if (request.mode) {
|
|
54
|
+
headers['x-lockllm-scan-mode'] = request.mode;
|
|
55
|
+
}
|
|
56
|
+
// Sensitivity header
|
|
57
|
+
if (request.sensitivity) {
|
|
58
|
+
headers['x-lockllm-sensitivity'] = request.sensitivity;
|
|
59
|
+
}
|
|
60
|
+
// Chunk header
|
|
61
|
+
if (request.chunk !== undefined) {
|
|
62
|
+
headers['x-lockllm-chunk'] = request.chunk ? 'true' : 'false';
|
|
63
|
+
}
|
|
64
|
+
// Add action headers if provided
|
|
65
|
+
// Scan action: controls core injection detection behavior
|
|
66
|
+
if (options?.scanAction) {
|
|
67
|
+
headers['x-lockllm-scan-action'] = options.scanAction;
|
|
68
|
+
}
|
|
69
|
+
// Policy action: controls custom policy violation behavior
|
|
70
|
+
if (options?.policyAction) {
|
|
71
|
+
headers['x-lockllm-policy-action'] = options.policyAction;
|
|
72
|
+
}
|
|
73
|
+
// Abuse action: opt-in abuse detection (null/undefined means disabled)
|
|
74
|
+
if (options?.abuseAction !== undefined && options?.abuseAction !== null) {
|
|
75
|
+
headers['x-lockllm-abuse-action'] = options.abuseAction;
|
|
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
|
+
// Build request body
|
|
82
|
+
const body = {
|
|
33
83
|
input: request.input,
|
|
34
|
-
|
|
35
|
-
},
|
|
84
|
+
};
|
|
85
|
+
const { data } = await this.http.post('/v1/scan', body, {
|
|
86
|
+
headers,
|
|
87
|
+
timeout: options?.timeout,
|
|
88
|
+
signal: options?.signal,
|
|
89
|
+
});
|
|
36
90
|
return data;
|
|
37
91
|
}
|
|
38
92
|
}
|
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
|
|
1
|
+
{"version":3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