@vaikora/sdk 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,403 @@
1
+ # Vaikora Node.js SDK
2
+
3
+ [![npm version](https://img.shields.io/npm/v/@vaikora/sdk.svg)](https://www.npmjs.com/package/@vaikora/sdk)
4
+ [![TypeScript](https://img.shields.io/badge/TypeScript-5.0+-blue.svg)](https://www.typescriptlang.org/)
5
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
6
+
7
+ The official Node.js SDK for the Vaikora AI Agent Security Platform.
8
+
9
+ ## Installation
10
+
11
+ ```bash
12
+ npm install @vaikora/sdk
13
+ # or
14
+ yarn add @vaikora/sdk
15
+ # or
16
+ pnpm add @vaikora/sdk
17
+ ```
18
+
19
+ ## Quick Start
20
+
21
+ ### Simple Configuration (Recommended)
22
+
23
+ ```typescript
24
+ import { configure, register, wrapAction, validateData } from '@vaikora/sdk';
25
+
26
+ // Configure the global client
27
+ configure('your-api-key');
28
+
29
+ // Register your AI agent
30
+ const agent = await register({
31
+ name: 'my-assistant',
32
+ agentType: 'autonomous',
33
+ capabilities: ['data_access', 'email_send', 'api_call'],
34
+ });
35
+
36
+ console.log(`Agent registered: ${agent.id}`);
37
+ ```
38
+
39
+ ### Secure Your Actions
40
+
41
+ ```typescript
42
+ import { configure, register, wrapAction } from '@vaikora/sdk';
43
+
44
+ configure('your-api-key');
45
+ await register({ name: 'my-agent' });
46
+
47
+ // Wrap any async function with security controls
48
+ const secureDbQuery = wrapAction(
49
+ { actionType: 'database_query', resource: 'users' },
50
+ async (query: string) => {
51
+ return await database.execute(query);
52
+ }
53
+ );
54
+
55
+ // Action is now secured - will be evaluated against policies
56
+ const users = await secureDbQuery('SELECT * FROM users WHERE active = true');
57
+ ```
58
+
59
+ ### Validate Data
60
+
61
+ ```typescript
62
+ import { configure, validateData } from '@vaikora/sdk';
63
+
64
+ configure('your-api-key');
65
+
66
+ const result = await validateData(
67
+ {
68
+ name: 'John Doe',
69
+ email: 'john@example.com',
70
+ ssn: '123-45-6789',
71
+ message: 'Hello world',
72
+ },
73
+ {
74
+ checkPii: true,
75
+ checkAnomalies: true,
76
+ checkToxicity: true,
77
+ autoClean: true,
78
+ }
79
+ );
80
+
81
+ if (!result.isValid) {
82
+ console.log('PII detected:', result.piiDetections);
83
+ console.log('Cleaned data:', result.cleanedData);
84
+ }
85
+ ```
86
+
87
+ ### Use the Interceptor for Advanced Control
88
+
89
+ ```typescript
90
+ import { configure, register, getClient, createInterceptor, InterceptorAction } from '@vaikora/sdk';
91
+
92
+ configure('your-api-key');
93
+ await register({ name: 'my-agent' });
94
+
95
+ const client = getClient();
96
+
97
+ // Create an interceptor with full configuration
98
+ const intercept = createInterceptor(client, {
99
+ actionType: 'sensitive_operation',
100
+ validateInputs: true,
101
+ validateOutputs: true,
102
+ checkPii: true,
103
+ checkToxicity: true,
104
+ evaluatePolicy: true,
105
+ onPolicyDeny: InterceptorAction.BLOCK,
106
+ requireApproval: true,
107
+ approvalTimeoutSeconds: 3600,
108
+ });
109
+
110
+ // Wrap your function
111
+ const secureSendEmail = intercept(async (to: string, subject: string, body: string) => {
112
+ await emailService.send({ to, subject, body });
113
+ return { sent: true };
114
+ });
115
+
116
+ // Execute with full security
117
+ const result = await secureSendEmail('user@example.com', 'Hello', 'Message content');
118
+ console.log('Action ID:', result.actionId);
119
+ console.log('Validation issues:', result.validationIssues);
120
+ ```
121
+
122
+ ## Class-Based Client Usage
123
+
124
+ For more control, use the `VaikoraClient` class directly:
125
+
126
+ ```typescript
127
+ import { VaikoraClient } from '@vaikora/sdk';
128
+
129
+ const client = new VaikoraClient({
130
+ apiKey: 'your-api-key',
131
+ baseUrl: 'https://api.vaikora.ai',
132
+ timeout: 30000,
133
+ retryCount: 3,
134
+ });
135
+
136
+ // Register an agent
137
+ const agent = await client.agents.register({
138
+ name: 'my-ai-agent',
139
+ agentType: 'autonomous',
140
+ capabilities: ['database_write', 'api_call', 'file_access'],
141
+ });
142
+
143
+ // Submit an action for approval
144
+ const result = await client.actions.submit({
145
+ agentId: agent.id,
146
+ actionType: 'database_write',
147
+ resource: 'users_table',
148
+ payload: { userId: 123, data: { name: 'John' } },
149
+ });
150
+
151
+ if (result.approved) {
152
+ // Proceed with the action
153
+ } else {
154
+ console.log(`Action blocked: ${result.denialReason}`);
155
+ }
156
+ ```
157
+
158
+ ## Features
159
+
160
+ - **TypeScript First**: Full TypeScript support with complete type definitions
161
+ - **Simple API**: Convenience functions for quick integration
162
+ - **Action Control**: Submit actions for policy evaluation before execution
163
+ - **Data Validation**: Check for PII, anomalies, and toxicity
164
+ - **Interceptor**: Wrap functions with security controls
165
+ - **Anomaly Detection**: Automatic detection of unusual agent behavior
166
+ - **Policy Enforcement**: Server-side policy evaluation
167
+ - **Human-in-the-Loop**: Approval workflows for sensitive actions
168
+ - **Alerting**: Real-time alerts for security events
169
+ - **Retry Logic**: Built-in exponential backoff for failed requests
170
+
171
+ ## Configuration Options
172
+
173
+ ```typescript
174
+ import { VaikoraClient } from '@vaikora/sdk';
175
+
176
+ const client = new VaikoraClient({
177
+ apiKey: 'your-api-key', // Required
178
+ baseUrl: 'https://api.vaikora.ai', // Default
179
+ timeout: 30000, // Request timeout in milliseconds
180
+ retryCount: 3, // Number of retries for failed requests
181
+ agentId: 'default-agent-id', // Default agent for actions
182
+ });
183
+ ```
184
+
185
+ ## API Reference
186
+
187
+ ### Convenience Functions
188
+
189
+ ```typescript
190
+ // Configure global client
191
+ configure(apiKey: string, options?: ConfigureOptions): VaikoraClient
192
+
193
+ // Get configured client
194
+ getClient(): VaikoraClient
195
+
196
+ // Register an agent
197
+ register(options: RegisterOptions): Promise<Agent>
198
+
199
+ // Get/set agent ID
200
+ getAgentId(): string | null
201
+ setAgentId(agentId: string): void
202
+
203
+ // Validate data
204
+ validateData(data: unknown, options?: ValidateDataOptions): Promise<DataValidationResult>
205
+
206
+ // Submit an action
207
+ submitAction(options: SubmitActionOptions): Promise<ActionResult>
208
+
209
+ // Wrap a function with security
210
+ wrapAction<TArgs, TResult>(options: SecureActionOptions, fn: Function): Function
211
+ ```
212
+
213
+ ### Agents API
214
+
215
+ ```typescript
216
+ // Register a new agent
217
+ const agent = await client.agents.register({
218
+ name: 'my-agent',
219
+ agentType: 'autonomous', // 'autonomous' | 'semi_autonomous' | 'supervised'
220
+ capabilities: ['capability1', 'capability2'],
221
+ metadata: { custom: 'data' },
222
+ });
223
+
224
+ // Get agent by ID
225
+ const agent = await client.agents.get('agent-id');
226
+
227
+ // Update agent
228
+ const updated = await client.agents.update('agent-id', {
229
+ status: 'active',
230
+ capabilities: ['new_capability'],
231
+ });
232
+
233
+ // List agents
234
+ const agents = await client.agents.list({
235
+ page: 1,
236
+ pageSize: 20,
237
+ status: 'active',
238
+ });
239
+
240
+ // Delete agent
241
+ await client.agents.delete('agent-id');
242
+ ```
243
+
244
+ ### Actions API
245
+
246
+ ```typescript
247
+ // Submit action for evaluation
248
+ const result = await client.actions.submit({
249
+ agentId: 'agent-id',
250
+ actionType: 'database_write',
251
+ resource: 'users_table',
252
+ payload: { data: 'value' },
253
+ metadata: { context: 'info' },
254
+ });
255
+
256
+ // Mark action as complete
257
+ await client.actions.complete('action-id', {
258
+ status: 'executed',
259
+ executionTimeMs: 150,
260
+ });
261
+
262
+ // List actions
263
+ const actions = await client.actions.list({
264
+ agentId: 'agent-id',
265
+ status: 'executed',
266
+ isAnomaly: false,
267
+ startDate: new Date('2024-01-01'),
268
+ endDate: new Date(),
269
+ });
270
+ ```
271
+
272
+ ### Policies API
273
+
274
+ ```typescript
275
+ // List policies
276
+ const policies = await client.policies.list({
277
+ enabled: true,
278
+ policyType: 'deny',
279
+ });
280
+
281
+ // Get policy by ID
282
+ const policy = await client.policies.get('policy-id');
283
+ ```
284
+
285
+ ### Alerts API
286
+
287
+ ```typescript
288
+ // List alerts
289
+ const alerts = await client.alerts.list({
290
+ status: 'open',
291
+ severity: 'high',
292
+ });
293
+
294
+ // Acknowledge alert
295
+ await client.alerts.acknowledge('alert-id');
296
+
297
+ // Resolve alert
298
+ await client.alerts.resolve('alert-id', {
299
+ notes: 'Issue was a false positive',
300
+ });
301
+
302
+ // Ignore alert
303
+ await client.alerts.ignore('alert-id');
304
+ ```
305
+
306
+ ## Interceptor Configuration
307
+
308
+ The interceptor provides comprehensive security controls:
309
+
310
+ ```typescript
311
+ interface InterceptorConfig {
312
+ actionType: string; // Required: Type of action
313
+ resource?: string; // Resource being accessed
314
+ agentId?: string; // Override agent ID
315
+
316
+ // Validation
317
+ validateInputs?: boolean; // Validate function inputs (default: true)
318
+ validateOutputs?: boolean; // Validate function outputs (default: false)
319
+ validationStrict?: boolean; // Throw on validation issues (default: false)
320
+ checkPii?: boolean; // Check for PII (default: true)
321
+ checkAnomalies?: boolean; // Check for anomalies (default: true)
322
+ checkToxicity?: boolean; // Check for toxic content (default: true)
323
+ autoClean?: boolean; // Auto-clean data (default: false)
324
+
325
+ // Policy
326
+ evaluatePolicy?: boolean; // Evaluate against policies (default: true)
327
+ onPolicyDeny?: InterceptorAction; // Action on deny (default: BLOCK)
328
+
329
+ // Approval
330
+ requireApproval?: boolean; // Require human approval (default: false)
331
+ approvalTimeoutSeconds?: number; // Approval timeout (default: 3600)
332
+ approvalNotifyChannels?: string[]; // Notification channels
333
+
334
+ // Fallback
335
+ fallbackFunction?: Function; // Fallback on policy deny
336
+
337
+ // Metadata
338
+ metadata?: Record<string, unknown>;
339
+ tags?: string[];
340
+ }
341
+ ```
342
+
343
+ ## Error Handling
344
+
345
+ ```typescript
346
+ import {
347
+ VaikoraError,
348
+ AuthenticationError,
349
+ AuthorizationError,
350
+ NotFoundError,
351
+ RateLimitError,
352
+ PolicyViolationError,
353
+ ValidationException,
354
+ PolicyDeniedException,
355
+ ApprovalRequiredException,
356
+ } from '@vaikora/sdk';
357
+
358
+ try {
359
+ const result = await client.actions.submit({...});
360
+ } catch (error) {
361
+ if (error instanceof AuthenticationError) {
362
+ console.log('Invalid API key');
363
+ } else if (error instanceof PolicyViolationError) {
364
+ console.log(`Blocked by policy: ${error.policyId}`);
365
+ } else if (error instanceof RateLimitError) {
366
+ console.log(`Rate limited, retry after: ${error.retryAfter}s`);
367
+ } else if (error instanceof ValidationException) {
368
+ console.log('Validation issues:', error.issues);
369
+ }
370
+ }
371
+ ```
372
+
373
+ ## Environment Variables
374
+
375
+ ```bash
376
+ VAIKORA_API_KEY=your-api-key
377
+ VAIKORA_BASE_URL=https://api.vaikora.ai
378
+ ```
379
+
380
+ ## TypeScript Types
381
+
382
+ All types are exported from the package:
383
+
384
+ ```typescript
385
+ import type {
386
+ Agent,
387
+ AgentType,
388
+ AgentStatus,
389
+ Action,
390
+ ActionStatus,
391
+ ActionResult,
392
+ Policy,
393
+ Alert,
394
+ AlertSeverity,
395
+ DataValidationResult,
396
+ InterceptorConfig,
397
+ InterceptorResult,
398
+ } from '@vaikora/sdk';
399
+ ```
400
+
401
+ ## License
402
+
403
+ MIT