@memberjunction/predictive-studio 0.0.1 → 5.45.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (266) hide show
  1. package/README.md +101 -28
  2. package/dist/actions/base-predictive-studio.action.d.ts +63 -0
  3. package/dist/actions/base-predictive-studio.action.d.ts.map +1 -0
  4. package/dist/actions/base-predictive-studio.action.js +125 -0
  5. package/dist/actions/base-predictive-studio.action.js.map +1 -0
  6. package/dist/actions/index.d.ts +38 -0
  7. package/dist/actions/index.d.ts.map +1 -0
  8. package/dist/actions/index.js +49 -0
  9. package/dist/actions/index.js.map +1 -0
  10. package/dist/actions/model-scoring-action-generator.d.ts +108 -0
  11. package/dist/actions/model-scoring-action-generator.d.ts.map +1 -0
  12. package/dist/actions/model-scoring-action-generator.js +316 -0
  13. package/dist/actions/model-scoring-action-generator.js.map +1 -0
  14. package/dist/actions/promote-model.action.d.ts +102 -0
  15. package/dist/actions/promote-model.action.d.ts.map +1 -0
  16. package/dist/actions/promote-model.action.js +132 -0
  17. package/dist/actions/promote-model.action.js.map +1 -0
  18. package/dist/actions/promote-model.gate.d.ts +77 -0
  19. package/dist/actions/promote-model.gate.d.ts.map +1 -0
  20. package/dist/actions/promote-model.gate.js +205 -0
  21. package/dist/actions/promote-model.gate.js.map +1 -0
  22. package/dist/actions/run-experiment.action.d.ts +60 -0
  23. package/dist/actions/run-experiment.action.d.ts.map +1 -0
  24. package/dist/actions/run-experiment.action.js +134 -0
  25. package/dist/actions/run-experiment.action.js.map +1 -0
  26. package/dist/actions/run-experiment.deps.d.ts +47 -0
  27. package/dist/actions/run-experiment.deps.d.ts.map +1 -0
  28. package/dist/actions/run-experiment.deps.js +71 -0
  29. package/dist/actions/run-experiment.deps.js.map +1 -0
  30. package/dist/actions/schedule-model-scoring.action.d.ts +71 -0
  31. package/dist/actions/schedule-model-scoring.action.d.ts.map +1 -0
  32. package/dist/actions/schedule-model-scoring.action.js +148 -0
  33. package/dist/actions/schedule-model-scoring.action.js.map +1 -0
  34. package/dist/actions/score-record-set.action.d.ts +133 -0
  35. package/dist/actions/score-record-set.action.d.ts.map +1 -0
  36. package/dist/actions/score-record-set.action.js +136 -0
  37. package/dist/actions/score-record-set.action.js.map +1 -0
  38. package/dist/actions/score-record-set.runner.d.ts +192 -0
  39. package/dist/actions/score-record-set.runner.d.ts.map +1 -0
  40. package/dist/actions/score-record-set.runner.js +416 -0
  41. package/dist/actions/score-record-set.runner.js.map +1 -0
  42. package/dist/actions/train-model.action.d.ts +57 -0
  43. package/dist/actions/train-model.action.d.ts.map +1 -0
  44. package/dist/actions/train-model.action.js +111 -0
  45. package/dist/actions/train-model.action.js.map +1 -0
  46. package/dist/agent/index.d.ts +14 -0
  47. package/dist/agent/index.d.ts.map +1 -0
  48. package/dist/agent/index.js +14 -0
  49. package/dist/agent/index.js.map +1 -0
  50. package/dist/agent/model-dev-orchestrator-agent.d.ts +42 -0
  51. package/dist/agent/model-dev-orchestrator-agent.d.ts.map +1 -0
  52. package/dist/agent/model-dev-orchestrator-agent.js +76 -0
  53. package/dist/agent/model-dev-orchestrator-agent.js.map +1 -0
  54. package/dist/agent/modeling-plan-to-pipeline.d.ts +49 -0
  55. package/dist/agent/modeling-plan-to-pipeline.d.ts.map +1 -0
  56. package/dist/agent/modeling-plan-to-pipeline.js +101 -0
  57. package/dist/agent/modeling-plan-to-pipeline.js.map +1 -0
  58. package/dist/agent/pipeline-builder-agent.d.ts +58 -0
  59. package/dist/agent/pipeline-builder-agent.d.ts.map +1 -0
  60. package/dist/agent/pipeline-builder-agent.js +101 -0
  61. package/dist/agent/pipeline-builder-agent.js.map +1 -0
  62. package/dist/agent/pipeline-builder.d.ts +67 -0
  63. package/dist/agent/pipeline-builder.d.ts.map +1 -0
  64. package/dist/agent/pipeline-builder.js +114 -0
  65. package/dist/agent/pipeline-builder.js.map +1 -0
  66. package/dist/experiment/concurrency.d.ts +41 -0
  67. package/dist/experiment/concurrency.d.ts.map +1 -0
  68. package/dist/experiment/concurrency.js +54 -0
  69. package/dist/experiment/concurrency.js.map +1 -0
  70. package/dist/experiment/experiment-orchestrator.d.ts +136 -0
  71. package/dist/experiment/experiment-orchestrator.d.ts.map +1 -0
  72. package/dist/experiment/experiment-orchestrator.js +408 -0
  73. package/dist/experiment/experiment-orchestrator.js.map +1 -0
  74. package/dist/experiment/index.d.ts +17 -0
  75. package/dist/experiment/index.d.ts.map +1 -0
  76. package/dist/experiment/index.js +17 -0
  77. package/dist/experiment/index.js.map +1 -0
  78. package/dist/experiment/leaderboard.d.ts +50 -0
  79. package/dist/experiment/leaderboard.d.ts.map +1 -0
  80. package/dist/experiment/leaderboard.js +91 -0
  81. package/dist/experiment/leaderboard.js.map +1 -0
  82. package/dist/experiment/seams.d.ts +95 -0
  83. package/dist/experiment/seams.d.ts.map +1 -0
  84. package/dist/experiment/seams.js +126 -0
  85. package/dist/experiment/seams.js.map +1 -0
  86. package/dist/experiment/types.d.ts +228 -0
  87. package/dist/experiment/types.d.ts.map +1 -0
  88. package/dist/experiment/types.js +19 -0
  89. package/dist/experiment/types.js.map +1 -0
  90. package/dist/experiment/wave-strategist.d.ts +31 -0
  91. package/dist/experiment/wave-strategist.d.ts.map +1 -0
  92. package/dist/experiment/wave-strategist.js +50 -0
  93. package/dist/experiment/wave-strategist.js.map +1 -0
  94. package/dist/feature-assembly/as-of.d.ts +74 -0
  95. package/dist/feature-assembly/as-of.d.ts.map +1 -0
  96. package/dist/feature-assembly/as-of.js +136 -0
  97. package/dist/feature-assembly/as-of.js.map +1 -0
  98. package/dist/feature-assembly/data-access.d.ts +114 -0
  99. package/dist/feature-assembly/data-access.d.ts.map +1 -0
  100. package/dist/feature-assembly/data-access.js +68 -0
  101. package/dist/feature-assembly/data-access.js.map +1 -0
  102. package/dist/feature-assembly/feature-assembly-executor.d.ts +273 -0
  103. package/dist/feature-assembly/feature-assembly-executor.d.ts.map +1 -0
  104. package/dist/feature-assembly/feature-assembly-executor.js +521 -0
  105. package/dist/feature-assembly/feature-assembly-executor.js.map +1 -0
  106. package/dist/feature-assembly/index.d.ts +13 -0
  107. package/dist/feature-assembly/index.d.ts.map +1 -0
  108. package/dist/feature-assembly/index.js +13 -0
  109. package/dist/feature-assembly/index.js.map +1 -0
  110. package/dist/feature-assembly/leakage-guard.d.ts +86 -0
  111. package/dist/feature-assembly/leakage-guard.d.ts.map +1 -0
  112. package/dist/feature-assembly/leakage-guard.js +111 -0
  113. package/dist/feature-assembly/leakage-guard.js.map +1 -0
  114. package/dist/feature-assembly/vision-llm.d.ts +125 -0
  115. package/dist/feature-assembly/vision-llm.d.ts.map +1 -0
  116. package/dist/feature-assembly/vision-llm.js +211 -0
  117. package/dist/feature-assembly/vision-llm.js.map +1 -0
  118. package/dist/feature-pipelines/feature-pipeline-engine.d.ts +159 -0
  119. package/dist/feature-pipelines/feature-pipeline-engine.d.ts.map +1 -0
  120. package/dist/feature-pipelines/feature-pipeline-engine.js +298 -0
  121. package/dist/feature-pipelines/feature-pipeline-engine.js.map +1 -0
  122. package/dist/feature-pipelines/index.d.ts +13 -0
  123. package/dist/feature-pipelines/index.d.ts.map +1 -0
  124. package/dist/feature-pipelines/index.js +13 -0
  125. package/dist/feature-pipelines/index.js.map +1 -0
  126. package/dist/feature-pipelines/types.d.ts +72 -0
  127. package/dist/feature-pipelines/types.d.ts.map +1 -0
  128. package/dist/feature-pipelines/types.js +17 -0
  129. package/dist/feature-pipelines/types.js.map +1 -0
  130. package/dist/index.d.ts +37 -0
  131. package/dist/index.d.ts.map +1 -0
  132. package/dist/index.js +80 -0
  133. package/dist/index.js.map +1 -0
  134. package/dist/maintenance/index.d.ts +19 -0
  135. package/dist/maintenance/index.d.ts.map +1 -0
  136. package/dist/maintenance/index.js +19 -0
  137. package/dist/maintenance/index.js.map +1 -0
  138. package/dist/maintenance/maintenance-engine.d.ts +152 -0
  139. package/dist/maintenance/maintenance-engine.d.ts.map +1 -0
  140. package/dist/maintenance/maintenance-engine.js +412 -0
  141. package/dist/maintenance/maintenance-engine.js.map +1 -0
  142. package/dist/maintenance/metrics.d.ts +37 -0
  143. package/dist/maintenance/metrics.d.ts.map +1 -0
  144. package/dist/maintenance/metrics.js +85 -0
  145. package/dist/maintenance/metrics.js.map +1 -0
  146. package/dist/maintenance/seams.d.ts +85 -0
  147. package/dist/maintenance/seams.d.ts.map +1 -0
  148. package/dist/maintenance/seams.js +166 -0
  149. package/dist/maintenance/seams.js.map +1 -0
  150. package/dist/maintenance/types.d.ts +318 -0
  151. package/dist/maintenance/types.d.ts.map +1 -0
  152. package/dist/maintenance/types.js +27 -0
  153. package/dist/maintenance/types.js.map +1 -0
  154. package/dist/operations/__tests__/helpers.d.ts +30 -0
  155. package/dist/operations/__tests__/helpers.d.ts.map +1 -0
  156. package/dist/operations/__tests__/helpers.js +44 -0
  157. package/dist/operations/__tests__/helpers.js.map +1 -0
  158. package/dist/operations/control-experiment-session.operation.d.ts +33 -0
  159. package/dist/operations/control-experiment-session.operation.d.ts.map +1 -0
  160. package/dist/operations/control-experiment-session.operation.js +71 -0
  161. package/dist/operations/control-experiment-session.operation.js.map +1 -0
  162. package/dist/operations/create-scoring-process.operation.d.ts +30 -0
  163. package/dist/operations/create-scoring-process.operation.d.ts.map +1 -0
  164. package/dist/operations/create-scoring-process.operation.js +65 -0
  165. package/dist/operations/create-scoring-process.operation.js.map +1 -0
  166. package/dist/operations/delegation.d.ts +113 -0
  167. package/dist/operations/delegation.d.ts.map +1 -0
  168. package/dist/operations/delegation.js +139 -0
  169. package/dist/operations/delegation.js.map +1 -0
  170. package/dist/operations/index.d.ts +40 -0
  171. package/dist/operations/index.d.ts.map +1 -0
  172. package/dist/operations/index.js +55 -0
  173. package/dist/operations/index.js.map +1 -0
  174. package/dist/operations/promote-model.operation.d.ts +57 -0
  175. package/dist/operations/promote-model.operation.d.ts.map +1 -0
  176. package/dist/operations/promote-model.operation.js +113 -0
  177. package/dist/operations/promote-model.operation.js.map +1 -0
  178. package/dist/operations/run-feature-pipeline.operation.d.ts +56 -0
  179. package/dist/operations/run-feature-pipeline.operation.d.ts.map +1 -0
  180. package/dist/operations/run-feature-pipeline.operation.js +94 -0
  181. package/dist/operations/run-feature-pipeline.operation.js.map +1 -0
  182. package/dist/operations/score-record-set.operation.d.ts +47 -0
  183. package/dist/operations/score-record-set.operation.d.ts.map +1 -0
  184. package/dist/operations/score-record-set.operation.js +113 -0
  185. package/dist/operations/score-record-set.operation.js.map +1 -0
  186. package/dist/operations/start-experiment-session.operation.d.ts +66 -0
  187. package/dist/operations/start-experiment-session.operation.d.ts.map +1 -0
  188. package/dist/operations/start-experiment-session.operation.js +132 -0
  189. package/dist/operations/start-experiment-session.operation.js.map +1 -0
  190. package/dist/operations/train-model.operation.d.ts +50 -0
  191. package/dist/operations/train-model.operation.d.ts.map +1 -0
  192. package/dist/operations/train-model.operation.js +114 -0
  193. package/dist/operations/train-model.operation.js.map +1 -0
  194. package/dist/scheduling/index.d.ts +13 -0
  195. package/dist/scheduling/index.d.ts.map +1 -0
  196. package/dist/scheduling/index.js +13 -0
  197. package/dist/scheduling/index.js.map +1 -0
  198. package/dist/scheduling/scheduled-model-scoring.d.ts +169 -0
  199. package/dist/scheduling/scheduled-model-scoring.d.ts.map +1 -0
  200. package/dist/scheduling/scheduled-model-scoring.js +189 -0
  201. package/dist/scheduling/scheduled-model-scoring.js.map +1 -0
  202. package/dist/scoring/artifact-loader.d.ts +65 -0
  203. package/dist/scoring/artifact-loader.d.ts.map +1 -0
  204. package/dist/scoring/artifact-loader.js +97 -0
  205. package/dist/scoring/artifact-loader.js.map +1 -0
  206. package/dist/scoring/index.d.ts +26 -0
  207. package/dist/scoring/index.d.ts.map +1 -0
  208. package/dist/scoring/index.js +26 -0
  209. package/dist/scoring/index.js.map +1 -0
  210. package/dist/scoring/ml-model-inference-processor.d.ts +154 -0
  211. package/dist/scoring/ml-model-inference-processor.d.ts.map +1 -0
  212. package/dist/scoring/ml-model-inference-processor.js +320 -0
  213. package/dist/scoring/ml-model-inference-processor.js.map +1 -0
  214. package/dist/scoring/ml-model-score-enricher.d.ts +80 -0
  215. package/dist/scoring/ml-model-score-enricher.d.ts.map +1 -0
  216. package/dist/scoring/ml-model-score-enricher.js +139 -0
  217. package/dist/scoring/ml-model-score-enricher.js.map +1 -0
  218. package/dist/scoring/register.d.ts +81 -0
  219. package/dist/scoring/register.d.ts.map +1 -0
  220. package/dist/scoring/register.js +105 -0
  221. package/dist/scoring/register.js.map +1 -0
  222. package/dist/scoring/scoring-binding.d.ts +72 -0
  223. package/dist/scoring/scoring-binding.d.ts.map +1 -0
  224. package/dist/scoring/scoring-binding.js +76 -0
  225. package/dist/scoring/scoring-binding.js.map +1 -0
  226. package/dist/scoring/scoring-process-shared.d.ts +105 -0
  227. package/dist/scoring/scoring-process-shared.d.ts.map +1 -0
  228. package/dist/scoring/scoring-process-shared.js +141 -0
  229. package/dist/scoring/scoring-process-shared.js.map +1 -0
  230. package/dist/scoring/scoring-process.d.ts +128 -0
  231. package/dist/scoring/scoring-process.d.ts.map +1 -0
  232. package/dist/scoring/scoring-process.js +146 -0
  233. package/dist/scoring/scoring-process.js.map +1 -0
  234. package/dist/scoring/seams.d.ts +40 -0
  235. package/dist/scoring/seams.d.ts.map +1 -0
  236. package/dist/scoring/seams.js +66 -0
  237. package/dist/scoring/seams.js.map +1 -0
  238. package/dist/scoring/startup-register.d.ts +49 -0
  239. package/dist/scoring/startup-register.d.ts.map +1 -0
  240. package/dist/scoring/startup-register.js +72 -0
  241. package/dist/scoring/startup-register.js.map +1 -0
  242. package/dist/scoring/types.d.ts +134 -0
  243. package/dist/scoring/types.d.ts.map +1 -0
  244. package/dist/scoring/types.js +26 -0
  245. package/dist/scoring/types.js.map +1 -0
  246. package/dist/training/artifact-store.d.ts +124 -0
  247. package/dist/training/artifact-store.d.ts.map +1 -0
  248. package/dist/training/artifact-store.js +163 -0
  249. package/dist/training/artifact-store.js.map +1 -0
  250. package/dist/training/index.d.ts +13 -0
  251. package/dist/training/index.d.ts.map +1 -0
  252. package/dist/training/index.js +13 -0
  253. package/dist/training/index.js.map +1 -0
  254. package/dist/training/seams.d.ts +57 -0
  255. package/dist/training/seams.d.ts.map +1 -0
  256. package/dist/training/seams.js +103 -0
  257. package/dist/training/seams.js.map +1 -0
  258. package/dist/training/training-engine.d.ts +96 -0
  259. package/dist/training/training-engine.d.ts.map +1 -0
  260. package/dist/training/training-engine.js +300 -0
  261. package/dist/training/training-engine.js.map +1 -0
  262. package/dist/training/types.d.ts +159 -0
  263. package/dist/training/types.d.ts.map +1 -0
  264. package/dist/training/types.js +16 -0
  265. package/dist/training/types.js.map +1 -0
  266. package/package.json +44 -7
@@ -0,0 +1,192 @@
1
+ /**
2
+ * @module actions/score-record-set.runner
3
+ *
4
+ * Production implementation of the {@link IScoreRecordSetRunner} seam used by the
5
+ * {@link PredictiveStudioScoreRecordSetAction}. It is the only place in the Score
6
+ * action path that touches MJ's live data plumbing: it resolves the requested
7
+ * {@link ScoringScope} into a concrete set of {@link RecordRef}s (via `RunView`),
8
+ * constructs the scoring work type {@link MLModelInferenceProcessor} with the
9
+ * production seams, and drives its batch path.
10
+ *
11
+ * Keeping this OUT of the action keeps the action thin (validate → delegate → map)
12
+ * and keeps this resolver independently testable. The artifact-loader seam is
13
+ * deliberately injected from a higher layer (the Engine package does not import
14
+ * MJStorage drivers — see `scoring/seams.ts`); when it is not supplied the runner
15
+ * fails with a clear, actionable message rather than silently mis-scoring.
16
+ */
17
+ import { type UserInfo, type IMetadataProvider, type EntityInfo } from '@memberjunction/core';
18
+ import { BaseEntity } from '@memberjunction/core';
19
+ import type { RecordRef, RecordProcessorContext, RecordResult } from '@memberjunction/record-set-processor-base';
20
+ import type { MLInferenceDeps, IArtifactLoader } from '../scoring/types.js';
21
+ import type { MLInferenceResultPayload } from '../scoring/ml-model-inference-processor.js';
22
+ import type { IScoreRecordSetRunner, ScoreRecordSetRequest, ScoreRecordSetResult, ScoringScope, WriteBackDirective } from './score-record-set.action.js';
23
+ import type { JsonObject } from './base-predictive-studio.action.js';
24
+ /**
25
+ * The declarative write-back shape this runner applies — IDENTICAL in meaning to
26
+ * the Record Set Processing substrate's `OutputMappingConfig`
27
+ * (`@memberjunction/record-set-processor`). Keys are **entity field names** on the
28
+ * scored record; values are **result references** resolved against the prediction
29
+ * payload via the shared {@link resolveMappingRef} resolver, where `$` is the
30
+ * payload root. So `{ "PredictedClass": "$.class", "ChurnProbability": "$.score" }`
31
+ * writes the prediction's `class` into `PredictedClass` and its `score` into
32
+ * `ChurnProbability`. Matching the substrate exactly keeps one mental model for
33
+ * write-back across the Action / Agent / Infer / ML-Model work types.
34
+ *
35
+ * Only the field-update form is honored here (the `MLInferenceResultPayload` is a
36
+ * flat score/class — there is no child-record fan-out to map). The substrate's
37
+ * optional `childRecord` shape is intentionally not part of the scoring path.
38
+ */
39
+ interface ScoringOutputMapping {
40
+ /** Map of `EntityFieldName -> resultRef` (e.g. `{ "Score": "$.score" }`). */
41
+ fields?: Record<string, string>;
42
+ }
43
+ /** Options for {@link ProductionScoreRecordSetRunner}. */
44
+ export interface ProductionScoreRecordSetRunnerOptions {
45
+ /**
46
+ * The scoring dependency bundle (model loader / artifact loader / sidecar). When
47
+ * omitted, production model-loader + sidecar are built, but the artifact loader
48
+ * MUST be supplied by the higher layer that owns the MJStorage binding.
49
+ */
50
+ deps?: MLInferenceDeps;
51
+ /** Primary-key field on scored entities (defaults to `ID`). */
52
+ primaryKeyField?: string;
53
+ }
54
+ /**
55
+ * Resolves a {@link ScoringScope} into records and drives the
56
+ * {@link MLModelInferenceProcessor} batch path.
57
+ */
58
+ export declare class ProductionScoreRecordSetRunner implements IScoreRecordSetRunner {
59
+ private readonly options;
60
+ constructor(options?: ProductionScoreRecordSetRunnerOptions);
61
+ /** @inheritdoc */
62
+ run(request: ScoreRecordSetRequest): Promise<ScoreRecordSetResult>;
63
+ /** Resolve the scope into a set of record refs. Exactly one selector is honored. */
64
+ protected resolveScope(scope: ScoringScope, contextUser?: UserInfo, provider?: IMetadataProvider): Promise<RecordRef[]>;
65
+ /**
66
+ * Resolve a `MJ: Lists` id into its member records as entity objects. Mirrors
67
+ * the substrate's `ListSource` membership contract — a List's members live in
68
+ * `MJ: List Details` (which store a composite-key-safe `RecordID`), NOT in a
69
+ * backing User View. We (1) read the list's target `EntityID`/name, (2) read its
70
+ * member `RecordID`s from `MJ: List Details`, then (3) load those target rows as
71
+ * `entity_object`s so the inference processor gets the same preloaded-row shape
72
+ * as the other scopes.
73
+ */
74
+ protected resolveList(listId: string, contextUser?: UserInfo, provider?: IMetadataProvider): Promise<RecordRef[]>;
75
+ /** Resolve an entity + filter into entity-object record refs. */
76
+ protected resolveFilter(entityName: string, extraFilter: string | undefined, maxRows: number | undefined, contextUser?: UserInfo, provider?: IMetadataProvider): Promise<RecordRef[]>;
77
+ /** Resolve a saved-view id into entity-object record refs. */
78
+ protected resolveView(params: {
79
+ ViewID: string;
80
+ }, contextUser?: UserInfo, provider?: IMetadataProvider): Promise<RecordRef[]>;
81
+ /**
82
+ * Build the per-record execution context for the processor. A `contextUser` is
83
+ * required (server-side scoring is user-scoped); the Action validates it before
84
+ * delegating, but we also assert here so this runner can't be driven without one
85
+ * (no silent force-cast of an absent user).
86
+ */
87
+ protected buildContext(request: ScoreRecordSetRequest): RecordProcessorContext;
88
+ /** Resolve the deps bundle, building production model-loader + sidecar when absent. */
89
+ protected resolveDeps(): MLInferenceDeps;
90
+ /**
91
+ * A placeholder {@link IArtifactLoader} that fails loudly. The Engine package
92
+ * does not import MJStorage drivers, so the real artifact loader is supplied by
93
+ * the layer that owns the storage binding (see `scoring/seams.ts`). Callers that
94
+ * run this action in production wire `deps` (with a real artifact loader) into
95
+ * the runner; tests inject the whole runner.
96
+ */
97
+ protected missingArtifactLoader(): IArtifactLoader;
98
+ /** Convert a scope `records` entry (id string or pk object) into a record ref. */
99
+ protected toRecordRef(entry: string | JsonObject): RecordRef;
100
+ /** Convert a loaded entity object into a record ref carrying the preloaded row. */
101
+ protected entityToRecordRef(row: BaseEntity, entityId?: string): RecordRef;
102
+ /**
103
+ * Build a `Field='value'`-style filter from a primary-key object. Each KEY is
104
+ * validated against the entity's real fields BEFORE interpolation — an unknown
105
+ * field name is rejected (SQL-injection defense for the untrusted key names,
106
+ * mirroring how the write-entity-fields action validates field names). Values
107
+ * are still single-quote-escaped.
108
+ */
109
+ protected primaryKeyFilter(entityName: string, primaryKey: JsonObject, provider?: IMetadataProvider): string;
110
+ /** Resolve an entity id from its name (best-effort; empty when unavailable). */
111
+ protected resolveEntityId(entityName: string, provider?: IMetadataProvider): string;
112
+ /** First string-able value of an object (used to key a record ref from a pk map). */
113
+ protected firstStringValue(obj: JsonObject): string;
114
+ /**
115
+ * Persist predictions back onto the scored records per the request's write-back
116
+ * `OutputMapping`, returning a {@link WriteBackOutcome} the summary folds in.
117
+ *
118
+ * No-ops (and reports `wroteBack: false`) when:
119
+ * - write-back is not requested, or is the boolean form (no explicit mapping — a
120
+ * default-mapping write-back is owned by the higher Record Process layer, not
121
+ * this runner), or
122
+ * - `request.dryRun` is `true` (compute-only — predictions are surfaced but never
123
+ * persisted, matching `ProcessRun.DryRun` in the substrate).
124
+ *
125
+ * Otherwise, for each **Succeeded** record (paired 1:1 with `records` in order),
126
+ * it resolves the target {@link BaseEntity}, validates + applies the mapped
127
+ * fields, and `Save()`s. A record whose Save fails is recorded in
128
+ * `failedIndexes` so {@link summarize} can move it from scored -> failed.
129
+ */
130
+ protected applyWriteBack(records: RecordRef[], results: RecordResult[], request: ScoreRecordSetRequest, context: RecordProcessorContext): Promise<WriteBackOutcome>;
131
+ /**
132
+ * Resolve the explicit field-mapping out of the write-back directive. Returns
133
+ * `undefined` for the boolean form or a malformed/empty mapping (treated as
134
+ * "no write-back to apply here").
135
+ */
136
+ protected resolveOutputMapping(directive: WriteBackDirective | undefined): ScoringOutputMapping | undefined;
137
+ /**
138
+ * Apply the mapping to ONE record's prediction and Save it. Resolves the target
139
+ * `BaseEntity` (reusing the preloaded `.Record` when present, else loading by id
140
+ * via the provider), validates every mapped field name against the entity's real
141
+ * fields (rejecting unknown names — mirroring the PK-name validation in
142
+ * {@link primaryKeyFilter}), sets the resolved values via the config-driven
143
+ * `Set` accessor, and Saves. Returns `true` on a successful Save, `false` on any
144
+ * failure (logged) so the caller can reclassify the record as failed.
145
+ */
146
+ protected writeBackRecord(record: RecordRef, payload: MLInferenceResultPayload | undefined, mapping: ScoringOutputMapping, context: RecordProcessorContext): Promise<boolean>;
147
+ /**
148
+ * Resolve the strongly-typed target {@link BaseEntity} for a record. Most scopes
149
+ * carry the already-loaded entity on `.Record`; reuse it (no extra DB round-trip)
150
+ * when it is a real `BaseEntity`. Otherwise (id-only `records`/`single` refs)
151
+ * load it from the provider via the record's `EntityID` + single-column PK using
152
+ * the request user, so write-back works regardless of how the scope was resolved.
153
+ */
154
+ protected resolveTargetEntity(record: RecordRef, context: RecordProcessorContext): Promise<BaseEntity>;
155
+ /**
156
+ * Validate every mapped target field name against the entity's real fields,
157
+ * throwing on the first unknown name. The mapping is caller-supplied, so an
158
+ * unknown field would otherwise silently no-op (or be swallowed by `Set`); we
159
+ * reject loudly — the same defensive posture as {@link primaryKeyFilter}.
160
+ */
161
+ protected assertMappedFieldsExist(entityInfo: EntityInfo, mapping: ScoringOutputMapping): void;
162
+ /**
163
+ * Fold per-record results into the run summary (counts + predictions /
164
+ * write-back). The `MLModelInferenceProcessor.ProcessBatch` contract returns
165
+ * results 1:1 with the input `records` in the SAME order, so we pair each
166
+ * result with its record by walking both together and key each prediction off
167
+ * the PAIRED record's `RecordID` (record-correlated, not a bare positional
168
+ * lookup that would silently misalign if the lengths ever diverged). All three
169
+ * outcome buckets — Succeeded / Failed / Skipped — are tallied.
170
+ *
171
+ * `wroteBack` reflects what was ACTUALLY persisted: it is `true` only when at
172
+ * least one record's prediction was Saved. A record that scored but whose
173
+ * write-back Save failed (its index is in `writeBack.failedIndexes`) is moved
174
+ * from the scored bucket into the failed bucket — its prediction did not land.
175
+ * Predictions are surfaced ephemerally only when nothing was written back.
176
+ */
177
+ protected summarize(records: RecordRef[], results: RecordResult[], request: ScoreRecordSetRequest, writeBack: WriteBackOutcome): ScoreRecordSetResult;
178
+ }
179
+ /**
180
+ * The outcome of the write-back pass, folded into the run summary. `wroteBack` is
181
+ * `true` only when at least one prediction was successfully Saved; `failedIndexes`
182
+ * holds the positions of records that scored but whose write-back Save failed (so
183
+ * they are reclassified scored -> failed).
184
+ */
185
+ interface WriteBackOutcome {
186
+ /** True when at least one record's prediction was Saved. */
187
+ wroteBack: boolean;
188
+ /** Indexes (into the paired records/results) whose write-back Save failed. */
189
+ failedIndexes: Set<number>;
190
+ }
191
+ export {};
192
+ //# sourceMappingURL=score-record-set.runner.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"score-record-set.runner.d.ts","sourceRoot":"","sources":["../../src/actions/score-record-set.runner.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAIL,KAAK,QAAQ,EACb,KAAK,iBAAiB,EACtB,KAAK,UAAU,EAEhB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAElD,OAAO,KAAK,EAAE,SAAS,EAAE,sBAAsB,EAAE,YAAY,EAAE,MAAM,2CAA2C,CAAC;AAIjH,OAAO,KAAK,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACzE,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,yCAAyC,CAAC;AACxF,OAAO,KAAK,EACV,qBAAqB,EACrB,qBAAqB,EACrB,oBAAoB,EACpB,YAAY,EAEZ,kBAAkB,EACnB,MAAM,2BAA2B,CAAC;AACnC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAElE;;;;;;;;;;;;;;GAcG;AACH,UAAU,oBAAoB;IAC5B,6EAA6E;IAC7E,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;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AAU,EAAE,UAAU,EAAE,OAAO,EAAE,oBAAoB,GAAG,IAAI;IAa9F;;;;;;;;;;;;;;OAcG;IACH,SAAS,CAAC,SAAS,CACjB,OAAO,EAAE,SAAS,EAAE,EACpB,OAAO,EAAE,YAAY,EAAE,EACvB,OAAO,EAAE,qBAAqB,EAC9B,SAAS,EAAE,gBAAgB,GAC1B,oBAAoB;CAqCxB;AAED;;;;;GAKG;AACH,UAAU,gBAAgB;IACxB,4DAA4D;IAC5D,SAAS,EAAE,OAAO,CAAC;IACnB,8EAA8E;IAC9E,aAAa,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;CAC5B"}
@@ -0,0 +1,416 @@
1
+ /**
2
+ * @module actions/score-record-set.runner
3
+ *
4
+ * Production implementation of the {@link IScoreRecordSetRunner} seam used by the
5
+ * {@link PredictiveStudioScoreRecordSetAction}. It is the only place in the Score
6
+ * action path that touches MJ's live data plumbing: it resolves the requested
7
+ * {@link ScoringScope} into a concrete set of {@link RecordRef}s (via `RunView`),
8
+ * constructs the scoring work type {@link MLModelInferenceProcessor} with the
9
+ * production seams, and drives its batch path.
10
+ *
11
+ * Keeping this OUT of the action keeps the action thin (validate → delegate → map)
12
+ * and keeps this resolver independently testable. The artifact-loader seam is
13
+ * deliberately injected from a higher layer (the Engine package does not import
14
+ * MJStorage drivers — see `scoring/seams.ts`); when it is not supplied the runner
15
+ * fails with a clear, actionable message rather than silently mis-scoring.
16
+ */
17
+ import { RunView, CompositeKey, LogError, Metadata, } from '@memberjunction/core';
18
+ import { BaseEntity } from '@memberjunction/core';
19
+ import { resolveMappingRef, UUIDsEqual } from '@memberjunction/global';
20
+ import { MLModelInferenceProcessor } from '../scoring/ml-model-inference-processor.js';
21
+ import { RunViewMLModelLoader, MJSidecarPredictor } from '../scoring/seams.js';
22
+ /**
23
+ * Resolves a {@link ScoringScope} into records and drives the
24
+ * {@link MLModelInferenceProcessor} batch path.
25
+ */
26
+ export class ProductionScoreRecordSetRunner {
27
+ constructor(options = {}) {
28
+ this.options = options;
29
+ }
30
+ /** @inheritdoc */
31
+ async run(request) {
32
+ const records = await this.resolveScope(request.scope, request.contextUser, request.provider);
33
+ const processor = new MLModelInferenceProcessor({
34
+ modelId: request.modelId,
35
+ deps: this.resolveDeps(),
36
+ primaryKeyField: this.options.primaryKeyField,
37
+ });
38
+ const context = this.buildContext(request);
39
+ const results = await processor.ProcessBatch(records, context);
40
+ // When an explicit OutputMapping was supplied (and this is not a dry run),
41
+ // persist each succeeded record's prediction into the mapped entity field(s).
42
+ // Records whose Save fails are reclassified Succeeded -> Failed in the summary.
43
+ const writeBack = await this.applyWriteBack(records, results, request, context);
44
+ return this.summarize(records, results, request, writeBack);
45
+ }
46
+ // ----- scope resolution ------------------------------------------------------
47
+ /** Resolve the scope into a set of record refs. Exactly one selector is honored. */
48
+ async resolveScope(scope, contextUser, provider) {
49
+ if (Array.isArray(scope.records) && scope.records.length > 0) {
50
+ return scope.records.map((r) => this.toRecordRef(r));
51
+ }
52
+ if (scope.single) {
53
+ return this.resolveFilter(scope.single.entityName, this.primaryKeyFilter(scope.single.entityName, scope.single.primaryKey, provider), 1, contextUser, provider);
54
+ }
55
+ if (scope.filter) {
56
+ return this.resolveFilter(scope.filter.entityName, scope.filter.extraFilter, scope.filter.maxRows, contextUser, provider);
57
+ }
58
+ if (scope.viewId) {
59
+ return this.resolveView({ ViewID: scope.viewId }, contextUser, provider);
60
+ }
61
+ if (scope.listId) {
62
+ return this.resolveList(scope.listId, contextUser, provider);
63
+ }
64
+ return [];
65
+ }
66
+ /**
67
+ * Resolve a `MJ: Lists` id into its member records as entity objects. Mirrors
68
+ * the substrate's `ListSource` membership contract — a List's members live in
69
+ * `MJ: List Details` (which store a composite-key-safe `RecordID`), NOT in a
70
+ * backing User View. We (1) read the list's target `EntityID`/name, (2) read its
71
+ * member `RecordID`s from `MJ: List Details`, then (3) load those target rows as
72
+ * `entity_object`s so the inference processor gets the same preloaded-row shape
73
+ * as the other scopes.
74
+ */
75
+ async resolveList(listId, contextUser, provider) {
76
+ const rv = provider ? RunView.FromMetadataProvider(provider) : new RunView();
77
+ const listResult = await rv.RunView({ EntityName: 'MJ: Lists', ExtraFilter: `ID='${listId}'`, Fields: ['EntityID'], ResultType: 'simple', MaxRows: 1 }, contextUser);
78
+ if (!listResult.Success) {
79
+ throw new Error(`Score Record Set: failed to load list '${listId}': ${listResult.ErrorMessage}`);
80
+ }
81
+ const entityId = listResult.Results[0]?.EntityID;
82
+ if (!entityId) {
83
+ throw new Error(`Score Record Set: list '${listId}' not found.`);
84
+ }
85
+ const entityName = (provider ?? Metadata.Provider)?.Entities.find((e) => UUIDsEqual(e.ID, entityId))?.Name;
86
+ if (!entityName) {
87
+ throw new Error(`Score Record Set: list '${listId}' targets an unknown entity (id '${entityId}').`);
88
+ }
89
+ const memberResult = await rv.RunView({ EntityName: 'MJ: List Details', ExtraFilter: `ListID='${listId}'`, Fields: ['RecordID'], OrderBy: 'ID', ResultType: 'simple' }, contextUser);
90
+ if (!memberResult.Success) {
91
+ throw new Error(`Score Record Set: failed to load members for list '${listId}': ${memberResult.ErrorMessage}`);
92
+ }
93
+ const recordIds = memberResult.Results.map((r) => String(r.RecordID)).filter((id) => id.length > 0);
94
+ if (recordIds.length === 0) {
95
+ return [];
96
+ }
97
+ // Load the member rows of the target entity as entity objects, keyed by their
98
+ // single-column PK (List Details store the PK string in RecordID).
99
+ const pkName = (provider ?? Metadata.Provider)?.EntityByName(entityName)?.FirstPrimaryKey?.Name ?? 'ID';
100
+ const inList = recordIds.map((id) => `'${id.replace(/'/g, "''")}'`).join(', ');
101
+ return this.resolveFilter(entityName, `${pkName} IN (${inList})`, undefined, contextUser, provider);
102
+ }
103
+ /** Resolve an entity + filter into entity-object record refs. */
104
+ async resolveFilter(entityName, extraFilter, maxRows, contextUser, provider) {
105
+ const rv = provider ? RunView.FromMetadataProvider(provider) : new RunView();
106
+ const result = await rv.RunView({
107
+ EntityName: entityName,
108
+ ExtraFilter: extraFilter,
109
+ MaxRows: maxRows,
110
+ ResultType: 'entity_object',
111
+ }, contextUser);
112
+ if (!result.Success) {
113
+ throw new Error(`Score Record Set: failed to resolve scope for '${entityName}': ${result.ErrorMessage}`);
114
+ }
115
+ const entityId = this.resolveEntityId(entityName, provider);
116
+ return result.Results.map((row) => this.entityToRecordRef(row, entityId));
117
+ }
118
+ /** Resolve a saved-view id into entity-object record refs. */
119
+ async resolveView(params, contextUser, provider) {
120
+ const rv = provider ? RunView.FromMetadataProvider(provider) : new RunView();
121
+ const result = await rv.RunView({ ViewID: params.ViewID, ResultType: 'entity_object' }, contextUser);
122
+ if (!result.Success) {
123
+ throw new Error(`Score Record Set: failed to resolve view '${params.ViewID}': ${result.ErrorMessage}`);
124
+ }
125
+ return result.Results.map((row) => this.entityToRecordRef(row));
126
+ }
127
+ // ----- helpers ---------------------------------------------------------------
128
+ /**
129
+ * Build the per-record execution context for the processor. A `contextUser` is
130
+ * required (server-side scoring is user-scoped); the Action validates it before
131
+ * delegating, but we also assert here so this runner can't be driven without one
132
+ * (no silent force-cast of an absent user).
133
+ */
134
+ buildContext(request) {
135
+ if (!request.contextUser) {
136
+ throw new Error('Score Record Set: a ContextUser is required to score records (server-side data access is user-scoped).');
137
+ }
138
+ const provider = request.provider ?? Metadata.Provider;
139
+ return {
140
+ contextUser: request.contextUser,
141
+ provider,
142
+ };
143
+ }
144
+ /** Resolve the deps bundle, building production model-loader + sidecar when absent. */
145
+ resolveDeps() {
146
+ if (this.options.deps) {
147
+ return this.options.deps;
148
+ }
149
+ return {
150
+ modelLoader: new RunViewMLModelLoader(),
151
+ sidecar: new MJSidecarPredictor(),
152
+ artifactLoader: this.missingArtifactLoader(),
153
+ };
154
+ }
155
+ /**
156
+ * A placeholder {@link IArtifactLoader} that fails loudly. The Engine package
157
+ * does not import MJStorage drivers, so the real artifact loader is supplied by
158
+ * the layer that owns the storage binding (see `scoring/seams.ts`). Callers that
159
+ * run this action in production wire `deps` (with a real artifact loader) into
160
+ * the runner; tests inject the whole runner.
161
+ */
162
+ missingArtifactLoader() {
163
+ return {
164
+ async load() {
165
+ throw new Error('Score Record Set: no artifact loader is configured. Supply MLInferenceDeps with a production ' +
166
+ 'IArtifactLoader (the MJStorage binding) when constructing ProductionScoreRecordSetRunner.');
167
+ },
168
+ };
169
+ }
170
+ /** Convert a scope `records` entry (id string or pk object) into a record ref. */
171
+ toRecordRef(entry) {
172
+ if (typeof entry === 'string') {
173
+ return { EntityID: '', RecordID: entry };
174
+ }
175
+ const id = this.firstStringValue(entry);
176
+ return { EntityID: '', RecordID: id, Record: entry };
177
+ }
178
+ /** Convert a loaded entity object into a record ref carrying the preloaded row. */
179
+ entityToRecordRef(row, entityId) {
180
+ return {
181
+ EntityID: entityId ?? row.EntityInfo?.ID ?? '',
182
+ RecordID: row.PrimaryKey.ToString(),
183
+ Record: row,
184
+ };
185
+ }
186
+ /**
187
+ * Build a `Field='value'`-style filter from a primary-key object. Each KEY is
188
+ * validated against the entity's real fields BEFORE interpolation — an unknown
189
+ * field name is rejected (SQL-injection defense for the untrusted key names,
190
+ * mirroring how the write-entity-fields action validates field names). Values
191
+ * are still single-quote-escaped.
192
+ */
193
+ primaryKeyFilter(entityName, primaryKey, provider) {
194
+ const entity = (provider ?? Metadata.Provider)?.EntityByName(entityName);
195
+ if (!entity) {
196
+ throw new Error(`Score Record Set: entity '${entityName}' not found in metadata; cannot resolve a single-record scope.`);
197
+ }
198
+ const entries = Object.entries(primaryKey);
199
+ if (entries.length === 0) {
200
+ throw new Error(`Score Record Set: single-record scope for '${entityName}' supplied no primary-key fields.`);
201
+ }
202
+ return entries
203
+ .map(([k, v]) => {
204
+ const field = entity.Fields.find((f) => f.Name.trim().toLowerCase() === k.trim().toLowerCase());
205
+ if (!field) {
206
+ throw new Error(`Score Record Set: '${k}' is not a field on entity '${entityName}'; refusing to build a filter from an unknown key.`);
207
+ }
208
+ return `${field.Name}='${String(v).replace(/'/g, "''")}'`;
209
+ })
210
+ .join(' AND ');
211
+ }
212
+ /** Resolve an entity id from its name (best-effort; empty when unavailable). */
213
+ resolveEntityId(entityName, provider) {
214
+ const md = provider ?? Metadata.Provider;
215
+ return md?.EntityByName(entityName)?.ID ?? '';
216
+ }
217
+ /** First string-able value of an object (used to key a record ref from a pk map). */
218
+ firstStringValue(obj) {
219
+ for (const v of Object.values(obj)) {
220
+ if (v != null) {
221
+ return String(v);
222
+ }
223
+ }
224
+ return '';
225
+ }
226
+ // ----- write-back ------------------------------------------------------------
227
+ /**
228
+ * Persist predictions back onto the scored records per the request's write-back
229
+ * `OutputMapping`, returning a {@link WriteBackOutcome} the summary folds in.
230
+ *
231
+ * No-ops (and reports `wroteBack: false`) when:
232
+ * - write-back is not requested, or is the boolean form (no explicit mapping — a
233
+ * default-mapping write-back is owned by the higher Record Process layer, not
234
+ * this runner), or
235
+ * - `request.dryRun` is `true` (compute-only — predictions are surfaced but never
236
+ * persisted, matching `ProcessRun.DryRun` in the substrate).
237
+ *
238
+ * Otherwise, for each **Succeeded** record (paired 1:1 with `records` in order),
239
+ * it resolves the target {@link BaseEntity}, validates + applies the mapped
240
+ * fields, and `Save()`s. A record whose Save fails is recorded in
241
+ * `failedIndexes` so {@link summarize} can move it from scored -> failed.
242
+ */
243
+ async applyWriteBack(records, results, request, context) {
244
+ const mapping = this.resolveOutputMapping(request.writeBack);
245
+ if (!mapping || request.dryRun) {
246
+ return { wroteBack: false, failedIndexes: new Set() };
247
+ }
248
+ const failedIndexes = new Set();
249
+ let anyWritten = false;
250
+ const pairCount = Math.min(records.length, results.length);
251
+ for (let i = 0; i < pairCount; i++) {
252
+ const result = results[i];
253
+ if (result.Status !== 'Succeeded') {
254
+ continue; // only persist predictions for records that actually scored
255
+ }
256
+ const payload = result.ResultPayload;
257
+ const ok = await this.writeBackRecord(records[i], payload, mapping, context);
258
+ if (ok) {
259
+ anyWritten = true;
260
+ }
261
+ else {
262
+ failedIndexes.add(i);
263
+ }
264
+ }
265
+ return { wroteBack: anyWritten, failedIndexes };
266
+ }
267
+ /**
268
+ * Resolve the explicit field-mapping out of the write-back directive. Returns
269
+ * `undefined` for the boolean form or a malformed/empty mapping (treated as
270
+ * "no write-back to apply here").
271
+ */
272
+ resolveOutputMapping(directive) {
273
+ if (!directive || directive === true) {
274
+ return undefined;
275
+ }
276
+ const raw = directive.OutputMapping;
277
+ const fields = raw?.fields;
278
+ if (!fields || typeof fields !== 'object' || Array.isArray(fields)) {
279
+ return undefined;
280
+ }
281
+ const normalized = {};
282
+ for (const [field, ref] of Object.entries(fields)) {
283
+ if (typeof ref === 'string') {
284
+ normalized[field] = ref;
285
+ }
286
+ }
287
+ return Object.keys(normalized).length > 0 ? { fields: normalized } : undefined;
288
+ }
289
+ /**
290
+ * Apply the mapping to ONE record's prediction and Save it. Resolves the target
291
+ * `BaseEntity` (reusing the preloaded `.Record` when present, else loading by id
292
+ * via the provider), validates every mapped field name against the entity's real
293
+ * fields (rejecting unknown names — mirroring the PK-name validation in
294
+ * {@link primaryKeyFilter}), sets the resolved values via the config-driven
295
+ * `Set` accessor, and Saves. Returns `true` on a successful Save, `false` on any
296
+ * failure (logged) so the caller can reclassify the record as failed.
297
+ */
298
+ async writeBackRecord(record, payload, mapping, context) {
299
+ try {
300
+ const entity = await this.resolveTargetEntity(record, context);
301
+ this.assertMappedFieldsExist(entity.EntityInfo, mapping);
302
+ // `$` is the prediction payload root; `record` exposes the source row — the
303
+ // SAME source contract the substrate's `applyOutputMapping` uses.
304
+ const sources = { $: payload ?? {}, record: record.Record ?? {} };
305
+ for (const [field, ref] of Object.entries(mapping.fields ?? {})) {
306
+ // Config-driven field name (no compile-time property) — the legitimate
307
+ // use of Set(), exactly as the substrate's write-back does.
308
+ entity.Set(field, resolveMappingRef(ref, sources));
309
+ }
310
+ const saved = await entity.Save();
311
+ if (!saved) {
312
+ LogError(`Score Record Set: write-back Save failed for record '${record.RecordID}': ` +
313
+ `${entity.LatestResult?.CompleteMessage ?? 'unknown error'}`);
314
+ }
315
+ return saved;
316
+ }
317
+ catch (err) {
318
+ const message = err instanceof Error ? err.message : String(err);
319
+ LogError(`Score Record Set: write-back failed for record '${record.RecordID}': ${message}`);
320
+ return false;
321
+ }
322
+ }
323
+ /**
324
+ * Resolve the strongly-typed target {@link BaseEntity} for a record. Most scopes
325
+ * carry the already-loaded entity on `.Record`; reuse it (no extra DB round-trip)
326
+ * when it is a real `BaseEntity`. Otherwise (id-only `records`/`single` refs)
327
+ * load it from the provider via the record's `EntityID` + single-column PK using
328
+ * the request user, so write-back works regardless of how the scope was resolved.
329
+ */
330
+ async resolveTargetEntity(record, context) {
331
+ if (record.Record instanceof BaseEntity) {
332
+ return record.Record;
333
+ }
334
+ const entityInfo = context.provider.EntityByID(record.EntityID);
335
+ if (!entityInfo) {
336
+ throw new Error(`entity '${record.EntityID}' not found in metadata; cannot write back prediction.`);
337
+ }
338
+ if (entityInfo.PrimaryKeys.length !== 1) {
339
+ throw new Error(`write-back supports single-primary-key entities only ('${entityInfo.Name}').`);
340
+ }
341
+ const obj = await context.provider.GetEntityObject(entityInfo.Name, context.contextUser);
342
+ const loaded = await obj.InnerLoad(CompositeKey.FromKeyValuePair(entityInfo.FirstPrimaryKey.Name, record.RecordID));
343
+ if (!loaded) {
344
+ throw new Error(`record '${record.RecordID}' of '${entityInfo.Name}' not found.`);
345
+ }
346
+ return obj;
347
+ }
348
+ /**
349
+ * Validate every mapped target field name against the entity's real fields,
350
+ * throwing on the first unknown name. The mapping is caller-supplied, so an
351
+ * unknown field would otherwise silently no-op (or be swallowed by `Set`); we
352
+ * reject loudly — the same defensive posture as {@link primaryKeyFilter}.
353
+ */
354
+ assertMappedFieldsExist(entityInfo, mapping) {
355
+ for (const field of Object.keys(mapping.fields ?? {})) {
356
+ const match = entityInfo.Fields.find((f) => f.Name.trim().toLowerCase() === field.trim().toLowerCase());
357
+ if (!match) {
358
+ throw new Error(`'${field}' is not a field on entity '${entityInfo.Name}'; refusing to write back to an unknown field.`);
359
+ }
360
+ }
361
+ }
362
+ // ----- result summarization --------------------------------------------------
363
+ /**
364
+ * Fold per-record results into the run summary (counts + predictions /
365
+ * write-back). The `MLModelInferenceProcessor.ProcessBatch` contract returns
366
+ * results 1:1 with the input `records` in the SAME order, so we pair each
367
+ * result with its record by walking both together and key each prediction off
368
+ * the PAIRED record's `RecordID` (record-correlated, not a bare positional
369
+ * lookup that would silently misalign if the lengths ever diverged). All three
370
+ * outcome buckets — Succeeded / Failed / Skipped — are tallied.
371
+ *
372
+ * `wroteBack` reflects what was ACTUALLY persisted: it is `true` only when at
373
+ * least one record's prediction was Saved. A record that scored but whose
374
+ * write-back Save failed (its index is in `writeBack.failedIndexes`) is moved
375
+ * from the scored bucket into the failed bucket — its prediction did not land.
376
+ * Predictions are surfaced ephemerally only when nothing was written back.
377
+ */
378
+ summarize(records, results, request, writeBack) {
379
+ let scoredCount = 0;
380
+ let failedCount = 0;
381
+ let skippedCount = 0;
382
+ const predictions = [];
383
+ const pairCount = Math.min(records.length, results.length);
384
+ for (let i = 0; i < pairCount; i++) {
385
+ const record = records[i];
386
+ const result = results[i];
387
+ if (result.Status === 'Succeeded') {
388
+ if (writeBack.failedIndexes.has(i)) {
389
+ // Scored, but the write-back Save failed — the prediction never landed.
390
+ failedCount++;
391
+ continue;
392
+ }
393
+ scoredCount++;
394
+ const payload = result.ResultPayload;
395
+ if (payload) {
396
+ predictions.push({ recordId: record.RecordID, score: payload.score, class: payload.class });
397
+ }
398
+ }
399
+ else if (result.Status === 'Failed') {
400
+ failedCount++;
401
+ }
402
+ else if (result.Status === 'Skipped') {
403
+ skippedCount++;
404
+ }
405
+ }
406
+ return {
407
+ scoredCount,
408
+ failedCount,
409
+ skippedCount,
410
+ wroteBack: writeBack.wroteBack,
411
+ // Predictions are ephemeral — only surfaced when NOTHING was written back.
412
+ predictions: writeBack.wroteBack ? undefined : predictions,
413
+ };
414
+ }
415
+ }
416
+ //# sourceMappingURL=score-record-set.runner.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"score-record-set.runner.js","sourceRoot":"","sources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