@memberjunction/predictive-studio 0.0.1 → 5.44.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (266) hide show
  1. package/README.md +101 -28
  2. package/dist/actions/base-predictive-studio.action.d.ts +63 -0
  3. package/dist/actions/base-predictive-studio.action.d.ts.map +1 -0
  4. package/dist/actions/base-predictive-studio.action.js +125 -0
  5. package/dist/actions/base-predictive-studio.action.js.map +1 -0
  6. package/dist/actions/index.d.ts +38 -0
  7. package/dist/actions/index.d.ts.map +1 -0
  8. package/dist/actions/index.js +49 -0
  9. package/dist/actions/index.js.map +1 -0
  10. package/dist/actions/model-scoring-action-generator.d.ts +108 -0
  11. package/dist/actions/model-scoring-action-generator.d.ts.map +1 -0
  12. package/dist/actions/model-scoring-action-generator.js +316 -0
  13. package/dist/actions/model-scoring-action-generator.js.map +1 -0
  14. package/dist/actions/promote-model.action.d.ts +102 -0
  15. package/dist/actions/promote-model.action.d.ts.map +1 -0
  16. package/dist/actions/promote-model.action.js +132 -0
  17. package/dist/actions/promote-model.action.js.map +1 -0
  18. package/dist/actions/promote-model.gate.d.ts +77 -0
  19. package/dist/actions/promote-model.gate.d.ts.map +1 -0
  20. package/dist/actions/promote-model.gate.js +205 -0
  21. package/dist/actions/promote-model.gate.js.map +1 -0
  22. package/dist/actions/run-experiment.action.d.ts +60 -0
  23. package/dist/actions/run-experiment.action.d.ts.map +1 -0
  24. package/dist/actions/run-experiment.action.js +134 -0
  25. package/dist/actions/run-experiment.action.js.map +1 -0
  26. package/dist/actions/run-experiment.deps.d.ts +47 -0
  27. package/dist/actions/run-experiment.deps.d.ts.map +1 -0
  28. package/dist/actions/run-experiment.deps.js +71 -0
  29. package/dist/actions/run-experiment.deps.js.map +1 -0
  30. package/dist/actions/schedule-model-scoring.action.d.ts +71 -0
  31. package/dist/actions/schedule-model-scoring.action.d.ts.map +1 -0
  32. package/dist/actions/schedule-model-scoring.action.js +148 -0
  33. package/dist/actions/schedule-model-scoring.action.js.map +1 -0
  34. package/dist/actions/score-record-set.action.d.ts +133 -0
  35. package/dist/actions/score-record-set.action.d.ts.map +1 -0
  36. package/dist/actions/score-record-set.action.js +136 -0
  37. package/dist/actions/score-record-set.action.js.map +1 -0
  38. package/dist/actions/score-record-set.runner.d.ts +192 -0
  39. package/dist/actions/score-record-set.runner.d.ts.map +1 -0
  40. package/dist/actions/score-record-set.runner.js +416 -0
  41. package/dist/actions/score-record-set.runner.js.map +1 -0
  42. package/dist/actions/train-model.action.d.ts +57 -0
  43. package/dist/actions/train-model.action.d.ts.map +1 -0
  44. package/dist/actions/train-model.action.js +111 -0
  45. package/dist/actions/train-model.action.js.map +1 -0
  46. package/dist/agent/index.d.ts +14 -0
  47. package/dist/agent/index.d.ts.map +1 -0
  48. package/dist/agent/index.js +14 -0
  49. package/dist/agent/index.js.map +1 -0
  50. package/dist/agent/model-dev-orchestrator-agent.d.ts +42 -0
  51. package/dist/agent/model-dev-orchestrator-agent.d.ts.map +1 -0
  52. package/dist/agent/model-dev-orchestrator-agent.js +76 -0
  53. package/dist/agent/model-dev-orchestrator-agent.js.map +1 -0
  54. package/dist/agent/modeling-plan-to-pipeline.d.ts +49 -0
  55. package/dist/agent/modeling-plan-to-pipeline.d.ts.map +1 -0
  56. package/dist/agent/modeling-plan-to-pipeline.js +101 -0
  57. package/dist/agent/modeling-plan-to-pipeline.js.map +1 -0
  58. package/dist/agent/pipeline-builder-agent.d.ts +58 -0
  59. package/dist/agent/pipeline-builder-agent.d.ts.map +1 -0
  60. package/dist/agent/pipeline-builder-agent.js +101 -0
  61. package/dist/agent/pipeline-builder-agent.js.map +1 -0
  62. package/dist/agent/pipeline-builder.d.ts +67 -0
  63. package/dist/agent/pipeline-builder.d.ts.map +1 -0
  64. package/dist/agent/pipeline-builder.js +114 -0
  65. package/dist/agent/pipeline-builder.js.map +1 -0
  66. package/dist/experiment/concurrency.d.ts +41 -0
  67. package/dist/experiment/concurrency.d.ts.map +1 -0
  68. package/dist/experiment/concurrency.js +54 -0
  69. package/dist/experiment/concurrency.js.map +1 -0
  70. package/dist/experiment/experiment-orchestrator.d.ts +136 -0
  71. package/dist/experiment/experiment-orchestrator.d.ts.map +1 -0
  72. package/dist/experiment/experiment-orchestrator.js +408 -0
  73. package/dist/experiment/experiment-orchestrator.js.map +1 -0
  74. package/dist/experiment/index.d.ts +17 -0
  75. package/dist/experiment/index.d.ts.map +1 -0
  76. package/dist/experiment/index.js +17 -0
  77. package/dist/experiment/index.js.map +1 -0
  78. package/dist/experiment/leaderboard.d.ts +50 -0
  79. package/dist/experiment/leaderboard.d.ts.map +1 -0
  80. package/dist/experiment/leaderboard.js +91 -0
  81. package/dist/experiment/leaderboard.js.map +1 -0
  82. package/dist/experiment/seams.d.ts +95 -0
  83. package/dist/experiment/seams.d.ts.map +1 -0
  84. package/dist/experiment/seams.js +126 -0
  85. package/dist/experiment/seams.js.map +1 -0
  86. package/dist/experiment/types.d.ts +228 -0
  87. package/dist/experiment/types.d.ts.map +1 -0
  88. package/dist/experiment/types.js +19 -0
  89. package/dist/experiment/types.js.map +1 -0
  90. package/dist/experiment/wave-strategist.d.ts +31 -0
  91. package/dist/experiment/wave-strategist.d.ts.map +1 -0
  92. package/dist/experiment/wave-strategist.js +50 -0
  93. package/dist/experiment/wave-strategist.js.map +1 -0
  94. package/dist/feature-assembly/as-of.d.ts +74 -0
  95. package/dist/feature-assembly/as-of.d.ts.map +1 -0
  96. package/dist/feature-assembly/as-of.js +136 -0
  97. package/dist/feature-assembly/as-of.js.map +1 -0
  98. package/dist/feature-assembly/data-access.d.ts +114 -0
  99. package/dist/feature-assembly/data-access.d.ts.map +1 -0
  100. package/dist/feature-assembly/data-access.js +68 -0
  101. package/dist/feature-assembly/data-access.js.map +1 -0
  102. package/dist/feature-assembly/feature-assembly-executor.d.ts +273 -0
  103. package/dist/feature-assembly/feature-assembly-executor.d.ts.map +1 -0
  104. package/dist/feature-assembly/feature-assembly-executor.js +521 -0
  105. package/dist/feature-assembly/feature-assembly-executor.js.map +1 -0
  106. package/dist/feature-assembly/index.d.ts +13 -0
  107. package/dist/feature-assembly/index.d.ts.map +1 -0
  108. package/dist/feature-assembly/index.js +13 -0
  109. package/dist/feature-assembly/index.js.map +1 -0
  110. package/dist/feature-assembly/leakage-guard.d.ts +86 -0
  111. package/dist/feature-assembly/leakage-guard.d.ts.map +1 -0
  112. package/dist/feature-assembly/leakage-guard.js +111 -0
  113. package/dist/feature-assembly/leakage-guard.js.map +1 -0
  114. package/dist/feature-assembly/vision-llm.d.ts +125 -0
  115. package/dist/feature-assembly/vision-llm.d.ts.map +1 -0
  116. package/dist/feature-assembly/vision-llm.js +211 -0
  117. package/dist/feature-assembly/vision-llm.js.map +1 -0
  118. package/dist/feature-pipelines/feature-pipeline-engine.d.ts +159 -0
  119. package/dist/feature-pipelines/feature-pipeline-engine.d.ts.map +1 -0
  120. package/dist/feature-pipelines/feature-pipeline-engine.js +298 -0
  121. package/dist/feature-pipelines/feature-pipeline-engine.js.map +1 -0
  122. package/dist/feature-pipelines/index.d.ts +13 -0
  123. package/dist/feature-pipelines/index.d.ts.map +1 -0
  124. package/dist/feature-pipelines/index.js +13 -0
  125. package/dist/feature-pipelines/index.js.map +1 -0
  126. package/dist/feature-pipelines/types.d.ts +72 -0
  127. package/dist/feature-pipelines/types.d.ts.map +1 -0
  128. package/dist/feature-pipelines/types.js +17 -0
  129. package/dist/feature-pipelines/types.js.map +1 -0
  130. package/dist/index.d.ts +37 -0
  131. package/dist/index.d.ts.map +1 -0
  132. package/dist/index.js +80 -0
  133. package/dist/index.js.map +1 -0
  134. package/dist/maintenance/index.d.ts +19 -0
  135. package/dist/maintenance/index.d.ts.map +1 -0
  136. package/dist/maintenance/index.js +19 -0
  137. package/dist/maintenance/index.js.map +1 -0
  138. package/dist/maintenance/maintenance-engine.d.ts +152 -0
  139. package/dist/maintenance/maintenance-engine.d.ts.map +1 -0
  140. package/dist/maintenance/maintenance-engine.js +412 -0
  141. package/dist/maintenance/maintenance-engine.js.map +1 -0
  142. package/dist/maintenance/metrics.d.ts +37 -0
  143. package/dist/maintenance/metrics.d.ts.map +1 -0
  144. package/dist/maintenance/metrics.js +85 -0
  145. package/dist/maintenance/metrics.js.map +1 -0
  146. package/dist/maintenance/seams.d.ts +85 -0
  147. package/dist/maintenance/seams.d.ts.map +1 -0
  148. package/dist/maintenance/seams.js +166 -0
  149. package/dist/maintenance/seams.js.map +1 -0
  150. package/dist/maintenance/types.d.ts +318 -0
  151. package/dist/maintenance/types.d.ts.map +1 -0
  152. package/dist/maintenance/types.js +27 -0
  153. package/dist/maintenance/types.js.map +1 -0
  154. package/dist/operations/__tests__/helpers.d.ts +30 -0
  155. package/dist/operations/__tests__/helpers.d.ts.map +1 -0
  156. package/dist/operations/__tests__/helpers.js +44 -0
  157. package/dist/operations/__tests__/helpers.js.map +1 -0
  158. package/dist/operations/control-experiment-session.operation.d.ts +33 -0
  159. package/dist/operations/control-experiment-session.operation.d.ts.map +1 -0
  160. package/dist/operations/control-experiment-session.operation.js +71 -0
  161. package/dist/operations/control-experiment-session.operation.js.map +1 -0
  162. package/dist/operations/create-scoring-process.operation.d.ts +30 -0
  163. package/dist/operations/create-scoring-process.operation.d.ts.map +1 -0
  164. package/dist/operations/create-scoring-process.operation.js +65 -0
  165. package/dist/operations/create-scoring-process.operation.js.map +1 -0
  166. package/dist/operations/delegation.d.ts +113 -0
  167. package/dist/operations/delegation.d.ts.map +1 -0
  168. package/dist/operations/delegation.js +139 -0
  169. package/dist/operations/delegation.js.map +1 -0
  170. package/dist/operations/index.d.ts +40 -0
  171. package/dist/operations/index.d.ts.map +1 -0
  172. package/dist/operations/index.js +55 -0
  173. package/dist/operations/index.js.map +1 -0
  174. package/dist/operations/promote-model.operation.d.ts +57 -0
  175. package/dist/operations/promote-model.operation.d.ts.map +1 -0
  176. package/dist/operations/promote-model.operation.js +113 -0
  177. package/dist/operations/promote-model.operation.js.map +1 -0
  178. package/dist/operations/run-feature-pipeline.operation.d.ts +56 -0
  179. package/dist/operations/run-feature-pipeline.operation.d.ts.map +1 -0
  180. package/dist/operations/run-feature-pipeline.operation.js +94 -0
  181. package/dist/operations/run-feature-pipeline.operation.js.map +1 -0
  182. package/dist/operations/score-record-set.operation.d.ts +47 -0
  183. package/dist/operations/score-record-set.operation.d.ts.map +1 -0
  184. package/dist/operations/score-record-set.operation.js +113 -0
  185. package/dist/operations/score-record-set.operation.js.map +1 -0
  186. package/dist/operations/start-experiment-session.operation.d.ts +66 -0
  187. package/dist/operations/start-experiment-session.operation.d.ts.map +1 -0
  188. package/dist/operations/start-experiment-session.operation.js +132 -0
  189. package/dist/operations/start-experiment-session.operation.js.map +1 -0
  190. package/dist/operations/train-model.operation.d.ts +50 -0
  191. package/dist/operations/train-model.operation.d.ts.map +1 -0
  192. package/dist/operations/train-model.operation.js +114 -0
  193. package/dist/operations/train-model.operation.js.map +1 -0
  194. package/dist/scheduling/index.d.ts +13 -0
  195. package/dist/scheduling/index.d.ts.map +1 -0
  196. package/dist/scheduling/index.js +13 -0
  197. package/dist/scheduling/index.js.map +1 -0
  198. package/dist/scheduling/scheduled-model-scoring.d.ts +169 -0
  199. package/dist/scheduling/scheduled-model-scoring.d.ts.map +1 -0
  200. package/dist/scheduling/scheduled-model-scoring.js +189 -0
  201. package/dist/scheduling/scheduled-model-scoring.js.map +1 -0
  202. package/dist/scoring/artifact-loader.d.ts +65 -0
  203. package/dist/scoring/artifact-loader.d.ts.map +1 -0
  204. package/dist/scoring/artifact-loader.js +97 -0
  205. package/dist/scoring/artifact-loader.js.map +1 -0
  206. package/dist/scoring/index.d.ts +26 -0
  207. package/dist/scoring/index.d.ts.map +1 -0
  208. package/dist/scoring/index.js +26 -0
  209. package/dist/scoring/index.js.map +1 -0
  210. package/dist/scoring/ml-model-inference-processor.d.ts +154 -0
  211. package/dist/scoring/ml-model-inference-processor.d.ts.map +1 -0
  212. package/dist/scoring/ml-model-inference-processor.js +320 -0
  213. package/dist/scoring/ml-model-inference-processor.js.map +1 -0
  214. package/dist/scoring/ml-model-score-enricher.d.ts +80 -0
  215. package/dist/scoring/ml-model-score-enricher.d.ts.map +1 -0
  216. package/dist/scoring/ml-model-score-enricher.js +139 -0
  217. package/dist/scoring/ml-model-score-enricher.js.map +1 -0
  218. package/dist/scoring/register.d.ts +81 -0
  219. package/dist/scoring/register.d.ts.map +1 -0
  220. package/dist/scoring/register.js +105 -0
  221. package/dist/scoring/register.js.map +1 -0
  222. package/dist/scoring/scoring-binding.d.ts +72 -0
  223. package/dist/scoring/scoring-binding.d.ts.map +1 -0
  224. package/dist/scoring/scoring-binding.js +76 -0
  225. package/dist/scoring/scoring-binding.js.map +1 -0
  226. package/dist/scoring/scoring-process-shared.d.ts +105 -0
  227. package/dist/scoring/scoring-process-shared.d.ts.map +1 -0
  228. package/dist/scoring/scoring-process-shared.js +141 -0
  229. package/dist/scoring/scoring-process-shared.js.map +1 -0
  230. package/dist/scoring/scoring-process.d.ts +128 -0
  231. package/dist/scoring/scoring-process.d.ts.map +1 -0
  232. package/dist/scoring/scoring-process.js +146 -0
  233. package/dist/scoring/scoring-process.js.map +1 -0
  234. package/dist/scoring/seams.d.ts +40 -0
  235. package/dist/scoring/seams.d.ts.map +1 -0
  236. package/dist/scoring/seams.js +66 -0
  237. package/dist/scoring/seams.js.map +1 -0
  238. package/dist/scoring/startup-register.d.ts +49 -0
  239. package/dist/scoring/startup-register.d.ts.map +1 -0
  240. package/dist/scoring/startup-register.js +72 -0
  241. package/dist/scoring/startup-register.js.map +1 -0
  242. package/dist/scoring/types.d.ts +134 -0
  243. package/dist/scoring/types.d.ts.map +1 -0
  244. package/dist/scoring/types.js +26 -0
  245. package/dist/scoring/types.js.map +1 -0
  246. package/dist/training/artifact-store.d.ts +124 -0
  247. package/dist/training/artifact-store.d.ts.map +1 -0
  248. package/dist/training/artifact-store.js +163 -0
  249. package/dist/training/artifact-store.js.map +1 -0
  250. package/dist/training/index.d.ts +13 -0
  251. package/dist/training/index.d.ts.map +1 -0
  252. package/dist/training/index.js +13 -0
  253. package/dist/training/index.js.map +1 -0
  254. package/dist/training/seams.d.ts +57 -0
  255. package/dist/training/seams.d.ts.map +1 -0
  256. package/dist/training/seams.js +103 -0
  257. package/dist/training/seams.js.map +1 -0
  258. package/dist/training/training-engine.d.ts +96 -0
  259. package/dist/training/training-engine.d.ts.map +1 -0
  260. package/dist/training/training-engine.js +300 -0
  261. package/dist/training/training-engine.js.map +1 -0
  262. package/dist/training/types.d.ts +159 -0
  263. package/dist/training/types.d.ts.map +1 -0
  264. package/dist/training/types.js +16 -0
  265. package/dist/training/types.js.map +1 -0
  266. package/package.json +44 -7
@@ -0,0 +1,134 @@
1
+ /**
2
+ * @module scoring/types
3
+ *
4
+ * Dependency-injection seams and input/output shapes for the
5
+ * {@link MLModelInferenceProcessor} — Predictive Studio's **scoring** work type
6
+ * (plan §10). Every external dependency the scorer touches — loading the
7
+ * `MJ: ML Models` row, fetching the serialized artifact, and the Python sidecar
8
+ * `/predict` call — is expressed as a narrow interface here so the processor is
9
+ * unit-testable with no live database and no live sidecar.
10
+ *
11
+ * The production implementations of these seams (`RunViewMLModelLoader`,
12
+ * `MJFilesArtifactLoader`, `MJSidecarPredictor`) are thin adapters around
13
+ * `RunView`, `MJ: Files` / MJStorage, and {@link MLSidecar}; the tests inject
14
+ * in-memory fakes implementing the same contracts.
15
+ *
16
+ * ## The anti-skew guarantee (§6.2)
17
+ *
18
+ * Scoring assembles features through the SAME {@link FeatureAssemblyExecutor} as
19
+ * training, in the **transform-only / on-demand** context, using the MODEL's
20
+ * frozen `FeatureSchema` + `FittedPreprocessing` — it NEVER re-fits. The fitted
21
+ * preprocessing travels with the model and is passed straight through to the
22
+ * sidecar's `/predict`, which only *applies* it. This is what keeps train-time
23
+ * and score-time features identical.
24
+ */
25
+ import type { UserInfo, IMetadataProvider } from '@memberjunction/core';
26
+ import type { MJMLModelEntity } from '@memberjunction/core-entities';
27
+ import type { PredictRequest, PredictResponse, FeatureSchemaEntry, FittedPreprocessing, SourceBinding, AsOfStrategy, LeakageGuard, ProblemType, FeatureStepGraph } from '@memberjunction/predictive-studio-core';
28
+ import type { DatedSourceSpec } from '../feature-assembly/index.js';
29
+ /**
30
+ * Read seam for loading the immutable `MJ: ML Models` row to score against.
31
+ * Wraps `RunView` in production; tests inject a canned entity. Returns `null`
32
+ * when the model is not found (mirrors `RunView`'s non-throwing contract).
33
+ */
34
+ export interface IMLModelLoader {
35
+ /**
36
+ * Load a single `MJ: ML Models` row by id, fully typed for mutation-free reads.
37
+ *
38
+ * @param modelId model primary-key value
39
+ * @param contextUser request user — required server-side for isolation/audit
40
+ * @param provider optional provider for multi-provider correctness
41
+ */
42
+ loadModel(modelId: string, contextUser?: UserInfo, provider?: IMetadataProvider): Promise<MJMLModelEntity | null>;
43
+ }
44
+ /**
45
+ * Read seam for fetching the serialized model artifact bytes by file id (the
46
+ * read-side counterpart to the training `IArtifactStore.save`). Wraps `MJ: Files`
47
+ * / MJStorage in production; tests inject an in-memory map.
48
+ */
49
+ export interface IArtifactLoader {
50
+ /**
51
+ * Fetch the serialized artifact bytes previously stored under `fileId`.
52
+ *
53
+ * @param fileId the `MLModel.ArtifactFileID` value
54
+ * @param contextUser request user — required server-side for isolation/audit
55
+ * @returns the artifact bytes, or `null` when not found
56
+ */
57
+ load(fileId: string, contextUser?: UserInfo): Promise<Uint8Array | null>;
58
+ }
59
+ /**
60
+ * Sidecar seam — the `/predict` call. Wraps {@link MLSidecar} from
61
+ * `@memberjunction/predictive-studio-sidecar` in production; tests inject a fake
62
+ * that returns canned predictions and captures the request so the test can
63
+ * assert the rows / fitted-preprocessing / feature-schema sent to the sidecar.
64
+ */
65
+ export interface ISidecarPredictor {
66
+ /**
67
+ * Score 1..N rows. The implementation owns sidecar lifecycle (start/connect);
68
+ * the processor only calls this method.
69
+ *
70
+ * @param req the predict request (artifact + frozen preprocessing + schema + rows)
71
+ */
72
+ predict(req: PredictRequest): Promise<PredictResponse>;
73
+ }
74
+ /**
75
+ * The frozen inference contract resolved off a loaded `MJ: ML Models` row — the
76
+ * artifact bytes plus everything the sidecar needs to *apply* (never re-fit) the
77
+ * model. Cached warm per processor run and reused across every record in a batch.
78
+ */
79
+ export interface LoadedModel {
80
+ /** The model primary-key id (cache key + lineage). */
81
+ modelId: string;
82
+ /** Target entity whose records this model scores (training-unit entity). */
83
+ targetEntityName: string;
84
+ /** Base64 of the serialized artifact, ready for the sidecar `PredictRequest`. */
85
+ artifactB64: string;
86
+ /** Frozen fitted-preprocessing params — passed through to `/predict` unchanged (§6.2). */
87
+ fittedPreprocessing: FittedPreprocessing;
88
+ /** The model's frozen, ordered feature schema (the inference input contract). */
89
+ featureSchema: FeatureSchemaEntry[];
90
+ /** What the model predicts (classification / regression). */
91
+ problemType: ProblemType;
92
+ /** The label/target column name (diagnostics + lineage; never a feature). */
93
+ targetVariable: string;
94
+ /** Ordered source bindings the model's features draw from (assembly input). */
95
+ sourceBindings: SourceBinding[];
96
+ /** The frozen FeatureStep DAG (assembly input). */
97
+ featureSteps: FeatureStepGraph;
98
+ /** Point-in-time strategy frozen on the model's pipeline (assembly input). */
99
+ asOf: AsOfStrategy;
100
+ /** Leakage guard frozen on the model's pipeline (assembly input). */
101
+ leakageGuard: LeakageGuard;
102
+ }
103
+ /**
104
+ * The injected dependency bundle for {@link MLModelInferenceProcessor}. Bundling
105
+ * the seams (rather than constructor-injecting each) keeps the processor
106
+ * stateless across records and lets a caller vary implementations per run.
107
+ */
108
+ export interface MLInferenceDeps {
109
+ /** Loads the `MJ: ML Models` row. */
110
+ modelLoader: IMLModelLoader;
111
+ /** Loads the serialized artifact bytes. */
112
+ artifactLoader: IArtifactLoader;
113
+ /** Sidecar `/predict` seam. */
114
+ sidecar: ISidecarPredictor;
115
+ }
116
+ /**
117
+ * Construction options for {@link MLModelInferenceProcessor}.
118
+ */
119
+ export interface MLModelInferenceProcessorOptions {
120
+ /** The `MJ: ML Models` id this processor scores with. */
121
+ modelId: string;
122
+ /** The injected seam bundle (model loader, artifact loader, sidecar). */
123
+ deps: MLInferenceDeps;
124
+ /** Primary-key field on the target entity (defaults to `ID`). */
125
+ primaryKeyField?: string;
126
+ /**
127
+ * Optional dated sources supplying point-in-time ("as-of") features, when the
128
+ * model's pipeline uses them. Carried through to the FeatureAssembly executor.
129
+ */
130
+ datedSources?: DatedSourceSpec[];
131
+ }
132
+ /** Re-export for downstream scoring consumers without reaching into core. */
133
+ export type { ProblemType };
134
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/scoring/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACxE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AACrE,OAAO,KAAK,EACV,cAAc,EACd,eAAe,EACf,kBAAkB,EAClB,mBAAmB,EACnB,aAAa,EACb,YAAY,EACZ,YAAY,EACZ,WAAW,EACX,gBAAgB,EACjB,MAAM,wCAAwC,CAAC;AAEhD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAE3D;;;;GAIG;AACH,MAAM,WAAW,cAAc;IAC7B;;;;;;OAMG;IACH,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,QAAQ,EAAE,QAAQ,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC,CAAC;CACnH;AAED;;;;GAIG;AACH,MAAM,WAAW,eAAe;IAC9B;;;;;;OAMG;IACH,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,QAAQ,GAAG,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC,CAAC;CAC1E;AAED;;;;;GAKG;AACH,MAAM,WAAW,iBAAiB;IAChC;;;;;OAKG;IACH,OAAO,CAAC,GAAG,EAAE,cAAc,GAAG,OAAO,CAAC,eAAe,CAAC,CAAC;CACxD;AAED;;;;GAIG;AACH,MAAM,WAAW,WAAW;IAC1B,sDAAsD;IACtD,OAAO,EAAE,MAAM,CAAC;IAChB,4EAA4E;IAC5E,gBAAgB,EAAE,MAAM,CAAC;IACzB,iFAAiF;IACjF,WAAW,EAAE,MAAM,CAAC;IACpB,0FAA0F;IAC1F,mBAAmB,EAAE,mBAAmB,CAAC;IACzC,iFAAiF;IACjF,aAAa,EAAE,kBAAkB,EAAE,CAAC;IACpC,6DAA6D;IAC7D,WAAW,EAAE,WAAW,CAAC;IACzB,6EAA6E;IAC7E,cAAc,EAAE,MAAM,CAAC;IACvB,+EAA+E;IAC/E,cAAc,EAAE,aAAa,EAAE,CAAC;IAChC,mDAAmD;IACnD,YAAY,EAAE,gBAAgB,CAAC;IAC/B,8EAA8E;IAC9E,IAAI,EAAE,YAAY,CAAC;IACnB,qEAAqE;IACrE,YAAY,EAAE,YAAY,CAAC;CAC5B;AAED;;;;GAIG;AACH,MAAM,WAAW,eAAe;IAC9B,qCAAqC;IACrC,WAAW,EAAE,cAAc,CAAC;IAC5B,2CAA2C;IAC3C,cAAc,EAAE,eAAe,CAAC;IAChC,+BAA+B;IAC/B,OAAO,EAAE,iBAAiB,CAAC;CAC5B;AAED;;GAEG;AACH,MAAM,WAAW,gCAAgC;IAC/C,yDAAyD;IACzD,OAAO,EAAE,MAAM,CAAC;IAChB,yEAAyE;IACzE,IAAI,EAAE,eAAe,CAAC;IACtB,iEAAiE;IACjE,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB;;;OAGG;IACH,YAAY,CAAC,EAAE,eAAe,EAAE,CAAC;CAClC;AAED,6EAA6E;AAC7E,YAAY,EAAE,WAAW,EAAE,CAAC"}
@@ -0,0 +1,26 @@
1
+ /**
2
+ * @module scoring/types
3
+ *
4
+ * Dependency-injection seams and input/output shapes for the
5
+ * {@link MLModelInferenceProcessor} — Predictive Studio's **scoring** work type
6
+ * (plan §10). Every external dependency the scorer touches — loading the
7
+ * `MJ: ML Models` row, fetching the serialized artifact, and the Python sidecar
8
+ * `/predict` call — is expressed as a narrow interface here so the processor is
9
+ * unit-testable with no live database and no live sidecar.
10
+ *
11
+ * The production implementations of these seams (`RunViewMLModelLoader`,
12
+ * `MJFilesArtifactLoader`, `MJSidecarPredictor`) are thin adapters around
13
+ * `RunView`, `MJ: Files` / MJStorage, and {@link MLSidecar}; the tests inject
14
+ * in-memory fakes implementing the same contracts.
15
+ *
16
+ * ## The anti-skew guarantee (§6.2)
17
+ *
18
+ * Scoring assembles features through the SAME {@link FeatureAssemblyExecutor} as
19
+ * training, in the **transform-only / on-demand** context, using the MODEL's
20
+ * frozen `FeatureSchema` + `FittedPreprocessing` — it NEVER re-fits. The fitted
21
+ * preprocessing travels with the model and is passed straight through to the
22
+ * sidecar's `/predict`, which only *applies* it. This is what keeps train-time
23
+ * and score-time features identical.
24
+ */
25
+ export {};
26
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/scoring/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG"}
@@ -0,0 +1,124 @@
1
+ /**
2
+ * @module training/artifact-store
3
+ *
4
+ * Implementations of the {@link IArtifactStore} seam (plan §11). The serialized
5
+ * model artifact is kept out of the `MJ: ML Models` row and referenced by file
6
+ * id; this module provides:
7
+ *
8
+ * - {@link MJFilesArtifactStore} — the single coherent store: it records a real
9
+ * `MJ: Files` row (so `MLModel.ArtifactFileID` satisfies its FK to `__mj.File`)
10
+ * AND writes the serialized bytes to local disk at `<baseDir>/<file.ID>.bin`. It
11
+ * returns the real File row id, which the matching loader uses to read the bytes
12
+ * back. Kept dependency-light: it does not import MJStorage cloud drivers.
13
+ * - {@link InMemoryArtifactStore} — an in-memory map used by unit tests (no DB).
14
+ *
15
+ * ## The real-File-id + local-bytes convention (dev / on-prem)
16
+ *
17
+ * `MLModel.ArtifactFileID` is a FK to `__mj.File`, so the fileId MUST be a genuine
18
+ * `MJ: Files` row id — a bare random UUID would violate `FK_MLModel_ArtifactFile`.
19
+ * Therefore the store ALWAYS creates the File row (stamped with the active storage
20
+ * `ProviderID`) and returns `file.ID`. For this dev / on-prem mode the bytes are
21
+ * persisted to **local disk** keyed by that same id (`<baseDir>/<file.ID>.bin`,
22
+ * {@link resolveLocalArtifactBaseDir}); the scoring loader reads them back by id.
23
+ *
24
+ * **Production follow-up**: replace the local `writeFile` with a real storage
25
+ * `PutObject` against the provider (and the loader with a `GetObject`); the File
26
+ * row + id contract is unchanged, so only the byte transport moves to the cloud.
27
+ */
28
+ import { type IMetadataProvider, type UserInfo } from '@memberjunction/core';
29
+ import type { IArtifactStore, IEntityFactory } from './types.js';
30
+ /**
31
+ * Resolve the base directory artifact bytes are written to: env `PS_ARTIFACT_DIR`
32
+ * when set, else `<os.tmpdir()>/mj-ps-artifacts`. Centralized so the store (write)
33
+ * and the loader (read) agree on the location (bytes live at `<baseDir>/<file.ID>.bin`).
34
+ */
35
+ export declare function resolveLocalArtifactBaseDir(): string;
36
+ /**
37
+ * Build the absolute path an artifact with the given File-row fileId lives at:
38
+ * `<baseDir>/<fileId>.bin`. Shared by the store (write) and the loader (read) so
39
+ * they agree on the on-disk layout.
40
+ *
41
+ * @param baseDir the resolved artifact base directory
42
+ * @param fileId the `MJ: Files` row id the artifact was stored under
43
+ */
44
+ export declare function localArtifactPath(baseDir: string, fileId: string): string;
45
+ /**
46
+ * In-memory {@link IArtifactStore} for unit tests. Stores bytes in a map keyed by
47
+ * a generated id and returns that id. No database, no MJStorage.
48
+ */
49
+ export declare class InMemoryArtifactStore implements IArtifactStore {
50
+ /** Saved artifacts, keyed by the returned file id. */
51
+ readonly Saved: Map<string, {
52
+ Name: string;
53
+ Bytes: Uint8Array;
54
+ }>;
55
+ private seq;
56
+ /** @inheritdoc */
57
+ save(bytes: Uint8Array, name: string): Promise<string>;
58
+ }
59
+ /**
60
+ * Options for {@link MJFilesArtifactStore}.
61
+ */
62
+ export interface MJFilesArtifactStoreOptions {
63
+ /**
64
+ * Storage-provider id to stamp on the `MJ: Files` row (`ProviderID`). Required in
65
+ * practice — the column is NOT NULL — and supplied by {@link buildArtifactStore}
66
+ * from the active `MJ: File Storage Providers` row.
67
+ */
68
+ providerId?: string;
69
+ /** MIME content type recorded on the file (defaults to `application/octet-stream`). */
70
+ contentType?: string;
71
+ /**
72
+ * Base directory the serialized bytes are written to. Defaults to
73
+ * {@link resolveLocalArtifactBaseDir} (env `PS_ARTIFACT_DIR`, else
74
+ * `<os.tmpdir()>/mj-ps-artifacts`). Injectable so tests target a scratch dir.
75
+ */
76
+ baseDir?: string;
77
+ }
78
+ /**
79
+ * The single coherent {@link IArtifactStore}: it creates a real `MJ: Files` row
80
+ * (through the injected {@link IEntityFactory}, stamped with the active storage
81
+ * `ProviderID`) AND persists the serialized artifact bytes to local disk at
82
+ * `<baseDir>/<file.ID>.bin`. It returns the real File row id so
83
+ * `MLModel.ArtifactFileID` satisfies its FK to `__mj.File`, and the matching
84
+ * {@link LocalArtifactLoader} reads the bytes back by that id.
85
+ *
86
+ * Why both halves: the FK forces a genuine File row id, but `MJ: Files.Save()` only
87
+ * records the metadata row — it never moves bytes — so for this dev / on-prem mode
88
+ * we write the bytes ourselves, keyed by the File id. **Production follow-up**:
89
+ * swap the local `writeFile` for a real provider `PutObject`; the id contract is
90
+ * unchanged.
91
+ */
92
+ export declare class MJFilesArtifactStore implements IArtifactStore {
93
+ private readonly entityFactory;
94
+ private readonly options;
95
+ private readonly baseDir;
96
+ constructor(entityFactory: IEntityFactory, options?: MJFilesArtifactStoreOptions);
97
+ /** @inheritdoc */
98
+ save(bytes: Uint8Array, name: string, contextUser?: UserInfo): Promise<string>;
99
+ }
100
+ /**
101
+ * Resolve the id of the first **active** `MJ: File Storage Providers` row, or
102
+ * `null` when none is active. The provider id is stamped on every artifact's
103
+ * `MJ: Files` row (its `ProviderID` is NOT NULL); a seeded active provider (e.g.
104
+ * "Local Storage") is what lets {@link MJFilesArtifactStore} create a valid File row
105
+ * in dev / on-prem deployments.
106
+ *
107
+ * @param contextUser the acting user (server-side data access is user-scoped)
108
+ * @param provider optional provider for multi-provider correctness
109
+ * @returns the active provider id, or `null` when none is active
110
+ */
111
+ export declare function resolveActiveFileStorageProviderId(contextUser?: UserInfo, provider?: IMetadataProvider): Promise<string | null>;
112
+ /**
113
+ * Build the training-side {@link IArtifactStore}, stamping the resolved active
114
+ * storage `providerId` on every File row. The store creates a real `MJ: Files` row
115
+ * (FK-valid `ArtifactFileID`) and writes the bytes to local disk keyed by that id
116
+ * (dev / on-prem). When no active provider exists the File row's NOT-NULL
117
+ * `ProviderID` cannot be set and `Save()` will fail with a clear error — seed an
118
+ * active provider (e.g. "Local Storage") to enable artifact persistence.
119
+ *
120
+ * @param providerId the active storage-provider id (or `null` when none is active)
121
+ * @param entityFactory the entity-creation seam the store records the File row through
122
+ */
123
+ export declare function buildArtifactStore(providerId: string | null, entityFactory: IEntityFactory): IArtifactStore;
124
+ //# sourceMappingURL=artifact-store.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"artifact-store.d.ts","sourceRoot":"","sources":["../../src/training/artifact-store.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAMH,OAAO,EAAqB,KAAK,iBAAiB,EAAE,KAAK,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAEhG,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAE9D;;;;GAIG;AACH,wBAAgB,2BAA2B,IAAI,MAAM,CAMpD;AAED;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAEzE;AAED;;;GAGG;AACH,qBAAa,qBAAsB,YAAW,cAAc;IAC1D,sDAAsD;IACtD,SAAgB,KAAK;cAA2B,MAAM;eAAS,UAAU;OAAM;IAC/E,OAAO,CAAC,GAAG,CAAK;IAEhB,kBAAkB;IACL,IAAI,CAAC,KAAK,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;CAKpE;AAED;;GAEG;AACH,MAAM,WAAW,2BAA2B;IAC1C;;;;OAIG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,uFAAuF;IACvF,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;;;OAIG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;;;;;;;;;;;;GAaG;AACH,qBAAa,oBAAqB,YAAW,cAAc;IAIvD,OAAO,CAAC,QAAQ,CAAC,aAAa;IAC9B,OAAO,CAAC,QAAQ,CAAC,OAAO;IAJ1B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;gBAGd,aAAa,EAAE,cAAc,EAC7B,OAAO,GAAE,2BAAgC;IAK5D,kBAAkB;IACL,IAAI,CAAC,KAAK,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,QAAQ,GAAG,OAAO,CAAC,MAAM,CAAC;CA6B5F;AAID;;;;;;;;;;GAUG;AACH,wBAAsB,kCAAkC,CACtD,WAAW,CAAC,EAAE,QAAQ,EACtB,QAAQ,CAAC,EAAE,iBAAiB,GAC3B,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAkBxB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,kBAAkB,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI,EAAE,aAAa,EAAE,cAAc,GAAG,cAAc,CAE3G"}
@@ -0,0 +1,163 @@
1
+ /**
2
+ * @module training/artifact-store
3
+ *
4
+ * Implementations of the {@link IArtifactStore} seam (plan §11). The serialized
5
+ * model artifact is kept out of the `MJ: ML Models` row and referenced by file
6
+ * id; this module provides:
7
+ *
8
+ * - {@link MJFilesArtifactStore} — the single coherent store: it records a real
9
+ * `MJ: Files` row (so `MLModel.ArtifactFileID` satisfies its FK to `__mj.File`)
10
+ * AND writes the serialized bytes to local disk at `<baseDir>/<file.ID>.bin`. It
11
+ * returns the real File row id, which the matching loader uses to read the bytes
12
+ * back. Kept dependency-light: it does not import MJStorage cloud drivers.
13
+ * - {@link InMemoryArtifactStore} — an in-memory map used by unit tests (no DB).
14
+ *
15
+ * ## The real-File-id + local-bytes convention (dev / on-prem)
16
+ *
17
+ * `MLModel.ArtifactFileID` is a FK to `__mj.File`, so the fileId MUST be a genuine
18
+ * `MJ: Files` row id — a bare random UUID would violate `FK_MLModel_ArtifactFile`.
19
+ * Therefore the store ALWAYS creates the File row (stamped with the active storage
20
+ * `ProviderID`) and returns `file.ID`. For this dev / on-prem mode the bytes are
21
+ * persisted to **local disk** keyed by that same id (`<baseDir>/<file.ID>.bin`,
22
+ * {@link resolveLocalArtifactBaseDir}); the scoring loader reads them back by id.
23
+ *
24
+ * **Production follow-up**: replace the local `writeFile` with a real storage
25
+ * `PutObject` against the provider (and the loader with a `GetObject`); the File
26
+ * row + id contract is unchanged, so only the byte transport moves to the cloud.
27
+ */
28
+ import { mkdir, writeFile } from 'node:fs/promises';
29
+ import { tmpdir } from 'node:os';
30
+ import { join } from 'node:path';
31
+ import { RunView, LogError } from '@memberjunction/core';
32
+ /**
33
+ * Resolve the base directory artifact bytes are written to: env `PS_ARTIFACT_DIR`
34
+ * when set, else `<os.tmpdir()>/mj-ps-artifacts`. Centralized so the store (write)
35
+ * and the loader (read) agree on the location (bytes live at `<baseDir>/<file.ID>.bin`).
36
+ */
37
+ export function resolveLocalArtifactBaseDir() {
38
+ const fromEnv = process.env.PS_ARTIFACT_DIR;
39
+ if (fromEnv && fromEnv.trim().length > 0) {
40
+ return fromEnv.trim();
41
+ }
42
+ return join(tmpdir(), 'mj-ps-artifacts');
43
+ }
44
+ /**
45
+ * Build the absolute path an artifact with the given File-row fileId lives at:
46
+ * `<baseDir>/<fileId>.bin`. Shared by the store (write) and the loader (read) so
47
+ * they agree on the on-disk layout.
48
+ *
49
+ * @param baseDir the resolved artifact base directory
50
+ * @param fileId the `MJ: Files` row id the artifact was stored under
51
+ */
52
+ export function localArtifactPath(baseDir, fileId) {
53
+ return join(baseDir, `${fileId}.bin`);
54
+ }
55
+ /**
56
+ * In-memory {@link IArtifactStore} for unit tests. Stores bytes in a map keyed by
57
+ * a generated id and returns that id. No database, no MJStorage.
58
+ */
59
+ export class InMemoryArtifactStore {
60
+ constructor() {
61
+ /** Saved artifacts, keyed by the returned file id. */
62
+ this.Saved = new Map();
63
+ this.seq = 0;
64
+ }
65
+ /** @inheritdoc */
66
+ async save(bytes, name) {
67
+ const id = `mem-file-${++this.seq}`;
68
+ this.Saved.set(id, { Name: name, Bytes: bytes });
69
+ return id;
70
+ }
71
+ }
72
+ /**
73
+ * The single coherent {@link IArtifactStore}: it creates a real `MJ: Files` row
74
+ * (through the injected {@link IEntityFactory}, stamped with the active storage
75
+ * `ProviderID`) AND persists the serialized artifact bytes to local disk at
76
+ * `<baseDir>/<file.ID>.bin`. It returns the real File row id so
77
+ * `MLModel.ArtifactFileID` satisfies its FK to `__mj.File`, and the matching
78
+ * {@link LocalArtifactLoader} reads the bytes back by that id.
79
+ *
80
+ * Why both halves: the FK forces a genuine File row id, but `MJ: Files.Save()` only
81
+ * records the metadata row — it never moves bytes — so for this dev / on-prem mode
82
+ * we write the bytes ourselves, keyed by the File id. **Production follow-up**:
83
+ * swap the local `writeFile` for a real provider `PutObject`; the id contract is
84
+ * unchanged.
85
+ */
86
+ export class MJFilesArtifactStore {
87
+ constructor(entityFactory, options = {}) {
88
+ this.entityFactory = entityFactory;
89
+ this.options = options;
90
+ this.baseDir = options.baseDir ?? resolveLocalArtifactBaseDir();
91
+ }
92
+ /** @inheritdoc */
93
+ async save(bytes, name, contextUser) {
94
+ const file = await this.entityFactory.getEntityObject('MJ: Files', contextUser);
95
+ file.Name = name;
96
+ file.ContentType = this.options.contentType ?? 'application/octet-stream';
97
+ if (this.options.providerId) {
98
+ file.ProviderID = this.options.providerId;
99
+ }
100
+ file.Description = `Predictive Studio model artifact (${bytes.byteLength} bytes)`;
101
+ const saved = await file.Save();
102
+ if (!saved) {
103
+ const message = file.LatestResult?.CompleteMessage ?? 'unknown error';
104
+ LogError(`MJFilesArtifactStore: failed to persist artifact file row '${name}': ${message}`);
105
+ throw new Error(`Failed to persist model artifact file: ${message}`);
106
+ }
107
+ // The File row exists but holds no bytes; persist them locally keyed by the real
108
+ // File id (dev/on-prem). Production follow-up: a provider PutObject instead.
109
+ try {
110
+ await mkdir(this.baseDir, { recursive: true });
111
+ await writeFile(localArtifactPath(this.baseDir, file.ID), bytes);
112
+ }
113
+ catch (error) {
114
+ const message = error instanceof Error ? error.message : String(error);
115
+ LogError(`MJFilesArtifactStore: persisted File row '${file.ID}' but failed to write bytes under '${this.baseDir}': ${message}`);
116
+ throw new Error(`Failed to persist model artifact bytes: ${message}`);
117
+ }
118
+ return file.ID;
119
+ }
120
+ }
121
+ // ----- Store wiring (shared by every training wiring site) ---------------------
122
+ /**
123
+ * Resolve the id of the first **active** `MJ: File Storage Providers` row, or
124
+ * `null` when none is active. The provider id is stamped on every artifact's
125
+ * `MJ: Files` row (its `ProviderID` is NOT NULL); a seeded active provider (e.g.
126
+ * "Local Storage") is what lets {@link MJFilesArtifactStore} create a valid File row
127
+ * in dev / on-prem deployments.
128
+ *
129
+ * @param contextUser the acting user (server-side data access is user-scoped)
130
+ * @param provider optional provider for multi-provider correctness
131
+ * @returns the active provider id, or `null` when none is active
132
+ */
133
+ export async function resolveActiveFileStorageProviderId(contextUser, provider) {
134
+ const rv = provider ? RunView.FromMetadataProvider(provider) : new RunView();
135
+ const result = await rv.RunView({
136
+ EntityName: 'MJ: File Storage Providers',
137
+ ExtraFilter: 'IsActive = 1',
138
+ Fields: ['ID'],
139
+ // Priority is "lower numbers are preferred" — take the most-preferred active provider.
140
+ OrderBy: 'Priority ASC',
141
+ MaxRows: 1,
142
+ ResultType: 'simple',
143
+ }, contextUser);
144
+ if (!result.Success || result.Results.length === 0) {
145
+ return null;
146
+ }
147
+ return result.Results[0].ID ?? null;
148
+ }
149
+ /**
150
+ * Build the training-side {@link IArtifactStore}, stamping the resolved active
151
+ * storage `providerId` on every File row. The store creates a real `MJ: Files` row
152
+ * (FK-valid `ArtifactFileID`) and writes the bytes to local disk keyed by that id
153
+ * (dev / on-prem). When no active provider exists the File row's NOT-NULL
154
+ * `ProviderID` cannot be set and `Save()` will fail with a clear error — seed an
155
+ * active provider (e.g. "Local Storage") to enable artifact persistence.
156
+ *
157
+ * @param providerId the active storage-provider id (or `null` when none is active)
158
+ * @param entityFactory the entity-creation seam the store records the File row through
159
+ */
160
+ export function buildArtifactStore(providerId, entityFactory) {
161
+ return new MJFilesArtifactStore(entityFactory, { providerId: providerId ?? undefined });
162
+ }
163
+ //# sourceMappingURL=artifact-store.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"artifact-store.js","sourceRoot":"","sources":["../../src/training/artifact-store.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAyC,MAAM,sBAAsB,CAAC;AAIhG;;;;GAIG;AACH,MAAM,UAAU,2BAA2B;IACzC,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC;IAC5C,IAAI,OAAO,IAAI,OAAO,CAAC,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACzC,OAAO,OAAO,CAAC,IAAI,EAAE,CAAC;IACxB,CAAC;IACD,OAAO,IAAI,CAAC,MAAM,EAAE,EAAE,iBAAiB,CAAC,CAAC;AAC3C,CAAC;AAED;;;;;;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AAC,CAAC,IAAI,OAAO,EAAE,CAAC;IAC7E,MAAM,MAAM,GAAG,MAAM,EAAE,CAAC,OAAO,CAC7B;QACE,UAAU,EAAE,4BAA4B;QACxC,WAAW,EAAE,cAAc;QAC3B,MAAM,EAAE,CAAC,IAAI,CAAC;QACd,uFAAuF;QACvF,OAAO,EAAE,cAAc;QACvB,OAAO,EAAE,CAAC;QACV,UAAU,EAAE,QAAQ;KACrB,EACD,WAAW,CACZ,CAAC;IACF,IAAI,CAAC,MAAM,CAAC,OAAO,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACnD,OAAO,IAAI,CAAC;IACd,CAAC;IACD,OAAO,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,IAAI,CAAC;AACtC,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,kBAAkB,CAAC,UAAyB,EAAE,aAA6B;IACzF,OAAO,IAAI,oBAAoB,CAAC,aAAa,EAAE,EAAE,UAAU,EAAE,UAAU,IAAI,SAAS,EAAE,CAAC,CAAC;AAC1F,CAAC"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * @module training
3
+ *
4
+ * Barrel for the Predictive Studio **training orchestration** — the
5
+ * {@link TrainingEngine}, its dependency-injection seams (entity factory, record
6
+ * loader, sidecar trainer, artifact store), and the production + in-memory
7
+ * implementations of those seams. See `./training-engine` for the flow overview.
8
+ */
9
+ export * from './types.js';
10
+ export * from './artifact-store.js';
11
+ export * from './seams.js';
12
+ export * from './training-engine.js';
13
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/training/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,cAAc,SAAS,CAAC;AACxB,cAAc,kBAAkB,CAAC;AACjC,cAAc,SAAS,CAAC;AACxB,cAAc,mBAAmB,CAAC"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * @module training
3
+ *
4
+ * Barrel for the Predictive Studio **training orchestration** — the
5
+ * {@link TrainingEngine}, its dependency-injection seams (entity factory, record
6
+ * loader, sidecar trainer, artifact store), and the production + in-memory
7
+ * implementations of those seams. See `./training-engine` for the flow overview.
8
+ */
9
+ export * from './types.js';
10
+ export * from './artifact-store.js';
11
+ export * from './seams.js';
12
+ export * from './training-engine.js';
13
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/training/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,cAAc,SAAS,CAAC;AACxB,cAAc,kBAAkB,CAAC;AACjC,cAAc,SAAS,CAAC;AACxB,cAAc,mBAAmB,CAAC"}
@@ -0,0 +1,57 @@
1
+ /**
2
+ * @module training/seams
3
+ *
4
+ * Production implementations of the {@link TrainingDeps} seams — thin adapters
5
+ * over `Metadata.GetEntityObject`, `RunView`, and the Python sidecar
6
+ * ({@link MLSidecar} from `@memberjunction/predictive-studio-sidecar`). These are
7
+ * the only place the engine touches MJ's live data/inference plumbing; the
8
+ * orchestrator itself depends solely on the narrow interfaces, so unit tests
9
+ * substitute in-memory fakes and never need a DB or sidecar.
10
+ */
11
+ import { type BaseEntity, type UserInfo, type IMetadataProvider } from '@memberjunction/core';
12
+ import type { MJMLTrainingPipelineEntity } from '@memberjunction/core-entities';
13
+ import type { TrainRequest, TrainResponse, MatrixData } from '@memberjunction/predictive-studio-core';
14
+ import { MLSidecar } from '@memberjunction/predictive-studio-sidecar';
15
+ import type { IEntityFactory, IRecordLoader, ISidecarTrainer } from './types.js';
16
+ /**
17
+ * `Metadata.GetEntityObject`-backed {@link IEntityFactory}. Optionally bound to a
18
+ * specific provider for multi-provider correctness.
19
+ */
20
+ export declare class MetadataEntityFactory implements IEntityFactory {
21
+ private readonly provider?;
22
+ /**
23
+ * @param provider optional provider; when supplied it (and its `CurrentUser`)
24
+ * is honored so multi-provider callers create entities on the RIGHT server.
25
+ * When omitted the global default `Metadata` provider is used.
26
+ */
27
+ constructor(provider?: IMetadataProvider);
28
+ /** @inheritdoc */
29
+ getEntityObject<T extends BaseEntity>(entityName: string, contextUser?: UserInfo): Promise<T>;
30
+ }
31
+ /**
32
+ * `RunView`-backed {@link IRecordLoader}. Loads the pipeline as a full
33
+ * `entity_object` (it is read, not mutated) and computes the next version from a
34
+ * narrow `simple` projection over `MJ: ML Models`.
35
+ */
36
+ export declare class RunViewRecordLoader implements IRecordLoader {
37
+ /** @inheritdoc */
38
+ loadPipeline(pipelineId: string, contextUser?: UserInfo, provider?: IMetadataProvider): Promise<MJMLTrainingPipelineEntity | null>;
39
+ /** @inheritdoc */
40
+ nextModelVersion(pipelineId: string, contextUser?: UserInfo, provider?: IMetadataProvider): Promise<number>;
41
+ }
42
+ /**
43
+ * {@link ISidecarTrainer} backed by the self-managing {@link MLSidecar} client.
44
+ * Lazily starts the sidecar on first use (managed or remote mode is decided by
45
+ * `MLSidecar` from options/env).
46
+ */
47
+ export declare class MJSidecarTrainer implements ISidecarTrainer {
48
+ private readonly sidecar;
49
+ private started;
50
+ /**
51
+ * @param sidecar an `MLSidecar` instance (managed or remote)
52
+ */
53
+ constructor(sidecar?: MLSidecar);
54
+ /** @inheritdoc */
55
+ train(req: TrainRequest, lockedHoldout?: MatrixData): Promise<TrainResponse>;
56
+ }
57
+ //# sourceMappingURL=seams.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"seams.d.ts","sourceRoot":"","sources":["../../src/training/seams.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAGL,KAAK,UAAU,EACf,KAAK,QAAQ,EACb,KAAK,iBAAiB,EACvB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,+BAA+B,CAAC;AAChF,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,wCAAwC,CAAC;AACtG,OAAO,E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