@devilsdev/rag-pipeline-utils 2.4.5 → 2.5.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 (225) hide show
  1. package/.ragrc.schema.json +83 -192
  2. package/CHANGELOG.md +345 -0
  3. package/README.md +418 -117
  4. package/SECURITY.md +5 -5
  5. package/dist/experimental.cjs +2 -0
  6. package/dist/experimental.d.ts +1 -0
  7. package/dist/experimental.mjs +5 -0
  8. package/dist/index.cjs +4992 -1242
  9. package/dist/index.d.ts +80 -2
  10. package/dist/index.mjs +1 -1
  11. package/dist/types/agentic/agentic-pipeline.d.ts +103 -0
  12. package/dist/types/agentic/iterative-retriever.d.ts +85 -0
  13. package/dist/types/agentic/query-planner.d.ts +145 -0
  14. package/dist/types/agentic/self-critique.d.ts +45 -0
  15. package/dist/types/ai/adaptive-retrieval.d.ts +44 -0
  16. package/dist/types/ai/federation/federated-learning-coordinator.d.ts +62 -0
  17. package/dist/types/ai/multimodal-processing.d.ts +32 -0
  18. package/dist/types/ai/multimodal.d.ts +39 -0
  19. package/dist/types/ai/retrieval-engine.d.ts +37 -0
  20. package/dist/types/ai/training/model-training-orchestrator.d.ts +31 -0
  21. package/dist/types/chunking/chunking-engine.d.ts +70 -0
  22. package/dist/types/chunking/strategies/fixed-size.d.ts +17 -0
  23. package/dist/types/chunking/strategies/recursive.d.ts +20 -0
  24. package/dist/types/chunking/strategies/semantic.d.ts +19 -0
  25. package/dist/types/chunking/strategies/sentence.d.ts +13 -0
  26. package/dist/types/chunking/strategies/structure-aware.d.ts +19 -0
  27. package/dist/types/citation/citation-tracker.d.ts +64 -0
  28. package/dist/types/citation/hallucination-detector.d.ts +40 -0
  29. package/dist/types/citation/source-mapper.d.ts +37 -0
  30. package/dist/types/connectors/anthropic-connector.d.ts +92 -0
  31. package/dist/types/connectors/base-connector.d.ts +87 -0
  32. package/dist/types/connectors/cohere-connector.d.ts +89 -0
  33. package/dist/types/connectors/connector-utils.d.ts +110 -0
  34. package/dist/types/connectors/local-embedder.d.ts +86 -0
  35. package/dist/types/connectors/memory-retriever.d.ts +91 -0
  36. package/dist/types/connectors/ollama-connector.d.ts +110 -0
  37. package/dist/types/connectors/openai-connector.d.ts +114 -0
  38. package/dist/types/connectors/rag-prompt.d.ts +40 -0
  39. package/dist/types/cost/cost-calculator.d.ts +152 -0
  40. package/dist/types/cost/cost-tracker.d.ts +126 -0
  41. package/dist/types/cost/token-budget.d.ts +110 -0
  42. package/dist/types/dag/core/error-context.d.ts +239 -0
  43. package/dist/types/dag/core/execution-scheduler.d.ts +191 -0
  44. package/dist/types/dag/core/topology-validation.d.ts +226 -0
  45. package/dist/types/dag/dag-engine.d.ts +156 -0
  46. package/dist/types/dag/dag-node.d.ts +37 -0
  47. package/dist/types/dashboard/dashboard-generator.d.ts +127 -0
  48. package/dist/types/dashboard/metrics-aggregator.d.ts +218 -0
  49. package/dist/types/debug/execution-tracer.d.ts +57 -0
  50. package/dist/types/debug/trace-inspector.d.ts +31 -0
  51. package/dist/types/ecosystem/plugin-certification.d.ts +169 -0
  52. package/dist/types/enterprise/data-governance.d.ts +203 -0
  53. package/dist/types/enterprise/multi-tenancy.d.ts +137 -0
  54. package/dist/types/enterprise/sso-integration.d.ts +420 -0
  55. package/dist/types/evaluate/context-metrics.d.ts +55 -0
  56. package/dist/types/evaluate/faithfulness.d.ts +41 -0
  57. package/dist/types/evaluate/groundedness.d.ts +60 -0
  58. package/dist/types/evaluate/pipeline-evaluator.d.ts +88 -0
  59. package/dist/types/evaluate/relevance.d.ts +21 -0
  60. package/dist/types/evaluate/scoring.d.ts +123 -0
  61. package/dist/types/experimental.d.ts +15 -0
  62. package/dist/types/graph/entity-extractor.d.ts +84 -0
  63. package/dist/types/graph/graph-index.d.ts +49 -0
  64. package/dist/types/graph/graph-retriever.d.ts +81 -0
  65. package/dist/types/graph/knowledge-graph.d.ts +129 -0
  66. package/dist/types/guardrails/guardrails-pipeline.d.ts +63 -0
  67. package/dist/types/guardrails/injection-detector.d.ts +47 -0
  68. package/dist/types/guardrails/post-generation-guard.d.ts +61 -0
  69. package/dist/types/guardrails/pre-retrieval-guard.d.ts +64 -0
  70. package/dist/types/guardrails/retrieval-guard.d.ts +57 -0
  71. package/dist/types/mcp/mcp-server.d.ts +85 -0
  72. package/dist/types/mcp/mcp-tool-builder.d.ts +55 -0
  73. package/dist/types/reranker/cascade-reranker.d.ts +40 -0
  74. package/dist/types/reranker/embedding-reranker.d.ts +77 -0
  75. package/dist/types/reranker/scoring-reranker.d.ts +41 -0
  76. package/dist/types/retrieval/bm25-search.d.ts +43 -0
  77. package/dist/types/retrieval/file-vector-store.d.ts +87 -0
  78. package/dist/types/retrieval/hybrid-retriever.d.ts +35 -0
  79. package/dist/types/retrieval/rank-fusion.d.ts +10 -0
  80. package/dist/types/security/jwt-config.d.ts +80 -0
  81. package/dist/types/security/jwt-validator.d.ts +195 -0
  82. package/dist/types/security/plugin-sandbox.d.ts +158 -0
  83. package/dist/types/security/plugin-signature-verifier.d.ts +139 -0
  84. package/dist/types/security/validator.d.ts +5 -0
  85. package/dist/types/streaming/embedding-stream.d.ts +65 -0
  86. package/dist/types/streaming/sse-adapter.d.ts +59 -0
  87. package/dist/types/streaming/stream-router.d.ts +88 -0
  88. package/dist/types/streaming/streaming-embedder.d.ts +99 -0
  89. package/dist/types/streaming/websocket-adapter.d.ts +71 -0
  90. package/dist/types/templates/scaffold.d.ts +55 -0
  91. package/dist/types/templates/template-registry.d.ts +63 -0
  92. package/dist/types/utils/embed-query.d.ts +20 -0
  93. package/dist/types/utils/logger.d.ts +50 -0
  94. package/dist/types/utils/rate-limiter.d.ts +66 -0
  95. package/dist/types/utils/retry.d.ts +27 -0
  96. package/dist/types/utils/run-abort.d.ts +34 -0
  97. package/dist/types/utils/secure-logging.d.ts +51 -0
  98. package/dist/types/utils/structured-logger.d.ts +126 -0
  99. package/package.json +53 -29
  100. package/src/agentic/agentic-pipeline.js +75 -7
  101. package/src/agentic/iterative-retriever.js +47 -10
  102. package/src/agentic/query-planner.js +329 -78
  103. package/src/citation/citation-tracker.js +6 -4
  104. package/src/citation/hallucination-detector.js +2 -2
  105. package/src/citation/source-mapper.js +15 -28
  106. package/src/cli/commands/ai.js +101 -0
  107. package/src/cli/commands/plugin-hub/event-handlers.js +6 -0
  108. package/src/cli/commands/plugin-hub/hub-commands.js +0 -74
  109. package/src/cli/commands/plugin-hub/local-commands.js +143 -0
  110. package/src/cli/commands/plugin-hub.js +96 -36
  111. package/src/cli/diagnostics/config-checker.js +76 -63
  112. package/src/cli/diagnostics/environment-checker.js +62 -31
  113. package/src/cli/diagnostics/plugin-checker.js +36 -89
  114. package/src/cli/doctor-command.js +39 -5
  115. package/src/cli/enhanced-cli-commands.js +72 -217
  116. package/src/cli/handlers/ai-handler.js +364 -0
  117. package/src/cli/handlers/diagnostics-handler.js +78 -31
  118. package/src/cli/handlers/ingest-handler.js +28 -22
  119. package/src/cli/handlers/init-handler.js +148 -25
  120. package/src/cli/handlers/query-handler.js +41 -26
  121. package/src/cli/handlers/run-handler.js +16 -167
  122. package/src/cli/handlers/serve-handler.js +60 -0
  123. package/src/cli/services/bench-stats.js +54 -0
  124. package/src/cli/services/benchmark.js +161 -0
  125. package/src/cli/services/feedback.js +155 -0
  126. package/src/cli/services/rag-service.js +322 -0
  127. package/src/cli/shared/cli-utils.js +24 -7
  128. package/src/cli/shared/config-context.js +21 -0
  129. package/src/cli/wizard/config-builder.js +81 -0
  130. package/src/cli/wizard/init-wizard.js +617 -0
  131. package/src/config/component-factory.js +125 -0
  132. package/src/config/load-config.js +29 -10
  133. package/src/config/load-plugin-config.js +46 -2
  134. package/src/connectors/anthropic-connector.js +93 -55
  135. package/src/connectors/base-connector.js +74 -19
  136. package/src/connectors/cohere-connector.js +88 -32
  137. package/src/connectors/connector-utils.js +302 -0
  138. package/src/connectors/local-embedder.js +43 -5
  139. package/src/connectors/memory-retriever.js +108 -15
  140. package/src/connectors/ollama-connector.js +83 -49
  141. package/src/connectors/openai-connector.js +108 -44
  142. package/src/connectors/rag-prompt.js +88 -0
  143. package/src/core/create-pipeline.js +209 -60
  144. package/src/core/plugin-registry.js +87 -11
  145. package/src/cost/cost-calculator.js +205 -32
  146. package/src/dev/dev-server.js +166 -11
  147. package/src/dev/hot-reload.js +40 -1
  148. package/src/ecosystem/plugin-checks.js +181 -0
  149. package/src/ecosystem/plugin-hub.js +50 -125
  150. package/src/ecosystem/plugin-installer.js +298 -0
  151. package/src/ecosystem/plugin-probe.js +127 -0
  152. package/src/ecosystem/plugin-scanner.js +185 -0
  153. package/src/ecosystem/tar-extract.js +114 -0
  154. package/src/enterprise/audit-logging.js +158 -29
  155. package/src/enterprise/sso-integration.js +715 -228
  156. package/src/evaluate/context-metrics.js +28 -16
  157. package/src/evaluate/evaluator.js +3 -3
  158. package/src/evaluate/faithfulness.js +18 -14
  159. package/src/evaluate/groundedness.js +43 -12
  160. package/src/evaluate/pipeline-evaluator.js +35 -8
  161. package/src/evaluate/scoring.js +251 -3
  162. package/src/experimental.js +71 -0
  163. package/src/guardrails/guardrails-pipeline.js +69 -7
  164. package/src/guardrails/injection-detector.js +283 -0
  165. package/src/guardrails/post-generation-guard.js +19 -0
  166. package/src/guardrails/pre-retrieval-guard.js +36 -36
  167. package/src/guardrails/retrieval-guard.js +58 -8
  168. package/src/index.js +36 -1
  169. package/src/loader/document-reader.js +91 -0
  170. package/src/reranker/cascade-reranker.js +3 -0
  171. package/src/reranker/embedding-reranker.js +136 -21
  172. package/src/reranker/llm-reranker.js +79 -12
  173. package/src/reranker/scoring-reranker.js +3 -0
  174. package/src/retrieval/bm25-search.js +12 -6
  175. package/src/retrieval/file-vector-store.js +212 -0
  176. package/src/retrieval/hybrid-retriever.js +22 -19
  177. package/src/security/jwt-config.js +13 -2
  178. package/src/security/jwt-validator.js +134 -30
  179. package/src/security/plugin-sandbox.js +18 -1
  180. package/src/security/plugin-signature-verifier.js +245 -70
  181. package/src/utils/deprecate.js +69 -0
  182. package/src/utils/embed-query.js +33 -0
  183. package/src/utils/input-sanitizer.js +19 -4
  184. package/src/utils/logger.js +34 -4
  185. package/src/utils/run-abort.js +102 -0
  186. package/src/ai/federated-learning.js +0 -211
  187. package/src/ai/federation.js +0 -71
  188. package/src/ai/index.js +0 -22
  189. package/src/ai/model-trainer.js +0 -217
  190. package/src/ai/model-training.js +0 -202
  191. package/src/ai/multimodal/multi-modal-processor.js +0 -345
  192. package/src/ai/orchestrator.js +0 -65
  193. package/src/ai/retrieval/adaptive-retrieval-engine.js +0 -398
  194. package/src/cli/commands/ai-ml/adaptive-commands.js +0 -178
  195. package/src/cli/commands/ai-ml/federated-commands.js +0 -207
  196. package/src/cli/commands/ai-ml/index.js +0 -17
  197. package/src/cli/commands/ai-ml/multimodal-commands.js +0 -187
  198. package/src/cli/commands/ai-ml/shared.js +0 -51
  199. package/src/cli/commands/ai-ml/training-commands.js +0 -228
  200. package/src/cli/commands/ai-ml.js +0 -386
  201. package/src/cli/commands/docs.js +0 -228
  202. package/src/cli/commands/dx.js +0 -538
  203. package/src/cli/commands/wizard.js +0 -627
  204. package/src/cli/input-sanitization-middleware.js +0 -356
  205. package/src/cli/interactive-wizard.js +0 -373
  206. package/src/cli/templates/development.template.json +0 -64
  207. package/src/cli/templates/minimal.template.json +0 -33
  208. package/src/cli/templates/production.template.json +0 -104
  209. package/src/cli/templates/testing.template.json +0 -45
  210. package/src/cli/wizard/configuration.js +0 -148
  211. package/src/cli/wizard/observability.js +0 -79
  212. package/src/cli/wizard/performance.js +0 -76
  213. package/src/cli/wizard/plugin-selection.js +0 -297
  214. package/src/cli/wizard/preview-save.js +0 -172
  215. package/src/cli/wizard/project-setup.js +0 -66
  216. package/src/core/pipeline-factory.js +0 -59
  217. package/src/dag/enhanced-dag-engine.js +0 -894
  218. package/src/dx/index.js +0 -40
  219. package/src/dx/integration-templates.js +0 -662
  220. package/src/dx/performance-profiler.js +0 -968
  221. package/src/dx/realtime-debugger.js +0 -755
  222. package/src/dx/visual-pipeline-builder.js +0 -578
  223. package/src/ingest.js +0 -59
  224. package/src/pipeline/pipeline.js +0 -18
  225. package/src/query.js +0 -117
@@ -1,356 +0,0 @@
1
- "use strict";
2
-
3
- /**
4
- * CLI Input Sanitization Middleware
5
- *
6
- * Provides automatic input sanitization for CLI commands to prevent:
7
- * - Command injection attacks
8
- * - Path traversal attacks
9
- * - XSS in output
10
- * - Invalid data types
11
- *
12
- * @module cli/input-sanitization-middleware
13
- * @since 2.3.0
14
- */
15
-
16
- const {
17
- InputSanitizer,
18
- SanitizationRules,
19
- sanitizePath,
20
- sanitizeCommand,
21
- validateEmail,
22
- validateUrl,
23
- } = require("../utils/input-sanitizer");
24
-
25
- /**
26
- * CLI-specific sanitization rules mapping
27
- */
28
- const CLI_SANITIZATION_RULES = {
29
- // File and path arguments
30
- file: SanitizationRules.PATH,
31
- path: SanitizationRules.PATH,
32
- output: SanitizationRules.PATH,
33
- input: SanitizationRules.PATH,
34
- config: SanitizationRules.PATH,
35
- report: SanitizationRules.PATH,
36
-
37
- // URL arguments
38
- url: SanitizationRules.URL,
39
-
40
- // Email arguments
41
- email: SanitizationRules.EMAIL,
42
-
43
- // String arguments (prompts, queries, templates)
44
- prompt: SanitizationRules.XSS,
45
- query: SanitizationRules.XSS,
46
- template: SanitizationRules.ALPHANUMERIC,
47
-
48
- // Configuration keys
49
- key: SanitizationRules.ALPHANUMERIC,
50
- name: SanitizationRules.SLUG,
51
-
52
- // Numeric arguments
53
- timeout: SanitizationRules.INTEGER,
54
- concurrency: SanitizationRules.INTEGER,
55
- batchSize: SanitizationRules.INTEGER,
56
- maxMemory: SanitizationRules.INTEGER,
57
-
58
- // Categories and sections
59
- category: SanitizationRules.SLUG,
60
- section: SanitizationRules.SLUG,
61
- format: SanitizationRules.SLUG,
62
- };
63
-
64
- /**
65
- * CLI Input Sanitization Middleware
66
- */
67
- class CLISanitizationMiddleware {
68
- constructor(options = {}) {
69
- this.sanitizer = new InputSanitizer({
70
- enableCache: options.enableCache !== false,
71
- cacheSize: options.cacheSize || 500,
72
- cacheTTL: options.cacheTTL || 300000, // 5 minutes
73
- throwOnInvalid: options.throwOnInvalid || false,
74
- stripInvalid: options.stripInvalid !== false,
75
- trackStats: options.trackStats !== false,
76
- });
77
-
78
- this.customRules = options.customRules || {};
79
- this.enabled = options.enabled !== false;
80
- this.verbose = options.verbose || false;
81
- }
82
-
83
- /**
84
- * Sanitize command arguments
85
- *
86
- * @param {Object} args - Command arguments object
87
- * @returns {Object} Sanitized arguments
88
- *
89
- * @example
90
- * const sanitized = middleware.sanitizeArgs({
91
- * file: '../../../etc/passwd',
92
- * query: '<script>alert("xss")</script>',
93
- * timeout: '1000'
94
- * });
95
- */
96
- sanitizeArgs(args) {
97
- if (!this.enabled) {
98
- return args;
99
- }
100
-
101
- if (!args || typeof args !== "object") {
102
- return args;
103
- }
104
-
105
- const sanitized = {};
106
-
107
- for (const [key, value] of Object.entries(args)) {
108
- // Skip undefined/null values
109
- if (value === undefined || value === null) {
110
- sanitized[key] = value;
111
- continue;
112
- }
113
-
114
- // Determine sanitization rule for this argument
115
- const rule = this._getRuleForArgument(key, value);
116
-
117
- // Sanitize the value
118
- try {
119
- sanitized[key] = this.sanitizer.sanitize(value, rule);
120
-
121
- // Log if value was modified (in verbose mode)
122
- if (this.verbose && sanitized[key] !== value) {
123
- console.warn(
124
- `[INPUT_SANITIZER] Sanitized argument '${key}': ${value} => ${sanitized[key]}`,
125
- );
126
- }
127
- } catch (error) {
128
- console.error(
129
- `[INPUT_SANITIZER] Error sanitizing argument '${key}':`,
130
- error.message,
131
- );
132
- sanitized[key] = value; // Fall back to original value
133
- }
134
- }
135
-
136
- return sanitized;
137
- }
138
-
139
- /**
140
- * Sanitize command options
141
- *
142
- * @param {Object} options - Command options object
143
- * @returns {Object} Sanitized options
144
- */
145
- sanitizeOptions(options) {
146
- return this.sanitizeArgs(options);
147
- }
148
-
149
- /**
150
- * Sanitize command output before displaying
151
- *
152
- * @param {string} output - Command output string
153
- * @returns {string} Sanitized output
154
- */
155
- sanitizeOutput(output) {
156
- if (!this.enabled) {
157
- return output;
158
- }
159
-
160
- if (typeof output !== "string") {
161
- return output;
162
- }
163
-
164
- // HTML escape for terminal output (prevents potential terminal injection)
165
- return this.sanitizer.sanitize(output, SanitizationRules.HTML);
166
- }
167
-
168
- /**
169
- * Wrap command action with sanitization
170
- *
171
- * @param {Function} action - Original command action
172
- * @returns {Function} Wrapped action with sanitization
173
- *
174
- * @example
175
- * const wrappedAction = middleware.wrapAction(async (options) => {
176
- * // Original action
177
- * });
178
- */
179
- wrapAction(action) {
180
- return async (...args) => {
181
- // Last argument is typically options object
182
- const lastArg = args[args.length - 1];
183
-
184
- if (lastArg && typeof lastArg === "object") {
185
- // Sanitize options
186
- args[args.length - 1] = this.sanitizeOptions(lastArg);
187
- }
188
-
189
- // Sanitize positional arguments
190
- for (let i = 0; i < args.length - 1; i++) {
191
- if (typeof args[i] === "string") {
192
- args[i] = this.sanitizer.sanitize(args[i], SanitizationRules.HTML);
193
- }
194
- }
195
-
196
- // Execute original action
197
- return await action(...args);
198
- };
199
- }
200
-
201
- /**
202
- * Get sanitization rule for argument based on name and type
203
- * @private
204
- */
205
- _getRuleForArgument(argName, value) {
206
- // Check custom rules first
207
- if (this.customRules[argName]) {
208
- return this.customRules[argName];
209
- }
210
-
211
- // Check predefined CLI rules
212
- if (CLI_SANITIZATION_RULES[argName]) {
213
- return CLI_SANITIZATION_RULES[argName];
214
- }
215
-
216
- // Infer rule from argument name patterns
217
- if (
218
- argName.includes("path") ||
219
- argName.includes("file") ||
220
- argName.includes("dir")
221
- ) {
222
- return SanitizationRules.PATH;
223
- }
224
-
225
- if (argName.includes("url") || argName.includes("uri")) {
226
- return SanitizationRules.URL;
227
- }
228
-
229
- if (argName.includes("email")) {
230
- return SanitizationRules.EMAIL;
231
- }
232
-
233
- if (argName.includes("id") || argName.includes("uuid")) {
234
- return SanitizationRules.UUID;
235
- }
236
-
237
- // Infer from value type
238
- if (typeof value === "number" || /^\d+$/.test(value)) {
239
- return SanitizationRules.INTEGER;
240
- }
241
-
242
- if (typeof value === "boolean") {
243
- return SanitizationRules.BOOLEAN;
244
- }
245
-
246
- // Default to XSS sanitization for strings
247
- return SanitizationRules.XSS;
248
- }
249
-
250
- /**
251
- * Get sanitization statistics
252
- *
253
- * @returns {Object} Statistics object
254
- */
255
- getStats() {
256
- return this.sanitizer.getStats();
257
- }
258
-
259
- /**
260
- * Reset statistics
261
- */
262
- resetStats() {
263
- this.sanitizer.resetStats();
264
- }
265
-
266
- /**
267
- * Destroy middleware and cleanup resources
268
- */
269
- destroy() {
270
- this.sanitizer.destroy();
271
- }
272
- }
273
-
274
- /**
275
- * Create global CLI sanitization middleware instance
276
- */
277
- const cliSanitizer = new CLISanitizationMiddleware({
278
- enabled: process.env.CLI_SANITIZATION !== "false",
279
- verbose: process.env.CLI_SANITIZATION_VERBOSE === "true",
280
- });
281
-
282
- /**
283
- * Quick sanitization helpers for CLI
284
- */
285
- function sanitizeCliPath(pathStr) {
286
- return sanitizePath(pathStr);
287
- }
288
-
289
- function sanitizeCliCommand(cmdStr) {
290
- return sanitizeCommand(cmdStr);
291
- }
292
-
293
- function sanitizeCliQuery(queryStr) {
294
- return cliSanitizer.sanitizer.sanitize(queryStr, SanitizationRules.XSS);
295
- }
296
-
297
- function sanitizeCliEmail(emailStr) {
298
- return validateEmail(emailStr);
299
- }
300
-
301
- function sanitizeCliUrl(urlStr) {
302
- return validateUrl(urlStr);
303
- }
304
-
305
- /**
306
- * Sanitize file path for CLI operations
307
- *
308
- * @param {string} filePath - File path to sanitize
309
- * @returns {string} Sanitized file path
310
- */
311
- function sanitizeFilePath(filePath) {
312
- if (!filePath || typeof filePath !== "string") {
313
- return filePath;
314
- }
315
-
316
- // Remove path traversal attempts
317
- let sanitized = filePath;
318
-
319
- // Remove leading traversal
320
- sanitized = sanitized.replace(/^(\.\.\/|\.\.\\)+/, "");
321
-
322
- // Remove embedded traversal
323
- sanitized = sanitized.replace(/\/(\.\.\/|\.\.\\)/g, "/");
324
- sanitized = sanitized.replace(/\\(\.\.\/|\.\.\\)/g, "\\");
325
-
326
- // Normalize path separators
327
- sanitized = sanitized.replace(/\\/g, "/");
328
-
329
- // Remove multiple consecutive slashes
330
- sanitized = sanitized.replace(/\/+/g, "/");
331
-
332
- return sanitized;
333
- }
334
-
335
- /**
336
- * Sanitize all CLI options at once
337
- *
338
- * @param {Object} options - CLI options object
339
- * @returns {Object} Sanitized options
340
- */
341
- function sanitizeAllCliOptions(options) {
342
- return cliSanitizer.sanitizeOptions(options);
343
- }
344
-
345
- module.exports = {
346
- CLISanitizationMiddleware,
347
- cliSanitizer,
348
- sanitizeCliPath,
349
- sanitizeCliCommand,
350
- sanitizeCliQuery,
351
- sanitizeCliEmail,
352
- sanitizeCliUrl,
353
- sanitizeFilePath,
354
- sanitizeAllCliOptions,
355
- CLI_SANITIZATION_RULES,
356
- };
@@ -1,373 +0,0 @@
1
- /**
2
- * Interactive CLI Wizard for RAG Pipeline Setup
3
- * Provides guided setup for plugin selection, DAG building, and configuration
4
- *
5
- * This module is a thin orchestrator that delegates to focused step modules
6
- * in src/cli/wizard/. Each step receives the wizard's config state and
7
- * inquirer instance.
8
- */
9
-
10
- const inquirer = require("inquirer");
11
- const path = require("path");
12
- const {
13
- DEFAULT_REGISTRY_URLS,
14
- } = require("../core/plugin-marketplace/plugin-registry-format.js");
15
-
16
- // Step modules
17
- const { setupProject } = require("./wizard/project-setup.js");
18
- const { selectPlugins } = require("./wizard/plugin-selection.js");
19
- const {
20
- configureSettings,
21
- configurePipeline,
22
- } = require("./wizard/configuration.js");
23
- const { configurePerformance } = require("./wizard/performance.js");
24
- const { configureObservability } = require("./wizard/observability.js");
25
- const {
26
- previewAndSave,
27
- showConfigSummary,
28
- runConfigurationTest,
29
- } = require("./wizard/preview-save.js");
30
-
31
- /**
32
- * Interactive wizard for RAG pipeline setup
33
- */
34
- class InteractiveWizard {
35
- constructor(_options = {}) {
36
- this._options = {
37
- registryUrl: _options.registryUrl || DEFAULT_REGISTRY_URLS[0],
38
- outputPath: _options.outputPath || ".ragrc.json",
39
- ..._options,
40
- };
41
- this.registry = null;
42
- this._config = {
43
- plugins: {
44
- loader: {},
45
- embedder: {},
46
- retriever: {},
47
- llm: {},
48
- },
49
- registry: {
50
- urls: [this._options.registryUrl],
51
- },
52
- };
53
-
54
- // Initialize steps for testing interface
55
- this.steps = [
56
- "project-setup",
57
- "plugin-selection",
58
- "configuration",
59
- "pipeline-setup",
60
- "performance-tuning",
61
- "observability",
62
- "preview-save",
63
- ];
64
- this.currentStep = 0;
65
- }
66
-
67
- /**
68
- * Run the complete interactive wizard
69
- * @returns {Promise<object>} Generated configuration
70
- */
71
- async run() {
72
- console.log("🧙‍♂️ Welcome to the RAG Pipeline Interactive Setup Wizard!\n");
73
- // eslint-disable-line no-console
74
- console.log(
75
- "This wizard will help you configure your RAG pipeline with the right plugins and settings.\n",
76
- );
77
- // eslint-disable-line no-console
78
-
79
- try {
80
- // Step 1: Project setup
81
- await this.setupProject();
82
-
83
- // Step 2: Plugin selection
84
- await this.selectPlugins();
85
-
86
- // Step 3: Configuration
87
- await this.configureSettings();
88
-
89
- // Step 4: Pipeline stages
90
- await this.configurePipeline();
91
-
92
- // Step 5: Performance settings
93
- await this.configurePerformance();
94
-
95
- // Step 6: Observability settings
96
- await this.configureObservability();
97
-
98
- // Step 7: Preview and save
99
- await this.previewAndSave();
100
-
101
- console.log("\n🎉 RAG Pipeline setup complete!");
102
- // eslint-disable-line no-console
103
- console.log(`Configuration saved to: ${this._options.outputPath}`);
104
- // eslint-disable-line no-console
105
-
106
- return this._config;
107
- } catch (error) {
108
- console.error("\n❌ Setup wizard failed:", error.message);
109
- // eslint-disable-line no-console
110
- throw error;
111
- }
112
- }
113
-
114
- /**
115
- * Setup project metadata - delegates to project-setup module
116
- */
117
- async setupProject() {
118
- this._config = await setupProject(this._config, inquirer);
119
- }
120
-
121
- /**
122
- * Select plugins for each type - delegates to plugin-selection module
123
- */
124
- async selectPlugins() {
125
- const context = {
126
- registry: this.registry,
127
- getAvailablePlugins: (type) => this.getAvailablePlugins(type),
128
- getPluginInfo: (type, name) => this.getPluginInfo(type, name),
129
- loadRegistry: () => this.loadRegistry(),
130
- };
131
- this._config = await selectPlugins(this._config, inquirer, context);
132
- // Sync registry back from context (loadRegistry may have updated it)
133
- this.registry = context.registry;
134
- }
135
-
136
- /**
137
- * Configure general settings - delegates to configuration module
138
- */
139
- async configureSettings() {
140
- this._config = await configureSettings(this._config, inquirer);
141
- }
142
-
143
- /**
144
- * Configure pipeline stages - delegates to configuration module
145
- */
146
- async configurePipeline() {
147
- this._config = await configurePipeline(this._config, inquirer);
148
- }
149
-
150
- /**
151
- * Configure performance settings - delegates to performance module
152
- */
153
- async configurePerformance() {
154
- this._config = await configurePerformance(this._config, inquirer);
155
- }
156
-
157
- /**
158
- * Configure observability settings - delegates to observability module
159
- */
160
- async configureObservability() {
161
- this._config = await configureObservability(this._config, inquirer);
162
- }
163
-
164
- /**
165
- * Preview configuration and save - delegates to preview-save module
166
- */
167
- async previewAndSave() {
168
- this._config = await previewAndSave(this._config, inquirer, this._options);
169
- }
170
-
171
- /**
172
- * Show configuration summary - delegates to preview-save module
173
- */
174
- showConfigSummary() {
175
- showConfigSummary(this._config);
176
- }
177
-
178
- /**
179
- * Run configuration test - delegates to preview-save module
180
- */
181
- async runConfigurationTest() {
182
- await runConfigurationTest(this._config);
183
- }
184
-
185
- /**
186
- * Configure plugin-specific settings
187
- * @param {object} plugin - Plugin information
188
- * @returns {Promise<object>} Plugin configuration
189
- */
190
- async configurePluginSettings(plugin) {
191
- const {
192
- configurePluginSettings: configPluginSettings,
193
- } = require("./wizard/plugin-selection.js");
194
- return configPluginSettings(plugin, inquirer);
195
- }
196
-
197
- /**
198
- * Load plugin registry
199
- * @returns {Promise<object>} Registry data
200
- */
201
- async loadRegistry() {
202
- // In a real implementation, this would fetch from the registry URL
203
- // For now, return mock data
204
- return {
205
- plugins: {
206
- "file-loader": {
207
- metadata: {
208
- name: "file-loader",
209
- _type: "loader",
210
- description: "Load files from filesystem",
211
- },
212
- versions: { "1.0.0": {}, "1.1.0": {} },
213
- latest: "1.1.0",
214
- },
215
- "openai-embedder": {
216
- metadata: {
217
- name: "openai-embedder",
218
- _type: "embedder",
219
- description: "OpenAI embeddings",
220
- },
221
- versions: { "2.0.0": {}, "2.1.0": {} },
222
- latest: "2.1.0",
223
- },
224
- },
225
- };
226
- }
227
-
228
- /**
229
- * Get available plugins for type
230
- * @param {string} _type - Plugin type
231
- * @returns {Array<object>} Available plugins
232
- */
233
- getAvailablePlugins(_type) {
234
- if (!this.registry) {
235
- return this.getBuiltinPlugins(_type);
236
- }
237
-
238
- return Object.values(this.registry.plugins)
239
- .filter((plugin) => plugin.metadata._type === _type)
240
- .map((plugin) => ({
241
- name: plugin.metadata.name,
242
- description: plugin.metadata.description,
243
- version: plugin.latest,
244
- }));
245
- }
246
-
247
- /**
248
- * Get built-in plugin options
249
- * @param {string} _type - Plugin type
250
- * @returns {Array<object>} Built-in plugins
251
- */
252
- getBuiltinPlugins(_type) {
253
- const builtins = {
254
- loader: [
255
- { name: "file-loader", description: "Load files from filesystem" },
256
- { name: "url-loader", description: "Load content from URLs" },
257
- ],
258
- embedder: [
259
- { name: "openai-embedder", description: "OpenAI embeddings" },
260
- { name: "local-embedder", description: "Local embedding model" },
261
- ],
262
- retriever: [
263
- { name: "vector-retriever", description: "Vector similarity search" },
264
- { name: "keyword-retriever", description: "Keyword-based search" },
265
- ],
266
- llm: [
267
- { name: "openai-llm", description: "OpenAI language models" },
268
- { name: "local-llm", description: "Local language model" },
269
- ],
270
- reranker: [
271
- {
272
- name: "similarity-reranker",
273
- description: "Similarity-based reranking",
274
- },
275
- ],
276
- };
277
-
278
- return builtins[_type] || [];
279
- }
280
-
281
- /**
282
- * Get plugin information
283
- * @param {string} _type - Plugin type
284
- * @param {string} name - Plugin name
285
- * @returns {object|null} Plugin information
286
- */
287
- getPluginInfo(_type, name) {
288
- if (!this.registry) {
289
- return null;
290
- }
291
-
292
- return this.registry.plugins[name] || null;
293
- }
294
-
295
- /**
296
- * Load wizard configuration
297
- * @returns {object} Current configuration
298
- */
299
- loadConfig() {
300
- return { ...this._config };
301
- }
302
-
303
- /**
304
- * Navigate to next step
305
- * @returns {string} Next step name
306
- */
307
- nextStep() {
308
- if (this.currentStep < this.steps.length - 1) {
309
- this.currentStep++;
310
- }
311
- return this.steps[this.currentStep];
312
- }
313
-
314
- /**
315
- * Navigate to previous step
316
- * @returns {string} Previous step name
317
- */
318
- previousStep() {
319
- if (this.currentStep > 0) {
320
- this.currentStep--;
321
- }
322
- return this.steps[this.currentStep];
323
- }
324
-
325
- /**
326
- * Complete the wizard
327
- * @returns {Promise<object>} Completion result
328
- */
329
- async complete() {
330
- return {
331
- success: true,
332
- config: this._config,
333
- message: "Wizard completed successfully",
334
- };
335
- }
336
-
337
- /**
338
- * Validate user input
339
- * @param {string} input - Input to validate
340
- * @returns {boolean} Whether input is valid
341
- */
342
- validateInput(input) {
343
- return typeof input === "string" && input.trim().length > 0;
344
- }
345
-
346
- /**
347
- * Process user selection
348
- * @param {string} selection - User selection
349
- * @returns {object} Processing result
350
- */
351
- processSelection(selection) {
352
- return {
353
- selection,
354
- processed: true,
355
- timestamp: Date.now(),
356
- };
357
- }
358
- }
359
-
360
- /**
361
- * Main wizard function for CLI usage
362
- * @param {object} options - Wizard options
363
- * @returns {Promise<object>} Generated configuration
364
- */
365
- async function runInteractiveWizard(options = {}) {
366
- const wizard = new InteractiveWizard(options);
367
- return await wizard.run();
368
- }
369
-
370
- module.exports = {
371
- InteractiveWizard,
372
- runInteractiveWizard,
373
- };