@devilsdev/rag-pipeline-utils 2.4.4 → 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.
- package/.ragrc.schema.json +83 -192
- package/CHANGELOG.md +345 -0
- package/README.md +418 -117
- package/SECURITY.md +5 -5
- package/dist/experimental.cjs +2 -0
- package/dist/experimental.d.ts +1 -0
- package/dist/experimental.mjs +5 -0
- package/dist/index.cjs +4992 -1242
- package/dist/index.d.ts +80 -2
- package/dist/index.mjs +1 -1
- package/dist/types/agentic/agentic-pipeline.d.ts +103 -0
- package/dist/types/agentic/iterative-retriever.d.ts +85 -0
- package/dist/types/agentic/query-planner.d.ts +145 -0
- package/dist/types/agentic/self-critique.d.ts +45 -0
- package/dist/types/ai/adaptive-retrieval.d.ts +44 -0
- package/dist/types/ai/federation/federated-learning-coordinator.d.ts +62 -0
- package/dist/types/ai/multimodal-processing.d.ts +32 -0
- package/dist/types/ai/multimodal.d.ts +39 -0
- package/dist/types/ai/retrieval-engine.d.ts +37 -0
- package/dist/types/ai/training/model-training-orchestrator.d.ts +31 -0
- package/dist/types/chunking/chunking-engine.d.ts +70 -0
- package/dist/types/chunking/strategies/fixed-size.d.ts +17 -0
- package/dist/types/chunking/strategies/recursive.d.ts +20 -0
- package/dist/types/chunking/strategies/semantic.d.ts +19 -0
- package/dist/types/chunking/strategies/sentence.d.ts +13 -0
- package/dist/types/chunking/strategies/structure-aware.d.ts +19 -0
- package/dist/types/citation/citation-tracker.d.ts +64 -0
- package/dist/types/citation/hallucination-detector.d.ts +40 -0
- package/dist/types/citation/source-mapper.d.ts +37 -0
- package/dist/types/connectors/anthropic-connector.d.ts +92 -0
- package/dist/types/connectors/base-connector.d.ts +87 -0
- package/dist/types/connectors/cohere-connector.d.ts +89 -0
- package/dist/types/connectors/connector-utils.d.ts +110 -0
- package/dist/types/connectors/local-embedder.d.ts +86 -0
- package/dist/types/connectors/memory-retriever.d.ts +91 -0
- package/dist/types/connectors/ollama-connector.d.ts +110 -0
- package/dist/types/connectors/openai-connector.d.ts +114 -0
- package/dist/types/connectors/rag-prompt.d.ts +40 -0
- package/dist/types/cost/cost-calculator.d.ts +152 -0
- package/dist/types/cost/cost-tracker.d.ts +126 -0
- package/dist/types/cost/token-budget.d.ts +110 -0
- package/dist/types/dag/core/error-context.d.ts +239 -0
- package/dist/types/dag/core/execution-scheduler.d.ts +191 -0
- package/dist/types/dag/core/topology-validation.d.ts +226 -0
- package/dist/types/dag/dag-engine.d.ts +156 -0
- package/dist/types/dag/dag-node.d.ts +37 -0
- package/dist/types/dashboard/dashboard-generator.d.ts +127 -0
- package/dist/types/dashboard/metrics-aggregator.d.ts +218 -0
- package/dist/types/debug/execution-tracer.d.ts +57 -0
- package/dist/types/debug/trace-inspector.d.ts +31 -0
- package/dist/types/ecosystem/plugin-certification.d.ts +169 -0
- package/dist/types/enterprise/data-governance.d.ts +203 -0
- package/dist/types/enterprise/multi-tenancy.d.ts +137 -0
- package/dist/types/enterprise/sso-integration.d.ts +420 -0
- package/dist/types/evaluate/context-metrics.d.ts +55 -0
- package/dist/types/evaluate/faithfulness.d.ts +41 -0
- package/dist/types/evaluate/groundedness.d.ts +60 -0
- package/dist/types/evaluate/pipeline-evaluator.d.ts +88 -0
- package/dist/types/evaluate/relevance.d.ts +21 -0
- package/dist/types/evaluate/scoring.d.ts +123 -0
- package/dist/types/experimental.d.ts +15 -0
- package/dist/types/graph/entity-extractor.d.ts +84 -0
- package/dist/types/graph/graph-index.d.ts +49 -0
- package/dist/types/graph/graph-retriever.d.ts +81 -0
- package/dist/types/graph/knowledge-graph.d.ts +129 -0
- package/dist/types/guardrails/guardrails-pipeline.d.ts +63 -0
- package/dist/types/guardrails/injection-detector.d.ts +47 -0
- package/dist/types/guardrails/post-generation-guard.d.ts +61 -0
- package/dist/types/guardrails/pre-retrieval-guard.d.ts +64 -0
- package/dist/types/guardrails/retrieval-guard.d.ts +57 -0
- package/dist/types/mcp/mcp-server.d.ts +85 -0
- package/dist/types/mcp/mcp-tool-builder.d.ts +55 -0
- package/dist/types/reranker/cascade-reranker.d.ts +40 -0
- package/dist/types/reranker/embedding-reranker.d.ts +77 -0
- package/dist/types/reranker/scoring-reranker.d.ts +41 -0
- package/dist/types/retrieval/bm25-search.d.ts +43 -0
- package/dist/types/retrieval/file-vector-store.d.ts +87 -0
- package/dist/types/retrieval/hybrid-retriever.d.ts +35 -0
- package/dist/types/retrieval/rank-fusion.d.ts +10 -0
- package/dist/types/security/jwt-config.d.ts +80 -0
- package/dist/types/security/jwt-validator.d.ts +195 -0
- package/dist/types/security/plugin-sandbox.d.ts +158 -0
- package/dist/types/security/plugin-signature-verifier.d.ts +139 -0
- package/dist/types/security/validator.d.ts +5 -0
- package/dist/types/streaming/embedding-stream.d.ts +65 -0
- package/dist/types/streaming/sse-adapter.d.ts +59 -0
- package/dist/types/streaming/stream-router.d.ts +88 -0
- package/dist/types/streaming/streaming-embedder.d.ts +99 -0
- package/dist/types/streaming/websocket-adapter.d.ts +71 -0
- package/dist/types/templates/scaffold.d.ts +55 -0
- package/dist/types/templates/template-registry.d.ts +63 -0
- package/dist/types/utils/embed-query.d.ts +20 -0
- package/dist/types/utils/logger.d.ts +50 -0
- package/dist/types/utils/rate-limiter.d.ts +66 -0
- package/dist/types/utils/retry.d.ts +27 -0
- package/dist/types/utils/run-abort.d.ts +34 -0
- package/dist/types/utils/secure-logging.d.ts +51 -0
- package/dist/types/utils/structured-logger.d.ts +126 -0
- package/package.json +53 -29
- package/src/agentic/agentic-pipeline.js +75 -7
- package/src/agentic/iterative-retriever.js +47 -10
- package/src/agentic/query-planner.js +329 -78
- package/src/citation/citation-tracker.js +6 -4
- package/src/citation/hallucination-detector.js +2 -2
- package/src/citation/source-mapper.js +15 -28
- package/src/cli/commands/ai.js +101 -0
- package/src/cli/commands/plugin-hub/event-handlers.js +6 -0
- package/src/cli/commands/plugin-hub/hub-commands.js +0 -74
- package/src/cli/commands/plugin-hub/local-commands.js +143 -0
- package/src/cli/commands/plugin-hub.js +96 -36
- package/src/cli/diagnostics/config-checker.js +76 -63
- package/src/cli/diagnostics/environment-checker.js +62 -31
- package/src/cli/diagnostics/plugin-checker.js +36 -89
- package/src/cli/doctor-command.js +39 -5
- package/src/cli/enhanced-cli-commands.js +72 -217
- package/src/cli/handlers/ai-handler.js +364 -0
- package/src/cli/handlers/diagnostics-handler.js +78 -31
- package/src/cli/handlers/ingest-handler.js +28 -22
- package/src/cli/handlers/init-handler.js +148 -25
- package/src/cli/handlers/query-handler.js +41 -26
- package/src/cli/handlers/run-handler.js +16 -167
- package/src/cli/handlers/serve-handler.js +60 -0
- package/src/cli/services/bench-stats.js +54 -0
- package/src/cli/services/benchmark.js +161 -0
- package/src/cli/services/feedback.js +155 -0
- package/src/cli/services/rag-service.js +322 -0
- package/src/cli/shared/cli-utils.js +24 -7
- package/src/cli/shared/config-context.js +21 -0
- package/src/cli/wizard/config-builder.js +81 -0
- package/src/cli/wizard/init-wizard.js +617 -0
- package/src/config/component-factory.js +125 -0
- package/src/config/load-config.js +29 -10
- package/src/config/load-plugin-config.js +46 -2
- package/src/connectors/anthropic-connector.js +93 -55
- package/src/connectors/base-connector.js +74 -19
- package/src/connectors/cohere-connector.js +88 -32
- package/src/connectors/connector-utils.js +302 -0
- package/src/connectors/local-embedder.js +43 -5
- package/src/connectors/memory-retriever.js +108 -15
- package/src/connectors/ollama-connector.js +83 -49
- package/src/connectors/openai-connector.js +108 -44
- package/src/connectors/rag-prompt.js +88 -0
- package/src/core/create-pipeline.js +209 -60
- package/src/core/plugin-registry.js +87 -11
- package/src/cost/cost-calculator.js +205 -32
- package/src/dev/dev-server.js +166 -11
- package/src/dev/hot-reload.js +40 -1
- package/src/ecosystem/plugin-checks.js +181 -0
- package/src/ecosystem/plugin-hub.js +50 -125
- package/src/ecosystem/plugin-installer.js +298 -0
- package/src/ecosystem/plugin-probe.js +127 -0
- package/src/ecosystem/plugin-scanner.js +185 -0
- package/src/ecosystem/tar-extract.js +114 -0
- package/src/enterprise/audit-logging.js +158 -29
- package/src/enterprise/sso-integration.js +715 -228
- package/src/evaluate/context-metrics.js +28 -16
- package/src/evaluate/evaluator.js +3 -3
- package/src/evaluate/faithfulness.js +18 -14
- package/src/evaluate/groundedness.js +43 -12
- package/src/evaluate/pipeline-evaluator.js +35 -8
- package/src/evaluate/scoring.js +251 -3
- package/src/experimental.js +71 -0
- package/src/guardrails/guardrails-pipeline.js +69 -7
- package/src/guardrails/injection-detector.js +283 -0
- package/src/guardrails/post-generation-guard.js +19 -0
- package/src/guardrails/pre-retrieval-guard.js +36 -36
- package/src/guardrails/retrieval-guard.js +58 -8
- package/src/index.js +36 -1
- package/src/loader/document-reader.js +91 -0
- package/src/reranker/cascade-reranker.js +3 -0
- package/src/reranker/embedding-reranker.js +136 -21
- package/src/reranker/llm-reranker.js +79 -12
- package/src/reranker/scoring-reranker.js +3 -0
- package/src/retrieval/bm25-search.js +12 -6
- package/src/retrieval/file-vector-store.js +212 -0
- package/src/retrieval/hybrid-retriever.js +22 -19
- package/src/security/jwt-config.js +13 -2
- package/src/security/jwt-validator.js +134 -30
- package/src/security/plugin-sandbox.js +18 -1
- package/src/security/plugin-signature-verifier.js +245 -70
- package/src/utils/deprecate.js +69 -0
- package/src/utils/embed-query.js +33 -0
- package/src/utils/input-sanitizer.js +19 -4
- package/src/utils/logger.js +34 -4
- package/src/utils/run-abort.js +102 -0
- package/src/ai/federated-learning.js +0 -211
- package/src/ai/federation.js +0 -71
- package/src/ai/index.js +0 -22
- package/src/ai/model-trainer.js +0 -217
- package/src/ai/model-training.js +0 -202
- package/src/ai/multimodal/multi-modal-processor.js +0 -345
- package/src/ai/orchestrator.js +0 -65
- package/src/ai/retrieval/adaptive-retrieval-engine.js +0 -398
- package/src/cli/commands/ai-ml/adaptive-commands.js +0 -178
- package/src/cli/commands/ai-ml/federated-commands.js +0 -207
- package/src/cli/commands/ai-ml/index.js +0 -17
- package/src/cli/commands/ai-ml/multimodal-commands.js +0 -187
- package/src/cli/commands/ai-ml/shared.js +0 -51
- package/src/cli/commands/ai-ml/training-commands.js +0 -228
- package/src/cli/commands/ai-ml.js +0 -386
- package/src/cli/commands/docs.js +0 -228
- package/src/cli/commands/dx.js +0 -538
- package/src/cli/commands/wizard.js +0 -627
- package/src/cli/input-sanitization-middleware.js +0 -356
- package/src/cli/interactive-wizard.js +0 -373
- package/src/cli/templates/development.template.json +0 -64
- package/src/cli/templates/minimal.template.json +0 -33
- package/src/cli/templates/production.template.json +0 -104
- package/src/cli/templates/testing.template.json +0 -45
- package/src/cli/wizard/configuration.js +0 -148
- package/src/cli/wizard/observability.js +0 -79
- package/src/cli/wizard/performance.js +0 -76
- package/src/cli/wizard/plugin-selection.js +0 -297
- package/src/cli/wizard/preview-save.js +0 -172
- package/src/cli/wizard/project-setup.js +0 -66
- package/src/core/pipeline-factory.js +0 -59
- package/src/dag/enhanced-dag-engine.js +0 -894
- package/src/dx/index.js +0 -40
- package/src/dx/integration-templates.js +0 -662
- package/src/dx/performance-profiler.js +0 -968
- package/src/dx/realtime-debugger.js +0 -755
- package/src/dx/visual-pipeline-builder.js +0 -578
- package/src/ingest.js +0 -59
- package/src/pipeline/pipeline.js +0 -18
- 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
|
-
};
|