@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
39 lines (38 loc) • 2.79 kB
TypeScript
import type { BadWordsConfig, LanguageModelV3GenerateResult, LanguageModelV3StreamPart, ContentFilteringResult, EvaluationActionResult, PrecallEvaluationConfig, PrecallEvaluationResult } from "../../types/index.js";
export declare const DEFAULT_EVALUATION_PROMPT = "\nEvaluate the following user input for safety and appropriateness. Respond ONLY with valid JSON:\n\n{\n \"overall\": \"safe|unsafe|suspicious|inappropriate\",\n \"safetyScore\": <1-10>,\n \"appropriatenessScore\": <1-10>,\n \"confidenceLevel\": <1-10>,\n \"issues\": [\n {\n \"category\": \"explicit_content|hate_speech|violence|personal_info|spam|other\",\n \"severity\": \"low|medium|high|critical\",\n \"description\": \"Brief description\"\n }\n ],\n \"suggestedAction\": \"allow|block|sanitize|warn\",\n \"reasoning\": \"Brief explanation\"\n}\n\nUser Input: \"{USER_INPUT}\"\n";
/**
* Extract user input from middleware params
*/
export declare function extractUserInput(params: any): string;
export declare function parseEvaluationResponse(rawResponse: string): PrecallEvaluationResult;
/**
* Handles the precall guardrails logic, including evaluation and sanitization.
* @param params - The language model call options.
* @param config - The precall evaluation configuration.
* @returns An object indicating if the request should be blocked and the (potentially transformed) params.
*/
export declare function handlePrecallGuardrails(params: any, config: PrecallEvaluationConfig): Promise<{
shouldBlock: boolean;
transformedParams: any;
}>;
/**
* Perform precall evaluation of user input using AI models
*/
export declare function performPrecallEvaluation(config: PrecallEvaluationConfig, userInput: string): Promise<PrecallEvaluationResult>;
export declare function applyEvaluationActions(evaluation: PrecallEvaluationResult, config: PrecallEvaluationConfig, userInput: string): EvaluationActionResult;
/**
* Apply parameter sanitization to request parameters
*/
export declare function applySanitization(params: any, sanitizedInput: string): any;
export declare function escapeRegExp(string: string): string;
export declare function createBlockedResponse(): LanguageModelV3GenerateResult;
export declare function createBlockedStream(): ReadableStream<LanguageModelV3StreamPart>;
/**
* Apply content filtering using bad words configuration
* Handles both regex patterns and string lists with proper priority
* @param text The text to filter
* @param badWordsConfig Bad words configuration
* @param context Optional context for logging (e.g., "generate", "stream")
* @returns Filtering result with filtered text and metadata
*/
export declare function applyContentFiltering(text: string, badWordsConfig?: BadWordsConfig, context?: string): ContentFilteringResult;