UNPKG

@dawans/promptshield

Version:

Secure your LLM stack with enterprise-grade RulePacks for AI safety scanning

76 lines (75 loc) 2.77 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ScanCommand = void 0; /** * Scan command data transfer object */ class ScanCommand { constructor(input, options) { this.input = input; this.options = options; } /** * Converts command options to scan configuration */ toScanConfig() { return { rulepack: this.options.rulepack || 'default', outputFormat: (this.options.output || 'markdown'), outputFile: this.options.outputFile, // Filtering severity: this.parseSeverity(this.options.severity), category: this.parseCategory(this.options.category), maxViolations: this.options.maxViolations, offset: this.options.offset, limit: this.options.limit, // Processing fields: this.parseFields(this.options.fields), scanEntireObject: this.options.scanEntireObject || false, maxObjects: this.options.maxObjects, maxDepth: this.options.maxDepth || 4, schema: this.options.schema, // Performance ndjsonMode: this.options.ndjson || false, streamingThreshold: this.options.streamingThreshold || 1000, parallel: this.parseParallel(this.options.parallel), batchSize: this.options.batchSize || 10, timeout: this.options.timeout || 300, memoryWarningThreshold: this.options.memoryWarningThreshold || 0.8, // Compression compress: this.options.compress, compressionLevel: this.options.compressionLevel, // Output control quiet: this.options.quiet || false, verbose: this.options.verbose || false, debug: this.options.debug || false, noColor: this.options.noColor, strict: this.options.strict || false, failOn: this.options.failOn, }; } parseSeverity(severity) { if (!severity) return ['low', 'medium', 'high', 'critical']; return severity.split(',').map((s) => s.trim()); } parseCategory(category) { if (!category) return []; return category.split(',').map((c) => c.trim()); } parseFields(fields) { if (!fields) return ['prompt', 'response', 'content']; return fields.split(',').map((f) => f.trim()); } parseParallel(parallel) { if (parallel === false || parallel === undefined) return false; if (parallel === true) return true; const num = parseInt(parallel, 10); return isNaN(num) ? true : num; } } exports.ScanCommand = ScanCommand;