@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
@@ -0,0 +1,88 @@
1
+ /**
2
+ * Routes pipeline streaming output to SSE or WebSocket transports.
3
+ *
4
+ * Provides both an Express/Node-HTTP-compatible request handler via
5
+ * {@link StreamRouter#createHandler} and lower-level convenience methods
6
+ * ({@link StreamRouter#streamSSE}, {@link StreamRouter#streamWS}) for
7
+ * manual integration.
8
+ *
9
+ * @extends EventEmitter
10
+ *
11
+ * @example
12
+ * const router = new StreamRouter({ enableCORS: true });
13
+ * const handler = router.createHandler(pipeline);
14
+ * app.post('/api/query', handler);
15
+ */
16
+ export class StreamRouter extends EventEmitter<[never]> {
17
+ /**
18
+ * @param {Object} [options] - Configuration overrides
19
+ * @param {string} [options.defaultTransport='sse'] - Fallback transport type
20
+ * @param {boolean} [options.enableCORS=true] - Enable CORS headers
21
+ * @param {string} [options.corsOrigin='*'] - CORS origin value
22
+ * @param {Object} [options.sseOptions] - Options forwarded to SSEAdapter
23
+ * @param {Object} [options.wsOptions] - Options forwarded to WebSocketAdapter
24
+ */
25
+ constructor(options?: {
26
+ defaultTransport?: string;
27
+ enableCORS?: boolean;
28
+ corsOrigin?: string;
29
+ sseOptions?: any;
30
+ wsOptions?: any;
31
+ });
32
+ config: any;
33
+ sseAdapter: SSEAdapter;
34
+ wsAdapter: WebSocketAdapter;
35
+ /**
36
+ * Create an HTTP request handler that runs the pipeline in streaming mode
37
+ * and routes output to the appropriate transport.
38
+ *
39
+ * The returned function is compatible with Node's `http.createServer`,
40
+ * Express, and similar frameworks.
41
+ *
42
+ * Transport detection:
43
+ * - `Accept: text/event-stream` header selects SSE
44
+ * - `Upgrade: websocket` header selects WebSocket (note: actual upgrade
45
+ * negotiation is typically handled at a higher level)
46
+ * - Otherwise falls back to {@link DEFAULT_CONFIG.defaultTransport}
47
+ *
48
+ * @param {Object} pipeline - A pipeline object with a `.run()` method
49
+ * @returns {Function} Async request handler `(req, res) => Promise<void>`
50
+ */
51
+ createHandler(pipeline: any): Function;
52
+ /**
53
+ * Run the pipeline in streaming mode and pipe tokens to an HTTP response
54
+ * via Server-Sent Events.
55
+ *
56
+ * If the pipeline returns a non-iterable result, it is sent as a single
57
+ * SSE data frame followed by the done sentinel.
58
+ *
59
+ * @param {Object} pipeline - Pipeline with a `.run()` method
60
+ * @param {string} query - User query string
61
+ * @param {import('http').ServerResponse} httpResponse - Writable HTTP response
62
+ * @param {Object} [options={}] - Additional pipeline run options
63
+ * @returns {Promise<void>}
64
+ */
65
+ streamSSE(pipeline: any, query: string, httpResponse: import("http").ServerResponse, options?: any): Promise<void>;
66
+ /**
67
+ * Run the pipeline in streaming mode and pipe tokens over a WebSocket
68
+ * connection.
69
+ *
70
+ * If the pipeline returns a non-iterable result, it is sent as a single
71
+ * `result` message followed by a `done` message.
72
+ *
73
+ * @param {Object} pipeline - Pipeline with a `.run()` method
74
+ * @param {string} query - User query string
75
+ * @param {Object} wsConnection - WebSocket-like connection with `.send()`
76
+ * @param {Object} [options={}] - Additional pipeline run options
77
+ * @returns {Promise<void>}
78
+ */
79
+ streamWS(pipeline: any, query: string, wsConnection: any, options?: any): Promise<void>;
80
+ }
81
+ /**
82
+ * Default configuration for the stream router
83
+ * @type {Object}
84
+ */
85
+ export const DEFAULT_CONFIG: any;
86
+ import { EventEmitter } from "events";
87
+ import { SSEAdapter } from "./sse-adapter";
88
+ import { WebSocketAdapter } from "./websocket-adapter";
@@ -0,0 +1,99 @@
1
+ /**
2
+ * EventEmitter-based wrapper around {@link createEmbeddingStream}.
3
+ *
4
+ * @extends EventEmitter
5
+ *
6
+ * @fires StreamingEmbedder#start
7
+ * @fires StreamingEmbedder#embedding
8
+ * @fires StreamingEmbedder#batch
9
+ * @fires StreamingEmbedder#backpressure
10
+ * @fires StreamingEmbedder#done
11
+ * @fires StreamingEmbedder#error
12
+ *
13
+ * @example
14
+ * const se = new StreamingEmbedder(myEmbedder, { batchSize: 25 });
15
+ * se.on('embedding', (e) => console.log(e.id, e.progress));
16
+ * se.on('done', (stats) => console.log('finished', stats));
17
+ * const all = await se.embedAll(documents);
18
+ */
19
+ export class StreamingEmbedder extends EventEmitter<[never]> {
20
+ /**
21
+ * @param {Object} embedder - Embedder instance with `.embed()` or `.embedQuery()`
22
+ * @param {Object} [options] - Override any key from {@link DEFAULT_CONFIG}
23
+ */
24
+ constructor(embedder: any, options?: any);
25
+ /** @type {Object} */
26
+ embedder: any;
27
+ /** @type {Object} */
28
+ config: any;
29
+ /** @type {{ processed: number, failed: number, totalTime: number }} */
30
+ stats: {
31
+ processed: number;
32
+ failed: number;
33
+ totalTime: number;
34
+ };
35
+ /**
36
+ * Async generator that yields embeddings while emitting lifecycle events.
37
+ *
38
+ * @param {Array<{id: string, content: string}>} documents - Documents to embed
39
+ * @yields {{ id: string, vector: number[], index: number, progress: number }}
40
+ *
41
+ * @fires StreamingEmbedder#start
42
+ * @fires StreamingEmbedder#embedding
43
+ * @fires StreamingEmbedder#batch
44
+ * @fires StreamingEmbedder#backpressure
45
+ * @fires StreamingEmbedder#done
46
+ * @fires StreamingEmbedder#error
47
+ */
48
+ embedStream(documents: Array<{
49
+ id: string;
50
+ content: string;
51
+ }>): AsyncGenerator<{
52
+ backpressure?: boolean;
53
+ id: string;
54
+ vector: any;
55
+ index: number;
56
+ progress: number;
57
+ error?: undefined;
58
+ } | {
59
+ id: string;
60
+ error: any;
61
+ index: number;
62
+ progress: number;
63
+ }, void, unknown>;
64
+ /**
65
+ * Convenience method that collects all embeddings into an array.
66
+ *
67
+ * @param {Array<{id: string, content: string}>} documents - Documents to embed
68
+ * @returns {Promise<Array<{ id: string, vector: number[], index: number, progress: number }>>}
69
+ */
70
+ embedAll(documents: Array<{
71
+ id: string;
72
+ content: string;
73
+ }>): Promise<Array<{
74
+ id: string;
75
+ vector: number[];
76
+ index: number;
77
+ progress: number;
78
+ }>>;
79
+ /**
80
+ * Returns a snapshot of the cumulative statistics.
81
+ *
82
+ * @returns {{ processed: number, failed: number, totalTime: number }}
83
+ */
84
+ getStats(): {
85
+ processed: number;
86
+ failed: number;
87
+ totalTime: number;
88
+ };
89
+ /**
90
+ * Resets the cumulative statistics to zero.
91
+ */
92
+ resetStats(): void;
93
+ }
94
+ /**
95
+ * Default configuration for the StreamingEmbedder
96
+ * @type {Object}
97
+ */
98
+ export const DEFAULT_CONFIG: any;
99
+ import { EventEmitter } from "events";
@@ -0,0 +1,71 @@
1
+ /**
2
+ * Adapts an AsyncGenerator to a WebSocket connection.
3
+ *
4
+ * Sends JSON-framed messages for each token, a completion message when
5
+ * the generator is exhausted, and an error message on failure. Handles
6
+ * premature connection closure gracefully.
7
+ *
8
+ * @extends EventEmitter
9
+ *
10
+ * @example
11
+ * const adapter = new WebSocketAdapter();
12
+ * adapter.on('done', () => console.log('stream complete'));
13
+ * await adapter.stream(asyncTokenGenerator, ws);
14
+ */
15
+ export class WebSocketAdapter extends EventEmitter<[never]> {
16
+ /**
17
+ * @param {Object} [options] - Configuration overrides
18
+ * @param {string} [options.messageType='token'] - Type field for token messages
19
+ * @param {string} [options.doneType='done'] - Type field for completion message
20
+ * @param {string} [options.errorType='error'] - Type field for error messages
21
+ */
22
+ constructor(options?: {
23
+ messageType?: string;
24
+ doneType?: string;
25
+ errorType?: string;
26
+ });
27
+ config: any;
28
+ /**
29
+ * Stream tokens from an AsyncGenerator over a WebSocket connection.
30
+ *
31
+ * Each yielded value should be an object with at least a `token` property
32
+ * and an optional `done` boolean. Messages are sent as JSON strings via
33
+ * `wsConnection.send()`.
34
+ *
35
+ * @param {AsyncGenerator<{token: string, done?: boolean}>} asyncGenerator - Token source
36
+ * @param {Object} wsConnection - WebSocket-like object with a `send(data)` method
37
+ * @param {Function} wsConnection.send - Sends a string message over the socket
38
+ * @param {number} [wsConnection.readyState] - Optional W3C readyState property
39
+ * @returns {Promise<void>} Resolves when the stream ends or the connection closes
40
+ * @throws {TypeError} If wsConnection lacks a send method
41
+ */
42
+ stream(asyncGenerator: AsyncGenerator<{
43
+ token: string;
44
+ done?: boolean;
45
+ }>, wsConnection: {
46
+ send: Function;
47
+ readyState?: number;
48
+ }): Promise<void>;
49
+ /**
50
+ * Check whether the WebSocket connection is still open.
51
+ *
52
+ * @param {Object} wsConnection
53
+ * @returns {boolean}
54
+ * @private
55
+ */
56
+ private _isOpen;
57
+ /**
58
+ * Send a JSON-serialised message over the WebSocket.
59
+ *
60
+ * @param {Object} wsConnection
61
+ * @param {Object} payload
62
+ * @private
63
+ */
64
+ private _send;
65
+ }
66
+ /**
67
+ * Default configuration for WebSocket streaming
68
+ * @type {Object}
69
+ */
70
+ export const DEFAULT_CONFIG: any;
71
+ import { EventEmitter } from "events";
@@ -0,0 +1,55 @@
1
+ /**
2
+ * Creates complete project directories from registered templates.
3
+ *
4
+ * @extends EventEmitter
5
+ * @fires ProjectScaffolder#created
6
+ *
7
+ * @example
8
+ * const scaffolder = new ProjectScaffolder();
9
+ * const result = scaffolder.create('document-qa', '/path/to/my-project');
10
+ * console.log(result.files); // list of created files
11
+ */
12
+ export class ProjectScaffolder extends EventEmitter<[never]> {
13
+ /**
14
+ * @param {Object} [options={}] - Scaffolder configuration
15
+ * @param {boolean} [options.installDependencies=false] - Whether to auto-run npm install
16
+ * @param {boolean} [options.overwrite=false] - Allow overwriting existing directories
17
+ */
18
+ constructor(options?: {
19
+ installDependencies?: boolean;
20
+ overwrite?: boolean;
21
+ });
22
+ config: any;
23
+ registry: TemplateRegistry;
24
+ /**
25
+ * Create a new project from a template.
26
+ *
27
+ * @param {string} templateKey - Key of the template to use
28
+ * @param {string} projectDir - Target directory for the new project
29
+ * @param {Object} [options={}] - Per-call overrides
30
+ * @param {boolean} [options.overwrite] - Override the instance-level overwrite setting
31
+ * @returns {{projectDir: string, files: string[], template: string}} Creation result
32
+ * @throws {Error} If template is not found or directory already exists
33
+ */
34
+ create(templateKey: string, projectDir: string, options?: {
35
+ overwrite?: boolean;
36
+ }): {
37
+ projectDir: string;
38
+ files: string[];
39
+ template: string;
40
+ };
41
+ /**
42
+ * List all available templates.
43
+ *
44
+ * @returns {Array<{key: string, name: string, description: string}>} Available templates
45
+ */
46
+ listTemplates(): Array<{
47
+ key: string;
48
+ name: string;
49
+ description: string;
50
+ }>;
51
+ }
52
+ /** @type {Object} Default configuration for the project scaffolder */
53
+ export const DEFAULT_CONFIG: any;
54
+ import { EventEmitter } from "events";
55
+ import { TemplateRegistry } from "./template-registry";
@@ -0,0 +1,63 @@
1
+ /**
2
+ * Registry of built-in and custom project templates.
3
+ *
4
+ * @example
5
+ * const registry = new TemplateRegistry();
6
+ * const templates = registry.list();
7
+ * const template = registry.get('document-qa');
8
+ */
9
+ export class TemplateRegistry {
10
+ /** @type {Map<string, Object>} */
11
+ templates: Map<string, any>;
12
+ /**
13
+ * List all available templates.
14
+ *
15
+ * @returns {Array<{key: string, name: string, description: string}>} Summary of each template
16
+ */
17
+ list(): Array<{
18
+ key: string;
19
+ name: string;
20
+ description: string;
21
+ }>;
22
+ /**
23
+ * Get a full template definition by key.
24
+ *
25
+ * @param {string} templateKey - Template identifier
26
+ * @returns {Object|null} Full template object, or null if not found
27
+ */
28
+ get(templateKey: string): any | null;
29
+ /**
30
+ * Register a custom template.
31
+ *
32
+ * @param {string} key - Template identifier
33
+ * @param {Object} template - Template definition
34
+ * @param {string} template.name - Display name
35
+ * @param {string} template.description - Short description
36
+ * @param {Object} template.dependencies - npm dependencies
37
+ * @param {Object} template.config - Pipeline configuration
38
+ * @param {Object} template.files - Map of filename to file content
39
+ * @returns {void}
40
+ */
41
+ register(key: string, template: {
42
+ name: string;
43
+ description: string;
44
+ dependencies: any;
45
+ config: any;
46
+ files: any;
47
+ }): void;
48
+ /**
49
+ * Check if a template exists.
50
+ *
51
+ * @param {string} key - Template identifier
52
+ * @returns {boolean} Whether the template is registered
53
+ */
54
+ has(key: string): boolean;
55
+ }
56
+ /**
57
+ * @module templates/template-registry
58
+ * @description Registry of built-in project templates for RAG pipeline scaffolding.
59
+ */
60
+ /** @type {Object<string, Object>} Built-in template definitions */
61
+ export const TEMPLATES: {
62
+ [x: string]: any;
63
+ };
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Embed a single query string with any supported embedder shape.
3
+ *
4
+ * Prefers embedQuery(); falls back to embed(). Accepts the common return
5
+ * shapes: a vector, a list of vectors, or [{ values | vector | embedding }].
6
+ *
7
+ * @param {object} embedder - Object with embedQuery() or embed()
8
+ * @param {string} query - Text to embed
9
+ * @param {{ signal?: AbortSignal }} [options] - Passed to the embedder as its
10
+ * second argument (only when given, so embedders keep their usual arity)
11
+ * @returns {Promise<number[]|undefined>} The query vector
12
+ */
13
+ export function embedQuery(embedder: object, query: string, options?: {
14
+ signal?: AbortSignal;
15
+ }): Promise<number[] | undefined>;
16
+ /**
17
+ * @param {object} [embedder]
18
+ * @returns {boolean} Whether embedQuery() can use this embedder
19
+ */
20
+ export function canEmbed(embedder?: object): boolean;
@@ -0,0 +1,50 @@
1
+ export const logger: StructuredLogger;
2
+ /**
3
+ * Create a logger with correlation ID for request tracing
4
+ */
5
+ export function createLogger(correlationId: any, context?: {}): StructuredLogger;
6
+ /**
7
+ * Middleware function for Express.js to add correlation IDs to requests
8
+ */
9
+ export function correlationMiddleware(req: any, res: any, next: any): void;
10
+ /**
11
+ * Enhanced logger with correlation ID support and structured context
12
+ */
13
+ export class StructuredLogger {
14
+ constructor(baseLogger: any);
15
+ logger: any;
16
+ correlationId: any;
17
+ context: {};
18
+ /**
19
+ * Create a child logger with correlation ID and context
20
+ */
21
+ child(context?: {}): StructuredLogger;
22
+ /**
23
+ * Set correlation ID for distributed tracing
24
+ */
25
+ setCorrelationId(correlationId: any): this;
26
+ /**
27
+ * Add persistent context to all log messages
28
+ */
29
+ setContext(context: any): this;
30
+ /**
31
+ * Log with automatic correlation ID and context injection
32
+ */
33
+ _log(level: any, message: any, meta?: {}): void;
34
+ info(message: any, meta: any): void;
35
+ error(message: any, meta: any): void;
36
+ warn(message: any, meta: any): void;
37
+ debug(message: any, meta: any): void;
38
+ /**
39
+ * Security audit logging with enhanced metadata
40
+ */
41
+ audit(action: any, meta?: {}): void;
42
+ /**
43
+ * Performance logging with timing information
44
+ */
45
+ performance(operation: any, duration: any, meta?: {}): void;
46
+ /**
47
+ * Tenant-specific logging for multi-tenant applications
48
+ */
49
+ tenant(tenantId: any, message: any, meta?: {}): void;
50
+ }
@@ -0,0 +1,66 @@
1
+ export = RateLimiter;
2
+ declare class RateLimiter {
3
+ /**
4
+ * Create a rate limiter instance
5
+ * @param {Object} options - Configuration options
6
+ * @param {number} options.maxAttempts - Maximum attempts allowed (default: 5)
7
+ * @param {number} options.windowMs - Time window in milliseconds (default: 15 minutes)
8
+ * @param {number} options.blockDurationMs - How long to block after exceeding limit (default: 1 hour)
9
+ * @param {number} options.cleanupIntervalMs - How often to cleanup expired entries (default: 5 minutes)
10
+ */
11
+ constructor(options?: {
12
+ maxAttempts: number;
13
+ windowMs: number;
14
+ blockDurationMs: number;
15
+ cleanupIntervalMs: number;
16
+ });
17
+ maxAttempts: number;
18
+ windowMs: number;
19
+ blockDurationMs: number;
20
+ cleanupIntervalMs: number;
21
+ store: Map<any, any>;
22
+ /**
23
+ * Check if a request should be allowed
24
+ * @param {string} identifier - Unique identifier (IP, userId, tenantId, etc.)
25
+ * @returns {Object} { allowed: boolean, remaining: number, resetAt: Date, blockedUntil: Date|null }
26
+ */
27
+ allowRequest(identifier: string): any;
28
+ /**
29
+ * Manually reset rate limit for an identifier
30
+ * @param {string} identifier - Identifier to reset
31
+ */
32
+ reset(identifier: string): void;
33
+ /**
34
+ * Get current status for an identifier
35
+ * @param {string} identifier - Identifier to check
36
+ * @returns {Object} Current rate limit status
37
+ */
38
+ getStatus(identifier: string): any;
39
+ /**
40
+ * Clean up expired entries
41
+ */
42
+ cleanup(): {
43
+ cleaned: number;
44
+ remaining: number;
45
+ };
46
+ /**
47
+ * Get statistics about rate limiter usage
48
+ * @returns {Object} Statistics
49
+ */
50
+ getStats(): any;
51
+ /**
52
+ * Stop the rate limiter and cleanup
53
+ */
54
+ destroy(): void;
55
+ _cleanupInterval: NodeJS.Timeout;
56
+ /**
57
+ * Hash identifier for storage (privacy)
58
+ * @private
59
+ */
60
+ private _hashIdentifier;
61
+ /**
62
+ * Start automatic cleanup timer
63
+ * @private
64
+ */
65
+ private _startCleanup;
66
+ }
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Retry a function with exponential backoff.
3
+ *
4
+ * @param {Function} fn - async or sync function to call; receives (attempt)
5
+ * @param {Object} [opts]
6
+ * @param {number} [opts.retries=3] - number of *retries* (total attempts = retries + 1)
7
+ * @param {number} [opts.baseDelay=100] - initial delay in ms
8
+ * @param {number} [opts.multiplier=2] - backoff multiplier
9
+ * @param {boolean} [opts.jitter=false] - add +/-50% jitter if true
10
+ * @param {Function} [opts.sleep=defaultSleep] - injected sleeper for tests
11
+ * @param {Function} [opts.onDelay] - callback (delayMs, attempt, error) before each sleep
12
+ * @returns {Promise<*>}
13
+ */
14
+ export function retry(fn: Function, opts?: {
15
+ retries?: number;
16
+ baseDelay?: number;
17
+ multiplier?: number;
18
+ jitter?: boolean;
19
+ sleep?: Function;
20
+ onDelay?: Function;
21
+ }): Promise<any>;
22
+ export function withRetry(_fn: any, { retries, initialDelay, label }?: {
23
+ retries?: number;
24
+ initialDelay?: number;
25
+ label?: string;
26
+ }): Promise<any>;
27
+ export function defaultSleep(ms: any): Promise<any>;
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Per-run cancellation: one AbortController that is aborted when `timeout`
3
+ * elapses or when the caller's `signal` aborts. Its `signal` is handed to
4
+ * every component call; `race()` makes the run settle as soon as it is
5
+ * aborted even if a component ignores the signal; `throwIfAborted()` stops
6
+ * work between stages.
7
+ *
8
+ * @param {object} [options]
9
+ * @param {number} [options.timeout] - Milliseconds before the run is aborted
10
+ * @param {AbortSignal} [options.signal] - Caller's signal to follow
11
+ * @returns {{
12
+ * signal: AbortSignal,
13
+ * race: (promise: Promise<any>) => Promise<any>,
14
+ * throwIfAborted: () => void,
15
+ * clearTimer: () => void,
16
+ * detach: () => void,
17
+ * cleanup: () => void
18
+ * }}
19
+ */
20
+ export function createRunAbort({ timeout, signal }?: {
21
+ timeout?: number;
22
+ signal?: AbortSignal;
23
+ }): {
24
+ signal: AbortSignal;
25
+ race: (promise: Promise<any>) => Promise<any>;
26
+ throwIfAborted: () => void;
27
+ clearTimer: () => void;
28
+ detach: () => void;
29
+ cleanup: () => void;
30
+ };
31
+ /** Message used for a run that exceeded its timeout. */
32
+ export const TIMEOUT_MESSAGE: "Execution timeout";
33
+ /** Message used for a run cancelled through the caller's AbortSignal. */
34
+ export const ABORTED_MESSAGE: "Execution aborted";
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Redact sensitive fields in an object
3
+ * @param {any} obj - Object to redact
4
+ * @param {number} depth - Current recursion depth
5
+ * @param {number} maxDepth - Maximum recursion depth
6
+ * @returns {any} Redacted object
7
+ */
8
+ export function redactObject(obj: any, depth?: number, maxDepth?: number): any;
9
+ /**
10
+ * Redact a string value if it contains secrets
11
+ * @param {string} value - String value to redact
12
+ * @returns {string} Redacted value if sensitive, original otherwise
13
+ */
14
+ export function redactStringValue(value: string): string;
15
+ /**
16
+ * Redact sensitive information from log data
17
+ * @param {string} message - Log message
18
+ * @param {object} meta - Log metadata object
19
+ * @returns {object} Redacted message and metadata
20
+ */
21
+ export function redactLogData(message: string, meta?: object): object;
22
+ /**
23
+ * Create a redacting wrapper for any logger
24
+ * @param {object} logger - Logger instance to wrap
25
+ * @returns {object} Wrapped logger with automatic redaction
26
+ */
27
+ export function createSecureLogger(logger: object): object;
28
+ /**
29
+ * Check if a field name is sensitive
30
+ * @param {string} fieldName - Field name to check
31
+ * @returns {boolean} True if sensitive
32
+ */
33
+ export function isSensitiveFieldName(fieldName: string): boolean;
34
+ /**
35
+ * Check if a value matches a secret pattern
36
+ * @param {string} value - Value to check
37
+ * @returns {boolean} True if matches secret pattern
38
+ */
39
+ export function matchesSecretPattern(value: string): boolean;
40
+ /**
41
+ * Sensitive field names that should be redacted
42
+ */
43
+ export const SENSITIVE_FIELD_NAMES: Set<string>;
44
+ /**
45
+ * Patterns that match secret-like values
46
+ */
47
+ export const SECRET_PATTERNS: RegExp[];
48
+ /**
49
+ * Redaction marker
50
+ */
51
+ export const REDACTED: "[REDACTED]";