@privacyscrubber/sdk 2.4.5 → 2.4.6
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/README.md +50 -1
- package/browser.js +399 -19
- package/cli.js +119 -11
- package/examples/python-bridge/README.md +3 -3
- package/examples/python-bridge/fastapi_example.py +1 -1
- package/examples/python-bridge/langchain_example.py +1 -1
- package/examples/python-bridge/privacyscrubber/__init__.py +1 -1
- package/examples/python-bridge/privacyscrubber/bridge_daemon.cjs +2 -2
- package/examples/python-bridge/privacyscrubber/cli.py +1 -1
- package/examples/python-bridge/pyproject.toml +1 -1
- package/examples/python-bridge/setup.py +1 -1
- package/index.cjs +1153 -81
- package/index.d.ts +147 -2
- package/index.js +1153 -81
- package/package.json +13 -3
- package/ps-license-manager.js +1 -1
- package/ps-pii-engine.cjs +1 -1
- package/sarif.cjs +14 -2
- package/scrubber-core.cjs +1 -1
- package/vercel-ai.cjs +123 -34
- package/vercel-ai.d.ts +7 -0
- package/benchmark.js +0 -355
- package/examples/python-bridge/bridge_daemon.cjs +0 -260
- package/examples/python-bridge/langchain_adapter.py +0 -20
- package/examples/python-bridge/privacyscrubber.py +0 -36
- package/examples/python-bridge/test_python_bridge.py +0 -320
package/index.d.ts
CHANGED
|
@@ -256,17 +256,67 @@ export interface ProcurementMemoOptions {
|
|
|
256
256
|
*/
|
|
257
257
|
export function generateProcurementMemo(options?: ProcurementMemoOptions): string;
|
|
258
258
|
|
|
259
|
+
export const SDK_VERSION: string;
|
|
260
|
+
export const PSR2_VERSION: 'PSR-2';
|
|
261
|
+
export const PSR2_STATEMENTS: {
|
|
262
|
+
measured: string[];
|
|
263
|
+
byDesign: string[];
|
|
264
|
+
limits: string[];
|
|
265
|
+
};
|
|
266
|
+
export const DEVOPS_SECRETS_DETECTOR: Array<{
|
|
267
|
+
name: string;
|
|
268
|
+
regex: RegExp;
|
|
269
|
+
label: string;
|
|
270
|
+
}>;
|
|
271
|
+
|
|
272
|
+
export interface Psr2Receipt {
|
|
273
|
+
version: string;
|
|
274
|
+
timestamp: string;
|
|
275
|
+
outputSha256: string | null;
|
|
276
|
+
manifestSha256: string;
|
|
277
|
+
entityCounts: string;
|
|
278
|
+
tokensTotal: number;
|
|
279
|
+
tokensPresentInOutput: number | null;
|
|
280
|
+
canonical: string;
|
|
281
|
+
receiptSha256: string;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
export function buildPsr2Receipt(tokenMap?: Record<string, string>, timestamp?: string): Psr2Receipt;
|
|
285
|
+
export function psr2Lines(receipt: Psr2Receipt): string[];
|
|
286
|
+
export function _resetCommunityNoticeForTesting(): void;
|
|
287
|
+
export function _resetDevSecretNoticeForTesting(): void;
|
|
288
|
+
|
|
259
289
|
/**
|
|
260
290
|
* Sanitizes input text, masking all PII and secrets with zero network requests.
|
|
261
291
|
*/
|
|
262
292
|
export function sanitize(text: string, options?: SanitizeOptions): SanitizeResult;
|
|
263
293
|
export function scrub(text: string, options?: SanitizeOptions): SanitizeResult;
|
|
264
294
|
|
|
295
|
+
export interface SanitizeObjectResult<T = any> {
|
|
296
|
+
sanitized: T;
|
|
297
|
+
tokenMap: Record<string, string>;
|
|
298
|
+
count: number;
|
|
299
|
+
executionMs: number;
|
|
300
|
+
telemetry: AuditTelemetry;
|
|
301
|
+
auditReceipt: string;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
/**
|
|
305
|
+
* Recursively sanitizes all string values within an object, array, Map, or Set.
|
|
306
|
+
*/
|
|
307
|
+
export function sanitizeObject<T = any>(obj: T, options?: SanitizeOptions): SanitizeObjectResult<T>;
|
|
308
|
+
|
|
265
309
|
/**
|
|
266
310
|
* Restores masked tokens in AI outputs back to original plaintext in-memory.
|
|
267
311
|
*/
|
|
268
312
|
export function restore(aiResponse: string, tokenMap: Record<string, string>): RestoreResult;
|
|
269
313
|
export function unscrub(aiResponse: string, tokenMap: Record<string, string>): RestoreResult;
|
|
314
|
+
export function desanitize(aiResponse: string, tokenMap: Record<string, string>): RestoreResult;
|
|
315
|
+
|
|
316
|
+
/**
|
|
317
|
+
* Recursively restores all masked tokens within a sanitized object, array, Map, or Set.
|
|
318
|
+
*/
|
|
319
|
+
export function restoreObject<T = any>(obj: T, tokenMap?: Record<string, string>): T;
|
|
270
320
|
|
|
271
321
|
export interface EngineConfig {
|
|
272
322
|
licenseKey?: string;
|
|
@@ -279,23 +329,98 @@ export interface EngineConfig {
|
|
|
279
329
|
tokenLabelMap?: Record<string, string>;
|
|
280
330
|
generateReceipt?: boolean;
|
|
281
331
|
initialSessionMap?: Record<string, string>;
|
|
332
|
+
ignoreList?: string[] | Set<string>;
|
|
333
|
+
maxSessionTokens?: number;
|
|
282
334
|
}
|
|
283
335
|
|
|
284
336
|
export class PrivacyScrubberEngine {
|
|
337
|
+
sessionMap: Record<string, string>;
|
|
338
|
+
ignoreList: Set<string>;
|
|
285
339
|
constructor(config?: EngineConfig);
|
|
286
340
|
setLicenseKey(key: string): LicenseValidationResult;
|
|
287
|
-
sanitize(text: string, options?: SanitizeOptions & { persistSession?: boolean }): SanitizeResult;
|
|
341
|
+
sanitize(text: string, options?: SanitizeOptions & { persistSession?: boolean; maxSessionTokens?: number }): SanitizeResult;
|
|
288
342
|
restore(aiResponse: string, tokenMap?: Record<string, string> | null): RestoreResult;
|
|
289
343
|
resetSession(): void;
|
|
344
|
+
markFalsePositive(token: string): { success: boolean; token?: string; original?: string; ignoreListSize?: number; reason?: string };
|
|
345
|
+
clearIgnoreList(): void;
|
|
290
346
|
createStreamRestorer(tokenMap?: Record<string, string> | null, options?: any): StreamTokenRestorer;
|
|
291
347
|
wrapStream<T = any>(stream: AsyncIterable<T>, tokenMap?: Record<string, string> | null, options?: any): AsyncGenerator<any, void, unknown>;
|
|
292
348
|
}
|
|
293
349
|
|
|
294
350
|
/**
|
|
295
|
-
* Transparent zero-trust wrapper for OpenAI SDK client.
|
|
351
|
+
* Transparent zero-trust wrapper for OpenAI SDK client (chat.completions.create & responses.create).
|
|
296
352
|
*/
|
|
297
353
|
export function wrapOpenAI<T = any>(openaiClient: T, options?: SanitizeOptions): T;
|
|
298
354
|
|
|
355
|
+
/**
|
|
356
|
+
* Transparent zero-trust wrapper for Anthropic SDK client (messages.create).
|
|
357
|
+
*/
|
|
358
|
+
export function wrapAnthropic<T = any>(anthropicClient: T, options?: SanitizeOptions): T;
|
|
359
|
+
|
|
360
|
+
/**
|
|
361
|
+
* Transparent zero-trust wrapper for Google Gemini SDKs (@google/genai and @google/generative-ai).
|
|
362
|
+
* Sanitizes string/Part[]/Content[] prompts and systemInstruction in RAM and restores tokens in sync and streaming responses.
|
|
363
|
+
*/
|
|
364
|
+
export function wrapGemini<T = any>(geminiClientOrModel: T, options?: SanitizeOptions & { engine?: PrivacyScrubberEngine }): T;
|
|
365
|
+
export const wrapGoogleGenAI: typeof wrapGemini;
|
|
366
|
+
|
|
367
|
+
/**
|
|
368
|
+
* Universal drop-in HTTP/SSE fetch wrapper for any OpenAI-compatible or custom LLM SDK
|
|
369
|
+
* (OpenAI, Anthropic, OpenRouter, Groq, DeepSeek, Mistral, Together, Ollama, Cloudflare AI Gateway).
|
|
370
|
+
*/
|
|
371
|
+
export interface PrivacyFetchOptions extends SanitizeOptions {
|
|
372
|
+
fetch?: typeof fetch;
|
|
373
|
+
engine?: PrivacyScrubberEngine;
|
|
374
|
+
sanitizeInputs?: boolean;
|
|
375
|
+
sanitizeOutputs?: boolean;
|
|
376
|
+
streamingOptions?: any;
|
|
377
|
+
onSanitized?: (telemetry: { url: string; tokenMap: Record<string, string>; tokenCount: number }) => void;
|
|
378
|
+
}
|
|
379
|
+
export function createPrivacyFetch(options?: PrivacyFetchOptions): typeof fetch & { engine: PrivacyScrubberEngine };
|
|
380
|
+
|
|
381
|
+
/**
|
|
382
|
+
* OpenAI Agents SDK (@openai/agents) compatible InputGuardrail and OutputGuardrail factory.
|
|
383
|
+
*/
|
|
384
|
+
export interface OpenAIAgentGuardrailsOptions extends SanitizeOptions {
|
|
385
|
+
engine?: PrivacyScrubberEngine;
|
|
386
|
+
inputGuardrailName?: string;
|
|
387
|
+
outputGuardrailName?: string;
|
|
388
|
+
tripwireOnCritical?: boolean;
|
|
389
|
+
tripwireOnAnyPii?: boolean;
|
|
390
|
+
tripwireOnOutputLeak?: boolean;
|
|
391
|
+
mutateInPlace?: boolean;
|
|
392
|
+
}
|
|
393
|
+
export interface OpenAIAgentGuardrailsResult {
|
|
394
|
+
inputGuardrail: {
|
|
395
|
+
name: string;
|
|
396
|
+
execute: (args: { input: any; context?: any; agent?: any }) => Promise<{
|
|
397
|
+
tripwireTriggered: boolean;
|
|
398
|
+
outputInfo: {
|
|
399
|
+
scrubbedInput: any;
|
|
400
|
+
tokenMap: Record<string, string>;
|
|
401
|
+
tokenCount: number;
|
|
402
|
+
riskLevel: string;
|
|
403
|
+
frameworks?: string[];
|
|
404
|
+
telemetry: AuditTelemetry;
|
|
405
|
+
};
|
|
406
|
+
}>;
|
|
407
|
+
};
|
|
408
|
+
outputGuardrail: {
|
|
409
|
+
name: string;
|
|
410
|
+
execute: (args: { agentOutput: any; context?: any; agent?: any }) => Promise<{
|
|
411
|
+
tripwireTriggered: boolean;
|
|
412
|
+
outputInfo: {
|
|
413
|
+
restoredOutput: any;
|
|
414
|
+
restoredCount: number;
|
|
415
|
+
};
|
|
416
|
+
}>;
|
|
417
|
+
};
|
|
418
|
+
inputGuardrails: Array<OpenAIAgentGuardrailsResult['inputGuardrail']>;
|
|
419
|
+
outputGuardrails: Array<OpenAIAgentGuardrailsResult['outputGuardrail']>;
|
|
420
|
+
engine: PrivacyScrubberEngine;
|
|
421
|
+
}
|
|
422
|
+
export function createOpenAIAgentGuardrails(options?: OpenAIAgentGuardrailsOptions): OpenAIAgentGuardrailsResult;
|
|
423
|
+
|
|
299
424
|
/**
|
|
300
425
|
* Transparent zero-trust wrapper for Vercel AI SDK language models.
|
|
301
426
|
* Sanitizes prompts in local RAM and detokenizes streaming and final outputs.
|
|
@@ -595,11 +720,15 @@ export function unscrubText(
|
|
|
595
720
|
};
|
|
596
721
|
|
|
597
722
|
declare const defaultExport: {
|
|
723
|
+
SDK_VERSION: typeof SDK_VERSION;
|
|
598
724
|
clean: typeof clean;
|
|
599
725
|
sanitize: typeof sanitize;
|
|
726
|
+
sanitizeObject: typeof sanitizeObject;
|
|
600
727
|
scrub: typeof scrub;
|
|
601
728
|
restore: typeof restore;
|
|
729
|
+
restoreObject: typeof restoreObject;
|
|
602
730
|
unscrub: typeof unscrub;
|
|
731
|
+
desanitize: typeof desanitize;
|
|
603
732
|
StreamingDetokenizer: typeof StreamingDetokenizer;
|
|
604
733
|
createStreamTokenRestorer: typeof createStreamTokenRestorer;
|
|
605
734
|
createNodeStreamTokenRestorer: typeof createNodeStreamTokenRestorer;
|
|
@@ -610,13 +739,28 @@ declare const defaultExport: {
|
|
|
610
739
|
validateLicense: typeof validateLicense;
|
|
611
740
|
validateLicenseKey: typeof validateLicenseKey;
|
|
612
741
|
buildAuditTelemetry: typeof buildAuditTelemetry;
|
|
742
|
+
buildCisoAuditTelemetry: typeof buildCisoAuditTelemetry;
|
|
613
743
|
formatAuditReceipt: typeof formatAuditReceipt;
|
|
744
|
+
generateAuditReport: typeof generateAuditReport;
|
|
745
|
+
PSR2_VERSION: typeof PSR2_VERSION;
|
|
746
|
+
PSR2_STATEMENTS: typeof PSR2_STATEMENTS;
|
|
747
|
+
buildPsr2Receipt: typeof buildPsr2Receipt;
|
|
748
|
+
psr2Lines: typeof psr2Lines;
|
|
749
|
+
formatCefEvent: typeof formatCefEvent;
|
|
750
|
+
formatSyslogEvent: typeof formatSyslogEvent;
|
|
751
|
+
formatJsonlEvent: typeof formatJsonlEvent;
|
|
752
|
+
createAuditLogger: typeof createAuditLogger;
|
|
614
753
|
generateProcurementMemo: typeof generateProcurementMemo;
|
|
615
754
|
PrivacyScrubberEngine: typeof PrivacyScrubberEngine;
|
|
616
755
|
PrivacyScrubberLicenseError: typeof PrivacyScrubberLicenseError;
|
|
617
756
|
wrapOpenAI: typeof wrapOpenAI;
|
|
757
|
+
wrapAnthropic: typeof wrapAnthropic;
|
|
758
|
+
wrapGemini: typeof wrapGemini;
|
|
759
|
+
wrapGoogleGenAI: typeof wrapGoogleGenAI;
|
|
618
760
|
wrapAiModel: typeof wrapAiModel;
|
|
619
761
|
wrapAiSdk: typeof wrapAiSdk;
|
|
762
|
+
createPrivacyFetch: typeof createPrivacyFetch;
|
|
763
|
+
createOpenAIAgentGuardrails: typeof createOpenAIAgentGuardrails;
|
|
620
764
|
createLangChainTransform: typeof createLangChainTransform;
|
|
621
765
|
createDocumentTransformer: typeof createDocumentTransformer;
|
|
622
766
|
createLangChainDocumentTransformer: typeof createLangChainDocumentTransformer;
|
|
@@ -628,6 +772,7 @@ declare const defaultExport: {
|
|
|
628
772
|
createGuardedTools: typeof createGuardedTools;
|
|
629
773
|
scrubText: typeof scrubText;
|
|
630
774
|
unscrubText: typeof unscrubText;
|
|
775
|
+
DEVOPS_SECRETS_DETECTOR: typeof DEVOPS_SECRETS_DETECTOR;
|
|
631
776
|
stripExifMetadata: typeof stripExifMetadata;
|
|
632
777
|
redactImageBoundingBoxes: typeof redactImageBoundingBoxes;
|
|
633
778
|
generateSvgRedactionOverlay: typeof generateSvgRedactionOverlay;
|