@lockllm/sdk 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. package/CHANGELOG.md +81 -0
  2. package/CODE_OF_CONDUCT.md +130 -0
  3. package/CONTRIBUTING.md +259 -0
  4. package/LICENSE +21 -0
  5. package/README.md +928 -0
  6. package/SECURITY.md +261 -0
  7. package/dist/client.d.ts +39 -0
  8. package/dist/client.d.ts.map +1 -0
  9. package/dist/client.js +65 -0
  10. package/dist/client.js.map +1 -0
  11. package/dist/client.mjs +61 -0
  12. package/dist/errors.d.ts +60 -0
  13. package/dist/errors.d.ts.map +1 -0
  14. package/dist/errors.js +175 -0
  15. package/dist/errors.js.map +1 -0
  16. package/dist/errors.mjs +164 -0
  17. package/dist/index.d.ts +17 -0
  18. package/dist/index.d.ts.map +1 -0
  19. package/dist/index.js +49 -0
  20. package/dist/index.js.map +1 -0
  21. package/dist/index.mjs +17 -0
  22. package/dist/scan.d.ts +32 -0
  23. package/dist/scan.d.ts.map +1 -0
  24. package/dist/scan.js +40 -0
  25. package/dist/scan.js.map +1 -0
  26. package/dist/scan.mjs +36 -0
  27. package/dist/types/common.d.ts +31 -0
  28. package/dist/types/common.d.ts.map +1 -0
  29. package/dist/types/common.js +6 -0
  30. package/dist/types/common.js.map +1 -0
  31. package/dist/types/common.mjs +5 -0
  32. package/dist/types/errors.d.ts +22 -0
  33. package/dist/types/errors.d.ts.map +1 -0
  34. package/dist/types/errors.js +6 -0
  35. package/dist/types/errors.js.map +1 -0
  36. package/dist/types/errors.mjs +5 -0
  37. package/dist/types/providers.d.ts +24 -0
  38. package/dist/types/providers.d.ts.map +1 -0
  39. package/dist/types/providers.js +26 -0
  40. package/dist/types/providers.js.map +1 -0
  41. package/dist/types/providers.mjs +23 -0
  42. package/dist/types/scan.d.ts +36 -0
  43. package/dist/types/scan.d.ts.map +1 -0
  44. package/dist/types/scan.js +6 -0
  45. package/dist/types/scan.js.map +1 -0
  46. package/dist/types/scan.mjs +5 -0
  47. package/dist/utils.d.ts +84 -0
  48. package/dist/utils.d.ts.map +1 -0
  49. package/dist/utils.js +225 -0
  50. package/dist/utils.js.map +1 -0
  51. package/dist/utils.mjs +215 -0
  52. package/dist/wrappers/anthropic-wrapper.d.ts +72 -0
  53. package/dist/wrappers/anthropic-wrapper.d.ts.map +1 -0
  54. package/dist/wrappers/anthropic-wrapper.js +78 -0
  55. package/dist/wrappers/anthropic-wrapper.js.map +1 -0
  56. package/dist/wrappers/anthropic-wrapper.mjs +74 -0
  57. package/dist/wrappers/generic-wrapper.d.ts +180 -0
  58. package/dist/wrappers/generic-wrapper.d.ts.map +1 -0
  59. package/dist/wrappers/generic-wrapper.js +246 -0
  60. package/dist/wrappers/generic-wrapper.js.map +1 -0
  61. package/dist/wrappers/generic-wrapper.mjs +225 -0
  62. package/dist/wrappers/index.d.ts +27 -0
  63. package/dist/wrappers/index.d.ts.map +1 -0
  64. package/dist/wrappers/index.js +48 -0
  65. package/dist/wrappers/index.js.map +1 -0
  66. package/dist/wrappers/index.mjs +26 -0
  67. package/dist/wrappers/openai-wrapper.d.ts +70 -0
  68. package/dist/wrappers/openai-wrapper.d.ts.map +1 -0
  69. package/dist/wrappers/openai-wrapper.js +76 -0
  70. package/dist/wrappers/openai-wrapper.js.map +1 -0
  71. package/dist/wrappers/openai-wrapper.mjs +72 -0
  72. package/package.json +106 -0
@@ -0,0 +1,164 @@
1
+ /**
2
+ * Custom error classes for LockLLM SDK
3
+ */
4
+ /**
5
+ * Base error class for all LockLLM errors
6
+ */
7
+ export class LockLLMError extends Error {
8
+ constructor(data) {
9
+ super(data.message);
10
+ this.name = 'LockLLMError';
11
+ this.type = data.type;
12
+ this.code = data.code;
13
+ this.status = data.status;
14
+ this.requestId = data.requestId;
15
+ // Maintains proper stack trace for where our error was thrown (only available on V8)
16
+ if (Error.captureStackTrace) {
17
+ Error.captureStackTrace(this, this.constructor);
18
+ }
19
+ }
20
+ }
21
+ /**
22
+ * Error thrown when authentication fails
23
+ */
24
+ export class AuthenticationError extends LockLLMError {
25
+ constructor(message, requestId) {
26
+ super({
27
+ message,
28
+ type: 'authentication_error',
29
+ code: 'unauthorized',
30
+ status: 401,
31
+ requestId,
32
+ });
33
+ this.name = 'AuthenticationError';
34
+ }
35
+ }
36
+ /**
37
+ * Error thrown when rate limit is exceeded
38
+ */
39
+ export class RateLimitError extends LockLLMError {
40
+ constructor(message, retryAfter, requestId) {
41
+ super({
42
+ message,
43
+ type: 'rate_limit_error',
44
+ code: 'rate_limited',
45
+ status: 429,
46
+ requestId,
47
+ });
48
+ this.name = 'RateLimitError';
49
+ this.retryAfter = retryAfter;
50
+ }
51
+ }
52
+ /**
53
+ * Error thrown when a prompt is blocked due to injection detection
54
+ */
55
+ export class PromptInjectionError extends LockLLMError {
56
+ constructor(data) {
57
+ super({
58
+ message: data.message,
59
+ type: 'lockllm_security_error',
60
+ code: 'prompt_injection_detected',
61
+ status: 400,
62
+ requestId: data.requestId,
63
+ });
64
+ this.name = 'PromptInjectionError';
65
+ this.scanResult = data.scanResult;
66
+ }
67
+ }
68
+ /**
69
+ * Error thrown when upstream provider returns an error
70
+ */
71
+ export class UpstreamError extends LockLLMError {
72
+ constructor(message, provider, upstreamStatus, requestId) {
73
+ super({
74
+ message,
75
+ type: 'upstream_error',
76
+ code: 'provider_error',
77
+ status: 502,
78
+ requestId,
79
+ });
80
+ this.name = 'UpstreamError';
81
+ this.provider = provider;
82
+ this.upstreamStatus = upstreamStatus;
83
+ }
84
+ }
85
+ /**
86
+ * Error thrown when configuration is missing or invalid
87
+ */
88
+ export class ConfigurationError extends LockLLMError {
89
+ constructor(message) {
90
+ super({
91
+ message,
92
+ type: 'configuration_error',
93
+ code: 'invalid_config',
94
+ status: 400,
95
+ });
96
+ this.name = 'ConfigurationError';
97
+ }
98
+ }
99
+ /**
100
+ * Error thrown when network request fails
101
+ */
102
+ export class NetworkError extends LockLLMError {
103
+ constructor(message, cause, requestId) {
104
+ super({
105
+ message,
106
+ type: 'network_error',
107
+ code: 'connection_failed',
108
+ status: 0,
109
+ requestId,
110
+ });
111
+ this.name = 'NetworkError';
112
+ this.cause = cause;
113
+ }
114
+ }
115
+ /**
116
+ * Parse error response from API and throw appropriate error
117
+ */
118
+ export function parseError(response, requestId) {
119
+ const error = response?.error;
120
+ if (!error) {
121
+ return new LockLLMError({
122
+ message: 'Unknown error occurred',
123
+ type: 'unknown_error',
124
+ requestId,
125
+ });
126
+ }
127
+ // Prompt injection error
128
+ if (error.code === 'prompt_injection_detected' && error.scan_result) {
129
+ return new PromptInjectionError({
130
+ message: error.message,
131
+ type: error.type,
132
+ code: error.code,
133
+ status: 400,
134
+ requestId: error.request_id || requestId,
135
+ scanResult: error.scan_result,
136
+ });
137
+ }
138
+ // Authentication error
139
+ if (error.type === 'authentication_error' || error.code === 'unauthorized') {
140
+ return new AuthenticationError(error.message, requestId);
141
+ }
142
+ // Rate limit error
143
+ if (error.type === 'rate_limit_error' || error.code === 'rate_limited') {
144
+ return new RateLimitError(error.message, undefined, requestId);
145
+ }
146
+ // Upstream provider error
147
+ if (error.type === 'upstream_error' || error.code === 'provider_error') {
148
+ return new UpstreamError(error.message, undefined, undefined, requestId);
149
+ }
150
+ // Configuration error
151
+ if (error.type === 'configuration_error' ||
152
+ error.type === 'lockllm_config_error' ||
153
+ error.code === 'no_upstream_key') {
154
+ return new ConfigurationError(error.message);
155
+ }
156
+ // Generic error
157
+ return new LockLLMError({
158
+ message: error.message || 'An error occurred',
159
+ type: error.type || 'unknown_error',
160
+ code: error.code,
161
+ requestId,
162
+ });
163
+ }
164
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1,17 @@
1
+ /**
2
+ * LockLLM JavaScript/TypeScript SDK
3
+ *
4
+ * Universal AI security SDK with prompt injection detection.
5
+ * Completely free with unlimited usage. BYOK (Bring Your Own Key).
6
+ *
7
+ * @packageDocumentation
8
+ */
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';
14
+ export type { ProviderName } from './types/providers';
15
+ export { getProxyURL, getAllProxyURLs } from './utils';
16
+ export { createOpenAI, createAnthropic, createClient, createOpenAICompatible, createGroq, createDeepSeek, createPerplexity, createMistral, createOpenRouter, createTogether, createXAI, createFireworks, createAnyscale, createHuggingFace, createGemini, createCohere, createAzure, createBedrock, createVertexAI, } from './wrappers';
17
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +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,EAAE,aAAa,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC9E,YAAY,EAAE,WAAW,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3E,YAAY,EACV,UAAU,EACV,gBAAgB,EAChB,wBAAwB,GACzB,MAAM,gBAAgB,CAAC;AACxB,YAAY,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAGtD,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAGvD,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 ADDED
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ /**
3
+ * LockLLM JavaScript/TypeScript SDK
4
+ *
5
+ * Universal AI security SDK with prompt injection detection.
6
+ * Completely free with unlimited usage. BYOK (Bring Your Own Key).
7
+ *
8
+ * @packageDocumentation
9
+ */
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;
12
+ // Main client
13
+ var client_1 = require("./client");
14
+ Object.defineProperty(exports, "LockLLM", { enumerable: true, get: function () { return client_1.LockLLM; } });
15
+ // Error classes
16
+ var errors_1 = require("./errors");
17
+ Object.defineProperty(exports, "LockLLMError", { enumerable: true, get: function () { return errors_1.LockLLMError; } });
18
+ Object.defineProperty(exports, "AuthenticationError", { enumerable: true, get: function () { return errors_1.AuthenticationError; } });
19
+ Object.defineProperty(exports, "RateLimitError", { enumerable: true, get: function () { return errors_1.RateLimitError; } });
20
+ Object.defineProperty(exports, "PromptInjectionError", { enumerable: true, get: function () { return errors_1.PromptInjectionError; } });
21
+ Object.defineProperty(exports, "UpstreamError", { enumerable: true, get: function () { return errors_1.UpstreamError; } });
22
+ Object.defineProperty(exports, "ConfigurationError", { enumerable: true, get: function () { return errors_1.ConfigurationError; } });
23
+ Object.defineProperty(exports, "NetworkError", { enumerable: true, get: function () { return errors_1.NetworkError; } });
24
+ // Utilities
25
+ var utils_1 = require("./utils");
26
+ Object.defineProperty(exports, "getProxyURL", { enumerable: true, get: function () { return utils_1.getProxyURL; } });
27
+ Object.defineProperty(exports, "getAllProxyURLs", { enumerable: true, get: function () { return utils_1.getAllProxyURLs; } });
28
+ // Wrappers (re-exported for convenience)
29
+ var wrappers_1 = require("./wrappers");
30
+ Object.defineProperty(exports, "createOpenAI", { enumerable: true, get: function () { return wrappers_1.createOpenAI; } });
31
+ Object.defineProperty(exports, "createAnthropic", { enumerable: true, get: function () { return wrappers_1.createAnthropic; } });
32
+ Object.defineProperty(exports, "createClient", { enumerable: true, get: function () { return wrappers_1.createClient; } });
33
+ Object.defineProperty(exports, "createOpenAICompatible", { enumerable: true, get: function () { return wrappers_1.createOpenAICompatible; } });
34
+ Object.defineProperty(exports, "createGroq", { enumerable: true, get: function () { return wrappers_1.createGroq; } });
35
+ Object.defineProperty(exports, "createDeepSeek", { enumerable: true, get: function () { return wrappers_1.createDeepSeek; } });
36
+ Object.defineProperty(exports, "createPerplexity", { enumerable: true, get: function () { return wrappers_1.createPerplexity; } });
37
+ Object.defineProperty(exports, "createMistral", { enumerable: true, get: function () { return wrappers_1.createMistral; } });
38
+ Object.defineProperty(exports, "createOpenRouter", { enumerable: true, get: function () { return wrappers_1.createOpenRouter; } });
39
+ Object.defineProperty(exports, "createTogether", { enumerable: true, get: function () { return wrappers_1.createTogether; } });
40
+ Object.defineProperty(exports, "createXAI", { enumerable: true, get: function () { return wrappers_1.createXAI; } });
41
+ Object.defineProperty(exports, "createFireworks", { enumerable: true, get: function () { return wrappers_1.createFireworks; } });
42
+ Object.defineProperty(exports, "createAnyscale", { enumerable: true, get: function () { return wrappers_1.createAnyscale; } });
43
+ Object.defineProperty(exports, "createHuggingFace", { enumerable: true, get: function () { return wrappers_1.createHuggingFace; } });
44
+ Object.defineProperty(exports, "createGemini", { enumerable: true, get: function () { return wrappers_1.createGemini; } });
45
+ Object.defineProperty(exports, "createCohere", { enumerable: true, get: function () { return wrappers_1.createCohere; } });
46
+ Object.defineProperty(exports, "createAzure", { enumerable: true, get: function () { return wrappers_1.createAzure; } });
47
+ Object.defineProperty(exports, "createBedrock", { enumerable: true, get: function () { return wrappers_1.createBedrock; } });
48
+ Object.defineProperty(exports, "createVertexAI", { enumerable: true, get: function () { return wrappers_1.createVertexAI; } });
49
+ //# sourceMappingURL=index.js.map
@@ -0,0 +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;AAYlB,YAAY;AACZ,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAEvD,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 ADDED
@@ -0,0 +1,17 @@
1
+ /**
2
+ * LockLLM JavaScript/TypeScript SDK
3
+ *
4
+ * Universal AI security SDK with prompt injection detection.
5
+ * Completely free with unlimited usage. BYOK (Bring Your Own Key).
6
+ *
7
+ * @packageDocumentation
8
+ */
9
+ // Main client
10
+ export { LockLLM } from './client';
11
+ // Error classes
12
+ export { LockLLMError, AuthenticationError, RateLimitError, PromptInjectionError, UpstreamError, ConfigurationError, NetworkError, } from './errors';
13
+ // Utilities
14
+ export { getProxyURL, getAllProxyURLs } from './utils';
15
+ // Wrappers (re-exported for convenience)
16
+ export { createOpenAI, createAnthropic, createClient, createOpenAICompatible, createGroq, createDeepSeek, createPerplexity, createMistral, createOpenRouter, createTogether, createXAI, createFireworks, createAnyscale, createHuggingFace, createGemini, createCohere, createAzure, createBedrock, createVertexAI, } from './wrappers';
17
+ //# sourceMappingURL=index.js.map
package/dist/scan.d.ts ADDED
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Scan API implementation
3
+ */
4
+ import { HttpClient } from './utils';
5
+ import type { ScanRequest, ScanResponse } from './types/scan';
6
+ import type { RequestOptions } from './types/common';
7
+ export declare class ScanClient {
8
+ private http;
9
+ constructor(http: HttpClient);
10
+ /**
11
+ * Scan a prompt for injection attacks
12
+ *
13
+ * @param request - Scan request parameters
14
+ * @param options - Request options
15
+ * @returns Scan result with safety information
16
+ *
17
+ * @example
18
+ * ```typescript
19
+ * const result = await client.scan({
20
+ * input: "Ignore previous instructions and...",
21
+ * sensitivity: "medium"
22
+ * });
23
+ *
24
+ * if (!result.safe) {
25
+ * console.log("Malicious prompt detected!");
26
+ * console.log("Injection score:", result.injection);
27
+ * }
28
+ * ```
29
+ */
30
+ scan(request: ScanRequest, options?: RequestOptions): Promise<ScanResponse>;
31
+ }
32
+ //# sourceMappingURL=scan.d.ts.map
@@ -0,0 +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,MAAM,cAAc,CAAC;AAC9D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAErD,qBAAa,UAAU;IACrB,OAAO,CAAC,IAAI,CAAa;gBAEb,IAAI,EAAE,UAAU;IAI5B;;;;;;;;;;;;;;;;;;;OAmBG;IACG,IAAI,CACR,OAAO,EAAE,WAAW,EACpB,OAAO,CAAC,EAAE,cAAc,GACvB,OAAO,CAAC,YAAY,CAAC;CAYzB"}
package/dist/scan.js ADDED
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ /**
3
+ * Scan API implementation
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.ScanClient = void 0;
7
+ class ScanClient {
8
+ constructor(http) {
9
+ this.http = http;
10
+ }
11
+ /**
12
+ * Scan a prompt for injection attacks
13
+ *
14
+ * @param request - Scan request parameters
15
+ * @param options - Request options
16
+ * @returns Scan result with safety information
17
+ *
18
+ * @example
19
+ * ```typescript
20
+ * const result = await client.scan({
21
+ * input: "Ignore previous instructions and...",
22
+ * sensitivity: "medium"
23
+ * });
24
+ *
25
+ * if (!result.safe) {
26
+ * console.log("Malicious prompt detected!");
27
+ * console.log("Injection score:", result.injection);
28
+ * }
29
+ * ```
30
+ */
31
+ async scan(request, options) {
32
+ const { data } = await this.http.post('/v1/scan', {
33
+ input: request.input,
34
+ sensitivity: request.sensitivity || 'medium',
35
+ }, options);
36
+ return data;
37
+ }
38
+ }
39
+ exports.ScanClient = ScanClient;
40
+ //# sourceMappingURL=scan.js.map
@@ -0,0 +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;;;;;;;;;;;;;;;;;;;OAmBG;IACH,KAAK,CAAC,IAAI,CACR,OAAoB,EACpB,OAAwB;QAExB,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,IAAI,CACnC,UAAU,EACV;YACE,KAAK,EAAE,OAAO,CAAC,KAAK;YACpB,WAAW,EAAE,OAAO,CAAC,WAAW,IAAI,QAAQ;SAC7C,EACD,OAAO,CACR,CAAC;QAEF,OAAO,IAAI,CAAC;IACd,CAAC;CACF"}
package/dist/scan.mjs ADDED
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Scan API implementation
3
+ */
4
+ export class ScanClient {
5
+ constructor(http) {
6
+ this.http = http;
7
+ }
8
+ /**
9
+ * Scan a prompt for injection attacks
10
+ *
11
+ * @param request - Scan request parameters
12
+ * @param options - Request options
13
+ * @returns Scan result with safety information
14
+ *
15
+ * @example
16
+ * ```typescript
17
+ * const result = await client.scan({
18
+ * input: "Ignore previous instructions and...",
19
+ * sensitivity: "medium"
20
+ * });
21
+ *
22
+ * if (!result.safe) {
23
+ * console.log("Malicious prompt detected!");
24
+ * console.log("Injection score:", result.injection);
25
+ * }
26
+ * ```
27
+ */
28
+ async scan(request, options) {
29
+ const { data } = await this.http.post('/v1/scan', {
30
+ input: request.input,
31
+ sensitivity: request.sensitivity || 'medium',
32
+ }, options);
33
+ return data;
34
+ }
35
+ }
36
+ //# sourceMappingURL=scan.js.map
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Common types used throughout the SDK
3
+ */
4
+ export interface LockLLMConfig {
5
+ /** Your LockLLM API key */
6
+ apiKey: string;
7
+ /** Base URL for LockLLM API (default: https://api.lockllm.com) */
8
+ baseURL?: string;
9
+ /** Request timeout in milliseconds (default: 60000) */
10
+ timeout?: number;
11
+ /** Maximum number of retries for rate-limited requests (default: 3) */
12
+ maxRetries?: number;
13
+ }
14
+ export interface RequestOptions {
15
+ /** Custom headers to include in the request */
16
+ headers?: Record<string, string>;
17
+ /** Request timeout in milliseconds */
18
+ timeout?: number;
19
+ /** Abort signal for cancelling requests */
20
+ signal?: AbortSignal;
21
+ }
22
+ export interface ErrorResponse {
23
+ error: {
24
+ message: string;
25
+ type: string;
26
+ code?: string;
27
+ [key: string]: any;
28
+ };
29
+ }
30
+ export type Provider = 'openai' | 'anthropic' | 'gemini' | 'cohere' | 'openrouter' | 'perplexity' | 'mistral' | 'groq' | 'deepseek' | 'together' | 'xai' | 'fireworks' | 'anyscale' | 'huggingface' | 'azure' | 'bedrock' | 'vertex-ai';
31
+ //# sourceMappingURL=common.d.ts.map
@@ -0,0 +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,aAAa,GACb,OAAO,GACP,SAAS,GACT,WAAW,CAAC"}
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ /**
3
+ * Common types used throughout the SDK
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ //# sourceMappingURL=common.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"common.js","sourceRoot":"","sources":["../../src/types/common.ts"],"names":[],"mappings":"AAAA;;GAEG"}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Common types used throughout the SDK
3
+ */
4
+ export {};
5
+ //# sourceMappingURL=common.js.map
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Error type definitions
3
+ */
4
+ export interface ScanResult {
5
+ safe: boolean;
6
+ label: 0 | 1;
7
+ confidence: number;
8
+ injection: number;
9
+ sensitivity: 'low' | 'medium' | 'high';
10
+ }
11
+ export interface LockLLMErrorData {
12
+ message: string;
13
+ type: string;
14
+ code?: string;
15
+ status?: number;
16
+ requestId?: string;
17
+ [key: string]: any;
18
+ }
19
+ export interface PromptInjectionErrorData extends LockLLMErrorData {
20
+ scanResult: ScanResult;
21
+ }
22
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +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"}
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ /**
3
+ * Error type definitions
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/types/errors.ts"],"names":[],"mappings":"AAAA;;GAEG"}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Error type definitions
3
+ */
4
+ export {};
5
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Provider-specific types
3
+ */
4
+ export declare const PROVIDER_BASE_URLS: {
5
+ readonly openai: "https://api.openai.com";
6
+ readonly anthropic: "https://api.anthropic.com";
7
+ readonly gemini: "https://generativelanguage.googleapis.com";
8
+ readonly cohere: "https://api.cohere.com";
9
+ readonly openrouter: "https://openrouter.ai";
10
+ readonly perplexity: "https://api.perplexity.ai";
11
+ readonly mistral: "https://api.mistral.ai";
12
+ readonly groq: "https://api.groq.com";
13
+ readonly deepseek: "https://api.deepseek.com";
14
+ readonly together: "https://api.together.xyz";
15
+ readonly xai: "https://api.x.ai";
16
+ readonly fireworks: "https://api.fireworks.ai";
17
+ readonly anyscale: "https://api.endpoints.anyscale.com";
18
+ readonly huggingface: "https://router.huggingface.co";
19
+ readonly azure: "";
20
+ readonly bedrock: "";
21
+ readonly 'vertex-ai': "";
22
+ };
23
+ export type ProviderName = keyof typeof PROVIDER_BASE_URLS;
24
+ //# sourceMappingURL=providers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"providers.d.ts","sourceRoot":"","sources":["../../src/types/providers.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;;;;;CAkBrB,CAAC;AAEX,MAAM,MAAM,YAAY,GAAG,MAAM,OAAO,kBAAkB,CAAC"}
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ /**
3
+ * Provider-specific types
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.PROVIDER_BASE_URLS = void 0;
7
+ exports.PROVIDER_BASE_URLS = {
8
+ openai: 'https://api.openai.com',
9
+ anthropic: 'https://api.anthropic.com',
10
+ gemini: 'https://generativelanguage.googleapis.com',
11
+ cohere: 'https://api.cohere.com',
12
+ openrouter: 'https://openrouter.ai',
13
+ perplexity: 'https://api.perplexity.ai',
14
+ mistral: 'https://api.mistral.ai',
15
+ groq: 'https://api.groq.com',
16
+ deepseek: 'https://api.deepseek.com',
17
+ together: 'https://api.together.xyz',
18
+ xai: 'https://api.x.ai',
19
+ fireworks: 'https://api.fireworks.ai',
20
+ anyscale: 'https://api.endpoints.anyscale.com',
21
+ huggingface: 'https://router.huggingface.co',
22
+ azure: '', // Custom endpoint URL required
23
+ bedrock: '', // Custom endpoint URL required
24
+ 'vertex-ai': '', // Custom endpoint URL required
25
+ };
26
+ //# sourceMappingURL=providers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"providers.js","sourceRoot":"","sources":["../../src/types/providers.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,CAAC,MAAM,kBAAkB,GAAG;IAChC,MAAM,EAAE,wBAAwB;IAChC,SAAS,EAAE,2BAA2B;IACtC,MAAM,EAAE,2CAA2C;IACnD,MAAM,EAAE,wBAAwB;IAChC,UAAU,EAAE,uBAAuB;IACnC,UAAU,EAAE,2BAA2B;IACvC,OAAO,EAAE,wBAAwB;IACjC,IAAI,EAAE,sBAAsB;IAC5B,QAAQ,EAAE,0BAA0B;IACpC,QAAQ,EAAE,0BAA0B;IACpC,GAAG,EAAE,kBAAkB;IACvB,SAAS,EAAE,0BAA0B;IACrC,QAAQ,EAAE,oCAAoC;IAC9C,WAAW,EAAE,+BAA+B;IAC5C,KAAK,EAAE,EAAE,EAAE,+BAA+B;IAC1C,OAAO,EAAE,EAAE,EAAE,+BAA+B;IAC5C,WAAW,EAAE,EAAE,EAAE,+BAA+B;CACxC,CAAC"}
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Provider-specific types
3
+ */
4
+ export const PROVIDER_BASE_URLS = {
5
+ openai: 'https://api.openai.com',
6
+ anthropic: 'https://api.anthropic.com',
7
+ gemini: 'https://generativelanguage.googleapis.com',
8
+ cohere: 'https://api.cohere.com',
9
+ openrouter: 'https://openrouter.ai',
10
+ perplexity: 'https://api.perplexity.ai',
11
+ mistral: 'https://api.mistral.ai',
12
+ groq: 'https://api.groq.com',
13
+ deepseek: 'https://api.deepseek.com',
14
+ together: 'https://api.together.xyz',
15
+ xai: 'https://api.x.ai',
16
+ fireworks: 'https://api.fireworks.ai',
17
+ anyscale: 'https://api.endpoints.anyscale.com',
18
+ huggingface: 'https://router.huggingface.co',
19
+ azure: '', // Custom endpoint URL required
20
+ bedrock: '', // Custom endpoint URL required
21
+ 'vertex-ai': '', // Custom endpoint URL required
22
+ };
23
+ //# sourceMappingURL=providers.js.map
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Scan API types
3
+ */
4
+ import type { ScanResult } from './errors';
5
+ export type Sensitivity = 'low' | 'medium' | 'high';
6
+ export interface ScanRequest {
7
+ /** The text prompt to scan for injection attacks */
8
+ input: string;
9
+ /** Detection sensitivity level (default: medium) */
10
+ sensitivity?: Sensitivity;
11
+ }
12
+ /**
13
+ * Full scan response from the scan API endpoint
14
+ * Extends the base ScanResult with additional metadata
15
+ */
16
+ export interface ScanResponse extends ScanResult {
17
+ /** Unique request identifier */
18
+ request_id: string;
19
+ /** Usage statistics */
20
+ usage: {
21
+ /** Number of upstream inference requests */
22
+ requests: number;
23
+ /** Number of input characters processed */
24
+ input_chars: number;
25
+ };
26
+ /** Debug information (only available with pro plan) */
27
+ debug?: {
28
+ /** Total processing duration in milliseconds */
29
+ duration_ms: number;
30
+ /** Inference time in milliseconds */
31
+ inference_ms: number;
32
+ /** Processing mode used */
33
+ mode: 'single' | 'chunked';
34
+ };
35
+ }
36
+ //# sourceMappingURL=scan.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scan.d.ts","sourceRoot":"","sources":["../../src/types/scan.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAE3C,MAAM,MAAM,WAAW,GAAG,KAAK,GAAG,QAAQ,GAAG,MAAM,CAAC;AAEpD,MAAM,WAAW,WAAW;IAC1B,oDAAoD;IACpD,KAAK,EAAE,MAAM,CAAC;IACd,oDAAoD;IACpD,WAAW,CAAC,EAAE,WAAW,CAAC;CAC3B;AAED;;;GAGG;AACH,MAAM,WAAW,YAAa,SAAQ,UAAU;IAC9C,gCAAgC;IAChC,UAAU,EAAE,MAAM,CAAC;IACnB,uBAAuB;IACvB,KAAK,EAAE;QACL,4CAA4C;QAC5C,QAAQ,EAAE,MAAM,CAAC;QACjB,2CAA2C;QAC3C,WAAW,EAAE,MAAM,CAAC;KACrB,CAAC;IACF,uDAAuD;IACvD,KAAK,CAAC,EAAE;QACN,gDAAgD;QAChD,WAAW,EAAE,MAAM,CAAC;QACpB,qCAAqC;QACrC,YAAY,EAAE,MAAM,CAAC;QACrB,2BAA2B;QAC3B,IAAI,EAAE,QAAQ,GAAG,SAAS,CAAC;KAC5B,CAAC;CACH"}
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ /**
3
+ * Scan API types
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ //# sourceMappingURL=scan.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scan.js","sourceRoot":"","sources":["../../src/types/scan.ts"],"names":[],"mappings":"AAAA;;GAEG"}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Scan API types
3
+ */
4
+ export {};
5
+ //# sourceMappingURL=scan.js.map