@devilsdev/rag-pipeline-utils 2.4.5 → 2.6.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 (258) hide show
  1. package/.ragrc.schema.json +83 -192
  2. package/CHANGELOG.md +431 -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 +6442 -1355
  9. package/dist/index.d.ts +129 -2
  10. package/dist/index.mjs +1 -1
  11. package/dist/testing.cjs +2 -0
  12. package/dist/testing.d.ts +1 -0
  13. package/dist/testing.mjs +5 -0
  14. package/dist/types/adapters/ai-sdk.d.ts +53 -0
  15. package/dist/types/agentic/agentic-pipeline.d.ts +103 -0
  16. package/dist/types/agentic/iterative-retriever.d.ts +85 -0
  17. package/dist/types/agentic/query-planner.d.ts +145 -0
  18. package/dist/types/agentic/self-critique.d.ts +45 -0
  19. package/dist/types/ai/adaptive-retrieval.d.ts +44 -0
  20. package/dist/types/ai/federation/federated-learning-coordinator.d.ts +62 -0
  21. package/dist/types/ai/multimodal-processing.d.ts +32 -0
  22. package/dist/types/ai/multimodal.d.ts +39 -0
  23. package/dist/types/ai/retrieval-engine.d.ts +37 -0
  24. package/dist/types/ai/training/model-training-orchestrator.d.ts +31 -0
  25. package/dist/types/cache/component-keys.d.ts +7 -0
  26. package/dist/types/cache/memory-cache.d.ts +54 -0
  27. package/dist/types/cache/pipeline-cache.d.ts +66 -0
  28. package/dist/types/cache/redis-cache.d.ts +46 -0
  29. package/dist/types/chunking/chunking-engine.d.ts +70 -0
  30. package/dist/types/chunking/strategies/fixed-size.d.ts +17 -0
  31. package/dist/types/chunking/strategies/recursive.d.ts +20 -0
  32. package/dist/types/chunking/strategies/semantic.d.ts +19 -0
  33. package/dist/types/chunking/strategies/sentence.d.ts +13 -0
  34. package/dist/types/chunking/strategies/structure-aware.d.ts +19 -0
  35. package/dist/types/citation/citation-tracker.d.ts +64 -0
  36. package/dist/types/citation/hallucination-detector.d.ts +40 -0
  37. package/dist/types/citation/source-mapper.d.ts +37 -0
  38. package/dist/types/connectors/anthropic-connector.d.ts +97 -0
  39. package/dist/types/connectors/base-connector.d.ts +87 -0
  40. package/dist/types/connectors/cohere-connector.d.ts +94 -0
  41. package/dist/types/connectors/connector-utils.d.ts +110 -0
  42. package/dist/types/connectors/local-embedder.d.ts +95 -0
  43. package/dist/types/connectors/memory-retriever.d.ts +99 -0
  44. package/dist/types/connectors/ollama-connector.d.ts +115 -0
  45. package/dist/types/connectors/openai-connector.d.ts +129 -0
  46. package/dist/types/connectors/rag-prompt.d.ts +40 -0
  47. package/dist/types/core/create-pipeline.d.ts +8 -0
  48. package/dist/types/core/plugin-registry.d.ts +136 -0
  49. package/dist/types/core/stage-contracts.d.ts +36 -0
  50. package/dist/types/core/validate-plugin.d.ts +45 -0
  51. package/dist/types/cost/cost-calculator.d.ts +152 -0
  52. package/dist/types/cost/cost-tracker.d.ts +126 -0
  53. package/dist/types/cost/token-budget.d.ts +110 -0
  54. package/dist/types/dag/core/error-context.d.ts +239 -0
  55. package/dist/types/dag/core/execution-scheduler.d.ts +191 -0
  56. package/dist/types/dag/core/topology-validation.d.ts +226 -0
  57. package/dist/types/dag/dag-engine.d.ts +156 -0
  58. package/dist/types/dag/dag-node.d.ts +37 -0
  59. package/dist/types/dashboard/dashboard-generator.d.ts +127 -0
  60. package/dist/types/dashboard/metrics-aggregator.d.ts +218 -0
  61. package/dist/types/debug/execution-tracer.d.ts +57 -0
  62. package/dist/types/debug/trace-inspector.d.ts +31 -0
  63. package/dist/types/ecosystem/plugin-certification.d.ts +169 -0
  64. package/dist/types/enterprise/data-governance.d.ts +203 -0
  65. package/dist/types/enterprise/multi-tenancy.d.ts +137 -0
  66. package/dist/types/enterprise/sso-integration.d.ts +420 -0
  67. package/dist/types/evaluate/context-metrics.d.ts +55 -0
  68. package/dist/types/evaluate/faithfulness.d.ts +41 -0
  69. package/dist/types/evaluate/groundedness.d.ts +60 -0
  70. package/dist/types/evaluate/pipeline-evaluator.d.ts +88 -0
  71. package/dist/types/evaluate/relevance.d.ts +21 -0
  72. package/dist/types/evaluate/scoring.d.ts +123 -0
  73. package/dist/types/evaluate/semantic-similarity.d.ts +14 -0
  74. package/dist/types/experimental.d.ts +15 -0
  75. package/dist/types/graph/entity-extractor.d.ts +84 -0
  76. package/dist/types/graph/graph-index.d.ts +49 -0
  77. package/dist/types/graph/graph-retriever.d.ts +81 -0
  78. package/dist/types/graph/knowledge-graph.d.ts +129 -0
  79. package/dist/types/grounding/check-answer.d.ts +101 -0
  80. package/dist/types/guardrails/guardrails-pipeline.d.ts +63 -0
  81. package/dist/types/guardrails/injection-detector.d.ts +47 -0
  82. package/dist/types/guardrails/post-generation-guard.d.ts +61 -0
  83. package/dist/types/guardrails/pre-retrieval-guard.d.ts +64 -0
  84. package/dist/types/guardrails/retrieval-guard.d.ts +57 -0
  85. package/dist/types/mcp/mcp-server.d.ts +85 -0
  86. package/dist/types/mcp/mcp-tool-builder.d.ts +55 -0
  87. package/dist/types/reranker/cascade-reranker.d.ts +40 -0
  88. package/dist/types/reranker/embedding-reranker.d.ts +77 -0
  89. package/dist/types/reranker/scoring-reranker.d.ts +41 -0
  90. package/dist/types/retrieval/bm25-search.d.ts +43 -0
  91. package/dist/types/retrieval/file-vector-store.d.ts +99 -0
  92. package/dist/types/retrieval/hybrid-retriever.d.ts +35 -0
  93. package/dist/types/retrieval/rank-fusion.d.ts +10 -0
  94. package/dist/types/security/jwt-config.d.ts +80 -0
  95. package/dist/types/security/jwt-validator.d.ts +195 -0
  96. package/dist/types/security/plugin-sandbox.d.ts +158 -0
  97. package/dist/types/security/plugin-signature-verifier.d.ts +139 -0
  98. package/dist/types/security/validator.d.ts +5 -0
  99. package/dist/types/streaming/embedding-stream.d.ts +65 -0
  100. package/dist/types/streaming/sse-adapter.d.ts +59 -0
  101. package/dist/types/streaming/stream-router.d.ts +88 -0
  102. package/dist/types/streaming/streaming-embedder.d.ts +99 -0
  103. package/dist/types/streaming/websocket-adapter.d.ts +71 -0
  104. package/dist/types/templates/scaffold.d.ts +55 -0
  105. package/dist/types/templates/template-registry.d.ts +63 -0
  106. package/dist/types/testing.d.ts +168 -0
  107. package/dist/types/utils/embed-query.d.ts +20 -0
  108. package/dist/types/utils/logger.d.ts +50 -0
  109. package/dist/types/utils/rate-limiter.d.ts +66 -0
  110. package/dist/types/utils/retry.d.ts +27 -0
  111. package/dist/types/utils/run-abort.d.ts +34 -0
  112. package/dist/types/utils/secure-logging.d.ts +51 -0
  113. package/dist/types/utils/structured-logger.d.ts +126 -0
  114. package/package.json +72 -33
  115. package/src/adapters/ai-sdk.js +215 -0
  116. package/src/agentic/agentic-pipeline.js +75 -7
  117. package/src/agentic/iterative-retriever.js +47 -10
  118. package/src/agentic/query-planner.js +329 -78
  119. package/src/cache/component-keys.js +38 -0
  120. package/src/cache/memory-cache.js +87 -0
  121. package/src/cache/pipeline-cache.js +260 -0
  122. package/src/cache/redis-cache.js +83 -0
  123. package/src/citation/citation-tracker.js +6 -4
  124. package/src/citation/hallucination-detector.js +2 -2
  125. package/src/citation/source-mapper.js +15 -28
  126. package/src/cli/commands/ai.js +106 -0
  127. package/src/cli/commands/plugin-hub/event-handlers.js +6 -0
  128. package/src/cli/commands/plugin-hub/hub-commands.js +0 -74
  129. package/src/cli/commands/plugin-hub/local-commands.js +143 -0
  130. package/src/cli/commands/plugin-hub.js +114 -49
  131. package/src/cli/diagnostics/config-checker.js +76 -63
  132. package/src/cli/diagnostics/environment-checker.js +62 -31
  133. package/src/cli/diagnostics/plugin-checker.js +36 -89
  134. package/src/cli/doctor-command.js +39 -5
  135. package/src/cli/enhanced-cli-commands.js +104 -233
  136. package/src/cli/handlers/ai-handler.js +364 -0
  137. package/src/cli/handlers/diagnostics-handler.js +78 -31
  138. package/src/cli/handlers/ingest-handler.js +28 -22
  139. package/src/cli/handlers/init-handler.js +148 -25
  140. package/src/cli/handlers/query-handler.js +203 -25
  141. package/src/cli/handlers/run-handler.js +16 -167
  142. package/src/cli/handlers/serve-handler.js +60 -0
  143. package/src/cli/services/bench-stats.js +54 -0
  144. package/src/cli/services/benchmark.js +161 -0
  145. package/src/cli/services/feedback.js +155 -0
  146. package/src/cli/services/instrument.js +83 -0
  147. package/src/cli/services/rag-service.js +361 -0
  148. package/src/cli/shared/cli-utils.js +24 -7
  149. package/src/cli/shared/config-context.js +21 -0
  150. package/src/cli/wizard/config-builder.js +81 -0
  151. package/src/cli/wizard/init-wizard.js +602 -0
  152. package/src/config/component-factory.js +125 -0
  153. package/src/config/enhanced-ragrc-schema.js +0 -2
  154. package/src/config/load-config.js +29 -10
  155. package/src/config/load-plugin-config.js +46 -2
  156. package/src/config/validate-schema.js +4 -1
  157. package/src/connectors/anthropic-connector.js +115 -57
  158. package/src/connectors/base-connector.js +74 -19
  159. package/src/connectors/cohere-connector.js +108 -34
  160. package/src/connectors/connector-utils.js +302 -0
  161. package/src/connectors/local-embedder.js +63 -5
  162. package/src/connectors/memory-retriever.js +125 -14
  163. package/src/connectors/ollama-connector.js +112 -51
  164. package/src/connectors/openai-connector.js +153 -44
  165. package/src/connectors/rag-prompt.js +88 -0
  166. package/src/core/create-pipeline.js +307 -61
  167. package/src/core/performance/parallel-processor.js +62 -1
  168. package/src/core/plugin-registry.js +125 -26
  169. package/src/core/stage-contracts.js +36 -0
  170. package/src/core/validate-plugin.js +85 -0
  171. package/src/cost/cost-calculator.js +205 -32
  172. package/src/debug/execution-tracer.js +14 -4
  173. package/src/dev/dev-server.js +173 -11
  174. package/src/dev/hot-reload.js +44 -4
  175. package/src/ecosystem/plugin-checks.js +181 -0
  176. package/src/ecosystem/plugin-hub.js +50 -125
  177. package/src/ecosystem/plugin-installer.js +298 -0
  178. package/src/ecosystem/plugin-probe.js +127 -0
  179. package/src/ecosystem/plugin-scanner.js +185 -0
  180. package/src/ecosystem/tar-extract.js +114 -0
  181. package/src/enterprise/audit-logging.js +158 -29
  182. package/src/enterprise/sso-integration.js +716 -228
  183. package/src/evaluate/context-metrics.js +28 -16
  184. package/src/evaluate/evaluator.js +3 -3
  185. package/src/evaluate/faithfulness.js +18 -14
  186. package/src/evaluate/groundedness.js +43 -12
  187. package/src/evaluate/pipeline-evaluator.js +35 -8
  188. package/src/evaluate/scoring.js +251 -3
  189. package/src/evaluate/semantic-similarity.js +79 -0
  190. package/src/experimental.js +71 -0
  191. package/src/grounding/check-answer.js +173 -0
  192. package/src/guardrails/guardrails-pipeline.js +69 -7
  193. package/src/guardrails/injection-detector.js +283 -0
  194. package/src/guardrails/post-generation-guard.js +19 -0
  195. package/src/guardrails/pre-retrieval-guard.js +36 -36
  196. package/src/guardrails/retrieval-guard.js +58 -8
  197. package/src/index.js +58 -1
  198. package/src/loader/csv-loader.js +3 -2
  199. package/src/loader/document-reader.js +91 -0
  200. package/src/loader/html-loader.js +3 -1
  201. package/src/loader/markdown-loader.js +3 -2
  202. package/src/reranker/cascade-reranker.js +3 -0
  203. package/src/reranker/embedding-reranker.js +136 -21
  204. package/src/reranker/llm-reranker.js +79 -12
  205. package/src/reranker/scoring-reranker.js +3 -0
  206. package/src/retrieval/bm25-search.js +12 -6
  207. package/src/retrieval/file-vector-store.js +241 -0
  208. package/src/retrieval/hybrid-retriever.js +22 -19
  209. package/src/security/jwt-config.js +13 -2
  210. package/src/security/jwt-validator.js +139 -34
  211. package/src/security/plugin-sandbox.js +18 -1
  212. package/src/security/plugin-signature-verifier.js +245 -70
  213. package/src/testing.js +254 -0
  214. package/src/utils/deprecate.js +69 -0
  215. package/src/utils/embed-query.js +33 -0
  216. package/src/utils/input-sanitizer.js +19 -4
  217. package/src/utils/logger.js +34 -4
  218. package/src/utils/run-abort.js +102 -0
  219. package/src/ai/federated-learning.js +0 -211
  220. package/src/ai/federation.js +0 -71
  221. package/src/ai/index.js +0 -22
  222. package/src/ai/model-trainer.js +0 -217
  223. package/src/ai/model-training.js +0 -202
  224. package/src/ai/multimodal/multi-modal-processor.js +0 -345
  225. package/src/ai/orchestrator.js +0 -65
  226. package/src/ai/retrieval/adaptive-retrieval-engine.js +0 -398
  227. package/src/cli/commands/ai-ml/adaptive-commands.js +0 -178
  228. package/src/cli/commands/ai-ml/federated-commands.js +0 -207
  229. package/src/cli/commands/ai-ml/index.js +0 -17
  230. package/src/cli/commands/ai-ml/multimodal-commands.js +0 -187
  231. package/src/cli/commands/ai-ml/shared.js +0 -51
  232. package/src/cli/commands/ai-ml/training-commands.js +0 -228
  233. package/src/cli/commands/ai-ml.js +0 -386
  234. package/src/cli/commands/docs.js +0 -228
  235. package/src/cli/commands/dx.js +0 -538
  236. package/src/cli/commands/wizard.js +0 -627
  237. package/src/cli/input-sanitization-middleware.js +0 -356
  238. package/src/cli/interactive-wizard.js +0 -373
  239. package/src/cli/templates/development.template.json +0 -64
  240. package/src/cli/templates/minimal.template.json +0 -33
  241. package/src/cli/templates/production.template.json +0 -104
  242. package/src/cli/templates/testing.template.json +0 -45
  243. package/src/cli/wizard/configuration.js +0 -148
  244. package/src/cli/wizard/observability.js +0 -79
  245. package/src/cli/wizard/performance.js +0 -76
  246. package/src/cli/wizard/plugin-selection.js +0 -297
  247. package/src/cli/wizard/preview-save.js +0 -172
  248. package/src/cli/wizard/project-setup.js +0 -66
  249. package/src/core/pipeline-factory.js +0 -59
  250. package/src/dag/enhanced-dag-engine.js +0 -894
  251. package/src/dx/index.js +0 -40
  252. package/src/dx/integration-templates.js +0 -662
  253. package/src/dx/performance-profiler.js +0 -968
  254. package/src/dx/realtime-debugger.js +0 -755
  255. package/src/dx/visual-pipeline-builder.js +0 -578
  256. package/src/ingest.js +0 -59
  257. package/src/pipeline/pipeline.js +0 -18
  258. package/src/query.js +0 -117
@@ -1,578 +0,0 @@
1
- /**
2
- * Visual Pipeline Builder
3
- *
4
- * Web-based drag-and-drop interface for creating and configuring RAG pipelines.
5
- * Provides visual representation of pipeline components and their connections.
6
- */
7
-
8
- const EventEmitter = require("events");
9
- // eslint-disable-line global-require
10
- const fs = require("fs").promises;
11
- // eslint-disable-line global-require
12
- const path = require("path");
13
- // eslint-disable-line global-require
14
-
15
- class VisualPipelineBuilder extends EventEmitter {
16
- constructor(_options = {}) {
17
- super();
18
-
19
- this._options = {
20
- port: _options.port || 3001,
21
- host: _options.host || "localhost",
22
- autoSave: _options.autoSave !== false,
23
- theme: _options.theme || "light",
24
- ..._options,
25
- };
26
-
27
- this.pipelines = new Map();
28
- this.components = new Map();
29
- this.connections = new Map();
30
- this.isRunning = false;
31
-
32
- this.initializeComponents();
33
- }
34
-
35
- /**
36
- * Initialize available pipeline components
37
- */
38
- initializeComponents() {
39
- const defaultComponents = [
40
- {
41
- id: "loader",
42
- type: "input",
43
- name: "Document Loader",
44
- description: "Load documents from various sources",
45
- inputs: [],
46
- outputs: ["documents"],
47
- config: {
48
- source: { type: "string", required: true },
49
- format: { type: "select", options: ["json", "txt", "pdf", "docx"] },
50
- },
51
- },
52
- {
53
- id: "embedder",
54
- type: "processor",
55
- name: "Text Embedder",
56
- description: "Generate embeddings for text content",
57
- inputs: ["documents"],
58
- outputs: ["embeddings"],
59
- config: {
60
- model: { type: "string", default: "openai" },
61
- dimensions: { type: "number", default: 1536 },
62
- },
63
- },
64
- {
65
- id: "retriever",
66
- type: "processor",
67
- name: "Document Retriever",
68
- description: "Retrieve relevant documents based on query",
69
- inputs: ["embeddings", "query"],
70
- outputs: ["results"],
71
- config: {
72
- topK: { type: "number", default: 5 },
73
- threshold: { type: "number", default: 0.7 },
74
- },
75
- },
76
- {
77
- id: "llm",
78
- type: "processor",
79
- name: "Language Model",
80
- description: "Generate responses using LLM",
81
- inputs: ["results", "query"],
82
- outputs: ["response"],
83
- config: {
84
- model: { type: "string", default: "gpt-3.5-turbo" },
85
- temperature: { type: "number", default: 0.7 },
86
- maxTokens: { type: "number", default: 1000 },
87
- },
88
- },
89
- {
90
- id: "reranker",
91
- type: "processor",
92
- name: "Result Reranker",
93
- description: "Rerank search results for better relevance",
94
- inputs: ["results"],
95
- outputs: ["rankedResults"],
96
- config: {
97
- model: { type: "string", default: "cross-encoder" },
98
- topK: { type: "number", default: 3 },
99
- },
100
- },
101
- {
102
- id: "evaluator",
103
- type: "output",
104
- name: "Response Evaluator",
105
- description: "Evaluate response quality and metrics",
106
- inputs: ["response", "query"],
107
- outputs: ["metrics"],
108
- config: {
109
- metrics: { type: "array", default: ["bleu", "rouge", "relevance"] },
110
- },
111
- },
112
- ];
113
-
114
- defaultComponents.forEach((component) => {
115
- this.components.set(component.id, component);
116
- });
117
- }
118
-
119
- /**
120
- * Create a new pipeline
121
- */
122
- createPipeline(name, description = "") {
123
- const pipelineId = `pipeline_${Date.now()}`;
124
- const pipeline = {
125
- id: pipelineId,
126
- name,
127
- description,
128
- components: [],
129
- connections: [],
130
- config: {},
131
- created: new Date().toISOString(),
132
- modified: new Date().toISOString(),
133
- };
134
-
135
- this.pipelines.set(pipelineId, pipeline);
136
- this.emit("pipelineCreated", { pipelineId, pipeline });
137
-
138
- return pipelineId;
139
- }
140
-
141
- /**
142
- * Add component to pipeline
143
- */
144
- addComponent(
145
- pipelineId,
146
- componentType,
147
- position = { x: 0, y: 0 },
148
- config = {},
149
- ) {
150
- const pipeline = this.pipelines.get(pipelineId);
151
- if (!pipeline) {
152
- throw new Error(`Pipeline ${pipelineId} not found`);
153
- }
154
-
155
- const componentTemplate = this.components.get(componentType);
156
- if (!componentTemplate) {
157
- throw new Error(`Component type ${componentType} not found`);
158
- }
159
-
160
- const componentId = `${componentType}_${Date.now()}`;
161
- const component = {
162
- id: componentId,
163
- type: componentType,
164
- position,
165
- config: { ...componentTemplate.config, ...config },
166
- inputs: [...componentTemplate.inputs],
167
- outputs: [...componentTemplate.outputs],
168
- };
169
-
170
- pipeline.components.push(component);
171
- pipeline.modified = new Date().toISOString();
172
-
173
- this.emit("componentAdded", { pipelineId, componentId, component });
174
-
175
- if (this._options.autoSave) {
176
- this.savePipeline(pipelineId);
177
- }
178
-
179
- return componentId;
180
- }
181
-
182
- /**
183
- * Connect two components
184
- */
185
- connectComponents(pipelineId, sourceId, sourceOutput, targetId, targetInput) {
186
- const pipeline = this.pipelines.get(pipelineId);
187
- if (!pipeline) {
188
- throw new Error(`Pipeline ${pipelineId} not found`);
189
- }
190
-
191
- const sourceComponent = pipeline.components.find((c) => c.id === sourceId);
192
- const targetComponent = pipeline.components.find((c) => c.id === targetId);
193
-
194
- if (!sourceComponent || !targetComponent) {
195
- throw new Error("Source or target component not found");
196
- }
197
-
198
- if (!sourceComponent.outputs.includes(sourceOutput)) {
199
- throw new Error(`Source component does not have output: ${sourceOutput}`);
200
- }
201
-
202
- if (!targetComponent.inputs.includes(targetInput)) {
203
- throw new Error(`Target component does not have input: ${targetInput}`);
204
- }
205
-
206
- const connectionId = `conn_${Date.now()}`;
207
- const connection = {
208
- id: connectionId,
209
- source: { componentId: sourceId, output: sourceOutput },
210
- target: { componentId: targetId, input: targetInput },
211
- };
212
-
213
- pipeline.connections.push(connection);
214
- pipeline.modified = new Date().toISOString();
215
-
216
- this.emit("connectionCreated", { pipelineId, connectionId, connection });
217
-
218
- if (this._options.autoSave) {
219
- this.savePipeline(pipelineId);
220
- }
221
-
222
- return connectionId;
223
- }
224
-
225
- /**
226
- * Validate pipeline configuration
227
- */
228
- validatePipeline(pipelineId) {
229
- const pipeline = this.pipelines.get(pipelineId);
230
- if (!pipeline) {
231
- throw new Error(`Pipeline ${pipelineId} not found`);
232
- }
233
-
234
- const errors = [];
235
- const warnings = [];
236
-
237
- // Check for disconnected components
238
- const connectedComponents = new Set();
239
- pipeline.connections.forEach((conn) => {
240
- connectedComponents.add(conn.source.componentId);
241
- connectedComponents.add(conn.target.componentId);
242
- });
243
-
244
- pipeline.components.forEach((component) => {
245
- if (
246
- !connectedComponents.has(component.id) &&
247
- pipeline.components.length > 1
248
- ) {
249
- warnings.push(`Component ${component.id} is not connected`);
250
- }
251
-
252
- // Check required configuration
253
- const template = this.components.get(component.type);
254
- if (template) {
255
- Object.entries(template.config).forEach(([key, configDef]) => {
256
- if (configDef.required && !component.config[key]) {
257
- errors.push(
258
- `Component ${component.id} missing required config: ${key}`,
259
- );
260
- }
261
- });
262
- }
263
- });
264
-
265
- // Check for cycles
266
- if (this.hasCycles(pipeline)) {
267
- errors.push("Pipeline contains cycles");
268
- }
269
-
270
- return {
271
- valid: errors.length === 0,
272
- errors,
273
- warnings,
274
- };
275
- }
276
-
277
- /**
278
- * Check for cycles in pipeline
279
- */
280
- hasCycles(pipeline) {
281
- const graph = new Map();
282
- const visited = new Set();
283
- const recursionStack = new Set();
284
-
285
- // Build adjacency list
286
- pipeline.components.forEach((component) => {
287
- graph.set(component.id, []);
288
- });
289
-
290
- pipeline.connections.forEach((connection) => {
291
- const sourceId = connection.source.componentId;
292
- const targetId = connection.target.componentId;
293
- if (graph.has(sourceId)) {
294
- graph.get(sourceId).push(targetId);
295
- }
296
- });
297
-
298
- // DFS cycle detection
299
- const hasCycleDFS = (nodeId) => {
300
- visited.add(nodeId);
301
- recursionStack.add(nodeId);
302
-
303
- const neighbors = graph.get(nodeId) || [];
304
- for (const neighbor of neighbors) {
305
- if (!visited.has(neighbor)) {
306
- if (hasCycleDFS(neighbor)) {
307
- return true;
308
- }
309
- } else if (recursionStack.has(neighbor)) {
310
- return true;
311
- }
312
- }
313
-
314
- recursionStack.delete(nodeId);
315
- return false;
316
- };
317
-
318
- for (const componentId of graph.keys()) {
319
- if (!visited.has(componentId)) {
320
- if (hasCycleDFS(componentId)) {
321
- return true;
322
- }
323
- }
324
- }
325
-
326
- return false;
327
- }
328
-
329
- /**
330
- * Generate pipeline code
331
- */
332
- generateCode(pipelineId, format = "javascript") {
333
- const pipeline = this.pipelines.get(pipelineId);
334
- if (!pipeline) {
335
- throw new Error(`Pipeline ${pipelineId} not found`);
336
- }
337
-
338
- const validation = this.validatePipeline(pipelineId);
339
- if (!validation.valid) {
340
- throw new Error(
341
- `Pipeline validation failed: ${validation.errors.join(", ")}`,
342
- );
343
- }
344
-
345
- if (format === "javascript") {
346
- return this.generateJavaScriptCode(pipeline);
347
- } else if (format === "json") {
348
- return this.generateJSONConfig(pipeline);
349
- } else {
350
- throw new Error(`Unsupported format: ${format}`);
351
- }
352
- }
353
-
354
- /**
355
- * Generate JavaScript code for pipeline
356
- */
357
- generateJavaScriptCode(pipeline) {
358
- const imports = new Set();
359
- const componentInits = [];
360
- const pipelineSteps = [];
361
-
362
- // Sort components topologically
363
- const sortedComponents = this.topologicalSort(pipeline);
364
-
365
- sortedComponents.forEach((component) => {
366
- const template = this.components.get(component.type);
367
- if (template) {
368
- imports.add(
369
- `const ${template.name.replace(/\s+/g, "")} = require('@devilsdev/rag-pipeline-utils/src/plugins/${component.type}');`,
370
- );
371
- // eslint-disable-line global-require
372
-
373
- const configStr = JSON.stringify(component.config, null, 2);
374
- componentInits.push(
375
- `const ${component.id} = new ${template.name.replace(/\s+/g, "")}(${configStr});`,
376
- );
377
-
378
- pipelineSteps.push(` await ${component.id}.process(context);`);
379
- }
380
- });
381
-
382
- return `// Generated RAG Pipeline: ${pipeline.name}
383
- // Created: ${pipeline.created}
384
- // Modified: ${pipeline.modified}
385
-
386
- ${Array.from(imports).join("\n")}
387
-
388
- async function ${pipeline.name.replace(/\s+/g, "")}Pipeline(input) {
389
- const context = { input, results: {} };
390
-
391
- // Initialize components
392
- ${componentInits.map((init) => ` ${init}`).join("\n")}
393
-
394
- // Execute pipeline
395
- ${pipelineSteps.join("\n")}
396
-
397
- return context.results;
398
- }
399
-
400
- module.exports = { ${pipeline.name.replace(/\s+/g, "")}Pipeline };`;
401
- }
402
-
403
- /**
404
- * Generate JSON configuration for pipeline
405
- */
406
- generateJSONConfig(pipeline) {
407
- return JSON.stringify(
408
- {
409
- name: pipeline.name,
410
- description: pipeline.description,
411
- version: "1.0.0",
412
- components: pipeline.components.map((component) => ({
413
- id: component.id,
414
- type: component.type,
415
- config: component.config,
416
- })),
417
- connections: pipeline.connections,
418
- metadata: {
419
- created: pipeline.created,
420
- modified: pipeline.modified,
421
- },
422
- },
423
- null,
424
- 2,
425
- );
426
- }
427
-
428
- /**
429
- * Topological sort of pipeline components
430
- */
431
- topologicalSort(pipeline) {
432
- const graph = new Map();
433
- const inDegree = new Map();
434
-
435
- // Initialize
436
- pipeline.components.forEach((component) => {
437
- graph.set(component.id, []);
438
- inDegree.set(component.id, 0);
439
- });
440
-
441
- // Build graph
442
- pipeline.connections.forEach((connection) => {
443
- const sourceId = connection.source.componentId;
444
- const targetId = connection.target.componentId;
445
- graph.get(sourceId).push(targetId);
446
- inDegree.set(targetId, inDegree.get(targetId) + 1);
447
- });
448
-
449
- // Kahn's algorithm
450
- const queue = [];
451
- const result = [];
452
-
453
- inDegree.forEach((degree, componentId) => {
454
- if (degree === 0) {
455
- queue.push(componentId);
456
- }
457
- });
458
-
459
- while (queue.length > 0) {
460
- const current = queue.shift();
461
- const component = pipeline.components.find((c) => c.id === current);
462
- result.push(component);
463
-
464
- graph.get(current).forEach((neighbor) => {
465
- inDegree.set(neighbor, inDegree.get(neighbor) - 1);
466
- if (inDegree.get(neighbor) === 0) {
467
- queue.push(neighbor);
468
- }
469
- });
470
- }
471
-
472
- return result;
473
- }
474
-
475
- /**
476
- * Save pipeline to disk
477
- */
478
- async savePipeline(pipelineId) {
479
- const pipeline = this.pipelines.get(pipelineId);
480
- if (!pipeline) {
481
- throw new Error(`Pipeline ${pipelineId} not found`);
482
- }
483
-
484
- const pipelinesDir = path.join(process.cwd(), "pipelines");
485
- await fs.mkdir(pipelinesDir, { recursive: true });
486
-
487
- const _filePath = path.join(pipelinesDir, `${pipelineId}.json`);
488
- await fs.writeFile(_filePath, JSON.stringify(pipeline, null, 2));
489
-
490
- this.emit("pipelineSaved", { pipelineId, _filePath });
491
- }
492
-
493
- /**
494
- * Load pipeline from disk
495
- */
496
- async loadPipeline(pipelineId) {
497
- const pipelinesDir = path.join(process.cwd(), "pipelines");
498
- const _filePath = path.join(pipelinesDir, `${pipelineId}.json`);
499
-
500
- try {
501
- const data = await fs.readFile(_filePath, "utf8");
502
- const pipeline = JSON.parse(data);
503
- this.pipelines.set(pipelineId, pipeline);
504
-
505
- this.emit("pipelineLoaded", { pipelineId, pipeline });
506
- return pipeline;
507
- } catch (error) {
508
- throw new Error(
509
- `Failed to load pipeline ${pipelineId}: ${error.message}`,
510
- );
511
- }
512
- }
513
-
514
- /**
515
- * Get all pipelines
516
- */
517
- getAllPipelines() {
518
- return Array.from(this.pipelines.values());
519
- }
520
-
521
- /**
522
- * Get available components
523
- */
524
- getAvailableComponents() {
525
- return Array.from(this.components.values());
526
- }
527
-
528
- /**
529
- * Start the visual builder web server
530
- */
531
- async startServer() {
532
- if (this.isRunning) {
533
- throw new Error("Server is already running");
534
- }
535
-
536
- // This would typically start an Express server with the web interface
537
- // For now, we'll simulate the server startup
538
- this.isRunning = true;
539
- this.emit("serverStarted", {
540
- host: this._options.host,
541
- port: this._options.port,
542
- url: `http://${this.options.host}:${this.options.port}`,
543
- });
544
-
545
- return {
546
- host: this._options.host,
547
- port: this._options.port,
548
- url: `http://${this.options.host}:${this.options.port}`,
549
- };
550
- }
551
-
552
- /**
553
- * Stop the visual builder web server
554
- */
555
- async stopServer() {
556
- if (!this.isRunning) {
557
- throw new Error("Server is not running");
558
- }
559
-
560
- this.isRunning = false;
561
- this.emit("serverStopped");
562
- }
563
-
564
- /**
565
- * Get server status
566
- */
567
- getServerStatus() {
568
- return {
569
- running: this.isRunning,
570
- host: this._options.host,
571
- port: this._options.port,
572
- pipelines: this.pipelines.size,
573
- components: this.components.size,
574
- };
575
- }
576
- }
577
-
578
- module.exports = VisualPipelineBuilder;
package/src/ingest.js DELETED
@@ -1,59 +0,0 @@
1
- 'use strict';
2
- /**
3
- * Minimal ingest surface; wire real backend later.
4
- */
5
- const path = require('path');
6
- const { logger } = require('./utils/logger.js');
7
-
8
- /**
9
- * Ingest a single document by path.
10
- * @param {string} filepath - Document path
11
- * @param {object} config - Configuration object
12
- * @returns {boolean} - Result (synchronous for now, can be made async later)
13
- */
14
- function ingestDocument(filepath, config) {
15
- // Validate document path - always throw synchronously for validation errors
16
- if (!filepath || typeof filepath !== 'string' || filepath.trim() === '') {
17
- throw new Error('Document path is required');
18
- }
19
-
20
- // Validate configuration - always throw synchronously for validation errors
21
- if (!config || typeof config !== 'object') {
22
- throw new Error('Configuration is required');
23
- }
24
-
25
- // Process document with safer error handling
26
- try {
27
- const abs = path.resolve(filepath);
28
- logger.info({ file: abs }, 'ingest:start');
29
-
30
- // TODO: real ingestion (mime sniff, loader selection, vector upsert)
31
- // For now, return success
32
- logger.info({ file: abs }, 'ingest:complete');
33
- return true;
34
- } catch (error) {
35
- // Log processing errors but don't crash
36
- logger.error({ file: filepath, error: error.message }, 'ingest:error');
37
-
38
- // Re-throw with more context for better debugging
39
- const enhancedError = new Error(
40
- `Failed to ingest document '${filepath}': ${error.message}`,
41
- );
42
- enhancedError.originalError = error;
43
- enhancedError.filepath = filepath;
44
- throw enhancedError;
45
- }
46
- }
47
-
48
- /**
49
- * Async version of ingestDocument for future use
50
- * @param {string} filepath - Document path
51
- * @param {object} config - Configuration object
52
- * @returns {Promise<boolean>} - Result promise
53
- */
54
- async function ingestDocumentAsync(filepath, config) {
55
- // Reuse sync validation and processing
56
- return ingestDocument(filepath, config);
57
- }
58
-
59
- module.exports = { ingestDocument, ingestDocumentAsync };
@@ -1,18 +0,0 @@
1
- // src/pipeline/pipeline.js
2
- class Pipeline {
3
- async run({ query, queryVector, options = {} }) {
4
- // minimal synthetic work so tests complete within timeouts
5
- void query;
6
- void queryVector;
7
- const topK = options.topK ?? 5;
8
- await new Promise((r) => setTimeout(r, 5)); // small async step
9
- return {
10
- results: Array.from({ length: topK }, (_, i) => ({
11
- id: `doc-${i}`,
12
- score: 1 - i * 0.01,
13
- })),
14
- };
15
- }
16
- }
17
-
18
- module.exports = { Pipeline };