@memberjunction/predictive-studio 0.0.1 → 5.45.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 +101 -28
- package/dist/actions/base-predictive-studio.action.d.ts +63 -0
- package/dist/actions/base-predictive-studio.action.d.ts.map +1 -0
- package/dist/actions/base-predictive-studio.action.js +125 -0
- package/dist/actions/base-predictive-studio.action.js.map +1 -0
- package/dist/actions/index.d.ts +38 -0
- package/dist/actions/index.d.ts.map +1 -0
- package/dist/actions/index.js +49 -0
- package/dist/actions/index.js.map +1 -0
- package/dist/actions/model-scoring-action-generator.d.ts +108 -0
- package/dist/actions/model-scoring-action-generator.d.ts.map +1 -0
- package/dist/actions/model-scoring-action-generator.js +316 -0
- package/dist/actions/model-scoring-action-generator.js.map +1 -0
- package/dist/actions/promote-model.action.d.ts +102 -0
- package/dist/actions/promote-model.action.d.ts.map +1 -0
- package/dist/actions/promote-model.action.js +132 -0
- package/dist/actions/promote-model.action.js.map +1 -0
- package/dist/actions/promote-model.gate.d.ts +77 -0
- package/dist/actions/promote-model.gate.d.ts.map +1 -0
- package/dist/actions/promote-model.gate.js +205 -0
- package/dist/actions/promote-model.gate.js.map +1 -0
- package/dist/actions/run-experiment.action.d.ts +60 -0
- package/dist/actions/run-experiment.action.d.ts.map +1 -0
- package/dist/actions/run-experiment.action.js +134 -0
- package/dist/actions/run-experiment.action.js.map +1 -0
- package/dist/actions/run-experiment.deps.d.ts +47 -0
- package/dist/actions/run-experiment.deps.d.ts.map +1 -0
- package/dist/actions/run-experiment.deps.js +71 -0
- package/dist/actions/run-experiment.deps.js.map +1 -0
- package/dist/actions/schedule-model-scoring.action.d.ts +71 -0
- package/dist/actions/schedule-model-scoring.action.d.ts.map +1 -0
- package/dist/actions/schedule-model-scoring.action.js +148 -0
- package/dist/actions/schedule-model-scoring.action.js.map +1 -0
- package/dist/actions/score-record-set.action.d.ts +133 -0
- package/dist/actions/score-record-set.action.d.ts.map +1 -0
- package/dist/actions/score-record-set.action.js +136 -0
- package/dist/actions/score-record-set.action.js.map +1 -0
- package/dist/actions/score-record-set.runner.d.ts +192 -0
- package/dist/actions/score-record-set.runner.d.ts.map +1 -0
- package/dist/actions/score-record-set.runner.js +416 -0
- package/dist/actions/score-record-set.runner.js.map +1 -0
- package/dist/actions/train-model.action.d.ts +57 -0
- package/dist/actions/train-model.action.d.ts.map +1 -0
- package/dist/actions/train-model.action.js +111 -0
- package/dist/actions/train-model.action.js.map +1 -0
- package/dist/agent/index.d.ts +14 -0
- package/dist/agent/index.d.ts.map +1 -0
- package/dist/agent/index.js +14 -0
- package/dist/agent/index.js.map +1 -0
- package/dist/agent/model-dev-orchestrator-agent.d.ts +42 -0
- package/dist/agent/model-dev-orchestrator-agent.d.ts.map +1 -0
- package/dist/agent/model-dev-orchestrator-agent.js +76 -0
- package/dist/agent/model-dev-orchestrator-agent.js.map +1 -0
- package/dist/agent/modeling-plan-to-pipeline.d.ts +49 -0
- package/dist/agent/modeling-plan-to-pipeline.d.ts.map +1 -0
- package/dist/agent/modeling-plan-to-pipeline.js +101 -0
- package/dist/agent/modeling-plan-to-pipeline.js.map +1 -0
- package/dist/agent/pipeline-builder-agent.d.ts +58 -0
- package/dist/agent/pipeline-builder-agent.d.ts.map +1 -0
- package/dist/agent/pipeline-builder-agent.js +101 -0
- package/dist/agent/pipeline-builder-agent.js.map +1 -0
- package/dist/agent/pipeline-builder.d.ts +67 -0
- package/dist/agent/pipeline-builder.d.ts.map +1 -0
- package/dist/agent/pipeline-builder.js +114 -0
- package/dist/agent/pipeline-builder.js.map +1 -0
- package/dist/experiment/concurrency.d.ts +41 -0
- package/dist/experiment/concurrency.d.ts.map +1 -0
- package/dist/experiment/concurrency.js +54 -0
- package/dist/experiment/concurrency.js.map +1 -0
- package/dist/experiment/experiment-orchestrator.d.ts +136 -0
- package/dist/experiment/experiment-orchestrator.d.ts.map +1 -0
- package/dist/experiment/experiment-orchestrator.js +408 -0
- package/dist/experiment/experiment-orchestrator.js.map +1 -0
- package/dist/experiment/index.d.ts +17 -0
- package/dist/experiment/index.d.ts.map +1 -0
- package/dist/experiment/index.js +17 -0
- package/dist/experiment/index.js.map +1 -0
- package/dist/experiment/leaderboard.d.ts +50 -0
- package/dist/experiment/leaderboard.d.ts.map +1 -0
- package/dist/experiment/leaderboard.js +91 -0
- package/dist/experiment/leaderboard.js.map +1 -0
- package/dist/experiment/seams.d.ts +95 -0
- package/dist/experiment/seams.d.ts.map +1 -0
- package/dist/experiment/seams.js +126 -0
- package/dist/experiment/seams.js.map +1 -0
- package/dist/experiment/types.d.ts +228 -0
- package/dist/experiment/types.d.ts.map +1 -0
- package/dist/experiment/types.js +19 -0
- package/dist/experiment/types.js.map +1 -0
- package/dist/experiment/wave-strategist.d.ts +31 -0
- package/dist/experiment/wave-strategist.d.ts.map +1 -0
- package/dist/experiment/wave-strategist.js +50 -0
- package/dist/experiment/wave-strategist.js.map +1 -0
- package/dist/feature-assembly/as-of.d.ts +74 -0
- package/dist/feature-assembly/as-of.d.ts.map +1 -0
- package/dist/feature-assembly/as-of.js +136 -0
- package/dist/feature-assembly/as-of.js.map +1 -0
- package/dist/feature-assembly/data-access.d.ts +114 -0
- package/dist/feature-assembly/data-access.d.ts.map +1 -0
- package/dist/feature-assembly/data-access.js +68 -0
- package/dist/feature-assembly/data-access.js.map +1 -0
- package/dist/feature-assembly/feature-assembly-executor.d.ts +273 -0
- package/dist/feature-assembly/feature-assembly-executor.d.ts.map +1 -0
- package/dist/feature-assembly/feature-assembly-executor.js +521 -0
- package/dist/feature-assembly/feature-assembly-executor.js.map +1 -0
- package/dist/feature-assembly/index.d.ts +13 -0
- package/dist/feature-assembly/index.d.ts.map +1 -0
- package/dist/feature-assembly/index.js +13 -0
- package/dist/feature-assembly/index.js.map +1 -0
- package/dist/feature-assembly/leakage-guard.d.ts +86 -0
- package/dist/feature-assembly/leakage-guard.d.ts.map +1 -0
- package/dist/feature-assembly/leakage-guard.js +111 -0
- package/dist/feature-assembly/leakage-guard.js.map +1 -0
- package/dist/feature-assembly/vision-llm.d.ts +125 -0
- package/dist/feature-assembly/vision-llm.d.ts.map +1 -0
- package/dist/feature-assembly/vision-llm.js +211 -0
- package/dist/feature-assembly/vision-llm.js.map +1 -0
- package/dist/feature-pipelines/feature-pipeline-engine.d.ts +159 -0
- package/dist/feature-pipelines/feature-pipeline-engine.d.ts.map +1 -0
- package/dist/feature-pipelines/feature-pipeline-engine.js +298 -0
- package/dist/feature-pipelines/feature-pipeline-engine.js.map +1 -0
- package/dist/feature-pipelines/index.d.ts +13 -0
- package/dist/feature-pipelines/index.d.ts.map +1 -0
- package/dist/feature-pipelines/index.js +13 -0
- package/dist/feature-pipelines/index.js.map +1 -0
- package/dist/feature-pipelines/types.d.ts +72 -0
- package/dist/feature-pipelines/types.d.ts.map +1 -0
- package/dist/feature-pipelines/types.js +17 -0
- package/dist/feature-pipelines/types.js.map +1 -0
- package/dist/index.d.ts +37 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +80 -0
- package/dist/index.js.map +1 -0
- package/dist/maintenance/index.d.ts +19 -0
- package/dist/maintenance/index.d.ts.map +1 -0
- package/dist/maintenance/index.js +19 -0
- package/dist/maintenance/index.js.map +1 -0
- package/dist/maintenance/maintenance-engine.d.ts +152 -0
- package/dist/maintenance/maintenance-engine.d.ts.map +1 -0
- package/dist/maintenance/maintenance-engine.js +412 -0
- package/dist/maintenance/maintenance-engine.js.map +1 -0
- package/dist/maintenance/metrics.d.ts +37 -0
- package/dist/maintenance/metrics.d.ts.map +1 -0
- package/dist/maintenance/metrics.js +85 -0
- package/dist/maintenance/metrics.js.map +1 -0
- package/dist/maintenance/seams.d.ts +85 -0
- package/dist/maintenance/seams.d.ts.map +1 -0
- package/dist/maintenance/seams.js +166 -0
- package/dist/maintenance/seams.js.map +1 -0
- package/dist/maintenance/types.d.ts +318 -0
- package/dist/maintenance/types.d.ts.map +1 -0
- package/dist/maintenance/types.js +27 -0
- package/dist/maintenance/types.js.map +1 -0
- package/dist/operations/__tests__/helpers.d.ts +30 -0
- package/dist/operations/__tests__/helpers.d.ts.map +1 -0
- package/dist/operations/__tests__/helpers.js +44 -0
- package/dist/operations/__tests__/helpers.js.map +1 -0
- package/dist/operations/control-experiment-session.operation.d.ts +33 -0
- package/dist/operations/control-experiment-session.operation.d.ts.map +1 -0
- package/dist/operations/control-experiment-session.operation.js +71 -0
- package/dist/operations/control-experiment-session.operation.js.map +1 -0
- package/dist/operations/create-scoring-process.operation.d.ts +30 -0
- package/dist/operations/create-scoring-process.operation.d.ts.map +1 -0
- package/dist/operations/create-scoring-process.operation.js +65 -0
- package/dist/operations/create-scoring-process.operation.js.map +1 -0
- package/dist/operations/delegation.d.ts +113 -0
- package/dist/operations/delegation.d.ts.map +1 -0
- package/dist/operations/delegation.js +139 -0
- package/dist/operations/delegation.js.map +1 -0
- package/dist/operations/index.d.ts +40 -0
- package/dist/operations/index.d.ts.map +1 -0
- package/dist/operations/index.js +55 -0
- package/dist/operations/index.js.map +1 -0
- package/dist/operations/promote-model.operation.d.ts +57 -0
- package/dist/operations/promote-model.operation.d.ts.map +1 -0
- package/dist/operations/promote-model.operation.js +113 -0
- package/dist/operations/promote-model.operation.js.map +1 -0
- package/dist/operations/run-feature-pipeline.operation.d.ts +56 -0
- package/dist/operations/run-feature-pipeline.operation.d.ts.map +1 -0
- package/dist/operations/run-feature-pipeline.operation.js +94 -0
- package/dist/operations/run-feature-pipeline.operation.js.map +1 -0
- package/dist/operations/score-record-set.operation.d.ts +47 -0
- package/dist/operations/score-record-set.operation.d.ts.map +1 -0
- package/dist/operations/score-record-set.operation.js +113 -0
- package/dist/operations/score-record-set.operation.js.map +1 -0
- package/dist/operations/start-experiment-session.operation.d.ts +66 -0
- package/dist/operations/start-experiment-session.operation.d.ts.map +1 -0
- package/dist/operations/start-experiment-session.operation.js +132 -0
- package/dist/operations/start-experiment-session.operation.js.map +1 -0
- package/dist/operations/train-model.operation.d.ts +50 -0
- package/dist/operations/train-model.operation.d.ts.map +1 -0
- package/dist/operations/train-model.operation.js +114 -0
- package/dist/operations/train-model.operation.js.map +1 -0
- package/dist/scheduling/index.d.ts +13 -0
- package/dist/scheduling/index.d.ts.map +1 -0
- package/dist/scheduling/index.js +13 -0
- package/dist/scheduling/index.js.map +1 -0
- package/dist/scheduling/scheduled-model-scoring.d.ts +169 -0
- package/dist/scheduling/scheduled-model-scoring.d.ts.map +1 -0
- package/dist/scheduling/scheduled-model-scoring.js +189 -0
- package/dist/scheduling/scheduled-model-scoring.js.map +1 -0
- package/dist/scoring/artifact-loader.d.ts +65 -0
- package/dist/scoring/artifact-loader.d.ts.map +1 -0
- package/dist/scoring/artifact-loader.js +97 -0
- package/dist/scoring/artifact-loader.js.map +1 -0
- package/dist/scoring/index.d.ts +26 -0
- package/dist/scoring/index.d.ts.map +1 -0
- package/dist/scoring/index.js +26 -0
- package/dist/scoring/index.js.map +1 -0
- package/dist/scoring/ml-model-inference-processor.d.ts +154 -0
- package/dist/scoring/ml-model-inference-processor.d.ts.map +1 -0
- package/dist/scoring/ml-model-inference-processor.js +320 -0
- package/dist/scoring/ml-model-inference-processor.js.map +1 -0
- package/dist/scoring/ml-model-score-enricher.d.ts +80 -0
- package/dist/scoring/ml-model-score-enricher.d.ts.map +1 -0
- package/dist/scoring/ml-model-score-enricher.js +139 -0
- package/dist/scoring/ml-model-score-enricher.js.map +1 -0
- package/dist/scoring/register.d.ts +81 -0
- package/dist/scoring/register.d.ts.map +1 -0
- package/dist/scoring/register.js +105 -0
- package/dist/scoring/register.js.map +1 -0
- package/dist/scoring/scoring-binding.d.ts +72 -0
- package/dist/scoring/scoring-binding.d.ts.map +1 -0
- package/dist/scoring/scoring-binding.js +76 -0
- package/dist/scoring/scoring-binding.js.map +1 -0
- package/dist/scoring/scoring-process-shared.d.ts +105 -0
- package/dist/scoring/scoring-process-shared.d.ts.map +1 -0
- package/dist/scoring/scoring-process-shared.js +141 -0
- package/dist/scoring/scoring-process-shared.js.map +1 -0
- package/dist/scoring/scoring-process.d.ts +128 -0
- package/dist/scoring/scoring-process.d.ts.map +1 -0
- package/dist/scoring/scoring-process.js +146 -0
- package/dist/scoring/scoring-process.js.map +1 -0
- package/dist/scoring/seams.d.ts +40 -0
- package/dist/scoring/seams.d.ts.map +1 -0
- package/dist/scoring/seams.js +66 -0
- package/dist/scoring/seams.js.map +1 -0
- package/dist/scoring/startup-register.d.ts +49 -0
- package/dist/scoring/startup-register.d.ts.map +1 -0
- package/dist/scoring/startup-register.js +72 -0
- package/dist/scoring/startup-register.js.map +1 -0
- package/dist/scoring/types.d.ts +134 -0
- package/dist/scoring/types.d.ts.map +1 -0
- package/dist/scoring/types.js +26 -0
- package/dist/scoring/types.js.map +1 -0
- package/dist/training/artifact-store.d.ts +124 -0
- package/dist/training/artifact-store.d.ts.map +1 -0
- package/dist/training/artifact-store.js +163 -0
- package/dist/training/artifact-store.js.map +1 -0
- package/dist/training/index.d.ts +13 -0
- package/dist/training/index.d.ts.map +1 -0
- package/dist/training/index.js +13 -0
- package/dist/training/index.js.map +1 -0
- package/dist/training/seams.d.ts +57 -0
- package/dist/training/seams.d.ts.map +1 -0
- package/dist/training/seams.js +103 -0
- package/dist/training/seams.js.map +1 -0
- package/dist/training/training-engine.d.ts +96 -0
- package/dist/training/training-engine.d.ts.map +1 -0
- package/dist/training/training-engine.js +300 -0
- package/dist/training/training-engine.js.map +1 -0
- package/dist/training/types.d.ts +159 -0
- package/dist/training/types.d.ts.map +1 -0
- package/dist/training/types.js +16 -0
- package/dist/training/types.js.map +1 -0
- package/package.json +44 -7
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module maintenance/seams
|
|
3
|
+
*
|
|
4
|
+
* Production implementations of the {@link MaintenanceDeps} seams — thin adapters
|
|
5
|
+
* over `RunView` (binding/model loads + row counts) and the scoring action's
|
|
6
|
+
* {@link ProductionScoreRecordSetRunner} (re-scoring), plus the DEFAULT honest
|
|
7
|
+
* drift detector. These are the only place the MaintenanceEngine touches MJ's live
|
|
8
|
+
* data/inference plumbing; the engine itself depends solely on the narrow
|
|
9
|
+
* interfaces, so unit tests substitute in-memory fakes and never need a DB or
|
|
10
|
+
* sidecar.
|
|
11
|
+
*/
|
|
12
|
+
import { RunView } from '@memberjunction/core';
|
|
13
|
+
import { ProductionScoreRecordSetRunner } from '../actions/score-record-set.runner.js';
|
|
14
|
+
/**
|
|
15
|
+
* `RunView`-backed {@link IMaintenanceLoader}. Loads bindings + models as full
|
|
16
|
+
* `entity_object`s — the binding IS mutated (its monitoring fields are stamped
|
|
17
|
+
* after a re-score), so it must be a real entity object.
|
|
18
|
+
*/
|
|
19
|
+
export class RunViewMaintenanceLoader {
|
|
20
|
+
/** @inheritdoc */
|
|
21
|
+
async loadBinding(bindingId, contextUser, provider) {
|
|
22
|
+
const rv = provider ? RunView.FromMetadataProvider(provider) : new RunView();
|
|
23
|
+
const result = await rv.RunView({
|
|
24
|
+
EntityName: 'MJ: ML Model Scoring Bindings',
|
|
25
|
+
ExtraFilter: `ID='${bindingId}'`,
|
|
26
|
+
ResultType: 'entity_object',
|
|
27
|
+
MaxRows: 1,
|
|
28
|
+
}, contextUser);
|
|
29
|
+
if (!result.Success || result.Results.length === 0) {
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
return result.Results[0];
|
|
33
|
+
}
|
|
34
|
+
/** @inheritdoc */
|
|
35
|
+
async loadBindings(mode, contextUser, provider) {
|
|
36
|
+
const rv = provider ? RunView.FromMetadataProvider(provider) : new RunView();
|
|
37
|
+
const result = await rv.RunView({
|
|
38
|
+
EntityName: 'MJ: ML Model Scoring Bindings',
|
|
39
|
+
ExtraFilter: mode ? `Mode='${mode}'` : undefined,
|
|
40
|
+
ResultType: 'entity_object',
|
|
41
|
+
}, contextUser);
|
|
42
|
+
if (!result.Success) {
|
|
43
|
+
return [];
|
|
44
|
+
}
|
|
45
|
+
return result.Results;
|
|
46
|
+
}
|
|
47
|
+
/** @inheritdoc */
|
|
48
|
+
async loadModel(modelId, contextUser, provider) {
|
|
49
|
+
const rv = provider ? RunView.FromMetadataProvider(provider) : new RunView();
|
|
50
|
+
const result = await rv.RunView({
|
|
51
|
+
EntityName: 'MJ: ML Models',
|
|
52
|
+
ExtraFilter: `ID='${modelId}'`,
|
|
53
|
+
ResultType: 'entity_object',
|
|
54
|
+
MaxRows: 1,
|
|
55
|
+
}, contextUser);
|
|
56
|
+
if (!result.Success || result.Results.length === 0) {
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
return result.Results[0];
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* `RunView`-backed {@link IRowCounter}. Uses the `count_only` result type so the
|
|
64
|
+
* full population size lands in `TotalRowCount` WITHOUT materializing any rows —
|
|
65
|
+
* the efficient way to get a current count for the data-volume / drift triggers.
|
|
66
|
+
*/
|
|
67
|
+
export class RunViewRowCounter {
|
|
68
|
+
/** @inheritdoc */
|
|
69
|
+
async countRows(entityName, extraFilter, contextUser, provider) {
|
|
70
|
+
const rv = provider ? RunView.FromMetadataProvider(provider) : new RunView();
|
|
71
|
+
const result = await rv.RunView({
|
|
72
|
+
EntityName: entityName,
|
|
73
|
+
ExtraFilter: extraFilter,
|
|
74
|
+
// count_only returns no rows but populates TotalRowCount (runView.ts).
|
|
75
|
+
ResultType: 'count_only',
|
|
76
|
+
}, contextUser);
|
|
77
|
+
if (!result.Success) {
|
|
78
|
+
throw new Error(`RunViewRowCounter: failed to count '${entityName}': ${result.ErrorMessage}`);
|
|
79
|
+
}
|
|
80
|
+
return result.TotalRowCount ?? result.Results.length;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* {@link IRescoreRunner} backed by the scoring action's
|
|
85
|
+
* {@link ProductionScoreRecordSetRunner}. Re-scores a binding's full population via
|
|
86
|
+
* a `filter` scope over the target entity, reusing the SAME inference path
|
|
87
|
+
* (transform-only assembly → sidecar `/predict`) as on-demand scoring.
|
|
88
|
+
*
|
|
89
|
+
* The artifact-loader half of `MLInferenceDeps` must be supplied by the higher
|
|
90
|
+
* layer that owns the MJStorage binding (the Engine package does not import
|
|
91
|
+
* MJStorage drivers — see `scoring/seams.ts`). Pass `deps` when constructing.
|
|
92
|
+
*/
|
|
93
|
+
export class ProductionRescoreRunner {
|
|
94
|
+
/**
|
|
95
|
+
* @param deps optional scoring deps bundle (model loader / artifact loader /
|
|
96
|
+
* sidecar). When omitted the underlying runner builds production model-loader +
|
|
97
|
+
* sidecar, but a real artifact loader must be wired in for production scoring.
|
|
98
|
+
* @param primaryKeyField primary-key field on scored entities (defaults to `ID`)
|
|
99
|
+
*/
|
|
100
|
+
constructor(deps, primaryKeyField) {
|
|
101
|
+
this.runner = new ProductionScoreRecordSetRunner({ deps, primaryKeyField });
|
|
102
|
+
}
|
|
103
|
+
/** @inheritdoc */
|
|
104
|
+
async rescore(request) {
|
|
105
|
+
const result = await this.runner.run({
|
|
106
|
+
modelId: request.modelId,
|
|
107
|
+
scope: {
|
|
108
|
+
filter: {
|
|
109
|
+
entityName: request.targetEntityName,
|
|
110
|
+
extraFilter: request.extraFilter,
|
|
111
|
+
maxRows: request.maxRows,
|
|
112
|
+
},
|
|
113
|
+
},
|
|
114
|
+
contextUser: request.contextUser,
|
|
115
|
+
provider: request.provider,
|
|
116
|
+
});
|
|
117
|
+
return { scoredCount: result.scoredCount, failedCount: result.failedCount };
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* The DEFAULT, intentionally-simple-and-honest {@link IDriftDetector} (plan §12 /
|
|
122
|
+
* §16 [O]). It does NOT pretend to run a real distributional test. Instead it uses
|
|
123
|
+
* an observable proxy: how much the population the model is being scored against
|
|
124
|
+
* has grown relative to the training population. When the scored/trained row-count
|
|
125
|
+
* ratio exceeds a configurable threshold, it reports "drift" — a transparent stand
|
|
126
|
+
* -in that flags "the world the model sees has materially changed in size".
|
|
127
|
+
*
|
|
128
|
+
* A genuine statistical method (population-stability index / KS over the score
|
|
129
|
+
* distribution) is a flagged follow-up — inject a real detector implementing the
|
|
130
|
+
* same {@link IDriftDetector} contract when it lands.
|
|
131
|
+
*/
|
|
132
|
+
export class RowCountProxyDriftDetector {
|
|
133
|
+
/**
|
|
134
|
+
* @param growthRatioThreshold the scored-vs-trained row-count growth ratio above
|
|
135
|
+
* which drift is reported (default `0.5` = "population is ≥50% bigger than the
|
|
136
|
+
* model was trained on"). This deliberately mirrors — but is independent of —
|
|
137
|
+
* the data-volume staleness trigger, so a deployment can run drift OR data
|
|
138
|
+
* -volume (or both) at different thresholds.
|
|
139
|
+
*/
|
|
140
|
+
constructor(growthRatioThreshold = 0.5) {
|
|
141
|
+
this.growthRatioThreshold = growthRatioThreshold;
|
|
142
|
+
}
|
|
143
|
+
/** @inheritdoc */
|
|
144
|
+
detectDrift(context) {
|
|
145
|
+
const trained = context.trainedRowCount;
|
|
146
|
+
const observed = context.currentRowCount ?? context.lastScoredRowCount;
|
|
147
|
+
if (trained == null || trained <= 0 || observed == null) {
|
|
148
|
+
return {
|
|
149
|
+
drifted: false,
|
|
150
|
+
detail: 'Not enough row-count history to assess drift; treating as no drift (default proxy detector).',
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
const growth = (observed - trained) / trained;
|
|
154
|
+
const drifted = growth > this.growthRatioThreshold;
|
|
155
|
+
return {
|
|
156
|
+
drifted,
|
|
157
|
+
score: growth,
|
|
158
|
+
detail: drifted
|
|
159
|
+
? `The scored population is ${(growth * 100).toFixed(0)}% larger than the training population ` +
|
|
160
|
+
`(${trained} → ${observed} rows), past the ${(this.growthRatioThreshold * 100).toFixed(0)}% drift proxy threshold. ` +
|
|
161
|
+
`This is a coarse size-based proxy, not a true distribution test — a human should confirm.`
|
|
162
|
+
: `The scored population (${observed} rows) is within the drift proxy threshold of the training population (${trained} rows).`,
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
//# sourceMappingURL=seams.js.map
|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IAAI,OAAO,CAAC,kBAAkB,CAAC;QACvE,IAAI,OAAO,IAAI,IAAI,IAAI,OAAO,IAAI,CAAC,IAAI,QAAQ,IAAI,IAAI,EAAE,CAAC;YACxD,OAAO;gBACL,OAAO,EAAE,KAAK;gBACd,MAAM,EAAE,8FAA8F;aACvG,CAAC;QACJ,CAAC;QACD,MAAM,MAAM,GAAG,CAAC,QAAQ,GAAG,OAAO,CAAC,GAAG,OAAO,CAAC;QAC9C,MAAM,OAAO,GAAG,MAAM,GAAG,IAAI,CAAC,oBAAoB,CAAC;QACnD,OAAO;YACL,OAAO;YACP,KAAK,EAAE,MAAM;YACb,MAAM,EAAE,OAAO;gBACb,CAAC,CAAC,4BAA4B,CAAC,MAAM,GAAG,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,wCAAwC;oBAC7F,IAAI,OAAO,MAAM,QAAQ,oBAAoB,CAAC,IAAI,CAAC,oBAAoB,GAAG,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,2BAA2B;oBACpH,2FAA2F;gBAC7F,CAAC,CAAC,0BAA0B,QAAQ,0EAA0E,OAAO,SAAS;SACjI,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module maintenance/types
|
|
3
|
+
*
|
|
4
|
+
* The {@link RetrainingPolicy} type + dependency-injection seams and input/output
|
|
5
|
+
* shapes for the {@link MaintenanceEngine} (plan §12 / SP10). Maintenance is a
|
|
6
|
+
* **co-equal pillar** — staleness detection, scheduled re-scoring, and retraining
|
|
7
|
+
* triggers (cadence / data-volume / drift) hung off `MJ: ML Model Scoring Bindings`.
|
|
8
|
+
*
|
|
9
|
+
* Every external dependency the engine touches — entity reads, the row counter,
|
|
10
|
+
* the training engine, the inference runner, the clock, and the drift detector —
|
|
11
|
+
* is expressed as a narrow interface here so the orchestrator is unit-testable
|
|
12
|
+
* with **no live database and no live sidecar**.
|
|
13
|
+
*/
|
|
14
|
+
import type { UserInfo, IMetadataProvider } from '@memberjunction/core';
|
|
15
|
+
import type { MJMLModelEntity, MJMLModelScoringBindingEntity } from '@memberjunction/core-entities';
|
|
16
|
+
import type { TrainingEngine } from '../training/index.js';
|
|
17
|
+
import type { TrainModelInput, TrainModelResult, TrainingDeps, IEntityFactory } from '../training/index.js';
|
|
18
|
+
/**
|
|
19
|
+
* Configurable retraining/staleness policy (plan §12). All thresholds carry
|
|
20
|
+
* sensible defaults via {@link DEFAULT_RETRAINING_POLICY} so a caller can opt into
|
|
21
|
+
* just the knobs it cares about. The same policy drives staleness detection AND
|
|
22
|
+
* the retraining-trigger decision (a model is "stale" → it is a retraining
|
|
23
|
+
* candidate).
|
|
24
|
+
*/
|
|
25
|
+
export interface RetrainingPolicy {
|
|
26
|
+
/**
|
|
27
|
+
* Cadence: a model is stale when its reference timestamp (last scored / last
|
|
28
|
+
* trained — see {@link cadenceAnchor}) is older than this many days. `0` or a
|
|
29
|
+
* negative value disables the cadence trigger.
|
|
30
|
+
*/
|
|
31
|
+
cadenceDays: number;
|
|
32
|
+
/**
|
|
33
|
+
* Which timestamp the cadence trigger measures staleness against:
|
|
34
|
+
* - `lastScored` — the binding's `LastScoredAt` (how long since we last scored)
|
|
35
|
+
* - `lastTrained` — the model's `TrainedAt` (how long since the model itself was built)
|
|
36
|
+
* Defaults to `lastTrained` (the model going stale is what drives retraining).
|
|
37
|
+
*/
|
|
38
|
+
cadenceAnchor: 'lastScored' | 'lastTrained';
|
|
39
|
+
/**
|
|
40
|
+
* Data-volume: a model is stale when the target entity's CURRENT row count has
|
|
41
|
+
* grown by more than this fraction over the count at training time
|
|
42
|
+
* (`(current - trained) / trained > threshold`). e.g. `0.25` = "stale once 25%
|
|
43
|
+
* more rows exist than the model was trained on". `0` or negative disables it.
|
|
44
|
+
*/
|
|
45
|
+
dataVolumeGrowthThreshold: number;
|
|
46
|
+
/**
|
|
47
|
+
* Drift: whether to consult the injected {@link IDriftDetector}. When `true` and
|
|
48
|
+
* the detector reports drift over its own threshold, the model is stale.
|
|
49
|
+
*/
|
|
50
|
+
driftEnabled: boolean;
|
|
51
|
+
/**
|
|
52
|
+
* Promotion margin: a freshly-retrained challenger is only RECOMMENDED for
|
|
53
|
+
* promotion when its holdout metric beats the incumbent's by at least this
|
|
54
|
+
* absolute margin (e.g. `0.01` = "must be ≥1 point better"). Below the margin →
|
|
55
|
+
* HOLD. Never auto-promotes regardless (promotion is a separate signed-off
|
|
56
|
+
* Action / human gate — §6.4 / PS-AGENT-7).
|
|
57
|
+
*/
|
|
58
|
+
promotionMargin: number;
|
|
59
|
+
/**
|
|
60
|
+
* Which holdout metric to compare challenger-vs-incumbent on (a key inside the
|
|
61
|
+
* model's `HoldoutMetrics` JSON). `'auto'` picks a sensible default per problem
|
|
62
|
+
* type (`roc_auc` for classification, `r2` for regression), falling back to the
|
|
63
|
+
* first numeric metric present on both. Higher-is-better is assumed for the
|
|
64
|
+
* built-in metrics.
|
|
65
|
+
*/
|
|
66
|
+
comparisonMetric: string | 'auto';
|
|
67
|
+
}
|
|
68
|
+
/** Sensible defaults for {@link RetrainingPolicy} (plan §12). */
|
|
69
|
+
export declare const DEFAULT_RETRAINING_POLICY: RetrainingPolicy;
|
|
70
|
+
/** One reason a model was flagged stale, with the supporting numbers. */
|
|
71
|
+
export interface StalenessReason {
|
|
72
|
+
/** Which trigger fired. */
|
|
73
|
+
trigger: 'cadence' | 'data-volume' | 'drift';
|
|
74
|
+
/** Plain-language explanation (business-friendly, surfaced to users/agents). */
|
|
75
|
+
detail: string;
|
|
76
|
+
}
|
|
77
|
+
/** The outcome of a staleness evaluation for a single binding/model. */
|
|
78
|
+
export interface StalenessResult {
|
|
79
|
+
/** The scoring binding evaluated. */
|
|
80
|
+
bindingId: string;
|
|
81
|
+
/** The model the binding scores with. */
|
|
82
|
+
modelId: string;
|
|
83
|
+
/** Whether ANY trigger flagged the model stale. */
|
|
84
|
+
stale: boolean;
|
|
85
|
+
/** Every trigger that fired (empty when fresh). */
|
|
86
|
+
reasons: StalenessReason[];
|
|
87
|
+
/** The current target-entity row count observed (for transparency/audit). */
|
|
88
|
+
currentRowCount?: number;
|
|
89
|
+
/** The row count the model was trained on (`MJMLModelEntity.TrainingRowCount`). */
|
|
90
|
+
trainedRowCount?: number;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Drift-detection seam. The DEFAULT implementation ({@link RowCountProxyDriftDetector})
|
|
94
|
+
* is intentionally simple and HONEST — it uses an observable proxy (relative
|
|
95
|
+
* change in scored-row volume vs the training row count) rather than pretending to
|
|
96
|
+
* do a real distributional test. A genuine statistical drift method
|
|
97
|
+
* (population-stability index / KS over the score distribution) is a flagged
|
|
98
|
+
* follow-up (plan §16 [O]); inject a real detector here when it lands.
|
|
99
|
+
*/
|
|
100
|
+
export interface IDriftDetector {
|
|
101
|
+
/**
|
|
102
|
+
* Decide whether the model has drifted enough to be considered stale.
|
|
103
|
+
*
|
|
104
|
+
* @param context the model + its binding + observed counts (read-only)
|
|
105
|
+
* @returns drift verdict + a plain-language explanation
|
|
106
|
+
*/
|
|
107
|
+
detectDrift(context: DriftContext): Promise<DriftResult> | DriftResult;
|
|
108
|
+
}
|
|
109
|
+
/** Read-only inputs handed to an {@link IDriftDetector}. */
|
|
110
|
+
export interface DriftContext {
|
|
111
|
+
/** The model being evaluated. */
|
|
112
|
+
modelId: string;
|
|
113
|
+
/** Row count the model was trained on. */
|
|
114
|
+
trainedRowCount?: number;
|
|
115
|
+
/** Current target-entity row count (from the injected counter). */
|
|
116
|
+
currentRowCount?: number;
|
|
117
|
+
/** The binding's last-recorded scored row count (`LastRowCount`). */
|
|
118
|
+
lastScoredRowCount?: number;
|
|
119
|
+
}
|
|
120
|
+
/** An {@link IDriftDetector}'s verdict. */
|
|
121
|
+
export interface DriftResult {
|
|
122
|
+
/** Whether the model has drifted past the detector's own threshold. */
|
|
123
|
+
drifted: boolean;
|
|
124
|
+
/** A 0..1 drift score (the detector's own metric); optional. */
|
|
125
|
+
score?: number;
|
|
126
|
+
/** Plain-language explanation. */
|
|
127
|
+
detail: string;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Counter seam — returns the CURRENT row count of a target entity (optionally
|
|
131
|
+
* filtered), so the data-volume trigger can compare today's count against the
|
|
132
|
+
* model's `TrainingRowCount`. Wraps a `RunView` count in production; tests inject
|
|
133
|
+
* a fake returning canned counts.
|
|
134
|
+
*/
|
|
135
|
+
export interface IRowCounter {
|
|
136
|
+
/**
|
|
137
|
+
* Count rows of a target entity right now.
|
|
138
|
+
*
|
|
139
|
+
* @param entityName the target entity (model's training-unit entity)
|
|
140
|
+
* @param extraFilter optional filter narrowing the population (mirrors the pipeline scope)
|
|
141
|
+
* @param contextUser request user — required server-side for isolation/audit
|
|
142
|
+
* @param provider optional provider for multi-provider correctness
|
|
143
|
+
*/
|
|
144
|
+
countRows(entityName: string, extraFilter?: string, contextUser?: UserInfo, provider?: IMetadataProvider): Promise<number>;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Read seam for loading the bindings + their models that maintenance evaluates.
|
|
148
|
+
* Wraps `RunView` in production; tests inject canned rows. Returns `null` for a
|
|
149
|
+
* missing single lookup (mirrors `RunView`'s non-throwing contract).
|
|
150
|
+
*/
|
|
151
|
+
export interface IMaintenanceLoader {
|
|
152
|
+
/**
|
|
153
|
+
* Load a single scoring binding by id (mutation-free read).
|
|
154
|
+
*
|
|
155
|
+
* @returns the binding, or `null` when not found
|
|
156
|
+
*/
|
|
157
|
+
loadBinding(bindingId: string, contextUser?: UserInfo, provider?: IMetadataProvider): Promise<MJMLModelScoringBindingEntity | null>;
|
|
158
|
+
/**
|
|
159
|
+
* Load every scoring binding in a given {@link RetrainingPolicy}-relevant `Mode`
|
|
160
|
+
* (e.g. all `Scheduled` bindings for the scheduled-rescore pass).
|
|
161
|
+
*
|
|
162
|
+
* @param mode the binding mode to filter on (omit for ALL bindings)
|
|
163
|
+
*/
|
|
164
|
+
loadBindings(mode?: MaintenanceBindingMode, contextUser?: UserInfo, provider?: IMetadataProvider): Promise<MJMLModelScoringBindingEntity[]>;
|
|
165
|
+
/**
|
|
166
|
+
* Load the `MJ: ML Models` row a binding scores with (mutation-free read).
|
|
167
|
+
*
|
|
168
|
+
* @returns the model, or `null` when not found
|
|
169
|
+
*/
|
|
170
|
+
loadModel(modelId: string, contextUser?: UserInfo, provider?: IMetadataProvider): Promise<MJMLModelEntity | null>;
|
|
171
|
+
}
|
|
172
|
+
/** The binding modes maintenance distinguishes (mirrors `MJMLModelScoringBindingEntity.Mode`). */
|
|
173
|
+
export type MaintenanceBindingMode = 'OnDemand' | 'Scheduled' | 'Materialized';
|
|
174
|
+
/**
|
|
175
|
+
* Re-scoring seam — re-runs scoring for a binding and reports how many rows were
|
|
176
|
+
* scored. Wraps the {@link MLModelInferenceProcessor} batch path (via the score
|
|
177
|
+
* runner) in production; tests inject a fake returning a canned count. Keeps the
|
|
178
|
+
* MaintenanceEngine decoupled from the scoring runner's storage/sidecar wiring.
|
|
179
|
+
*/
|
|
180
|
+
export interface IRescoreRunner {
|
|
181
|
+
/**
|
|
182
|
+
* Re-score the population a binding targets.
|
|
183
|
+
*
|
|
184
|
+
* @param request which model/entity to score + the context
|
|
185
|
+
* @returns the number of rows scored (and failures, for monitoring)
|
|
186
|
+
*/
|
|
187
|
+
rescore(request: RescoreRequest): Promise<RescoreResult>;
|
|
188
|
+
}
|
|
189
|
+
/** Input to {@link IRescoreRunner.rescore}. */
|
|
190
|
+
export interface RescoreRequest {
|
|
191
|
+
/** The model id to score with. */
|
|
192
|
+
modelId: string;
|
|
193
|
+
/** The target entity whose records get scored. */
|
|
194
|
+
targetEntityName: string;
|
|
195
|
+
/** Optional filter narrowing the population (mirrors the pipeline scope). */
|
|
196
|
+
extraFilter?: string;
|
|
197
|
+
/** Optional cap on rows. */
|
|
198
|
+
maxRows?: number;
|
|
199
|
+
/** Request user. */
|
|
200
|
+
contextUser?: UserInfo;
|
|
201
|
+
/** Optional provider. */
|
|
202
|
+
provider?: IMetadataProvider;
|
|
203
|
+
}
|
|
204
|
+
/** Result of an {@link IRescoreRunner.rescore} call. */
|
|
205
|
+
export interface RescoreResult {
|
|
206
|
+
/** Rows successfully scored. */
|
|
207
|
+
scoredCount: number;
|
|
208
|
+
/** Rows that failed to score. */
|
|
209
|
+
failedCount: number;
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Clock seam — abstracts `new Date()` so cadence math is deterministic in tests.
|
|
213
|
+
* Named `IMaintenanceClock` (returning a `Date`) to avoid colliding with the
|
|
214
|
+
* experiment module's millisecond-based `IClock`.
|
|
215
|
+
*/
|
|
216
|
+
export interface IMaintenanceClock {
|
|
217
|
+
/** The current instant. */
|
|
218
|
+
now(): Date;
|
|
219
|
+
}
|
|
220
|
+
/** Default {@link IMaintenanceClock} backed by the system clock. */
|
|
221
|
+
export declare const MaintenanceSystemClock: IMaintenanceClock;
|
|
222
|
+
/**
|
|
223
|
+
* The injected dependency bundle for {@link MaintenanceEngine}. Bundling the
|
|
224
|
+
* seams (rather than constructor-injecting each) keeps the engine stateless and
|
|
225
|
+
* lets a caller vary implementations per pass.
|
|
226
|
+
*/
|
|
227
|
+
export interface MaintenanceDeps {
|
|
228
|
+
/** Loads bindings + models. */
|
|
229
|
+
loader: IMaintenanceLoader;
|
|
230
|
+
/** Entity-creation seam (shared with training) — used to stamp binding monitoring fields. */
|
|
231
|
+
entityFactory: IEntityFactory;
|
|
232
|
+
/** Counts target-entity rows for the data-volume trigger. */
|
|
233
|
+
rowCounter: IRowCounter;
|
|
234
|
+
/** Re-runs scoring for the scheduled-rescore pass. */
|
|
235
|
+
rescoreRunner: IRescoreRunner;
|
|
236
|
+
/** Drift-detection seam (consulted only when `policy.driftEnabled`). */
|
|
237
|
+
driftDetector: IDriftDetector;
|
|
238
|
+
/** The training engine used to retrain a stale model into a new version. */
|
|
239
|
+
trainingEngine: TrainingEngine;
|
|
240
|
+
/** The training dependency bundle threaded into `trainingEngine.trainModel`. */
|
|
241
|
+
trainingDeps: TrainingDeps;
|
|
242
|
+
/** Clock seam (defaults to the system clock when omitted at the engine boundary). */
|
|
243
|
+
clock?: IMaintenanceClock;
|
|
244
|
+
/** Request user — threaded through every entity op for isolation/audit. */
|
|
245
|
+
contextUser?: UserInfo;
|
|
246
|
+
/** Optional provider for multi-provider correctness. */
|
|
247
|
+
provider?: IMetadataProvider;
|
|
248
|
+
}
|
|
249
|
+
/** The promotion verdict produced after a retrain+compare. */
|
|
250
|
+
export type PromotionRecommendation = 'promote' | 'hold';
|
|
251
|
+
/** The result of evaluating a freshly-retrained challenger against the incumbent. */
|
|
252
|
+
export interface ChallengerComparison {
|
|
253
|
+
/** The metric key the comparison used. */
|
|
254
|
+
metric: string;
|
|
255
|
+
/** Incumbent's value for that metric (or `null` when absent). */
|
|
256
|
+
incumbentValue: number | null;
|
|
257
|
+
/** Challenger's value for that metric (or `null` when absent). */
|
|
258
|
+
challengerValue: number | null;
|
|
259
|
+
/** challenger − incumbent (when both present). */
|
|
260
|
+
delta: number | null;
|
|
261
|
+
/** The configured promotion margin the delta was tested against. */
|
|
262
|
+
margin: number;
|
|
263
|
+
/** `promote` when delta ≥ margin, else `hold`. NEVER triggers an actual promotion. */
|
|
264
|
+
recommendation: PromotionRecommendation;
|
|
265
|
+
/** Plain-language explanation (business-friendly). */
|
|
266
|
+
detail: string;
|
|
267
|
+
}
|
|
268
|
+
/** The outcome of a retraining trigger for a single stale binding/model. */
|
|
269
|
+
export interface RetrainOutcome {
|
|
270
|
+
/** The binding that triggered the retrain. */
|
|
271
|
+
bindingId: string;
|
|
272
|
+
/** The incumbent model that was found stale. */
|
|
273
|
+
incumbentModelId: string;
|
|
274
|
+
/** Whether a retrain actually ran (false when the model was not stale). */
|
|
275
|
+
retrained: boolean;
|
|
276
|
+
/** Why the incumbent was found stale (empty when not stale). */
|
|
277
|
+
stalenessReasons: StalenessReason[];
|
|
278
|
+
/** The newly-trained challenger model + run (present only when `retrained`). */
|
|
279
|
+
challenger?: TrainModelResult;
|
|
280
|
+
/** Challenger-vs-incumbent comparison (present only when `retrained`). */
|
|
281
|
+
comparison?: ChallengerComparison;
|
|
282
|
+
}
|
|
283
|
+
/** Per-binding outcome of the full maintenance pass. */
|
|
284
|
+
export interface MaintenancePassEntry {
|
|
285
|
+
/** The binding evaluated. */
|
|
286
|
+
bindingId: string;
|
|
287
|
+
/** The staleness verdict. */
|
|
288
|
+
staleness: StalenessResult;
|
|
289
|
+
/** The re-score result, when the binding is `Scheduled` and was re-scored. */
|
|
290
|
+
rescore?: RescoreResult;
|
|
291
|
+
/** The retrain outcome, when retraining was requested AND the model was stale. */
|
|
292
|
+
retrain?: RetrainOutcome;
|
|
293
|
+
/** Any error captured for this binding (the pass is isolated per-binding). */
|
|
294
|
+
error?: string;
|
|
295
|
+
}
|
|
296
|
+
/** Options controlling a {@link MaintenanceEngine.runMaintenancePass} run. */
|
|
297
|
+
export interface MaintenancePassOptions {
|
|
298
|
+
/** When true, `Scheduled` bindings are re-scored as part of the pass. Default true. */
|
|
299
|
+
rescoreScheduled?: boolean;
|
|
300
|
+
/** When true, stale models are retrained + compared (never promoted). Default true. */
|
|
301
|
+
retrainStale?: boolean;
|
|
302
|
+
/** Optional per-binding train input overrides (e.g. labelEventDates / maxRows). */
|
|
303
|
+
trainModelInput?: Partial<Omit<TrainModelInput, 'pipelineId'>>;
|
|
304
|
+
}
|
|
305
|
+
/** The full maintenance pass summary. */
|
|
306
|
+
export interface MaintenancePassResult {
|
|
307
|
+
/** One entry per binding processed. */
|
|
308
|
+
entries: MaintenancePassEntry[];
|
|
309
|
+
/** Count of bindings flagged stale. */
|
|
310
|
+
staleCount: number;
|
|
311
|
+
/** Count of bindings re-scored. */
|
|
312
|
+
rescoredCount: number;
|
|
313
|
+
/** Count of models retrained. */
|
|
314
|
+
retrainedCount: number;
|
|
315
|
+
/** Count of challengers recommended for promotion (recommendation only). */
|
|
316
|
+
promoteRecommendedCount: number;
|
|
317
|
+
}
|
|
318
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/maintenance/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACxE,OAAO,KAAK,EACV,eAAe,EACf,6BAA6B,EAC9B,MAAM,+BAA+B,CAAC;AAEvC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAEnG;;;;;;GAMG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;;;OAIG;IACH,WAAW,EAAE,MAAM,CAAC;IACpB;;;;;OAKG;IACH,aAAa,EAAE,YAAY,GAAG,aAAa,CAAC;IAC5C;;;;;OAKG;IACH,yBAAyB,EAAE,MAAM,CAAC;IAClC;;;OAGG;IACH,YAAY,EAAE,OAAO,CAAC;IACtB;;;;;;OAMG;IACH,eAAe,EAAE,MAAM,CAAC;IACxB;;;;;;OAMG;IACH,gBAAgB,EAAE,MAAM,GAAG,MAAM,CAAC;CACnC;AAED,iEAAiE;AACjE,eAAO,MAAM,yBAAyB,EAAE,gBAOvC,CAAC;AAEF,yEAAyE;AACzE,MAAM,WAAW,eAAe;IAC9B,2BAA2B;IAC3B,OAAO,EAAE,SAAS,GAAG,aAAa,GAAG,OAAO,CAAC;IAC7C,gFAAgF;IAChF,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,wEAAwE;AACxE,MAAM,WAAW,eAAe;IAC9B,qCAAqC;IACrC,SAAS,EAAE,MAAM,CAAC;IAClB,yCAAyC;IACzC,OAAO,EAAE,MAAM,CAAC;IAChB,mDAAmD;IACnD,KAAK,EAAE,OAAO,CAAC;IACf,mDAAmD;IACnD,OAAO,EAAE,eAA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AACxD,MAAM,WAAW,oBAAoB;IACnC,6BAA6B;IAC7B,SAAS,EAAE,MAAM,CAAC;IAClB,6BAA6B;IAC7B,SAAS,EAAE,eAAe,CAAC;IAC3B,8EAA8E;IAC9E,OAAO,CAAC,EAAE,aAAa,CAAC;IACxB,kFAAkF;IAClF,OAAO,CAAC,EAAE,cAAc,CAAC;IACzB,8EAA8E;IAC9E,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,8EAA8E;AAC9E,MAAM,WAAW,sBAAsB;IACrC,uFAAuF;IACvF,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,uFAAuF;IACvF,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,mFAAmF;IACnF,eAAe,CAAC,EAAE,OAAO,CAAC,IAAI,CAAC,eAAe,EAAE,YAAY,CAAC,CAAC,CAAC;CAChE;AAED,yCAAyC;AACzC,MAAM,WAAW,qBAAqB;IACpC,uCAAuC;IACvC,OAAO,EAAE,oBAAoB,EAAE,CAAC;IAChC,uCAAuC;IACvC,UAAU,EAAE,MAAM,CAAC;IACnB,mCAAmC;IACnC,aAAa,EAAE,MAAM,CAAC;IACtB,iCAAiC;IACjC,cAAc,EAAE,MAAM,CAAC;IACvB,4EAA4E;IAC5E,uBAAuB,EAAE,MAAM,CAAC;CACjC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module maintenance/types
|
|
3
|
+
*
|
|
4
|
+
* The {@link RetrainingPolicy} type + dependency-injection seams and input/output
|
|
5
|
+
* shapes for the {@link MaintenanceEngine} (plan §12 / SP10). Maintenance is a
|
|
6
|
+
* **co-equal pillar** — staleness detection, scheduled re-scoring, and retraining
|
|
7
|
+
* triggers (cadence / data-volume / drift) hung off `MJ: ML Model Scoring Bindings`.
|
|
8
|
+
*
|
|
9
|
+
* Every external dependency the engine touches — entity reads, the row counter,
|
|
10
|
+
* the training engine, the inference runner, the clock, and the drift detector —
|
|
11
|
+
* is expressed as a narrow interface here so the orchestrator is unit-testable
|
|
12
|
+
* with **no live database and no live sidecar**.
|
|
13
|
+
*/
|
|
14
|
+
/** Sensible defaults for {@link RetrainingPolicy} (plan §12). */
|
|
15
|
+
export const DEFAULT_RETRAINING_POLICY = {
|
|
16
|
+
cadenceDays: 30,
|
|
17
|
+
cadenceAnchor: 'lastTrained',
|
|
18
|
+
dataVolumeGrowthThreshold: 0.25,
|
|
19
|
+
driftEnabled: false,
|
|
20
|
+
promotionMargin: 0.01,
|
|
21
|
+
comparisonMetric: 'auto',
|
|
22
|
+
};
|
|
23
|
+
/** Default {@link IMaintenanceClock} backed by the system clock. */
|
|
24
|
+
export const MaintenanceSystemClock = {
|
|
25
|
+
now: () => new Date(),
|
|
26
|
+
};
|
|
27
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/maintenance/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AA8DH,iEAAiE;AACjE,MAAM,CAAC,MAAM,yBAAyB,GAAqB;IACzD,WAAW,EAAE,EAAE;IACf,aAAa,EAAE,aAAa;IAC5B,yBAAyB,EAAE,IAAI;IAC/B,YAAY,EAAE,KAAK;IACnB,eAAe,EAAE,IAAI;IACrB,gBAAgB,EAAE,MAAM;CACzB,CAAC;AAuLF,oEAAoE;AACpE,MAAM,CAAC,MAAM,sBAAsB,GAAsB;IACvD,GAAG,EAAE,GAAG,EAAE,CAAC,IAAI,IAAI,EAAE;CACtB,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module operations/__tests__/helpers
|
|
3
|
+
*
|
|
4
|
+
* Shared test fixtures for the Predictive Studio Remote Operation unit tests — a
|
|
5
|
+
* stub provider / user and a capturing {@link RemoteOpServerContext} so each test can
|
|
6
|
+
* drive a server operation's `ExecuteServer` with NO live DB / sidecar and assert
|
|
7
|
+
* both the mapped output AND the emitted progress.
|
|
8
|
+
*/
|
|
9
|
+
import type { IMetadataProvider, UserInfo } from '@memberjunction/core';
|
|
10
|
+
import type { RemoteOpServerContext } from '@memberjunction/core';
|
|
11
|
+
import type { RemoteOpProgress } from '@memberjunction/core';
|
|
12
|
+
/**
|
|
13
|
+
* A minimal stub provider. The engine seams are mocked, but the training
|
|
14
|
+
* delegation now resolves the active File Storage Provider via `RunView` before
|
|
15
|
+
* delegating — so the stub answers that ONE read with an empty result (→ no active
|
|
16
|
+
* provider → the local-disk artifact fallback), keeping the train-op unit tests DB-free.
|
|
17
|
+
*/
|
|
18
|
+
export declare function stubProvider(): IMetadataProvider;
|
|
19
|
+
/** A minimal stub user threaded through delegation for isolation/audit. */
|
|
20
|
+
export declare function stubUser(): UserInfo;
|
|
21
|
+
/** A capturing server context — records every progress event and exposes the user/provider. */
|
|
22
|
+
export declare class CapturingContext implements RemoteOpServerContext {
|
|
23
|
+
readonly provider: IMetadataProvider;
|
|
24
|
+
readonly user: UserInfo;
|
|
25
|
+
readonly Progress: RemoteOpProgress[];
|
|
26
|
+
handle?: string;
|
|
27
|
+
constructor(provider?: IMetadataProvider, user?: UserInfo);
|
|
28
|
+
emitProgress: (progress: RemoteOpProgress) => void;
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=helpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../../src/operations/__tests__/helpers.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,QAAQ,EAAgC,MAAM,sBAAsB,CAAC;AACtG,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAClE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAE7D;;;;;GAKG;AACH,wBAAgB,YAAY,IAAI,iBAAiB,CAahD;AAED,2EAA2E;AAC3E,wBAAgB,QAAQ,IAAI,QAAQ,CAEnC;AAED,+FAA+F;AAC/F,qBAAa,gBAAiB,YAAW,qBAAqB;IAC5D,SAAgB,QAAQ,EAAE,iBAAiB,CAAC;IAC5C,SAAgB,IAAI,EAAE,QAAQ,CAAC;IAC/B,SAAgB,QAAQ,EAAE,gBAAgB,EAAE,CAAM;IAC3C,MAAM,CAAC,EAAE,MAAM,CAAC;gBAEX,QAAQ,GAAE,iBAAkC,EAAE,IAAI,GAAE,QAAqB;IAK9E,YAAY,GAAI,UAAU,gBAAgB,KAAG,IAAI,CAEtD;CACH"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module operations/__tests__/helpers
|
|
3
|
+
*
|
|
4
|
+
* Shared test fixtures for the Predictive Studio Remote Operation unit tests — a
|
|
5
|
+
* stub provider / user and a capturing {@link RemoteOpServerContext} so each test can
|
|
6
|
+
* drive a server operation's `ExecuteServer` with NO live DB / sidecar and assert
|
|
7
|
+
* both the mapped output AND the emitted progress.
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* A minimal stub provider. The engine seams are mocked, but the training
|
|
11
|
+
* delegation now resolves the active File Storage Provider via `RunView` before
|
|
12
|
+
* delegating — so the stub answers that ONE read with an empty result (→ no active
|
|
13
|
+
* provider → the local-disk artifact fallback), keeping the train-op unit tests DB-free.
|
|
14
|
+
*/
|
|
15
|
+
export function stubProvider() {
|
|
16
|
+
return {
|
|
17
|
+
async RunView(_params) {
|
|
18
|
+
return {
|
|
19
|
+
Success: true,
|
|
20
|
+
Results: [],
|
|
21
|
+
RowCount: 0,
|
|
22
|
+
TotalRowCount: 0,
|
|
23
|
+
ExecutionTime: 0,
|
|
24
|
+
ErrorMessage: '',
|
|
25
|
+
};
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
/** A minimal stub user threaded through delegation for isolation/audit. */
|
|
30
|
+
export function stubUser() {
|
|
31
|
+
return { ID: 'test-user', Email: 'test@example.com', Name: 'Test User' };
|
|
32
|
+
}
|
|
33
|
+
/** A capturing server context — records every progress event and exposes the user/provider. */
|
|
34
|
+
export class CapturingContext {
|
|
35
|
+
constructor(provider = stubProvider(), user = stubUser()) {
|
|
36
|
+
this.Progress = [];
|
|
37
|
+
this.emitProgress = (progress) => {
|
|
38
|
+
this.Progress.push(progress);
|
|
39
|
+
};
|
|
40
|
+
this.provider = provider;
|
|
41
|
+
this.user = user;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../../src/operations/__tests__/helpers.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAMH;;;;;GAKG;AACH,MAAM,UAAU,YAAY;IAC1B,OAAO;QACL,KAAK,CAAC,OAAO,CAAI,OAAsB;YACrC,OAAO;gBACL,OAAO,EAAE,IAAI;gBACb,OAAO,EAAE,EAAS;gBAClB,QAAQ,EAAE,CAAC;gBACX,aAAa,EAAE,CAAC;gBAChB,aAAa,EAAE,CAAC;gBAChB,YAAY,EAAE,EAAE;aACG,CAAC;QACxB,CAAC;KAC8B,CAAC;AACpC,CAAC;AAED,2EAA2E;AAC3E,MAAM,UAAU,QAAQ;IACtB,OAAO,EAAE,EAAE,EAAE,WAAW,EAAE,KAAK,EAAE,kBAAkB,EAAE,IAAI,EAAE,WAAW,EAAyB,CAAC;AAClG,CAAC;AAED,+FAA+F;AAC/F,MAAM,OAAO,gBAAgB;IAM3B,YAAY,WAA8B,YAAY,EAAE,EAAE,OAAiB,QAAQ,EAAE;QAHrE,aAAQ,GAAuB,EAAE,CAAC;QAQ3C,iBAAY,GAAG,CAAC,QAA0B,EAAQ,EAAE;YACzD,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAC/B,CAAC,CAAC;QANA,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;CAKF"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module operations/control-experiment-session.operation
|
|
3
|
+
*
|
|
4
|
+
* **Control Experiment Session** Remote Operation — the server body for the
|
|
5
|
+
* Manual-mode `PredictiveStudio.ControlExperimentSession` operation. A quick `Sync`
|
|
6
|
+
* lifecycle transition over an `MJ: Experiment Sessions` run: pause a running
|
|
7
|
+
* session, resume a paused one, or cancel.
|
|
8
|
+
*
|
|
9
|
+
* Analogous to the Record Process `Pause/Resume/Cancel` control surface (which sets
|
|
10
|
+
* a run's `CancellationRequested` flag): the orchestrator honors the session's
|
|
11
|
+
* `Status` at its next wave checkpoint, so controlling a session is a lifecycle-only
|
|
12
|
+
* `Status` write on the session row. This operation therefore loads the session and
|
|
13
|
+
* sets ONLY its `Status` — it never touches the plan, budget, or any iteration.
|
|
14
|
+
*
|
|
15
|
+
* Per CLAUDE.md, data access uses the per-execution `provider` + `user` (never
|
|
16
|
+
* `new Metadata()`), and the entity Save return is checked (Save returns `false`, it
|
|
17
|
+
* does not throw, on logical failure).
|
|
18
|
+
*/
|
|
19
|
+
import type { IMetadataProvider, UserInfo } from '@memberjunction/core';
|
|
20
|
+
import { PredictiveStudioControlExperimentSessionOperation, type PredictiveStudioControlExperimentSessionInput, type PredictiveStudioControlExperimentSessionOutput } from '@memberjunction/core-entities';
|
|
21
|
+
/**
|
|
22
|
+
* Server implementation of `PredictiveStudio.ControlExperimentSession`. Extends the
|
|
23
|
+
* CodeGen-emitted {@link PredictiveStudioControlExperimentSessionOperation} base
|
|
24
|
+
* (`ExecutionMode='Sync'`, `RequiredScope='predictive:execute'`) and supplies only
|
|
25
|
+
* the body; registered last so it wins server-side dispatch.
|
|
26
|
+
*/
|
|
27
|
+
export declare class PredictiveStudioControlExperimentSessionServerOperation extends PredictiveStudioControlExperimentSessionOperation {
|
|
28
|
+
/** @inheritdoc */
|
|
29
|
+
protected InternalExecute(input: PredictiveStudioControlExperimentSessionInput, provider: IMetadataProvider, user: UserInfo): Promise<PredictiveStudioControlExperimentSessionOutput>;
|
|
30
|
+
}
|
|
31
|
+
/** Tree-shaking anchor — call from a server bootstrap to retain this registration. */
|
|
32
|
+
export declare function LoadPredictiveStudioControlExperimentSessionOperation(): void;
|
|
33
|
+
//# sourceMappingURL=control-experiment-session.operation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"control-experiment-session.operation.d.ts","sourceRoot":"","sources":["../../src/operations/control-experiment-session.operation.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAGH,OAAO,KAAK,EAAE,iBAAiB,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAExE,OAAO,EACL,iDAAiD,EACjD,KAAK,6CAA6C,EAClD,KAAK,8CAA8C,EAGpD,MAAM,+BAA+B,CAAC;AASvC;;;;;GAKG;AACH,qBACa,uDAAwD,SAAQ,iDAAiD;IAC5H,kBAAkB;cACF,eAAe,CAC7B,KAAK,EAAE,6CAA6C,EACpD,QAAQ,EAAE,iBAAiB,EAC3B,IAAI,EAAE,QAAQ,GACb,OAAO,CAAC,8CAA8C,CAAC;CAyB3D;AAED,sFAAsF;AACtF,wBAAgB,qDAAqD,IAAI,IAAI,CAE5E"}
|