@juspay/neurolink
Version:
Universal AI Development Platform with working MCP integration, multi-provider support, voice (TTS/STT/realtime), and professional CLI. 58+ external MCP servers discoverable, multimodal file processing, RAG pipelines. Build, test, and deploy AI applicatio
63 lines (62 loc) • 1.78 kB
JavaScript
/**
* Prompt redaction utilities for safe logging
* Provides consistent prompt masking across NeuroLink components
*/
/**
* Default redaction options
*/
const DEFAULT_REDACTION_OPTIONS = {
maxLength: 100,
showWordCount: true,
maskChar: "*",
};
/**
* Redact a prompt for safe logging
* Truncates to maxLength and optionally shows word count
*/
export function redactPrompt(prompt, options = {}) {
const opts = { ...DEFAULT_REDACTION_OPTIONS, ...options };
if (!prompt || typeof prompt !== "string") {
return "[INVALID_PROMPT]";
}
const wordCount = prompt.trim().split(/\s+/).length;
let redacted = prompt.substring(0, opts.maxLength);
// Add ellipsis if truncated
if (prompt.length > opts.maxLength) {
redacted = redacted.substring(0, opts.maxLength - 3) + "...";
}
// Optionally append word count
if (opts.showWordCount) {
redacted += ` [${wordCount} words]`;
}
return redacted;
}
/**
* Create a short safe mask for highly sensitive contexts
*/
export function createSafeMask(prompt, _maskLength = 20) {
if (!prompt || typeof prompt !== "string") {
return "[INVALID_PROMPT]";
}
const wordCount = prompt.trim().split(/\s+/).length;
const charCount = prompt.length;
return `[REDACTED: ${charCount} chars, ${wordCount} words]`;
}
/**
* Redact for classification context (matches classifier behavior)
*/
export function redactForClassification(prompt) {
return redactPrompt(prompt, {
maxLength: 100,
showWordCount: false,
});
}
/**
* Redact for routing context (matches router behavior)
*/
export function redactForRouting(prompt) {
return redactPrompt(prompt, {
maxLength: 100,
showWordCount: true,
});
}