@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
@@ -0,0 +1,194 @@
1
+ /**
2
+ * @module snapshot/snapshot-retrainer
3
+ *
4
+ * Retraining from a Training Snapshot: a completed run's snapshot files are read back and verified against the hashes on
5
+ * the snapshot row, the protocol trainer (`/trainer`) is called again with the request settings the run logged and new
6
+ * downloads of the same files (it reads the rows by the roles the row manifest records, so what was frozen is exactly
7
+ * what is trained on), and the holdout metrics are compared, so a run can be shown to reproduce from what it stored. A
8
+ * run that logged no trainer request is refused.
9
+ */
10
+ import { UUIDsEqual } from '@memberjunction/global';
11
+ import { PredictionUnit, TrainerContract, TrainingRunResultsParser, UtcDay, } from '@memberjunction/predictive-studio-core';
12
+ import { TrainerRequestBuilder } from '../training/trainer-request.js';
13
+ import { EvaluationProtocolSpecs, RunViewEvaluationProtocolStore } from '../training/evaluation-protocol-store.js';
14
+ import { RunViewPredictionUnitStore } from '../prediction-unit/unit-store.js';
15
+ import { SnapshotFiles } from './snapshot-serialization.js';
16
+ import { SnapshotIntegrityError, SnapshotManifest } from './snapshot-manifest.js';
17
+ import { StorageProviderSnapshotFileStore } from './snapshot-file-store.js';
18
+ import { RunViewTrainingSnapshotStore } from './training-snapshot-store.js';
19
+ /**
20
+ * Retrains from Training Snapshots: `Retrain` re-runs a completed run through the protocol trainer from its verified
21
+ * snapshot files, with its reads split into protected steps a subclass can replace.
22
+ */
23
+ export class SnapshotRetrainer {
24
+ /** The default largest holdout-metric difference a retraining may show and still reproduce its run. */
25
+ static { this.DefaultTolerance = 1e-9; }
26
+ /**
27
+ * Re-runs a completed unit run from its snapshot files and logged trainer request. The run and snapshot are read
28
+ * through `deps.snapshots` and the files through `deps.snapshotFiles` (defaults: the RunView and storage-provider
29
+ * stores on `deps.provider`, as `deps.contextUser`).
30
+ *
31
+ * @param trainingRunId the `MJ: ML Training Runs` row to retrain
32
+ * @param deps the training seams; only the snapshot stores, the trainer, the provider and the user are used
33
+ * @param tolerance the largest holdout-metric difference that still counts as reproduced
34
+ * @returns both metric sets, their largest difference and whether the run reproduced
35
+ * @throws Error when the run logged no trainer request (only runs trained through `/trainer` are retrained)
36
+ * @throws SnapshotIntegrityError when a stored file or the content hash does not match the snapshot row
37
+ */
38
+ async Retrain(trainingRunId, deps, tolerance = SnapshotRetrainer.DefaultTolerance) {
39
+ const store = this.SnapshotStore(deps);
40
+ const run = await store.LoadRun(trainingRunId);
41
+ if (!run)
42
+ throw new Error(`Training run ${trainingRunId} not found`);
43
+ if (!run.TrainingSnapshotID)
44
+ throw new Error(`Training run ${trainingRunId} has no Training Snapshot`);
45
+ const trainerRun = SnapshotRetrainer.loggedTrainerRunOf(run, this.StoredResultsOf(run));
46
+ const snapshot = await store.LoadSnapshot(run.TrainingSnapshotID);
47
+ if (!snapshot)
48
+ throw new Error(`Training Snapshot ${run.TrainingSnapshotID} of run ${trainingRunId} not found`);
49
+ const files = this.FileStore(deps);
50
+ // Verified before the trainer is called: the trainer reads the same files through new downloads.
51
+ await this.ReadVerifiedContent(snapshot, files);
52
+ SnapshotRetrainer.assertLoggedProtocolIsSnapshots(run, snapshot, trainerRun);
53
+ const retrained = await this.RetrainThroughTrainer(run, snapshot, files, trainerRun, deps);
54
+ return SnapshotRetrainer.compared(run, snapshot, TrainerContract.HoldoutMetricsOf(trainerRun.Result.holdout), retrained, tolerance);
55
+ }
56
+ /**
57
+ * Sends a run's logged request settings to the trainer again, with new downloads of the verified
58
+ * snapshot files, under the protocol and unit the run was trained with; the retraining's holdout metrics.
59
+ *
60
+ * @throws Error when the deps have no trainer, the protocol or unit row is missing or does not parse, or the
61
+ * retraining does not complete
62
+ */
63
+ async RetrainThroughTrainer(run, snapshot, files, logged, deps) {
64
+ if (!deps.trainer)
65
+ throw new Error(`Training run ${run.ID} was trained under an Evaluation Protocol; retraining it needs the trainer (deps.trainer)`);
66
+ const [protocol, unit] = await Promise.all([this.LoadProtocolSpec(logged.Request.evaluationProtocolId, deps), this.LoadUnitSpec(snapshot.PredictionUnitID, deps)]);
67
+ // Each call pre-authorises fresh snapshot downloads: the first attempt sends one, every retry another.
68
+ const issue = () => TrainerRequestBuilder.BuildTrainerRequest({
69
+ TrainingRunID: run.ID, Snapshot: snapshot, Files: files, Protocol: protocol, Task: unit.label.outcome,
70
+ Candidates: logged.Request.candidates, Seed: logged.Request.seed, Threads: logged.Request.threads,
71
+ TimeoutSeconds: logged.Request.timeoutSeconds, MaxRetries: logged.Request.maxRetries,
72
+ });
73
+ const again = await deps.trainer.RunTrainer(await issue(), issue);
74
+ if (again.status === 'failed')
75
+ throw new Error(`Retraining run ${run.ID} failed at stage ${again.stage}: ${again.message}`);
76
+ return TrainerContract.HoldoutMetricsOf(again.holdout);
77
+ }
78
+ /**
79
+ * The protocol a retraining runs under is the one the run logged; the snapshot's `EvaluationProtocolID` is covered by
80
+ * its verified content hash. A run whose log names another protocol (an edited run row) would retrain under rules the
81
+ * snapshot was not frozen for, so it is refused.
82
+ *
83
+ * @throws Error naming both protocols when they differ
84
+ */
85
+ static assertLoggedProtocolIsSnapshots(run, snapshot, logged) {
86
+ if (UUIDsEqual(logged.Request.evaluationProtocolId, snapshot.EvaluationProtocolID))
87
+ return;
88
+ throw new Error(`Training run ${run.ID} logged Evaluation Protocol ${logged.Request.evaluationProtocolId}, but its Training Snapshot ${snapshot.ID} was frozen under ${snapshot.EvaluationProtocolID}; it is not retrained`);
89
+ }
90
+ /** The Evaluation Protocol a run was trained under, read through `deps.protocols` (default: RunView on `deps.provider`). */
91
+ async LoadProtocolSpec(protocolId, deps) {
92
+ const spec = await EvaluationProtocolSpecs.LoadSpec(deps.protocols || new RunViewEvaluationProtocolStore(deps.provider, deps.contextUser), protocolId);
93
+ if (!spec)
94
+ throw new Error(`Evaluation Protocol ${protocolId} not found`);
95
+ return spec;
96
+ }
97
+ /** The Prediction Unit version a snapshot was built from, read through `deps.predictionUnits` (default: RunView on `deps.provider`). */
98
+ async LoadUnitSpec(unitId, deps) {
99
+ const row = await (deps.predictionUnits || new RunViewPredictionUnitStore(deps.provider, deps.contextUser)).Load(unitId);
100
+ if (!row)
101
+ throw new Error(`Prediction Unit ${unitId} not found`);
102
+ const parsed = PredictionUnit.ParsePredictionUnitRow(row);
103
+ if (parsed.Ok === false)
104
+ throw new Error(`Prediction Unit ${unitId} does not parse: ${parsed.Errors.join('; ')}`);
105
+ return parsed.Value;
106
+ }
107
+ /** Both metric sets of a retraining, their largest difference and whether the run reproduced. */
108
+ static compared(run, snapshot, original, retrained, tolerance) {
109
+ const diff = SnapshotRetrainer.MaxAbsDiff(original, retrained);
110
+ return {
111
+ TrainingRunID: run.ID,
112
+ TrainingSnapshotID: snapshot.ID,
113
+ FilesVerified: true,
114
+ ContentHashVerified: true,
115
+ Original: original,
116
+ Retrained: retrained,
117
+ MaxAbsDiff: diff.Value,
118
+ Reproduced: diff.Keys > 0 && diff.Value <= tolerance,
119
+ };
120
+ }
121
+ /**
122
+ * The trainer result and request a completed run stored. A run without them is refused, naming it: only runs trained
123
+ * through `/trainer` are retrained.
124
+ */
125
+ static loggedTrainerRunOf(run, results) {
126
+ if (results.status !== 'completed' || !results.trainer || !results.trainerRequest) {
127
+ throw new Error(`Run ${run.ID} has no trainer request; only runs trained through /trainer are retrained`);
128
+ }
129
+ return { Result: results.trainer, Request: results.trainerRequest };
130
+ }
131
+ /**
132
+ * The largest |original − retrained| over every metric name on either side. A name present on one side only makes
133
+ * the difference `Infinity` (the retraining did not measure what the run measured), and so does a non-finite value.
134
+ */
135
+ static MaxAbsDiff(original, retrained) {
136
+ const originalKeys = new Set(Object.keys(original));
137
+ const retrainedKeys = new Set(Object.keys(retrained));
138
+ const keys = [...new Set([...originalKeys, ...retrainedKeys])];
139
+ const value = keys.reduce((max, k) => {
140
+ if (!originalKeys.has(k) || !retrainedKeys.has(k))
141
+ return Number.POSITIVE_INFINITY;
142
+ const d = Math.abs(original[k] - retrained[k]);
143
+ return Number.isFinite(d) ? Math.max(max, d) : Number.POSITIVE_INFINITY;
144
+ }, 0);
145
+ return { Value: value, Keys: keys.length };
146
+ }
147
+ /**
148
+ * Reads the three files in parallel and refuses any whose SHA-256 differs from its column on the snapshot row (the
149
+ * provenance file included: it is outside the content hash, so its own column is its only check), then refuses a
150
+ * row whose verified matrix and manifest hashes and identity columns no longer yield its `ContentHash`.
151
+ *
152
+ * @throws SnapshotIntegrityError naming the file, or `'content'`
153
+ */
154
+ async ReadVerifiedContent(snapshot, files) {
155
+ const [matrix, manifest, provenance] = await Promise.all([
156
+ files.Get(snapshot.MatrixFileID),
157
+ files.Get(snapshot.RowManifestFileID),
158
+ files.Get(snapshot.ProvenanceFileID),
159
+ ]);
160
+ const matrixSha256 = SnapshotManifest.VerifiedSha256('matrix', matrix, snapshot.MatrixSha256);
161
+ const manifestSha256 = SnapshotManifest.VerifiedSha256('manifest', manifest, snapshot.RowManifestSha256);
162
+ SnapshotManifest.VerifiedSha256('provenance', provenance, snapshot.ProvenanceSha256);
163
+ const contentHash = SnapshotFiles.ComputeSnapshotContentHash({
164
+ MatrixSha256: matrixSha256,
165
+ RowManifestSha256: manifestSha256,
166
+ FeatureSchemaHash: snapshot.FeatureSchemaHash,
167
+ PredictionUnitID: snapshot.PredictionUnitID,
168
+ LabelVersion: snapshot.LabelVersion,
169
+ FeatureSpecVersion: snapshot.FeatureSpecVersion,
170
+ EvaluationProtocolID: snapshot.EvaluationProtocolID,
171
+ // The column holds the cutoff day at UTC midnight (the builder writes it so), so its UTC date is the day hashed.
172
+ DataCutoff: UtcDay.UtcDayIso(snapshot.DataCutoff),
173
+ });
174
+ if (contentHash !== snapshot.ContentHash)
175
+ throw new SnapshotIntegrityError('content', snapshot.ContentHash, contentHash);
176
+ return SnapshotFiles.ParseSnapshotFiles(matrix, manifest, provenance);
177
+ }
178
+ /** The run's results envelope, parsed once; a run without a readable envelope is refused, naming it. */
179
+ StoredResultsOf(run) {
180
+ const results = TrainingRunResultsParser.ParseTrainingRunResults(run.ValidationResults);
181
+ if (results.Ok === false)
182
+ throw new Error(`Training run ${run.ID} has no readable results: ${results.Errors.join('; ')}`);
183
+ return results.Value;
184
+ }
185
+ /** Where the run and its snapshot are read: `deps.snapshots`, or the RunView store on the request's provider. */
186
+ SnapshotStore(deps) {
187
+ return deps.snapshots || new RunViewTrainingSnapshotStore(deps.provider, deps.contextUser);
188
+ }
189
+ /** Where the snapshot files are read: `deps.snapshotFiles`, or the storage-provider store on the request's provider. */
190
+ FileStore(deps) {
191
+ return deps.snapshotFiles || StorageProviderSnapshotFileStore.ForProviderName(deps.entityFactory, deps.provider, deps.contextUser);
192
+ }
193
+ }
194
+ //# sourceMappingURL=snapshot-retrainer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"snapshot-retrainer.js","sourceRoot":"","sources":["../../src/snapshot/snapshot-retrainer.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAEpD,OAAO,EACL,cAAc,EACd,eAAe,EACf,wBAAwB,EACxB,MAAM,GAOP,MAAM,wCAAwC,CAAC;AAEhD,OAAO,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAC;AACpE,OAAO,EAAE,uBAAuB,EAAE,8BAA8B,EAAE,MAAM,uCAAuC,CAAC;AAChH,OAAO,EAAE,0BAA0B,EAAE,MAAM,+BAA+B,CAAC;AAC3E,OAAO,EAAE,aAAa,EAAwB,MAAM,0BAA0B,CAAC;AAC/E,OAAO,EAAE,sBAAsB,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAC/E,OAAO,EAAE,gCAAgC,EAA2B,MAAM,uBAAuB,CAAC;AAClG,OAAO,EAAE,4BAA4B,EAA+B,MAAM,2BAA2B,CAAC;AAsCtG;;;GAGG;AACH,MAAM,OAAO,iBAAiB;IAC5B,uGAAuG;aAChF,qBAAgB,GAAG,IAAI,CAAC;IAE/C;;;;;;;;;;;OAWG;IACI,KAAK,CAAC,OAAO,CAAC,aAAqB,EAAE,IAAkB,EAAE,YAAoB,iBAAiB,CAAC,gBAAgB;QACpH,MAAM,KAAK,GAAG,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;QACvC,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,OAAO,CAAC,aAAa,CAAC,CA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,CAAC,CAAC;IAC7F,CAAC;IAED,wHAAwH;IAC9G,SAAS,CAAC,IAAkB;QACpC,OAAO,IAAI,CAAC,aAAa,IAAI,gCAAgC,CAAC,eAAe,CAAC,IAAI,CAAC,aAAa,EAAE,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC;IACrI,CAAC"}
@@ -0,0 +1,99 @@
1
+ import type { RowProvenance, SnapshotCell, SnapshotFeatureColumn, SnapshotMatrixHeader, SnapshotRowKey } from '@memberjunction/predictive-studio-core';
2
+ /** A Training Snapshot's content: the header, the rows, and the aligned manifest and provenance lines. */
3
+ export interface SnapshotContent {
4
+ readonly Header: SnapshotMatrixHeader;
5
+ readonly Rows: readonly (readonly SnapshotCell[])[];
6
+ readonly Manifest: readonly SnapshotRowKey[];
7
+ readonly Provenance: readonly RowProvenance[];
8
+ }
9
+ /** The three snapshot files' bytes. */
10
+ export interface SnapshotFileBytes {
11
+ readonly Matrix: Uint8Array;
12
+ readonly Manifest: Uint8Array;
13
+ readonly Provenance: Uint8Array;
14
+ }
15
+ /**
16
+ * The inputs of a Training Snapshot's content hash (the `ContentHash` column). The provenance file's hash is stored on
17
+ * the snapshot and verified when the files are read back, but it is not an input here (see
18
+ * `SnapshotFiles.ComputeSnapshotContentHash`).
19
+ */
20
+ export interface SnapshotContentHashInput {
21
+ readonly MatrixSha256: string;
22
+ readonly RowManifestSha256: string;
23
+ readonly FeatureSchemaHash: string;
24
+ readonly PredictionUnitID: string;
25
+ readonly LabelVersion: number;
26
+ readonly FeatureSpecVersion: number;
27
+ readonly EvaluationProtocolID: string | null;
28
+ /** The data cutoff day, `YYYY-MM-DD`. */
29
+ readonly DataCutoff: string;
30
+ }
31
+ /** A snapshot file line that is not what the writer writes; names the file and the 1-based line. */
32
+ export declare class SnapshotFileFormatError extends Error {
33
+ readonly File: string;
34
+ readonly Line: number;
35
+ readonly Problems: readonly string[];
36
+ constructor(File: string, Line: number, Problems: readonly string[]);
37
+ }
38
+ /**
39
+ * A numeric cell that is NaN or infinite. JSON has no such number (it would be written as `null`, silently turning a
40
+ * computation error into a missing value), so the writer refuses it and names the row and column.
41
+ */
42
+ export declare class SnapshotNonFiniteCellError extends Error {
43
+ readonly RowID: string;
44
+ readonly Column: string;
45
+ readonly Value: number;
46
+ constructor(RowID: string, Column: string, Value: number);
47
+ }
48
+ /** The Training Snapshot file format: serialize, parse and fingerprint. */
49
+ export declare class SnapshotFiles {
50
+ /**
51
+ * The content as the three files' bytes. Refuses content whose rows, manifest and provenance do not align, a row
52
+ * whose width differs from the header's columns, and a NaN or infinite numeric cell.
53
+ */
54
+ static SerializeSnapshotFiles(c: SnapshotContent): SnapshotFileBytes;
55
+ /**
56
+ * The three files back to content. Every line is checked with its store schema — a stored file is text that a hash
57
+ * check proves unchanged, not well-formed — and so is the structure across the files: every matrix row is as wide
58
+ * as the header's columns, the matrix rows, manifest lines and provenance lines are equally many, and provenance
59
+ * line i carries manifest line i's rowId. A violation throws `SnapshotFileFormatError` naming the file and line.
60
+ */
61
+ static ParseSnapshotFiles(matrix: Uint8Array, manifest: Uint8Array, provenance: Uint8Array): SnapshotContent;
62
+ /** The manifest file's rows, each checked with `StoreSchemas.SnapshotRowKey` (also read alone, without the matrix). */
63
+ static ParseManifestLines(manifest: Uint8Array): SnapshotRowKey[];
64
+ /** SHA-256 of the canonical JSON of each feature column's name, encoding kind and source column, in column order. */
65
+ static ComputeFeatureSchemaHash(columns: readonly SnapshotFeatureColumn[]): string;
66
+ /**
67
+ * The snapshot's content hash: SHA-256 of the canonical JSON of the matrix and row-manifest file hashes, the feature
68
+ * schema hash, PredictionUnitID, LabelVersion, FeatureSpecVersion, EvaluationProtocolID and DataCutoff. The matrix
69
+ * file holds the header, so the encodings, incumbent and slice columns and decision spec are covered through its
70
+ * hash.
71
+ *
72
+ * The provenance file is deliberately outside the hash: it records when each value was computed (aggregates, series
73
+ * and missing values carry the assembly time), so including it would give identical data a new hash on every
74
+ * assembly, and identical data must resolve to one snapshot. Its own hash is stored and verified on read.
75
+ *
76
+ * IDs are normalized, so the hash does not depend on the database's UUID casing. `DataCutoff` must be a
77
+ * `YYYY-MM-DD` day; any other spelling of the same cutoff would hash differently, so it is refused.
78
+ */
79
+ static ComputeSnapshotContentHash(x: SnapshotContentHashInput): string;
80
+ /** A NaN or infinite numeric cell throws `SnapshotNonFiniteCellError` naming the row id and column. */
81
+ private static refuseNonFinite;
82
+ /**
83
+ * Matrix row i is manifest line i is provenance line i, so the three counts must agree. The refusal names the first
84
+ * line that has no partner: in the longer file when it has extra lines, in the manifest when it is the longer one.
85
+ */
86
+ private static refuseCountMismatch;
87
+ /** JSON Lines bytes: one item per line, each line terminated by `\n`. */
88
+ private static lines;
89
+ /**
90
+ * JSON Lines → parsed JSON values with their 1-based line numbers. Only the final line terminator is dropped, so a
91
+ * blank line inside the file is refused (it is not JSON) and every reported line number is the file's own.
92
+ */
93
+ private static jsonLines;
94
+ /** One matrix row line: a schema-checked array exactly as wide as the header's columns. */
95
+ private static checkRow;
96
+ /** One line checked by its store schema; a mismatch throws `SnapshotFileFormatError` naming the file and line. */
97
+ private static check;
98
+ }
99
+ //# sourceMappingURL=snapshot-serialization.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"snapshot-serialization.d.ts","sourceRoot":"","sources":["../../src/snapshot/snapshot-serialization.ts"],"names":[],"mappings":"AAmBA,OAAO,KAAK,EACV,aAAa,EACb,YAAY,EACZ,qBAAqB,EACrB,oBAAoB,EACpB,cAAc,EACf,MAAM,wCAAwC,CAAC;AAGhD,0GAA0G;AAC1G,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,MAAM,EAAE,oBAAoB,CAAC;IACtC,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC,SAAS,YAAY,EAAE,CAAC,EAAE,CAAC;IACpD,QAAQ,CAAC,QAAQ,EAAE,SAAS,cAAc,EAAE,CAAC;IAC7C,QAAQ,CAAC,UAAU,EAAE,SAAS,aAAa,EAAE,CAAC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,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,GAAG,eAAe;IAmBnH,uHAAuH;WACzG,kBAAkB,CAAC,QAAQ,EAAE,UAAU,GAAG,cAAc,EAAE;IAKxE,qHAAqH;WACvG,wBAAwB,CAAC,OAAO,EAAE,SAAS,qBAAqB,EAAE,GAAG,MAAM;IAKzF;;;;;;;;;;;;OAYG;WACW,0BAA0B,CAAC,CAAC,EAAE,wBAAwB,GAAG,MAAM;IAc7E,uGAAuG;IACvG,OAAO,CAAC,MAAM,CAAC,eAAe;IAM9B;;;OAGG;IACH,OAAO,CAAC,MAAM,CAAC,mBAAmB;IAQlC,yEAAyE;IACzE,OAAO,CAAC,MAAM,CAAC,KAAK;IAIpB;;;OAGG;IACH,OAAO,CAAC,MAAM,CAAC,SAAS;IAUxB,2FAA2F;IAC3F,OAAO,CAAC,MAAM,CAAC,QAAQ;IASvB,kHAAkH;IAClH,OAAO,CAAC,MAAM,CAAC,KAAK;CAKrB"}
@@ -0,0 +1,191 @@
1
+ /**
2
+ * @module snapshot/snapshot-serialization
3
+ *
4
+ * The three Training Snapshot files, as UTF-8 JSON Lines:
5
+ * - `matrix.jsonl` — line 1 is the header the trainer reads: the format tag, every column in row order, the label
6
+ * column, each feature column's source column and full `ColumnEncoding`, the optional incumbent-score,
7
+ * reference-score and slice columns, the unit's `DecisionSpec`, and the sidecar feature schema and preprocessing
8
+ * recipe; then one JSON array per manifest row.
9
+ * - `manifest.jsonl` — one `SnapshotRowKey` per row, in the same order: matrix row i is manifest line i.
10
+ * - `provenance.jsonl` — one `RowProvenance` (`{ rowId, values }`) per row, in the same order (stored as
11
+ * `provenance-<sha256>.jsonl`, since provenance is outside the content hash).
12
+ *
13
+ * The persisted shapes, reserved column names and their schemas are Core's (`snapshot-format`, `StoreSchemas`); this
14
+ * module writes, reads and fingerprints the bytes. Every line is written through MJ's `Canonicalize` from
15
+ * `@memberjunction/global` (keys sorted at every depth, no whitespace), so identical content produces byte-identical
16
+ * files whatever order its keys were built in, and the file hashes identify the content.
17
+ */
18
+ import { Canonicalize, NormalizeUUID } from '@memberjunction/global';
19
+ import { JsonParse, StoreSchemas } from '@memberjunction/predictive-studio-core';
20
+ import { SnapshotHash } from './snapshot-hash.js';
21
+ /** A snapshot file line that is not what the writer writes; names the file and the 1-based line. */
22
+ export class SnapshotFileFormatError extends Error {
23
+ constructor(File, Line, Problems) {
24
+ super(`Snapshot ${File} file, line ${Line}: ${Problems.join('; ')}`);
25
+ this.File = File;
26
+ this.Line = Line;
27
+ this.Problems = Problems;
28
+ this.name = 'SnapshotFileFormatError';
29
+ }
30
+ }
31
+ /**
32
+ * A numeric cell that is NaN or infinite. JSON has no such number (it would be written as `null`, silently turning a
33
+ * computation error into a missing value), so the writer refuses it and names the row and column.
34
+ */
35
+ export class SnapshotNonFiniteCellError extends Error {
36
+ constructor(RowID, Column, Value) {
37
+ super(`Snapshot row ${RowID}, column ${Column}: ${String(Value)} is not a finite number`);
38
+ this.RowID = RowID;
39
+ this.Column = Column;
40
+ this.Value = Value;
41
+ this.name = 'SnapshotNonFiniteCellError';
42
+ }
43
+ }
44
+ /** A calendar day, `YYYY-MM-DD`. */
45
+ const DAY = /^\d{4}-\d{2}-\d{2}$/;
46
+ const encoder = new TextEncoder();
47
+ const decoder = new TextDecoder();
48
+ /** The Training Snapshot file format: serialize, parse and fingerprint. */
49
+ export class SnapshotFiles {
50
+ /**
51
+ * The content as the three files' bytes. Refuses content whose rows, manifest and provenance do not align, a row
52
+ * whose width differs from the header's columns, and a NaN or infinite numeric cell.
53
+ */
54
+ static SerializeSnapshotFiles(c) {
55
+ if (c.Rows.length !== c.Manifest.length || c.Provenance.length !== c.Manifest.length) {
56
+ throw new Error(`Snapshot rows (${c.Rows.length}), manifest (${c.Manifest.length}) and provenance (${c.Provenance.length})`
57
+ + ' must align');
58
+ }
59
+ c.Rows.forEach((r, i) => {
60
+ if (r.length !== c.Header.columns.length) {
61
+ throw new Error(`Snapshot row ${i} has ${r.length} cells; the header lists ${c.Header.columns.length} columns`);
62
+ }
63
+ SnapshotFiles.refuseNonFinite(r, c.Manifest[i].rowId, c.Header.columns);
64
+ });
65
+ return {
66
+ Matrix: SnapshotFiles.lines([Canonicalize(c.Header), ...c.Rows.map((r) => Canonicalize(r))]),
67
+ Manifest: SnapshotFiles.lines(c.Manifest.map((m) => Canonicalize(m))),
68
+ Provenance: SnapshotFiles.lines(c.Provenance.map((p) => Canonicalize(p))),
69
+ };
70
+ }
71
+ /**
72
+ * The three files back to content. Every line is checked with its store schema — a stored file is text that a hash
73
+ * check proves unchanged, not well-formed — and so is the structure across the files: every matrix row is as wide
74
+ * as the header's columns, the matrix rows, manifest lines and provenance lines are equally many, and provenance
75
+ * line i carries manifest line i's rowId. A violation throws `SnapshotFileFormatError` naming the file and line.
76
+ */
77
+ static ParseSnapshotFiles(matrix, manifest, provenance) {
78
+ const [headerLine, ...rowLines] = SnapshotFiles.jsonLines('matrix', matrix);
79
+ if (headerLine === undefined)
80
+ throw new SnapshotFileFormatError('matrix', 1, ['the matrix file has no header line']);
81
+ const header = SnapshotFiles.check('matrix', headerLine, StoreSchemas.SnapshotMatrixHeader);
82
+ const rows = rowLines.map((r) => SnapshotFiles.checkRow(r, header.columns.length));
83
+ const keys = SnapshotFiles.ParseManifestLines(manifest);
84
+ const provenanceLines = SnapshotFiles.jsonLines('provenance', provenance);
85
+ const lineage = provenanceLines.map((p) => SnapshotFiles.check('provenance', p, StoreSchemas.RowProvenance));
86
+ SnapshotFiles.refuseCountMismatch(rows.length, keys.length, lineage.length);
87
+ lineage.forEach((p, i) => {
88
+ const expected = keys[i].rowId;
89
+ if (p.rowId !== expected) {
90
+ const problem = `rowId "${p.rowId}" is not manifest line ${i + 1}'s rowId "${expected}"`;
91
+ throw new SnapshotFileFormatError('provenance', i + 1, [problem]);
92
+ }
93
+ });
94
+ return { Header: header, Rows: rows, Manifest: keys, Provenance: lineage };
95
+ }
96
+ /** The manifest file's rows, each checked with `StoreSchemas.SnapshotRowKey` (also read alone, without the matrix). */
97
+ static ParseManifestLines(manifest) {
98
+ return SnapshotFiles.jsonLines('manifest', manifest)
99
+ .map((m) => SnapshotFiles.check('manifest', m, StoreSchemas.SnapshotRowKey));
100
+ }
101
+ /** SHA-256 of the canonical JSON of each feature column's name, encoding kind and source column, in column order. */
102
+ static ComputeFeatureSchemaHash(columns) {
103
+ const entries = columns.map((c) => ({ name: c.name, encoding: c.encoding, sourceColumn: c.sourceColumn }));
104
+ return SnapshotHash.Sha256Hex(Canonicalize(entries));
105
+ }
106
+ /**
107
+ * The snapshot's content hash: SHA-256 of the canonical JSON of the matrix and row-manifest file hashes, the feature
108
+ * schema hash, PredictionUnitID, LabelVersion, FeatureSpecVersion, EvaluationProtocolID and DataCutoff. The matrix
109
+ * file holds the header, so the encodings, incumbent and slice columns and decision spec are covered through its
110
+ * hash.
111
+ *
112
+ * The provenance file is deliberately outside the hash: it records when each value was computed (aggregates, series
113
+ * and missing values carry the assembly time), so including it would give identical data a new hash on every
114
+ * assembly, and identical data must resolve to one snapshot. Its own hash is stored and verified on read.
115
+ *
116
+ * IDs are normalized, so the hash does not depend on the database's UUID casing. `DataCutoff` must be a
117
+ * `YYYY-MM-DD` day; any other spelling of the same cutoff would hash differently, so it is refused.
118
+ */
119
+ static ComputeSnapshotContentHash(x) {
120
+ if (!DAY.test(x.DataCutoff))
121
+ throw new Error(`Snapshot DataCutoff "${x.DataCutoff}" must be a YYYY-MM-DD day`);
122
+ return SnapshotHash.Sha256Hex(Canonicalize({
123
+ matrixSha256: x.MatrixSha256,
124
+ rowManifestSha256: x.RowManifestSha256,
125
+ featureSchemaHash: x.FeatureSchemaHash,
126
+ predictionUnitId: NormalizeUUID(x.PredictionUnitID),
127
+ labelVersion: x.LabelVersion,
128
+ featureSpecVersion: x.FeatureSpecVersion,
129
+ evaluationProtocolId: x.EvaluationProtocolID === null ? null : NormalizeUUID(x.EvaluationProtocolID),
130
+ dataCutoff: x.DataCutoff,
131
+ }));
132
+ }
133
+ /** A NaN or infinite numeric cell throws `SnapshotNonFiniteCellError` naming the row id and column. */
134
+ static refuseNonFinite(row, rowID, columns) {
135
+ row.forEach((cell, j) => {
136
+ if (typeof cell === 'number' && !Number.isFinite(cell))
137
+ throw new SnapshotNonFiniteCellError(rowID, columns[j], cell);
138
+ });
139
+ }
140
+ /**
141
+ * Matrix row i is manifest line i is provenance line i, so the three counts must agree. The refusal names the first
142
+ * line that has no partner: in the longer file when it has extra lines, in the manifest when it is the longer one.
143
+ */
144
+ static refuseCountMismatch(rows, manifest, provenance) {
145
+ const problem = [`the matrix has ${rows} rows, the manifest ${manifest} lines and the provenance ${provenance} lines`];
146
+ if (rows > manifest)
147
+ throw new SnapshotFileFormatError('matrix', manifest + 2, problem);
148
+ if (rows < manifest)
149
+ throw new SnapshotFileFormatError('manifest', rows + 1, problem);
150
+ if (provenance > manifest)
151
+ throw new SnapshotFileFormatError('provenance', manifest + 1, problem);
152
+ if (provenance < manifest)
153
+ throw new SnapshotFileFormatError('manifest', provenance + 1, problem);
154
+ }
155
+ /** JSON Lines bytes: one item per line, each line terminated by `\n`. */
156
+ static lines(items) {
157
+ return encoder.encode(items.map((l) => `${l}\n`).join(''));
158
+ }
159
+ /**
160
+ * JSON Lines → parsed JSON values with their 1-based line numbers. Only the final line terminator is dropped, so a
161
+ * blank line inside the file is refused (it is not JSON) and every reported line number is the file's own.
162
+ */
163
+ static jsonLines(file, bytes) {
164
+ const lines = decoder.decode(bytes).split('\n');
165
+ if (lines[lines.length - 1] === '')
166
+ lines.pop();
167
+ return lines.map((line, i) => {
168
+ const json = JsonParse.ParseJsonText(line, `${file} line ${i + 1}`);
169
+ if (json.Ok === false)
170
+ throw new SnapshotFileFormatError(file, i + 1, json.Errors);
171
+ return { Line: i + 1, Value: json.Value };
172
+ });
173
+ }
174
+ /** One matrix row line: a schema-checked array exactly as wide as the header's columns. */
175
+ static checkRow(line, width) {
176
+ const row = SnapshotFiles.check('matrix', line, StoreSchemas.SnapshotRow);
177
+ if (row.length !== width) {
178
+ const problem = `the row has ${row.length} cells; the header lists ${width} columns`;
179
+ throw new SnapshotFileFormatError('matrix', line.Line, [problem]);
180
+ }
181
+ return row;
182
+ }
183
+ /** One line checked by its store schema; a mismatch throws `SnapshotFileFormatError` naming the file and line. */
184
+ static check(file, line, schema) {
185
+ const checked = StoreSchemas.Validate(schema, line.Value);
186
+ if (checked.Ok === false)
187
+ throw new SnapshotFileFormatError(file, line.Line, checked.Errors);
188
+ return checked.Value;
189
+ }
190
+ }
191
+ //# sourceMappingURL=snapshot-serialization.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"snapshot-serialization.js","sourceRoot":"","sources":["../../src/snapshot/snapshot-serialization.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACrE,OAAO,EAAE,SAAS,EAAE,YAAY,EAAoC,MAAM,wCAAwC,CAAC;AAQnH,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAwC/C,oGAAoG;AACpG,MAAM,OAAO,uBAAwB,SAAQ,KAAK;IAChD,YAA4B,IAAY,EAAkB,IAAY,EAAkB,QAA2B;QACjH,KAAK,CAAC,YAAY,IAAI,eAAe,IAAI,KAAK,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAD3C,SAAI,GAAJ,IAAI,CAAQ;QAAkB,SAAI,GAAJ,IAAI,CAAQ;QAAkB,aAAQ,GAAR,QAAQ,CAAmB;QAEjH,IAAI,CAAC,IAAI,GAAG,yBAAyB,CAAC;IACxC,CAAC;CACF;AAED;;;GAGG;AACH,MAAM,OAAO,0BAA2B,SAAQ,KAAK;IACnD,YAA4B,KAAa,EAAkB,MAAc,EAAkB,KAAa;QACtG,KAAK,CAAC,gBAAgB,KAAK,YAAY,MAAM,KAAK,MAAM,CAAC,KAAK,CAAC,yBAAyB,CAAC,CAAC;QADhE,UAAK,G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,OAAO,CAAC,KAAK,CAAC;IACvB,CAAC;CACF"}
@@ -0,0 +1,38 @@
1
+ /**
2
+ * @module snapshot/training-snapshot-store
3
+ *
4
+ * Reading Training Snapshots and the runs that reference them: by content hash (identical content resolves to one
5
+ * snapshot), by snapshot ID and by run ID. Training finds an existing snapshot through it; a retraining loads the run
6
+ * and its snapshot through the same seam.
7
+ */
8
+ import { type IMetadataProvider, type UserInfo } from '@memberjunction/core';
9
+ import type { MJMLTrainingRunEntity, MJMLTrainingSnapshotEntity } from '@memberjunction/core-entities';
10
+ /** Reads Training Snapshots and training runs. */
11
+ export interface ITrainingSnapshotStore {
12
+ /** The snapshot with this content hash, or null. */
13
+ FindByContentHash(contentHash: string): Promise<MJMLTrainingSnapshotEntity | null>;
14
+ /** The snapshot with this ID, or null. */
15
+ LoadSnapshot(id: string): Promise<MJMLTrainingSnapshotEntity | null>;
16
+ /** The training run with this ID, or null. */
17
+ LoadRun(id: string): Promise<MJMLTrainingRunEntity | null>;
18
+ /** The training run hung off this Experiment Session Iteration, or null when none was written. */
19
+ FindRunForIteration(iterationId: string): Promise<MJMLTrainingRunEntity | null>;
20
+ }
21
+ /** Reads through the request's provider (never the global one), as the request's user. A failed read throws. */
22
+ export declare class RunViewTrainingSnapshotStore implements ITrainingSnapshotStore {
23
+ private readonly contextUser;
24
+ private readonly runView;
25
+ constructor(provider: IMetadataProvider, contextUser: UserInfo);
26
+ /**
27
+ * The snapshot with this content hash, as an entity object (it becomes the run's snapshot). Read past the cache: the
28
+ * builder also calls this after its own save lost the content-hash race, and only the database can say which
29
+ * snapshot won.
30
+ */
31
+ FindByContentHash(contentHash: string): Promise<MJMLTrainingSnapshotEntity | null>;
32
+ LoadSnapshot(id: string): Promise<MJMLTrainingSnapshotEntity | null>;
33
+ LoadRun(id: string): Promise<MJMLTrainingRunEntity | null>;
34
+ /** Read past the cache: the run was written moments ago by the attempt that just failed. */
35
+ FindRunForIteration(iterationId: string): Promise<MJMLTrainingRunEntity | null>;
36
+ private first;
37
+ }
38
+ //# sourceMappingURL=training-snapshot-store.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"training-snapshot-store.d.ts","sourceRoot":"","sources":["../../src/snapshot/training-snapshot-store.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAW,KAAK,iBAAiB,EAAE,KAAK,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAEtF,OAAO,KAAK,EAAE,qBAAqB,EAAE,0BAA0B,EAAE,MAAM,+BAA+B,CAAC;AAEvG,kDAAkD;AAClD,MAAM,WAAW,sBAAsB;IACrC,oDAAoD;IACpD,iBAAiB,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,0BAA0B,GAAG,IAAI,CAAC,CAAC;IACnF,0CAA0C;IAC1C,YAAY,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,0BAA0B,GAAG,IAAI,CAAC,CAAC;IACrE,8CAA8C;IAC9C,OAAO,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,qBAAqB,GAAG,IAAI,CAAC,CAAC;IAC3D,kGAAkG;IAClG,mBAAmB,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,qBAAqB,GAAG,IAAI,CAAC,CAAC;CACjF;AAED,gHAAgH;AAChH,qBAAa,4BAA6B,YAAW,sBAAsB;IAEhC,OAAO,CAAC,QAAQ,CAAC,WAAW;IADrE,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAU;gBACtB,QAAQ,EAAE,iBAAiB,EAAmB,WAAW,EAAE,QAAQ;IAI/E;;;;OAIG;IACU,iBAAiB,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,0BAA0B,GAAG,IAAI,CAAC;IAIlF,YAAY,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,0BAA0B,GAAG,IAAI,CAAC;IAIpE,OAAO,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,qBAAqB,GAAG,IAAI,CAAC;IAIvE,4FAA4F;IAC/E,mBAAmB,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,qBAAqB,GAAG,IAAI,CAAC;YAI9E,KAAK;CAKpB"}
@@ -0,0 +1,41 @@
1
+ /**
2
+ * @module snapshot/training-snapshot-store
3
+ *
4
+ * Reading Training Snapshots and the runs that reference them: by content hash (identical content resolves to one
5
+ * snapshot), by snapshot ID and by run ID. Training finds an existing snapshot through it; a retraining loads the run
6
+ * and its snapshot through the same seam.
7
+ */
8
+ import { RunView } from '@memberjunction/core';
9
+ import { EscapeSQLString } from '@memberjunction/global';
10
+ /** Reads through the request's provider (never the global one), as the request's user. A failed read throws. */
11
+ export class RunViewTrainingSnapshotStore {
12
+ constructor(provider, contextUser) {
13
+ this.contextUser = contextUser;
14
+ this.runView = RunView.FromMetadataProvider(provider);
15
+ }
16
+ /**
17
+ * The snapshot with this content hash, as an entity object (it becomes the run's snapshot). Read past the cache: the
18
+ * builder also calls this after its own save lost the content-hash race, and only the database can say which
19
+ * snapshot won.
20
+ */
21
+ async FindByContentHash(contentHash) {
22
+ return this.first('MJ: ML Training Snapshots', `ContentHash='${EscapeSQLString(contentHash)}'`, true);
23
+ }
24
+ async LoadSnapshot(id) {
25
+ return this.first('MJ: ML Training Snapshots', `ID='${EscapeSQLString(id)}'`, false);
26
+ }
27
+ async LoadRun(id) {
28
+ return this.first('MJ: ML Training Runs', `ID='${EscapeSQLString(id)}'`, false);
29
+ }
30
+ /** Read past the cache: the run was written moments ago by the attempt that just failed. */
31
+ async FindRunForIteration(iterationId) {
32
+ return this.first('MJ: ML Training Runs', `ExperimentSessionIterationID='${EscapeSQLString(iterationId)}'`, true);
33
+ }
34
+ async first(entityName, filter, bypassCache) {
35
+ const r = await this.runView.RunView({ EntityName: entityName, ExtraFilter: filter, MaxRows: 1, ResultType: 'entity_object', BypassCache: bypassCache }, this.contextUser);
36
+ if (!r.Success)
37
+ throw new Error(`Reading ${entityName} (${filter}) failed: ${r.ErrorMessage}`);
38
+ return r.Results[0] || null;
39
+ }
40
+ }
41
+ //# sourceMappingURL=training-snapshot-store.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"training-snapshot-store.js","sourceRoot":"","sources":["../../src/snapshot/training-snapshot-store.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAE,OAAO,EAAyC,MAAM,sBAAsB,CAAC;AACtF,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAezD,gHAAgH;AAChH,MAAM,OAAO,4BAA4B;IAEvC,YAAY,QAA2B,EAAmB,WAAqB;QAArB,gBAAW,GAAX,WAAW,CAAU;QAC7E,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,oBAAoB,CAAC,QAAQ,CAAC,CAAC;IACxD,CAAC;IAED;;;;OAIG;IACI,KAAK,CAAC,iBAAiB,CAAC,WAAmB;QAChD,OAAO,IAAI,CAAC,KAAK,CAA6B,2BAA2B,EAAE,gBAAgB,eAAe,CAAC,WAAW,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;IACpI,CAAC;IAEM,KAAK,CAAC,YAAY,CAAC,EAAU;QAClC,OAAO,IAAI,CAAC,KAAK,CAA6B,2BAA2B,EAAE,OAAO,eAAe,CAAC,EAAE,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IACnH,CAAC;IAEM,KAAK,CAAC,OAAO,CAAC,EAAU;QAC7B,OAAO,IAAI,CAAC,KAAK,CAAwB,sBAAsB,EAAE,OAAO,eAAe,CAAC,EAAE,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IACzG,CAAC;IAED,4FAA4F;IACrF,KAAK,CAAC,mBAAmB,CAAC,WAAmB;QAClD,OAAO,IAAI,CAAC,KAAK,CAAwB,sBAAsB,EAAE,iCAAiC,eAAe,CAAC,WAAW,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;IAC3I,CAAC;IAEO,KAAK,CAAC,KAAK,CAA+D,UAAkB,EAAE,MAAc,EAAE,WAA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