@artemiskit/sdk 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,436 @@
1
+ /**
2
+ * Guardian Mode Types
3
+ *
4
+ * Types and interfaces for the ArtemisKit Guardian Mode -
5
+ * runtime protection and validation for AI/LLM agents.
6
+ */
7
+
8
+ /**
9
+ * Guardian operating mode
10
+ */
11
+ export type GuardianMode = 'testing' | 'guardian' | 'hybrid';
12
+
13
+ /**
14
+ * Severity levels for violations
15
+ */
16
+ export type ViolationSeverity = 'low' | 'medium' | 'high' | 'critical';
17
+
18
+ /**
19
+ * Action to take when a violation is detected
20
+ */
21
+ export type ViolationAction = 'allow' | 'warn' | 'block' | 'transform';
22
+
23
+ /**
24
+ * Types of guardrails available
25
+ */
26
+ export type GuardrailType =
27
+ | 'input_validation'
28
+ | 'output_validation'
29
+ | 'action_validation'
30
+ | 'intent_classification'
31
+ | 'pii_detection'
32
+ | 'injection_detection'
33
+ | 'content_filter'
34
+ | 'hallucination_check'
35
+ | 'rate_limit'
36
+ | 'cost_limit';
37
+
38
+ /**
39
+ * Violation detected by guardrails
40
+ */
41
+ export interface Violation {
42
+ id: string;
43
+ type: GuardrailType;
44
+ severity: ViolationSeverity;
45
+ message: string;
46
+ details?: Record<string, unknown>;
47
+ timestamp: Date;
48
+ action: ViolationAction;
49
+ blocked: boolean;
50
+ }
51
+
52
+ /**
53
+ * Result of a guardrail check
54
+ */
55
+ export interface GuardrailResult {
56
+ passed: boolean;
57
+ violations: Violation[];
58
+ transformedContent?: string;
59
+ metadata?: Record<string, unknown>;
60
+ }
61
+
62
+ /**
63
+ * Policy rule for guardrails
64
+ */
65
+ export interface PolicyRule {
66
+ id: string;
67
+ name: string;
68
+ description?: string;
69
+ type: GuardrailType;
70
+ enabled: boolean;
71
+ severity: ViolationSeverity;
72
+ action: ViolationAction;
73
+ config?: Record<string, unknown>;
74
+ conditions?: PolicyCondition[];
75
+ }
76
+
77
+ /**
78
+ * Condition for policy rules
79
+ */
80
+ export interface PolicyCondition {
81
+ field: string;
82
+ operator:
83
+ | 'equals'
84
+ | 'contains'
85
+ | 'matches'
86
+ | 'not_equals'
87
+ | 'not_contains'
88
+ | 'greater_than'
89
+ | 'less_than';
90
+ value: string | number | boolean | RegExp;
91
+ }
92
+
93
+ /**
94
+ * Guardian policy configuration
95
+ */
96
+ export interface GuardianPolicy {
97
+ name: string;
98
+ version: string;
99
+ description?: string;
100
+ mode: GuardianMode;
101
+ rules: PolicyRule[];
102
+ defaults?: {
103
+ severity?: ViolationSeverity;
104
+ action?: ViolationAction;
105
+ };
106
+ circuitBreaker?: CircuitBreakerConfig;
107
+ rateLimits?: RateLimitConfig;
108
+ costLimits?: CostLimitConfig;
109
+ }
110
+
111
+ /**
112
+ * Circuit breaker configuration
113
+ */
114
+ export interface CircuitBreakerConfig {
115
+ enabled: boolean;
116
+ threshold: number;
117
+ windowMs: number;
118
+ cooldownMs: number;
119
+ halfOpenRequests?: number;
120
+ }
121
+
122
+ /**
123
+ * Rate limiting configuration
124
+ */
125
+ export interface RateLimitConfig {
126
+ enabled: boolean;
127
+ requestsPerMinute?: number;
128
+ requestsPerHour?: number;
129
+ requestsPerDay?: number;
130
+ burstLimit?: number;
131
+ }
132
+
133
+ /**
134
+ * Cost limiting configuration
135
+ */
136
+ export interface CostLimitConfig {
137
+ enabled: boolean;
138
+ maxCostPerRequest?: number;
139
+ maxCostPerMinute?: number;
140
+ maxCostPerHour?: number;
141
+ maxCostPerDay?: number;
142
+ currency?: string;
143
+ }
144
+
145
+ /**
146
+ * Action definition for agent tool/function calls
147
+ */
148
+ export interface ActionDefinition {
149
+ name: string;
150
+ description?: string;
151
+ category?: string;
152
+ riskLevel?: ViolationSeverity;
153
+ parameters?: ActionParameter[];
154
+ allowed?: boolean;
155
+ requiresApproval?: boolean;
156
+ maxCallsPerMinute?: number;
157
+ }
158
+
159
+ /**
160
+ * Action parameter definition
161
+ */
162
+ export interface ActionParameter {
163
+ name: string;
164
+ type: string;
165
+ required?: boolean;
166
+ validation?: ParameterValidation;
167
+ }
168
+
169
+ /**
170
+ * Parameter validation rules
171
+ */
172
+ export interface ParameterValidation {
173
+ pattern?: string;
174
+ minLength?: number;
175
+ maxLength?: number;
176
+ minValue?: number;
177
+ maxValue?: number;
178
+ allowedValues?: (string | number)[];
179
+ blockedValues?: (string | number)[];
180
+ blockedPatterns?: string[];
181
+ }
182
+
183
+ /**
184
+ * Intent classification result
185
+ */
186
+ export interface IntentClassification {
187
+ intent: string;
188
+ confidence: number;
189
+ category?: string;
190
+ riskLevel?: ViolationSeverity;
191
+ subIntents?: IntentClassification[];
192
+ }
193
+
194
+ /**
195
+ * PII detection result
196
+ */
197
+ export interface PIIDetection {
198
+ found: boolean;
199
+ types: PIIType[];
200
+ locations: PIILocation[];
201
+ redactedContent?: string;
202
+ }
203
+
204
+ /**
205
+ * Types of PII that can be detected
206
+ */
207
+ export type PIIType =
208
+ | 'email'
209
+ | 'phone'
210
+ | 'ssn'
211
+ | 'credit_card'
212
+ | 'ip_address'
213
+ | 'address'
214
+ | 'name'
215
+ | 'date_of_birth'
216
+ | 'password'
217
+ | 'api_key'
218
+ | 'jwt_token'
219
+ | 'custom';
220
+
221
+ /**
222
+ * Location of detected PII
223
+ */
224
+ export interface PIILocation {
225
+ type: PIIType;
226
+ start: number;
227
+ end: number;
228
+ value?: string;
229
+ masked?: string;
230
+ }
231
+
232
+ /**
233
+ * Injection detection result
234
+ */
235
+ export interface InjectionDetection {
236
+ detected: boolean;
237
+ type?: InjectionType;
238
+ confidence: number;
239
+ pattern?: string;
240
+ location?: { start: number; end: number };
241
+ }
242
+
243
+ /**
244
+ * Types of injections that can be detected
245
+ */
246
+ export type InjectionType =
247
+ | 'prompt_injection'
248
+ | 'jailbreak'
249
+ | 'role_hijack'
250
+ | 'instruction_override'
251
+ | 'data_extraction'
252
+ | 'system_prompt_leak'
253
+ | 'delimiter_attack'
254
+ | 'encoding_attack';
255
+
256
+ /**
257
+ * Content filter result
258
+ */
259
+ export interface ContentFilterResult {
260
+ passed: boolean;
261
+ flags: ContentFlag[];
262
+ categories: ContentCategory[];
263
+ }
264
+
265
+ /**
266
+ * Content flag
267
+ */
268
+ export interface ContentFlag {
269
+ category: ContentCategory;
270
+ severity: ViolationSeverity;
271
+ confidence: number;
272
+ snippet?: string;
273
+ }
274
+
275
+ /**
276
+ * Content categories for filtering
277
+ */
278
+ export type ContentCategory =
279
+ | 'violence'
280
+ | 'hate_speech'
281
+ | 'sexual'
282
+ | 'self_harm'
283
+ | 'dangerous'
284
+ | 'illegal'
285
+ | 'harassment'
286
+ | 'misinformation'
287
+ | 'spam'
288
+ | 'profanity';
289
+
290
+ /**
291
+ * Hallucination check result
292
+ */
293
+ export interface HallucinationCheckResult {
294
+ passed: boolean;
295
+ confidence: number;
296
+ citations?: Citation[];
297
+ unsupportedClaims?: UnsupportedClaim[];
298
+ }
299
+
300
+ /**
301
+ * Citation for hallucination checking
302
+ */
303
+ export interface Citation {
304
+ claim: string;
305
+ source?: string;
306
+ verified: boolean;
307
+ }
308
+
309
+ /**
310
+ * Unsupported claim detected
311
+ */
312
+ export interface UnsupportedClaim {
313
+ claim: string;
314
+ reason: string;
315
+ suggestedFix?: string;
316
+ }
317
+
318
+ /**
319
+ * Guardian metrics
320
+ */
321
+ export interface GuardianMetrics {
322
+ totalRequests: number;
323
+ blockedRequests: number;
324
+ warnedRequests: number;
325
+ allowedRequests: number;
326
+ violationsByType: Record<GuardrailType, number>;
327
+ violationsBySeverity: Record<ViolationSeverity, number>;
328
+ averageLatencyMs: number;
329
+ circuitBreakerState: CircuitBreakerState;
330
+ requestsPerSecond: number;
331
+ costTracking?: CostTracking;
332
+ }
333
+
334
+ /**
335
+ * Circuit breaker state
336
+ */
337
+ export type CircuitBreakerState = 'closed' | 'open' | 'half-open';
338
+
339
+ /**
340
+ * Cost tracking metrics
341
+ */
342
+ export interface CostTracking {
343
+ totalCost: number;
344
+ costPerMinute: number;
345
+ costPerHour: number;
346
+ costPerDay: number;
347
+ currency: string;
348
+ }
349
+
350
+ /**
351
+ * Guardian event types
352
+ */
353
+ export type GuardianEventType =
354
+ | 'request_start'
355
+ | 'request_complete'
356
+ | 'violation_detected'
357
+ | 'request_blocked'
358
+ | 'circuit_breaker_open'
359
+ | 'circuit_breaker_close'
360
+ | 'rate_limit_exceeded'
361
+ | 'cost_limit_exceeded';
362
+
363
+ /**
364
+ * Guardian event
365
+ */
366
+ export interface GuardianEvent {
367
+ type: GuardianEventType;
368
+ timestamp: Date;
369
+ data: Record<string, unknown>;
370
+ }
371
+
372
+ /**
373
+ * Guardian event handler
374
+ */
375
+ export type GuardianEventHandler = (event: GuardianEvent) => void;
376
+
377
+ /**
378
+ * Input/output wrapper for interceptor
379
+ */
380
+ export interface InterceptedRequest {
381
+ id: string;
382
+ input: string | unknown[];
383
+ metadata?: Record<string, unknown>;
384
+ timestamp: Date;
385
+ }
386
+
387
+ /**
388
+ * Intercepted response
389
+ */
390
+ export interface InterceptedResponse {
391
+ id: string;
392
+ requestId: string;
393
+ output: string;
394
+ metadata?: Record<string, unknown>;
395
+ timestamp: Date;
396
+ latencyMs: number;
397
+ }
398
+
399
+ /**
400
+ * Framework integration types
401
+ */
402
+ export type FrameworkType = 'langchain' | 'crewai' | 'autogen' | 'custom';
403
+
404
+ /**
405
+ * Framework integration config
406
+ */
407
+ export interface FrameworkIntegrationConfig {
408
+ framework: FrameworkType;
409
+ enabled: boolean;
410
+ interceptTools?: boolean;
411
+ interceptMessages?: boolean;
412
+ interceptAgentSteps?: boolean;
413
+ }
414
+
415
+ /**
416
+ * Tool call intercepted from agentic frameworks
417
+ */
418
+ export interface InterceptedToolCall {
419
+ id: string;
420
+ toolName: string;
421
+ arguments: Record<string, unknown>;
422
+ agentId?: string;
423
+ timestamp: Date;
424
+ }
425
+
426
+ /**
427
+ * Agent step intercepted from agentic frameworks
428
+ */
429
+ export interface InterceptedAgentStep {
430
+ id: string;
431
+ agentId: string;
432
+ stepType: 'plan' | 'execute' | 'observe' | 'reflect';
433
+ input: unknown;
434
+ output?: unknown;
435
+ timestamp: Date;
436
+ }
package/src/index.ts ADDED
@@ -0,0 +1,164 @@
1
+ /**
2
+ * @artemiskit/sdk
3
+ * Programmatic SDK for ArtemisKit LLM evaluation toolkit
4
+ */
5
+
6
+ // Main class
7
+ export { ArtemisKit } from './artemiskit';
8
+
9
+ // Types
10
+ export type {
11
+ // Configuration
12
+ ArtemisKitConfig,
13
+ RunOptions,
14
+ RedTeamOptions,
15
+ StressOptions,
16
+ // Results
17
+ RunResult,
18
+ RedTeamResult,
19
+ StressResult,
20
+ // Events
21
+ CaseStartEvent,
22
+ CaseCompleteEvent,
23
+ ProgressEvent,
24
+ RedTeamMutationStartEvent,
25
+ RedTeamMutationCompleteEvent,
26
+ StressRequestCompleteEvent,
27
+ // Event handlers
28
+ CaseStartHandler,
29
+ CaseCompleteHandler,
30
+ ProgressHandler,
31
+ RedTeamMutationStartHandler,
32
+ RedTeamMutationCompleteHandler,
33
+ StressRequestCompleteHandler,
34
+ // Event emitter
35
+ ArtemisKitEvents,
36
+ ArtemisKitEventName,
37
+ } from './types';
38
+
39
+ // Re-export core types for convenience
40
+ export type {
41
+ // Core types
42
+ Scenario,
43
+ TestCase,
44
+ Expected,
45
+ Provider,
46
+ CaseResult,
47
+ RunManifest,
48
+ RedTeamManifest,
49
+ StressManifest,
50
+ RedTeamCaseResult,
51
+ StressRequestResult,
52
+ // Adapter types
53
+ ModelClient,
54
+ AdapterConfig,
55
+ GenerateOptions,
56
+ GenerateResult,
57
+ // Redaction
58
+ RedactionConfig,
59
+ } from '@artemiskit/core';
60
+
61
+ // Re-export redteam types for convenience
62
+ export type { Severity, SeverityInfo, CvssScore } from '@artemiskit/redteam';
63
+
64
+ // Export matchers
65
+ export {
66
+ artemiskitMatchers,
67
+ type ArtemisKitMatchers,
68
+ type MatcherResult,
69
+ } from './matchers';
70
+
71
+ // Export guardian module for runtime protection
72
+ export {
73
+ // Main Guardian class
74
+ Guardian,
75
+ createGuardian,
76
+ // Interceptor
77
+ GuardianInterceptor,
78
+ GuardianBlockedError,
79
+ createInterceptor,
80
+ // Action Validator
81
+ ActionValidator,
82
+ createDefaultActionValidator,
83
+ // Intent Classifier
84
+ IntentClassifier,
85
+ createIntentClassifier,
86
+ // Guardrails
87
+ detectInjection,
88
+ createInjectionGuardrail,
89
+ detectPII,
90
+ createPIIGuardrail,
91
+ filterContent,
92
+ createContentFilterGuardrail,
93
+ createGuardrails,
94
+ // Policy
95
+ loadPolicy,
96
+ parsePolicy,
97
+ validatePolicy,
98
+ createDefaultPolicy,
99
+ mergePolicies,
100
+ generatePolicyTemplate,
101
+ PolicyLoadError,
102
+ PolicyValidationError,
103
+ // Circuit Breaker and Metrics
104
+ CircuitBreaker,
105
+ MetricsCollector,
106
+ RateLimiter,
107
+ } from './guardian';
108
+
109
+ // Export guardian types
110
+ export type {
111
+ // Config types
112
+ GuardianConfig,
113
+ InterceptorConfig,
114
+ ActionValidatorConfig,
115
+ IntentClassifierConfig,
116
+ GuardrailsConfig,
117
+ RateLimiterConfig,
118
+ // Core types
119
+ GuardianMode,
120
+ ViolationSeverity,
121
+ ViolationAction,
122
+ GuardrailType,
123
+ Violation,
124
+ GuardrailResult,
125
+ // Policy types
126
+ PolicyRule,
127
+ PolicyCondition,
128
+ GuardianPolicy,
129
+ CircuitBreakerConfig,
130
+ RateLimitConfig,
131
+ CostLimitConfig,
132
+ // Action types
133
+ ActionDefinition,
134
+ ActionParameter,
135
+ ParameterValidation,
136
+ // Intent types
137
+ IntentClassification,
138
+ IntentCategory,
139
+ // Detection types
140
+ PIIDetection,
141
+ PIIType,
142
+ PIILocation,
143
+ InjectionDetection,
144
+ InjectionType,
145
+ ContentFilterResult,
146
+ ContentFlag,
147
+ ContentCategory,
148
+ // Metrics types
149
+ GuardianMetrics,
150
+ CircuitBreakerState,
151
+ CostTracking,
152
+ // Event types
153
+ GuardianEventType,
154
+ GuardianEvent,
155
+ GuardianEventHandler,
156
+ // Interceptor types
157
+ InterceptedRequest,
158
+ InterceptedResponse,
159
+ InterceptedToolCall,
160
+ InterceptedAgentStep,
161
+ // Framework types
162
+ FrameworkType,
163
+ FrameworkIntegrationConfig,
164
+ } from './guardian';