@devilsdev/rag-pipeline-utils 2.3.1 → 2.4.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/README.md +293 -369
- package/contracts/loader-contract.json +11 -6
- package/contracts/reranker-contract.json +18 -26
- package/dist/index.cjs +21190 -47
- package/dist/index.d.ts +298 -68
- package/dist/index.mjs +9 -76
- package/package.json +20 -8
- package/src/agentic/agentic-pipeline.js +235 -0
- package/src/agentic/iterative-retriever.js +213 -0
- package/src/agentic/query-planner.js +208 -0
- package/src/agentic/self-critique.js +102 -0
- package/src/ai/adaptive-retrieval.js +0 -3
- package/src/ai/federated-learning.js +0 -3
- package/src/ai/federation.js +1 -6
- package/src/ai/index.js +9 -20
- package/src/ai/model-training.js +0 -3
- package/src/ai/multimodal-processing.js +0 -3
- package/src/ai/multimodal.js +1 -6
- package/src/ai/orchestrator.js +1 -6
- package/src/ai/retrieval-engine.js +1 -6
- package/src/chunking/chunking-engine.js +142 -0
- package/src/chunking/strategies/fixed-size.js +54 -0
- package/src/chunking/strategies/recursive.js +127 -0
- package/src/chunking/strategies/semantic.js +128 -0
- package/src/chunking/strategies/sentence.js +32 -0
- package/src/chunking/strategies/structure-aware.js +138 -0
- package/src/citation/citation-tracker.js +161 -0
- package/src/citation/hallucination-detector.js +74 -0
- package/src/citation/source-mapper.js +95 -0
- package/src/cli/commands/ai-ml/adaptive-commands.js +178 -0
- package/src/cli/commands/ai-ml/federated-commands.js +207 -0
- package/src/cli/commands/ai-ml/index.js +17 -0
- package/src/cli/commands/ai-ml/multimodal-commands.js +187 -0
- package/src/cli/commands/ai-ml/shared.js +51 -0
- package/src/cli/commands/ai-ml/training-commands.js +228 -0
- package/src/cli/commands/ai-ml.js +176 -757
- package/src/cli/commands/plugin-hub/certification-commands.js +221 -0
- package/src/cli/commands/plugin-hub/event-handlers.js +64 -0
- package/src/cli/commands/plugin-hub/hub-commands.js +290 -0
- package/src/cli/commands/plugin-hub/review-commands.js +78 -0
- package/src/cli/commands/plugin-hub.js +106 -782
- package/src/cli/diagnostics/config-checker.js +81 -0
- package/src/cli/diagnostics/dependency-checker.js +69 -0
- package/src/cli/diagnostics/environment-checker.js +45 -0
- package/src/cli/diagnostics/performance-checker.js +51 -0
- package/src/cli/diagnostics/plugin-checker.js +106 -0
- package/src/cli/diagnostics/security-checker.js +61 -0
- package/src/cli/doctor-command.js +70 -369
- package/src/cli/enhanced-cli-commands.js +162 -706
- package/src/cli/handlers/config-handler.js +126 -0
- package/src/cli/handlers/diagnostics-handler.js +113 -0
- package/src/cli/handlers/ingest-handler.js +42 -0
- package/src/cli/handlers/init-handler.js +51 -0
- package/src/cli/handlers/query-handler.js +45 -0
- package/src/cli/handlers/run-handler.js +181 -0
- package/src/cli/interactive-wizard.js +99 -723
- package/src/cli/shared/cli-utils.js +89 -0
- package/src/cli/wizard/configuration.js +148 -0
- package/src/cli/wizard/observability.js +79 -0
- package/src/cli/wizard/performance.js +76 -0
- package/src/cli/wizard/plugin-selection.js +297 -0
- package/src/cli/wizard/preview-save.js +172 -0
- package/src/cli/wizard/project-setup.js +66 -0
- package/src/config/memory-optimization.js +3 -3
- package/src/connectors/anthropic-connector.js +179 -0
- package/src/connectors/base-connector.js +94 -0
- package/src/connectors/cohere-connector.js +143 -0
- package/src/connectors/local-embedder.js +171 -0
- package/src/connectors/memory-retriever.js +150 -0
- package/src/connectors/ollama-connector.js +205 -0
- package/src/connectors/openai-connector.js +173 -0
- package/src/core/create-pipeline.js +21 -1
- package/src/core/observability/tracing.js +2 -1
- package/src/core/pipeline-factory.js +0 -1
- package/src/core/plugin-registry.js +14 -14
- package/src/cost/cost-calculator.js +146 -0
- package/src/cost/cost-tracker.js +260 -0
- package/src/cost/token-budget.js +245 -0
- package/src/dag/core/execution-scheduler.js +2 -1
- package/src/dag/core/topology-validation.js +0 -3
- package/src/dag/dag-engine.js +3 -5
- package/src/dag/dag-node.js +0 -1
- package/src/dag/enhanced-dag-engine.js +171 -99
- package/src/dashboard/dashboard-generator.js +642 -0
- package/src/dashboard/metrics-aggregator.js +409 -0
- package/src/debug/execution-tracer.js +210 -0
- package/src/debug/trace-inspector.js +281 -0
- package/src/dev/dev-server.js +5 -5
- package/src/dev/hot-reload.js +3 -2
- package/src/dx/integration-templates.js +0 -3
- package/src/ecosystem/plugin-analytics-dashboard.js +2 -2
- package/src/ecosystem/plugin-hub.js +2 -2
- package/src/enterprise/audit-logging.js +2 -2
- package/src/enterprise/sso-integration.js +52 -32
- package/src/evaluate/context-metrics.js +127 -0
- package/src/evaluate/evaluator.js +4 -2
- package/src/evaluate/faithfulness.js +117 -0
- package/src/evaluate/groundedness.js +60 -0
- package/src/evaluate/pipeline-evaluator.js +156 -0
- package/src/evaluate/relevance.js +129 -0
- package/src/evaluate/scoring.js +27 -0
- package/src/graph/entity-extractor.js +183 -0
- package/src/graph/graph-index.js +113 -0
- package/src/graph/graph-retriever.js +244 -0
- package/src/graph/knowledge-graph.js +256 -0
- package/src/guardrails/guardrails-pipeline.js +136 -0
- package/src/guardrails/post-generation-guard.js +170 -0
- package/src/guardrails/pre-retrieval-guard.js +161 -0
- package/src/guardrails/retrieval-guard.js +126 -0
- package/src/index.js +255 -9
- package/src/loader/html-loader.js +4 -15
- package/src/loader/markdown-loader.js +4 -15
- package/src/mcp/mcp-server.js +199 -0
- package/src/mcp/mcp-tool-builder.js +121 -0
- package/src/observability/audit-logger.js +0 -2
- package/src/observability/event-logger.js +2 -1
- package/src/observability/security-monitor.js +0 -2
- package/src/observability/telemetry.js +0 -2
- package/src/reranker/cascade-reranker.js +79 -0
- package/src/reranker/embedding-reranker.js +124 -0
- package/src/reranker/llm-reranker.js +6 -3
- package/src/reranker/scoring-reranker.js +123 -0
- package/src/retrieval/bm25-search.js +157 -0
- package/src/retrieval/hybrid-retriever.js +111 -0
- package/src/retrieval/rank-fusion.js +62 -0
- package/src/security/jwt-config.js +4 -3
- package/src/security/jwt-validator.js +2 -1
- package/src/security/plugin-sandbox.js +0 -3
- package/src/security/plugin-signature-verifier.js +4 -6
- package/src/security/validator.js +0 -2
- package/src/streaming/embedding-stream.js +197 -0
- package/src/streaming/sse-adapter.js +168 -0
- package/src/streaming/stream-router.js +210 -0
- package/src/streaming/streaming-embedder.js +231 -0
- package/src/streaming/websocket-adapter.js +171 -0
- package/src/templates/scaffold.js +147 -0
- package/src/templates/template-registry.js +272 -0
- package/src/utils/contract-validator.js +2 -1
- package/src/utils/input-sanitizer.js +80 -99
- package/src/utils/performance-monitor.js +0 -3
- package/src/utils/plugin-scaffolder.js +9 -16
- package/src/utils/rate-limiter.js +0 -1
- package/src/utils/retry-policy.js +0 -3
- package/src/utils/safe-expression-evaluator.js +0 -3
- package/src/utils/secure-logger-config.js +2 -4
- package/src/utils/secure-logging.js +0 -3
- package/src/utils/structured-logger.js +0 -3
- package/src/ai/index-fixed.js +0 -509
- package/src/ai/module-template.js +0 -37
- package/src/ci/workflow-analyzer.js +0 -71
- package/src/cli/plugin-marketplace-commands.js +0 -869
- package/src/dev/README.md +0 -126
- package/src/dev/examples/hot-reload-usage.js +0 -355
- package/src/mocks/openai-embedder.js +0 -119
- package/src/mocks/openai-llm.js +0 -77
- package/src/mocks/pdf-loader.js +0 -21
- package/src/mocks/pinecone-retriever.js +0 -106
- package/src/scripts/script-utilities.js +0 -36
- package/src/utils/ci/diagnostic-reporter.js +0 -57
- package/src/utils/examples/error-formatter-usage.js +0 -351
package/src/dev/README.md
DELETED
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
# Development Tools
|
|
2
|
-
|
|
3
|
-
This directory contains development tools for the RAG Pipeline Utils library.
|
|
4
|
-
|
|
5
|
-
## Available Tools
|
|
6
|
-
|
|
7
|
-
### Hot Reload Manager (`hot-reload.js`)
|
|
8
|
-
|
|
9
|
-
Provides automatic reloading of plugins and configuration files during development.
|
|
10
|
-
|
|
11
|
-
**Features:**
|
|
12
|
-
|
|
13
|
-
- File watching with chokidar
|
|
14
|
-
- Plugin hot-reloading with module cache clearing
|
|
15
|
-
- Configuration hot-reloading with validation
|
|
16
|
-
- State preservation and restoration
|
|
17
|
-
- Lifecycle hooks (beforeReload, afterReload, onError, etc.)
|
|
18
|
-
- Statistics tracking and history
|
|
19
|
-
- Error handling with notifications
|
|
20
|
-
|
|
21
|
-
**Usage:**
|
|
22
|
-
|
|
23
|
-
```javascript
|
|
24
|
-
const { createHotReloadManager } = require("./hot-reload");
|
|
25
|
-
|
|
26
|
-
const hotReload = createHotReloadManager({
|
|
27
|
-
watchPaths: ["./src/plugins"],
|
|
28
|
-
configPath: ".ragrc.json",
|
|
29
|
-
verbose: true,
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
await hotReload.start();
|
|
33
|
-
```
|
|
34
|
-
|
|
35
|
-
### Development Server (`dev-server.js`)
|
|
36
|
-
|
|
37
|
-
Integrated development server with hot reload support.
|
|
38
|
-
|
|
39
|
-
**Features:**
|
|
40
|
-
|
|
41
|
-
- Hot reload integration
|
|
42
|
-
- Real-time notifications
|
|
43
|
-
- Statistics dashboard
|
|
44
|
-
- Event-driven architecture
|
|
45
|
-
- Graceful shutdown
|
|
46
|
-
- Pipeline integration
|
|
47
|
-
|
|
48
|
-
**Usage:**
|
|
49
|
-
|
|
50
|
-
```javascript
|
|
51
|
-
const { createDevServer } = require("./dev-server");
|
|
52
|
-
|
|
53
|
-
const devServer = createDevServer({
|
|
54
|
-
port: 3000,
|
|
55
|
-
watchPaths: ["./src/plugins"],
|
|
56
|
-
autoReload: true,
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
await devServer.start();
|
|
60
|
-
```
|
|
61
|
-
|
|
62
|
-
## Examples
|
|
63
|
-
|
|
64
|
-
See `examples/hot-reload-usage.js` for comprehensive examples including:
|
|
65
|
-
|
|
66
|
-
1. Basic hot reload setup
|
|
67
|
-
2. Integration with plugin registry
|
|
68
|
-
3. Development server usage
|
|
69
|
-
4. Pipeline integration
|
|
70
|
-
5. Custom state preservation
|
|
71
|
-
6. Manual reload triggering
|
|
72
|
-
7. Configuration validation
|
|
73
|
-
8. Complete development workflows
|
|
74
|
-
|
|
75
|
-
## Documentation
|
|
76
|
-
|
|
77
|
-
Full documentation is available at `docs/hot-reload.md`.
|
|
78
|
-
|
|
79
|
-
## Testing
|
|
80
|
-
|
|
81
|
-
Tests are located in `__tests__/dev/hot-reload.test.js`.
|
|
82
|
-
|
|
83
|
-
Run tests:
|
|
84
|
-
|
|
85
|
-
```bash
|
|
86
|
-
npm test -- __tests__/dev/hot-reload.test.js
|
|
87
|
-
```
|
|
88
|
-
|
|
89
|
-
## API Reference
|
|
90
|
-
|
|
91
|
-
### Hot Reload Manager
|
|
92
|
-
|
|
93
|
-
- `start()` - Start watching for changes
|
|
94
|
-
- `stop()` - Stop watching
|
|
95
|
-
- `triggerReload(filePath, type)` - Manually trigger reload
|
|
96
|
-
- `registerHook(hookName, callback)` - Register lifecycle hook
|
|
97
|
-
- `getStats()` - Get reload statistics
|
|
98
|
-
- `getHistory()` - Get reload history
|
|
99
|
-
|
|
100
|
-
### Development Server
|
|
101
|
-
|
|
102
|
-
- `start()` - Start dev server
|
|
103
|
-
- `stop()` - Stop dev server
|
|
104
|
-
- `getStatus()` - Get server status
|
|
105
|
-
- `getStatistics()` - Get formatted statistics
|
|
106
|
-
- `triggerReload(filePath, type)` - Manually trigger reload
|
|
107
|
-
- `registerHook(hookName, callback)` - Register lifecycle hook
|
|
108
|
-
|
|
109
|
-
## Events
|
|
110
|
-
|
|
111
|
-
Both tools emit various events:
|
|
112
|
-
|
|
113
|
-
- `started` / `stopped`
|
|
114
|
-
- `plugin:reloaded` / `plugin:reload-failed`
|
|
115
|
-
- `config:reloaded` / `config:reload-failed`
|
|
116
|
-
- `plugin:added` / `plugin:removed`
|
|
117
|
-
- `error`
|
|
118
|
-
- `notification` (DevServer only)
|
|
119
|
-
|
|
120
|
-
## Dependencies
|
|
121
|
-
|
|
122
|
-
- `chokidar` - File system watching
|
|
123
|
-
|
|
124
|
-
## License
|
|
125
|
-
|
|
126
|
-
GPL-3.0
|
|
@@ -1,355 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Hot Reload Usage Examples
|
|
5
|
-
*
|
|
6
|
-
* This file demonstrates various ways to use the hot reload functionality
|
|
7
|
-
* in development environments.
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
const { createHotReloadManager } = require('../hot-reload');
|
|
11
|
-
const { createDevServer } = require('../dev-server');
|
|
12
|
-
const { createRagPipeline } = require('../../core/create-pipeline');
|
|
13
|
-
const pluginRegistry = require('../../core/plugin-registry');
|
|
14
|
-
|
|
15
|
-
// ============================================================================
|
|
16
|
-
// Example 1: Basic Hot Reload Setup
|
|
17
|
-
// ============================================================================
|
|
18
|
-
|
|
19
|
-
function basicHotReloadExample() {
|
|
20
|
-
console.log('\n=== Example 1: Basic Hot Reload ===\n');
|
|
21
|
-
|
|
22
|
-
// Create hot reload manager
|
|
23
|
-
const hotReload = createHotReloadManager({
|
|
24
|
-
enabled: true,
|
|
25
|
-
watchPaths: ['./src/plugins', './src/mocks'],
|
|
26
|
-
configPath: '.ragrc.json',
|
|
27
|
-
verbose: true,
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
// Listen to events
|
|
31
|
-
hotReload.on('plugin:reloaded', ({ path, duration }) => {
|
|
32
|
-
console.log(`Plugin reloaded: ${path} in ${duration}ms`);
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
hotReload.on('config:reloaded', ({ config }) => {
|
|
36
|
-
console.log('Configuration reloaded:', config.metadata?.name);
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
// Start watching
|
|
40
|
-
hotReload.start().then(() => {
|
|
41
|
-
console.log('Hot reload started');
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
// To stop:
|
|
45
|
-
// hotReload.stop();
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
// ============================================================================
|
|
49
|
-
// Example 2: Hot Reload with Plugin Registry Integration
|
|
50
|
-
// ============================================================================
|
|
51
|
-
|
|
52
|
-
async function hotReloadWithRegistryExample() {
|
|
53
|
-
console.log('\n=== Example 2: Hot Reload with Plugin Registry ===\n');
|
|
54
|
-
|
|
55
|
-
// Create hot reload manager with plugin registry
|
|
56
|
-
const hotReload = createHotReloadManager({
|
|
57
|
-
enabled: true,
|
|
58
|
-
watchPaths: ['./src/plugins'],
|
|
59
|
-
pluginRegistry: pluginRegistry,
|
|
60
|
-
verbose: true,
|
|
61
|
-
preserveState: true, // Preserve plugin state during reloads
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
// Register hooks for advanced control
|
|
65
|
-
hotReload.registerHook('beforeReload', async (data) => {
|
|
66
|
-
console.log(`About to reload ${data.type}: ${data.path}`);
|
|
67
|
-
// Perform any cleanup or preparation
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
hotReload.registerHook('afterReload', async (data) => {
|
|
71
|
-
console.log(`Reload completed for ${data.type}: ${data.path}`);
|
|
72
|
-
// Re-register with plugin registry, update references, etc.
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
hotReload.registerHook('onError', async ({ message, error }) => {
|
|
76
|
-
console.error(`Reload error: ${message}`, error);
|
|
77
|
-
// Send notification, log to service, etc.
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
await hotReload.start();
|
|
81
|
-
|
|
82
|
-
// Get statistics
|
|
83
|
-
setInterval(() => {
|
|
84
|
-
const stats = hotReload.getStats();
|
|
85
|
-
console.log('Reload Stats:', {
|
|
86
|
-
total: stats.totalReloads,
|
|
87
|
-
successful: stats.successfulReloads,
|
|
88
|
-
failed: stats.failedReloads,
|
|
89
|
-
avgTime: Math.round(stats.averageReloadTime) + 'ms',
|
|
90
|
-
});
|
|
91
|
-
}, 60000); // Every minute
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
// ============================================================================
|
|
95
|
-
// Example 3: Development Server with Hot Reload
|
|
96
|
-
// ============================================================================
|
|
97
|
-
|
|
98
|
-
async function devServerExample() {
|
|
99
|
-
console.log('\n=== Example 3: Development Server ===\n');
|
|
100
|
-
|
|
101
|
-
// Create development server with integrated hot reload
|
|
102
|
-
const devServer = createDevServer({
|
|
103
|
-
port: 3000,
|
|
104
|
-
host: 'localhost',
|
|
105
|
-
watchPaths: ['./src/plugins', './src/mocks'],
|
|
106
|
-
configPath: '.ragrc.json',
|
|
107
|
-
verbose: true,
|
|
108
|
-
autoReload: true,
|
|
109
|
-
notifyOnReload: true,
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
// Listen to server events
|
|
113
|
-
devServer.on('started', () => {
|
|
114
|
-
console.log('Development server started');
|
|
115
|
-
console.log(devServer.getStatistics());
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
devServer.on('plugin:reloaded', ({ path, duration }) => {
|
|
119
|
-
console.log(`✓ Plugin reloaded: ${path} (${duration}ms)`);
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
devServer.on('config:reloaded', ({ path, duration }) => {
|
|
123
|
-
console.log(`✓ Config reloaded: ${path} (${duration}ms)`);
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
devServer.on('notification', ({ message, type }) => {
|
|
127
|
-
console.log(`[${type.toUpperCase()}] ${message}`);
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
// Start the server
|
|
131
|
-
await devServer.start();
|
|
132
|
-
|
|
133
|
-
// Display statistics periodically
|
|
134
|
-
setInterval(() => {
|
|
135
|
-
console.log(devServer.getStatistics());
|
|
136
|
-
}, 300000); // Every 5 minutes
|
|
137
|
-
|
|
138
|
-
// Handle graceful shutdown
|
|
139
|
-
process.on('SIGINT', async () => {
|
|
140
|
-
console.log('\nShutting down...');
|
|
141
|
-
await devServer.stop();
|
|
142
|
-
process.exit(0);
|
|
143
|
-
});
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
// ============================================================================
|
|
147
|
-
// Example 4: Hot Reload with RAG Pipeline
|
|
148
|
-
// ============================================================================
|
|
149
|
-
|
|
150
|
-
async function hotReloadWithPipelineExample() {
|
|
151
|
-
console.log('\n=== Example 4: Hot Reload with Pipeline ===\n');
|
|
152
|
-
|
|
153
|
-
// Create pipeline
|
|
154
|
-
const pipeline = await createRagPipeline({
|
|
155
|
-
configPath: '.ragrc.json',
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
// Create dev server with pipeline integration
|
|
159
|
-
const devServer = createDevServer({
|
|
160
|
-
watchPaths: ['./src/plugins', './src/mocks'],
|
|
161
|
-
configPath: '.ragrc.json',
|
|
162
|
-
verbose: true,
|
|
163
|
-
pluginRegistry: pluginRegistry,
|
|
164
|
-
pipeline: pipeline,
|
|
165
|
-
});
|
|
166
|
-
|
|
167
|
-
// When config changes, pipeline will be reinitialized automatically
|
|
168
|
-
devServer.on('config:reloaded', async () => {
|
|
169
|
-
console.log('Pipeline configuration updated');
|
|
170
|
-
// Pipeline is automatically reinitialized by dev server
|
|
171
|
-
});
|
|
172
|
-
|
|
173
|
-
// When plugins change, they're hot-reloaded
|
|
174
|
-
devServer.on('plugin:reloaded', async ({ path }) => {
|
|
175
|
-
console.log(`Plugin ${path} updated and reloaded`);
|
|
176
|
-
// Plugin is automatically updated in registry
|
|
177
|
-
});
|
|
178
|
-
|
|
179
|
-
await devServer.start();
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
// ============================================================================
|
|
183
|
-
// Example 5: Custom State Preservation
|
|
184
|
-
// ============================================================================
|
|
185
|
-
|
|
186
|
-
async function customStatePreservationExample() {
|
|
187
|
-
console.log('\n=== Example 5: Custom State Preservation ===\n');
|
|
188
|
-
|
|
189
|
-
const hotReload = createHotReloadManager({
|
|
190
|
-
enabled: true,
|
|
191
|
-
watchPaths: ['./src/plugins'],
|
|
192
|
-
preserveState: true,
|
|
193
|
-
verbose: true,
|
|
194
|
-
});
|
|
195
|
-
|
|
196
|
-
// Hook into state preservation
|
|
197
|
-
hotReload.registerHook('onStatePreserve', async ({ path, state }) => {
|
|
198
|
-
console.log(`Preserving state for ${path}:`, state);
|
|
199
|
-
// You can save state to external storage here
|
|
200
|
-
});
|
|
201
|
-
|
|
202
|
-
hotReload.registerHook('onStateRestore', async ({ plugin, state }) => {
|
|
203
|
-
console.log('Restoring state:', state);
|
|
204
|
-
// You can restore state from external storage here
|
|
205
|
-
});
|
|
206
|
-
|
|
207
|
-
await hotReload.start();
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
// ============================================================================
|
|
211
|
-
// Example 6: Manual Reload Triggering
|
|
212
|
-
// ============================================================================
|
|
213
|
-
|
|
214
|
-
async function manualReloadExample() {
|
|
215
|
-
console.log('\n=== Example 6: Manual Reload ===\n');
|
|
216
|
-
|
|
217
|
-
const devServer = createDevServer({
|
|
218
|
-
watchPaths: ['./src/plugins'],
|
|
219
|
-
autoReload: false, // Disable automatic reloading
|
|
220
|
-
verbose: true,
|
|
221
|
-
});
|
|
222
|
-
|
|
223
|
-
await devServer.start();
|
|
224
|
-
|
|
225
|
-
// Manually trigger reloads
|
|
226
|
-
await devServer.triggerReload('./src/plugins/my-plugin.js', 'plugin');
|
|
227
|
-
await devServer.triggerReload('.ragrc.json', 'config');
|
|
228
|
-
|
|
229
|
-
console.log('Manual reloads completed');
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
// ============================================================================
|
|
233
|
-
// Example 7: Configuration Validation
|
|
234
|
-
// ============================================================================
|
|
235
|
-
|
|
236
|
-
async function configValidationExample() {
|
|
237
|
-
console.log('\n=== Example 7: Config Validation ===\n');
|
|
238
|
-
|
|
239
|
-
const hotReload = createHotReloadManager({
|
|
240
|
-
enabled: true,
|
|
241
|
-
configPath: '.ragrc.json',
|
|
242
|
-
verbose: true,
|
|
243
|
-
// Custom config validator
|
|
244
|
-
configValidator: (config) => {
|
|
245
|
-
const errors = [];
|
|
246
|
-
|
|
247
|
-
// Validate required fields
|
|
248
|
-
if (!config.metadata || !config.metadata.name) {
|
|
249
|
-
errors.push({ message: 'metadata.name is required' });
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
if (!config.pipeline || !config.pipeline.stages) {
|
|
253
|
-
errors.push({ message: 'pipeline.stages is required' });
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
return {
|
|
257
|
-
valid: errors.length === 0,
|
|
258
|
-
errors,
|
|
259
|
-
};
|
|
260
|
-
},
|
|
261
|
-
});
|
|
262
|
-
|
|
263
|
-
hotReload.on('config:reload-failed', ({ error }) => {
|
|
264
|
-
console.error('Configuration validation failed:', error);
|
|
265
|
-
});
|
|
266
|
-
|
|
267
|
-
await hotReload.start();
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
// ============================================================================
|
|
271
|
-
// Example 8: Development Workflow Integration
|
|
272
|
-
// ============================================================================
|
|
273
|
-
|
|
274
|
-
async function developmentWorkflowExample() {
|
|
275
|
-
console.log('\n=== Example 8: Complete Development Workflow ===\n');
|
|
276
|
-
|
|
277
|
-
// Create a complete development environment
|
|
278
|
-
const devServer = createDevServer({
|
|
279
|
-
port: 3000,
|
|
280
|
-
host: 'localhost',
|
|
281
|
-
watchPaths: ['./src/plugins', './src/mocks', './src/config'],
|
|
282
|
-
configPath: '.ragrc.json',
|
|
283
|
-
verbose: true,
|
|
284
|
-
autoReload: true,
|
|
285
|
-
notifyOnReload: true,
|
|
286
|
-
pluginRegistry: pluginRegistry,
|
|
287
|
-
});
|
|
288
|
-
|
|
289
|
-
// Add custom hooks
|
|
290
|
-
devServer.registerHook('beforeReload', async (data) => {
|
|
291
|
-
console.log(`[BEFORE] Reloading ${data.type}: ${data.path}`);
|
|
292
|
-
// Run pre-reload tasks (tests, linting, etc.)
|
|
293
|
-
});
|
|
294
|
-
|
|
295
|
-
devServer.registerHook('afterReload', async (data) => {
|
|
296
|
-
console.log(`[AFTER] Reloaded ${data.type}: ${data.path}`);
|
|
297
|
-
// Run post-reload tasks (smoke tests, notifications, etc.)
|
|
298
|
-
});
|
|
299
|
-
|
|
300
|
-
// Start server
|
|
301
|
-
await devServer.start();
|
|
302
|
-
|
|
303
|
-
// Log status every 5 minutes
|
|
304
|
-
setInterval(() => {
|
|
305
|
-
const status = devServer.getStatus();
|
|
306
|
-
console.log('\n=== Server Status ===');
|
|
307
|
-
console.log(`Uptime: ${Math.floor(status.uptime / 1000)}s`);
|
|
308
|
-
console.log(`Total Reloads: ${status.hotReload.stats.totalReloads}`);
|
|
309
|
-
console.log(
|
|
310
|
-
`Success Rate: ${
|
|
311
|
-
status.hotReload.stats.totalReloads > 0
|
|
312
|
-
? Math.round(
|
|
313
|
-
(status.hotReload.stats.successfulReloads /
|
|
314
|
-
status.hotReload.stats.totalReloads) *
|
|
315
|
-
100,
|
|
316
|
-
) + '%'
|
|
317
|
-
: 'N/A'
|
|
318
|
-
}`,
|
|
319
|
-
);
|
|
320
|
-
}, 300000);
|
|
321
|
-
|
|
322
|
-
// Handle shutdown
|
|
323
|
-
process.on('SIGINT', async () => {
|
|
324
|
-
console.log('\n\nShutting down development server...');
|
|
325
|
-
console.log(devServer.getStatistics());
|
|
326
|
-
await devServer.stop();
|
|
327
|
-
process.exit(0);
|
|
328
|
-
});
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
// ============================================================================
|
|
332
|
-
// Run Examples
|
|
333
|
-
// ============================================================================
|
|
334
|
-
|
|
335
|
-
// Uncomment the example you want to run:
|
|
336
|
-
|
|
337
|
-
// basicHotReloadExample();
|
|
338
|
-
// hotReloadWithRegistryExample();
|
|
339
|
-
// devServerExample();
|
|
340
|
-
// hotReloadWithPipelineExample();
|
|
341
|
-
// customStatePreservationExample();
|
|
342
|
-
// manualReloadExample();
|
|
343
|
-
// configValidationExample();
|
|
344
|
-
// developmentWorkflowExample();
|
|
345
|
-
|
|
346
|
-
module.exports = {
|
|
347
|
-
basicHotReloadExample,
|
|
348
|
-
hotReloadWithRegistryExample,
|
|
349
|
-
devServerExample,
|
|
350
|
-
hotReloadWithPipelineExample,
|
|
351
|
-
customStatePreservationExample,
|
|
352
|
-
manualReloadExample,
|
|
353
|
-
configValidationExample,
|
|
354
|
-
developmentWorkflowExample,
|
|
355
|
-
};
|
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Version: 2.0.0
|
|
3
|
-
* Description: Mock implementation of OpenAI embedder for testing and development
|
|
4
|
-
* Author: Ali Kahwaji
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
class OpenAIEmbedder {
|
|
8
|
-
constructor(_options = {}) {
|
|
9
|
-
this.apiKey = _options.apiKey || "mock-api-key";
|
|
10
|
-
this.model = _options.model || "text-embedding-ada-002";
|
|
11
|
-
this.dimensions = _options.dimensions || 1536;
|
|
12
|
-
this.options = _options;
|
|
13
|
-
|
|
14
|
-
// Configurable batch size from environment or options
|
|
15
|
-
this.batchSize =
|
|
16
|
-
parseInt(process.env.RAG_EMBEDDER_BATCH_SIZE) ||
|
|
17
|
-
_options.batchSize ||
|
|
18
|
-
100; // Default batch size for OpenAI API
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Generate embeddings for an array of text chunks
|
|
23
|
-
* @param {string[]} chunks - Array of text chunks to embed
|
|
24
|
-
* @returns {Promise<number[][]>} Array of embedding vectors
|
|
25
|
-
*/
|
|
26
|
-
async embed(chunks) {
|
|
27
|
-
if (!Array.isArray(chunks)) {
|
|
28
|
-
throw new Error("embed() expects an array of strings");
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
// Process in batches for better memory management and API rate limiting
|
|
32
|
-
const results = [];
|
|
33
|
-
for (let i = 0; i < chunks.length; i += this.batchSize) {
|
|
34
|
-
const batch = chunks.slice(i, i + this.batchSize);
|
|
35
|
-
const batchResults = await this._processBatch(batch);
|
|
36
|
-
results.push(...batchResults);
|
|
37
|
-
|
|
38
|
-
// Optional progress callback
|
|
39
|
-
if (this.options.onProgress) {
|
|
40
|
-
this.options.onProgress({
|
|
41
|
-
processed: Math.min(i + this.batchSize, chunks.length),
|
|
42
|
-
total: chunks.length,
|
|
43
|
-
stage: "embedding",
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
// Simulate API rate limiting delay
|
|
48
|
-
if (chunks.length > this.batchSize) {
|
|
49
|
-
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
return results;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Process a batch of chunks
|
|
58
|
-
* @private
|
|
59
|
-
* @param {string[]} batch - Batch of text chunks
|
|
60
|
-
* @returns {Promise<number[][]>} Array of embedding vectors
|
|
61
|
-
*/
|
|
62
|
-
async _processBatch(batch) {
|
|
63
|
-
// Return mock embeddings - deterministic based on content for testing
|
|
64
|
-
return batch.map((chunk) => this.#generateMockEmbedding(chunk));
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* Generate embedding for a single query string
|
|
69
|
-
* @param {string} query - Query string to embed
|
|
70
|
-
* @returns {Promise<number[]>} Embedding vector
|
|
71
|
-
*/
|
|
72
|
-
async embedQuery(query) {
|
|
73
|
-
if (typeof query !== "string") {
|
|
74
|
-
throw new Error("embedQuery() expects a string");
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
return this.#generateMockEmbedding(query);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* Generate a deterministic mock embedding based on input text
|
|
82
|
-
* @private
|
|
83
|
-
* @param {string} text - Input text
|
|
84
|
-
* @returns {number[]} Mock embedding vector
|
|
85
|
-
*/
|
|
86
|
-
#generateMockEmbedding(text) {
|
|
87
|
-
// Create deterministic "embedding" based on text content
|
|
88
|
-
const hash = this.#simpleHash(text);
|
|
89
|
-
const embedding = [];
|
|
90
|
-
|
|
91
|
-
for (let i = 0; i < this.dimensions; i++) {
|
|
92
|
-
// Generate pseudo-random values based on hash and index
|
|
93
|
-
const value = Math.sin(hash + i) * 0.5;
|
|
94
|
-
embedding.push(value);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
return embedding;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* Simple hash function for deterministic mock data
|
|
102
|
-
* @private
|
|
103
|
-
* @param {string} str - Input string
|
|
104
|
-
* @returns {number} Hash value
|
|
105
|
-
*/
|
|
106
|
-
#simpleHash(str) {
|
|
107
|
-
let hash = 0;
|
|
108
|
-
for (let i = 0; i < str.length; i++) {
|
|
109
|
-
const char = str.charCodeAt(i);
|
|
110
|
-
hash = (hash << 5) - hash + char;
|
|
111
|
-
hash = hash & hash; // Convert to 32-bit integer
|
|
112
|
-
}
|
|
113
|
-
return hash;
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
module.exports = {
|
|
118
|
-
OpenAIEmbedder,
|
|
119
|
-
};
|
package/src/mocks/openai-llm.js
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Version: 2.0.0
|
|
3
|
-
* File: /src/mocks/openai-llm.js
|
|
4
|
-
* Description: Mock implementation of an OpenAI LLM with streaming support
|
|
5
|
-
* Author: Ali Kahwaji
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
class OpenAILLM {
|
|
9
|
-
constructor(_options = {}) {
|
|
10
|
-
this.streamDelay = _options.streamDelay || 50; // ms between tokens
|
|
11
|
-
this.model = _options.model || "gpt-3.5-turbo";
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Generates a complete response from input prompt and context
|
|
16
|
-
* @param {string} prompt
|
|
17
|
-
* @param {Array<{ text: string }>} context
|
|
18
|
-
* @returns {Promise<string>}
|
|
19
|
-
*/
|
|
20
|
-
async generate(prompt, context) {
|
|
21
|
-
const contextText = Array.isArray(context)
|
|
22
|
-
? context.map((d) => d.text || d).join(", ")
|
|
23
|
-
: "";
|
|
24
|
-
return `Generated answer using context: ${contextText}. Query: "${prompt}". This is a comprehensive response that addresses the user's question based on the retrieved information.`;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Generates a streaming response token-by-token
|
|
29
|
-
* @param {string} prompt
|
|
30
|
-
* @param {Array<{ text: string }>} context
|
|
31
|
-
* @returns {AsyncIterable<string>} Stream of tokens
|
|
32
|
-
*/
|
|
33
|
-
async *generateStream(prompt, context) {
|
|
34
|
-
const fullResponse = await this.generate(prompt, context);
|
|
35
|
-
const tokens = this.#tokenize(fullResponse);
|
|
36
|
-
|
|
37
|
-
for (const token of tokens) {
|
|
38
|
-
// Simulate network delay between tokens
|
|
39
|
-
await this.#delay(this.streamDelay);
|
|
40
|
-
yield token;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Simple tokenization for mock streaming
|
|
46
|
-
* @private
|
|
47
|
-
* @param {string} text - Text to tokenize
|
|
48
|
-
* @returns {string[]} Array of tokens
|
|
49
|
-
*/
|
|
50
|
-
#tokenize(text) {
|
|
51
|
-
// Simple word-based tokenization for demo purposes
|
|
52
|
-
// In real implementation, this would use proper tokenization
|
|
53
|
-
return text.split(/\s+/).map((word) => word + " ");
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Utility delay function for simulating streaming
|
|
58
|
-
* @private
|
|
59
|
-
* @param {number} ms - Milliseconds to delay
|
|
60
|
-
* @returns {Promise<void>}
|
|
61
|
-
*/
|
|
62
|
-
#delay(ms) {
|
|
63
|
-
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* Check if this LLM _instance supports streaming
|
|
68
|
-
* @returns {boolean}
|
|
69
|
-
*/
|
|
70
|
-
supportsStreaming() {
|
|
71
|
-
return true;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
// Default export
|
|
76
|
-
|
|
77
|
-
module.exports = OpenAILLM;
|
package/src/mocks/pdf-loader.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Version: 0.1.0
|
|
3
|
-
* File: /src/mocks/pdf-loader.js
|
|
4
|
-
* Description: Mock implementation of a PDF document loader
|
|
5
|
-
* Author: Ali Kahwaji
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
class PDFLoader {
|
|
9
|
-
/**
|
|
10
|
-
* Loads a mock PDF file and returns an array of chunked content.
|
|
11
|
-
* @param {string} _filePath - Path to the PDF file
|
|
12
|
-
* @returns {Promise<Array<{ chunk: () => string[] }>>}
|
|
13
|
-
*/
|
|
14
|
-
async load(_filePath) {
|
|
15
|
-
return [{ chunk: () => [`Test loaded: ${_filePath}`] }];
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
// Default export
|
|
20
|
-
|
|
21
|
-
module.exports = PDFLoader;
|