@memberjunction/predictive-studio 6.2.0 → 6.3.0-edge.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 (390) hide show
  1. package/README.md +16 -11
  2. package/dist/actions/base-predictive-studio.action.d.ts +7 -0
  3. package/dist/actions/base-predictive-studio.action.d.ts.map +1 -1
  4. package/dist/actions/base-predictive-studio.action.js +22 -0
  5. package/dist/actions/base-predictive-studio.action.js.map +1 -1
  6. package/dist/actions/driver-classes.d.ts +2 -0
  7. package/dist/actions/driver-classes.d.ts.map +1 -1
  8. package/dist/actions/driver-classes.js +2 -0
  9. package/dist/actions/driver-classes.js.map +1 -1
  10. package/dist/actions/evaluate-drift.action.d.ts +100 -0
  11. package/dist/actions/evaluate-drift.action.d.ts.map +1 -0
  12. package/dist/actions/evaluate-drift.action.js +512 -0
  13. package/dist/actions/evaluate-drift.action.js.map +1 -0
  14. package/dist/actions/index.d.ts +3 -0
  15. package/dist/actions/index.d.ts.map +1 -1
  16. package/dist/actions/index.js +7 -0
  17. package/dist/actions/index.js.map +1 -1
  18. package/dist/actions/migrate-pipelines.action.d.ts +19 -0
  19. package/dist/actions/migrate-pipelines.action.d.ts.map +1 -0
  20. package/dist/actions/migrate-pipelines.action.js +51 -0
  21. package/dist/actions/migrate-pipelines.action.js.map +1 -0
  22. package/dist/actions/promote-model.action.d.ts +12 -1
  23. package/dist/actions/promote-model.action.d.ts.map +1 -1
  24. package/dist/actions/promote-model.action.js +7 -2
  25. package/dist/actions/promote-model.action.js.map +1 -1
  26. package/dist/actions/promote-model.gate.d.ts +31 -2
  27. package/dist/actions/promote-model.gate.d.ts.map +1 -1
  28. package/dist/actions/promote-model.gate.js +84 -5
  29. package/dist/actions/promote-model.gate.js.map +1 -1
  30. package/dist/actions/run-experiment.action.d.ts.map +1 -1
  31. package/dist/actions/run-experiment.action.js +5 -4
  32. package/dist/actions/run-experiment.action.js.map +1 -1
  33. package/dist/actions/schedule-model-scoring.action.js +2 -2
  34. package/dist/actions/schedule-model-scoring.action.js.map +1 -1
  35. package/dist/actions/score-record-set.action.js +1 -1
  36. package/dist/actions/score-record-set.action.js.map +1 -1
  37. package/dist/actions/score-record-set.runner.d.ts +2 -2
  38. package/dist/actions/score-record-set.runner.js +3 -3
  39. package/dist/actions/score-record-set.runner.js.map +1 -1
  40. package/dist/actions/train-model.action.d.ts +28 -25
  41. package/dist/actions/train-model.action.d.ts.map +1 -1
  42. package/dist/actions/train-model.action.js +50 -39
  43. package/dist/actions/train-model.action.js.map +1 -1
  44. package/dist/agent/index.d.ts +1 -1
  45. package/dist/agent/index.js +1 -1
  46. package/dist/agent/modeling-plan-to-pipeline.d.ts +0 -2
  47. package/dist/agent/modeling-plan-to-pipeline.d.ts.map +1 -1
  48. package/dist/agent/modeling-plan-to-pipeline.js +30 -39
  49. package/dist/agent/modeling-plan-to-pipeline.js.map +1 -1
  50. package/dist/agent/pipeline-builder-agent.d.ts +47 -18
  51. package/dist/agent/pipeline-builder-agent.d.ts.map +1 -1
  52. package/dist/agent/pipeline-builder-agent.js +161 -92
  53. package/dist/agent/pipeline-builder-agent.js.map +1 -1
  54. package/dist/agent/pipeline-builder.d.ts +178 -56
  55. package/dist/agent/pipeline-builder.d.ts.map +1 -1
  56. package/dist/agent/pipeline-builder.js +333 -234
  57. package/dist/agent/pipeline-builder.js.map +1 -1
  58. package/dist/experiment/budget.d.ts +61 -0
  59. package/dist/experiment/budget.d.ts.map +1 -0
  60. package/dist/experiment/budget.js +72 -0
  61. package/dist/experiment/budget.js.map +1 -0
  62. package/dist/experiment/experiment-orchestrator.d.ts +43 -7
  63. package/dist/experiment/experiment-orchestrator.d.ts.map +1 -1
  64. package/dist/experiment/experiment-orchestrator.js +130 -33
  65. package/dist/experiment/experiment-orchestrator.js.map +1 -1
  66. package/dist/experiment/index.d.ts +2 -0
  67. package/dist/experiment/index.d.ts.map +1 -1
  68. package/dist/experiment/index.js +2 -0
  69. package/dist/experiment/index.js.map +1 -1
  70. package/dist/experiment/leaderboard.d.ts +15 -15
  71. package/dist/experiment/leaderboard.d.ts.map +1 -1
  72. package/dist/experiment/leaderboard.js +44 -18
  73. package/dist/experiment/leaderboard.js.map +1 -1
  74. package/dist/experiment/scores.d.ts +32 -0
  75. package/dist/experiment/scores.d.ts.map +1 -0
  76. package/dist/experiment/scores.js +62 -0
  77. package/dist/experiment/scores.js.map +1 -0
  78. package/dist/experiment/seams.d.ts +23 -20
  79. package/dist/experiment/seams.d.ts.map +1 -1
  80. package/dist/experiment/seams.js +54 -56
  81. package/dist/experiment/seams.js.map +1 -1
  82. package/dist/experiment/types.d.ts +55 -10
  83. package/dist/experiment/types.d.ts.map +1 -1
  84. package/dist/experiment/types.js.map +1 -1
  85. package/dist/feature-assembly/as-of/as-of-assembler.d.ts +412 -0
  86. package/dist/feature-assembly/as-of/as-of-assembler.d.ts.map +1 -0
  87. package/dist/feature-assembly/as-of/as-of-assembler.js +1239 -0
  88. package/dist/feature-assembly/as-of/as-of-assembler.js.map +1 -0
  89. package/dist/feature-assembly/as-of/feature-resolution.d.ts +84 -0
  90. package/dist/feature-assembly/as-of/feature-resolution.d.ts.map +1 -0
  91. package/dist/feature-assembly/as-of/feature-resolution.js +229 -0
  92. package/dist/feature-assembly/as-of/feature-resolution.js.map +1 -0
  93. package/dist/feature-assembly/as-of/index.d.ts +15 -0
  94. package/dist/feature-assembly/as-of/index.d.ts.map +1 -0
  95. package/dist/feature-assembly/as-of/index.js +15 -0
  96. package/dist/feature-assembly/as-of/index.js.map +1 -0
  97. package/dist/feature-assembly/as-of/read-by-keys.d.ts +30 -0
  98. package/dist/feature-assembly/as-of/read-by-keys.d.ts.map +1 -0
  99. package/dist/feature-assembly/as-of/read-by-keys.js +51 -0
  100. package/dist/feature-assembly/as-of/read-by-keys.js.map +1 -0
  101. package/dist/feature-assembly/as-of/record-history.d.ts +256 -0
  102. package/dist/feature-assembly/as-of/record-history.d.ts.map +1 -0
  103. package/dist/feature-assembly/as-of/record-history.js +505 -0
  104. package/dist/feature-assembly/as-of/record-history.js.map +1 -0
  105. package/dist/feature-assembly/as-of/refusal.d.ts +19 -0
  106. package/dist/feature-assembly/as-of/refusal.d.ts.map +1 -0
  107. package/dist/feature-assembly/as-of/refusal.js +13 -0
  108. package/dist/feature-assembly/as-of/refusal.js.map +1 -0
  109. package/dist/feature-assembly/as-of/series-features.d.ts +65 -0
  110. package/dist/feature-assembly/as-of/series-features.d.ts.map +1 -0
  111. package/dist/feature-assembly/as-of/series-features.js +97 -0
  112. package/dist/feature-assembly/as-of/series-features.js.map +1 -0
  113. package/dist/feature-assembly/as-of/windowed-aggregate.d.ts +36 -0
  114. package/dist/feature-assembly/as-of/windowed-aggregate.d.ts.map +1 -0
  115. package/dist/feature-assembly/as-of/windowed-aggregate.js +99 -0
  116. package/dist/feature-assembly/as-of/windowed-aggregate.js.map +1 -0
  117. package/dist/feature-assembly/as-of.d.ts +1 -9
  118. package/dist/feature-assembly/as-of.d.ts.map +1 -1
  119. package/dist/feature-assembly/as-of.js +2 -19
  120. package/dist/feature-assembly/as-of.js.map +1 -1
  121. package/dist/feature-assembly/assembly-metadata.d.ts +34 -0
  122. package/dist/feature-assembly/assembly-metadata.d.ts.map +1 -0
  123. package/dist/feature-assembly/assembly-metadata.js +26 -0
  124. package/dist/feature-assembly/assembly-metadata.js.map +1 -0
  125. package/dist/feature-assembly/data-access.d.ts +21 -2
  126. package/dist/feature-assembly/data-access.d.ts.map +1 -1
  127. package/dist/feature-assembly/data-access.js +14 -0
  128. package/dist/feature-assembly/data-access.js.map +1 -1
  129. package/dist/feature-assembly/feature-assembly-executor.d.ts.map +1 -1
  130. package/dist/feature-assembly/feature-assembly-executor.js +5 -2
  131. package/dist/feature-assembly/feature-assembly-executor.js.map +1 -1
  132. package/dist/feature-assembly/index.d.ts +3 -0
  133. package/dist/feature-assembly/index.d.ts.map +1 -1
  134. package/dist/feature-assembly/index.js +3 -0
  135. package/dist/feature-assembly/index.js.map +1 -1
  136. package/dist/feature-assembly/leakage-guard.d.ts +1 -1
  137. package/dist/feature-assembly/leakage-guard.js +1 -1
  138. package/dist/feature-assembly/read-policy.d.ts +27 -0
  139. package/dist/feature-assembly/read-policy.d.ts.map +1 -0
  140. package/dist/feature-assembly/read-policy.js +63 -0
  141. package/dist/feature-assembly/read-policy.js.map +1 -0
  142. package/dist/feature-pipelines/feature-pipeline-engine.d.ts.map +1 -1
  143. package/dist/feature-pipelines/feature-pipeline-engine.js +3 -1
  144. package/dist/feature-pipelines/feature-pipeline-engine.js.map +1 -1
  145. package/dist/index.d.ts +5 -2
  146. package/dist/index.d.ts.map +1 -1
  147. package/dist/index.js +16 -4
  148. package/dist/index.js.map +1 -1
  149. package/dist/maintenance/index.d.ts +1 -0
  150. package/dist/maintenance/index.d.ts.map +1 -1
  151. package/dist/maintenance/index.js +1 -0
  152. package/dist/maintenance/index.js.map +1 -1
  153. package/dist/maintenance/maintenance-engine.d.ts +16 -19
  154. package/dist/maintenance/maintenance-engine.d.ts.map +1 -1
  155. package/dist/maintenance/maintenance-engine.js +53 -53
  156. package/dist/maintenance/maintenance-engine.js.map +1 -1
  157. package/dist/maintenance/metrics.d.ts +19 -15
  158. package/dist/maintenance/metrics.d.ts.map +1 -1
  159. package/dist/maintenance/metrics.js +29 -24
  160. package/dist/maintenance/metrics.js.map +1 -1
  161. package/dist/maintenance/psi-drift-detector.d.ts +246 -0
  162. package/dist/maintenance/psi-drift-detector.d.ts.map +1 -0
  163. package/dist/maintenance/psi-drift-detector.js +1002 -0
  164. package/dist/maintenance/psi-drift-detector.js.map +1 -0
  165. package/dist/maintenance/types.d.ts +11 -2
  166. package/dist/maintenance/types.d.ts.map +1 -1
  167. package/dist/maintenance/types.js.map +1 -1
  168. package/dist/migration/index.d.ts +8 -0
  169. package/dist/migration/index.d.ts.map +1 -0
  170. package/dist/migration/index.js +8 -0
  171. package/dist/migration/index.js.map +1 -0
  172. package/dist/migration/legacy-pipeline-migration.d.ts +138 -0
  173. package/dist/migration/legacy-pipeline-migration.d.ts.map +1 -0
  174. package/dist/migration/legacy-pipeline-migration.js +273 -0
  175. package/dist/migration/legacy-pipeline-migration.js.map +1 -0
  176. package/dist/operations/delegation.d.ts +58 -46
  177. package/dist/operations/delegation.d.ts.map +1 -1
  178. package/dist/operations/delegation.js +90 -77
  179. package/dist/operations/delegation.js.map +1 -1
  180. package/dist/operations/promote-model.operation.d.ts +2 -2
  181. package/dist/operations/promote-model.operation.d.ts.map +1 -1
  182. package/dist/operations/promote-model.operation.js +6 -2
  183. package/dist/operations/promote-model.operation.js.map +1 -1
  184. package/dist/operations/refusals.d.ts +5 -0
  185. package/dist/operations/refusals.d.ts.map +1 -1
  186. package/dist/operations/refusals.js +26 -1
  187. package/dist/operations/refusals.js.map +1 -1
  188. package/dist/operations/start-experiment-session.operation.js +3 -3
  189. package/dist/operations/train-model.mapping.d.ts +91 -0
  190. package/dist/operations/train-model.mapping.d.ts.map +1 -0
  191. package/dist/operations/train-model.mapping.js +145 -0
  192. package/dist/operations/train-model.mapping.js.map +1 -0
  193. package/dist/operations/train-model.operation.d.ts +14 -9
  194. package/dist/operations/train-model.operation.d.ts.map +1 -1
  195. package/dist/operations/train-model.operation.js +30 -51
  196. package/dist/operations/train-model.operation.js.map +1 -1
  197. package/dist/prediction-unit/decision-date-advance.d.ts +46 -0
  198. package/dist/prediction-unit/decision-date-advance.d.ts.map +1 -0
  199. package/dist/prediction-unit/decision-date-advance.js +79 -0
  200. package/dist/prediction-unit/decision-date-advance.js.map +1 -0
  201. package/dist/prediction-unit/index.d.ts +12 -0
  202. package/dist/prediction-unit/index.d.ts.map +1 -0
  203. package/dist/prediction-unit/index.js +12 -0
  204. package/dist/prediction-unit/index.js.map +1 -0
  205. package/dist/prediction-unit/target-validation.d.ts +21 -0
  206. package/dist/prediction-unit/target-validation.d.ts.map +1 -0
  207. package/dist/prediction-unit/target-validation.js +54 -0
  208. package/dist/prediction-unit/target-validation.js.map +1 -0
  209. package/dist/prediction-unit/unit-row-reader.d.ts +108 -0
  210. package/dist/prediction-unit/unit-row-reader.d.ts.map +1 -0
  211. package/dist/prediction-unit/unit-row-reader.js +348 -0
  212. package/dist/prediction-unit/unit-row-reader.js.map +1 -0
  213. package/dist/prediction-unit/unit-store.d.ts +28 -0
  214. package/dist/prediction-unit/unit-store.d.ts.map +1 -0
  215. package/dist/prediction-unit/unit-store.js +41 -0
  216. package/dist/prediction-unit/unit-store.js.map +1 -0
  217. package/dist/prediction-unit/unit-versioning.d.ts +43 -0
  218. package/dist/prediction-unit/unit-versioning.d.ts.map +1 -0
  219. package/dist/prediction-unit/unit-versioning.js +71 -0
  220. package/dist/prediction-unit/unit-versioning.js.map +1 -0
  221. package/dist/protocol/index.d.ts +9 -0
  222. package/dist/protocol/index.d.ts.map +1 -0
  223. package/dist/protocol/index.js +9 -0
  224. package/dist/protocol/index.js.map +1 -0
  225. package/dist/protocol/protocol-defaults.d.ts +37 -0
  226. package/dist/protocol/protocol-defaults.d.ts.map +1 -0
  227. package/dist/protocol/protocol-defaults.js +59 -0
  228. package/dist/protocol/protocol-defaults.js.map +1 -0
  229. package/dist/protocol/protocol-versioning.d.ts +46 -0
  230. package/dist/protocol/protocol-versioning.d.ts.map +1 -0
  231. package/dist/protocol/protocol-versioning.js +48 -0
  232. package/dist/protocol/protocol-versioning.js.map +1 -0
  233. package/dist/protocol/search-guard.d.ts +45 -0
  234. package/dist/protocol/search-guard.d.ts.map +1 -0
  235. package/dist/protocol/search-guard.js +50 -0
  236. package/dist/protocol/search-guard.js.map +1 -0
  237. package/dist/scoring/artifact-loader.d.ts +5 -32
  238. package/dist/scoring/artifact-loader.d.ts.map +1 -1
  239. package/dist/scoring/artifact-loader.js +4 -59
  240. package/dist/scoring/artifact-loader.js.map +1 -1
  241. package/dist/scoring/auto-train.d.ts +25 -5
  242. package/dist/scoring/auto-train.d.ts.map +1 -1
  243. package/dist/scoring/auto-train.js +48 -31
  244. package/dist/scoring/auto-train.js.map +1 -1
  245. package/dist/scoring/index.d.ts +3 -0
  246. package/dist/scoring/index.d.ts.map +1 -1
  247. package/dist/scoring/index.js +3 -0
  248. package/dist/scoring/index.js.map +1 -1
  249. package/dist/scoring/ml-model-inference-processor.d.ts +137 -10
  250. package/dist/scoring/ml-model-inference-processor.d.ts.map +1 -1
  251. package/dist/scoring/ml-model-inference-processor.js +383 -40
  252. package/dist/scoring/ml-model-inference-processor.js.map +1 -1
  253. package/dist/scoring/model-readiness.d.ts +45 -0
  254. package/dist/scoring/model-readiness.d.ts.map +1 -1
  255. package/dist/scoring/model-readiness.js +49 -0
  256. package/dist/scoring/model-readiness.js.map +1 -1
  257. package/dist/scoring/register.d.ts +8 -3
  258. package/dist/scoring/register.d.ts.map +1 -1
  259. package/dist/scoring/register.js +28 -4
  260. package/dist/scoring/register.js.map +1 -1
  261. package/dist/scoring/seams.d.ts +18 -2
  262. package/dist/scoring/seams.d.ts.map +1 -1
  263. package/dist/scoring/seams.js +35 -10
  264. package/dist/scoring/seams.js.map +1 -1
  265. package/dist/scoring/shadow-scoring.d.ts +245 -0
  266. package/dist/scoring/shadow-scoring.d.ts.map +1 -0
  267. package/dist/scoring/shadow-scoring.js +510 -0
  268. package/dist/scoring/shadow-scoring.js.map +1 -0
  269. package/dist/scoring/startup-register.d.ts +3 -3
  270. package/dist/scoring/startup-register.d.ts.map +1 -1
  271. package/dist/scoring/startup-register.js +10 -4
  272. package/dist/scoring/startup-register.js.map +1 -1
  273. package/dist/scoring/storage-provider-artifact-loader.d.ts +14 -0
  274. package/dist/scoring/storage-provider-artifact-loader.d.ts.map +1 -0
  275. package/dist/scoring/storage-provider-artifact-loader.js +47 -0
  276. package/dist/scoring/storage-provider-artifact-loader.js.map +1 -0
  277. package/dist/scoring/training-keys.d.ts +27 -0
  278. package/dist/scoring/training-keys.d.ts.map +1 -0
  279. package/dist/scoring/training-keys.js +54 -0
  280. package/dist/scoring/training-keys.js.map +1 -0
  281. package/dist/scoring/types.d.ts +72 -7
  282. package/dist/scoring/types.d.ts.map +1 -1
  283. package/dist/scoring/types.js +4 -0
  284. package/dist/scoring/types.js.map +1 -1
  285. package/dist/sidecar-provider.d.ts +2 -2
  286. package/dist/sidecar-provider.js +3 -3
  287. package/dist/snapshot/code-version.d.ts +16 -0
  288. package/dist/snapshot/code-version.d.ts.map +1 -0
  289. package/dist/snapshot/code-version.js +39 -0
  290. package/dist/snapshot/code-version.js.map +1 -0
  291. package/dist/snapshot/holdout-carver.d.ts +110 -0
  292. package/dist/snapshot/holdout-carver.d.ts.map +1 -0
  293. package/dist/snapshot/holdout-carver.js +171 -0
  294. package/dist/snapshot/holdout-carver.js.map +1 -0
  295. package/dist/snapshot/index.d.ts +17 -0
  296. package/dist/snapshot/index.d.ts.map +1 -0
  297. package/dist/snapshot/index.js +17 -0
  298. package/dist/snapshot/index.js.map +1 -0
  299. package/dist/snapshot/snapshot-builder.d.ts +152 -0
  300. package/dist/snapshot/snapshot-builder.d.ts.map +1 -0
  301. package/dist/snapshot/snapshot-builder.js +286 -0
  302. package/dist/snapshot/snapshot-builder.js.map +1 -0
  303. package/dist/snapshot/snapshot-file-store.d.ts +161 -0
  304. package/dist/snapshot/snapshot-file-store.d.ts.map +1 -0
  305. package/dist/snapshot/snapshot-file-store.js +204 -0
  306. package/dist/snapshot/snapshot-file-store.js.map +1 -0
  307. package/dist/snapshot/snapshot-hash.d.ts +6 -0
  308. package/dist/snapshot/snapshot-hash.d.ts.map +1 -0
  309. package/dist/snapshot/snapshot-hash.js +16 -0
  310. package/dist/snapshot/snapshot-hash.js.map +1 -0
  311. package/dist/snapshot/snapshot-manifest.d.ts +43 -0
  312. package/dist/snapshot/snapshot-manifest.d.ts.map +1 -0
  313. package/dist/snapshot/snapshot-manifest.js +43 -0
  314. package/dist/snapshot/snapshot-manifest.js.map +1 -0
  315. package/dist/snapshot/snapshot-retrainer.d.ts +107 -0
  316. package/dist/snapshot/snapshot-retrainer.d.ts.map +1 -0
  317. package/dist/snapshot/snapshot-retrainer.js +194 -0
  318. package/dist/snapshot/snapshot-retrainer.js.map +1 -0
  319. package/dist/snapshot/snapshot-serialization.d.ts +99 -0
  320. package/dist/snapshot/snapshot-serialization.d.ts.map +1 -0
  321. package/dist/snapshot/snapshot-serialization.js +191 -0
  322. package/dist/snapshot/snapshot-serialization.js.map +1 -0
  323. package/dist/snapshot/training-snapshot-store.d.ts +38 -0
  324. package/dist/snapshot/training-snapshot-store.d.ts.map +1 -0
  325. package/dist/snapshot/training-snapshot-store.js +41 -0
  326. package/dist/snapshot/training-snapshot-store.js.map +1 -0
  327. package/dist/storage/ps-storage-provider.d.ts +108 -0
  328. package/dist/storage/ps-storage-provider.d.ts.map +1 -0
  329. package/dist/storage/ps-storage-provider.js +154 -0
  330. package/dist/storage/ps-storage-provider.js.map +1 -0
  331. package/dist/training/artifact-store.d.ts +12 -103
  332. package/dist/training/artifact-store.d.ts.map +1 -1
  333. package/dist/training/artifact-store.js +13 -137
  334. package/dist/training/artifact-store.js.map +1 -1
  335. package/dist/training/compute-cost.d.ts +23 -0
  336. package/dist/training/compute-cost.d.ts.map +1 -0
  337. package/dist/training/compute-cost.js +36 -0
  338. package/dist/training/compute-cost.js.map +1 -0
  339. package/dist/training/evaluation-protocol-store.d.ts +53 -0
  340. package/dist/training/evaluation-protocol-store.d.ts.map +1 -0
  341. package/dist/training/evaluation-protocol-store.js +54 -0
  342. package/dist/training/evaluation-protocol-store.js.map +1 -0
  343. package/dist/training/index.d.ts +9 -1
  344. package/dist/training/index.d.ts.map +1 -1
  345. package/dist/training/index.js +9 -1
  346. package/dist/training/index.js.map +1 -1
  347. package/dist/training/locked-holdout.d.ts +19 -4
  348. package/dist/training/locked-holdout.d.ts.map +1 -1
  349. package/dist/training/locked-holdout.js +29 -5
  350. package/dist/training/locked-holdout.js.map +1 -1
  351. package/dist/training/seams.d.ts +34 -8
  352. package/dist/training/seams.d.ts.map +1 -1
  353. package/dist/training/seams.js +74 -18
  354. package/dist/training/seams.js.map +1 -1
  355. package/dist/training/storage-provider-artifact-store.d.ts +49 -0
  356. package/dist/training/storage-provider-artifact-store.d.ts.map +1 -0
  357. package/dist/training/storage-provider-artifact-store.js +147 -0
  358. package/dist/training/storage-provider-artifact-store.js.map +1 -0
  359. package/dist/training/trainer-model-lineage.d.ts +32 -0
  360. package/dist/training/trainer-model-lineage.d.ts.map +1 -0
  361. package/dist/training/trainer-model-lineage.js +62 -0
  362. package/dist/training/trainer-model-lineage.js.map +1 -0
  363. package/dist/training/trainer-request.d.ts +50 -0
  364. package/dist/training/trainer-request.d.ts.map +1 -0
  365. package/dist/training/trainer-request.js +65 -0
  366. package/dist/training/trainer-request.js.map +1 -0
  367. package/dist/training/trainer-result.d.ts +30 -0
  368. package/dist/training/trainer-result.d.ts.map +1 -0
  369. package/dist/training/trainer-result.js +40 -0
  370. package/dist/training/trainer-result.js.map +1 -0
  371. package/dist/training/training-engine.d.ts +417 -64
  372. package/dist/training/training-engine.d.ts.map +1 -1
  373. package/dist/training/training-engine.js +869 -178
  374. package/dist/training/training-engine.js.map +1 -1
  375. package/dist/training/training-refusal.d.ts +15 -0
  376. package/dist/training/training-refusal.d.ts.map +1 -0
  377. package/dist/training/training-refusal.js +62 -0
  378. package/dist/training/training-refusal.js.map +1 -0
  379. package/dist/training/types.d.ts +133 -41
  380. package/dist/training/types.d.ts.map +1 -1
  381. package/dist/training/types.js +4 -4
  382. package/dist/training/unit-model-lineage.d.ts +72 -0
  383. package/dist/training/unit-model-lineage.d.ts.map +1 -0
  384. package/dist/training/unit-model-lineage.js +288 -0
  385. package/dist/training/unit-model-lineage.js.map +1 -0
  386. package/package.json +16 -13
  387. package/dist/operations/__tests__/helpers.d.ts +0 -30
  388. package/dist/operations/__tests__/helpers.d.ts.map +0 -1
  389. package/dist/operations/__tests__/helpers.js +0 -44
  390. package/dist/operations/__tests__/helpers.js.map +0 -1
@@ -18,7 +18,12 @@
18
18
  * 2. **Assemble features** via the SAME {@link FeatureAssemblyExecutor} as
19
19
  * training, in the **on-demand / transform-only** context, using the model's
20
20
  * FROZEN `FeatureSchema` + `FittedPreprocessing` (never re-fit — the anti-skew
21
- * guarantee, §6.2). The matrix shape matches what the model expects.
21
+ * guarantee, §6.2). The matrix shape matches what the model expects. A model
22
+ * trained on a Prediction Unit is assembled instead by
23
+ * {@link MLModelInferenceProcessor.AssembleForScoring}: the scoped rows are dated
24
+ * by the unit's decision-date rule and read as of that date through the same
25
+ * `AsOfFeatureAssembler` training used, with the feature columns and categorical
26
+ * levels training stored in the model Lineage.
22
27
  * 3. **Call the sidecar `/predict`** with the artifact + frozen preprocessing +
23
28
  * feature schema + the assembled row(s) → predictions (score + class).
24
29
  * 4. **Produce the per-record `RecordResult`** carrying the prediction.
@@ -47,11 +52,25 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
47
52
  var __metadata = (this && this.__metadata) || function (k, v) {
48
53
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
49
54
  };
50
- import { RegisterClass } from '@memberjunction/global';
55
+ var MLModelInferenceProcessor_1;
56
+ import { NormalizeUUID, RegisterClass, UserScopedCacheKey, UUIDSet, UUIDsEqual } from '@memberjunction/global';
51
57
  import { LogError, RunView } from '@memberjunction/core';
52
- import { resolveOutcomeConfig, resolveScoreBand, resolveOutcomeStyle, } from '@memberjunction/predictive-studio-core';
58
+ import { UtcDay, resolveOutcomeConfig, resolveScoreBand, resolveOutcomeStyle, LABEL_COLUMN, PredictionUnit, } from '@memberjunction/predictive-studio-core';
53
59
  import { FeatureAssemblyExecutor } from '../feature-assembly/index.js';
54
- import { ModelHasTrainedArtifact, ModelNeedsTrainingMessage, ModelArtifactMissingMessage, ModelNeedsTrainingError, ModelNotScorableError, } from './model-readiness.js';
60
+ import { RunViewDataAccess } from '../feature-assembly/data-access.js';
61
+ import { ProviderAssemblyMetadata } from '../feature-assembly/assembly-metadata.js';
62
+ import { AsOfFeatureAssembler } from '../feature-assembly/as-of/as-of-assembler.js';
63
+ import { KeyedReader } from '../feature-assembly/as-of/read-by-keys.js';
64
+ import { RunViewRecordHistoryReader } from '../feature-assembly/as-of/record-history.js';
65
+ import { PredictionUnitRowReader } from '../prediction-unit/unit-row-reader.js';
66
+ import { DecisionDateAdvance } from '../prediction-unit/decision-date-advance.js';
67
+ import { RunViewPredictionUnitStore } from '../prediction-unit/unit-store.js';
68
+ import { TrainingEngine } from '../training/training-engine.js';
69
+ import { TrainingRefusedError } from '../training/training-refusal.js';
70
+ import { UnitModelLineageParser } from '../training/unit-model-lineage.js';
71
+ import { RunViewPipelineUnitLookup, RunViewTrainingRowsLookup } from './seams.js';
72
+ import { ModelHasTrainedArtifact, ModelNeedsTrainingMessage, ModelArtifactMissingMessage, ModelNeedsTrainingError, ModelNotScorableError, ModelNotServableError, ModelReadiness, } from './model-readiness.js';
73
+ import { SHADOW_NOT_DISPATCHED } from './shadow-scoring.js';
55
74
  /** Stable work-type keys this processor is registered under on the ClassFactory. */
56
75
  export const ML_INFERENCE_WORK_TYPE = 'ML Model';
57
76
  /** Alias work-type key (no spaces) for callers that prefer an identifier-style key. */
@@ -60,8 +79,12 @@ export const ML_INFERENCE_WORK_TYPE_ALIAS = 'MLModelInference';
60
79
  * Record Set Processing **scoring** processor. Stateless across records except
61
80
  * for a warm, lazily-loaded model cache (artifact + frozen contract) shared
62
81
  * across a batch. Construct one per Record Process run.
82
+ *
83
+ * Note on drift population: An ML Record Process with no challenger configured
84
+ * does not run shadow sampling, so no Feature Values are recorded and the
85
+ * scheduled drift sweep reports InsufficientData for it (S5).
63
86
  */
64
- let MLModelInferenceProcessor = class MLModelInferenceProcessor {
87
+ let MLModelInferenceProcessor = MLModelInferenceProcessor_1 = class MLModelInferenceProcessor {
65
88
  /**
66
89
  * @param options model id + injected seams (+ optional pk field / dated sources)
67
90
  * @param assembler optional FeatureAssembly executor override (tests may inject one)
@@ -71,14 +94,43 @@ let MLModelInferenceProcessor = class MLModelInferenceProcessor {
71
94
  this.loadedModel = null;
72
95
  /** Memoized in-flight load so concurrent records don't double-load the artifact. */
73
96
  this.loadPromise = null;
97
+ /**
98
+ * The run's one scoring instant, read by its first unit assembly and kept for every later batch: every row of a run is
99
+ * dated (an advancing fixed decision date), assembled and read for lags as of the same instant.
100
+ */
101
+ this.scoringInstant = null;
102
+ /**
103
+ * The run's series history ({@link SeriesHistoryForScoring}), built by the first batch that needs it and reused by
104
+ * every later batch of the run, so the unit's rows are read once per run, not once per batch. A processor is
105
+ * constructed per run, so it is never shared across runs. One entry, bounded by construction: keyed by the unit
106
+ * version, the run's scoring instant and the user it was read as, a different key replaces it, a failed build is
107
+ * dropped so a later batch retries, and {@link resetModelCache} clears it when the run retargets its model.
108
+ */
109
+ this.seriesHistoryEntry = null;
74
110
  this.modelId = options.modelId;
75
111
  this.deps = options.deps;
76
112
  this.primaryKeyField = options.primaryKeyField ?? 'ID';
77
113
  this.datedSources = options.datedSources;
78
114
  this.autoTrain = options.autoTrain;
79
115
  this.autoTrainer = options.autoTrainer;
116
+ this.recordProcessId = options.recordProcessId;
117
+ if (options.challengerConfig && options.challengerConfig.WorkType !== 'ML Model') {
118
+ LogError(`MLModelInferenceProcessor: skipping ChallengerConfigurationObject with mismatched WorkType '${String(options.challengerConfig.WorkType)}' (expected 'ML Model').`);
119
+ this.challengerConfig = undefined;
120
+ }
121
+ else {
122
+ this.challengerConfig = options.challengerConfig;
123
+ }
124
+ this.shadowCoordinator = options.shadowCoordinator;
80
125
  this.assembler = assembler ?? new FeatureAssemblyExecutor();
81
126
  }
127
+ /**
128
+ * Convert a row-major {@link MatrixData} into schema-ordered feature row objects.
129
+ * Exposed as a static method so callers and unit tests can spy on conversion counts.
130
+ */
131
+ static MatrixToFeatureRows(matrix, featureSchema) {
132
+ return MatrixToFeatureRows(matrix, featureSchema);
133
+ }
82
134
  /**
83
135
  * Run-level readiness check (the Record Set Processing `Preflight` seam): warm-loads
84
136
  * the model + artifact ONCE before the first batch, so a model that needs training
@@ -94,9 +146,13 @@ let MLModelInferenceProcessor = class MLModelInferenceProcessor {
94
146
  * @throws when the model is missing, has no trained artifact, or its artifact can't be loaded
95
147
  */
96
148
  async Preflight(context) {
149
+ const model = await this.loadForPreflight(context);
150
+ this.assertScopeEntity(model, context);
151
+ }
152
+ /** Warm-load the model, training it first when it needs training and the run opted into auto-train. */
153
+ async loadForPreflight(context) {
97
154
  try {
98
- await this.ensureModel(context);
99
- return;
155
+ return await this.ensureModel(context);
100
156
  }
101
157
  catch (err) {
102
158
  // Clear the memoized failure so a retry (or the auto-train below) re-attempts the load.
@@ -109,21 +165,35 @@ let MLModelInferenceProcessor = class MLModelInferenceProcessor {
109
165
  this.modelId = await this.autoTrainer.EnsureTrainedModel({
110
166
  pipelineId: this.autoTrain.pipelineId,
111
167
  currentModelId: this.modelId || null,
112
- recordProcessId: context.RecordProcessID ?? null,
168
+ recordProcessId: context.RecordProcessID ?? this.recordProcessId ?? null,
113
169
  binding: this.autoTrain.binding,
114
170
  }, context.ContextUser, context.Provider);
115
171
  try {
116
- await this.ensureModel(context);
172
+ return await this.ensureModel(context);
117
173
  }
118
174
  catch (err) {
119
175
  this.resetModelCache();
120
176
  throw err;
121
177
  }
122
178
  }
123
- /** Drop the warm-model cache (and any memoized failed load). */
179
+ /**
180
+ * A unit model scores records of its unit's row entity only: a scope over another entity is refused before any
181
+ * record is read (`scope-entity-mismatch`), since its records would be read through the wrong rows.
182
+ */
183
+ assertScopeEntity(model, context) {
184
+ if (model.unit === null || !context.EntityID)
185
+ return;
186
+ const modelEntity = context.Provider.EntityByName(model.unit.RowEntity);
187
+ if (modelEntity && UUIDsEqual(modelEntity.ID, context.EntityID))
188
+ return;
189
+ const scopeEntity = context.Provider.EntityByID(context.EntityID)?.Name || context.EntityID;
190
+ throw new TrainingRefusedError({ stage: 'assembly', reason: { kind: 'scope-entity-mismatch', modelEntity: model.unit.RowEntity, scopeEntity } });
191
+ }
192
+ /** Drop the warm-model cache (and any memoized failed load) and the series history read for that model's unit. */
124
193
  resetModelCache() {
125
194
  this.loadPromise = null;
126
195
  this.loadedModel = null;
196
+ this.seriesHistoryEntry = null;
127
197
  }
128
198
  /**
129
199
  * Score one record. Warm-loads the model on first call, assembles the single
@@ -136,15 +206,21 @@ let MLModelInferenceProcessor = class MLModelInferenceProcessor {
136
206
  */
137
207
  async ProcessRecord(record, context) {
138
208
  try {
209
+ const startedAt = Date.now();
139
210
  const model = await this.ensureModel(context);
140
211
  const row = this.recordToPlain(record);
141
212
  const assembly = await this.assembleFeatures(model, [row], context);
142
- const response = await this.callSidecar(model, assembly);
213
+ const featureRows = MLModelInferenceProcessor_1.MatrixToFeatureRows(assembly.matrix, model.featureSchema);
214
+ const response = await this.callSidecar(model, featureRows);
143
215
  const prediction = response.predictions[0];
144
216
  if (!prediction) {
145
217
  return { Status: 'Failed', ErrorMessage: 'Sidecar returned no prediction for the record' };
146
218
  }
147
- return { Status: 'Succeeded', ResultPayload: this.toPayload(model, prediction) };
219
+ const championLatencyMs = Date.now() - startedAt;
220
+ const payload = this.toPayload(model, prediction, record.RecordID);
221
+ // The champion audit row is written before the record reports done; the challenger runs on.
222
+ await this.dispatchShadowIfConfigured(record, model, featureRows[0] ?? {}, prediction, championLatencyMs, context).ChampionAudit;
223
+ return { Status: 'Succeeded', ResultPayload: payload };
148
224
  }
149
225
  catch (err) {
150
226
  const message = err instanceof Error ? err.message : String(err);
@@ -168,16 +244,33 @@ let MLModelInferenceProcessor = class MLModelInferenceProcessor {
168
244
  return [];
169
245
  }
170
246
  try {
247
+ const startedAt = Date.now();
171
248
  const model = await this.ensureModel(context);
172
249
  const rows = records.map((r) => this.recordToPlain(r));
173
250
  const assembly = await this.assembleFeatures(model, rows, context);
174
- const response = await this.callSidecar(model, assembly);
175
- return records.map((_r, i) => {
251
+ const featureRows = MLModelInferenceProcessor_1.MatrixToFeatureRows(assembly.matrix, model.featureSchema);
252
+ const response = await this.callSidecar(model, featureRows);
253
+ // Amortize batch wall-clock latency across the batch size so per-record champion latency
254
+ // is comparable to single-record challenger latency for P95 latency-ratio drift checks.
255
+ const perRecordLatencyMs = (Date.now() - startedAt) / Math.max(1, records.length);
256
+ const dispatches = [];
257
+ const results = records.map((rec, i) => {
176
258
  const prediction = response.predictions[i];
177
- return prediction
178
- ? { Status: 'Succeeded', ResultPayload: this.toPayload(model, prediction) }
179
- : { Status: 'Failed', ErrorMessage: 'Sidecar returned no prediction for the record' };
259
+ if (!prediction) {
260
+ return { Status: 'Failed', ErrorMessage: 'Sidecar returned no prediction for the record' };
261
+ }
262
+ dispatches.push(this.dispatchShadowIfConfigured(rec, model, featureRows[i] ?? {}, prediction, perRecordLatencyMs, context));
263
+ return { Status: 'Succeeded', ResultPayload: this.toPayload(model, prediction, rec.RecordID) };
180
264
  });
265
+ // The batch's champion audit rows are written before it reports done (at most one per record, so bounded
266
+ // by the batch); the challengers run on and are never awaited here.
267
+ await Promise.all(dispatches.map((d) => d.ChampionAudit));
268
+ // Counted from this batch's own dispatches: the coordinator's DroppedCount is shared by every run.
269
+ const dropped = dispatches.filter((d) => d.Dropped).length;
270
+ if (dropped > 0) {
271
+ LogError(`MLModelInferenceProcessor: Record Process '${context.RecordProcessID ?? this.recordProcessId ?? ''}' run '${context.ProcessRunID ?? ''}': ${dropped} shadow challenger task(s) dropped in this batch (in-flight cap reached)`);
272
+ }
273
+ return results;
181
274
  }
182
275
  catch (err) {
183
276
  const message = err instanceof Error ? err.message : String(err);
@@ -185,6 +278,48 @@ let MLModelInferenceProcessor = class MLModelInferenceProcessor {
185
278
  return records.map(() => ({ Status: 'Failed', ErrorMessage: message }));
186
279
  }
187
280
  }
281
+ /**
282
+ * Mirrors a sampled record to the challenger. Returns what was dispatched: the record's champion audit write
283
+ * (never rejects) for the caller to await, and whether the challenger was dropped. Nothing dispatched settles at once.
284
+ */
285
+ dispatchShadowIfConfigured(record, model, featureRow, prediction, championLatencyMs, context) {
286
+ if (!this.shadowCoordinator ||
287
+ !this.challengerConfig ||
288
+ this.challengerConfig.WorkType !== 'ML Model' ||
289
+ context.DryRun) {
290
+ return SHADOW_NOT_DISPATCHED;
291
+ }
292
+ try {
293
+ // Sample BEFORE cloning the feature row or constructing the envelope (D3).
294
+ if (!this.shadowCoordinator.ShouldSample(this.challengerConfig)) {
295
+ return SHADOW_NOT_DISPATCHED;
296
+ }
297
+ const championConfidence = model.problemType === 'classification' && Number.isFinite(prediction.score)
298
+ ? Math.max(prediction.score, 1 - prediction.score)
299
+ : undefined;
300
+ return this.shadowCoordinator.DispatchShadowScore({
301
+ RecordProcessID: context.RecordProcessID ?? this.recordProcessId,
302
+ ProcessRunID: context.ProcessRunID ?? null,
303
+ EntityID: record.EntityID || context.EntityID,
304
+ EntityName: model.targetEntityName,
305
+ RecordID: record.RecordID,
306
+ FeatureName: model.targetVariable || 'Prediction',
307
+ ChampionModelID: model.modelId,
308
+ ChallengerConfig: this.challengerConfig,
309
+ FrozenFeatures: Object.freeze({ ...featureRow }),
310
+ ChampionScore: prediction.score,
311
+ ChampionLabel: prediction.class != null ? String(prediction.class) : undefined,
312
+ ChampionConfidence: championConfidence,
313
+ ChampionLatencyMs: championLatencyMs,
314
+ DispatchedAt: new Date().toISOString(),
315
+ }, context.ContextUser, context.Provider, { AlreadySampled: true });
316
+ }
317
+ catch (shadowErr) {
318
+ const msg = shadowErr instanceof Error ? shadowErr.message : String(shadowErr);
319
+ LogError(`MLModelInferenceProcessor: non-fatal shadow dispatch failure for '${record.RecordID}': ${msg}`);
320
+ return SHADOW_NOT_DISPATCHED;
321
+ }
322
+ }
188
323
  // region: warm model load -----------------------------------------------------
189
324
  /**
190
325
  * Load the model + artifact ONCE and cache it for the run (§3.1 warm cache).
@@ -210,41 +345,49 @@ let MLModelInferenceProcessor = class MLModelInferenceProcessor {
210
345
  if (!model) {
211
346
  throw new ModelNeedsTrainingError(`MLModelInferenceProcessor: ML Model '${this.modelId}' not found`);
212
347
  }
213
- this.assertStatusCanScore(model);
214
- const bytes = await this.deps.artifactLoader.load(model.ArtifactFileID, context.ContextUser);
348
+ const artifactFileId = this.assertStatusCanScore(model);
349
+ const bytes = await this.deps.artifactLoader.load(artifactFileId, context.ContextUser, context.Provider);
215
350
  if (!bytes) {
216
- throw new ModelNeedsTrainingError(`MLModelInferenceProcessor: ${ModelArtifactMissingMessage(this.modelId, model.ArtifactFileID)}`);
351
+ throw new ModelNeedsTrainingError(`MLModelInferenceProcessor: ${ModelArtifactMissingMessage(this.modelId, artifactFileId)}`);
217
352
  }
218
353
  return this.buildLoadedModel(model, bytes, context);
219
354
  }
220
355
  /**
221
356
  * Refuse a model whose lifecycle status or missing artifact forbids scoring, in this order: a Draft with no artifact
222
357
  * needs training (the opt-in auto-train path reacts to that, D2-C3) and a trained Draft is not scorable; Validated and
223
- * Published score once they have an artifact; any other status (Archived, or a value CodeGen adds later) is refused
224
- * before the artifact is looked at.
358
+ * Published score once they have an artifact that `/predict` serves (a series forecaster's is refused with
359
+ * {@link ModelNotServableError}, never "needs training", so auto-train does not retrain for it); any other status (Archived, or a value CodeGen adds later) is refused
360
+ * before the artifact is looked at. Returns the artifact file of a model that may score.
225
361
  */
226
362
  assertStatusCanScore(model) {
227
363
  const status = model.Status;
228
364
  switch (status) {
229
365
  case 'Draft':
230
- this.assertHasArtifact(model);
366
+ this.requireArtifactFileId(model);
231
367
  throw new ModelNotScorableError(this.modelId, status);
232
368
  case 'Validated':
233
- case 'Published':
234
- this.assertHasArtifact(model);
235
- return;
369
+ case 'Published': {
370
+ const fileId = this.requireArtifactFileId(model);
371
+ if (!ModelReadiness.IsServedByPredict(model))
372
+ throw new ModelNotServableError(this.modelId);
373
+ return fileId;
374
+ }
236
375
  default:
237
376
  throw new ModelNotScorableError(this.modelId, status);
238
377
  }
239
378
  }
240
- /** Throw "needs training" when the model has no trained artifact reference. */
241
- assertHasArtifact(model) {
242
- if (!ModelHasTrainedArtifact(model) || !model.ArtifactFileID) {
379
+ /** The model's trained artifact file; throws "needs training" when it has none. */
380
+ requireArtifactFileId(model) {
381
+ const fileId = model.ArtifactFileID;
382
+ if (!ModelHasTrainedArtifact(model) || fileId === null || fileId === '') {
243
383
  throw new ModelNeedsTrainingError(`MLModelInferenceProcessor: ${ModelNeedsTrainingMessage(this.modelId)}`);
244
384
  }
385
+ return fileId;
245
386
  }
246
387
  /** Assemble the frozen inference contract from a loaded model row + artifact bytes. */
247
388
  async buildLoadedModel(model, bytes, context) {
389
+ // The unit part first: a unit model with an unreadable Lineage fails here, before anything else reads the Lineage.
390
+ const unit = await this.loadUnitModel(model, context);
248
391
  let pipeline = this.resolvePipelineConfig(model);
249
392
  if ((pipeline.featureSteps.Steps.length === 0 || !pipeline.targetEntityName) && model.PipelineID) {
250
393
  pipeline = await this.loadPipelineFallback(model.PipelineID, pipeline, context);
@@ -262,6 +405,47 @@ let MLModelInferenceProcessor = class MLModelInferenceProcessor {
262
405
  asOf: pipeline.asOf,
263
406
  leakageGuard: pipeline.leakageGuard,
264
407
  outcomeConfig: pipeline.outcomeConfig,
408
+ unit,
409
+ trainingRowIds: new UUIDSet(await (this.deps.trainingRows || new RunViewTrainingRowsLookup()).TrainingRowIDsOf(model.ID, context.ContextUser, context.Provider)),
410
+ };
411
+ }
412
+ /**
413
+ * The unit a model was trained on, with the feature columns and categorical levels its Lineage stored; null for a
414
+ * legacy model. The model's own Lineage, frozen at training, decides, by the marker only unit training writes
415
+ * (`predictionUnitId`): a Lineage that carries it takes the unit path (the unit it stored, even when the pipeline's
416
+ * editable `PredictionUnitID` was later cleared or moved) and must validate. Every other readable Lineage is a model
417
+ * trained before Prediction Units (every such shape, with or without the feature graph, which the pipeline-row
418
+ * fallback rebuilds): it keeps scoring on the legacy path even after the migration bound its pipeline to a unit. A
419
+ * Lineage that cannot be read fails loudly on a pipeline that points at a unit (it cannot be told apart); on one that
420
+ * does not, the model is legacy, as it always was. A unit Lineage that fails validation, or whose unit cannot be
421
+ * loaded or parsed, fails loudly naming the model; it is never scored through the legacy current-value path.
422
+ */
423
+ async loadUnitModel(model, context) {
424
+ if (!UnitModelLineageParser.NamesUnit(model.Lineage)) {
425
+ if (UnitModelLineageParser.IsReadable(model.Lineage))
426
+ return null;
427
+ const lookup = this.deps.pipelineUnits || new RunViewPipelineUnitLookup();
428
+ if (!(await lookup.PredictionUnitIDOf(model.PipelineID, context.ContextUser, context.Provider)))
429
+ return null;
430
+ throw new Error(`MLModelInferenceProcessor: model '${model.ID}' has an unreadable Lineage and its pipeline points at a Prediction Unit, so whether it was trained on a unit cannot be told`);
431
+ }
432
+ const lineage = UnitModelLineageParser.ParseUnitModelLineage(model.Lineage);
433
+ if (lineage.Ok === false) {
434
+ throw new Error(`MLModelInferenceProcessor: model '${model.ID}' was trained on a Prediction Unit but its Lineage cannot be read: ${lineage.Errors[0]}`);
435
+ }
436
+ const unitId = lineage.Value.predictionUnitId;
437
+ const store = this.deps.predictionUnits || new RunViewPredictionUnitStore(context.Provider, context.ContextUser);
438
+ const row = await store.Load(unitId);
439
+ if (!row)
440
+ throw new Error(`MLModelInferenceProcessor: Prediction Unit ${unitId} of model '${model.ID}' was not found`);
441
+ const parsed = PredictionUnit.ParsePredictionUnitRow(row);
442
+ if (parsed.Ok === false)
443
+ throw new Error(`MLModelInferenceProcessor: Prediction Unit ${unitId} of model '${model.ID}' is invalid: ${parsed.Errors.join('; ')}`);
444
+ return {
445
+ Spec: parsed.Value,
446
+ Features: lineage.Value.featureSpec,
447
+ RowEntity: lineage.Value.unitRowEntity,
448
+ CategoryLevels: new Map(Object.entries(lineage.Value.categoryLevels)),
265
449
  };
266
450
  }
267
451
  /**
@@ -328,6 +512,8 @@ let MLModelInferenceProcessor = class MLModelInferenceProcessor {
328
512
  * (the sidecar applies the frozen `FittedPreprocessing`).
329
513
  */
330
514
  async assembleFeatures(model, rows, context) {
515
+ if (model.unit !== null)
516
+ return this.assembleUnitFeatures(model, rows, context);
331
517
  const assembly = await this.assembler.assemble({
332
518
  targetEntityName: model.targetEntityName,
333
519
  records: rows,
@@ -342,13 +528,173 @@ let MLModelInferenceProcessor = class MLModelInferenceProcessor {
342
528
  contextUser: context.ContextUser,
343
529
  provider: context.Provider,
344
530
  });
531
+ this.assertHasColumns(model, assembly);
532
+ return assembly;
533
+ }
534
+ /** Refuse to score with an empty matrix when the model's schema expects features (degenerate predictions). */
535
+ assertHasColumns(model, assembly) {
345
536
  if (assembly.matrix.columns.length === 0 && model.featureSchema.length > 0) {
346
537
  throw new Error(`MLModelInferenceProcessor: feature assembly produced 0 columns for model '${model.modelId}' ` +
347
538
  `which requires ${model.featureSchema.length} feature(s) [${model.featureSchema.map((f) => f.Name).join(', ')}]. ` +
348
539
  `Refusing to score with empty features to avoid degenerate predictions.`);
349
540
  }
541
+ }
542
+ /**
543
+ * A unit model's matrix, assembled as of each row's decision date. A refusal is thrown as a typed
544
+ * {@link TrainingRefusedError}. A row the history cannot read as of its decision date (its history starts after it,
545
+ * or its parent was hard-deleted before it) fails the whole batch, since the results are aligned by position: it is
546
+ * thrown as the typed `decision-date-before-change-history` refusal training's `refuse` policy raises, built from the
547
+ * first uncovered entity field, whatever the unit's `onUncoveredRow` policy.
548
+ */
549
+ async assembleUnitFeatures(model, rows, context) {
550
+ const assembled = await this.AssembleForScoring(rows, context, 'unit-rule');
551
+ if (assembled.Status === 'refused')
552
+ throw new TrainingRefusedError({ stage: 'assembly', reason: assembled.Refusal });
553
+ const first = assembled.UncoveredRowsExcluded[0];
554
+ if (first)
555
+ throw new TrainingRefusedError({ stage: 'assembly', reason: MLModelInferenceProcessor_1.uncoveredRefusal(assembled, first) });
556
+ const assembly = AsOfFeatureAssembler.ToFeatureAssemblyResult(assembled, null, LABEL_COLUMN);
557
+ this.assertHasColumns(model, assembly);
350
558
  return assembly;
351
559
  }
560
+ /** The refusal of an uncovered entity field: its history start is the one the assembly's coverage reports for it. */
561
+ static uncoveredRefusal(assembled, first) {
562
+ const coverage = assembled.Coverage.find((c) => c.entity === first.entity && c.field === first.field);
563
+ return { kind: 'decision-date-before-change-history', entity: first.entity, field: first.field, historyStart: coverage?.historyStart || null, rowsAffected: first.rows };
564
+ }
565
+ // region: as-of assembly (unit models) ----------------------------------------
566
+ /**
567
+ * Assemble a unit model's feature rows for scoring through the same `AsOfFeatureAssembler` training uses. The scoped
568
+ * rows are read by key (only the fields that date them: the decision-date column, the grain foreign key, the time
569
+ * column); each is dated by the unit's rule (`'unit-rule'`, the reader's own rule) or, given a date, every row is read
570
+ * as of that day. The assembler gets the feature columns and kept categorical levels training stored, so a value
571
+ * reads and folds exactly as it did in training. A refusal (a key that is not found, a read the history does not
572
+ * cover) is returned as the refused result; the scoring path throws it as a typed `TrainingRefusedError`. The run
573
+ * reads its clock once, on its first assembly: every batch of the run is dated and assembled as of that instant and
574
+ * reads its lags from one series history, built by the first batch that needs it.
575
+ *
576
+ * @param rows the rows to score; each carries the unit row entity's primary key
577
+ * @param context the run's user and provider
578
+ * @param asOf `'unit-rule'` to date each row by the unit, or one date for every row
579
+ */
580
+ async AssembleForScoring(rows, context, asOf) {
581
+ const unit = this.requireUnit(await this.ensureModel(context));
582
+ const seams = this.scoringSeams(context);
583
+ const rowEntity = seams.Metadata.Entity(unit.RowEntity);
584
+ if (!rowEntity)
585
+ throw new Error(`MLModelInferenceProcessor: the unit row entity "${unit.RowEntity}" of model '${this.modelId}' is not registered`);
586
+ const keys = rows.map((r) => this.rowKey(r, rowEntity));
587
+ const read = await KeyedReader.ReadByKeys(seams.DataAccess, rowEntity.Name, rowEntity.PrimaryKey, keys, MLModelInferenceProcessor_1.datingFields(unit.Spec));
588
+ if (read.Status === 'refused')
589
+ return read;
590
+ // One clock read per scoring run: the assembly day and the day an advancing fixed decision date moves to.
591
+ const now = this.runScoringInstant();
592
+ const refs = keys.map((k) => MLModelInferenceProcessor_1.rowRef(unit.Spec, rowEntity, read.Rows.get(k.toLowerCase()), k, asOf, now));
593
+ return new AsOfFeatureAssembler().Assemble({
594
+ Context: 'score',
595
+ Unit: unit.Spec,
596
+ RowEntity: rowEntity,
597
+ Rows: refs,
598
+ Features: unit.Features,
599
+ SeriesHistory: await this.seriesHistoryForRun(unit.Spec, seams, now, context),
600
+ Read: { mode: 'complete' },
601
+ DataAccess: seams.DataAccess,
602
+ History: this.deps.history || new RunViewRecordHistoryReader(seams.DataAccess, { mode: 'complete' }),
603
+ Metadata: seams.Metadata,
604
+ AssembledAt: now,
605
+ CategoryLevels: unit.CategoryLevels,
606
+ });
607
+ }
608
+ /** The unit part of a loaded model; a model trained without a unit has no as-of assembly. */
609
+ requireUnit(model) {
610
+ if (model.unit === null)
611
+ throw new Error(`MLModelInferenceProcessor: model '${model.modelId}' was not trained on a Prediction Unit, so it has no as-of assembly`);
612
+ return model.unit;
613
+ }
614
+ /** The run's metadata and data access, unless the deps supply them; never a global provider. */
615
+ scoringSeams(context) {
616
+ return {
617
+ Metadata: this.deps.assemblyMetadata || new ProviderAssemblyMetadata(context.Provider),
618
+ DataAccess: this.deps.dataAccess || new RunViewDataAccess(context.ContextUser, context.Provider),
619
+ };
620
+ }
621
+ /** A scoped row's key: the unit row entity's primary key (or the processor's key field); a row without one fails. */
622
+ rowKey(row, rowEntity) {
623
+ const value = row[rowEntity.PrimaryKey] !== undefined ? row[rowEntity.PrimaryKey] : row[this.primaryKeyField];
624
+ if (value === null || value === undefined || value === '')
625
+ throw new Error(`MLModelInferenceProcessor: a scoped row has no ${rowEntity.Name}.${rowEntity.PrimaryKey}`);
626
+ return value instanceof Date ? value.toISOString() : String(value);
627
+ }
628
+ /** The row fields the unit's rule dates a row with: its decision-date or period column, grain foreign key and time column. */
629
+ static datingFields(spec) {
630
+ const fields = [];
631
+ if (spec.rows.kind === 'grain-x-periods') {
632
+ fields.push(spec.rows.periodDate, spec.rows.foreignKey);
633
+ }
634
+ else if (spec.rows.decisionDate.kind !== 'fixed') {
635
+ fields.push(spec.rows.decisionDate.column);
636
+ }
637
+ if (spec.temporal)
638
+ fields.push(spec.temporal.timeColumn);
639
+ return [...new Set(fields)];
640
+ }
641
+ /**
642
+ * One scoped row as the assembler reads it, by the unit row rule the training reader uses; `asOf` sets its decision
643
+ * day. Under the unit rule a fixed decision date that advances each run is the scoring run's UTC day (`now`), the day
644
+ * a training run started now would advance it to; the stored date is the day the model was trained.
645
+ */
646
+ static rowRef(spec, rowEntity, row, key, asOf, now) {
647
+ if (!row)
648
+ throw new Error(`MLModelInferenceProcessor: ${rowEntity.Name} ${key} was not read`);
649
+ const decision = asOf !== 'unit-rule' ? UtcDay.ToUtcDay(asOf)
650
+ : DecisionDateAdvance.AdvancesEachRun(spec) ? UtcDay.ToUtcDay(now)
651
+ : PredictionUnitRowReader.UnitDecisionDate(spec, row);
652
+ if (decision === null)
653
+ throw new Error(`MLModelInferenceProcessor: ${rowEntity.Name} ${key} has no decision date under its Prediction Unit's rule`);
654
+ return PredictionUnitRowReader.UnitRowRef(spec, rowEntity, row, decision);
655
+ }
656
+ /** The run's scoring instant: the clock read by the run's first unit assembly ({@link scoringInstant}). */
657
+ runScoringInstant() {
658
+ if (this.scoringInstant === null)
659
+ this.scoringInstant = new Date();
660
+ return this.scoringInstant;
661
+ }
662
+ /**
663
+ * The run's series history ({@link seriesHistoryEntry}): built once for the key and shared by every batch, concurrent
664
+ * ones included (they await one in-flight read). Without a user there is no safe key, so the history is read for the
665
+ * batch and not kept: rows read under one user's permissions are never handed to another.
666
+ */
667
+ seriesHistoryForRun(spec, seams, now, context) {
668
+ const key = UserScopedCacheKey(context.ContextUser?.ID, NormalizeUUID(spec.id), String(spec.version), now.toISOString());
669
+ if (key === null)
670
+ return MLModelInferenceProcessor_1.SeriesHistoryForScoring(spec, seams, now);
671
+ if (this.seriesHistoryEntry !== null && this.seriesHistoryEntry.Key === key)
672
+ return this.seriesHistoryEntry.History;
673
+ const entry = { Key: key, History: MLModelInferenceProcessor_1.SeriesHistoryForScoring(spec, seams, now) };
674
+ this.seriesHistoryEntry = entry;
675
+ // The batch awaiting the build sees its failure; the entry is only dropped so the next batch reads again.
676
+ entry.History.catch(() => {
677
+ if (this.seriesHistoryEntry === entry)
678
+ this.seriesHistoryEntry = null;
679
+ });
680
+ return entry.History;
681
+ }
682
+ /**
683
+ * The series history a unit with a Temporal Spec reads its lags from at scoring, built from the unit's rows the way
684
+ * training builds it. Rows whose outcome window has not closed by the unit's cutoff are kept, not censored: a period's
685
+ * value is its resolved outcome, and a lag reads it only once its outcome window has closed by the row's decision day
686
+ * and the scoring day (`SeriesFeatures.ComputeSeriesFeature`). A period whose window closed after the unit's cutoff but
687
+ * before the scoring day is therefore read, as training would read it had it run on the scoring day, and a period
688
+ * still open is kept in the history but never read.
689
+ */
690
+ static async SeriesHistoryForScoring(spec, seams, now) {
691
+ if (!spec.temporal)
692
+ return null;
693
+ const read = await new PredictionUnitRowReader().Read(spec, { DataAccess: seams.DataAccess, Metadata: seams.Metadata, Read: { mode: 'complete' }, Now: now, KeepOpenWindows: true });
694
+ if (read.Status === 'refused')
695
+ throw new TrainingRefusedError(read.Refusal);
696
+ return TrainingEngine.SeriesHistoryFor(spec, read.Rows);
697
+ }
352
698
  // region: sidecar predict -----------------------------------------------------
353
699
  /**
354
700
  * Build the `/predict` request from the model's frozen contract + the assembled
@@ -356,18 +702,18 @@ let MLModelInferenceProcessor = class MLModelInferenceProcessor {
356
702
  * feature-name → value objects `/predict` expects, using the MODEL's frozen
357
703
  * feature schema order (the inference input contract).
358
704
  */
359
- async callSidecar(model, assembly) {
705
+ async callSidecar(model, featureRows) {
360
706
  const req = {
361
707
  artifact_b64: model.artifactB64,
362
708
  fitted_preprocessing: model.fittedPreprocessing,
363
709
  feature_schema: model.featureSchema,
364
- rows: MatrixToFeatureRows(assembly.matrix, model.featureSchema),
710
+ rows: featureRows,
365
711
  };
366
712
  return this.deps.sidecar.predict(req);
367
713
  }
368
714
  // region: result shaping ------------------------------------------------------
369
- /** Shape a single sidecar prediction into the record result payload. */
370
- toPayload(model, prediction) {
715
+ /** Shape a single sidecar prediction for the record `recordId` (its serialized key) into the record result payload. */
716
+ toPayload(model, prediction, recordId) {
371
717
  const band = resolveScoreBand(prediction.score, model.outcomeConfig);
372
718
  const style = resolveOutcomeStyle(prediction.class, model.outcomeConfig);
373
719
  return {
@@ -388,6 +734,7 @@ let MLModelInferenceProcessor = class MLModelInferenceProcessor {
388
734
  // Stamp when the prediction was produced so write-back can persist a "last scored at"
389
735
  // column via OutputMapping (`{ "<YourColumn>": "$.scoredAt" }`). ISO-8601 UTC.
390
736
  scoredAt: new Date().toISOString(),
737
+ inTraining: model.trainingRowIds.Has(recordId),
391
738
  };
392
739
  }
393
740
  // region: record helpers ------------------------------------------------------
@@ -404,7 +751,7 @@ let MLModelInferenceProcessor = class MLModelInferenceProcessor {
404
751
  return { [this.primaryKeyField]: record.RecordID };
405
752
  }
406
753
  };
407
- MLModelInferenceProcessor = __decorate([
754
+ MLModelInferenceProcessor = MLModelInferenceProcessor_1 = __decorate([
408
755
  RegisterClass(MLModelInferenceProcessor, ML_INFERENCE_WORK_TYPE),
409
756
  __metadata("design:paramtypes", [Object, FeatureAssemblyExecutor])
410
757
  ], MLModelInferenceProcessor);
@@ -423,18 +770,14 @@ export function MatrixToFeatureRows(matrix, featureSchema) {
423
770
  const obj = {};
424
771
  for (const name of schemaNames) {
425
772
  const idx = colIndex.get(name);
426
- obj[name] = idx != null ? row[idx] : null;
773
+ obj[name] = (idx !== null && idx !== undefined) ? row[idx] : null;
427
774
  }
428
775
  return obj;
429
776
  });
430
777
  }
431
- /** @deprecated Use {@link MatrixToFeatureRows}. */
432
- export function matrixToFeatureRows(matrix, featureSchema) {
433
- return MatrixToFeatureRows(matrix, featureSchema);
434
- }
435
778
  /** Parse a possibly-null JSON column, falling back to a default on null/parse error. */
436
779
  function parseJson(raw, fallback) {
437
- if (raw == null || raw.trim().length === 0) {
780
+ if ((raw === null || raw === undefined) || raw.trim().length === 0) {
438
781
  return fallback;
439
782
  }
440
783
  try {