@devilsdev/rag-pipeline-utils 2.1.12 → 2.2.0

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.
Files changed (110) hide show
  1. package/.ragrc.schema.json +218 -0
  2. package/README.md +292 -32
  3. package/bin/cli.js +8 -14
  4. package/dist/index.d.ts +237 -0
  5. package/dist/index.mjs +22 -7
  6. package/package.json +17 -13
  7. package/src/ai/adaptive-retrieval.js +191 -0
  8. package/src/ai/federated-learning.js +214 -0
  9. package/src/ai/federation/federated-learning-coordinator.js +345 -0
  10. package/src/ai/federation.js +76 -0
  11. package/src/ai/index-fixed.js +509 -0
  12. package/src/ai/index.js +33 -0
  13. package/src/ai/model-trainer.js +217 -0
  14. package/src/ai/model-training.js +205 -0
  15. package/src/ai/module-template.js +37 -0
  16. package/src/ai/multimodal/multi-modal-processor.js +345 -0
  17. package/src/ai/multimodal-processing.js +268 -0
  18. package/src/ai/multimodal.js +71 -0
  19. package/src/ai/orchestrator.js +70 -0
  20. package/src/ai/retrieval/adaptive-retrieval-engine.js +398 -0
  21. package/src/ai/retrieval-engine.js +69 -0
  22. package/src/ai/training/model-training-orchestrator.js +228 -0
  23. package/src/ci/workflow-analyzer.js +71 -0
  24. package/src/cli/commands/ai-ml.js +967 -0
  25. package/src/cli/commands/docs.js +228 -0
  26. package/src/cli/commands/dx.js +538 -0
  27. package/src/cli/commands/plugin-hub.js +875 -0
  28. package/src/cli/doctor-command.js +639 -0
  29. package/src/cli/enhanced-cli-commands.js +945 -0
  30. package/src/cli/interactive-wizard.js +997 -0
  31. package/src/cli/plugin-marketplace-commands.js +869 -0
  32. package/src/cli.js +17 -0
  33. package/src/config/enhanced-ragrc-schema.js +632 -0
  34. package/src/config/load-config.js +54 -0
  35. package/src/config/load-plugin-config.js +69 -0
  36. package/src/config/normalize-config.js +105 -0
  37. package/src/config/schema-validator.js +315 -0
  38. package/src/config/validate-plugin-schema.js +35 -0
  39. package/src/config/validate-schema.js +113 -0
  40. package/src/contracts/plugin-contracts.js +33 -0
  41. package/src/core/create-pipeline.js +99 -0
  42. package/src/core/dependency-injection.js +242 -0
  43. package/src/core/observability/event-logger.js +241 -0
  44. package/src/core/observability/instrumented-pipeline.js +609 -0
  45. package/src/core/observability/metrics.js +497 -0
  46. package/src/core/observability/tracing.js +781 -0
  47. package/src/core/performance/benchmark.js +516 -0
  48. package/src/core/performance/parallel-processor.js +240 -0
  49. package/src/core/performance/streaming-safeguards.js +611 -0
  50. package/src/core/pipeline-factory.js +60 -0
  51. package/src/core/plugin-contracts.js +89 -0
  52. package/src/core/plugin-marketplace/plugin-metadata.js +485 -0
  53. package/src/core/plugin-marketplace/plugin-publisher.js +574 -0
  54. package/src/core/plugin-marketplace/plugin-registry-format.js +419 -0
  55. package/src/core/plugin-marketplace/version-resolver.js +61 -0
  56. package/src/core/plugin-registry.js +265 -0
  57. package/src/dag/dag-engine.js +954 -0
  58. package/src/dag/dag-node.js +76 -0
  59. package/src/dag/enhanced-dag-engine.js +822 -0
  60. package/src/dx/index.js +40 -0
  61. package/src/dx/integration-templates.js +665 -0
  62. package/src/dx/performance-profiler.js +968 -0
  63. package/src/dx/realtime-debugger.js +755 -0
  64. package/src/dx/visual-pipeline-builder.js +578 -0
  65. package/src/ecosystem/plugin-analytics-dashboard.js +778 -0
  66. package/src/ecosystem/plugin-certification.js +580 -0
  67. package/src/ecosystem/plugin-hub.js +821 -0
  68. package/src/enterprise/audit-logging.js +967 -0
  69. package/src/enterprise/data-governance.js +408 -0
  70. package/src/enterprise/multi-tenancy.js +496 -0
  71. package/src/enterprise/sso-integration.js +903 -0
  72. package/src/evaluate/evaluator.js +52 -0
  73. package/src/evaluate/scoring.js +91 -0
  74. package/src/index.js +67 -0
  75. package/src/ingest.js +59 -0
  76. package/src/loader/csv-loader.js +38 -0
  77. package/src/loader/directory-loader.js +48 -0
  78. package/src/loader/html-loader.js +62 -0
  79. package/src/loader/markdown-loader.js +67 -0
  80. package/src/mocks/openai-embedder.js +119 -0
  81. package/src/mocks/openai-llm.js +77 -0
  82. package/src/mocks/pdf-loader.js +21 -0
  83. package/src/mocks/pinecone-retriever.js +106 -0
  84. package/src/observability/audit-logger.js +758 -0
  85. package/src/observability/dashboard-config.json +675 -0
  86. package/src/observability/event-logger.js +310 -0
  87. package/src/observability/metrics.js +691 -0
  88. package/src/observability/security-monitor.js +830 -0
  89. package/src/observability/slo-monitor.js +319 -0
  90. package/src/observability/telemetry.js +686 -0
  91. package/src/pipeline/pipeline.js +18 -0
  92. package/src/plugins/sample-embedder.js +53 -0
  93. package/src/plugins/sample-llm.js +30 -0
  94. package/src/plugins/sample-loader.js +24 -0
  95. package/src/plugins/sample-retriever.js +84 -0
  96. package/src/query.js +117 -0
  97. package/src/reranker/llm-reranker.js +85 -0
  98. package/src/scripts/script-utilities.js +36 -0
  99. package/src/security/plugin-sandbox.js +586 -0
  100. package/src/security/plugin-signature-verifier.js +414 -0
  101. package/src/security/validator.js +36 -0
  102. package/src/utils/ci/diagnostic-reporter.js +57 -0
  103. package/src/utils/logger.js +211 -0
  104. package/src/utils/performance-monitor.js +561 -0
  105. package/src/utils/plugin-scaffolder.js +447 -0
  106. package/src/utils/retry-policy.js +443 -0
  107. package/src/utils/retry.js +107 -0
  108. package/src/utils/safe-expression-evaluator.js +579 -0
  109. package/src/utils/structured-logger.js +361 -0
  110. package/src/utils/validate-plugin-contract.js +42 -0
@@ -0,0 +1,408 @@
1
+ /**
2
+ * Enterprise Data Governance
3
+ * PII detection, data lineage, retention policies, and privacy controls
4
+ */
5
+
6
+ const fs = require('fs').promises;
7
+ const path = require('path');
8
+ const crypto = require('crypto');
9
+ // eslint-disable-line global-require
10
+ const { EventEmitter } = require('events');
11
+ // eslint-disable-line global-require
12
+
13
+ class DataGovernanceManager extends EventEmitter {
14
+ constructor(_options = {}) {
15
+ super();
16
+
17
+ this._config = {
18
+ policies: {
19
+ dataRetention: {
20
+ defaultRetentionDays: 2555, // 7 years
21
+ piiRetentionDays: 1095, // 3 years
22
+ logRetentionDays: 2555,
23
+ backupRetentionDays: 365,
24
+ },
25
+ dataClassification: {
26
+ levels: ['PUBLIC', 'INTERNAL', 'CONFIDENTIAL', 'RESTRICTED'],
27
+ autoClassify: true,
28
+ requireManualReview: true,
29
+ },
30
+ privacy: {
31
+ piiDetection: true,
32
+ dataMinimization: true,
33
+ consentTracking: true,
34
+ rightToErasure: true,
35
+ dataPortability: true,
36
+ },
37
+ },
38
+ compliance: {
39
+ standards: ['GDPR', 'CCPA', 'HIPAA', 'SOX'],
40
+ autoReporting: true,
41
+ breachNotification: true,
42
+ },
43
+ ..._options,
44
+ };
45
+
46
+ this.classificationEngine = new DataClassificationEngine(this._config);
47
+ this.piiDetector = new PIIDetector(this._config);
48
+ this.lineageTracker = new DataLineageTracker(this._config);
49
+ this.retentionManager = new DataRetentionManager(this._config);
50
+ this.privacyManager = new PrivacyManager(this._config);
51
+ }
52
+
53
+ /**
54
+ * Classify and govern data
55
+ */
56
+ async governData(_tenantId, _data, _context = {}) {
57
+ const governanceResult = {
58
+ dataId: crypto.randomUUID(),
59
+ _tenantId,
60
+ timestamp: new Date().toISOString(),
61
+ classification: null,
62
+ piiDetected: false,
63
+ lineage: null,
64
+ retentionPolicy: null,
65
+ privacyControls: [],
66
+ complianceStatus: 'pending',
67
+ };
68
+
69
+ try {
70
+ // Step 1: Classify _data
71
+ governanceResult.classification =
72
+ await this.classificationEngine.classify(_data, _context);
73
+
74
+ // Step 2: Detect PII
75
+ const piiResults = await this.piiDetector.scan(_data);
76
+ governanceResult.piiDetected = piiResults.detected;
77
+ governanceResult.piiTypes = piiResults.types;
78
+
79
+ // Step 3: Track lineage
80
+ governanceResult.lineage = await this.lineageTracker.track(
81
+ _data,
82
+ _context,
83
+ );
84
+
85
+ // Step 4: Apply retention policy
86
+ governanceResult.retentionPolicy =
87
+ await this.retentionManager.applyPolicy(
88
+ governanceResult.classification.level,
89
+ governanceResult.piiDetected,
90
+ );
91
+
92
+ // Step 5: Apply privacy controls
93
+ if (governanceResult.piiDetected) {
94
+ governanceResult.privacyControls =
95
+ await this.privacyManager.applyControls(_data, piiResults, _context);
96
+ }
97
+
98
+ // Step 6: Check compliance
99
+ governanceResult.complianceStatus =
100
+ await this._checkCompliance(governanceResult);
101
+
102
+ this.emit('data_governed', governanceResult);
103
+
104
+ return governanceResult;
105
+ } catch (error) {
106
+ this.emit('governance_error', { error: error.message, _tenantId });
107
+ throw error;
108
+ }
109
+ }
110
+
111
+ /**
112
+ * Handle privacy requests (GDPR Article 17, CCPA)
113
+ */
114
+ async handlePrivacyRequest(_tenantId, _request) {
115
+ const requestId = crypto.randomUUID();
116
+
117
+ const privacyRequest = {
118
+ id: requestId,
119
+ _tenantId,
120
+ type: _request.type, // access, rectification, erasure, portability, restriction
121
+ subjectId: _request.subjectId,
122
+ subjectEmail: _request.subjectEmail,
123
+ status: 'received',
124
+ requestedAt: new Date().toISOString(),
125
+ deadline: new Date(Date.now() + 30 * 24 * 60 * 60 * 1000).toISOString(), // 30 days
126
+ metadata: _request.metadata || {},
127
+ };
128
+
129
+ switch (_request._type) {
130
+ case 'access':
131
+ privacyRequest.result = await this._handleDataAccess(
132
+ _tenantId,
133
+ _request,
134
+ );
135
+ break;
136
+ case 'erasure':
137
+ privacyRequest.result = await this._handleDataErasure(
138
+ _tenantId,
139
+ _request,
140
+ );
141
+ break;
142
+ case 'portability':
143
+ privacyRequest.result = await this._handleDataPortability(
144
+ _tenantId,
145
+ _request,
146
+ );
147
+ break;
148
+ case 'rectification':
149
+ privacyRequest.result = await this._handleDataRectification(
150
+ _tenantId,
151
+ _request,
152
+ );
153
+ break;
154
+ }
155
+
156
+ privacyRequest.status = 'completed';
157
+ privacyRequest.completedAt = new Date().toISOString();
158
+
159
+ this.emit('privacy_request_completed', privacyRequest);
160
+
161
+ return privacyRequest;
162
+ }
163
+
164
+ /**
165
+ * Generate data governance report
166
+ */
167
+ async generateGovernanceReport(_tenantId, _options = {}) {
168
+ const report = {
169
+ _tenantId,
170
+ period: {
171
+ startDate:
172
+ _options.startDate ||
173
+ new Date(Date.now() - 30 * 24 * 60 * 60 * 1000).toISOString(),
174
+ endDate: _options.endDate || new Date().toISOString(),
175
+ },
176
+ generatedAt: new Date().toISOString(),
177
+ summary: {
178
+ totalDataAssets: 0,
179
+ classifiedAssets: 0,
180
+ piiAssets: 0,
181
+ retentionPoliciesApplied: 0,
182
+ privacyRequests: 0,
183
+ complianceViolations: 0,
184
+ },
185
+ classification: {
186
+ PUBLIC: 0,
187
+ INTERNAL: 0,
188
+ CONFIDENTIAL: 0,
189
+ RESTRICTED: 0,
190
+ },
191
+ piiTypes: {},
192
+ retentionStatus: {},
193
+ complianceStatus: {
194
+ GDPR: 'compliant',
195
+ CCPA: 'compliant',
196
+ HIPAA: 'compliant',
197
+ },
198
+ };
199
+
200
+ // Mock report data - would integrate with actual data stores
201
+ report.summary.totalDataAssets = Math.floor(Math.random() * 10000);
202
+ report.summary.classifiedAssets = Math.floor(
203
+ report.summary.totalDataAssets * 0.95,
204
+ );
205
+ report.summary.piiAssets = Math.floor(
206
+ report.summary.totalDataAssets * 0.15,
207
+ );
208
+
209
+ return report;
210
+ }
211
+
212
+ // Private methods
213
+ async _checkCompliance(governanceResult) {
214
+ // Check against compliance requirements
215
+ const violations = [];
216
+
217
+ if (
218
+ governanceResult.piiDetected &&
219
+ !governanceResult.privacyControls.length
220
+ ) {
221
+ violations.push('PII detected without privacy controls');
222
+ }
223
+
224
+ if (
225
+ governanceResult.classification.level === 'RESTRICTED' &&
226
+ !governanceResult.retentionPolicy
227
+ ) {
228
+ violations.push('Restricted _data without retention policy');
229
+ }
230
+
231
+ return violations.length === 0 ? 'compliant' : 'non_compliant';
232
+ }
233
+
234
+ async _handleDataAccess(_tenantId, _request) {
235
+ // Mock data access - would query actual data stores
236
+ return {
237
+ dataFound: true,
238
+ records: [
239
+ {
240
+ _type: 'profile',
241
+ _data: { email: _request.subjectEmail, name: 'User Name' },
242
+ },
243
+ { _type: 'activity', _data: { lastLogin: '2024-01-01T00:00:00Z' } },
244
+ ],
245
+ };
246
+ }
247
+
248
+ async _handleDataErasure(_tenantId, _request) {
249
+ // Mock data erasure - would delete from actual _data stores
250
+ return {
251
+ recordsDeleted: 5,
252
+ backupsScheduledForDeletion: 2,
253
+ retentionOverrides: [],
254
+ };
255
+ }
256
+
257
+ async _handleDataPortability(_tenantId, _request) {
258
+ // Mock _data export - would generate actual export
259
+ return {
260
+ exportFormat: 'JSON',
261
+ exportSize: '2.5MB',
262
+ downloadUrl: `https://exports.example.com/${crypto.randomUUID()}.json`,
263
+ expiresAt: new Date(Date.now() + 7 * 24 * 60 * 60 * 1000).toISOString(),
264
+ };
265
+ }
266
+
267
+ async _handleDataRectification(_tenantId, _request) {
268
+ // Mock data correction - would update actual _data
269
+ return {
270
+ recordsUpdated: 3,
271
+ fieldsModified: _request.corrections || [],
272
+ };
273
+ }
274
+ }
275
+
276
+ class DataClassificationEngine {
277
+ constructor(_config) {
278
+ this._config = _config;
279
+ }
280
+
281
+ async classify(_data, _context) {
282
+ // Mock classification - would use ML models
283
+ const confidence = Math.random();
284
+ const levels = ['PUBLIC', 'INTERNAL', 'CONFIDENTIAL', 'RESTRICTED'];
285
+
286
+ return {
287
+ level: levels[Math.floor(Math.random() * levels.length)],
288
+ confidence,
289
+ reasoning: 'Automated classification based on content analysis',
290
+ reviewRequired: confidence < 0.8,
291
+ };
292
+ }
293
+ }
294
+
295
+ class PIIDetector {
296
+ constructor(_config) {
297
+ this._config = _config;
298
+ this.patterns = {
299
+ email: /\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b/g,
300
+ ssn: /\b\d{3}-\d{2}-\d{4}\b/g,
301
+ phone: /\b\d{3}-\d{3}-\d{4}\b/g,
302
+ creditCard: /\b\d{4}[-\s]?\d{4}[-\s]?\d{4}[-\s]?\d{4}\b/g,
303
+ };
304
+ }
305
+
306
+ async scan(_data) {
307
+ const dataStr = JSON.stringify(_data);
308
+ const detected = [];
309
+
310
+ for (const [_type, pattern] of Object.entries(this.patterns)) {
311
+ const matches = dataStr.match(pattern);
312
+ if (matches) {
313
+ detected.push({
314
+ _type,
315
+ count: matches.length,
316
+ samples: matches.slice(0, 3),
317
+ });
318
+ }
319
+ }
320
+
321
+ return {
322
+ detected: detected.length > 0,
323
+ types: detected,
324
+ confidence: detected.length > 0 ? 0.9 : 0.1,
325
+ };
326
+ }
327
+ }
328
+
329
+ class DataLineageTracker {
330
+ constructor(_config) {
331
+ this._config = _config;
332
+ }
333
+
334
+ async track(_data, _context) {
335
+ return {
336
+ source: _context.source || 'unknown',
337
+ transformations: _context.transformations || [],
338
+ destinations: _context.destinations || [],
339
+ timestamp: new Date().toISOString(),
340
+ version: '1.0',
341
+ };
342
+ }
343
+ }
344
+
345
+ class DataRetentionManager {
346
+ constructor(_config) {
347
+ this._config = _config;
348
+ }
349
+
350
+ async applyPolicy(classificationLevel, hasPII) {
351
+ const baseDays = this._config.policies.dataRetention.defaultRetentionDays;
352
+ const piiDays = this._config.policies.dataRetention.piiRetentionDays;
353
+
354
+ const retentionDays = hasPII ? Math.min(baseDays, piiDays) : baseDays;
355
+
356
+ return {
357
+ retentionDays,
358
+ deleteAfter: new Date(
359
+ Date.now() + retentionDays * 24 * 60 * 60 * 1000,
360
+ ).toISOString(),
361
+ policy: hasPII ? 'PII_RETENTION' : 'STANDARD_RETENTION',
362
+ autoDelete: true,
363
+ };
364
+ }
365
+ }
366
+
367
+ class PrivacyManager {
368
+ constructor(_config) {
369
+ this._config = _config;
370
+ }
371
+
372
+ async applyControls(_data, piiResults, _context) {
373
+ const controls = [];
374
+
375
+ if (piiResults.detected) {
376
+ controls.push({
377
+ _type: 'ENCRYPTION',
378
+ applied: true,
379
+ algorithm: 'AES-256-GCM',
380
+ });
381
+
382
+ controls.push({
383
+ _type: 'ACCESS_CONTROL',
384
+ applied: true,
385
+ permissions: ['read:pii', 'write:pii'],
386
+ });
387
+
388
+ controls.push({
389
+ _type: 'AUDIT_LOGGING',
390
+ applied: true,
391
+ level: 'DETAILED',
392
+ });
393
+ }
394
+
395
+ return controls;
396
+ }
397
+ }
398
+
399
+ module.exports = {
400
+ DataGovernanceManager,
401
+ DataClassificationEngine,
402
+ PIIDetector,
403
+ DataLineageTracker,
404
+ DataRetentionManager,
405
+ PrivacyManager,
406
+ };
407
+
408
+ // Ensure module.exports is properly defined