@koreshield/koreshield 0.1.4

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,201 @@
1
+ /**
2
+ * KoreShield JavaScript/TypeScript SDK Types
3
+ */
4
+ interface KoreShieldConfig {
5
+ /** KoreShield proxy base URL */
6
+ baseURL: string;
7
+ /** API key for authentication (optional, can be set via environment) */
8
+ apiKey?: string;
9
+ /** Request timeout in milliseconds */
10
+ timeout?: number;
11
+ /** Enable debug logging */
12
+ debug?: boolean;
13
+ /** Custom headers to include in all requests */
14
+ headers?: Record<string, string>;
15
+ }
16
+ interface SecurityOptions {
17
+ /** Sensitivity level: 'low', 'medium', 'high' */
18
+ sensitivity?: 'low' | 'medium' | 'high';
19
+ /** Action on detection: 'allow', 'warn', 'block' */
20
+ defaultAction?: 'allow' | 'warn' | 'block';
21
+ /** Enable/disable specific security features */
22
+ features?: {
23
+ sanitization?: boolean;
24
+ detection?: boolean;
25
+ policyEnforcement?: boolean;
26
+ };
27
+ }
28
+ interface ChatCompletionRequest {
29
+ model: string;
30
+ messages: Array<{
31
+ role: 'system' | 'user' | 'assistant';
32
+ content: string;
33
+ }>;
34
+ temperature?: number;
35
+ max_tokens?: number;
36
+ top_p?: number;
37
+ frequency_penalty?: number;
38
+ presence_penalty?: number;
39
+ stop?: string | string[];
40
+ stream?: boolean;
41
+ [key: string]: any;
42
+ }
43
+ interface ChatCompletionResponse {
44
+ id: string;
45
+ object: string;
46
+ created: number;
47
+ model: string;
48
+ choices: Array<{
49
+ index: number;
50
+ message: {
51
+ role: string;
52
+ content: string;
53
+ };
54
+ finish_reason: string;
55
+ }>;
56
+ usage: {
57
+ prompt_tokens: number;
58
+ completion_tokens: number;
59
+ total_tokens: number;
60
+ };
61
+ }
62
+ interface SecurityEvent {
63
+ id: string;
64
+ timestamp: string;
65
+ type: 'attack_detected' | 'request_blocked' | 'sanitization_applied';
66
+ severity: 'low' | 'medium' | 'high' | 'critical';
67
+ description: string;
68
+ details?: Record<string, any>;
69
+ requestId?: string;
70
+ }
71
+ interface MetricsResponse {
72
+ requests_total: number;
73
+ requests_blocked: number;
74
+ attacks_detected: number;
75
+ avg_response_time: number;
76
+ active_connections: number;
77
+ uptime_seconds: number;
78
+ }
79
+ interface KoreShieldError extends Error {
80
+ code: string;
81
+ statusCode?: number;
82
+ details?: Record<string, any>;
83
+ }
84
+ type ProviderType = 'openai' | 'anthropic' | 'deepseek' | 'gemini' | 'azure';
85
+ interface ProviderConfig {
86
+ type: ProviderType;
87
+ apiKey?: string;
88
+ baseURL?: string;
89
+ organization?: string;
90
+ project?: string;
91
+ }
92
+
93
+ /**
94
+ * KoreShield Core Client
95
+ */
96
+
97
+ declare class KoreShieldClient {
98
+ private client;
99
+ private config;
100
+ constructor(config: KoreShieldConfig);
101
+ /**
102
+ * Create a chat completion request through KoreShield
103
+ */
104
+ createChatCompletion(request: ChatCompletionRequest, securityOptions?: SecurityOptions): Promise<ChatCompletionResponse>;
105
+ /**
106
+ * Get security events/logs
107
+ */
108
+ getSecurityEvents(limit?: number, offset?: number, type?: string, severity?: string): Promise<SecurityEvent[]>;
109
+ /**
110
+ * Get metrics and statistics
111
+ */
112
+ getMetrics(): Promise<MetricsResponse>;
113
+ /**
114
+ * Get Prometheus metrics in text format
115
+ */
116
+ getPrometheusMetrics(): Promise<string>;
117
+ /**
118
+ * Health check
119
+ */
120
+ health(): Promise<{
121
+ status: string;
122
+ version: string;
123
+ uptime: number;
124
+ }>;
125
+ /**
126
+ * Update security configuration
127
+ */
128
+ updateSecurityConfig(options: SecurityOptions): Promise<void>;
129
+ /**
130
+ * Test connection to KoreShield
131
+ */
132
+ testConnection(): Promise<boolean>;
133
+ private handleError;
134
+ }
135
+
136
+ declare class KoreShieldOpenAI {
137
+ private client;
138
+ constructor(config: KoreShieldConfig);
139
+ /**
140
+ * Chat completions API (OpenAI-compatible)
141
+ */
142
+ chat(_completions: any): Promise<{
143
+ create: (request: ChatCompletionRequest, securityOptions?: SecurityOptions) => Promise<ChatCompletionResponse>;
144
+ }>;
145
+ /**
146
+ * Get underlying KoreShield client for advanced operations
147
+ */
148
+ getClient(): KoreShieldClient;
149
+ }
150
+ /**
151
+ * Factory function to create OpenAI-compatible instance
152
+ */
153
+ declare function createKoreShieldOpenAI(config: KoreShieldConfig): KoreShieldOpenAI;
154
+
155
+ /**
156
+ * KoreShield Utility Functions
157
+ */
158
+
159
+ /**
160
+ * Validate KoreShield configuration
161
+ */
162
+ declare function validateConfig(config: KoreShieldConfig): {
163
+ valid: boolean;
164
+ errors: string[];
165
+ };
166
+ /**
167
+ * Create a KoreShield client with environment variable defaults
168
+ */
169
+ declare function createClient(config?: Partial<KoreShieldConfig>): KoreShieldClient;
170
+ /**
171
+ * Sanitize user input for safe LLM processing
172
+ */
173
+ declare function sanitizeInput(input: string): string;
174
+ /**
175
+ * Check if a response contains potentially unsafe content
176
+ */
177
+ declare function checkResponseSafety(response: string): {
178
+ safe: boolean;
179
+ issues: string[];
180
+ severity: 'low' | 'medium' | 'high';
181
+ };
182
+ /**
183
+ * Format chat messages for KoreShield
184
+ */
185
+ declare function formatMessages(messages: Array<{
186
+ role: string;
187
+ content: string;
188
+ }>): {
189
+ role: string;
190
+ content: string;
191
+ }[];
192
+ /**
193
+ * Sleep utility for rate limiting
194
+ */
195
+ declare function sleep(ms: number): Promise<void>;
196
+ /**
197
+ * Retry utility with exponential backoff
198
+ */
199
+ declare function retry<T>(fn: () => Promise<T>, maxRetries?: number, baseDelay?: number): Promise<T>;
200
+
201
+ export { ChatCompletionRequest, ChatCompletionResponse, KoreShieldClient, KoreShieldConfig, KoreShieldError, KoreShieldOpenAI, MetricsResponse, ProviderConfig, ProviderType, SecurityEvent, SecurityOptions, checkResponseSafety, createClient, createKoreShieldOpenAI, KoreShieldClient as default, formatMessages, retry, sanitizeInput, sleep, validateConfig };
@@ -0,0 +1,201 @@
1
+ /**
2
+ * KoreShield JavaScript/TypeScript SDK Types
3
+ */
4
+ interface KoreShieldConfig {
5
+ /** KoreShield proxy base URL */
6
+ baseURL: string;
7
+ /** API key for authentication (optional, can be set via environment) */
8
+ apiKey?: string;
9
+ /** Request timeout in milliseconds */
10
+ timeout?: number;
11
+ /** Enable debug logging */
12
+ debug?: boolean;
13
+ /** Custom headers to include in all requests */
14
+ headers?: Record<string, string>;
15
+ }
16
+ interface SecurityOptions {
17
+ /** Sensitivity level: 'low', 'medium', 'high' */
18
+ sensitivity?: 'low' | 'medium' | 'high';
19
+ /** Action on detection: 'allow', 'warn', 'block' */
20
+ defaultAction?: 'allow' | 'warn' | 'block';
21
+ /** Enable/disable specific security features */
22
+ features?: {
23
+ sanitization?: boolean;
24
+ detection?: boolean;
25
+ policyEnforcement?: boolean;
26
+ };
27
+ }
28
+ interface ChatCompletionRequest {
29
+ model: string;
30
+ messages: Array<{
31
+ role: 'system' | 'user' | 'assistant';
32
+ content: string;
33
+ }>;
34
+ temperature?: number;
35
+ max_tokens?: number;
36
+ top_p?: number;
37
+ frequency_penalty?: number;
38
+ presence_penalty?: number;
39
+ stop?: string | string[];
40
+ stream?: boolean;
41
+ [key: string]: any;
42
+ }
43
+ interface ChatCompletionResponse {
44
+ id: string;
45
+ object: string;
46
+ created: number;
47
+ model: string;
48
+ choices: Array<{
49
+ index: number;
50
+ message: {
51
+ role: string;
52
+ content: string;
53
+ };
54
+ finish_reason: string;
55
+ }>;
56
+ usage: {
57
+ prompt_tokens: number;
58
+ completion_tokens: number;
59
+ total_tokens: number;
60
+ };
61
+ }
62
+ interface SecurityEvent {
63
+ id: string;
64
+ timestamp: string;
65
+ type: 'attack_detected' | 'request_blocked' | 'sanitization_applied';
66
+ severity: 'low' | 'medium' | 'high' | 'critical';
67
+ description: string;
68
+ details?: Record<string, any>;
69
+ requestId?: string;
70
+ }
71
+ interface MetricsResponse {
72
+ requests_total: number;
73
+ requests_blocked: number;
74
+ attacks_detected: number;
75
+ avg_response_time: number;
76
+ active_connections: number;
77
+ uptime_seconds: number;
78
+ }
79
+ interface KoreShieldError extends Error {
80
+ code: string;
81
+ statusCode?: number;
82
+ details?: Record<string, any>;
83
+ }
84
+ type ProviderType = 'openai' | 'anthropic' | 'deepseek' | 'gemini' | 'azure';
85
+ interface ProviderConfig {
86
+ type: ProviderType;
87
+ apiKey?: string;
88
+ baseURL?: string;
89
+ organization?: string;
90
+ project?: string;
91
+ }
92
+
93
+ /**
94
+ * KoreShield Core Client
95
+ */
96
+
97
+ declare class KoreShieldClient {
98
+ private client;
99
+ private config;
100
+ constructor(config: KoreShieldConfig);
101
+ /**
102
+ * Create a chat completion request through KoreShield
103
+ */
104
+ createChatCompletion(request: ChatCompletionRequest, securityOptions?: SecurityOptions): Promise<ChatCompletionResponse>;
105
+ /**
106
+ * Get security events/logs
107
+ */
108
+ getSecurityEvents(limit?: number, offset?: number, type?: string, severity?: string): Promise<SecurityEvent[]>;
109
+ /**
110
+ * Get metrics and statistics
111
+ */
112
+ getMetrics(): Promise<MetricsResponse>;
113
+ /**
114
+ * Get Prometheus metrics in text format
115
+ */
116
+ getPrometheusMetrics(): Promise<string>;
117
+ /**
118
+ * Health check
119
+ */
120
+ health(): Promise<{
121
+ status: string;
122
+ version: string;
123
+ uptime: number;
124
+ }>;
125
+ /**
126
+ * Update security configuration
127
+ */
128
+ updateSecurityConfig(options: SecurityOptions): Promise<void>;
129
+ /**
130
+ * Test connection to KoreShield
131
+ */
132
+ testConnection(): Promise<boolean>;
133
+ private handleError;
134
+ }
135
+
136
+ declare class KoreShieldOpenAI {
137
+ private client;
138
+ constructor(config: KoreShieldConfig);
139
+ /**
140
+ * Chat completions API (OpenAI-compatible)
141
+ */
142
+ chat(_completions: any): Promise<{
143
+ create: (request: ChatCompletionRequest, securityOptions?: SecurityOptions) => Promise<ChatCompletionResponse>;
144
+ }>;
145
+ /**
146
+ * Get underlying KoreShield client for advanced operations
147
+ */
148
+ getClient(): KoreShieldClient;
149
+ }
150
+ /**
151
+ * Factory function to create OpenAI-compatible instance
152
+ */
153
+ declare function createKoreShieldOpenAI(config: KoreShieldConfig): KoreShieldOpenAI;
154
+
155
+ /**
156
+ * KoreShield Utility Functions
157
+ */
158
+
159
+ /**
160
+ * Validate KoreShield configuration
161
+ */
162
+ declare function validateConfig(config: KoreShieldConfig): {
163
+ valid: boolean;
164
+ errors: string[];
165
+ };
166
+ /**
167
+ * Create a KoreShield client with environment variable defaults
168
+ */
169
+ declare function createClient(config?: Partial<KoreShieldConfig>): KoreShieldClient;
170
+ /**
171
+ * Sanitize user input for safe LLM processing
172
+ */
173
+ declare function sanitizeInput(input: string): string;
174
+ /**
175
+ * Check if a response contains potentially unsafe content
176
+ */
177
+ declare function checkResponseSafety(response: string): {
178
+ safe: boolean;
179
+ issues: string[];
180
+ severity: 'low' | 'medium' | 'high';
181
+ };
182
+ /**
183
+ * Format chat messages for KoreShield
184
+ */
185
+ declare function formatMessages(messages: Array<{
186
+ role: string;
187
+ content: string;
188
+ }>): {
189
+ role: string;
190
+ content: string;
191
+ }[];
192
+ /**
193
+ * Sleep utility for rate limiting
194
+ */
195
+ declare function sleep(ms: number): Promise<void>;
196
+ /**
197
+ * Retry utility with exponential backoff
198
+ */
199
+ declare function retry<T>(fn: () => Promise<T>, maxRetries?: number, baseDelay?: number): Promise<T>;
200
+
201
+ export { ChatCompletionRequest, ChatCompletionResponse, KoreShieldClient, KoreShieldConfig, KoreShieldError, KoreShieldOpenAI, MetricsResponse, ProviderConfig, ProviderType, SecurityEvent, SecurityOptions, checkResponseSafety, createClient, createKoreShieldOpenAI, KoreShieldClient as default, formatMessages, retry, sanitizeInput, sleep, validateConfig };