@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 @@
1
+ {"version":3,"file":"as-of.d.ts","sourceRoot":"","sources":["../../src/feature-assembly/as-of.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wCAAwC,CAAC;AAC3E,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAE/C,mEAAmE;AACnE,MAAM,WAAW,QAAQ;IACvB,6BAA6B;IAC7B,IAAI,EAAE,IAAI,CAAC;IACX,8EAA8E;IAC9E,GAAG,EAAE,SAAS,CAAC;CAChB;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,eAAe,CAAC,QAAQ,EAAE,YAAY,EAAE,MAAM,EAAE,SAAS,EAAE,cAAc,CAAC,EAAE,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,CAgCpH;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,QAAQ,EAAE,EAAE,QAAQ,EAAE,IAAI,GAAG,IAAI,GAAG,QAAQ,EAAE,CAM9E;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,yBAAyB,CAAC,IAAI,EAAE,QAAQ,EAAE,EAAE,QAAQ,EAAE,IAAI,GAAG,IAAI,GAAG,MAAM,GAAG,IAAI,CAehG;AAED;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,QAAQ,EAAE,EAAE,QAAQ,EAAE,IAAI,GAAG,IAAI,GAAG,MAAM,CAEjF"}
@@ -0,0 +1,136 @@
1
+ /**
2
+ * @module feature-assembly/as-of
3
+ *
4
+ * Point-in-time ("as-of") assembly — the single biggest **new** correctness
5
+ * primitive in Predictive Studio (plan §6.3). For forward prediction, features
6
+ * must be assembled **as they were at the decision point**, not as they are
7
+ * today. A time-relative feature like `days_since_last_activity` computed over
8
+ * data that includes events *after* the decision date leaks the future and
9
+ * produces a model that scores beautifully in the lab and uselessly in
10
+ * production.
11
+ *
12
+ * This module resolves a per-record **as-of date** from the {@link AsOfStrategy}
13
+ * and provides helpers that filter dated source rows to those at-or-before that
14
+ * date, then compute recency/aggregate features only over the surviving rows.
15
+ */
16
+ /**
17
+ * Resolves the per-record as-of date from the configured {@link AsOfStrategy}.
18
+ *
19
+ * - `none` → `null` (no point-in-time filtering; features reflect "now").
20
+ * - `column` → the value of `Strategy.Column` on the record, parsed as a date.
21
+ * - `offset` → `labelEventDate − OffsetDays`. The label-event date is the
22
+ * per-record anchor (e.g. the renewal-window start); we assemble features as
23
+ * of N days *before* it so the model only ever sees pre-decision data.
24
+ *
25
+ * @param strategy the configured as-of strategy
26
+ * @param record the training/scoring unit record
27
+ * @param labelEventDate the record's label-event date (required for `offset`)
28
+ * @returns the resolved as-of cutoff, or `null` when no filtering applies
29
+ */
30
+ export function resolveAsOfDate(strategy, record, labelEventDate) {
31
+ switch (strategy.Mode) {
32
+ case 'none':
33
+ return null;
34
+ case 'column': {
35
+ if (!strategy.Column) {
36
+ throw new Error(`AsOfStrategy.Mode='column' requires a Column name.`);
37
+ }
38
+ const raw = record[strategy.Column];
39
+ const parsed = coerceDate(raw);
40
+ if (parsed === null) {
41
+ throw new Error(`AsOfStrategy column '${strategy.Column}' is missing or not a date on the record.`);
42
+ }
43
+ return parsed;
44
+ }
45
+ case 'offset': {
46
+ if (strategy.OffsetDays == null) {
47
+ throw new Error(`AsOfStrategy.Mode='offset' requires OffsetDays.`);
48
+ }
49
+ if (!labelEventDate) {
50
+ throw new Error(`AsOfStrategy.Mode='offset' requires a label-event date per record.`);
51
+ }
52
+ const asOf = new Date(labelEventDate.getTime());
53
+ asOf.setUTCDate(asOf.getUTCDate() - strategy.OffsetDays);
54
+ return asOf;
55
+ }
56
+ default: {
57
+ // Exhaustiveness guard — narrows to `never` if a new mode is added.
58
+ const exhaustive = strategy.Mode;
59
+ throw new Error(`Unsupported AsOfStrategy mode: ${String(exhaustive)}`);
60
+ }
61
+ }
62
+ }
63
+ /**
64
+ * Filters dated rows to those occurring at-or-before the as-of cutoff. A `null`
65
+ * cutoff (i.e. `Mode='none'`) is the identity filter — all rows survive.
66
+ *
67
+ * This is the leakage-prevention boundary: **only** rows passing this filter may
68
+ * feed any time-relative feature.
69
+ *
70
+ * @param rows the candidate dated rows for one record
71
+ * @param asOfDate the resolved cutoff, or `null` for no filtering
72
+ * @returns the rows at-or-before the cutoff
73
+ */
74
+ export function filterAsOf(rows, asOfDate) {
75
+ if (asOfDate === null) {
76
+ return rows;
77
+ }
78
+ const cutoff = asOfDate.getTime();
79
+ return rows.filter((r) => r.Date.getTime() <= cutoff);
80
+ }
81
+ /**
82
+ * Computes `days_since_last_activity` as of the cutoff: the whole-day gap
83
+ * between the cutoff date and the most recent surviving event. Returns `null`
84
+ * when there is no qualifying activity (the caller decides how to encode "no
85
+ * activity" — typically imputed downstream by the sidecar, §6.2).
86
+ *
87
+ * Computing recency relative to the **as-of date** (not "now") is what keeps
88
+ * train-time ("as-of-then") and score-time ("as-of-now") consistent.
89
+ *
90
+ * @param rows candidate dated rows (will be filtered to the cutoff internally)
91
+ * @param asOfDate the resolved cutoff; when `null`, recency is measured from "now"
92
+ */
93
+ export function daysSinceLastActivityAsOf(rows, asOfDate) {
94
+ const reference = asOfDate ?? new Date();
95
+ const surviving = filterAsOf(rows, asOfDate);
96
+ if (surviving.length === 0) {
97
+ return null;
98
+ }
99
+ let mostRecent = surviving[0].Date.getTime();
100
+ for (const r of surviving) {
101
+ const t = r.Date.getTime();
102
+ if (t > mostRecent) {
103
+ mostRecent = t;
104
+ }
105
+ }
106
+ const diffMs = reference.getTime() - mostRecent;
107
+ return Math.floor(diffMs / MS_PER_DAY);
108
+ }
109
+ /**
110
+ * Counts surviving activity rows as of the cutoff — a generic point-in-time
111
+ * aggregate (e.g. `activity_count_asof`). Only rows at-or-before the cutoff are
112
+ * counted, preventing future leakage.
113
+ *
114
+ * @param rows candidate dated rows
115
+ * @param asOfDate the resolved cutoff, or `null` for no filtering
116
+ */
117
+ export function activityCountAsOf(rows, asOfDate) {
118
+ return filterAsOf(rows, asOfDate).length;
119
+ }
120
+ /** Milliseconds in one day. */
121
+ const MS_PER_DAY = 24 * 60 * 60 * 1000;
122
+ /**
123
+ * Coerces a loosely-typed source value into a `Date`, or `null` when it cannot
124
+ * be interpreted as a valid date.
125
+ */
126
+ function coerceDate(value) {
127
+ if (value instanceof Date) {
128
+ return Number.isNaN(value.getTime()) ? null : value;
129
+ }
130
+ if (typeof value === 'string' || typeof value === 'number') {
131
+ const d = new Date(value);
132
+ return Number.isNaN(d.getTime()) ? null : d;
133
+ }
134
+ return null;
135
+ }
136
+ //# sourceMappingURL=as-of.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"as-of.js","sourceRoot":"","sources":["../../src/feature-assembly/as-of.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAaH;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,eAAe,CAAC,QAAsB,EAAE,MAAiB,EAAE,cAA4B;IACrG,QAAQ,QAAQ,CAAC,IAAI,EAAE,CAAC;QACtB,KAAK,MAAM;YACT,OAAO,IAAI,CAAC;QACd,KAAK,QAAQ,CAAC,CAAC,CAAC;YACd,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC;gBACrB,MAAM,IAAI,KAAK,CAAC,oDAAoD,CAAC,CAA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,CAAC,CAAC,KAAK,CAAC;IACtD,CAAC;IACD,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC3D,MAAM,CAAC,GAAG,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC;QAC1B,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;IAC9C,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC"}
@@ -0,0 +1,114 @@
1
+ /**
2
+ * @module feature-assembly/data-access
3
+ *
4
+ * The **data-access seam** for the FeatureAssembly executor. The executor reads
5
+ * source rows (entities, Queries, external entities) and persisted embedding
6
+ * vectors through this narrow, read-only interface rather than calling
7
+ * `RunView` directly. This keeps the executor:
8
+ *
9
+ * - **Testable without a live database** — unit tests inject an in-memory
10
+ * implementation backed by plain arrays (no DB, no GraphQL).
11
+ * - **Single-pathed** — the same executor code runs in all three contexts
12
+ * (train / materialize / on-demand), with only the data-access implementation
13
+ * differing between a real `RunView`-backed reader and a test fixture.
14
+ *
15
+ * The production implementation ({@link RunViewDataAccess}) wraps
16
+ * `@memberjunction/core`'s `RunView` and always passes the `contextUser` so the
17
+ * reads honor per-user data isolation on the server.
18
+ */
19
+ import { type UserInfo, type IMetadataProvider } from '@memberjunction/core';
20
+ /**
21
+ * A single fetched row — a plain map of column name → value. Deliberately loose
22
+ * because sources come from heterogeneous entities/queries; the executor selects
23
+ * and types the columns it needs downstream.
24
+ */
25
+ export type SourceRow = Record<string, string | number | boolean | null | undefined>;
26
+ /**
27
+ * Read parameters for fetching rows from a named source. A subset of MJ's
28
+ * `RunViewParams`, narrowed to what FeatureAssembly needs (read-only).
29
+ */
30
+ export interface FetchRowsParams {
31
+ /** Entity / external-entity name to read from. */
32
+ EntityName: string;
33
+ /** Optional SQL-ish filter expression (passed through to RunView's `ExtraFilter`). */
34
+ ExtraFilter?: string;
35
+ /** Optional ordering expression (passed through to RunView's `OrderBy`). */
36
+ OrderBy?: string;
37
+ /** Optional column projection — narrows the read for performance. */
38
+ Fields?: string[];
39
+ /** Optional cap on rows returned. */
40
+ MaxRows?: number;
41
+ }
42
+ /**
43
+ * Result of a {@link IFeatureDataAccess.fetchRows} call.
44
+ */
45
+ export interface FetchRowsResult {
46
+ /** Whether the read succeeded. */
47
+ Success: boolean;
48
+ /** The fetched rows (empty when `Success` is false). */
49
+ Rows: SourceRow[];
50
+ /** Error detail when `Success` is false. */
51
+ ErrorMessage?: string;
52
+ }
53
+ /**
54
+ * The read-only data-access contract the FeatureAssembly executor depends on.
55
+ *
56
+ * Implementations:
57
+ * - {@link RunViewDataAccess} — production, wraps `RunView` (DB-backed).
58
+ * - test fixtures — in-memory, back the unit tests with plain arrays.
59
+ */
60
+ export interface IFeatureDataAccess {
61
+ /**
62
+ * Fetch rows from a named source (entity / external entity / query-backed
63
+ * entity). Returns a {@link FetchRowsResult} — never throws for logical
64
+ * read failures (mirrors `RunView`'s non-throwing contract).
65
+ */
66
+ fetchRows(params: FetchRowsParams): Promise<FetchRowsResult>;
67
+ /**
68
+ * Fetch a persisted, version-pinned embedding vector for a single record of
69
+ * an entity (plan §5.2). Returns the dense numeric vector, or `null` when no
70
+ * persisted embedding exists for that record/model.
71
+ *
72
+ * The default implementation is a documented integration seam (see
73
+ * {@link RunViewDataAccess.fetchEmbedding}); tests supply vectors directly.
74
+ *
75
+ * @param entity entity whose persisted embedding is requested
76
+ * @param recordId primary-key value of the record
77
+ * @param embeddingModelRef pinned embedding-model id/name (part of model lineage)
78
+ * @param dims expected dimensionality
79
+ */
80
+ fetchEmbedding(entity: string, recordId: string, embeddingModelRef: string, dims: number): Promise<number[] | null>;
81
+ }
82
+ /**
83
+ * Production {@link IFeatureDataAccess} backed by `@memberjunction/core`'s
84
+ * `RunView`. Always passes `contextUser` so server-side reads honor per-user
85
+ * data isolation. Constructed with an optional `IMetadataProvider` for
86
+ * multi-provider correctness (CLAUDE.md) — the provider, when supplied, is the
87
+ * one the reads run against.
88
+ */
89
+ export declare class RunViewDataAccess implements IFeatureDataAccess {
90
+ private readonly runView;
91
+ private readonly contextUser?;
92
+ private readonly provider?;
93
+ /**
94
+ * @param contextUser the request's user — REQUIRED on the server for isolation/audit
95
+ * @param provider optional provider for multi-provider scenarios (defaults to global)
96
+ */
97
+ constructor(contextUser?: UserInfo, provider?: IMetadataProvider);
98
+ /** @inheritdoc */
99
+ fetchRows(params: FetchRowsParams): Promise<FetchRowsResult>;
100
+ /**
101
+ * @inheritdoc
102
+ *
103
+ * INTEGRATION SEAM (plan §5.2): wiring persisted embeddings is a later-phase
104
+ * task (PS-FEAT-1 pulls persisted vectors; the concrete read depends on the
105
+ * vector-store binding — pgvector / Qdrant / Pinecone / SQL Server via
106
+ * `EntityVectorSyncer`). Until that binding is wired, this returns `null`
107
+ * (no persisted embedding), which the executor handles by emitting zero-filled
108
+ * embedding columns. It MUST NOT regenerate embeddings inline — embeddings are
109
+ * persisted + version-pinned (anti-skew, §6.5). Tests inject vectors directly
110
+ * via an in-memory `IFeatureDataAccess`, so this stub never blocks them.
111
+ */
112
+ fetchEmbedding(_entity: string, _recordId: string, _embeddingModelRef: string, _dims: number): Promise<number[] | null>;
113
+ }
114
+ //# sourceMappingURL=data-access.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"data-access.d.ts","sourceRoot":"","sources":["../../src/feature-assembly/data-access.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAAW,KAAK,QAAQ,EAAE,KAAK,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAEtF;;;;GAIG;AACH,MAAM,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,GAAG,SAAS,CAAC,CAAC;AAErF;;;GAGG;AACH,MAAM,WAAW,eAAe;IAC9B,kDAAkD;IAClD,U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AK,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC;CAGrI"}
@@ -0,0 +1,68 @@
1
+ /**
2
+ * @module feature-assembly/data-access
3
+ *
4
+ * The **data-access seam** for the FeatureAssembly executor. The executor reads
5
+ * source rows (entities, Queries, external entities) and persisted embedding
6
+ * vectors through this narrow, read-only interface rather than calling
7
+ * `RunView` directly. This keeps the executor:
8
+ *
9
+ * - **Testable without a live database** — unit tests inject an in-memory
10
+ * implementation backed by plain arrays (no DB, no GraphQL).
11
+ * - **Single-pathed** — the same executor code runs in all three contexts
12
+ * (train / materialize / on-demand), with only the data-access implementation
13
+ * differing between a real `RunView`-backed reader and a test fixture.
14
+ *
15
+ * The production implementation ({@link RunViewDataAccess}) wraps
16
+ * `@memberjunction/core`'s `RunView` and always passes the `contextUser` so the
17
+ * reads honor per-user data isolation on the server.
18
+ */
19
+ import { RunView } from '@memberjunction/core';
20
+ /**
21
+ * Production {@link IFeatureDataAccess} backed by `@memberjunction/core`'s
22
+ * `RunView`. Always passes `contextUser` so server-side reads honor per-user
23
+ * data isolation. Constructed with an optional `IMetadataProvider` for
24
+ * multi-provider correctness (CLAUDE.md) — the provider, when supplied, is the
25
+ * one the reads run against.
26
+ */
27
+ export class RunViewDataAccess {
28
+ /**
29
+ * @param contextUser the request's user — REQUIRED on the server for isolation/audit
30
+ * @param provider optional provider for multi-provider scenarios (defaults to global)
31
+ */
32
+ constructor(contextUser, provider) {
33
+ this.contextUser = contextUser;
34
+ this.provider = provider;
35
+ this.runView = this.provider ? RunView.FromMetadataProvider(this.provider) : new RunView();
36
+ }
37
+ /** @inheritdoc */
38
+ async fetchRows(params) {
39
+ const result = await this.runView.RunView({
40
+ EntityName: params.EntityName,
41
+ ExtraFilter: params.ExtraFilter ?? '',
42
+ OrderBy: params.OrderBy ?? '',
43
+ Fields: params.Fields,
44
+ MaxRows: params.MaxRows,
45
+ ResultType: 'simple',
46
+ }, this.contextUser);
47
+ if (!result.Success) {
48
+ return { Success: false, Rows: [], ErrorMessage: result.ErrorMessage };
49
+ }
50
+ return { Success: true, Rows: result.Results ?? [] };
51
+ }
52
+ /**
53
+ * @inheritdoc
54
+ *
55
+ * INTEGRATION SEAM (plan §5.2): wiring persisted embeddings is a later-phase
56
+ * task (PS-FEAT-1 pulls persisted vectors; the concrete read depends on the
57
+ * vector-store binding — pgvector / Qdrant / Pinecone / SQL Server via
58
+ * `EntityVectorSyncer`). Until that binding is wired, this returns `null`
59
+ * (no persisted embedding), which the executor handles by emitting zero-filled
60
+ * embedding columns. It MUST NOT regenerate embeddings inline — embeddings are
61
+ * persisted + version-pinned (anti-skew, §6.5). Tests inject vectors directly
62
+ * via an in-memory `IFeatureDataAccess`, so this stub never blocks them.
63
+ */
64
+ async fetchEmbedding(_entity, _recordId, _embeddingModelRef, _dims) {
65
+ return null;
66
+ }
67
+ }
68
+ //# sourceMappingURL=data-access.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"data-access.js","sourceRoot":"","sources":["../../src/feature-assembly/data-access.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAAE,OAAO,EAAyC,MAAM,sBAAsB,CAAC;AAqEtF;;;;;;GAMG;AACH,MAAM,OAAO,iBAAiB;IAK5B;;;OAGG;IACH,YAAY,WAAsB,EAAE,QAA4B;QAC9D,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAC/B,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,oBAAoB,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,IAAI,OAAO,EAAE,CAAC;IAC7F,CAAC;IAED,kBAAkB;IACX,KAAK,CAAC,SAAS,CAAC,MAAuB;QAC5C,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,OAAO,CACvC;YACE,UAAU,EAAE,MAAM,CAAC,UAAU;YAC7B,WAAW,EAAE,MAAM,CAAC,WAAW,IAAI,EAAE;YACrC,OAAO,EAAE,MAAM,CAAC,OAAO,IAAI,EAAE;YAC7B,MAAM,EAAE,MAAM,CAAC,MAAM;YACrB,OAAO,EAAE,MAAM,CAAC,OAAO;YACvB,UAAU,EAAE,QAAQ;SACrB,EACD,IAAI,CAAC,WAAW,CACjB,CAAC;QAEF,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;YACpB,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE,EAAE,YAAY,EAAE,MAAM,CAAC,YAAY,EAAE,CAAC;QACzE,CAAC;QACD,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,CAAC,OAAO,IAAI,EAAE,EAAE,CAAC;IACvD,CAAC;IAED;;;;;;;;;;;OAWG;IACI,KAAK,CAAC,cAAc,CAAC,OAAe,EAAE,SAAiB,EAAE,kBAA0B,EAAE,KAAa;QACvG,OAAO,IAAI,CAAC;IACd,CAAC;CACF"}
@@ -0,0 +1,273 @@
1
+ /**
2
+ * @module feature-assembly/feature-assembly-executor
3
+ *
4
+ * The **FeatureAssembly executor** — Predictive Studio's correctness backbone
5
+ * (plan §6). It turns `(record set, frozen FeatureStep DAG) → feature matrix`,
6
+ * and is the **single code path used in all three contexts** — training,
7
+ * scheduled/materialized scoring, and on-demand/interactive scoring — so the
8
+ * features produced are identical and train/serve skew is impossible by
9
+ * construction (§6.1). The only difference between contexts is an
10
+ * {@link AssemblyContext} enum tag for telemetry; the assembly logic is the same.
11
+ *
12
+ * ## The raw-vs-preprocessing split (§6.2 — the anti-skew design)
13
+ *
14
+ * The TS executor assembles the **raw** feature matrix from MJ data and **emits
15
+ * the preprocessing recipe** for the Python sidecar to *fit then apply*. It does
16
+ * **not** fit impute/standardize/onehot/bin itself:
17
+ *
18
+ * - **Data-assembly step kinds** (`select`, `embedding`, `llm-derived`,
19
+ * `flow-agent`) → produce raw column values in the matrix.
20
+ * - **Preprocessing step kinds** (`impute`, `standardize`, `onehot`, `bin`) →
21
+ * translate into ordered {@link PreprocessingOp}[] returned for the sidecar;
22
+ * they do NOT transform values in TS.
23
+ *
24
+ * The sidecar fits these once on training data and replays the frozen params at
25
+ * scoring, guaranteeing identical preprocessing at train and at score.
26
+ *
27
+ * ## As-of and leakage
28
+ *
29
+ * Time-relative features are assembled as of each record's decision date
30
+ * (see `./as-of`), and deny-listed fields/sources are filtered out before any
31
+ * column is produced (see `./leakage-guard`).
32
+ */
33
+ import type { FeatureStepGraph, SourceBinding, AsOfStrategy, LeakageGuard, FeatureSchemaEntry, PreprocessingOp, MatrixData, FeatureKind } from '@memberjunction/predictive-studio-core';
34
+ import type { UserInfo, IMetadataProvider } from '@memberjunction/core';
35
+ import type { AIPromptParams } from '@memberjunction/ai-core-plus';
36
+ import type { VisionLLMFeatureStep } from '@memberjunction/predictive-studio-core';
37
+ import { type IFeatureDataAccess, type SourceRow } from './data-access.js';
38
+ import { type IVisionPromptRunner } from './vision-llm.js';
39
+ /**
40
+ * Resolves a {@link VisionLLMFeatureStep}'s `Prompt` (id/name/inline) into the
41
+ * prompt entity the injected runner executes. Supplied by the caller so the
42
+ * executor stays decoupled from `MJ: AI Prompts` loading; tests provide a stub.
43
+ *
44
+ * @param step the vision-llm step whose prompt to resolve
45
+ * @returns the prompt entity to run
46
+ */
47
+ export type VisionPromptResolver = (step: VisionLLMFeatureStep) => Promise<AIPromptParams['prompt']> | AIPromptParams['prompt'];
48
+ /**
49
+ * Which of the three contexts the executor is running in. The value is purely a
50
+ * telemetry/diagnostics tag — the assembly logic is identical in all three so
51
+ * that features never differ between train and score (§6.1).
52
+ */
53
+ export type AssemblyContext = 'train' | 'materialize' | 'on-demand';
54
+ /**
55
+ * A dated source supplying time-relative ("as-of") features for the target
56
+ * records. Each row carries the record it belongs to (via `ForeignKeyField`)
57
+ * and a date column used for point-in-time filtering.
58
+ */
59
+ export interface DatedSourceSpec {
60
+ /** Entity to read the dated rows from (e.g. an Activities entity). */
61
+ EntityName: string;
62
+ /** Column on the dated rows that references the target record's primary key. */
63
+ ForeignKeyField: string;
64
+ /** Date column on the dated rows used for as-of filtering. */
65
+ DateField: string;
66
+ /**
67
+ * Which as-of features to emit from this dated source. Each entry names the
68
+ * output column and the aggregate kind to compute as-of the decision date.
69
+ */
70
+ Features: DatedFeatureSpec[];
71
+ }
72
+ /** One as-of feature derived from a {@link DatedSourceSpec}. */
73
+ export interface DatedFeatureSpec {
74
+ /** Output column name in the matrix (e.g. `days_since_last_activity_asof`). */
75
+ OutputColumn: string;
76
+ /** The point-in-time aggregate to compute over the surviving (pre-decision) rows. */
77
+ Aggregate: 'days_since_last_activity' | 'activity_count';
78
+ }
79
+ /**
80
+ * Descriptor for the target record set. Either the records are passed inline
81
+ * (`records`) — used by on-demand scoring and tests — or a `source` descriptor
82
+ * tells the executor how to fetch them (used by train / materialize over a
83
+ * full population).
84
+ */
85
+ export interface RecordSetDescriptor {
86
+ /** Entity to read target records from. */
87
+ EntityName: string;
88
+ /** Optional filter narrowing the population. */
89
+ ExtraFilter?: string;
90
+ /** Optional ordering. */
91
+ OrderBy?: string;
92
+ /** Optional row cap. */
93
+ MaxRows?: number;
94
+ }
95
+ /**
96
+ * Parameters for a FeatureAssembly run.
97
+ */
98
+ export interface FeatureAssemblyParams {
99
+ /** Entity whose records are the training/scoring units (e.g. `Members`). */
100
+ targetEntityName: string;
101
+ /** Inline records to assemble (preferred for on-demand/tests). */
102
+ records?: SourceRow[];
103
+ /** OR a descriptor telling the executor how to fetch the target records. */
104
+ recordSet?: RecordSetDescriptor;
105
+ /** Ordered source bindings the pipeline draws features from (§4.2/§5.5). */
106
+ sources: SourceBinding[];
107
+ /** The frozen FeatureStep DAG (§5/§6). */
108
+ steps: FeatureStepGraph;
109
+ /** Point-in-time assembly strategy (§6.3). */
110
+ asOf: AsOfStrategy;
111
+ /** Leakage protection (§6.4). */
112
+ leakageGuard: LeakageGuard;
113
+ /** Dated sources supplying as-of features (optional). */
114
+ datedSources?: DatedSourceSpec[];
115
+ /** The label column to carry through (train context). Omitted at score time. */
116
+ targetVariable?: string;
117
+ /** Per-record label-event date (required for as-of `offset` mode). Keyed by record primary key. */
118
+ labelEventDates?: Record<string, Date>;
119
+ /** Primary-key field name on the target entity (defaults to `ID`). */
120
+ primaryKeyField?: string;
121
+ /** Telemetry tag (train / materialize / on-demand). Logic is identical regardless. */
122
+ context?: AssemblyContext;
123
+ /** Request user — REQUIRED on the server for isolation/audit. */
124
+ contextUser?: UserInfo;
125
+ /** Optional provider for multi-provider correctness. */
126
+ provider?: IMetadataProvider;
127
+ /**
128
+ * Optional data-access override — the seam that makes the executor unit-testable
129
+ * without a DB. When omitted, a {@link RunViewDataAccess} is used.
130
+ */
131
+ dataAccess?: IFeatureDataAccess;
132
+ /**
133
+ * Optional injected prompt-runner seam for `vision-llm` steps (plan §11). When
134
+ * a pipeline contains a `vision-llm` step, this is REQUIRED — unit tests mock
135
+ * it so the step assembles without a live model. When omitted, vision steps
136
+ * yield null feature values (no model call).
137
+ */
138
+ visionRunner?: IVisionPromptRunner;
139
+ /**
140
+ * Optional resolver turning a `vision-llm` step's `Prompt` reference into the
141
+ * prompt entity the runner executes. Required alongside {@link visionRunner}
142
+ * when vision steps are present.
143
+ */
144
+ visionPromptResolver?: VisionPromptResolver;
145
+ }
146
+ /**
147
+ * The output of a FeatureAssembly run.
148
+ */
149
+ export interface FeatureAssemblyResult {
150
+ /** The assembled RAW feature matrix (columns + row-major values). */
151
+ matrix: MatrixData;
152
+ /** Ordered feature schema (the inference input contract) — aligns with `matrix.columns`. */
153
+ featureSchema: FeatureSchemaEntry[];
154
+ /** Ordered preprocessing recipe for the sidecar to FIT + APPLY (NOT applied here). */
155
+ preprocessing: PreprocessingOp[];
156
+ /** ISO timestamp the assembly ran (diagnostics). */
157
+ assembledAsOf?: string;
158
+ }
159
+ /**
160
+ * The FeatureAssembly executor. Stateless per call; construct once and reuse.
161
+ */
162
+ export declare class FeatureAssemblyExecutor {
163
+ /**
164
+ * Assemble the raw feature matrix + schema + preprocessing recipe for the
165
+ * given record set and frozen step graph. This is the single code path for
166
+ * train / materialize / on-demand.
167
+ *
168
+ * @param params the assembly parameters
169
+ * @returns the matrix, feature schema, and preprocessing ops
170
+ */
171
+ assemble(params: FeatureAssemblyParams): Promise<FeatureAssemblyResult>;
172
+ /**
173
+ * Resolve target records: prefer inline `records`, else fetch via the
174
+ * `recordSet` descriptor through the data-access seam.
175
+ */
176
+ private resolveRecords;
177
+ /**
178
+ * The RAW columns that must be present on every record because the matrix reads them
179
+ * directly off the row (the `select`-emitter source columns — which also cover the
180
+ * `llm-derived` / `flow-agent` persisted-attribute reads — plus the train-time target
181
+ * variable). Embedding / as-of / vision values are fetched or computed, not row-read, so
182
+ * they are deliberately excluded.
183
+ */
184
+ private requiredRowColumns;
185
+ /**
186
+ * Fill in any required raw column the resolved records are MISSING, by re-reading just those
187
+ * columns from the same entity view the training path reads (`dataAccess.fetchRows`), keyed by
188
+ * primary key. Columns already present are left untouched — so a complete record set (training,
189
+ * a full `entity_object` load, unit-test fixtures) incurs no second read and no blob tax; only
190
+ * the on-demand narrow-projection case pays for the re-read, and only for the dropped columns.
191
+ * Returns a new row array when anything was hydrated (non-mutating), else the original array.
192
+ */
193
+ private hydrateMissingFeatureColumns;
194
+ /**
195
+ * HARD FAIL when a required raw feature column is absent from the records after hydration. A
196
+ * model executing without a column it was trained on would silently produce degenerate (often
197
+ * constant) predictions — the most dangerous class of train/serve skew, because it looks like it
198
+ * succeeded. We refuse to assemble: the caller (e.g. {@link MLModelInferenceProcessor}) catches
199
+ * this and marks the run **Failed** with this message, which bubbles to the run history + UI. This
200
+ * also guards TRAINING — a pipeline declaring a column the entity view doesn't expose fails loudly
201
+ * up front rather than producing a no-signal model.
202
+ */
203
+ private assertRequiredColumnsPresent;
204
+ /**
205
+ * Partition the frozen step graph into data-assembly steps (produce raw
206
+ * columns) and preprocessing steps (emit ordered {@link PreprocessingOp}[] for
207
+ * the sidecar). This is the anti-skew split (§6.2): TS NEVER fits or applies
208
+ * impute/standardize/onehot/bin — it only declares them for the sidecar.
209
+ */
210
+ private partitionSteps;
211
+ /**
212
+ * Translate a preprocessing step into a sidecar {@link PreprocessingOp}.
213
+ * Deny-listed columns are dropped (defense in depth — they should already be
214
+ * excluded from the matrix). Returns `null` when the op targets only
215
+ * deny-listed columns.
216
+ */
217
+ private toPreprocessingOp;
218
+ /**
219
+ * Build the ordered RAW-column plan from the data-assembly steps. Produces the
220
+ * `FeatureSchemaEntry[]` (ordered) and the column-emitter list the matrix
221
+ * builder replays per record. Deny-listed columns are excluded here, before
222
+ * any value is produced (§6.4).
223
+ */
224
+ private buildColumnPlan;
225
+ /** Plan plain `select` columns (raw passthrough from the target row). */
226
+ private planSelectColumns;
227
+ /** Plan embedding columns: one numeric feature per dimension (`emb_0..emb_{n-1}`). */
228
+ private planEmbeddingColumns;
229
+ /** Plan an llm-derived column read from a persisted, version-pinned attribute. */
230
+ private planLLMDerivedColumns;
231
+ /** Plan flow-agent output columns (resolved from persisted attributes for now). */
232
+ private planFlowAgentColumns;
233
+ /**
234
+ * Plan a `vision-llm` column (plan §11/§5.6). Produces one RAW feature column
235
+ * named by the step's `Output.FeatureName`. The feature is derived from the
236
+ * row's OWN image, so the leakage guard ALLOWS it (it's a property of the
237
+ * record, not a future-label proxy); the output name is still passed through
238
+ * the guard so an operator can deny-list a specific vision feature if it proves
239
+ * leaky post-train.
240
+ */
241
+ private planVisionLLMColumn;
242
+ /**
243
+ * Build an index of dated rows grouped by target-record primary key, for as-of
244
+ * feature computation. Filtered through the source deny-list.
245
+ */
246
+ private indexDatedSources;
247
+ /**
248
+ * Build the matrix rows: for each target record, emit one value per planned
249
+ * column (in schema order), then append the target variable when present.
250
+ */
251
+ private buildMatrix;
252
+ /**
253
+ * Build the vision-extraction context (extractor + prompt resolver) once per
254
+ * assembly when a `visionRunner` is supplied. Returns `null` when no runner is
255
+ * wired — vision emitters then yield null (no model call).
256
+ */
257
+ private buildVisionContext;
258
+ /** Produce the value for a single planned column on a single record. */
259
+ private emitValue;
260
+ /** Compute an as-of aggregate for one record from the dated index. */
261
+ private emitAsOfValue;
262
+ /**
263
+ * Emit a `vision-llm` feature value for one record (plan §11). Resolves the
264
+ * step's prompt (memoized per step) and runs the per-row extractor over the
265
+ * row's OWN image. When no vision runner/resolver is wired, yields `null`
266
+ * (no model call) so the rest of the matrix still assembles.
267
+ */
268
+ private emitVisionValue;
269
+ /** Resolve (and memoize) the prompt entity for a vision step via the injected resolver. */
270
+ private resolveVisionPrompt;
271
+ }
272
+ export type { FeatureKind };
273
+ //# sourceMappingURL=feature-assembly-executor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"feature-assembly-executor.d.ts","sourceRoot":"","sources":["../../src/feature-assembly/feature-assembly-executor.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAEH,OAAO,KAAK,EACV,gBAAgB,EAEhB,aAAa,EACb,YAAY,EACZ,YAAY,EACZ,kBAAkB,EAClB,eAAe,EACf,UAAU,EACV,WAAW,EACZ,MAAM,wCAAwC,CAAC;AAChD,OAAO,KAAK,EAAE,QAAQ,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAExE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,wCAAwC,CAAC;AAEnF,OAAO,EAAE,KAAK,kBAAkB,EAAqB,KAAK,SAAS,EAAE,MAAM,eAAe,CAAC;AAG3F,OAAO,EAA0B,KAAK,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAEhF;;;;;;;GAOG;AACH,MAAM,MAAM,oBAAoB,GAAG,CAAC,IAAI,EAAE,oBAAoB,KAAK,OAAO,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC,GAAG,cAAc,CAAC,QAAQ,CAAC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