@juspay/neurolink 7.38.1 → 7.39.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 +6 -0
- package/dist/hitl/hitlErrors.d.ts +38 -0
- package/dist/hitl/hitlErrors.js +54 -0
- package/dist/hitl/hitlManager.d.ts +100 -0
- package/dist/hitl/hitlManager.js +457 -0
- package/dist/hitl/index.d.ts +8 -0
- package/dist/hitl/index.js +9 -0
- package/dist/hitl/types.d.ts +196 -0
- package/dist/hitl/types.js +8 -0
- package/dist/lib/hitl/hitlErrors.d.ts +38 -0
- package/dist/lib/hitl/hitlErrors.js +54 -0
- package/dist/lib/hitl/hitlManager.d.ts +100 -0
- package/dist/lib/hitl/hitlManager.js +457 -0
- package/dist/lib/hitl/index.d.ts +8 -0
- package/dist/lib/hitl/index.js +9 -0
- package/dist/lib/hitl/types.d.ts +196 -0
- package/dist/lib/hitl/types.js +8 -0
- package/dist/lib/mcp/externalServerManager.d.ts +11 -0
- package/dist/lib/mcp/externalServerManager.js +69 -2
- package/dist/lib/mcp/toolRegistry.d.ts +11 -0
- package/dist/lib/mcp/toolRegistry.js +69 -3
- package/dist/lib/neurolink.d.ts +27 -0
- package/dist/lib/neurolink.js +146 -0
- package/dist/mcp/externalServerManager.d.ts +11 -0
- package/dist/mcp/externalServerManager.js +69 -2
- package/dist/mcp/toolRegistry.d.ts +11 -0
- package/dist/mcp/toolRegistry.js +69 -3
- package/dist/neurolink.d.ts +27 -0
- package/dist/neurolink.js +146 -0
- package/package.json +1 -1
@@ -0,0 +1,196 @@
|
|
1
|
+
/**
|
2
|
+
* HITL (Human-in-the-Loop) Type Definitions
|
3
|
+
*
|
4
|
+
* Comprehensive TypeScript interfaces for the HITL safety system.
|
5
|
+
* These types ensure type safety and provide clear contracts for
|
6
|
+
* all HITL-related functionality.
|
7
|
+
*/
|
8
|
+
/**
|
9
|
+
* Core HITL configuration interface
|
10
|
+
* Controls how the HITL system behaves and what tools require confirmation
|
11
|
+
*/
|
12
|
+
export interface HITLConfig {
|
13
|
+
/** Master enable/disable switch for HITL functionality */
|
14
|
+
enabled: boolean;
|
15
|
+
/** Keywords that trigger HITL confirmation (e.g., "delete", "remove", "drop") */
|
16
|
+
dangerousActions: string[];
|
17
|
+
/** Timeout in milliseconds for user confirmation (default: 30000) */
|
18
|
+
timeout?: number;
|
19
|
+
/** Communication method - currently only "event" is supported (default: "event") */
|
20
|
+
confirmationMethod?: "event";
|
21
|
+
/** Whether users can modify tool arguments during approval (default: true) */
|
22
|
+
allowArgumentModification?: boolean;
|
23
|
+
/** Auto-approve requests when they timeout (default: false - rejects on timeout) */
|
24
|
+
autoApproveOnTimeout?: boolean;
|
25
|
+
/** Enable audit logging for compliance and debugging (default: false) */
|
26
|
+
auditLogging?: boolean;
|
27
|
+
/** Advanced custom rules for complex tool scenarios (default: []) */
|
28
|
+
customRules?: HITLRule[];
|
29
|
+
}
|
30
|
+
/**
|
31
|
+
* Custom rule for advanced HITL scenarios
|
32
|
+
* Allows enterprises to define complex conditions for when tools require confirmation
|
33
|
+
*/
|
34
|
+
export interface HITLRule {
|
35
|
+
/** Human-readable name for the rule */
|
36
|
+
name: string;
|
37
|
+
/** Function that determines if a tool requires confirmation */
|
38
|
+
condition: (toolName: string, args: unknown) => boolean;
|
39
|
+
/** Whether this rule requires confirmation when triggered */
|
40
|
+
requiresConfirmation: boolean;
|
41
|
+
/** Custom message to show users when this rule is triggered */
|
42
|
+
customMessage?: string;
|
43
|
+
}
|
44
|
+
/**
|
45
|
+
* Internal confirmation request tracking
|
46
|
+
* Used by HITLManager to track pending confirmations
|
47
|
+
*/
|
48
|
+
export interface ConfirmationRequest {
|
49
|
+
/** Unique identifier for this confirmation request */
|
50
|
+
confirmationId: string;
|
51
|
+
/** Name of the tool requiring confirmation */
|
52
|
+
toolName: string;
|
53
|
+
/** Arguments that will be passed to the tool */
|
54
|
+
arguments: unknown;
|
55
|
+
/** Timestamp when the request was created */
|
56
|
+
timestamp: number;
|
57
|
+
/** Timeout handle for cleanup */
|
58
|
+
timeoutHandle: NodeJS.Timeout;
|
59
|
+
/** Promise resolve function */
|
60
|
+
resolve: (result: ConfirmationResult) => void;
|
61
|
+
/** Promise reject function */
|
62
|
+
reject: (error: Error) => void;
|
63
|
+
}
|
64
|
+
/**
|
65
|
+
* Result of a confirmation request
|
66
|
+
* Contains user decision and potentially modified arguments
|
67
|
+
*/
|
68
|
+
export interface ConfirmationResult {
|
69
|
+
/** Whether the user approved the tool execution */
|
70
|
+
approved: boolean;
|
71
|
+
/** Optional reason for rejection (if approved is false) */
|
72
|
+
reason?: string;
|
73
|
+
/** User-modified arguments (if allowArgumentModification is enabled) */
|
74
|
+
modifiedArguments?: unknown;
|
75
|
+
/** Time taken for user to respond in milliseconds */
|
76
|
+
responseTime: number;
|
77
|
+
}
|
78
|
+
/**
|
79
|
+
* Event payload for confirmation requests
|
80
|
+
* Sent to frontends via EventEmitter when tool needs approval
|
81
|
+
*/
|
82
|
+
export interface ConfirmationRequestEvent {
|
83
|
+
type: "hitl:confirmation-request";
|
84
|
+
payload: {
|
85
|
+
/** Unique ID for tracking this request */
|
86
|
+
confirmationId: string;
|
87
|
+
/** Name of the tool requiring confirmation */
|
88
|
+
toolName: string;
|
89
|
+
/** MCP server ID (if this is an external tool) */
|
90
|
+
serverId?: string;
|
91
|
+
/** Human-readable description of the action */
|
92
|
+
actionType: string;
|
93
|
+
/** Tool parameters for user review */
|
94
|
+
arguments: unknown;
|
95
|
+
/** Additional metadata about the request */
|
96
|
+
metadata: {
|
97
|
+
/** ISO timestamp when request was created */
|
98
|
+
timestamp: string;
|
99
|
+
/** User session identifier */
|
100
|
+
sessionId?: string;
|
101
|
+
/** User identifier */
|
102
|
+
userId?: string;
|
103
|
+
/** Keywords that triggered HITL */
|
104
|
+
dangerousKeywords: string[];
|
105
|
+
};
|
106
|
+
/** Confirmation timeout in milliseconds */
|
107
|
+
timeoutMs: number;
|
108
|
+
/** Whether user can modify arguments */
|
109
|
+
allowModification: boolean;
|
110
|
+
};
|
111
|
+
}
|
112
|
+
/**
|
113
|
+
* Event payload for confirmation responses
|
114
|
+
* Sent from frontends back to HITLManager with user decision
|
115
|
+
*/
|
116
|
+
export interface ConfirmationResponseEvent {
|
117
|
+
type: "hitl:confirmation-response";
|
118
|
+
payload: {
|
119
|
+
/** Matching confirmation ID from the request */
|
120
|
+
confirmationId: string;
|
121
|
+
/** User's approval decision */
|
122
|
+
approved: boolean;
|
123
|
+
/** Optional reason for rejection */
|
124
|
+
reason?: string;
|
125
|
+
/** User-edited parameters (if modification allowed) */
|
126
|
+
modifiedArguments?: unknown;
|
127
|
+
/** Response metadata */
|
128
|
+
metadata: {
|
129
|
+
/** ISO timestamp when user responded */
|
130
|
+
timestamp: string;
|
131
|
+
/** Time taken to respond in milliseconds */
|
132
|
+
responseTime: number;
|
133
|
+
/** User who made the decision */
|
134
|
+
userId?: string;
|
135
|
+
};
|
136
|
+
};
|
137
|
+
}
|
138
|
+
/**
|
139
|
+
* Event payload for confirmation timeouts
|
140
|
+
* Emitted when user doesn't respond within timeout period
|
141
|
+
*/
|
142
|
+
export interface ConfirmationTimeoutEvent {
|
143
|
+
type: "hitl:timeout";
|
144
|
+
payload: {
|
145
|
+
/** Confirmation ID that timed out */
|
146
|
+
confirmationId: string;
|
147
|
+
/** Tool name that timed out */
|
148
|
+
toolName: string;
|
149
|
+
/** Timeout duration in milliseconds */
|
150
|
+
timeout: number;
|
151
|
+
};
|
152
|
+
}
|
153
|
+
/**
|
154
|
+
* HITL audit log entry
|
155
|
+
* Used for compliance and debugging purposes
|
156
|
+
*/
|
157
|
+
export interface HITLAuditLog {
|
158
|
+
/** ISO timestamp of the event */
|
159
|
+
timestamp: string;
|
160
|
+
/** Type of HITL event */
|
161
|
+
eventType: "confirmation-requested" | "confirmation-approved" | "confirmation-rejected" | "confirmation-timeout" | "confirmation-auto-approved";
|
162
|
+
/** Tool that was involved */
|
163
|
+
toolName: string;
|
164
|
+
/** User who made the decision (if applicable) */
|
165
|
+
userId?: string;
|
166
|
+
/** Session identifier */
|
167
|
+
sessionId?: string;
|
168
|
+
/** Tool arguments (may be sanitized for security) */
|
169
|
+
arguments: unknown;
|
170
|
+
/** Reason for rejection (if applicable) */
|
171
|
+
reason?: string;
|
172
|
+
/** IP address of the user (if available) */
|
173
|
+
ipAddress?: string;
|
174
|
+
/** User agent string (if available) */
|
175
|
+
userAgent?: string;
|
176
|
+
/** Response time in milliseconds (if applicable) */
|
177
|
+
responseTime?: number;
|
178
|
+
}
|
179
|
+
/**
|
180
|
+
* HITL statistics interface
|
181
|
+
* Provides metrics about HITL usage for monitoring
|
182
|
+
*/
|
183
|
+
export interface HITLStatistics {
|
184
|
+
/** Total number of confirmation requests made */
|
185
|
+
totalRequests: number;
|
186
|
+
/** Number of pending confirmations */
|
187
|
+
pendingRequests: number;
|
188
|
+
/** Average response time for user decisions */
|
189
|
+
averageResponseTime: number;
|
190
|
+
/** Number of approved requests */
|
191
|
+
approvedRequests: number;
|
192
|
+
/** Number of rejected requests */
|
193
|
+
rejectedRequests: number;
|
194
|
+
/** Number of timed out requests */
|
195
|
+
timedOutRequests: number;
|
196
|
+
}
|
@@ -0,0 +1,38 @@
|
|
1
|
+
/**
|
2
|
+
* HITL (Human-in-the-Loop) Error Classes
|
3
|
+
*
|
4
|
+
* Provides structured error handling for HITL safety mechanisms.
|
5
|
+
* These errors allow applications to distinguish between different
|
6
|
+
* types of HITL failures and handle them appropriately.
|
7
|
+
*/
|
8
|
+
/**
|
9
|
+
* Base class for all HITL-related errors
|
10
|
+
*/
|
11
|
+
export declare class HITLError extends Error {
|
12
|
+
readonly confirmationId?: string | undefined;
|
13
|
+
constructor(message: string, confirmationId?: string | undefined);
|
14
|
+
}
|
15
|
+
/**
|
16
|
+
* Thrown when a user explicitly rejects a tool execution request
|
17
|
+
* This indicates the HITL system worked correctly - the user saw the request
|
18
|
+
* and made a conscious decision to deny it.
|
19
|
+
*/
|
20
|
+
export declare class HITLUserRejectedError extends HITLError {
|
21
|
+
readonly toolName: string;
|
22
|
+
readonly reason?: string | undefined;
|
23
|
+
constructor(message: string, toolName: string, reason?: string | undefined, confirmationId?: string);
|
24
|
+
}
|
25
|
+
/**
|
26
|
+
* Thrown when a confirmation request times out without user response
|
27
|
+
* This indicates the user didn't respond within the configured timeout period.
|
28
|
+
*/
|
29
|
+
export declare class HITLTimeoutError extends HITLError {
|
30
|
+
readonly timeout: number;
|
31
|
+
constructor(message: string, confirmationId: string, timeout: number);
|
32
|
+
}
|
33
|
+
/**
|
34
|
+
* Thrown when HITL configuration is invalid or missing required properties
|
35
|
+
*/
|
36
|
+
export declare class HITLConfigurationError extends HITLError {
|
37
|
+
constructor(message: string);
|
38
|
+
}
|
@@ -0,0 +1,54 @@
|
|
1
|
+
/**
|
2
|
+
* HITL (Human-in-the-Loop) Error Classes
|
3
|
+
*
|
4
|
+
* Provides structured error handling for HITL safety mechanisms.
|
5
|
+
* These errors allow applications to distinguish between different
|
6
|
+
* types of HITL failures and handle them appropriately.
|
7
|
+
*/
|
8
|
+
/**
|
9
|
+
* Base class for all HITL-related errors
|
10
|
+
*/
|
11
|
+
export class HITLError extends Error {
|
12
|
+
confirmationId;
|
13
|
+
constructor(message, confirmationId) {
|
14
|
+
super(message);
|
15
|
+
this.confirmationId = confirmationId;
|
16
|
+
this.name = "HITLError";
|
17
|
+
}
|
18
|
+
}
|
19
|
+
/**
|
20
|
+
* Thrown when a user explicitly rejects a tool execution request
|
21
|
+
* This indicates the HITL system worked correctly - the user saw the request
|
22
|
+
* and made a conscious decision to deny it.
|
23
|
+
*/
|
24
|
+
export class HITLUserRejectedError extends HITLError {
|
25
|
+
toolName;
|
26
|
+
reason;
|
27
|
+
constructor(message, toolName, reason, confirmationId) {
|
28
|
+
super(message, confirmationId);
|
29
|
+
this.toolName = toolName;
|
30
|
+
this.reason = reason;
|
31
|
+
this.name = "HITLUserRejectedError";
|
32
|
+
}
|
33
|
+
}
|
34
|
+
/**
|
35
|
+
* Thrown when a confirmation request times out without user response
|
36
|
+
* This indicates the user didn't respond within the configured timeout period.
|
37
|
+
*/
|
38
|
+
export class HITLTimeoutError extends HITLError {
|
39
|
+
timeout;
|
40
|
+
constructor(message, confirmationId, timeout) {
|
41
|
+
super(message, confirmationId);
|
42
|
+
this.timeout = timeout;
|
43
|
+
this.name = "HITLTimeoutError";
|
44
|
+
}
|
45
|
+
}
|
46
|
+
/**
|
47
|
+
* Thrown when HITL configuration is invalid or missing required properties
|
48
|
+
*/
|
49
|
+
export class HITLConfigurationError extends HITLError {
|
50
|
+
constructor(message) {
|
51
|
+
super(message);
|
52
|
+
this.name = "HITLConfigurationError";
|
53
|
+
}
|
54
|
+
}
|
@@ -0,0 +1,100 @@
|
|
1
|
+
/**
|
2
|
+
* HITL (Human-in-the-Loop) Manager
|
3
|
+
*
|
4
|
+
* Central orchestrator for all HITL confirmation workflows.
|
5
|
+
* Manages user confirmation requests, timeouts, and argument modifications
|
6
|
+
* for enterprise-grade AI safety.
|
7
|
+
*/
|
8
|
+
import { EventEmitter } from "events";
|
9
|
+
import type { HITLConfig, ConfirmationResult, HITLStatistics } from "./types.js";
|
10
|
+
/**
|
11
|
+
* HITLManager - Central orchestrator for Human-in-the-Loop safety mechanisms
|
12
|
+
*
|
13
|
+
* Features:
|
14
|
+
* - Real-time user confirmation via events
|
15
|
+
* - Configurable dangerous action detection
|
16
|
+
* - Custom rule engine for complex scenarios
|
17
|
+
* - Argument modification support
|
18
|
+
* - Comprehensive audit logging
|
19
|
+
* - Timeout handling with cleanup
|
20
|
+
*/
|
21
|
+
export declare class HITLManager extends EventEmitter {
|
22
|
+
private config;
|
23
|
+
private pendingConfirmations;
|
24
|
+
private statistics;
|
25
|
+
constructor(config: HITLConfig);
|
26
|
+
/**
|
27
|
+
* Validate HITL configuration and apply defaults
|
28
|
+
*/
|
29
|
+
private validateConfig;
|
30
|
+
/**
|
31
|
+
* Check if a tool requires confirmation based on configuration
|
32
|
+
*/
|
33
|
+
requiresConfirmation(toolName: string, args?: unknown): boolean;
|
34
|
+
/**
|
35
|
+
* Request confirmation for a tool execution
|
36
|
+
*/
|
37
|
+
requestConfirmation(toolName: string, arguments_: unknown, context?: {
|
38
|
+
serverId?: string;
|
39
|
+
sessionId?: string;
|
40
|
+
userId?: string;
|
41
|
+
}): Promise<ConfirmationResult>;
|
42
|
+
/**
|
43
|
+
* Process user response to confirmation request
|
44
|
+
*/
|
45
|
+
processUserResponse(confirmationId: string, response: {
|
46
|
+
approved: boolean;
|
47
|
+
reason?: string;
|
48
|
+
modifiedArguments?: unknown;
|
49
|
+
responseTime?: number;
|
50
|
+
userId?: string;
|
51
|
+
}): void;
|
52
|
+
/**
|
53
|
+
* Handle confirmation timeout
|
54
|
+
*/
|
55
|
+
private handleTimeout;
|
56
|
+
/**
|
57
|
+
* Set up event handlers for processing responses
|
58
|
+
*/
|
59
|
+
private setupEventHandlers;
|
60
|
+
/**
|
61
|
+
* Generate unique confirmation ID
|
62
|
+
*/
|
63
|
+
private generateConfirmationId;
|
64
|
+
/**
|
65
|
+
* Generate human-readable action description
|
66
|
+
*/
|
67
|
+
private generateActionDescription;
|
68
|
+
/**
|
69
|
+
* Get keywords that triggered HITL
|
70
|
+
*/
|
71
|
+
private getTriggeredKeywords;
|
72
|
+
/**
|
73
|
+
* Log audit events for compliance and debugging
|
74
|
+
*/
|
75
|
+
private logAuditEvent;
|
76
|
+
/**
|
77
|
+
* Get current HITL usage statistics
|
78
|
+
*/
|
79
|
+
getStatistics(): HITLStatistics;
|
80
|
+
/**
|
81
|
+
* Get current configuration
|
82
|
+
*/
|
83
|
+
getConfig(): HITLConfig;
|
84
|
+
/**
|
85
|
+
* Update configuration (for dynamic reconfiguration)
|
86
|
+
*/
|
87
|
+
updateConfig(newConfig: Partial<HITLConfig>): void;
|
88
|
+
/**
|
89
|
+
* Clean up resources and reject pending confirmations
|
90
|
+
*/
|
91
|
+
cleanup(): void;
|
92
|
+
/**
|
93
|
+
* Check if manager is currently enabled
|
94
|
+
*/
|
95
|
+
isEnabled(): boolean;
|
96
|
+
/**
|
97
|
+
* Get count of pending confirmations
|
98
|
+
*/
|
99
|
+
getPendingCount(): number;
|
100
|
+
}
|