@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.
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 @@
1
+ {"version":3,"file":"register.d.ts","sourceRoot":"","sources":["../../src/scoring/register.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAGH,OAAO,EAEL,KAAK,gBAAgB,EAEtB,MAAM,2CAA2C,CAAC;AAOnD,OAAO,KAAK,EAAE,eAAe,EAAE,gCAAgC,EAAE,MAAM,SAAS,CAAC;AACjF,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAO3D;;;;GAIG;AACH,eAAO,MAAM,uBAAuB,EAAE,SAAS,MAAM,EAA2D,CAAC;AAEjH;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,OAAO,CAElF;AAED;;;;;;;;GAQG;AACH,wBAAgB,2BAA2B,CACzC,QAAQ,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EACnC,OAAO,EAAE,gCAAgC,GACxC,gBAAgB,GAAG,IAAI,CAczB;AAED;;;;;GAKG;AACH,MAAM,WAAW,sBAAsB;IACrC,8DAA8D;IAC9D,OAAO,EAAE,MAAM,CAAC;IAChB,iEAAiE;IACjE,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,yEAAyE;IACzE,YAAY,CAAC,EAAE,eAAe,EAAE,CAAC;CAClC;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,0BAA0B,CAAC,IAAI,EAAE,eAAe,GAAG,IAAI,CAsBtE;AAED;;;;GAIG;AACH,wBAAgB,6BAA6B,IAAI,IAAI,CAGpD"}
@@ -0,0 +1,105 @@
1
+ /**
2
+ * @module scoring/register
3
+ *
4
+ * Work-type registration + dynamic resolution for the scoring processor, WITHOUT
5
+ * modifying the `record-set-processor` substrate (its base package must not
6
+ * depend on Predictive Studio).
7
+ *
8
+ * ## How scoring plugs into Record Set Processing
9
+ *
10
+ * The substrate's `RecordProcessExecutor.buildProcessor()` builds the built-in
11
+ * work types (`FieldRules` / `Action` / `Agent` / `Infer`) directly. To add the
12
+ * `ML Model` work type without editing that package, the
13
+ * {@link MLModelInferenceProcessor} registers itself on the MJGlobal ClassFactory
14
+ * via `@RegisterClass` (mirroring how the substrate's own Remote Operations
15
+ * register, e.g. `@RegisterClass(BaseRemotableOperation, 'RecordProcess.RunNow')`).
16
+ *
17
+ * A thin {@link resolveMLInferenceProcessor} pulls the processor back out by
18
+ * work-type key. The supervisor wires this into the executor seam (a small
19
+ * extension/override of `buildProcessor`) — no change to the base substrate is
20
+ * required, so the package stays Predictive-Studio-free.
21
+ */
22
+ import { MJGlobal, RegisterClass, SafeJSONParse } from '@memberjunction/global';
23
+ import { RecordProcessorRegistry, } from '@memberjunction/record-set-processor-base';
24
+ import { MLModelInferenceProcessor, ML_INFERENCE_WORK_TYPE, ML_INFERENCE_WORK_TYPE_ALIAS, } from './ml-model-inference-processor.js';
25
+ // Register the alias key too, so both `'ML Model'` (the human-readable work-type)
26
+ // and `'MLModelInference'` (the identifier-style key) resolve to the processor.
27
+ // The primary `'ML Model'` registration lives on the class decorator itself.
28
+ RegisterClass(MLModelInferenceProcessor, ML_INFERENCE_WORK_TYPE_ALIAS)(MLModelInferenceProcessor);
29
+ /**
30
+ * The set of work-type keys the scoring processor is registered under. A
31
+ * `RecordProcessExecutor` extension checks membership to decide whether to
32
+ * delegate a Record Process's `WorkType` to the ML scorer.
33
+ */
34
+ export const ML_INFERENCE_WORK_TYPES = [ML_INFERENCE_WORK_TYPE, ML_INFERENCE_WORK_TYPE_ALIAS];
35
+ /**
36
+ * Whether a Record Process `WorkType` value targets the ML scoring processor.
37
+ *
38
+ * @param workType the `MJ: Record Processes.WorkType` value
39
+ */
40
+ export function isMLInferenceWorkType(workType) {
41
+ return workType != null && ML_INFERENCE_WORK_TYPES.includes(workType);
42
+ }
43
+ /**
44
+ * Resolve an {@link MLModelInferenceProcessor} for a work-type key via the
45
+ * MJGlobal ClassFactory, constructed with the supplied options. Returns `null`
46
+ * when the key is not an ML-inference work type (so callers can fall through to
47
+ * the substrate's built-in processors).
48
+ *
49
+ * @param workType the Record Process `WorkType` value (`'ML Model'` / `'MLModelInference'`)
50
+ * @param options the model id + injected seams to construct the processor with
51
+ */
52
+ export function resolveMLInferenceProcessor(workType, options) {
53
+ if (!isMLInferenceWorkType(workType)) {
54
+ return null;
55
+ }
56
+ // CreateInstance dynamically returns the highest-priority registration for the
57
+ // base class + key — here the MLModelInferenceProcessor itself. Constructor args
58
+ // are forwarded by the factory. Falls back to a direct construction if the
59
+ // factory has no registration (defensive — the decorator registers it at import).
60
+ const instance = MJGlobal.Instance.ClassFactory.CreateInstance(MLModelInferenceProcessor, workType ?? ML_INFERENCE_WORK_TYPE, options);
61
+ return instance ?? new MLModelInferenceProcessor(options);
62
+ }
63
+ /**
64
+ * Register the {@link MLModelInferenceProcessor} into the Record Set Processing
65
+ * {@link RecordProcessorRegistry} for the `'ML Model'` work type (and the `'MLModelInference'` alias),
66
+ * so `RecordProcessExecutor.buildProcessor()` resolves it automatically — WITHOUT the substrate
67
+ * depending on Predictive Studio. The registered factory closes over the injected {@link MLInferenceDeps}
68
+ * (model loader / artifact loader / sidecar) and reads the per-run {@link MLScoringConfiguration}
69
+ * (the `modelId` etc.) off the Record Process's `Configuration`.
70
+ *
71
+ * Idempotent — calling more than once simply re-registers (last-wins). Call from the engine's
72
+ * startup/bootstrap with the production deps.
73
+ *
74
+ * @param deps the injected runtime seams the ML scorer needs (model loader, artifact loader, sidecar)
75
+ */
76
+ export function registerMLScoringProcessor(deps) {
77
+ const factory = (context) => {
78
+ const config = context.Configuration ? SafeJSONParse(context.Configuration) : undefined;
79
+ if (!config || !config.modelId) {
80
+ throw new Error(`Record Process '${context.RecordProcessName ?? context.RecordProcessID ?? ''}': WorkType=${context.WorkType} requires a Configuration with a 'modelId'`);
81
+ }
82
+ const options = {
83
+ modelId: config.modelId,
84
+ deps,
85
+ primaryKeyField: config.primaryKeyField,
86
+ datedSources: config.datedSources,
87
+ };
88
+ // Resolve through the ClassFactory so a higher-priority subclass registration (if any) wins.
89
+ return resolveMLInferenceProcessor(context.WorkType, options) ?? new MLModelInferenceProcessor(options);
90
+ };
91
+ const registry = RecordProcessorRegistry.Instance;
92
+ for (const workType of ML_INFERENCE_WORK_TYPES) {
93
+ registry.Register(workType, factory);
94
+ }
95
+ }
96
+ /**
97
+ * Tree-shaking anchor — call from a server bootstrap to guarantee the
98
+ * `@RegisterClass` registration is not eliminated by the bundler. Referencing the
99
+ * class through this function creates a static code path the bundler keeps.
100
+ */
101
+ export function LoadMLModelInferenceProcessor() {
102
+ // Reference the class so the module (and its decorator side-effect) is retained.
103
+ void MLModelInferenceProcessor;
104
+ }
105
+ //# sourceMappingURL=register.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"register.js","sourceRoot":"","sources":["../../src/scoring/register.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAChF,OAAO,EACL,uBAAuB,GAGxB,MAAM,2CAA2C,CAAC;AAEnD,OAAO,EACL,yBAAyB,EACzB,sBAAsB,EACtB,4BAA4B,GAC7B,MAAM,gCAAgC,CAAC;AAIxC,kFAAkF;AAClF,gFAAgF;AAChF,6EAA6E;AAC7E,aA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qC;YAChD,OAAO,EAAE,MAAM,CAAC,OAAO;YACvB,IAAI;YACJ,eAAe,EAAE,MAAM,CAAC,eAAe;YACvC,YAAY,EAAE,MAAM,CAAC,YAAY;SAClC,CAAC;QACF,6FAA6F;QAC7F,OAAO,2BAA2B,CAAC,OAAO,CAAC,QAAQ,EAAE,OAAO,CAAC,IAAI,IAAI,yBAAyB,CAAC,OAAO,CAAC,CAAC;IAC1G,CAAC,CAAC;IAEF,MAAM,QAAQ,GAAG,uBAAuB,CAAC,QAAQ,CAAC;IAClD,KAAK,MAAM,QAAQ,IAAI,uBAAuB,EAAE,CAAC;QAC/C,QAAQ,CAAC,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IACvC,CAAC;AACH,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,6BAA6B;IAC3C,iFAAiF;IACjF,KAAK,yBAAyB,CAAC;AACjC,CAAC"}
@@ -0,0 +1,72 @@
1
+ /**
2
+ * @module scoring/scoring-binding
3
+ *
4
+ * Helper to create or update a `MJ: ML Model Scoring Binding` (plan §4.6) so a
5
+ * model's scoring is **lineage-tracked**. A binding ties an `MJ: ML Models` row to
6
+ * the `MJ: Record Processes` row that scores it, the target entity/column where
7
+ * scores land, the {@link ScoringBindingMode}, and monitoring fields
8
+ * (`LastScoredAt` / `LastRowCount`). Used by both the on-demand and scheduled
9
+ * scoring paths (the Remote-Op + scheduled-trigger wiring is a later phase — this
10
+ * helper builds the binding now).
11
+ *
12
+ * The entity-creation seam is injected ({@link IEntityFactory}, shared with the
13
+ * training engine) so this helper is unit-testable with no live database.
14
+ */
15
+ import { type UserInfo } from '@memberjunction/core';
16
+ import type { MJMLModelScoringBindingEntity } from '@memberjunction/core-entities';
17
+ import type { IEntityFactory } from '../training/index.js';
18
+ /**
19
+ * How a binding scores. Mirrors `MJ: ML Model Scoring Bindings.Mode`. `Materialized`
20
+ * is reserved for the post-#2770 path (plan §10.2) — `OnDemand` + `Scheduled` ship
21
+ * now.
22
+ */
23
+ export type ScoringBindingMode = 'OnDemand' | 'Scheduled' | 'Materialized';
24
+ /**
25
+ * Input to {@link upsertScoringBinding}. When `bindingId` is supplied the existing
26
+ * binding is updated (e.g. to refresh `LastScoredAt` / `LastRowCount` after a
27
+ * run); otherwise a new binding is created.
28
+ */
29
+ export interface ScoringBindingInput {
30
+ /** Existing binding id to update; omit to create a new binding. */
31
+ bindingId?: string;
32
+ /** The `MJ: ML Models` id this binding scores with. */
33
+ mlModelId: string;
34
+ /** The `MJ: Record Processes` id that runs the scoring. */
35
+ recordProcessId: string;
36
+ /** Target entity id where scores are written (when write-back/materialized). */
37
+ targetEntityId?: string;
38
+ /** Target column where the score lands (when write-back/materialized). */
39
+ targetColumn?: string;
40
+ /** Scoring mode (defaults to `OnDemand`). */
41
+ mode?: ScoringBindingMode;
42
+ /** Monitoring: when the binding last scored. */
43
+ lastScoredAt?: Date;
44
+ /** Monitoring: how many rows the last scoring run covered. */
45
+ lastRowCount?: number;
46
+ }
47
+ /**
48
+ * Create or update a `MJ: ML Model Scoring Binding`. Returns the saved entity.
49
+ *
50
+ * @param input the binding fields (create when `bindingId` is omitted, else update)
51
+ * @param entityFactory the entity-creation seam (production: `MetadataEntityFactory`)
52
+ * @param contextUser request user — required server-side for isolation/audit
53
+ * @throws when the underlying `Save()` fails (surfaces `LatestResult.CompleteMessage`)
54
+ */
55
+ export declare function upsertScoringBinding(input: ScoringBindingInput, entityFactory: IEntityFactory, contextUser?: UserInfo): Promise<MJMLModelScoringBindingEntity>;
56
+ /**
57
+ * Convenience wrapper to stamp a binding's monitoring fields after a scoring run
58
+ * — `LastScoredAt = now` and `LastRowCount = rowCount`. Creates the binding if it
59
+ * does not yet exist.
60
+ *
61
+ * @param bindingId existing binding id (omit to create)
62
+ * @param details the model + record-process ids the binding ties together
63
+ * @param rowCount the number of rows the run scored
64
+ * @param entityFactory the entity-creation seam
65
+ * @param contextUser request user
66
+ */
67
+ export declare function recordScoringRun(bindingId: string | undefined, details: {
68
+ mlModelId: string;
69
+ recordProcessId: string;
70
+ mode?: ScoringBindingMode;
71
+ }, rowCount: number, entityFactory: IEntityFactory, contextUser?: UserInfo): Promise<MJMLModelScoringBindingEntity>;
72
+ //# sourceMappingURL=scoring-binding.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scoring-binding.d.ts","sourceRoot":"","sources":["../../src/scoring/scoring-binding.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAY,KAAK,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAC/D,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,+BAA+B,CAAC;AACnF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAElD;;;;GAIG;AACH,MAAM,MAAM,kBAAkB,GAAG,UAAU,GAAG,WAAW,GAAG,cAAc,CAAC;AAE3E;;;;GAIG;AACH,MAAM,WAAW,mBAAmB;IAClC,mEAAmE;IACnE,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,uDAAuD;IACvD,SAAS,EAAE,MAAM,CAAC;IAClB,2DAA2D;IAC3D,eAAe,EAAE,MAAM,CAAC;IACxB,gFAAgF;IAChF,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,0EAA0E;IAC1E,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,6CAA6C;IAC7C,IAAI,CAAC,EAAE,kBAAkB,CAAC;IAC1B,gDAAgD;IAChD,YAAY,CAAC,EAAE,IAAI,CAAC;IACpB,8DAA8D;IAC9D,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED;;;;;;;GAOG;AACH,wBAAsB,oBAAoB,CACxC,KAAK,EAAE,mBAAmB,EAC1B,aAAa,EAAE,cAAc,EAC7B,WAAW,CAAC,EAAE,QAAQ,GACrB,OAAO,CAAC,6BAA6B,CAAC,CAgCxC;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,gBAAgB,CACpC,SAAS,EAAE,MAAM,GAAG,SAAS,EAC7B,OAAO,EAAE;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,eAAe,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,kBAAkB,CAAA;CAAE,EAClF,QAAQ,EAAE,MAAM,EAChB,aAAa,EAAE,cAAc,EAC7B,WAAW,CAAC,EAAE,QAAQ,GACrB,OAAO,CAAC,6BAA6B,CAAC,CAaxC"}
@@ -0,0 +1,76 @@
1
+ /**
2
+ * @module scoring/scoring-binding
3
+ *
4
+ * Helper to create or update a `MJ: ML Model Scoring Binding` (plan §4.6) so a
5
+ * model's scoring is **lineage-tracked**. A binding ties an `MJ: ML Models` row to
6
+ * the `MJ: Record Processes` row that scores it, the target entity/column where
7
+ * scores land, the {@link ScoringBindingMode}, and monitoring fields
8
+ * (`LastScoredAt` / `LastRowCount`). Used by both the on-demand and scheduled
9
+ * scoring paths (the Remote-Op + scheduled-trigger wiring is a later phase — this
10
+ * helper builds the binding now).
11
+ *
12
+ * The entity-creation seam is injected ({@link IEntityFactory}, shared with the
13
+ * training engine) so this helper is unit-testable with no live database.
14
+ */
15
+ import { LogError } from '@memberjunction/core';
16
+ /**
17
+ * Create or update a `MJ: ML Model Scoring Binding`. Returns the saved entity.
18
+ *
19
+ * @param input the binding fields (create when `bindingId` is omitted, else update)
20
+ * @param entityFactory the entity-creation seam (production: `MetadataEntityFactory`)
21
+ * @param contextUser request user — required server-side for isolation/audit
22
+ * @throws when the underlying `Save()` fails (surfaces `LatestResult.CompleteMessage`)
23
+ */
24
+ export async function upsertScoringBinding(input, entityFactory, contextUser) {
25
+ const binding = await entityFactory.getEntityObject('MJ: ML Model Scoring Bindings', contextUser);
26
+ if (input.bindingId) {
27
+ const loaded = await binding.Load(input.bindingId);
28
+ if (!loaded) {
29
+ throw new Error(`upsertScoringBinding: scoring binding '${input.bindingId}' not found`);
30
+ }
31
+ }
32
+ binding.MLModelID = input.mlModelId;
33
+ binding.RecordProcessID = input.recordProcessId;
34
+ if (input.targetEntityId !== undefined) {
35
+ binding.TargetEntityID = input.targetEntityId;
36
+ }
37
+ if (input.targetColumn !== undefined) {
38
+ binding.TargetColumn = input.targetColumn;
39
+ }
40
+ binding.Mode = input.mode ?? 'OnDemand';
41
+ if (input.lastScoredAt !== undefined) {
42
+ binding.LastScoredAt = input.lastScoredAt;
43
+ }
44
+ if (input.lastRowCount !== undefined) {
45
+ binding.LastRowCount = input.lastRowCount;
46
+ }
47
+ const saved = await binding.Save();
48
+ if (!saved) {
49
+ const message = binding.LatestResult?.CompleteMessage ?? 'unknown error';
50
+ LogError(`upsertScoringBinding: failed to save scoring binding for model '${input.mlModelId}': ${message}`);
51
+ throw new Error(`Failed to save ML Model Scoring Binding: ${message}`);
52
+ }
53
+ return binding;
54
+ }
55
+ /**
56
+ * Convenience wrapper to stamp a binding's monitoring fields after a scoring run
57
+ * — `LastScoredAt = now` and `LastRowCount = rowCount`. Creates the binding if it
58
+ * does not yet exist.
59
+ *
60
+ * @param bindingId existing binding id (omit to create)
61
+ * @param details the model + record-process ids the binding ties together
62
+ * @param rowCount the number of rows the run scored
63
+ * @param entityFactory the entity-creation seam
64
+ * @param contextUser request user
65
+ */
66
+ export async function recordScoringRun(bindingId, details, rowCount, entityFactory, contextUser) {
67
+ return upsertScoringBinding({
68
+ bindingId,
69
+ mlModelId: details.mlModelId,
70
+ recordProcessId: details.recordProcessId,
71
+ mode: details.mode,
72
+ lastScoredAt: new Date(),
73
+ lastRowCount: rowCount,
74
+ }, entityFactory, contextUser);
75
+ }
76
+ //# sourceMappingURL=scoring-binding.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scoring-binding.js","sourceRoot":"","sources":["../../src/scoring/scoring-binding.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,QAAQ,EAAiB,MAAM,sBAAsB,CAAC;AAmC/D;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,oBAAoB,CACxC,KAA0B,EAC1B,aAA6B,EAC7B,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AO,EAAE,CAAC,CAAC;QAC5G,MAAM,IAAI,KAAK,CAAC,4CAA4C,OAAO,EAAE,CAAC,CAAC;IACzE,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,SAA6B,EAC7B,OAAkF,EAClF,QAAgB,EAChB,aAA6B,EAC7B,WAAsB;IAEtB,OAAO,oBAAoB,CACzB;QACE,SAAS;QACT,SAAS,EAAE,OAAO,CAAC,SAAS;QAC5B,eAAe,EAAE,OAAO,CAAC,eAAe;QACxC,IAAI,EAAE,OAAO,CAAC,IAAI;QAClB,YAAY,EAAE,IAAI,IAAI,EAAE;QACxB,YAAY,EAAE,QAAQ;KACvB,EACD,aAAa,EACb,WAAW,CACZ,CAAC;AACJ,CAAC"}
@@ -0,0 +1,105 @@
1
+ /**
2
+ * @module scoring/scoring-process-shared
3
+ *
4
+ * Shared primitives for the two model-scoring Record-Process builders — the
5
+ * **scheduled** helper ({@link module:scheduling/scheduled-model-scoring}, recurring
6
+ * cron-driven write-back) and the **on-demand** helper
7
+ * ({@link module:scoring/scoring-process}, a single `WorkType='ML Model'` Record
8
+ * Process the UI run-now / generic scheduler dialog then targets). Both assemble the
9
+ * SAME kind of Record Process row + (optional) `MJ: ML Model Scoring Bindings` lineage
10
+ * row, differing only in trigger (schedule vs on-demand) and binding `Mode`
11
+ * (`'Scheduled'` vs `'OnDemand'`).
12
+ *
13
+ * Rather than copy-paste that contract twice, the shared shape + the field-population
14
+ * primitives live here: the scope model, the value-kind → result-ref mapping, the
15
+ * runtime-registered work-type constant, scope application onto the row, the model
16
+ * `Configuration` JSON, the (optional) write-back `OutputMapping`, scope validation,
17
+ * target-entity resolution, and the lineage-binding creation. The two helpers compose
18
+ * these primitives and own only their trigger-specific bits.
19
+ */
20
+ import { type UserInfo, type IMetadataProvider } from '@memberjunction/core';
21
+ import type { MJRecordProcessEntity, MJMLModelScoringBindingEntity } from '@memberjunction/core-entities';
22
+ import { type ScoringBindingMode } from './scoring-binding.js';
23
+ /**
24
+ * Which prediction value the write-back lands in the target column: the numeric
25
+ * `score` (probability / regression value — the default) or the predicted `class`
26
+ * label (classification). Maps to the `OutputMapping` result-ref `$.score` / `$.class`.
27
+ */
28
+ export type ScoringValueKind = 'score' | 'class';
29
+ /**
30
+ * The scope of records a scoring run covers. Exactly one selector must be populated —
31
+ * the common case is a `filter` (SQL predicate over the target entity, e.g. only active
32
+ * memberships), but a saved `viewId` or `listId` is also supported, as is `all` (the
33
+ * whole entity — "score everyone"). Mirrors the Record Set Processing `ScopeType` shapes
34
+ * (Filter / View / List); `all` is expressed as a `Filter` with an explicit all-rows
35
+ * predicate (`(1=1)`).
36
+ */
37
+ export interface ScoringScope {
38
+ /** A SQL filter (`ScopeFilter`) over the target entity selecting the rows to score. */
39
+ filter?: string;
40
+ /** A `User Views` id whose rows are scored (`ScopeViewID`). */
41
+ viewId?: string;
42
+ /** A `Lists` id whose member rows are scored (`ScopeListID`). */
43
+ listId?: string;
44
+ /**
45
+ * Score the WHOLE target entity ("score everyone"). When `true`, the run scores
46
+ * every row — expressed as `ScopeType='Filter'` with the explicit all-rows
47
+ * predicate `(1=1)`. Mutually exclusive with `filter` / `viewId` / `listId`.
48
+ */
49
+ all?: boolean;
50
+ }
51
+ /** The runtime-registered scoring work-type (PS2-1) — not in the CodeGen'd `WorkType` union. */
52
+ export declare const ML_MODEL_WORK_TYPE = "ML Model";
53
+ /** Set the `ScopeType` + corresponding scope field from the (validated, single-selector) scope. */
54
+ export declare function applyScope(rp: MJRecordProcessEntity, scope: ScoringScope): void;
55
+ /** The prediction result-ref the write-back maps into the column: `$.class` for a label, else `$.score`. */
56
+ export declare function outputRef(valueKind: ScoringValueKind | undefined): string;
57
+ /**
58
+ * Serialize the model `Configuration` JSON every scoring Record Process carries: the
59
+ * `MJ: ML Models` id to score with and the target-entity primary-key field (default
60
+ * `'ID'`). The `'ML Model'` work-type reads this at run time to load + apply the model.
61
+ */
62
+ export declare function modelConfiguration(modelId: string, primaryKeyField: string | undefined): string;
63
+ /**
64
+ * Serialize the write-back `OutputMapping` JSON mapping the (non-empty) `outputField`
65
+ * to the prediction result-ref for `valueKind`. Only called in write-back mode.
66
+ */
67
+ export declare function writeBackOutputMapping(outputField: string, valueKind: ScoringValueKind | undefined): string;
68
+ /**
69
+ * Create the `MJ: ML Model Scoring Bindings` lineage row for a just-saved scoring
70
+ * Record Process. Reuses the already-resolved `entityID` (no second metadata lookup)
71
+ * and the production `MetadataEntityFactory` over the same provider so the binding
72
+ * lands on the right server in multi-provider setups. `mode` distinguishes the
73
+ * scheduled (`'Scheduled'`) from the on-demand (`'OnDemand'`) caller.
74
+ *
75
+ * Fail-loud on save failure: {@link upsertScoringBinding} throws (after `LogError`)
76
+ * when the binding `Save()` fails, which propagates out of this helper. We do NOT
77
+ * swallow it — a scoring Record Process whose lineage binding is missing would score
78
+ * records but stay invisible to the model-prediction panel / production dashboard, the
79
+ * exact bug this wiring exists to prevent. The Record Process is already persisted at
80
+ * this point, so the failure is surfaced for operator follow-up rather than rolled back
81
+ * (there is no cross-row transaction across the two saves).
82
+ *
83
+ * @param modelId the `MJ: ML Models` id the binding scores with
84
+ * @param outputField the (non-empty) target column the prediction lands in
85
+ * @param recordProcessId the id of the just-saved scoring Record Process
86
+ * @param entityID the already-resolved target-entity id
87
+ * @param mode the binding mode — `'Scheduled'` or `'OnDemand'`
88
+ * @param provider the metadata provider the binding is created against
89
+ * @param contextUser request user — required server-side for isolation/audit
90
+ * @param contextLabel a short helper name used to prefix the contextual log on failure
91
+ */
92
+ export declare function createScoringBinding(modelId: string, outputField: string, recordProcessId: string, entityID: string, mode: ScoringBindingMode, provider: IMetadataProvider, contextUser: UserInfo | undefined, contextLabel: string): Promise<MJMLModelScoringBindingEntity>;
93
+ /**
94
+ * Count how many of the mutually-exclusive scope selectors are populated — the basis
95
+ * for the exactly-one-selector validation both helpers enforce.
96
+ */
97
+ export declare function countScopeSelectors(scope: ScoringScope | undefined): number;
98
+ /**
99
+ * Resolve the target entity's id from its name, throwing when the entity is unknown.
100
+ * `contextLabel` prefixes the error so the failing helper is identifiable.
101
+ */
102
+ export declare function resolveTargetEntityID(targetEntityName: string, provider: IMetadataProvider, contextLabel: string): string;
103
+ /** Whether a value is a non-empty (trimmed) string. */
104
+ export declare function isNonEmpty(value: string | undefined | null): value is string;
105
+ //# sourceMappingURL=scoring-process-shared.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scoring-process-shared.d.ts","sourceRoot":"","sources":["../../src/scoring/scoring-process-shared.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EAAY,KAAK,QAAQ,EAAE,KAAK,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACvF,OAAO,KAAK,EAAE,qBAAqB,EAAE,6BAA6B,EAAE,MAAM,+BAA+B,CAAC;AAC1G,OAAO,EAAwB,KAAK,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAGlF;;;;GAIG;AACH,MAAM,MAAM,gBAAgB,GAAG,OAAO,GAAG,OAAO,CAAC;AAEjD;;;;;;;GAOG;AACH,MAAM,WAAW,YAAY;IAC3B,uFAAuF;IACvF,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,+DAA+D;IAC/D,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,iEAAiE;IACjE,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;;OAIG;IACH,GAAG,CAAC,EAAE,OAAO,CAAC;CACf;AAED,gGAAgG;AAChG,eAAO,MAAM,kBAAkB,aAAa,CAAC;AAE7C,mGAAmG;AACnG,wBAAgB,UAAU,CAAC,EAAE,EAAE,qBAAqB,EAAE,KAAK,EAAE,YAAY,GAAG,IAAI,CAgB/E;AAED,4GAA4G;AAC5G,wBAAgB,SAAS,CAAC,SAAS,EAAE,gBAAgB,GAAG,SAAS,GAAG,MAAM,CAEzE;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,CAE/F;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,WAAW,EAAE,MAAM,EAAE,SAAS,EAAE,gBAAgB,GAAG,SAAS,GAAG,MAAM,CAE3G;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAsB,oBAAoB,CACxC,OAAO,EAAE,MAAM,EACf,WAAW,EAAE,MAAM,EACnB,eAAe,EAAE,MAAM,EACvB,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,kBAAkB,EACxB,QAAQ,EAAE,iBAAiB,EAC3B,WAAW,EAAE,QAAQ,GAAG,SAAS,EACjC,YAAY,EAAE,MAAM,GACnB,OAAO,CAAC,6BAA6B,CAAC,CAsBxC;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,YAAY,GAAG,SAAS,GAAG,MAAM,CAU3E;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CACnC,gBAAgB,EAAE,MAAM,EACxB,QAAQ,EAAE,iBAAiB,EAC3B,YAAY,EAAE,MAAM,GACnB,MAAM,CAMR;AAED,uDAAuD;AACvD,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,GAAG,KAAK,IAAI,MAAM,CAE5E"}
@@ -0,0 +1,141 @@
1
+ /**
2
+ * @module scoring/scoring-process-shared
3
+ *
4
+ * Shared primitives for the two model-scoring Record-Process builders — the
5
+ * **scheduled** helper ({@link module:scheduling/scheduled-model-scoring}, recurring
6
+ * cron-driven write-back) and the **on-demand** helper
7
+ * ({@link module:scoring/scoring-process}, a single `WorkType='ML Model'` Record
8
+ * Process the UI run-now / generic scheduler dialog then targets). Both assemble the
9
+ * SAME kind of Record Process row + (optional) `MJ: ML Model Scoring Bindings` lineage
10
+ * row, differing only in trigger (schedule vs on-demand) and binding `Mode`
11
+ * (`'Scheduled'` vs `'OnDemand'`).
12
+ *
13
+ * Rather than copy-paste that contract twice, the shared shape + the field-population
14
+ * primitives live here: the scope model, the value-kind → result-ref mapping, the
15
+ * runtime-registered work-type constant, scope application onto the row, the model
16
+ * `Configuration` JSON, the (optional) write-back `OutputMapping`, scope validation,
17
+ * target-entity resolution, and the lineage-binding creation. The two helpers compose
18
+ * these primitives and own only their trigger-specific bits.
19
+ */
20
+ import { LogError } from '@memberjunction/core';
21
+ import { upsertScoringBinding } from './scoring-binding.js';
22
+ import { MetadataEntityFactory } from '../training/seams.js';
23
+ /** The runtime-registered scoring work-type (PS2-1) — not in the CodeGen'd `WorkType` union. */
24
+ export const ML_MODEL_WORK_TYPE = 'ML Model';
25
+ /** Set the `ScopeType` + corresponding scope field from the (validated, single-selector) scope. */
26
+ export function applyScope(rp, scope) {
27
+ if (scope.all === true) {
28
+ // Whole entity ("score everyone") — a Filter with an explicit all-rows predicate.
29
+ rp.ScopeType = 'Filter';
30
+ rp.ScopeFilter = '(1=1)';
31
+ }
32
+ else if (scope.filter != null) {
33
+ rp.ScopeType = 'Filter';
34
+ rp.ScopeFilter = scope.filter;
35
+ }
36
+ else if (scope.viewId != null) {
37
+ rp.ScopeType = 'View';
38
+ rp.ScopeViewID = scope.viewId;
39
+ }
40
+ else {
41
+ // The exactly-one-selector rule guarantees listId is the remaining case.
42
+ rp.ScopeType = 'List';
43
+ rp.ScopeListID = scope.listId;
44
+ }
45
+ }
46
+ /** The prediction result-ref the write-back maps into the column: `$.class` for a label, else `$.score`. */
47
+ export function outputRef(valueKind) {
48
+ return valueKind === 'class' ? '$.class' : '$.score';
49
+ }
50
+ /**
51
+ * Serialize the model `Configuration` JSON every scoring Record Process carries: the
52
+ * `MJ: ML Models` id to score with and the target-entity primary-key field (default
53
+ * `'ID'`). The `'ML Model'` work-type reads this at run time to load + apply the model.
54
+ */
55
+ export function modelConfiguration(modelId, primaryKeyField) {
56
+ return JSON.stringify({ modelId, primaryKeyField: primaryKeyField ?? 'ID' });
57
+ }
58
+ /**
59
+ * Serialize the write-back `OutputMapping` JSON mapping the (non-empty) `outputField`
60
+ * to the prediction result-ref for `valueKind`. Only called in write-back mode.
61
+ */
62
+ export function writeBackOutputMapping(outputField, valueKind) {
63
+ return JSON.stringify({ fields: { [outputField]: outputRef(valueKind) } });
64
+ }
65
+ /**
66
+ * Create the `MJ: ML Model Scoring Bindings` lineage row for a just-saved scoring
67
+ * Record Process. Reuses the already-resolved `entityID` (no second metadata lookup)
68
+ * and the production `MetadataEntityFactory` over the same provider so the binding
69
+ * lands on the right server in multi-provider setups. `mode` distinguishes the
70
+ * scheduled (`'Scheduled'`) from the on-demand (`'OnDemand'`) caller.
71
+ *
72
+ * Fail-loud on save failure: {@link upsertScoringBinding} throws (after `LogError`)
73
+ * when the binding `Save()` fails, which propagates out of this helper. We do NOT
74
+ * swallow it — a scoring Record Process whose lineage binding is missing would score
75
+ * records but stay invisible to the model-prediction panel / production dashboard, the
76
+ * exact bug this wiring exists to prevent. The Record Process is already persisted at
77
+ * this point, so the failure is surfaced for operator follow-up rather than rolled back
78
+ * (there is no cross-row transaction across the two saves).
79
+ *
80
+ * @param modelId the `MJ: ML Models` id the binding scores with
81
+ * @param outputField the (non-empty) target column the prediction lands in
82
+ * @param recordProcessId the id of the just-saved scoring Record Process
83
+ * @param entityID the already-resolved target-entity id
84
+ * @param mode the binding mode — `'Scheduled'` or `'OnDemand'`
85
+ * @param provider the metadata provider the binding is created against
86
+ * @param contextUser request user — required server-side for isolation/audit
87
+ * @param contextLabel a short helper name used to prefix the contextual log on failure
88
+ */
89
+ export async function createScoringBinding(modelId, outputField, recordProcessId, entityID, mode, provider, contextUser, contextLabel) {
90
+ try {
91
+ return await upsertScoringBinding({
92
+ mlModelId: modelId,
93
+ recordProcessId,
94
+ targetEntityId: entityID,
95
+ targetColumn: outputField,
96
+ mode,
97
+ }, new MetadataEntityFactory(provider), contextUser);
98
+ }
99
+ catch (e) {
100
+ // upsertScoringBinding already LogError'd the underlying Save() failure; add the
101
+ // caller's context (the saved RP id) so the inconsistency is traceable.
102
+ LogError(`${contextLabel}: Record Process '${recordProcessId}' saved but its scoring binding ` +
103
+ `failed for model '${modelId}': ${e instanceof Error ? e.message : String(e)}`);
104
+ throw e;
105
+ }
106
+ }
107
+ /**
108
+ * Count how many of the mutually-exclusive scope selectors are populated — the basis
109
+ * for the exactly-one-selector validation both helpers enforce.
110
+ */
111
+ export function countScopeSelectors(scope) {
112
+ if (!scope) {
113
+ return 0;
114
+ }
115
+ let count = 0;
116
+ if (isNonEmpty(scope.filter))
117
+ count++;
118
+ if (isNonEmpty(scope.viewId))
119
+ count++;
120
+ if (isNonEmpty(scope.listId))
121
+ count++;
122
+ if (scope.all === true)
123
+ count++;
124
+ return count;
125
+ }
126
+ /**
127
+ * Resolve the target entity's id from its name, throwing when the entity is unknown.
128
+ * `contextLabel` prefixes the error so the failing helper is identifiable.
129
+ */
130
+ export function resolveTargetEntityID(targetEntityName, provider, contextLabel) {
131
+ const entity = provider.EntityByName(targetEntityName);
132
+ if (!entity) {
133
+ throw new Error(`${contextLabel}: target entity '${targetEntityName}' was not found in metadata.`);
134
+ }
135
+ return entity.ID;
136
+ }
137
+ /** Whether a value is a non-empty (trimmed) string. */
138
+ export function isNonEmpty(value) {
139
+ return typeof value === 'string' && value.trim().length > 0;
140
+ }
141
+ //# sourceMappingURL=scoring-process-shared.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scoring-process-shared.js","sourceRoot":"","sources":["../../src/scoring/scoring-process-shared.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EAAE,QAAQ,EAAyC,MAAM,sBAAsB,CAAC;AAEvF,OAAO,EAAE,oBAAoB,EAA2B,MAAM,mBAAmB,CAAC;AAClF,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAgC1D,gGAAgG;AAChG,MAAM,CAAC,MAAM,kBAAkB,GAAG,UAAU,CAAC;AAE7C,mG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