@memberjunction/predictive-studio 0.0.1 → 5.44.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (266) hide show
  1. package/README.md +101 -28
  2. package/dist/actions/base-predictive-studio.action.d.ts +63 -0
  3. package/dist/actions/base-predictive-studio.action.d.ts.map +1 -0
  4. package/dist/actions/base-predictive-studio.action.js +125 -0
  5. package/dist/actions/base-predictive-studio.action.js.map +1 -0
  6. package/dist/actions/index.d.ts +38 -0
  7. package/dist/actions/index.d.ts.map +1 -0
  8. package/dist/actions/index.js +49 -0
  9. package/dist/actions/index.js.map +1 -0
  10. package/dist/actions/model-scoring-action-generator.d.ts +108 -0
  11. package/dist/actions/model-scoring-action-generator.d.ts.map +1 -0
  12. package/dist/actions/model-scoring-action-generator.js +316 -0
  13. package/dist/actions/model-scoring-action-generator.js.map +1 -0
  14. package/dist/actions/promote-model.action.d.ts +102 -0
  15. package/dist/actions/promote-model.action.d.ts.map +1 -0
  16. package/dist/actions/promote-model.action.js +132 -0
  17. package/dist/actions/promote-model.action.js.map +1 -0
  18. package/dist/actions/promote-model.gate.d.ts +77 -0
  19. package/dist/actions/promote-model.gate.d.ts.map +1 -0
  20. package/dist/actions/promote-model.gate.js +205 -0
  21. package/dist/actions/promote-model.gate.js.map +1 -0
  22. package/dist/actions/run-experiment.action.d.ts +60 -0
  23. package/dist/actions/run-experiment.action.d.ts.map +1 -0
  24. package/dist/actions/run-experiment.action.js +134 -0
  25. package/dist/actions/run-experiment.action.js.map +1 -0
  26. package/dist/actions/run-experiment.deps.d.ts +47 -0
  27. package/dist/actions/run-experiment.deps.d.ts.map +1 -0
  28. package/dist/actions/run-experiment.deps.js +71 -0
  29. package/dist/actions/run-experiment.deps.js.map +1 -0
  30. package/dist/actions/schedule-model-scoring.action.d.ts +71 -0
  31. package/dist/actions/schedule-model-scoring.action.d.ts.map +1 -0
  32. package/dist/actions/schedule-model-scoring.action.js +148 -0
  33. package/dist/actions/schedule-model-scoring.action.js.map +1 -0
  34. package/dist/actions/score-record-set.action.d.ts +133 -0
  35. package/dist/actions/score-record-set.action.d.ts.map +1 -0
  36. package/dist/actions/score-record-set.action.js +136 -0
  37. package/dist/actions/score-record-set.action.js.map +1 -0
  38. package/dist/actions/score-record-set.runner.d.ts +192 -0
  39. package/dist/actions/score-record-set.runner.d.ts.map +1 -0
  40. package/dist/actions/score-record-set.runner.js +416 -0
  41. package/dist/actions/score-record-set.runner.js.map +1 -0
  42. package/dist/actions/train-model.action.d.ts +57 -0
  43. package/dist/actions/train-model.action.d.ts.map +1 -0
  44. package/dist/actions/train-model.action.js +111 -0
  45. package/dist/actions/train-model.action.js.map +1 -0
  46. package/dist/agent/index.d.ts +14 -0
  47. package/dist/agent/index.d.ts.map +1 -0
  48. package/dist/agent/index.js +14 -0
  49. package/dist/agent/index.js.map +1 -0
  50. package/dist/agent/model-dev-orchestrator-agent.d.ts +42 -0
  51. package/dist/agent/model-dev-orchestrator-agent.d.ts.map +1 -0
  52. package/dist/agent/model-dev-orchestrator-agent.js +76 -0
  53. package/dist/agent/model-dev-orchestrator-agent.js.map +1 -0
  54. package/dist/agent/modeling-plan-to-pipeline.d.ts +49 -0
  55. package/dist/agent/modeling-plan-to-pipeline.d.ts.map +1 -0
  56. package/dist/agent/modeling-plan-to-pipeline.js +101 -0
  57. package/dist/agent/modeling-plan-to-pipeline.js.map +1 -0
  58. package/dist/agent/pipeline-builder-agent.d.ts +58 -0
  59. package/dist/agent/pipeline-builder-agent.d.ts.map +1 -0
  60. package/dist/agent/pipeline-builder-agent.js +101 -0
  61. package/dist/agent/pipeline-builder-agent.js.map +1 -0
  62. package/dist/agent/pipeline-builder.d.ts +67 -0
  63. package/dist/agent/pipeline-builder.d.ts.map +1 -0
  64. package/dist/agent/pipeline-builder.js +114 -0
  65. package/dist/agent/pipeline-builder.js.map +1 -0
  66. package/dist/experiment/concurrency.d.ts +41 -0
  67. package/dist/experiment/concurrency.d.ts.map +1 -0
  68. package/dist/experiment/concurrency.js +54 -0
  69. package/dist/experiment/concurrency.js.map +1 -0
  70. package/dist/experiment/experiment-orchestrator.d.ts +136 -0
  71. package/dist/experiment/experiment-orchestrator.d.ts.map +1 -0
  72. package/dist/experiment/experiment-orchestrator.js +408 -0
  73. package/dist/experiment/experiment-orchestrator.js.map +1 -0
  74. package/dist/experiment/index.d.ts +17 -0
  75. package/dist/experiment/index.d.ts.map +1 -0
  76. package/dist/experiment/index.js +17 -0
  77. package/dist/experiment/index.js.map +1 -0
  78. package/dist/experiment/leaderboard.d.ts +50 -0
  79. package/dist/experiment/leaderboard.d.ts.map +1 -0
  80. package/dist/experiment/leaderboard.js +91 -0
  81. package/dist/experiment/leaderboard.js.map +1 -0
  82. package/dist/experiment/seams.d.ts +95 -0
  83. package/dist/experiment/seams.d.ts.map +1 -0
  84. package/dist/experiment/seams.js +126 -0
  85. package/dist/experiment/seams.js.map +1 -0
  86. package/dist/experiment/types.d.ts +228 -0
  87. package/dist/experiment/types.d.ts.map +1 -0
  88. package/dist/experiment/types.js +19 -0
  89. package/dist/experiment/types.js.map +1 -0
  90. package/dist/experiment/wave-strategist.d.ts +31 -0
  91. package/dist/experiment/wave-strategist.d.ts.map +1 -0
  92. package/dist/experiment/wave-strategist.js +50 -0
  93. package/dist/experiment/wave-strategist.js.map +1 -0
  94. package/dist/feature-assembly/as-of.d.ts +74 -0
  95. package/dist/feature-assembly/as-of.d.ts.map +1 -0
  96. package/dist/feature-assembly/as-of.js +136 -0
  97. package/dist/feature-assembly/as-of.js.map +1 -0
  98. package/dist/feature-assembly/data-access.d.ts +114 -0
  99. package/dist/feature-assembly/data-access.d.ts.map +1 -0
  100. package/dist/feature-assembly/data-access.js +68 -0
  101. package/dist/feature-assembly/data-access.js.map +1 -0
  102. package/dist/feature-assembly/feature-assembly-executor.d.ts +273 -0
  103. package/dist/feature-assembly/feature-assembly-executor.d.ts.map +1 -0
  104. package/dist/feature-assembly/feature-assembly-executor.js +521 -0
  105. package/dist/feature-assembly/feature-assembly-executor.js.map +1 -0
  106. package/dist/feature-assembly/index.d.ts +13 -0
  107. package/dist/feature-assembly/index.d.ts.map +1 -0
  108. package/dist/feature-assembly/index.js +13 -0
  109. package/dist/feature-assembly/index.js.map +1 -0
  110. package/dist/feature-assembly/leakage-guard.d.ts +86 -0
  111. package/dist/feature-assembly/leakage-guard.d.ts.map +1 -0
  112. package/dist/feature-assembly/leakage-guard.js +111 -0
  113. package/dist/feature-assembly/leakage-guard.js.map +1 -0
  114. package/dist/feature-assembly/vision-llm.d.ts +125 -0
  115. package/dist/feature-assembly/vision-llm.d.ts.map +1 -0
  116. package/dist/feature-assembly/vision-llm.js +211 -0
  117. package/dist/feature-assembly/vision-llm.js.map +1 -0
  118. package/dist/feature-pipelines/feature-pipeline-engine.d.ts +159 -0
  119. package/dist/feature-pipelines/feature-pipeline-engine.d.ts.map +1 -0
  120. package/dist/feature-pipelines/feature-pipeline-engine.js +298 -0
  121. package/dist/feature-pipelines/feature-pipeline-engine.js.map +1 -0
  122. package/dist/feature-pipelines/index.d.ts +13 -0
  123. package/dist/feature-pipelines/index.d.ts.map +1 -0
  124. package/dist/feature-pipelines/index.js +13 -0
  125. package/dist/feature-pipelines/index.js.map +1 -0
  126. package/dist/feature-pipelines/types.d.ts +72 -0
  127. package/dist/feature-pipelines/types.d.ts.map +1 -0
  128. package/dist/feature-pipelines/types.js +17 -0
  129. package/dist/feature-pipelines/types.js.map +1 -0
  130. package/dist/index.d.ts +37 -0
  131. package/dist/index.d.ts.map +1 -0
  132. package/dist/index.js +80 -0
  133. package/dist/index.js.map +1 -0
  134. package/dist/maintenance/index.d.ts +19 -0
  135. package/dist/maintenance/index.d.ts.map +1 -0
  136. package/dist/maintenance/index.js +19 -0
  137. package/dist/maintenance/index.js.map +1 -0
  138. package/dist/maintenance/maintenance-engine.d.ts +152 -0
  139. package/dist/maintenance/maintenance-engine.d.ts.map +1 -0
  140. package/dist/maintenance/maintenance-engine.js +412 -0
  141. package/dist/maintenance/maintenance-engine.js.map +1 -0
  142. package/dist/maintenance/metrics.d.ts +37 -0
  143. package/dist/maintenance/metrics.d.ts.map +1 -0
  144. package/dist/maintenance/metrics.js +85 -0
  145. package/dist/maintenance/metrics.js.map +1 -0
  146. package/dist/maintenance/seams.d.ts +85 -0
  147. package/dist/maintenance/seams.d.ts.map +1 -0
  148. package/dist/maintenance/seams.js +166 -0
  149. package/dist/maintenance/seams.js.map +1 -0
  150. package/dist/maintenance/types.d.ts +318 -0
  151. package/dist/maintenance/types.d.ts.map +1 -0
  152. package/dist/maintenance/types.js +27 -0
  153. package/dist/maintenance/types.js.map +1 -0
  154. package/dist/operations/__tests__/helpers.d.ts +30 -0
  155. package/dist/operations/__tests__/helpers.d.ts.map +1 -0
  156. package/dist/operations/__tests__/helpers.js +44 -0
  157. package/dist/operations/__tests__/helpers.js.map +1 -0
  158. package/dist/operations/control-experiment-session.operation.d.ts +33 -0
  159. package/dist/operations/control-experiment-session.operation.d.ts.map +1 -0
  160. package/dist/operations/control-experiment-session.operation.js +71 -0
  161. package/dist/operations/control-experiment-session.operation.js.map +1 -0
  162. package/dist/operations/create-scoring-process.operation.d.ts +30 -0
  163. package/dist/operations/create-scoring-process.operation.d.ts.map +1 -0
  164. package/dist/operations/create-scoring-process.operation.js +65 -0
  165. package/dist/operations/create-scoring-process.operation.js.map +1 -0
  166. package/dist/operations/delegation.d.ts +113 -0
  167. package/dist/operations/delegation.d.ts.map +1 -0
  168. package/dist/operations/delegation.js +139 -0
  169. package/dist/operations/delegation.js.map +1 -0
  170. package/dist/operations/index.d.ts +40 -0
  171. package/dist/operations/index.d.ts.map +1 -0
  172. package/dist/operations/index.js +55 -0
  173. package/dist/operations/index.js.map +1 -0
  174. package/dist/operations/promote-model.operation.d.ts +57 -0
  175. package/dist/operations/promote-model.operation.d.ts.map +1 -0
  176. package/dist/operations/promote-model.operation.js +113 -0
  177. package/dist/operations/promote-model.operation.js.map +1 -0
  178. package/dist/operations/run-feature-pipeline.operation.d.ts +56 -0
  179. package/dist/operations/run-feature-pipeline.operation.d.ts.map +1 -0
  180. package/dist/operations/run-feature-pipeline.operation.js +94 -0
  181. package/dist/operations/run-feature-pipeline.operation.js.map +1 -0
  182. package/dist/operations/score-record-set.operation.d.ts +47 -0
  183. package/dist/operations/score-record-set.operation.d.ts.map +1 -0
  184. package/dist/operations/score-record-set.operation.js +113 -0
  185. package/dist/operations/score-record-set.operation.js.map +1 -0
  186. package/dist/operations/start-experiment-session.operation.d.ts +66 -0
  187. package/dist/operations/start-experiment-session.operation.d.ts.map +1 -0
  188. package/dist/operations/start-experiment-session.operation.js +132 -0
  189. package/dist/operations/start-experiment-session.operation.js.map +1 -0
  190. package/dist/operations/train-model.operation.d.ts +50 -0
  191. package/dist/operations/train-model.operation.d.ts.map +1 -0
  192. package/dist/operations/train-model.operation.js +114 -0
  193. package/dist/operations/train-model.operation.js.map +1 -0
  194. package/dist/scheduling/index.d.ts +13 -0
  195. package/dist/scheduling/index.d.ts.map +1 -0
  196. package/dist/scheduling/index.js +13 -0
  197. package/dist/scheduling/index.js.map +1 -0
  198. package/dist/scheduling/scheduled-model-scoring.d.ts +169 -0
  199. package/dist/scheduling/scheduled-model-scoring.d.ts.map +1 -0
  200. package/dist/scheduling/scheduled-model-scoring.js +189 -0
  201. package/dist/scheduling/scheduled-model-scoring.js.map +1 -0
  202. package/dist/scoring/artifact-loader.d.ts +65 -0
  203. package/dist/scoring/artifact-loader.d.ts.map +1 -0
  204. package/dist/scoring/artifact-loader.js +97 -0
  205. package/dist/scoring/artifact-loader.js.map +1 -0
  206. package/dist/scoring/index.d.ts +26 -0
  207. package/dist/scoring/index.d.ts.map +1 -0
  208. package/dist/scoring/index.js +26 -0
  209. package/dist/scoring/index.js.map +1 -0
  210. package/dist/scoring/ml-model-inference-processor.d.ts +154 -0
  211. package/dist/scoring/ml-model-inference-processor.d.ts.map +1 -0
  212. package/dist/scoring/ml-model-inference-processor.js +320 -0
  213. package/dist/scoring/ml-model-inference-processor.js.map +1 -0
  214. package/dist/scoring/ml-model-score-enricher.d.ts +80 -0
  215. package/dist/scoring/ml-model-score-enricher.d.ts.map +1 -0
  216. package/dist/scoring/ml-model-score-enricher.js +139 -0
  217. package/dist/scoring/ml-model-score-enricher.js.map +1 -0
  218. package/dist/scoring/register.d.ts +81 -0
  219. package/dist/scoring/register.d.ts.map +1 -0
  220. package/dist/scoring/register.js +105 -0
  221. package/dist/scoring/register.js.map +1 -0
  222. package/dist/scoring/scoring-binding.d.ts +72 -0
  223. package/dist/scoring/scoring-binding.d.ts.map +1 -0
  224. package/dist/scoring/scoring-binding.js +76 -0
  225. package/dist/scoring/scoring-binding.js.map +1 -0
  226. package/dist/scoring/scoring-process-shared.d.ts +105 -0
  227. package/dist/scoring/scoring-process-shared.d.ts.map +1 -0
  228. package/dist/scoring/scoring-process-shared.js +141 -0
  229. package/dist/scoring/scoring-process-shared.js.map +1 -0
  230. package/dist/scoring/scoring-process.d.ts +128 -0
  231. package/dist/scoring/scoring-process.d.ts.map +1 -0
  232. package/dist/scoring/scoring-process.js +146 -0
  233. package/dist/scoring/scoring-process.js.map +1 -0
  234. package/dist/scoring/seams.d.ts +40 -0
  235. package/dist/scoring/seams.d.ts.map +1 -0
  236. package/dist/scoring/seams.js +66 -0
  237. package/dist/scoring/seams.js.map +1 -0
  238. package/dist/scoring/startup-register.d.ts +49 -0
  239. package/dist/scoring/startup-register.d.ts.map +1 -0
  240. package/dist/scoring/startup-register.js +72 -0
  241. package/dist/scoring/startup-register.js.map +1 -0
  242. package/dist/scoring/types.d.ts +134 -0
  243. package/dist/scoring/types.d.ts.map +1 -0
  244. package/dist/scoring/types.js +26 -0
  245. package/dist/scoring/types.js.map +1 -0
  246. package/dist/training/artifact-store.d.ts +124 -0
  247. package/dist/training/artifact-store.d.ts.map +1 -0
  248. package/dist/training/artifact-store.js +163 -0
  249. package/dist/training/artifact-store.js.map +1 -0
  250. package/dist/training/index.d.ts +13 -0
  251. package/dist/training/index.d.ts.map +1 -0
  252. package/dist/training/index.js +13 -0
  253. package/dist/training/index.js.map +1 -0
  254. package/dist/training/seams.d.ts +57 -0
  255. package/dist/training/seams.d.ts.map +1 -0
  256. package/dist/training/seams.js +103 -0
  257. package/dist/training/seams.js.map +1 -0
  258. package/dist/training/training-engine.d.ts +96 -0
  259. package/dist/training/training-engine.d.ts.map +1 -0
  260. package/dist/training/training-engine.js +300 -0
  261. package/dist/training/training-engine.js.map +1 -0
  262. package/dist/training/types.d.ts +159 -0
  263. package/dist/training/types.d.ts.map +1 -0
  264. package/dist/training/types.js +16 -0
  265. package/dist/training/types.js.map +1 -0
  266. package/package.json +44 -7
@@ -0,0 +1,77 @@
1
+ /**
2
+ * @module actions/promote-model.gate
3
+ *
4
+ * Production implementation of the {@link IModelPromotionGate} seam used by the
5
+ * {@link PredictiveStudioPromoteModelAction}. It is the only place in the Promote
6
+ * action path that touches MJ's live data: it loads the immutable `MJ: ML Models`
7
+ * row, determines whether the model was **leakage-flagged**, enforces the
8
+ * sign-off gate, and saves ONLY the lifecycle `Status` (never metrics, artifact,
9
+ * or any training payload — the model is immutable, §6.4).
10
+ *
11
+ * ## Leakage detection (no dedicated column)
12
+ * A model has no `LeakageFlagged` column; the leakage signal is derived. The gate
13
+ * re-runs the SAME single-feature-dominance check the {@link TrainingEngine} uses
14
+ * (§6.4) over the model's frozen `FeatureImportance`, against the dominance
15
+ * threshold from the producing pipeline's `LeakageGuard` (falling back to the
16
+ * standard 0.6). This is deterministic and needs no extra state on the model.
17
+ */
18
+ import { type UserInfo, type IMetadataProvider } from '@memberjunction/core';
19
+ import type { MJMLModelEntity } from '@memberjunction/core-entities';
20
+ import type { IModelPromotionGate, PromoteModelRequest, PromoteModelOutcome } from './promote-model.action.js';
21
+ /**
22
+ * Loads a model, enforces the leakage sign-off gate, and transitions its status.
23
+ */
24
+ export declare class ProductionModelPromotionGate implements IModelPromotionGate {
25
+ /** @inheritdoc */
26
+ promote(request: PromoteModelRequest): Promise<PromoteModelOutcome>;
27
+ /**
28
+ * Persist an auditable sign-off note for a leakage override. The model is
29
+ * immutable (no free-text column to write), so the override is recorded via the
30
+ * platform log (an operator-visible audit line) and returned in the outcome so
31
+ * the calling Action surfaces it. The note captures who/when/what-was-overridden
32
+ * and the supplied reason.
33
+ */
34
+ protected recordSignOff(model: MJMLModelEntity, request: PromoteModelRequest, leakage: {
35
+ topFeature?: string;
36
+ topShare?: number;
37
+ }, reason: string): string;
38
+ /** Load the model as an `entity_object` (it is mutated to set Status). */
39
+ protected loadModel(modelId: string, contextUser?: UserInfo, provider?: IMetadataProvider): Promise<MJMLModelEntity | null>;
40
+ /**
41
+ * Determine whether the model was leakage-flagged by re-running the
42
+ * single-feature-dominance check over its frozen `FeatureImportance` against the
43
+ * producing pipeline's threshold.
44
+ */
45
+ protected detectLeakage(model: MJMLModelEntity, contextUser?: UserInfo, provider?: IMetadataProvider): Promise<{
46
+ flagged: boolean;
47
+ topFeature?: string;
48
+ topShare?: number;
49
+ }>;
50
+ /** Resolve the dominance threshold from the producing pipeline's `LeakageGuard`. */
51
+ protected resolveThreshold(pipelineId: string | null | undefined, contextUser?: UserInfo, provider?: IMetadataProvider): Promise<number>;
52
+ /**
53
+ * Allowed lifecycle transitions keyed on the model's CURRENT status. The
54
+ * lifecycle is `Draft → Validated → Published → Archived`, with the
55
+ * conservative reversible edges `Validated → Archived` (abandon a candidate)
56
+ * and `Archived ↔ Published` (un-archive / re-archive). Anything not listed
57
+ * (e.g. `Draft → Published`) is rejected as an invalid jump.
58
+ */
59
+ protected static readonly ALLOWED_TRANSITIONS: Readonly<Record<string, readonly PromoteModelRequest['targetStatus'][]>>;
60
+ /**
61
+ * Set ONLY the lifecycle status and save; never touches metrics/artifact.
62
+ * Enforces the {@link ALLOWED_TRANSITIONS} state machine first — an illegal
63
+ * jump (e.g. Draft → Published) is refused before any mutation/save.
64
+ */
65
+ protected transition(model: MJMLModelEntity, targetStatus: PromoteModelRequest['targetStatus'], signOffNote?: string, contextUser?: UserInfo, provider?: IMetadataProvider): Promise<PromoteModelOutcome>;
66
+ /**
67
+ * Keep the per-model scoring Action (PS2-2) in step with the model's new
68
+ * lifecycle status — generate/refresh it on `Published` (the status that makes a
69
+ * model usable for scoring) and disable it on `Archived`. This is a pure
70
+ * enhancement, NOT part of the promotion contract: any failure is logged and
71
+ * swallowed so it can never fail an otherwise-successful promotion.
72
+ */
73
+ protected syncScoringAction(model: MJMLModelEntity, targetStatus: PromoteModelRequest['targetStatus'], contextUser?: UserInfo, provider?: IMetadataProvider): Promise<void>;
74
+ /** Parse a possibly-null JSON column, falling back to a default on null/parse error. */
75
+ private parseJson;
76
+ }
77
+ //# sourceMappingURL=promote-model.gate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"promote-model.gate.d.ts","sourceRoot":"","sources":["../../src/actions/promote-model.gate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAgC,KAAK,QAAQ,EAAE,KAAK,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAC3G,OAAO,KAAK,EAAE,eAAe,EAA8B,MAAM,+BAA+B,CAAC;AAKjG,OAAO,KAAK,EACV,mBAAmB,EACnB,mBAAmB,EACnB,mBAAmB,EACpB,MAAM,wBAAwB,CAAC;AAahC;;GAEG;AACH,qBAAa,4BAA6B,YAAW,mBAAmB;IACtE,kBAAkB;IACL,OAAO,CAAC,OAAO,EAAE,mBAAmB,GAAG,OAAO,CAAC,mBAAmB,CAAC;IAyBhF;;;;;;OAMG;IACH,SAAS,CAAC,aAAa,CACrB,KAAK,EAAE,eAAe,EACtB,OAAO,EAAE,mBAAmB,EAC5B,OAAO,EAAE;QAAE,UAAU,CAAC,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;KAAE,EACnD,MAAM,EAAE,MAAM,GACb,MAAM;IAcT,0EAA0E;cAC1D,SAAS,CACvB,OAAO,EAAE,MAAM,EACf,WAAW,CAAC,EAAE,QAAQ,E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ionGate} seam used by the
5
+ * {@link PredictiveStudioPromoteModelAction}. It is the only place in the Promote
6
+ * action path that touches MJ's live data: it loads the immutable `MJ: ML Models`
7
+ * row, determines whether the model was **leakage-flagged**, enforces the
8
+ * sign-off gate, and saves ONLY the lifecycle `Status` (never metrics, artifact,
9
+ * or any training payload — the model is immutable, §6.4).
10
+ *
11
+ * ## Leakage detection (no dedicated column)
12
+ * A model has no `LeakageFlagged` column; the leakage signal is derived. The gate
13
+ * re-runs the SAME single-feature-dominance check the {@link TrainingEngine} uses
14
+ * (§6.4) over the model's frozen `FeatureImportance`, against the dominance
15
+ * threshold from the producing pipeline's `LeakageGuard` (falling back to the
16
+ * standard 0.6). This is deterministic and needs no extra state on the model.
17
+ */
18
+ import { RunView, LogError, LogStatus } from '@memberjunction/core';
19
+ import { detectSingleFeatureDominance } from '../feature-assembly/leakage-guard.js';
20
+ import { ModelScoringActionGenerator } from './model-scoring-action-generator.js';
21
+ /** Default single-feature-dominance threshold when a pipeline doesn't specify one. */
22
+ const DEFAULT_DOMINANCE_THRESHOLD = 0.6;
23
+ /** Canonical UUID shape (8-4-4-4-12 hex), case-insensitive. */
24
+ const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
25
+ /** Whether a string is a well-formed UUID (the only legal `MJ: ML Models` / pipeline id shape). */
26
+ function isUuid(value) {
27
+ return typeof value === 'string' && UUID_RE.test(value.trim());
28
+ }
29
+ /**
30
+ * Loads a model, enforces the leakage sign-off gate, and transitions its status.
31
+ */
32
+ export class ProductionModelPromotionGate {
33
+ /** @inheritdoc */
34
+ async promote(request) {
35
+ const model = await this.loadModel(request.modelId, request.contextUser, request.provider);
36
+ if (!model) {
37
+ return { kind: 'not-found' };
38
+ }
39
+ // Always evaluate leakage so a sign-off override of a FLAGGED model can be
40
+ // audited. A clean (non-flagged) model needs neither a sign-off nor a reason.
41
+ const leakage = await this.detectLeakage(model, request.contextUser, request.provider);
42
+ let signOffNote;
43
+ if (leakage.flagged) {
44
+ if (!request.signOff) {
45
+ return { kind: 'refused-leakage', topFeature: leakage.topFeature, topShare: leakage.topShare };
46
+ }
47
+ // Sign-off overriding a FLAGGED model REQUIRES a non-empty justification.
48
+ const reason = request.reason?.trim();
49
+ if (!reason) {
50
+ return { kind: 'signoff-reason-required', topFeature: leakage.topFeature, topShare: leakage.topShare };
51
+ }
52
+ signOffNote = this.recordSignOff(model, request, leakage, reason);
53
+ }
54
+ return this.transition(model, request.targetStatus, signOffNote, request.contextUser, request.provider);
55
+ }
56
+ /**
57
+ * Persist an auditable sign-off note for a leakage override. The model is
58
+ * immutable (no free-text column to write), so the override is recorded via the
59
+ * platform log (an operator-visible audit line) and returned in the outcome so
60
+ * the calling Action surfaces it. The note captures who/when/what-was-overridden
61
+ * and the supplied reason.
62
+ */
63
+ recordSignOff(model, request, leakage, reason) {
64
+ const who = request.contextUser?.Email ?? request.contextUser?.Name ?? 'unknown user';
65
+ const when = new Date().toISOString();
66
+ const share = leakage.topShare != null ? ` (${(leakage.topShare * 100).toFixed(0)}% share)` : '';
67
+ const feature = leakage.topFeature ? ` on feature "${leakage.topFeature}"${share}` : '';
68
+ const note = `Leakage sign-off override for ML Model '${model.ID}' by ${who} at ${when}: ` +
69
+ `leakage flag${feature} overridden to ${request.targetStatus}. Reason: ${reason}`;
70
+ LogStatus(note);
71
+ return note;
72
+ }
73
+ // ----- model load ----------------------------------------------------------
74
+ /** Load the model as an `entity_object` (it is mutated to set Status). */
75
+ async loadModel(modelId, contextUser, provider) {
76
+ // The model id is interpolated into a SQL filter — it MUST be a UUID. A
77
+ // non-UUID can't match a real row and is refused rather than concatenated.
78
+ if (!isUuid(modelId)) {
79
+ return null;
80
+ }
81
+ const rv = provider ? RunView.FromMetadataProvider(provider) : new RunView();
82
+ const result = await rv.RunView({
83
+ EntityName: 'MJ: ML Models',
84
+ ExtraFilter: `ID='${modelId}'`,
85
+ ResultType: 'entity_object',
86
+ MaxRows: 1,
87
+ }, contextUser);
88
+ if (!result.Success || result.Results.length === 0) {
89
+ return null;
90
+ }
91
+ return result.Results[0];
92
+ }
93
+ // ----- leakage detection ---------------------------------------------------
94
+ /**
95
+ * Determine whether the model was leakage-flagged by re-running the
96
+ * single-feature-dominance check over its frozen `FeatureImportance` against the
97
+ * producing pipeline's threshold.
98
+ */
99
+ async detectLeakage(model, contextUser, provider) {
100
+ const importance = this.parseJson(model.FeatureImportance, {});
101
+ const threshold = await this.resolveThreshold(model.PipelineID, contextUser, provider);
102
+ const dominance = detectSingleFeatureDominance(importance, threshold);
103
+ return { flagged: dominance.Dominant, topFeature: dominance.TopFeature, topShare: dominance.TopShare };
104
+ }
105
+ /** Resolve the dominance threshold from the producing pipeline's `LeakageGuard`. */
106
+ async resolveThreshold(pipelineId, contextUser, provider) {
107
+ // pipelineId is interpolated into a SQL filter — only a UUID is valid. A
108
+ // missing/malformed id falls back to the default threshold (never concatenated).
109
+ if (!isUuid(pipelineId)) {
110
+ return DEFAULT_DOMINANCE_THRESHOLD;
111
+ }
112
+ const rv = provider ? RunView.FromMetadataProvider(provider) : new RunView();
113
+ const result = await rv.RunView({
114
+ EntityName: 'MJ: ML Training Pipelines',
115
+ ExtraFilter: `ID='${pipelineId}'`,
116
+ Fields: ['LeakageGuard'],
117
+ ResultType: 'simple',
118
+ MaxRows: 1,
119
+ }, contextUser);
120
+ if (!result.Success || result.Results.length === 0) {
121
+ return DEFAULT_DOMINANCE_THRESHOLD;
122
+ }
123
+ const guard = this.parseJson(result.Results[0].LeakageGuard, {
124
+ DenyFields: [],
125
+ SingleFeatureDominanceThreshold: DEFAULT_DOMINANCE_THRESHOLD,
126
+ });
127
+ const threshold = guard.SingleFeatureDominanceThreshold;
128
+ return Number.isFinite(threshold) ? threshold : DEFAULT_DOMINANCE_THRESHOLD;
129
+ }
130
+ // ----- transition ----------------------------------------------------------
131
+ /**
132
+ * Allowed lifecycle transitions keyed on the model's CURRENT status. The
133
+ * lifecycle is `Draft → Validated → Published → Archived`, with the
134
+ * conservative reversible edges `Validated → Archived` (abandon a candidate)
135
+ * and `Archived ↔ Published` (un-archive / re-archive). Anything not listed
136
+ * (e.g. `Draft → Published`) is rejected as an invalid jump.
137
+ */
138
+ static { this.ALLOWED_TRANSITIONS = {
139
+ Draft: ['Validated'],
140
+ Validated: ['Published', 'Archived'],
141
+ Published: ['Archived'],
142
+ Archived: ['Published'],
143
+ }; }
144
+ /**
145
+ * Set ONLY the lifecycle status and save; never touches metrics/artifact.
146
+ * Enforces the {@link ALLOWED_TRANSITIONS} state machine first — an illegal
147
+ * jump (e.g. Draft → Published) is refused before any mutation/save.
148
+ */
149
+ async transition(model, targetStatus, signOffNote, contextUser, provider) {
150
+ const currentStatus = model.Status ?? 'Draft';
151
+ const allowed = ProductionModelPromotionGate.ALLOWED_TRANSITIONS[currentStatus] ?? [];
152
+ if (!allowed.includes(targetStatus)) {
153
+ return { kind: 'invalid-transition', currentStatus, targetStatus };
154
+ }
155
+ model.Status = targetStatus;
156
+ const saved = await model.Save();
157
+ if (!saved) {
158
+ return { kind: 'save-failed', message: model.LatestResult?.CompleteMessage ?? 'unknown error' };
159
+ }
160
+ await this.syncScoringAction(model, targetStatus, contextUser, provider);
161
+ return { kind: 'promoted', newStatus: targetStatus, signOffNote };
162
+ }
163
+ /**
164
+ * Keep the per-model scoring Action (PS2-2) in step with the model's new
165
+ * lifecycle status — generate/refresh it on `Published` (the status that makes a
166
+ * model usable for scoring) and disable it on `Archived`. This is a pure
167
+ * enhancement, NOT part of the promotion contract: any failure is logged and
168
+ * swallowed so it can never fail an otherwise-successful promotion.
169
+ */
170
+ async syncScoringAction(model, targetStatus, contextUser, provider) {
171
+ // The generator needs a contextUser + provider to read/write Action metadata.
172
+ // Without them (e.g. a bare in-process call) we simply skip — the live path
173
+ // always supplies both.
174
+ if (!contextUser || !provider) {
175
+ return;
176
+ }
177
+ try {
178
+ const generator = new ModelScoringActionGenerator();
179
+ if (targetStatus === 'Published') {
180
+ await generator.generateForModel(model, contextUser, provider);
181
+ }
182
+ else if (targetStatus === 'Archived') {
183
+ await generator.disableForModel(model, contextUser, provider);
184
+ }
185
+ }
186
+ catch (e) {
187
+ LogError(`ProductionModelPromotionGate: scoring-action sync for model '${model.ID}' (→ ${targetStatus}) failed ` +
188
+ `but the promotion succeeded: ${e instanceof Error ? e.message : String(e)}`);
189
+ }
190
+ }
191
+ // ----- helpers -------------------------------------------------------------
192
+ /** Parse a possibly-null JSON column, falling back to a default on null/parse error. */
193
+ parseJson(raw, fallback) {
194
+ if (raw == null || raw.trim().length === 0) {
195
+ return fallback;
196
+ }
197
+ try {
198
+ return JSON.parse(raw);
199
+ }
200
+ catch {
201
+ return fallback;
202
+ }
203
+ }
204
+ }
205
+ //# sourceMappingURL=promote-model.gate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"promote-model.gate.js","sourceRoot":"","sources":["../../src/actions/promote-model.gate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAyC,MAAM,sBAAsB,CAAC;AAI3G,OAAO,EAAE,4BAA4B,EAAE,MAAM,mCAAmC,CAAC;AACjF,OAAO,EAAE,2BAA2B,EAAE,MAAM,kCAAkC,CAAC;AAO/E,sFAAsF;AACtF,MAAM,2BAA2B,GAAG,GAAG,CAAC;AAExC,+DAA+D;AAC/D,MAAM,OAAO,GAAG,iEAAiE,CAAC;AAElF,mGAAmG;AACnG,SAAS,MAAM,CAAC,KAAgC;IAC9C,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC;AACjE,CAAC;AAED;;GAEG;AACH,MAAM,OAAO,4BAA4B;IACvC,kBAAkB;IACX,KAAK,CAAC,OAAO,CAAC,OAA4B;QAC/C,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC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AAI,IAAI,GAAG,CAAC,IAAI,EAAE,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC3C,OAAO,QAAQ,CAAC;QAClB,CAAC;QACD,IAAI,CAAC;YACH,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAM,CAAC;QAC9B,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,QAAQ,CAAC;QAClB,CAAC;IACH,CAAC"}
@@ -0,0 +1,60 @@
1
+ /**
2
+ * @module actions/run-experiment.action
3
+ *
4
+ * **Run Experiment Session** action — the thin Action boundary over
5
+ * {@link ExperimentOrchestrator} (plan §8.3 / §9.1 / §12). It lets an agent /
6
+ * workflow / UI execute an approved modeling plan to completion (or until the
7
+ * budget bound) and read back the session id, the best model id, and the
8
+ * leaderboard.
9
+ *
10
+ * Per CLAUDE.md "Actions are boundaries": this action does NOT do any experiment
11
+ * orchestration. It validates that an **approved** `PlanSpec` is supplied (and an
12
+ * optional `ExperimentID` to attach the session to an existing durable
13
+ * experiment), parses the optional `Budget`, builds the orchestrator's production
14
+ * deps (entity factory + clock + trainer), delegates to
15
+ * `ExperimentOrchestrator.runSession`, then maps the result onto output params.
16
+ *
17
+ * The orchestrator + deps are created behind overridable factory seams so unit
18
+ * tests substitute mocks with no live DB and no sidecar.
19
+ */
20
+ import type { ActionResultSimple, RunActionParams } from '@memberjunction/actions-base';
21
+ import type { Budget } from '@memberjunction/predictive-studio-core';
22
+ import { ExperimentOrchestrator } from '../experiment/experiment-orchestrator.js';
23
+ import type { ExperimentDeps, ExperimentRunOptions, ExperimentSessionResult } from '../experiment/types.js';
24
+ import { BasePredictiveStudioAction } from './base-predictive-studio.action.js';
25
+ /** The driver-class key this action registers under (matches the metadata row). */
26
+ export declare const RUN_EXPERIMENT_DRIVER_CLASS = "PredictiveStudioRunExperimentAction";
27
+ /**
28
+ * Runs an approved modeling plan as an experiment session. Outputs: `SessionID`
29
+ * (string), `BestModelID` (string | null), `Leaderboard` (JSON string),
30
+ * `StopReason` (string).
31
+ */
32
+ export declare class PredictiveStudioRunExperimentAction extends BasePredictiveStudioAction {
33
+ /** @inheritdoc */
34
+ protected InternalRunAction(params: RunActionParams): Promise<ActionResultSimple>;
35
+ /** Map the orchestrator result onto output params + a human-readable message. */
36
+ protected mapResult(params: RunActionParams, result: ExperimentSessionResult): ActionResultSimple;
37
+ /**
38
+ * Parse + VALIDATE the optional `Budget` JSON param into a {@link Budget}.
39
+ * Returns `undefined` when absent OR malformed (a malformed budget is not a hard
40
+ * failure — the plan's `ProposedBudget` is used as the fallback downstream), but
41
+ * never a blind cast of an arbitrary object.
42
+ */
43
+ protected parseBudget(params: RunActionParams): Budget | undefined;
44
+ /**
45
+ * Build the orchestrator run options from the action's params — an optional
46
+ * pre-resolved `ExperimentID` to attach the session to, and an optional `Budget`
47
+ * override (otherwise the plan's `ProposedBudget` is used).
48
+ */
49
+ protected buildOptions(params: RunActionParams): ExperimentRunOptions;
50
+ /** Construct the {@link ExperimentOrchestrator}. Overridable so tests inject a mock. */
51
+ protected createOrchestrator(): ExperimentOrchestrator;
52
+ /**
53
+ * Build the orchestrator's production dependency bundle from the action's run
54
+ * params. Async because the wiring resolves the active File Storage Provider to
55
+ * pick the artifact-store family. Overridable so tests inject in-memory seams
56
+ * (entity factory, fake clock, fake trainer).
57
+ */
58
+ protected buildDeps(params: RunActionParams): Promise<ExperimentDeps>;
59
+ }
60
+ //# sourceMappingURL=run-experiment.action.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run-experiment.action.d.ts","sourceRoot":"","sources":["../../src/actions/run-experiment.action.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,KAAK,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAIxF,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,wCAAwC,CAAC;AAGrE,OAAO,EAAE,sBAAsB,EAAE,MAAM,uCAAuC,CAAC;AAC/E,OAAO,KAAK,EAAE,cAAc,EAAE,oBAAoB,EAAE,uBAAuB,EAAE,MAAM,qBAAqB,CAAC;AACzG,OAAO,EAAE,0BAA0B,EAAE,MAAM,iCAAiC,CAAC;AAG7E,mFAAmF;AACnF,eAAO,MAAM,2BAA2B,wCAAwC,CAAC;AAEjF;;;;GAIG;AACH,qBACa,mCAAoC,SAAQ,0BAA0B;IACjF,kBAAkB;cACF,iBAAiB,CAAC,MAAM,EAAE,eAAe,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAwCvF,iFAAiF;IACjF,SAAS,CAAC,SAAS,CAAC,MAAM,EAAE,eAAe,EAAE,MAAM,EAAE,uBAAuB,GAAG,kBAAkB;IAejG;;;;;OAKG;IACH,SAAS,CAAC,WAAW,CAAC,MAAM,EAAE,eAAe,GAAG,MAAM,GAAG,SAAS;IASlE;;;;OAIG;IACH,SAAS,CAAC,YAAY,CAAC,MAAM,EAAE,eAAe,GAAG,oBAAoB;IAerE,wFAAwF;IACxF,SAAS,CAAC,kBAAkB,IAAI,sBAAsB;IAItD;;;;;OAKG;IACH,SAAS,CAAC,SAAS,CAAC,MAAM,EAAE,eAAe,GAAG,OAAO,CAAC,cAAc,CAAC;CAGtE"}
@@ -0,0 +1,134 @@
1
+ /**
2
+ * @module actions/run-experiment.action
3
+ *
4
+ * **Run Experiment Session** action — the thin Action boundary over
5
+ * {@link ExperimentOrchestrator} (plan §8.3 / §9.1 / §12). It lets an agent /
6
+ * workflow / UI execute an approved modeling plan to completion (or until the
7
+ * budget bound) and read back the session id, the best model id, and the
8
+ * leaderboard.
9
+ *
10
+ * Per CLAUDE.md "Actions are boundaries": this action does NOT do any experiment
11
+ * orchestration. It validates that an **approved** `PlanSpec` is supplied (and an
12
+ * optional `ExperimentID` to attach the session to an existing durable
13
+ * experiment), parses the optional `Budget`, builds the orchestrator's production
14
+ * deps (entity factory + clock + trainer), delegates to
15
+ * `ExperimentOrchestrator.runSession`, then maps the result onto output params.
16
+ *
17
+ * The orchestrator + deps are created behind overridable factory seams so unit
18
+ * tests substitute mocks with no live DB and no sidecar.
19
+ */
20
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
21
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
22
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
23
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
24
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
25
+ };
26
+ import { RegisterClass } from '@memberjunction/global';
27
+ import { LogError } from '@memberjunction/core';
28
+ import { BaseAction } from '@memberjunction/actions';
29
+ import { validateModelingPlanSpec, validateBudget } from '@memberjunction/predictive-studio-core';
30
+ import { ExperimentOrchestrator } from '../experiment/experiment-orchestrator.js';
31
+ import { BasePredictiveStudioAction } from './base-predictive-studio.action.js';
32
+ import { buildProductionExperimentDeps } from './run-experiment.deps.js';
33
+ /** The driver-class key this action registers under (matches the metadata row). */
34
+ export const RUN_EXPERIMENT_DRIVER_CLASS = 'PredictiveStudioRunExperimentAction';
35
+ /**
36
+ * Runs an approved modeling plan as an experiment session. Outputs: `SessionID`
37
+ * (string), `BestModelID` (string | null), `Leaderboard` (JSON string),
38
+ * `StopReason` (string).
39
+ */
40
+ let PredictiveStudioRunExperimentAction = class PredictiveStudioRunExperimentAction extends BasePredictiveStudioAction {
41
+ /** @inheritdoc */
42
+ async InternalRunAction(params) {
43
+ try {
44
+ const rawPlan = this.getJsonObjectParam(params, 'PlanSpec');
45
+ if (!rawPlan) {
46
+ return this.fail('VALIDATION_ERROR', 'PlanSpec parameter is required and must be a JSON modeling plan (the approved plan to execute)');
47
+ }
48
+ // Validate the untrusted JSON against the Core schema BEFORE delegating —
49
+ // no blind double-cast of an arbitrary object into a ModelingPlanSpec.
50
+ // NB: the server tsconfig runs with strictNullChecks OFF, under which a
51
+ // discriminated-union return type does NOT narrow on `validation.ok`. We
52
+ // therefore read the failure detail off the concrete failure shape rather
53
+ // than relying on control-flow narrowing of the union member.
54
+ const validation = validateModelingPlanSpec(rawPlan);
55
+ if (!validation.ok) {
56
+ const error = validation.error ?? 'unknown validation error';
57
+ return this.fail('VALIDATION_ERROR', `PlanSpec is not a valid modeling plan: ${error}`);
58
+ }
59
+ const plan = validation.value;
60
+ if (plan.Approved !== true) {
61
+ return this.fail('PLAN_NOT_APPROVED', 'The PlanSpec is not approved. Experiment execution is gated on user approval — set Approved=true on the plan before running.');
62
+ }
63
+ const options = this.buildOptions(params);
64
+ const orchestrator = this.createOrchestrator();
65
+ const deps = await this.buildDeps(params);
66
+ const result = await orchestrator.runSession(plan, deps, options);
67
+ return this.mapResult(params, result);
68
+ }
69
+ catch (e) {
70
+ LogError(e);
71
+ return this.fail('EXPERIMENT_FAILED', `Experiment session failed: ${e instanceof Error ? e.message : String(e)}`);
72
+ }
73
+ }
74
+ /** Map the orchestrator result onto output params + a human-readable message. */
75
+ mapResult(params, result) {
76
+ this.addOutputParam(params, 'SessionID', result.session.ID);
77
+ this.addOutputParam(params, 'BestModelID', result.bestModel?.ID ?? null);
78
+ this.addOutputParam(params, 'Leaderboard', JSON.stringify(result.leaderboard));
79
+ this.addOutputParam(params, 'StopReason', result.stopReason);
80
+ const best = result.bestModel ? `best model ${result.bestModel.ID}` : 'no winning model';
81
+ return this.ok(params, `Experiment session ${result.session.ID} finished (${result.stopReason}) with ${best} across ${result.iterations.length} iteration(s).`);
82
+ }
83
+ // ----- param parsing -------------------------------------------------------
84
+ /**
85
+ * Parse + VALIDATE the optional `Budget` JSON param into a {@link Budget}.
86
+ * Returns `undefined` when absent OR malformed (a malformed budget is not a hard
87
+ * failure — the plan's `ProposedBudget` is used as the fallback downstream), but
88
+ * never a blind cast of an arbitrary object.
89
+ */
90
+ parseBudget(params) {
91
+ const raw = this.getJsonObjectParam(params, 'Budget');
92
+ if (!raw) {
93
+ return undefined;
94
+ }
95
+ const validation = validateBudget(raw);
96
+ return validation.ok ? validation.value : undefined;
97
+ }
98
+ /**
99
+ * Build the orchestrator run options from the action's params — an optional
100
+ * pre-resolved `ExperimentID` to attach the session to, and an optional `Budget`
101
+ * override (otherwise the plan's `ProposedBudget` is used).
102
+ */
103
+ buildOptions(params) {
104
+ const options = {};
105
+ const experimentId = this.getStringParam(params, 'ExperimentID');
106
+ if (experimentId) {
107
+ options.experimentID = experimentId;
108
+ }
109
+ const budget = this.parseBudget(params);
110
+ if (budget) {
111
+ options.budget = budget;
112
+ }
113
+ return options;
114
+ }
115
+ // ----- injectable orchestrator + deps seams (overridden in tests) ----------
116
+ /** Construct the {@link ExperimentOrchestrator}. Overridable so tests inject a mock. */
117
+ createOrchestrator() {
118
+ return new ExperimentOrchestrator();
119
+ }
120
+ /**
121
+ * Build the orchestrator's production dependency bundle from the action's run
122
+ * params. Async because the wiring resolves the active File Storage Provider to
123
+ * pick the artifact-store family. Overridable so tests inject in-memory seams
124
+ * (entity factory, fake clock, fake trainer).
125
+ */
126
+ buildDeps(params) {
127
+ return buildProductionExperimentDeps(params.ContextUser, params.Provider);
128
+ }
129
+ };
130
+ PredictiveStudioRunExperimentAction = __decorate([
131
+ RegisterClass(BaseAction, RUN_EXPERIMENT_DRIVER_CLASS)
132
+ ], PredictiveStudioRunExperimentAction);
133
+ export { PredictiveStudioRunExperimentAction };
134
+ //# sourceMappingURL=run-experiment.action.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run-experiment.action.js","sourceRoot":"","sources":["../../src/actions/run-experiment.action.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;;;;;;;AAGH,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAErD,OAAO,EAAE,wBAAwB,EAAE,cAAc,EAAE,MAAM,wC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 /**
2
+ * @module actions/run-experiment.deps
3
+ *
4
+ * Builds the production {@link ExperimentDeps} bundle for the
5
+ * {@link PredictiveStudioRunExperimentAction}. Kept out of the action so the
6
+ * action stays thin (validate → delegate → map) and so the wiring is
7
+ * independently readable.
8
+ *
9
+ * The orchestrator's per-iteration {@link IExperimentTrainer} bridges to the
10
+ * {@link TrainingEngine}, which trains by **pipeline id**. Mapping a plan's
11
+ * proposed experiment (algorithm × feature set × hyperparameters) to a concrete
12
+ * `MJ: ML Training Pipelines` id is an {@link IPipelineResolver} — a materialization
13
+ * strategy that belongs to the higher layer that owns pipeline definitions. The
14
+ * Engine package therefore supplies a clear-failing default resolver; production
15
+ * callers inject a real one (and a real artifact loader) by constructing the deps
16
+ * themselves and passing them via the action's `buildDeps` override.
17
+ */
18
+ import type { UserInfo, IMetadataProvider } from '@memberjunction/core';
19
+ import { type IPipelineResolver } from '../experiment/seams.js';
20
+ import type { ExperimentDeps, TrainExperimentInput } from '../experiment/types.js';
21
+ /**
22
+ * A clear-failing default {@link IPipelineResolver}. The strategy for turning a
23
+ * proposed experiment into a `MJ: ML Training Pipelines` id (reuse vs. materialize)
24
+ * is owned by the higher layer; until one is wired, attempting to execute an
25
+ * experiment session in production surfaces an actionable error rather than
26
+ * silently training the wrong pipeline.
27
+ */
28
+ export declare class UnresolvedPipelineResolver implements IPipelineResolver {
29
+ resolvePipelineId(input: TrainExperimentInput): Promise<string>;
30
+ }
31
+ /**
32
+ * Build the production {@link ExperimentDeps} from the request user/provider. The
33
+ * training-side bundle (entity factory + record loader + sidecar + artifact store)
34
+ * is composed here and handed to the {@link TrainingEngineExperimentTrainer} so
35
+ * each iteration trains through the real {@link TrainingEngine}.
36
+ *
37
+ * The artifact store is built the same way the standalone training path builds it:
38
+ * resolve the active `MJ: File Storage Providers` id (see
39
+ * {@link resolveActiveFileStorageProviderId}) and stamp it on the store, which
40
+ * creates a real `MJ: Files` row and writes the bytes to local disk keyed by that
41
+ * id (dev / on-prem). Async so the provider lookup is part of the wiring.
42
+ *
43
+ * @param contextUser request user — threaded for isolation/audit
44
+ * @param provider optional provider for multi-provider correctness
45
+ */
46
+ export declare function buildProductionExperimentDeps(contextUser?: UserInfo, provider?: IMetadataProvider): Promise<ExperimentDeps>;
47
+ //# sourceMappingURL=run-experiment.deps.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run-experiment.deps.d.ts","sourceRoot":"","sources":["../../src/actions/run-experiment.deps.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAMxE,OAAO,EAIL,KAAK,iBAAiB,EACvB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK,EAAE,cAAc,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAEhF;;;;;;GAMG;AACH,qBAAa,0BAA2B,YAAW,iBAAiB;IACrD,iBAAiB,CAAC,KAAK,EAAE,oBAAoB,GAAG,OAAO,CAAC,MAAM,CAAC;CAO7E;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,6BAA6B,CACjD,WAAW,CAAC,EAAE,QAAQ,EACtB,QAAQ,CAAC,EAAE,iBAAiB,GAC3B,OAAO,CAAC,cAAc,CAAC,CAyBzB"}
@@ -0,0 +1,71 @@
1
+ /**
2
+ * @module actions/run-experiment.deps
3
+ *
4
+ * Builds the production {@link ExperimentDeps} bundle for the
5
+ * {@link PredictiveStudioRunExperimentAction}. Kept out of the action so the
6
+ * action stays thin (validate → delegate → map) and so the wiring is
7
+ * independently readable.
8
+ *
9
+ * The orchestrator's per-iteration {@link IExperimentTrainer} bridges to the
10
+ * {@link TrainingEngine}, which trains by **pipeline id**. Mapping a plan's
11
+ * proposed experiment (algorithm × feature set × hyperparameters) to a concrete
12
+ * `MJ: ML Training Pipelines` id is an {@link IPipelineResolver} — a materialization
13
+ * strategy that belongs to the higher layer that owns pipeline definitions. The
14
+ * Engine package therefore supplies a clear-failing default resolver; production
15
+ * callers inject a real one (and a real artifact loader) by constructing the deps
16
+ * themselves and passing them via the action's `buildDeps` override.
17
+ */
18
+ import { TrainingEngine } from '../training/training-engine.js';
19
+ import { MetadataEntityFactory, RunViewRecordLoader, MJSidecarTrainer } from '../training/seams.js';
20
+ import { resolveActiveFileStorageProviderId, buildArtifactStore } from '../training/artifact-store.js';
21
+ import { SystemClock, MetadataExperimentEntityFactory, TrainingEngineExperimentTrainer, } from '../experiment/seams.js';
22
+ /**
23
+ * A clear-failing default {@link IPipelineResolver}. The strategy for turning a
24
+ * proposed experiment into a `MJ: ML Training Pipelines` id (reuse vs. materialize)
25
+ * is owned by the higher layer; until one is wired, attempting to execute an
26
+ * experiment session in production surfaces an actionable error rather than
27
+ * silently training the wrong pipeline.
28
+ */
29
+ export class UnresolvedPipelineResolver {
30
+ async resolvePipelineId(input) {
31
+ throw new Error(`Run Experiment Session: no pipeline resolver is configured for experiment '${input.experiment.Label}'. ` +
32
+ 'Supply a production IPipelineResolver (the experiment → pipeline materialization strategy) by constructing ' +
33
+ 'ExperimentDeps in the higher layer and passing them via the action.');
34
+ }
35
+ }
36
+ /**
37
+ * Build the production {@link ExperimentDeps} from the request user/provider. The
38
+ * training-side bundle (entity factory + record loader + sidecar + artifact store)
39
+ * is composed here and handed to the {@link TrainingEngineExperimentTrainer} so
40
+ * each iteration trains through the real {@link TrainingEngine}.
41
+ *
42
+ * The artifact store is built the same way the standalone training path builds it:
43
+ * resolve the active `MJ: File Storage Providers` id (see
44
+ * {@link resolveActiveFileStorageProviderId}) and stamp it on the store, which
45
+ * creates a real `MJ: Files` row and writes the bytes to local disk keyed by that
46
+ * id (dev / on-prem). Async so the provider lookup is part of the wiring.
47
+ *
48
+ * @param contextUser request user — threaded for isolation/audit
49
+ * @param provider optional provider for multi-provider correctness
50
+ */
51
+ export async function buildProductionExperimentDeps(contextUser, provider) {
52
+ const entityFactory = new MetadataEntityFactory(provider);
53
+ const providerId = await resolveActiveFileStorageProviderId(contextUser, provider);
54
+ const trainingDeps = {
55
+ entityFactory,
56
+ recordLoader: new RunViewRecordLoader(),
57
+ sidecar: new MJSidecarTrainer(),
58
+ artifactStore: buildArtifactStore(providerId, entityFactory),
59
+ contextUser,
60
+ provider,
61
+ };
62
+ const trainer = new TrainingEngineExperimentTrainer(trainingDeps, new UnresolvedPipelineResolver(), new TrainingEngine());
63
+ return {
64
+ entityFactory: new MetadataExperimentEntityFactory(provider),
65
+ trainer,
66
+ clock: new SystemClock(),
67
+ contextUser,
68
+ provider,
69
+ };
70
+ }
71
+ //# sourceMappingURL=run-experiment.deps.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run-experiment.deps.js","sourceRoot":"","sources":["../../src/actions/run-experiment.deps.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAIH,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAC7D,OAAO,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AACjG,OAAO,EAAE,kCAAkC,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAEpG,OAAO,EACL,WAAW,EACX,+BAA+B,EAC/B,+BAA+B,GAEhC,MAAM,qBAAqB,CAAC;AAG7B;;;;;;GAMG;AACH,MAAM,OAAO,0BAA0B;IAC9B,KAAK,CAAC,iBAAiB,CAAC,KAA2B;QACxD,MAAM,IAAI,KAAK,CACb,8EAA8E,KAAK,CAAC,UAAU,CAAC,KAAK,KAAK;YACvG,6GAA6G;YAC7G,qEAAqE,CACxE,CAAC;IACJ,CAAC;CACF;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,KAAK,UAAU,6BAA6B,CACjD,WAAsB,EACtB,QAA4B;IAE5B,MAAM,aAAa,GAAG,IAAI,qBAAqB,CAAC,QAAQ,CAAC,CAAC;IAC1D,MAAM,UAAU,GAAG,MAAM,kCAAkC,CAAC,WAA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