@devilsdev/rag-pipeline-utils 2.1.12 → 2.2.1

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 (113) hide show
  1. package/.ragrc.schema.json +218 -0
  2. package/README.md +178 -550
  3. package/bin/cli.js +8 -14
  4. package/contracts/reranker-contract.json +69 -0
  5. package/dist/index.d.ts +237 -0
  6. package/dist/index.mjs +22 -7
  7. package/package.json +18 -13
  8. package/src/ai/adaptive-retrieval.js +191 -0
  9. package/src/ai/federated-learning.js +214 -0
  10. package/src/ai/federation/federated-learning-coordinator.js +345 -0
  11. package/src/ai/federation.js +76 -0
  12. package/src/ai/index-fixed.js +509 -0
  13. package/src/ai/index.js +33 -0
  14. package/src/ai/model-trainer.js +217 -0
  15. package/src/ai/model-training.js +205 -0
  16. package/src/ai/module-template.js +37 -0
  17. package/src/ai/multimodal/multi-modal-processor.js +345 -0
  18. package/src/ai/multimodal-processing.js +268 -0
  19. package/src/ai/multimodal.js +71 -0
  20. package/src/ai/orchestrator.js +70 -0
  21. package/src/ai/retrieval/adaptive-retrieval-engine.js +398 -0
  22. package/src/ai/retrieval-engine.js +69 -0
  23. package/src/ai/training/model-training-orchestrator.js +228 -0
  24. package/src/ci/workflow-analyzer.js +71 -0
  25. package/src/cli/commands/ai-ml.js +967 -0
  26. package/src/cli/commands/docs.js +228 -0
  27. package/src/cli/commands/dx.js +538 -0
  28. package/src/cli/commands/plugin-hub.js +875 -0
  29. package/src/cli/doctor-command.js +639 -0
  30. package/src/cli/enhanced-cli-commands.js +945 -0
  31. package/src/cli/interactive-wizard.js +997 -0
  32. package/src/cli/plugin-marketplace-commands.js +869 -0
  33. package/src/cli.js +17 -0
  34. package/src/config/enhanced-ragrc-schema.js +632 -0
  35. package/src/config/load-config.js +54 -0
  36. package/src/config/load-plugin-config.js +69 -0
  37. package/src/config/normalize-config.js +105 -0
  38. package/src/config/schema-validator.js +315 -0
  39. package/src/config/validate-plugin-schema.js +35 -0
  40. package/src/config/validate-schema.js +113 -0
  41. package/src/contracts/plugin-contracts.js +33 -0
  42. package/src/core/create-pipeline.js +99 -0
  43. package/src/core/dependency-injection.js +242 -0
  44. package/src/core/observability/event-logger.js +241 -0
  45. package/src/core/observability/instrumented-pipeline.js +609 -0
  46. package/src/core/observability/metrics.js +497 -0
  47. package/src/core/observability/tracing.js +781 -0
  48. package/src/core/performance/benchmark.js +516 -0
  49. package/src/core/performance/parallel-processor.js +240 -0
  50. package/src/core/performance/streaming-safeguards.js +620 -0
  51. package/src/core/pipeline-factory.js +60 -0
  52. package/src/core/plugin-contracts.js +89 -0
  53. package/src/core/plugin-marketplace/plugin-metadata.js +485 -0
  54. package/src/core/plugin-marketplace/plugin-publisher.js +574 -0
  55. package/src/core/plugin-marketplace/plugin-registry-format.js +419 -0
  56. package/src/core/plugin-marketplace/version-resolver.js +61 -0
  57. package/src/core/plugin-registry.js +294 -0
  58. package/src/dag/dag-engine.js +954 -0
  59. package/src/dag/dag-node.js +76 -0
  60. package/src/dag/enhanced-dag-engine.js +822 -0
  61. package/src/dx/index.js +40 -0
  62. package/src/dx/integration-templates.js +665 -0
  63. package/src/dx/performance-profiler.js +968 -0
  64. package/src/dx/realtime-debugger.js +755 -0
  65. package/src/dx/visual-pipeline-builder.js +578 -0
  66. package/src/ecosystem/plugin-analytics-dashboard.js +778 -0
  67. package/src/ecosystem/plugin-certification.js +580 -0
  68. package/src/ecosystem/plugin-hub.js +821 -0
  69. package/src/enterprise/audit-logging.js +967 -0
  70. package/src/enterprise/data-governance.js +408 -0
  71. package/src/enterprise/multi-tenancy.js +496 -0
  72. package/src/enterprise/sso-integration.js +1030 -0
  73. package/src/evaluate/evaluator.js +52 -0
  74. package/src/evaluate/scoring.js +91 -0
  75. package/src/index.js +67 -0
  76. package/src/ingest.js +59 -0
  77. package/src/loader/csv-loader.js +38 -0
  78. package/src/loader/directory-loader.js +48 -0
  79. package/src/loader/html-loader.js +62 -0
  80. package/src/loader/markdown-loader.js +67 -0
  81. package/src/mocks/openai-embedder.js +119 -0
  82. package/src/mocks/openai-llm.js +77 -0
  83. package/src/mocks/pdf-loader.js +21 -0
  84. package/src/mocks/pinecone-retriever.js +106 -0
  85. package/src/observability/audit-logger.js +758 -0
  86. package/src/observability/dashboard-config.json +675 -0
  87. package/src/observability/event-logger.js +310 -0
  88. package/src/observability/metrics.js +691 -0
  89. package/src/observability/security-monitor.js +830 -0
  90. package/src/observability/slo-monitor.js +319 -0
  91. package/src/observability/telemetry.js +686 -0
  92. package/src/pipeline/pipeline.js +18 -0
  93. package/src/plugins/sample-embedder.js +53 -0
  94. package/src/plugins/sample-llm.js +30 -0
  95. package/src/plugins/sample-loader.js +24 -0
  96. package/src/plugins/sample-retriever.js +84 -0
  97. package/src/query.js +117 -0
  98. package/src/reranker/llm-reranker.js +111 -0
  99. package/src/scripts/script-utilities.js +36 -0
  100. package/src/security/plugin-sandbox.js +586 -0
  101. package/src/security/plugin-signature-verifier.js +414 -0
  102. package/src/security/validator.js +36 -0
  103. package/src/utils/ci/diagnostic-reporter.js +57 -0
  104. package/src/utils/logger.js +211 -0
  105. package/src/utils/performance-monitor.js +561 -0
  106. package/src/utils/plugin-scaffolder.js +447 -0
  107. package/src/utils/rate-limiter.js +244 -0
  108. package/src/utils/retry-policy.js +443 -0
  109. package/src/utils/retry.js +107 -0
  110. package/src/utils/safe-expression-evaluator.js +579 -0
  111. package/src/utils/secure-logging.js +338 -0
  112. package/src/utils/structured-logger.js +388 -0
  113. package/src/utils/validate-plugin-contract.js +42 -0
@@ -0,0 +1,310 @@
1
+ 'use strict';
2
+
3
+ const EventTypes = {
4
+ PLUGIN_START: 'plugin.start',
5
+ PLUGIN_END: 'plugin.end',
6
+ PLUGIN_ERROR: 'plugin.error',
7
+ STAGE_START: 'stage.start',
8
+ STAGE_END: 'stage.end',
9
+ PERFORMANCE_METRIC: 'performance.metric',
10
+ MEMORY_WARNING: 'memory.warning',
11
+ BACKPRESSURE_APPLIED: 'backpressure.applied',
12
+ BACKPRESSURE_RELEASED: 'backpressure.released',
13
+ };
14
+
15
+ const EventSeverity = {
16
+ DEBUG: 'debug',
17
+ INFO: 'info',
18
+ WARN: 'warn',
19
+ ERROR: 'error',
20
+ };
21
+
22
+ function nowISO() {
23
+ return new Date().toISOString();
24
+ }
25
+ function randId() {
26
+ return Math.random().toString(36).slice(2, 10);
27
+ }
28
+
29
+ class PipelineEventLogger {
30
+ constructor(options = {}) {
31
+ const {
32
+ enabled = true,
33
+ includeStackTrace = false,
34
+ maxEventHistory = 1000,
35
+ sessionId = `session_${Date.now()}_${randId()}`,
36
+ } = options;
37
+ this.enabled = !!enabled;
38
+ this.includeStackTrace = !!includeStackTrace;
39
+ this.maxEventHistory = maxEventHistory || 1000;
40
+ this.sessionId = sessionId;
41
+ this.eventHistory = [];
42
+ this._listeners = new Map();
43
+ }
44
+
45
+ logEvent(eventType, severity, metadata = {}, message = '') {
46
+ if (!this.enabled) return;
47
+ const evt = {
48
+ timestamp: nowISO(),
49
+ sessionId: this.sessionId,
50
+ eventType,
51
+ severity,
52
+ message,
53
+ metadata,
54
+ };
55
+ if (this.includeStackTrace && severity === EventSeverity.ERROR) {
56
+ evt.stackTrace = new Error().stack;
57
+ }
58
+ this.eventHistory.push(evt);
59
+ if (this.eventHistory.length > this.maxEventHistory) {
60
+ this.eventHistory.splice(
61
+ 0,
62
+ this.eventHistory.length - this.maxEventHistory,
63
+ );
64
+ }
65
+ const listeners = this._listeners.get(eventType);
66
+ if (listeners) {
67
+ for (const fn of listeners) {
68
+ try {
69
+ fn(evt);
70
+ } catch (e) {
71
+ console.warn('Event listener error:', e);
72
+ }
73
+ }
74
+ }
75
+ }
76
+
77
+ getInputSize(input) {
78
+ return Array.isArray(input)
79
+ ? { type: 'array', length: input.length }
80
+ : typeof input === 'string'
81
+ ? { type: 'string', length: input.length }
82
+ : typeof input === 'object' && input !== null
83
+ ? { type: 'object', keys: Object.keys(input).length }
84
+ : { type: typeof input };
85
+ }
86
+
87
+ logPluginStart(pluginType, pluginName, input, context = {}) {
88
+ const inputSize = this.getInputSize(input);
89
+ this.logEvent(
90
+ EventTypes.PLUGIN_START,
91
+ EventSeverity.DEBUG,
92
+ {
93
+ pluginType,
94
+ pluginName,
95
+ inputSize,
96
+ context,
97
+ stage: 'start',
98
+ pid: process.pid,
99
+ platform: process.platform,
100
+ nodeVersion: process.version,
101
+ },
102
+ `Starting ${pluginType} plugin: ${pluginName}`,
103
+ );
104
+ }
105
+
106
+ logPluginEnd(
107
+ pluginType,
108
+ pluginName,
109
+ duration,
110
+ resultSize = {},
111
+ context = {},
112
+ ) {
113
+ this.logEvent(
114
+ EventTypes.PLUGIN_END,
115
+ EventSeverity.DEBUG,
116
+ {
117
+ pluginType,
118
+ pluginName,
119
+ duration,
120
+ resultSize,
121
+ context,
122
+ status: 'success',
123
+ stage: 'end',
124
+ pid: process.pid,
125
+ platform: process.platform,
126
+ nodeVersion: process.version,
127
+ },
128
+ `Completed ${pluginType} plugin: ${pluginName} (${duration}ms)`,
129
+ );
130
+ }
131
+
132
+ logPluginError(pluginType, pluginName, error, duration, context = {}) {
133
+ const safeError =
134
+ error instanceof Error
135
+ ? { name: error.name, message: error.message, code: error.code }
136
+ : { name: 'Error', message: String(error) };
137
+ this.logEvent(
138
+ EventTypes.PLUGIN_ERROR,
139
+ EventSeverity.ERROR,
140
+ {
141
+ pluginType,
142
+ pluginName,
143
+ duration,
144
+ context,
145
+ status: 'error',
146
+ error: safeError,
147
+ pid: process.pid,
148
+ platform: process.platform,
149
+ nodeVersion: process.version,
150
+ },
151
+ `Failed ${pluginType} plugin: ${pluginName} - ${safeError.message}`,
152
+ );
153
+ }
154
+
155
+ logStageStart(stage, metadata = {}) {
156
+ this.logEvent(
157
+ EventTypes.STAGE_START,
158
+ EventSeverity.INFO,
159
+ {
160
+ stage,
161
+ ...metadata,
162
+ pid: process.pid,
163
+ platform: process.platform,
164
+ nodeVersion: process.version,
165
+ },
166
+ `Starting pipeline stage: ${stage}`,
167
+ );
168
+ }
169
+
170
+ logStageEnd(stage, duration, metadata = {}) {
171
+ this.logEvent(
172
+ EventTypes.STAGE_END,
173
+ EventSeverity.INFO,
174
+ {
175
+ stage,
176
+ duration,
177
+ status: 'success', // Default status for completed stages
178
+ ...metadata,
179
+ pid: process.pid,
180
+ platform: process.platform,
181
+ nodeVersion: process.version,
182
+ },
183
+ `Completed pipeline stage: ${stage} (${duration}ms)`,
184
+ );
185
+ }
186
+
187
+ logPerformanceMetric(name, value, unit = '', extra = {}) {
188
+ this.logEvent(
189
+ EventTypes.PERFORMANCE_METRIC,
190
+ EventSeverity.DEBUG,
191
+ {
192
+ metric: name,
193
+ value,
194
+ unit,
195
+ tags: extra, // Store extra as tags object
196
+ },
197
+ `Perf ${name}: ${value}${unit}`,
198
+ );
199
+ }
200
+
201
+ logMemoryWarning(memoryUsage, thresholdMB) {
202
+ const bytes = memoryUsage.heapUsed || 0;
203
+ const thresholdBytes = thresholdMB * 1024 * 1024;
204
+ const usagePercentage =
205
+ thresholdBytes > 0 ? (bytes / thresholdBytes) * 100 : 0;
206
+ this.logEvent(
207
+ EventTypes.MEMORY_WARNING,
208
+ EventSeverity.WARN,
209
+ { memoryUsage, threshold: thresholdMB, usagePercentage },
210
+ 'Memory warning',
211
+ );
212
+ }
213
+
214
+ logBackpressure(action, status = {}) {
215
+ const eventType =
216
+ action === 'released'
217
+ ? EventTypes.BACKPRESSURE_RELEASED
218
+ : EventTypes.BACKPRESSURE_APPLIED;
219
+ this.logEvent(
220
+ eventType,
221
+ EventSeverity.WARN,
222
+ { action, ...status },
223
+ `Backpressure ${action}`,
224
+ );
225
+ }
226
+
227
+ addEventListener(eventType, fn) {
228
+ if (!this._listeners.has(eventType))
229
+ this._listeners.set(eventType, new Set());
230
+ this._listeners.get(eventType).add(fn);
231
+ }
232
+ removeEventListener(eventType, fn) {
233
+ const s = this._listeners.get(eventType);
234
+ if (s) s.delete(fn);
235
+ }
236
+
237
+ getEventHistory(filters = {}) {
238
+ const { pluginType, eventType, severity, since, limit } = filters;
239
+ let out = this.eventHistory.slice();
240
+ if (eventType) out = out.filter((e) => e.eventType === eventType);
241
+ if (severity) out = out.filter((e) => e.severity === severity);
242
+ if (pluginType)
243
+ out = out.filter(
244
+ (e) => e.metadata && e.metadata.pluginType === pluginType,
245
+ );
246
+ if (since)
247
+ out = out.filter((e) => new Date(e.timestamp) >= new Date(since));
248
+ if (typeof limit === 'number') out = out.slice(-limit);
249
+ return out;
250
+ }
251
+
252
+ clearHistory() {
253
+ this.eventHistory = [];
254
+ }
255
+
256
+ exportEvents(filters = {}) {
257
+ const events = this.getEventHistory(filters);
258
+ return JSON.stringify({
259
+ sessionId: this.sessionId,
260
+ exportTime: nowISO(),
261
+ eventCount: events.length,
262
+ events,
263
+ });
264
+ }
265
+
266
+ getSessionStats() {
267
+ const total = this.eventHistory.length;
268
+ const eventTypes = this.eventHistory.reduce((acc, e) => {
269
+ acc[e.eventType] = (acc[e.eventType] || 0) + 1;
270
+ return acc;
271
+ }, {});
272
+
273
+ const severityLevels = this.eventHistory.reduce((acc, e) => {
274
+ acc[e.severity] = (acc[e.severity] || 0) + 1;
275
+ return acc;
276
+ }, {});
277
+
278
+ const pluginTypes = this.eventHistory.reduce((acc, e) => {
279
+ if (e.metadata && e.metadata.pluginType) {
280
+ acc[e.metadata.pluginType] = (acc[e.metadata.pluginType] || 0) + 1;
281
+ }
282
+ return acc;
283
+ }, {});
284
+
285
+ const timestamps = this.eventHistory.map((e) => new Date(e.timestamp));
286
+ const sessionStartTime = timestamps.length ? Math.min(...timestamps) : null;
287
+ const lastEventTime = timestamps.length ? Math.max(...timestamps) : null;
288
+
289
+ return {
290
+ sessionId: this.sessionId,
291
+ totalEvents: total,
292
+ byType: eventTypes, // Keep for backward compatibility
293
+ eventTypes,
294
+ severityLevels,
295
+ pluginTypes,
296
+ sessionStartTime,
297
+ lastEventTime,
298
+ };
299
+ }
300
+ }
301
+
302
+ const eventLogger = new PipelineEventLogger();
303
+ if (!global.eventLogger) global.eventLogger = eventLogger;
304
+
305
+ module.exports = {
306
+ PipelineEventLogger,
307
+ EventTypes,
308
+ EventSeverity,
309
+ eventLogger,
310
+ };