@lockllm/sdk 1.0.0 → 1.1.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 +146 -5
- package/README.md +238 -39
- package/dist/client.d.ts +1 -1
- package/dist/client.d.ts.map +1 -1
- package/dist/errors.d.ts +46 -1
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +104 -2
- package/dist/errors.js.map +1 -1
- package/dist/errors.mjs +100 -1
- package/dist/index.d.ts +6 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -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 +55 -5
- package/dist/scan.js.map +1 -1
- package/dist/scan.mjs +55 -5
- package/dist/types/common.d.ts +85 -0
- package/dist/types/common.d.ts.map +1 -1
- package/dist/types/errors.d.ts +33 -0
- package/dist/types/errors.d.ts.map +1 -1
- package/dist/types/scan.d.ts +102 -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 +175 -0
- package/dist/utils/proxy-headers.js.map +1 -0
- package/dist/utils/proxy-headers.mjs +170 -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 -18
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 } from './types/errors';
|
|
4
|
+
import type { ScanResult, LockLLMErrorData, PromptInjectionErrorData, PolicyViolationErrorData, AbuseDetectedErrorData, InsufficientCreditsErrorData } from './types/errors';
|
|
5
5
|
/**
|
|
6
6
|
* Base error class for all LockLLM errors
|
|
7
7
|
*/
|
|
@@ -46,6 +46,51 @@ export declare class UpstreamError extends LockLLMError {
|
|
|
46
46
|
export declare class ConfigurationError extends LockLLMError {
|
|
47
47
|
constructor(message: string);
|
|
48
48
|
}
|
|
49
|
+
/**
|
|
50
|
+
* Error thrown when custom policy violations are detected
|
|
51
|
+
*/
|
|
52
|
+
export declare class PolicyViolationError extends LockLLMError {
|
|
53
|
+
readonly violated_policies: Array<{
|
|
54
|
+
policy_name: string;
|
|
55
|
+
violated_categories: Array<{
|
|
56
|
+
name: string;
|
|
57
|
+
}>;
|
|
58
|
+
violation_details?: string;
|
|
59
|
+
}>;
|
|
60
|
+
constructor(data: PolicyViolationErrorData);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Error thrown when AI abuse is detected
|
|
64
|
+
*/
|
|
65
|
+
export declare class AbuseDetectedError extends LockLLMError {
|
|
66
|
+
readonly abuse_details: {
|
|
67
|
+
confidence: number;
|
|
68
|
+
abuse_types: string[];
|
|
69
|
+
indicators: {
|
|
70
|
+
bot_score: number;
|
|
71
|
+
repetition_score: number;
|
|
72
|
+
resource_score: number;
|
|
73
|
+
pattern_score: number;
|
|
74
|
+
};
|
|
75
|
+
recommendation?: string;
|
|
76
|
+
details?: {
|
|
77
|
+
recommendation?: string;
|
|
78
|
+
bot_indicators?: string[];
|
|
79
|
+
repetition_indicators?: string[];
|
|
80
|
+
resource_indicators?: string[];
|
|
81
|
+
pattern_indicators?: string[];
|
|
82
|
+
};
|
|
83
|
+
};
|
|
84
|
+
constructor(data: AbuseDetectedErrorData);
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Error thrown when user has insufficient credits
|
|
88
|
+
*/
|
|
89
|
+
export declare class InsufficientCreditsError extends LockLLMError {
|
|
90
|
+
readonly current_balance: number;
|
|
91
|
+
readonly estimated_cost: number;
|
|
92
|
+
constructor(data: InsufficientCreditsErrorData);
|
|
93
|
+
}
|
|
49
94
|
/**
|
|
50
95
|
* Error thrown when network request fails
|
|
51
96
|
*/
|
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,
|
|
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,EAC7B,MAAM,gBAAgB,CAAC;AAExB;;GAEG;AACH,qBAAa,YAAa,SAAQ,KAAK;IACrC,SAAgB,IAAI,EAAE,MAAM,CAAC;IAC7B,SAAgB,IAAI,CAAC,EAAE,MAAM,CAAC;IAC9B,SAAgB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChC,SAAgB,SAAS,CAAC,EAAE,MAAM,CAAC;gBAEvB,IAAI,EAAE,gBAAgB;CAanC;AAED;;GAEG;AACH,qBAAa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AAc,EAAE,MAAM,CAAC;YACvB,aAAa,EAAE,MAAM,CAAC;SACvB,CAAC;QACF,cAAc,CAAC,EAAE,MAAM,CAAC;QACxB,OAAO,CAAC,EAAE;YACR,cAAc,CAAC,EAAE,MAAM,CAAC;YACxB,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;YAC1B,qBAAqB,CAAC,EAAE,MAAM,EAAE,CAAC;YACjC,mBAAmB,CAAC,EAAE,MAAM,EAAE,CAAC;YAC/B,kBAAkB,CAAC,EAAE,MAAM,EAAE,CAAC;SAC/B,CAAC;KACH,CAAC;gBAEU,IAAI,EAAE,sBAAsB;CAWzC;AAED;;GAEG;AACH,qBAAa,wBAAyB,SAAQ,YAAY;IACxD,SAAgB,eAAe,EAAE,MAAM,CAAC;IACxC,SAAgB,cAAc,EAAE,MAAM,CAAC;gBAE3B,IAAI,EAAE,4BAA4B;CAY/C;AAED;;GAEG;AACH,qBAAa,YAAa,SAAQ,YAAY;IAC5C,SAAgB,KAAK,CAAC,EAAE,KAAK,CAAC;gBAElB,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,KAAK,EAAE,SAAS,CAAC,EAAE,MAAM;CAW/D;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,QAAQ,EAAE,GAAG,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,YAAY,CA8G1E"}
|
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.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,58 @@ 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 user has insufficient credits
|
|
145
|
+
*/
|
|
146
|
+
class InsufficientCreditsError extends LockLLMError {
|
|
147
|
+
constructor(data) {
|
|
148
|
+
super({
|
|
149
|
+
message: data.message,
|
|
150
|
+
type: 'lockllm_balance_error',
|
|
151
|
+
code: 'insufficient_credits',
|
|
152
|
+
status: 402,
|
|
153
|
+
requestId: data.requestId,
|
|
154
|
+
});
|
|
155
|
+
this.name = 'InsufficientCreditsError';
|
|
156
|
+
this.current_balance = data.current_balance;
|
|
157
|
+
this.estimated_cost = data.estimated_cost;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
exports.InsufficientCreditsError = InsufficientCreditsError;
|
|
109
161
|
/**
|
|
110
162
|
* Error thrown when network request fails
|
|
111
163
|
*/
|
|
@@ -146,6 +198,40 @@ function parseError(response, requestId) {
|
|
|
146
198
|
scanResult: error.scan_result,
|
|
147
199
|
});
|
|
148
200
|
}
|
|
201
|
+
// Policy violation error
|
|
202
|
+
if (error.code === 'policy_violation' && error.violated_policies) {
|
|
203
|
+
return new PolicyViolationError({
|
|
204
|
+
message: error.message,
|
|
205
|
+
type: error.type,
|
|
206
|
+
code: error.code,
|
|
207
|
+
status: 403,
|
|
208
|
+
requestId: error.request_id || requestId,
|
|
209
|
+
violated_policies: error.violated_policies,
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
// Abuse detected error
|
|
213
|
+
if (error.code === 'abuse_detected' && error.abuse_details) {
|
|
214
|
+
return new AbuseDetectedError({
|
|
215
|
+
message: error.message,
|
|
216
|
+
type: error.type,
|
|
217
|
+
code: error.code,
|
|
218
|
+
status: 400,
|
|
219
|
+
requestId: error.request_id || requestId,
|
|
220
|
+
abuse_details: error.abuse_details,
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
// Insufficient credits error
|
|
224
|
+
if (error.code === 'insufficient_credits' || error.code === 'insufficient_routing_credits') {
|
|
225
|
+
return new InsufficientCreditsError({
|
|
226
|
+
message: error.message,
|
|
227
|
+
type: error.type,
|
|
228
|
+
code: error.code,
|
|
229
|
+
status: 402,
|
|
230
|
+
requestId: error.request_id || requestId,
|
|
231
|
+
current_balance: error.current_balance || 0,
|
|
232
|
+
estimated_cost: error.estimated_cost || 0,
|
|
233
|
+
});
|
|
234
|
+
}
|
|
149
235
|
// Authentication error
|
|
150
236
|
if (error.type === 'authentication_error' || error.code === 'unauthorized') {
|
|
151
237
|
return new AuthenticationError(error.message, requestId);
|
|
@@ -158,10 +244,26 @@ function parseError(response, requestId) {
|
|
|
158
244
|
if (error.type === 'upstream_error' || error.code === 'provider_error') {
|
|
159
245
|
return new UpstreamError(error.message, undefined, undefined, requestId);
|
|
160
246
|
}
|
|
247
|
+
// Balance/credits errors
|
|
248
|
+
if (error.code === 'no_balance' ||
|
|
249
|
+
error.code === 'balance_check_failed' ||
|
|
250
|
+
error.code === 'credits_unavailable' ||
|
|
251
|
+
error.code === 'invalid_provider_for_credits_mode') {
|
|
252
|
+
return new InsufficientCreditsError({
|
|
253
|
+
message: error.message,
|
|
254
|
+
type: error.type,
|
|
255
|
+
code: error.code,
|
|
256
|
+
status: 402,
|
|
257
|
+
requestId: error.request_id || requestId,
|
|
258
|
+
current_balance: error.current_balance || 0,
|
|
259
|
+
estimated_cost: error.estimated_cost || 0,
|
|
260
|
+
});
|
|
261
|
+
}
|
|
161
262
|
// Configuration error
|
|
162
263
|
if (error.type === 'configuration_error' ||
|
|
163
264
|
error.type === 'lockllm_config_error' ||
|
|
164
|
-
error.code === 'no_upstream_key'
|
|
265
|
+
error.code === 'no_upstream_key' ||
|
|
266
|
+
error.code === 'no_byok_key') {
|
|
165
267
|
return new ConfigurationError(error.message);
|
|
166
268
|
}
|
|
167
269
|
// 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;AAWH;;GAEG;AACH,MAAM,OAAO,YAAa,SAAQ,KAAK;IAMrC,YAAY,IAAsB;QAChC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACpB,IAAI,CAAC,IAAI,GAAG,cAAc,CAA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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
|
@@ -96,6 +96,55 @@ 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 user has insufficient credits
|
|
133
|
+
*/
|
|
134
|
+
export class InsufficientCreditsError extends LockLLMError {
|
|
135
|
+
constructor(data) {
|
|
136
|
+
super({
|
|
137
|
+
message: data.message,
|
|
138
|
+
type: 'lockllm_balance_error',
|
|
139
|
+
code: 'insufficient_credits',
|
|
140
|
+
status: 402,
|
|
141
|
+
requestId: data.requestId,
|
|
142
|
+
});
|
|
143
|
+
this.name = 'InsufficientCreditsError';
|
|
144
|
+
this.current_balance = data.current_balance;
|
|
145
|
+
this.estimated_cost = data.estimated_cost;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
99
148
|
/**
|
|
100
149
|
* Error thrown when network request fails
|
|
101
150
|
*/
|
|
@@ -135,6 +184,40 @@ export function parseError(response, requestId) {
|
|
|
135
184
|
scanResult: error.scan_result,
|
|
136
185
|
});
|
|
137
186
|
}
|
|
187
|
+
// Policy violation error
|
|
188
|
+
if (error.code === 'policy_violation' && error.violated_policies) {
|
|
189
|
+
return new PolicyViolationError({
|
|
190
|
+
message: error.message,
|
|
191
|
+
type: error.type,
|
|
192
|
+
code: error.code,
|
|
193
|
+
status: 403,
|
|
194
|
+
requestId: error.request_id || requestId,
|
|
195
|
+
violated_policies: error.violated_policies,
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
// Abuse detected error
|
|
199
|
+
if (error.code === 'abuse_detected' && error.abuse_details) {
|
|
200
|
+
return new AbuseDetectedError({
|
|
201
|
+
message: error.message,
|
|
202
|
+
type: error.type,
|
|
203
|
+
code: error.code,
|
|
204
|
+
status: 400,
|
|
205
|
+
requestId: error.request_id || requestId,
|
|
206
|
+
abuse_details: error.abuse_details,
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
// Insufficient credits error
|
|
210
|
+
if (error.code === 'insufficient_credits' || error.code === 'insufficient_routing_credits') {
|
|
211
|
+
return new InsufficientCreditsError({
|
|
212
|
+
message: error.message,
|
|
213
|
+
type: error.type,
|
|
214
|
+
code: error.code,
|
|
215
|
+
status: 402,
|
|
216
|
+
requestId: error.request_id || requestId,
|
|
217
|
+
current_balance: error.current_balance || 0,
|
|
218
|
+
estimated_cost: error.estimated_cost || 0,
|
|
219
|
+
});
|
|
220
|
+
}
|
|
138
221
|
// Authentication error
|
|
139
222
|
if (error.type === 'authentication_error' || error.code === 'unauthorized') {
|
|
140
223
|
return new AuthenticationError(error.message, requestId);
|
|
@@ -147,10 +230,26 @@ export function parseError(response, requestId) {
|
|
|
147
230
|
if (error.type === 'upstream_error' || error.code === 'provider_error') {
|
|
148
231
|
return new UpstreamError(error.message, undefined, undefined, requestId);
|
|
149
232
|
}
|
|
233
|
+
// Balance/credits errors
|
|
234
|
+
if (error.code === 'no_balance' ||
|
|
235
|
+
error.code === 'balance_check_failed' ||
|
|
236
|
+
error.code === 'credits_unavailable' ||
|
|
237
|
+
error.code === 'invalid_provider_for_credits_mode') {
|
|
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
|
+
}
|
|
150
248
|
// Configuration error
|
|
151
249
|
if (error.type === 'configuration_error' ||
|
|
152
250
|
error.type === 'lockllm_config_error' ||
|
|
153
|
-
error.code === 'no_upstream_key'
|
|
251
|
+
error.code === 'no_upstream_key' ||
|
|
252
|
+
error.code === 'no_byok_key') {
|
|
154
253
|
return new ConfigurationError(error.message);
|
|
155
254
|
}
|
|
156
255
|
// 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, 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';
|
|
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,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,GACb,MAAM,cAAc,CAAC;AAEtB,YAAY,EACV,UAAU,EACV,gBAAgB,EAChB,wBAAwB,EACxB,wBAAwB,EACxB,sBAAsB,EACtB,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.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,9 @@ 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, "InsufficientCreditsError", { enumerable: true, get: function () { return errors_1.InsufficientCreditsError; } });
|
|
21
24
|
Object.defineProperty(exports, "UpstreamError", { enumerable: true, get: function () { return errors_1.UpstreamError; } });
|
|
22
25
|
Object.defineProperty(exports, "ConfigurationError", { enumerable: true, get: function () { return errors_1.ConfigurationError; } });
|
|
23
26
|
Object.defineProperty(exports, "NetworkError", { enumerable: true, get: function () { return errors_1.NetworkError; } });
|
|
@@ -25,6 +28,11 @@ Object.defineProperty(exports, "NetworkError", { enumerable: true, get: function
|
|
|
25
28
|
var utils_1 = require("./utils");
|
|
26
29
|
Object.defineProperty(exports, "getProxyURL", { enumerable: true, get: function () { return utils_1.getProxyURL; } });
|
|
27
30
|
Object.defineProperty(exports, "getAllProxyURLs", { enumerable: true, get: function () { return utils_1.getAllProxyURLs; } });
|
|
31
|
+
Object.defineProperty(exports, "getUniversalProxyURL", { enumerable: true, get: function () { return utils_1.getUniversalProxyURL; } });
|
|
32
|
+
var proxy_headers_1 = require("./utils/proxy-headers");
|
|
33
|
+
Object.defineProperty(exports, "buildLockLLMHeaders", { enumerable: true, get: function () { return proxy_headers_1.buildLockLLMHeaders; } });
|
|
34
|
+
Object.defineProperty(exports, "parseProxyMetadata", { enumerable: true, get: function () { return proxy_headers_1.parseProxyMetadata; } });
|
|
35
|
+
Object.defineProperty(exports, "decodeDetailField", { enumerable: true, get: function () { return proxy_headers_1.decodeDetailField; } });
|
|
28
36
|
// Wrappers (re-exported for convenience)
|
|
29
37
|
var wrappers_1 = require("./wrappers");
|
|
30
38
|
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,wBAAwB,EACxB,aAAa,EACb,kBAAkB,EAClB,YAAY,GACb,MAAM,UAAU,CAAC;AAmClB,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, 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;CAsDzB"}
|
package/dist/scan.js
CHANGED
|
@@ -12,27 +12,77 @@ 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
|
+
// Build request body
|
|
78
|
+
const body = {
|
|
33
79
|
input: request.input,
|
|
34
|
-
|
|
35
|
-
},
|
|
80
|
+
};
|
|
81
|
+
const { data } = await this.http.post('/v1/scan', body, {
|
|
82
|
+
headers,
|
|
83
|
+
timeout: options?.timeout,
|
|
84
|
+
signal: options?.signal,
|
|
85
|
+
});
|
|
36
86
|
return data;
|
|
37
87
|
}
|
|
38
88
|
}
|
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,"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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