@devilsdev/rag-pipeline-utils 2.1.12 → 2.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.ragrc.schema.json +218 -0
- package/README.md +178 -550
- package/bin/cli.js +8 -14
- package/contracts/reranker-contract.json +69 -0
- package/dist/index.d.ts +237 -0
- package/dist/index.mjs +22 -7
- package/package.json +18 -13
- package/src/ai/adaptive-retrieval.js +191 -0
- package/src/ai/federated-learning.js +214 -0
- package/src/ai/federation/federated-learning-coordinator.js +345 -0
- package/src/ai/federation.js +76 -0
- package/src/ai/index-fixed.js +509 -0
- package/src/ai/index.js +33 -0
- package/src/ai/model-trainer.js +217 -0
- package/src/ai/model-training.js +205 -0
- package/src/ai/module-template.js +37 -0
- package/src/ai/multimodal/multi-modal-processor.js +345 -0
- package/src/ai/multimodal-processing.js +268 -0
- package/src/ai/multimodal.js +71 -0
- package/src/ai/orchestrator.js +70 -0
- package/src/ai/retrieval/adaptive-retrieval-engine.js +398 -0
- package/src/ai/retrieval-engine.js +69 -0
- package/src/ai/training/model-training-orchestrator.js +228 -0
- package/src/ci/workflow-analyzer.js +71 -0
- package/src/cli/commands/ai-ml.js +967 -0
- package/src/cli/commands/docs.js +228 -0
- package/src/cli/commands/dx.js +538 -0
- package/src/cli/commands/plugin-hub.js +875 -0
- package/src/cli/doctor-command.js +639 -0
- package/src/cli/enhanced-cli-commands.js +945 -0
- package/src/cli/interactive-wizard.js +997 -0
- package/src/cli/plugin-marketplace-commands.js +869 -0
- package/src/cli.js +17 -0
- package/src/config/enhanced-ragrc-schema.js +632 -0
- package/src/config/load-config.js +54 -0
- package/src/config/load-plugin-config.js +69 -0
- package/src/config/normalize-config.js +105 -0
- package/src/config/schema-validator.js +315 -0
- package/src/config/validate-plugin-schema.js +35 -0
- package/src/config/validate-schema.js +113 -0
- package/src/contracts/plugin-contracts.js +33 -0
- package/src/core/create-pipeline.js +99 -0
- package/src/core/dependency-injection.js +242 -0
- package/src/core/observability/event-logger.js +241 -0
- package/src/core/observability/instrumented-pipeline.js +609 -0
- package/src/core/observability/metrics.js +497 -0
- package/src/core/observability/tracing.js +781 -0
- package/src/core/performance/benchmark.js +516 -0
- package/src/core/performance/parallel-processor.js +240 -0
- package/src/core/performance/streaming-safeguards.js +620 -0
- package/src/core/pipeline-factory.js +60 -0
- package/src/core/plugin-contracts.js +89 -0
- package/src/core/plugin-marketplace/plugin-metadata.js +485 -0
- package/src/core/plugin-marketplace/plugin-publisher.js +574 -0
- package/src/core/plugin-marketplace/plugin-registry-format.js +419 -0
- package/src/core/plugin-marketplace/version-resolver.js +61 -0
- package/src/core/plugin-registry.js +294 -0
- package/src/dag/dag-engine.js +954 -0
- package/src/dag/dag-node.js +76 -0
- package/src/dag/enhanced-dag-engine.js +822 -0
- package/src/dx/index.js +40 -0
- package/src/dx/integration-templates.js +665 -0
- package/src/dx/performance-profiler.js +968 -0
- package/src/dx/realtime-debugger.js +755 -0
- package/src/dx/visual-pipeline-builder.js +578 -0
- package/src/ecosystem/plugin-analytics-dashboard.js +778 -0
- package/src/ecosystem/plugin-certification.js +580 -0
- package/src/ecosystem/plugin-hub.js +821 -0
- package/src/enterprise/audit-logging.js +967 -0
- package/src/enterprise/data-governance.js +408 -0
- package/src/enterprise/multi-tenancy.js +496 -0
- package/src/enterprise/sso-integration.js +1030 -0
- package/src/evaluate/evaluator.js +52 -0
- package/src/evaluate/scoring.js +91 -0
- package/src/index.js +67 -0
- package/src/ingest.js +59 -0
- package/src/loader/csv-loader.js +38 -0
- package/src/loader/directory-loader.js +48 -0
- package/src/loader/html-loader.js +62 -0
- package/src/loader/markdown-loader.js +67 -0
- package/src/mocks/openai-embedder.js +119 -0
- package/src/mocks/openai-llm.js +77 -0
- package/src/mocks/pdf-loader.js +21 -0
- package/src/mocks/pinecone-retriever.js +106 -0
- package/src/observability/audit-logger.js +758 -0
- package/src/observability/dashboard-config.json +675 -0
- package/src/observability/event-logger.js +310 -0
- package/src/observability/metrics.js +691 -0
- package/src/observability/security-monitor.js +830 -0
- package/src/observability/slo-monitor.js +319 -0
- package/src/observability/telemetry.js +686 -0
- package/src/pipeline/pipeline.js +18 -0
- package/src/plugins/sample-embedder.js +53 -0
- package/src/plugins/sample-llm.js +30 -0
- package/src/plugins/sample-loader.js +24 -0
- package/src/plugins/sample-retriever.js +84 -0
- package/src/query.js +117 -0
- package/src/reranker/llm-reranker.js +111 -0
- package/src/scripts/script-utilities.js +36 -0
- package/src/security/plugin-sandbox.js +586 -0
- package/src/security/plugin-signature-verifier.js +414 -0
- package/src/security/validator.js +36 -0
- package/src/utils/ci/diagnostic-reporter.js +57 -0
- package/src/utils/logger.js +211 -0
- package/src/utils/performance-monitor.js +561 -0
- package/src/utils/plugin-scaffolder.js +447 -0
- package/src/utils/rate-limiter.js +244 -0
- package/src/utils/retry-policy.js +443 -0
- package/src/utils/retry.js +107 -0
- package/src/utils/safe-expression-evaluator.js +579 -0
- package/src/utils/secure-logging.js +338 -0
- package/src/utils/structured-logger.js +388 -0
- package/src/utils/validate-plugin-contract.js +42 -0
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Model Trainer - In-memory deterministic training orchestration
|
|
3
|
+
*
|
|
4
|
+
* Google-style implementation with dependency injection for clocks/RNG.
|
|
5
|
+
* Provides training job management, hyperparameter optimization, and model deployment.
|
|
6
|
+
*
|
|
7
|
+
* @module ModelTrainer
|
|
8
|
+
* @exports {ModelTrainer, modelTrainer}
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
const EventEmitter = require("events");
|
|
12
|
+
|
|
13
|
+
class ModelTrainer extends EventEmitter {
|
|
14
|
+
constructor(options = {}) {
|
|
15
|
+
super();
|
|
16
|
+
this.now = options.now || (() => Date.now());
|
|
17
|
+
this.sleep =
|
|
18
|
+
options.sleep ||
|
|
19
|
+
((ms) => new Promise((resolve) => setTimeout(resolve, Math.min(ms, 5))));
|
|
20
|
+
this.jobs = new Map();
|
|
21
|
+
this.optimizations = new Map();
|
|
22
|
+
this.deployments = new Map();
|
|
23
|
+
this.jobCounter = 0;
|
|
24
|
+
this.optCounter = 0;
|
|
25
|
+
this.deployCounter = 0;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Create a training job
|
|
30
|
+
* @param {string} tenantId - Tenant identifier
|
|
31
|
+
* @param {object} config - Training configuration
|
|
32
|
+
* @returns {string} Job ID
|
|
33
|
+
*/
|
|
34
|
+
createTrainingJob(tenantId, config) {
|
|
35
|
+
if (!tenantId || !config) {
|
|
36
|
+
const error = new Error("Tenant ID and config are required");
|
|
37
|
+
error.code = "INVALID_ARGUMENT";
|
|
38
|
+
throw error;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const jobId = `job-${++this.jobCounter}`;
|
|
42
|
+
const job = {
|
|
43
|
+
id: jobId,
|
|
44
|
+
tenantId,
|
|
45
|
+
config,
|
|
46
|
+
status: "created",
|
|
47
|
+
createdAt: this.now(),
|
|
48
|
+
progress: 0,
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
this.jobs.set(jobId, job);
|
|
52
|
+
return jobId;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Start training for a job
|
|
57
|
+
* @param {string} jobId - Job identifier
|
|
58
|
+
* @returns {Promise<void>}
|
|
59
|
+
*/
|
|
60
|
+
async startTraining(jobId) {
|
|
61
|
+
const job = this.jobs.get(jobId);
|
|
62
|
+
if (!job) {
|
|
63
|
+
const error = new Error(`Training job not found: ${jobId}`);
|
|
64
|
+
error.code = "NOT_FOUND";
|
|
65
|
+
throw error;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
job.status = "running";
|
|
69
|
+
job.startedAt = this.now();
|
|
70
|
+
this.emit("training_started", { jobId, tenantId: job.tenantId });
|
|
71
|
+
|
|
72
|
+
// Simulate training with tiny delay
|
|
73
|
+
await this.sleep(2);
|
|
74
|
+
|
|
75
|
+
job.status = "completed";
|
|
76
|
+
job.completedAt = this.now();
|
|
77
|
+
job.progress = 100;
|
|
78
|
+
this.emit("training_completed", {
|
|
79
|
+
jobId,
|
|
80
|
+
tenantId: job.tenantId,
|
|
81
|
+
status: "completed",
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Optimize hyperparameters
|
|
87
|
+
* @param {string} tenantId - Tenant identifier
|
|
88
|
+
* @param {object} config - Optimization configuration
|
|
89
|
+
* @returns {string} Optimization ID
|
|
90
|
+
*/
|
|
91
|
+
optimizeHyperparameters(tenantId, config) {
|
|
92
|
+
if (!tenantId || !config) {
|
|
93
|
+
const error = new Error("Tenant ID and config are required");
|
|
94
|
+
error.code = "INVALID_ARGUMENT";
|
|
95
|
+
throw error;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const optId = `opt-${++this.optCounter}`;
|
|
99
|
+
const optimization = {
|
|
100
|
+
id: optId,
|
|
101
|
+
tenantId,
|
|
102
|
+
config,
|
|
103
|
+
status: "running",
|
|
104
|
+
createdAt: this.now(),
|
|
105
|
+
trials: [
|
|
106
|
+
{ params: { lr: 0.001, batch_size: 32 }, score: 0.85 },
|
|
107
|
+
{ params: { lr: 0.01, batch_size: 64 }, score: 0.92 },
|
|
108
|
+
{ params: { lr: 0.005, batch_size: 32 }, score: 0.89 },
|
|
109
|
+
],
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
this.optimizations.set(optId, optimization);
|
|
113
|
+
|
|
114
|
+
// Emit completion immediately for deterministic tests
|
|
115
|
+
setImmediate(() => {
|
|
116
|
+
optimization.status = "completed";
|
|
117
|
+
optimization.completedAt = this.now();
|
|
118
|
+
this.emit("hpo_completed", { optId, tenantId, bestScore: 0.92 });
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
return optId;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Get optimization results
|
|
126
|
+
* @param {string} optId - Optimization identifier
|
|
127
|
+
* @returns {Array} Array of trials
|
|
128
|
+
*/
|
|
129
|
+
getOptimizationResults(optId) {
|
|
130
|
+
const optimization = this.optimizations.get(optId);
|
|
131
|
+
if (!optimization) {
|
|
132
|
+
const error = new Error(`Optimization not found: ${optId}`);
|
|
133
|
+
error.code = "NOT_FOUND";
|
|
134
|
+
throw error;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
return optimization.trials;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Deploy a trained model
|
|
142
|
+
* @param {string} jobId - Training job identifier
|
|
143
|
+
* @param {object} options - Deployment options
|
|
144
|
+
* @returns {string} Deployment ID
|
|
145
|
+
*/
|
|
146
|
+
deployModel(jobId, options = {}) {
|
|
147
|
+
const job = this.jobs.get(jobId);
|
|
148
|
+
if (!job) {
|
|
149
|
+
const error = new Error(`Training job not found: ${jobId}`);
|
|
150
|
+
error.code = "NOT_FOUND";
|
|
151
|
+
throw error;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
if (job.status !== "completed") {
|
|
155
|
+
const error = new Error("Job must be completed before deployment");
|
|
156
|
+
error.code = "FAILED_PRECONDITION";
|
|
157
|
+
throw error;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
const deploymentId = `deploy-${++this.deployCounter}`;
|
|
161
|
+
const deployment = {
|
|
162
|
+
id: deploymentId,
|
|
163
|
+
jobId,
|
|
164
|
+
tenantId: job.tenantId,
|
|
165
|
+
environment: options.environment || "staging",
|
|
166
|
+
status: "deployed",
|
|
167
|
+
deployedAt: this.now(),
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
this.deployments.set(deploymentId, deployment);
|
|
171
|
+
this.emit("model_deployed", {
|
|
172
|
+
deploymentId,
|
|
173
|
+
jobId,
|
|
174
|
+
environment: deployment.environment,
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
return deploymentId;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Get deployment status
|
|
182
|
+
* @param {string} deploymentId - Deployment identifier
|
|
183
|
+
* @returns {object} Deployment status
|
|
184
|
+
*/
|
|
185
|
+
getDeploymentStatus(deploymentId) {
|
|
186
|
+
const deployment = this.deployments.get(deploymentId);
|
|
187
|
+
if (!deployment) {
|
|
188
|
+
const error = new Error(`Deployment not found: ${deploymentId}`);
|
|
189
|
+
error.code = "NOT_FOUND";
|
|
190
|
+
throw error;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
return {
|
|
194
|
+
id: deployment.id,
|
|
195
|
+
status: deployment.status,
|
|
196
|
+
environment: deployment.environment,
|
|
197
|
+
deployedAt: deployment.deployedAt,
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* Clear all data (for testing)
|
|
203
|
+
*/
|
|
204
|
+
clear() {
|
|
205
|
+
this.jobs.clear();
|
|
206
|
+
this.optimizations.clear();
|
|
207
|
+
this.deployments.clear();
|
|
208
|
+
this.jobCounter = 0;
|
|
209
|
+
this.optCounter = 0;
|
|
210
|
+
this.deployCounter = 0;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
// Default instance
|
|
215
|
+
const modelTrainer = new ModelTrainer();
|
|
216
|
+
|
|
217
|
+
module.exports = { ModelTrainer, modelTrainer };
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Model Training Orchestrator
|
|
3
|
+
* Lightweight, deterministic in-memory trainer for RAG pipeline models
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
"use strict";
|
|
7
|
+
|
|
8
|
+
// In-memory storage for deterministic behavior
|
|
9
|
+
const jobs = new Map();
|
|
10
|
+
const optimizations = new Map();
|
|
11
|
+
const deployments = new Map();
|
|
12
|
+
|
|
13
|
+
// Deterministic ID generation using monotonic counter
|
|
14
|
+
let jobCounter = 0;
|
|
15
|
+
let optCounter = 0;
|
|
16
|
+
let deployCounter = 0;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Create a training job
|
|
20
|
+
* @param {string} tenantId - Tenant identifier
|
|
21
|
+
* @param {object} trainingConfig - Training configuration
|
|
22
|
+
* @returns {Promise<string>} Job ID
|
|
23
|
+
*/
|
|
24
|
+
async function createTrainingJob(tenantId, trainingConfig) {
|
|
25
|
+
const jobId = `job-${++jobCounter}`;
|
|
26
|
+
const job = {
|
|
27
|
+
jobId,
|
|
28
|
+
tenantId,
|
|
29
|
+
trainingConfig,
|
|
30
|
+
status: "queued",
|
|
31
|
+
createdAt: Date.now(),
|
|
32
|
+
metrics: { accuracy: 0.9 },
|
|
33
|
+
};
|
|
34
|
+
jobs.set(jobId, job);
|
|
35
|
+
return jobId;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Start training for a job
|
|
40
|
+
* @param {string} jobId - Job ID
|
|
41
|
+
* @returns {Promise<object>} Training result
|
|
42
|
+
*/
|
|
43
|
+
async function startTraining(jobId) {
|
|
44
|
+
const job = jobs.get(jobId);
|
|
45
|
+
if (!job) {
|
|
46
|
+
throw new Error(`Job ${jobId} not found`);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// Transition through states quickly
|
|
50
|
+
job.status = "running";
|
|
51
|
+
jobs.set(jobId, job);
|
|
52
|
+
|
|
53
|
+
// Simulate quick completion
|
|
54
|
+
await new Promise((resolve) => setTimeout(resolve, 1));
|
|
55
|
+
job.status = "completed";
|
|
56
|
+
jobs.set(jobId, job);
|
|
57
|
+
|
|
58
|
+
return { started: true };
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Optimize hyperparameters
|
|
63
|
+
* @param {string} tenantId - Tenant identifier
|
|
64
|
+
* @param {object} optimizationConfig - Optimization configuration
|
|
65
|
+
* @returns {Promise<string>} Optimization ID
|
|
66
|
+
*/
|
|
67
|
+
async function optimizeHyperparameters(tenantId, optimizationConfig) {
|
|
68
|
+
const optId = `opt-${++optCounter}`;
|
|
69
|
+
const optimization = {
|
|
70
|
+
optId,
|
|
71
|
+
tenantId,
|
|
72
|
+
optimizationConfig,
|
|
73
|
+
status: "completed",
|
|
74
|
+
bestConfiguration: {
|
|
75
|
+
learningRate: 0.01,
|
|
76
|
+
batchSize: 32,
|
|
77
|
+
hiddenSize: 512,
|
|
78
|
+
},
|
|
79
|
+
trials: [
|
|
80
|
+
{
|
|
81
|
+
trialId: "trial-1",
|
|
82
|
+
params: { learningRate: 0.001 },
|
|
83
|
+
metrics: { accuracy: 0.85 },
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
trialId: "trial-2",
|
|
87
|
+
params: { learningRate: 0.01 },
|
|
88
|
+
metrics: { accuracy: 0.92 },
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
trialId: "trial-3",
|
|
92
|
+
params: { learningRate: 0.1 },
|
|
93
|
+
metrics: { accuracy: 0.88 },
|
|
94
|
+
},
|
|
95
|
+
],
|
|
96
|
+
};
|
|
97
|
+
optimizations.set(optId, optimization);
|
|
98
|
+
return optId;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Deploy a trained model
|
|
103
|
+
* @param {string} jobId - Training job ID
|
|
104
|
+
* @param {object} deployConfig - Deployment configuration
|
|
105
|
+
* @returns {Promise<string>} Deployment ID
|
|
106
|
+
*/
|
|
107
|
+
async function deployModel(jobId, deployConfig = {}) {
|
|
108
|
+
const deploymentId = `dep-${++deployCounter}`;
|
|
109
|
+
const deployment = {
|
|
110
|
+
deploymentId,
|
|
111
|
+
jobId,
|
|
112
|
+
status: "deployed",
|
|
113
|
+
endpoint: `https://models.local/${deploymentId}`,
|
|
114
|
+
config: deployConfig,
|
|
115
|
+
createdAt: Date.now(),
|
|
116
|
+
};
|
|
117
|
+
deployments.set(deploymentId, deployment);
|
|
118
|
+
|
|
119
|
+
return deploymentId;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Get training status by job ID
|
|
124
|
+
* @param {string} jobId - Job ID
|
|
125
|
+
* @returns {Promise<object>} Status object with jobId, status, and metrics
|
|
126
|
+
*/
|
|
127
|
+
async function getTrainingStatus(jobId) {
|
|
128
|
+
const job = jobs.get(jobId);
|
|
129
|
+
if (!job) {
|
|
130
|
+
throw new Error(`Job ${jobId} not found`);
|
|
131
|
+
}
|
|
132
|
+
return {
|
|
133
|
+
jobId: job.jobId,
|
|
134
|
+
status: job.status,
|
|
135
|
+
metrics: job.metrics,
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Get training job by ID
|
|
141
|
+
* @param {string} jobId - Job ID
|
|
142
|
+
* @returns {object|null} Job object or null if not found
|
|
143
|
+
*/
|
|
144
|
+
function getJob(jobId) {
|
|
145
|
+
return jobs.get(jobId) || null;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Get optimization by ID
|
|
150
|
+
* @param {string} optId - Optimization ID
|
|
151
|
+
* @returns {object|null} Optimization object or null if not found
|
|
152
|
+
*/
|
|
153
|
+
function getOptimization(optId) {
|
|
154
|
+
return optimizations.get(optId) || null;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Get deployment by ID
|
|
159
|
+
* @param {string} deploymentId - Deployment ID
|
|
160
|
+
* @returns {object} Deployment object with deploymentId, jobId, status, endpoint
|
|
161
|
+
*/
|
|
162
|
+
function getDeployment(deploymentId) {
|
|
163
|
+
const deployment = deployments.get(deploymentId);
|
|
164
|
+
if (!deployment) {
|
|
165
|
+
throw new Error(`Deployment ${deploymentId} not found`);
|
|
166
|
+
}
|
|
167
|
+
return {
|
|
168
|
+
deploymentId: deployment.deploymentId,
|
|
169
|
+
jobId: deployment.jobId,
|
|
170
|
+
status: deployment.status,
|
|
171
|
+
endpoint: deployment.endpoint,
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Clear all stored data (for testing)
|
|
177
|
+
*/
|
|
178
|
+
function clear() {
|
|
179
|
+
jobs.clear();
|
|
180
|
+
optimizations.clear();
|
|
181
|
+
deployments.clear();
|
|
182
|
+
jobCounter = 0;
|
|
183
|
+
optCounter = 0;
|
|
184
|
+
deployCounter = 0;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// Singleton object with required methods
|
|
188
|
+
const modelTrainingOrchestrator = {
|
|
189
|
+
createTrainingJob,
|
|
190
|
+
startTraining,
|
|
191
|
+
optimizeHyperparameters,
|
|
192
|
+
getTrainingStatus,
|
|
193
|
+
deployModel,
|
|
194
|
+
// Additional utility methods
|
|
195
|
+
getJob,
|
|
196
|
+
getOptimization,
|
|
197
|
+
getDeployment,
|
|
198
|
+
clear,
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
// Export singleton as default
|
|
202
|
+
module.exports = modelTrainingOrchestrator;
|
|
203
|
+
|
|
204
|
+
// CJS+ESM interop pattern
|
|
205
|
+
module.exports.default = module.exports;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Standardized Module Template for CommonJS Exports
|
|
3
|
+
* Ensures reliable module.exports that work with Jest and Node.js
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
const { EventEmitter } = require("events");
|
|
7
|
+
// eslint-disable-line global-require
|
|
8
|
+
|
|
9
|
+
// Example class with proper CommonJS export pattern
|
|
10
|
+
class ExampleAIModule extends EventEmitter {
|
|
11
|
+
constructor(_options = {}) {
|
|
12
|
+
super();
|
|
13
|
+
this._config = _options;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
async exampleMethod() {
|
|
17
|
+
return "example result";
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// CRITICAL: Use this exact export pattern for all AI/ML modules
|
|
22
|
+
// This ensures compatibility with both Jest and Node.js runtime
|
|
23
|
+
module.exports = ExampleAIModule;
|
|
24
|
+
|
|
25
|
+
// Alternative pattern for multiple exports:
|
|
26
|
+
// module.exports = {
|
|
27
|
+
// ExampleAIModule,
|
|
28
|
+
// AnotherClass,
|
|
29
|
+
// utilityFunction
|
|
30
|
+
// };
|
|
31
|
+
|
|
32
|
+
// DO NOT USE: any ESM syntax in CommonJS files
|
|
33
|
+
// DO NOT USE: exports.default =
|
|
34
|
+
// DO NOT MIX: CommonJS and ESM syntax in the same file
|
|
35
|
+
|
|
36
|
+
// Ensure module.exports is properly defined
|
|
37
|
+
module.exports = {};
|