traceprompt-node
Version:
Client-side encrypted, audit-ready logging for LLM applications
84 lines (74 loc) • 3.22 kB
text/typescript
import { Registry } from 'prom-client';
interface TracePromptInit {
dataDir?: string;
apiKey: string;
ingestUrl: string;
batchSize?: number;
flushIntervalMs?: number;
staticMeta?: Record<string, unknown>;
logLevel?: "error" | "warn" | "info" | "verbose" | "debug" | "silly";
}
interface WrapOpts {
modelVendor: "openai" | "anthropic" | "grok" | "gemini" | "mistral" | "deepseek" | "xai" | "local";
modelName: string;
userId?: string;
}
interface EncryptedBundle {
ciphertext: string;
encryptedDataKey: string;
suiteId?: number;
}
interface QueueItem {
payload: Record<string, unknown> & {
enc: EncryptedBundle;
};
leafHash: string;
}
type EntityType = "FULL_NAME" | "FIRST_NAME" | "EMAIL" | "PHONE" | "CREDIT_CARD" | "CREDIT_CARD_PARTIAL" | "SSN" | "PASSPORT" | "ADDRESS" | "POSTCODE" | "IP" | "IBAN" | "SWIFT_BIC" | "NINO" | "UK_BANK_ACCT" | "US_ROUTING" | "INSURANCE_ID" | "MEDICAL_ID" | "NHS_NUMBER" | "DOB" | "DRIVER_LICENSE" | "DNI" | "INSEE_SSN" | "EIN" | "EU_NATIONAL_ID" | "UK_DL" | "ON_DL" | "PERSONNUMMER" | "CA_SIN" | "NHS_NUMBER" | "MBI" | "NPI" | "ON_HEALTH" | "SVNR" | "MAC_ADDRESS" | "IMEI" | "BANK_ACCOUNT";
type RiskLevel = "critical" | "sensitive" | "general";
interface Entity {
type: EntityType;
start: number;
end: number;
text: string;
confidence: number;
source: string;
risk: RiskLevel;
}
declare function initTracePrompt(cfg?: Partial<TracePromptInit>): Promise<void>;
declare function wrapLLM<P extends Record<string, any>, R>(originalFn: (prompt: string, params?: P) => Promise<R>, meta: WrapOpts): (prompt: string, params?: P) => Promise<R>;
declare function decryptBundle(bundle: EncryptedBundle): Promise<Buffer>;
declare const registry: Registry<"text/plain; version=0.0.4; charset=utf-8">;
declare function append(item: QueueItem): Promise<void>;
declare function flushOnce(): Promise<any>;
declare function gracefulShutdown(): Promise<void>;
declare const PersistentBatcher: {
enqueue: typeof append;
flush: typeof flushOnce;
gracefulShutdown: typeof gracefulShutdown;
};
declare function detectPII(raw: string): Entity[];
declare const detectPii: typeof detectPII;
interface PiiAnalysisResult {
piiDetected: boolean;
piiTypes: EntityType[];
riskLevel: RiskLevel;
}
interface FullPiiAnalysis {
overallPiiDetected: boolean;
allPiiTypes: EntityType[];
prompt: PiiAnalysisResult;
response: PiiAnalysisResult;
}
type PiiDetectionResult = FullPiiAnalysis;
declare function analyzePiiInPromptResponse(prompt: string, response: string): Promise<FullPiiAnalysis>;
/**
* 🎯 ENHANCED PII DETECTION with Multi-Recognizer Consensus
*
* This approach scales to any domain without requiring word lists:
* - Uses linguistic intelligence over pattern matching
* - Requires recognizer consensus for edge cases
* - Validates entity plausibility contextually
*/
declare function detectPIIEnhanced(raw: string): Entity[];
export { type EncryptedBundle, PersistentBatcher, type PiiDetectionResult, type TracePromptInit, type WrapOpts, analyzePiiInPromptResponse, decryptBundle, detectPIIEnhanced, detectPii, initTracePrompt, registry, wrapLLM };