@juspay/neurolink
Version:
The pipe layer of an AI nervous system: one interface connecting provider neurons to your application, across three inference types — generate, stream and decide. `decide` returns typed, calibrated judgements from a non-generative model (~400ms, ~$0.00002
115 lines (114 loc) • 3.61 kB
TypeScript
/**
* HITL (Human-in-the-Loop) Manager
*
* Central orchestrator for all HITL confirmation workflows.
* Manages user confirmation requests, timeouts, and argument modifications
* for enterprise-grade AI safety.
*/
import { EventEmitter } from "events";
import type { HITLConfig, ConfirmationResult, HITLStatistics } from "../types/index.js";
/**
* HITLManager - Central orchestrator for Human-in-the-Loop safety mechanisms
*
* Features:
* - Real-time user confirmation via events
* - Configurable dangerous action detection
* - Custom rule engine for complex scenarios
* - Argument modification support
* - Comprehensive audit logging
* - Timeout handling with cleanup
*/
export declare class HITLManager extends EventEmitter {
private config;
private pendingConfirmations;
private statistics;
constructor(config: HITLConfig);
/**
* Validate HITL configuration and apply defaults
*/
private validateConfig;
/**
* Check if a tool requires confirmation based on configuration
*/
requiresConfirmation(toolName: string, args?: unknown): boolean;
/**
* Request confirmation for a tool execution
*/
requestConfirmation(toolName: string, arguments_: unknown, context?: {
serverId?: string;
sessionId?: string;
userId?: string;
}): Promise<ConfirmationResult>;
/**
* Process user response to confirmation request
*/
processUserResponse(confirmationId: string, response: {
approved: boolean;
reason?: string;
modifiedArguments?: unknown;
responseTime?: number;
userId?: string;
}): void;
/**
* Handle confirmation timeout
*/
private handleTimeout;
/**
* Set up event handlers for processing responses
*/
private setupEventHandlers;
/**
* Generate unique confirmation ID
*/
private generateConfirmationId;
/**
* Generate human-readable action description
*/
private generateActionDescription;
/**
* Get keywords that triggered HITL
*/
private getTriggeredKeywords;
/**
* Log audit events for compliance and debugging
*/
private logAuditEvent;
/**
* Get current HITL usage statistics
*/
getStatistics(): HITLStatistics;
/**
* Get current configuration
*/
getConfig(): HITLConfig;
/**
* Update configuration (for dynamic reconfiguration)
*/
updateConfig(newConfig: Partial<HITLConfig>): void;
/**
* Clean up resources and reject pending confirmations
*/
cleanup(): void;
/**
* Check if manager is currently enabled
*/
isEnabled(): boolean;
/**
* Get count of pending confirmations
*/
getPendingCount(): number;
/**
* Whether a specific confirmation is still awaiting a response on this manager.
*
* A pending entry holds the `resolve`/`reject` of the suspended tool call, so it
* exists only in the memory of the manager that issued it. A manager constructed
* after the confirmation was issued — a session rebuilt from persisted state, for
* example — has an empty set, and `processUserResponse` for such an id logs a
* warning and returns without resolving anything.
*
* Callers that report an outcome back to a user should check this before treating
* a delivered `hitl:confirmation-response` as acted upon: the event being received
* says a listener existed, not that anything was waiting for it.
*/
hasPendingConfirmation(confirmationId: string): boolean;
}