@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.
- package/README.md +101 -28
- package/dist/actions/base-predictive-studio.action.d.ts +63 -0
- package/dist/actions/base-predictive-studio.action.d.ts.map +1 -0
- package/dist/actions/base-predictive-studio.action.js +125 -0
- package/dist/actions/base-predictive-studio.action.js.map +1 -0
- package/dist/actions/index.d.ts +38 -0
- package/dist/actions/index.d.ts.map +1 -0
- package/dist/actions/index.js +49 -0
- package/dist/actions/index.js.map +1 -0
- package/dist/actions/model-scoring-action-generator.d.ts +108 -0
- package/dist/actions/model-scoring-action-generator.d.ts.map +1 -0
- package/dist/actions/model-scoring-action-generator.js +316 -0
- package/dist/actions/model-scoring-action-generator.js.map +1 -0
- package/dist/actions/promote-model.action.d.ts +102 -0
- package/dist/actions/promote-model.action.d.ts.map +1 -0
- package/dist/actions/promote-model.action.js +132 -0
- package/dist/actions/promote-model.action.js.map +1 -0
- package/dist/actions/promote-model.gate.d.ts +77 -0
- package/dist/actions/promote-model.gate.d.ts.map +1 -0
- package/dist/actions/promote-model.gate.js +205 -0
- package/dist/actions/promote-model.gate.js.map +1 -0
- package/dist/actions/run-experiment.action.d.ts +60 -0
- package/dist/actions/run-experiment.action.d.ts.map +1 -0
- package/dist/actions/run-experiment.action.js +134 -0
- package/dist/actions/run-experiment.action.js.map +1 -0
- package/dist/actions/run-experiment.deps.d.ts +47 -0
- package/dist/actions/run-experiment.deps.d.ts.map +1 -0
- package/dist/actions/run-experiment.deps.js +71 -0
- package/dist/actions/run-experiment.deps.js.map +1 -0
- package/dist/actions/schedule-model-scoring.action.d.ts +71 -0
- package/dist/actions/schedule-model-scoring.action.d.ts.map +1 -0
- package/dist/actions/schedule-model-scoring.action.js +148 -0
- package/dist/actions/schedule-model-scoring.action.js.map +1 -0
- package/dist/actions/score-record-set.action.d.ts +133 -0
- package/dist/actions/score-record-set.action.d.ts.map +1 -0
- package/dist/actions/score-record-set.action.js +136 -0
- package/dist/actions/score-record-set.action.js.map +1 -0
- package/dist/actions/score-record-set.runner.d.ts +192 -0
- package/dist/actions/score-record-set.runner.d.ts.map +1 -0
- package/dist/actions/score-record-set.runner.js +416 -0
- package/dist/actions/score-record-set.runner.js.map +1 -0
- package/dist/actions/train-model.action.d.ts +57 -0
- package/dist/actions/train-model.action.d.ts.map +1 -0
- package/dist/actions/train-model.action.js +111 -0
- package/dist/actions/train-model.action.js.map +1 -0
- package/dist/agent/index.d.ts +14 -0
- package/dist/agent/index.d.ts.map +1 -0
- package/dist/agent/index.js +14 -0
- package/dist/agent/index.js.map +1 -0
- package/dist/agent/model-dev-orchestrator-agent.d.ts +42 -0
- package/dist/agent/model-dev-orchestrator-agent.d.ts.map +1 -0
- package/dist/agent/model-dev-orchestrator-agent.js +76 -0
- package/dist/agent/model-dev-orchestrator-agent.js.map +1 -0
- package/dist/agent/modeling-plan-to-pipeline.d.ts +49 -0
- package/dist/agent/modeling-plan-to-pipeline.d.ts.map +1 -0
- package/dist/agent/modeling-plan-to-pipeline.js +101 -0
- package/dist/agent/modeling-plan-to-pipeline.js.map +1 -0
- package/dist/agent/pipeline-builder-agent.d.ts +58 -0
- package/dist/agent/pipeline-builder-agent.d.ts.map +1 -0
- package/dist/agent/pipeline-builder-agent.js +101 -0
- package/dist/agent/pipeline-builder-agent.js.map +1 -0
- package/dist/agent/pipeline-builder.d.ts +67 -0
- package/dist/agent/pipeline-builder.d.ts.map +1 -0
- package/dist/agent/pipeline-builder.js +114 -0
- package/dist/agent/pipeline-builder.js.map +1 -0
- package/dist/experiment/concurrency.d.ts +41 -0
- package/dist/experiment/concurrency.d.ts.map +1 -0
- package/dist/experiment/concurrency.js +54 -0
- package/dist/experiment/concurrency.js.map +1 -0
- package/dist/experiment/experiment-orchestrator.d.ts +136 -0
- package/dist/experiment/experiment-orchestrator.d.ts.map +1 -0
- package/dist/experiment/experiment-orchestrator.js +408 -0
- package/dist/experiment/experiment-orchestrator.js.map +1 -0
- package/dist/experiment/index.d.ts +17 -0
- package/dist/experiment/index.d.ts.map +1 -0
- package/dist/experiment/index.js +17 -0
- package/dist/experiment/index.js.map +1 -0
- package/dist/experiment/leaderboard.d.ts +50 -0
- package/dist/experiment/leaderboard.d.ts.map +1 -0
- package/dist/experiment/leaderboard.js +91 -0
- package/dist/experiment/leaderboard.js.map +1 -0
- package/dist/experiment/seams.d.ts +95 -0
- package/dist/experiment/seams.d.ts.map +1 -0
- package/dist/experiment/seams.js +126 -0
- package/dist/experiment/seams.js.map +1 -0
- package/dist/experiment/types.d.ts +228 -0
- package/dist/experiment/types.d.ts.map +1 -0
- package/dist/experiment/types.js +19 -0
- package/dist/experiment/types.js.map +1 -0
- package/dist/experiment/wave-strategist.d.ts +31 -0
- package/dist/experiment/wave-strategist.d.ts.map +1 -0
- package/dist/experiment/wave-strategist.js +50 -0
- package/dist/experiment/wave-strategist.js.map +1 -0
- package/dist/feature-assembly/as-of.d.ts +74 -0
- package/dist/feature-assembly/as-of.d.ts.map +1 -0
- package/dist/feature-assembly/as-of.js +136 -0
- package/dist/feature-assembly/as-of.js.map +1 -0
- package/dist/feature-assembly/data-access.d.ts +114 -0
- package/dist/feature-assembly/data-access.d.ts.map +1 -0
- package/dist/feature-assembly/data-access.js +68 -0
- package/dist/feature-assembly/data-access.js.map +1 -0
- package/dist/feature-assembly/feature-assembly-executor.d.ts +273 -0
- package/dist/feature-assembly/feature-assembly-executor.d.ts.map +1 -0
- package/dist/feature-assembly/feature-assembly-executor.js +521 -0
- package/dist/feature-assembly/feature-assembly-executor.js.map +1 -0
- package/dist/feature-assembly/index.d.ts +13 -0
- package/dist/feature-assembly/index.d.ts.map +1 -0
- package/dist/feature-assembly/index.js +13 -0
- package/dist/feature-assembly/index.js.map +1 -0
- package/dist/feature-assembly/leakage-guard.d.ts +86 -0
- package/dist/feature-assembly/leakage-guard.d.ts.map +1 -0
- package/dist/feature-assembly/leakage-guard.js +111 -0
- package/dist/feature-assembly/leakage-guard.js.map +1 -0
- package/dist/feature-assembly/vision-llm.d.ts +125 -0
- package/dist/feature-assembly/vision-llm.d.ts.map +1 -0
- package/dist/feature-assembly/vision-llm.js +211 -0
- package/dist/feature-assembly/vision-llm.js.map +1 -0
- package/dist/feature-pipelines/feature-pipeline-engine.d.ts +159 -0
- package/dist/feature-pipelines/feature-pipeline-engine.d.ts.map +1 -0
- package/dist/feature-pipelines/feature-pipeline-engine.js +298 -0
- package/dist/feature-pipelines/feature-pipeline-engine.js.map +1 -0
- package/dist/feature-pipelines/index.d.ts +13 -0
- package/dist/feature-pipelines/index.d.ts.map +1 -0
- package/dist/feature-pipelines/index.js +13 -0
- package/dist/feature-pipelines/index.js.map +1 -0
- package/dist/feature-pipelines/types.d.ts +72 -0
- package/dist/feature-pipelines/types.d.ts.map +1 -0
- package/dist/feature-pipelines/types.js +17 -0
- package/dist/feature-pipelines/types.js.map +1 -0
- package/dist/index.d.ts +37 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +80 -0
- package/dist/index.js.map +1 -0
- package/dist/maintenance/index.d.ts +19 -0
- package/dist/maintenance/index.d.ts.map +1 -0
- package/dist/maintenance/index.js +19 -0
- package/dist/maintenance/index.js.map +1 -0
- package/dist/maintenance/maintenance-engine.d.ts +152 -0
- package/dist/maintenance/maintenance-engine.d.ts.map +1 -0
- package/dist/maintenance/maintenance-engine.js +412 -0
- package/dist/maintenance/maintenance-engine.js.map +1 -0
- package/dist/maintenance/metrics.d.ts +37 -0
- package/dist/maintenance/metrics.d.ts.map +1 -0
- package/dist/maintenance/metrics.js +85 -0
- package/dist/maintenance/metrics.js.map +1 -0
- package/dist/maintenance/seams.d.ts +85 -0
- package/dist/maintenance/seams.d.ts.map +1 -0
- package/dist/maintenance/seams.js +166 -0
- package/dist/maintenance/seams.js.map +1 -0
- package/dist/maintenance/types.d.ts +318 -0
- package/dist/maintenance/types.d.ts.map +1 -0
- package/dist/maintenance/types.js +27 -0
- package/dist/maintenance/types.js.map +1 -0
- package/dist/operations/__tests__/helpers.d.ts +30 -0
- package/dist/operations/__tests__/helpers.d.ts.map +1 -0
- package/dist/operations/__tests__/helpers.js +44 -0
- package/dist/operations/__tests__/helpers.js.map +1 -0
- package/dist/operations/control-experiment-session.operation.d.ts +33 -0
- package/dist/operations/control-experiment-session.operation.d.ts.map +1 -0
- package/dist/operations/control-experiment-session.operation.js +71 -0
- package/dist/operations/control-experiment-session.operation.js.map +1 -0
- package/dist/operations/create-scoring-process.operation.d.ts +30 -0
- package/dist/operations/create-scoring-process.operation.d.ts.map +1 -0
- package/dist/operations/create-scoring-process.operation.js +65 -0
- package/dist/operations/create-scoring-process.operation.js.map +1 -0
- package/dist/operations/delegation.d.ts +113 -0
- package/dist/operations/delegation.d.ts.map +1 -0
- package/dist/operations/delegation.js +139 -0
- package/dist/operations/delegation.js.map +1 -0
- package/dist/operations/index.d.ts +40 -0
- package/dist/operations/index.d.ts.map +1 -0
- package/dist/operations/index.js +55 -0
- package/dist/operations/index.js.map +1 -0
- package/dist/operations/promote-model.operation.d.ts +57 -0
- package/dist/operations/promote-model.operation.d.ts.map +1 -0
- package/dist/operations/promote-model.operation.js +113 -0
- package/dist/operations/promote-model.operation.js.map +1 -0
- package/dist/operations/run-feature-pipeline.operation.d.ts +56 -0
- package/dist/operations/run-feature-pipeline.operation.d.ts.map +1 -0
- package/dist/operations/run-feature-pipeline.operation.js +94 -0
- package/dist/operations/run-feature-pipeline.operation.js.map +1 -0
- package/dist/operations/score-record-set.operation.d.ts +47 -0
- package/dist/operations/score-record-set.operation.d.ts.map +1 -0
- package/dist/operations/score-record-set.operation.js +113 -0
- package/dist/operations/score-record-set.operation.js.map +1 -0
- package/dist/operations/start-experiment-session.operation.d.ts +66 -0
- package/dist/operations/start-experiment-session.operation.d.ts.map +1 -0
- package/dist/operations/start-experiment-session.operation.js +132 -0
- package/dist/operations/start-experiment-session.operation.js.map +1 -0
- package/dist/operations/train-model.operation.d.ts +50 -0
- package/dist/operations/train-model.operation.d.ts.map +1 -0
- package/dist/operations/train-model.operation.js +114 -0
- package/dist/operations/train-model.operation.js.map +1 -0
- package/dist/scheduling/index.d.ts +13 -0
- package/dist/scheduling/index.d.ts.map +1 -0
- package/dist/scheduling/index.js +13 -0
- package/dist/scheduling/index.js.map +1 -0
- package/dist/scheduling/scheduled-model-scoring.d.ts +169 -0
- package/dist/scheduling/scheduled-model-scoring.d.ts.map +1 -0
- package/dist/scheduling/scheduled-model-scoring.js +189 -0
- package/dist/scheduling/scheduled-model-scoring.js.map +1 -0
- package/dist/scoring/artifact-loader.d.ts +65 -0
- package/dist/scoring/artifact-loader.d.ts.map +1 -0
- package/dist/scoring/artifact-loader.js +97 -0
- package/dist/scoring/artifact-loader.js.map +1 -0
- package/dist/scoring/index.d.ts +26 -0
- package/dist/scoring/index.d.ts.map +1 -0
- package/dist/scoring/index.js +26 -0
- package/dist/scoring/index.js.map +1 -0
- package/dist/scoring/ml-model-inference-processor.d.ts +154 -0
- package/dist/scoring/ml-model-inference-processor.d.ts.map +1 -0
- package/dist/scoring/ml-model-inference-processor.js +320 -0
- package/dist/scoring/ml-model-inference-processor.js.map +1 -0
- package/dist/scoring/ml-model-score-enricher.d.ts +80 -0
- package/dist/scoring/ml-model-score-enricher.d.ts.map +1 -0
- package/dist/scoring/ml-model-score-enricher.js +139 -0
- package/dist/scoring/ml-model-score-enricher.js.map +1 -0
- package/dist/scoring/register.d.ts +81 -0
- package/dist/scoring/register.d.ts.map +1 -0
- package/dist/scoring/register.js +105 -0
- package/dist/scoring/register.js.map +1 -0
- package/dist/scoring/scoring-binding.d.ts +72 -0
- package/dist/scoring/scoring-binding.d.ts.map +1 -0
- package/dist/scoring/scoring-binding.js +76 -0
- package/dist/scoring/scoring-binding.js.map +1 -0
- package/dist/scoring/scoring-process-shared.d.ts +105 -0
- package/dist/scoring/scoring-process-shared.d.ts.map +1 -0
- package/dist/scoring/scoring-process-shared.js +141 -0
- package/dist/scoring/scoring-process-shared.js.map +1 -0
- package/dist/scoring/scoring-process.d.ts +128 -0
- package/dist/scoring/scoring-process.d.ts.map +1 -0
- package/dist/scoring/scoring-process.js +146 -0
- package/dist/scoring/scoring-process.js.map +1 -0
- package/dist/scoring/seams.d.ts +40 -0
- package/dist/scoring/seams.d.ts.map +1 -0
- package/dist/scoring/seams.js +66 -0
- package/dist/scoring/seams.js.map +1 -0
- package/dist/scoring/startup-register.d.ts +49 -0
- package/dist/scoring/startup-register.d.ts.map +1 -0
- package/dist/scoring/startup-register.js +72 -0
- package/dist/scoring/startup-register.js.map +1 -0
- package/dist/scoring/types.d.ts +134 -0
- package/dist/scoring/types.d.ts.map +1 -0
- package/dist/scoring/types.js +26 -0
- package/dist/scoring/types.js.map +1 -0
- package/dist/training/artifact-store.d.ts +124 -0
- package/dist/training/artifact-store.d.ts.map +1 -0
- package/dist/training/artifact-store.js +163 -0
- package/dist/training/artifact-store.js.map +1 -0
- package/dist/training/index.d.ts +13 -0
- package/dist/training/index.d.ts.map +1 -0
- package/dist/training/index.js +13 -0
- package/dist/training/index.js.map +1 -0
- package/dist/training/seams.d.ts +57 -0
- package/dist/training/seams.d.ts.map +1 -0
- package/dist/training/seams.js +103 -0
- package/dist/training/seams.js.map +1 -0
- package/dist/training/training-engine.d.ts +96 -0
- package/dist/training/training-engine.d.ts.map +1 -0
- package/dist/training/training-engine.js +300 -0
- package/dist/training/training-engine.js.map +1 -0
- package/dist/training/types.d.ts +159 -0
- package/dist/training/types.d.ts.map +1 -0
- package/dist/training/types.js +16 -0
- package/dist/training/types.js.map +1 -0
- package/package.json +44 -7
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module scoring/scoring-process
|
|
3
|
+
*
|
|
4
|
+
* **On-demand model scoring** ("Operate this model"). A one-call way to create a
|
|
5
|
+
* persisted `WorkType='ML Model'` `MJ: Record Processes` row that scores a target
|
|
6
|
+
* entity's records with a trained `MJ: ML Models` — WITHOUT a schedule. It is the
|
|
7
|
+
* sibling of {@link module:scheduling/scheduled-model-scoring}: same assembled Record
|
|
8
|
+
* Process, but an **on-demand** trigger (no cron) instead of a recurring one.
|
|
9
|
+
*
|
|
10
|
+
* ## Why this shape (the UI "Operate this model" flow)
|
|
11
|
+
* The new UX lets a user operationalize a model in two steps that REUSE existing
|
|
12
|
+
* generic machinery:
|
|
13
|
+
*
|
|
14
|
+
* 1. **Create** the on-demand scoring Record Process — this helper. It assembles a
|
|
15
|
+
* single `MJ: Record Processes` row (`WorkType='ML Model'`, `Status='Active'`,
|
|
16
|
+
* `OnDemandEnabled=true`, `ScheduleEnabled=false`, NO cron) with the model
|
|
17
|
+
* `Configuration`, the scope, and — when a write-back column is supplied — an
|
|
18
|
+
* `OutputMapping` plus a `MJ: ML Model Scoring Bindings` lineage row
|
|
19
|
+
* (`Mode='OnDemand'`).
|
|
20
|
+
* 2. **Run / schedule** it later via the GENERIC surfaces — the existing
|
|
21
|
+
* "Run Record Process" Remote Op for run-now, and the generic
|
|
22
|
+
* `@memberjunction/ng-scheduling` dialog for scheduling (which creates its own
|
|
23
|
+
* "Run Record Process" scheduled job). Neither needs ML-specific server code.
|
|
24
|
+
*
|
|
25
|
+
* So the only ML-specific server piece is creating the row in step 1 — exactly what
|
|
26
|
+
* this helper does. It shares the scope model, value-kind → result-ref mapping,
|
|
27
|
+
* `Configuration`/`OutputMapping` serialization, scope application, validation, entity
|
|
28
|
+
* resolution, and lineage-binding creation with the scheduled sibling (in
|
|
29
|
+
* {@link module:scoring/scoring-process-shared}); it owns only the on-demand-trigger
|
|
30
|
+
* difference (no cron, `ScheduleEnabled=false`, binding `Mode='OnDemand'`).
|
|
31
|
+
*
|
|
32
|
+
* The `'ML Model'` `WorkType` is a runtime-registered extension (PS2-1) that the
|
|
33
|
+
* CodeGen'd `WorkType` value-list union (`'Action' | 'Agent' | 'FieldRules' |
|
|
34
|
+
* 'Infer'`) cannot represent, so it is set via `rp.Set('WorkType', 'ML Model')` —
|
|
35
|
+
* the same legitimate, documented exception PS2-1's scoring path uses.
|
|
36
|
+
*/
|
|
37
|
+
import { type UserInfo, type IMetadataProvider } from '@memberjunction/core';
|
|
38
|
+
import type { MJRecordProcessEntity, MJMLModelScoringBindingEntity } from '@memberjunction/core-entities';
|
|
39
|
+
import { type ScoringValueKind, type ScoringScope } from './scoring-process-shared.js';
|
|
40
|
+
/**
|
|
41
|
+
* Inputs for {@link createScoringProcess}. The required pair — `modelId` and
|
|
42
|
+
* `targetEntityName` — plus exactly one `scope` selector is the minimum to create an
|
|
43
|
+
* on-demand scoring Record Process; everything else has a sensible default (`ID`
|
|
44
|
+
* primary key, numeric score, generated name).
|
|
45
|
+
*
|
|
46
|
+
* Two output modes, driven by whether `outputField` is supplied:
|
|
47
|
+
* - **Write-back** (`outputField` present): a run writes the prediction into that
|
|
48
|
+
* target column AND a `MJ: ML Model Scoring Bindings` lineage row (`Mode='OnDemand'`)
|
|
49
|
+
* is created.
|
|
50
|
+
* - **Generic** (`outputField` omitted): a run records its predictions in the process
|
|
51
|
+
* run history (`MJ: Process Run Details`) only — no write-back column and no binding.
|
|
52
|
+
*/
|
|
53
|
+
export interface CreateScoringProcessOptions {
|
|
54
|
+
/** The `MJ: ML Models` id to score with. */
|
|
55
|
+
modelId: string;
|
|
56
|
+
/** The entity whose rows are scored (e.g. `'Memberships'`). */
|
|
57
|
+
targetEntityName: string;
|
|
58
|
+
/** The records a run scores. Populate EXACTLY ONE of: `filter`, `viewId`, `listId`, `all`. */
|
|
59
|
+
scope: ScoringScope;
|
|
60
|
+
/**
|
|
61
|
+
* Optional. The target-entity column to write the prediction into (e.g.
|
|
62
|
+
* `'RenewalScore'`). **Omit for generic output** — a run's predictions are recorded
|
|
63
|
+
* in the process run history (`MJ: Process Run Details`) only; no write-back column
|
|
64
|
+
* and no scoring binding are created.
|
|
65
|
+
*/
|
|
66
|
+
outputField?: string;
|
|
67
|
+
/** Which prediction value to write — numeric `'score'` (default) or `'class'` label. */
|
|
68
|
+
valueKind?: ScoringValueKind;
|
|
69
|
+
/** Primary-key field on the target entity (defaults to `'ID'`). */
|
|
70
|
+
primaryKeyField?: string;
|
|
71
|
+
/** Optional Record Process name; a descriptive default is generated when omitted. */
|
|
72
|
+
name?: string;
|
|
73
|
+
/** Server-side context user (required for data isolation + audit on the saved row). */
|
|
74
|
+
contextUser?: UserInfo;
|
|
75
|
+
/** Metadata provider to create the entity object against (defaults to the global). */
|
|
76
|
+
provider?: IMetadataProvider;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* The result of {@link createScoringProcess}: the saved on-demand Record Process AND —
|
|
80
|
+
* in write-back mode — its lineage binding. The Record Process is the row that the
|
|
81
|
+
* generic "Run Record Process" run-now / scheduler dialog then targets; the
|
|
82
|
+
* `MJ: ML Model Scoring Bindings` row *records* the operationalized model so the
|
|
83
|
+
* model-prediction form panel and "Models in Production" dashboard surface it.
|
|
84
|
+
*
|
|
85
|
+
* `binding` is `null` in **generic** mode (no `outputField`): there is no write-back
|
|
86
|
+
* column to bind, so no lineage row is created — predictions live in the process run
|
|
87
|
+
* history (`MJ: Process Run Details`) only.
|
|
88
|
+
*/
|
|
89
|
+
export interface CreateScoringProcessResult {
|
|
90
|
+
/** The saved on-demand `MJ: Record Processes` entity (`OnDemandEnabled=true`, no schedule). */
|
|
91
|
+
recordProcess: MJRecordProcessEntity;
|
|
92
|
+
/**
|
|
93
|
+
* The saved `MJ: ML Model Scoring Bindings` lineage row (`Mode='OnDemand'`) in
|
|
94
|
+
* write-back mode, or `null` in generic mode (no `outputField`, no binding).
|
|
95
|
+
*/
|
|
96
|
+
binding: MJMLModelScoringBindingEntity | null;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Create and save an **on-demand** Record Process that scores `targetEntity`'s rows
|
|
100
|
+
* with `modelId` — no schedule. The generic "Run Record Process" run-now Remote Op
|
|
101
|
+
* and the generic scheduling dialog target the returned row later. Operates in one of
|
|
102
|
+
* two modes, driven by whether `opts.outputField` is supplied:
|
|
103
|
+
*
|
|
104
|
+
* - **Write-back** (`outputField` present): a run writes the prediction into that
|
|
105
|
+
* target column (via the Record Process `OutputMapping`), AND this helper records a
|
|
106
|
+
* `MJ: ML Model Scoring Bindings` lineage row (`Mode='OnDemand'`) tying the model →
|
|
107
|
+
* Record Process → target entity/column so the operationalized model is discoverable
|
|
108
|
+
* by the UX surfaces that read those bindings. `result.binding` is the saved row.
|
|
109
|
+
* - **Generic** (`outputField` omitted): no `OutputMapping` is set and no binding is
|
|
110
|
+
* created — a run's predictions are recorded in the process run history
|
|
111
|
+
* (`MJ: Process Run Details`) only. `result.binding` is `null`.
|
|
112
|
+
*
|
|
113
|
+
* Unlike the scheduled sibling, this row carries `ScheduleEnabled=false` and NO cron,
|
|
114
|
+
* so saving it does NOT create an owned `MJ: Scheduled Jobs` row — it stays purely
|
|
115
|
+
* on-demand until a generic scheduler dialog (optionally) schedules it.
|
|
116
|
+
*
|
|
117
|
+
* @param opts the model + target + scope (+ optional write-back column); see
|
|
118
|
+
* {@link CreateScoringProcessOptions}
|
|
119
|
+
* @returns the saved Record Process AND — in write-back mode — its scoring binding
|
|
120
|
+
* (`null` in generic mode); see {@link CreateScoringProcessResult}
|
|
121
|
+
* @throws if a required input is missing, the scope is not exactly one selector, the
|
|
122
|
+
* target entity is unknown, the Record Process fails to save, or — in write-back mode,
|
|
123
|
+
* after the Record Process was saved — the binding fails to save (the message carries
|
|
124
|
+
* the cause). The binding save is intentionally fail-loud (not swallowed): a saved RP
|
|
125
|
+
* without a binding would run invisibly to the lineage UX, so we surface the inconsistency.
|
|
126
|
+
*/
|
|
127
|
+
export declare function createScoringProcess(opts: CreateScoringProcessOptions): Promise<CreateScoringProcessResult>;
|
|
128
|
+
//# sourceMappingURL=scoring-process.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scoring-process.d.ts","sourceRoot":"","sources":["../../src/scoring/scoring-process.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AAEH,OAAO,EAAE,KAAK,QAAQ,EAAE,KAAK,iBAAiB,EAAY,MAAM,sBAAsB,CAAC;AACvF,OAAO,KAAK,EAAE,qBAAqB,EAAE,6BAA6B,EAAE,MAAM,+BAA+B,CAAC;AAC1G,OAAO,EASL,KAAK,gBAAgB,EACrB,KAAK,YAAY,EAClB,MAAM,0BAA0B,CAAC;AAElC;;;;;;;;;;;;GAYG;AACH,MAAM,WAAW,2BAA2B;IAC1C,4CAA4C;IAC5C,OAAO,EAAE,MAAM,CAAC;IAChB,+DAA+D;IAC/D,gBAAgB,EAAE,MAAM,CAAC;IACzB,8FAA8F;IAC9F,KAAK,EAAE,YAAY,CAAC;IACpB;;;;;OAKG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,wFAAwF;IACxF,SAAS,CAAC,EAAE,gBAAgB,CAAC;IAC7B,mEAAmE;IACnE,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,qFAAqF;IACrF,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,uFAAuF;IACvF,WAAW,CAAC,EAAE,QAAQ,CAAC;IACvB,sFAAsF;IACtF,QAAQ,CAAC,EAAE,iBAAiB,CAAC;CAC9B;AAED;;;;;;;;;;GAUG;AACH,MAAM,WAAW,0BAA0B;IACzC,+FAA+F;IAC/F,aAAa,EAAE,qBAAqB,CAAC;IACrC;;;OAGG;IACH,OAAO,EAAE,6BAA6B,GAAG,IAAI,CAAC;CAC/C;AAKD;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAsB,oBAAoB,CACxC,IAAI,EAAE,2BAA2B,GAChC,OAAO,CAAC,0BAA0B,CAAC,CA+BrC"}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module scoring/scoring-process
|
|
3
|
+
*
|
|
4
|
+
* **On-demand model scoring** ("Operate this model"). A one-call way to create a
|
|
5
|
+
* persisted `WorkType='ML Model'` `MJ: Record Processes` row that scores a target
|
|
6
|
+
* entity's records with a trained `MJ: ML Models` — WITHOUT a schedule. It is the
|
|
7
|
+
* sibling of {@link module:scheduling/scheduled-model-scoring}: same assembled Record
|
|
8
|
+
* Process, but an **on-demand** trigger (no cron) instead of a recurring one.
|
|
9
|
+
*
|
|
10
|
+
* ## Why this shape (the UI "Operate this model" flow)
|
|
11
|
+
* The new UX lets a user operationalize a model in two steps that REUSE existing
|
|
12
|
+
* generic machinery:
|
|
13
|
+
*
|
|
14
|
+
* 1. **Create** the on-demand scoring Record Process — this helper. It assembles a
|
|
15
|
+
* single `MJ: Record Processes` row (`WorkType='ML Model'`, `Status='Active'`,
|
|
16
|
+
* `OnDemandEnabled=true`, `ScheduleEnabled=false`, NO cron) with the model
|
|
17
|
+
* `Configuration`, the scope, and — when a write-back column is supplied — an
|
|
18
|
+
* `OutputMapping` plus a `MJ: ML Model Scoring Bindings` lineage row
|
|
19
|
+
* (`Mode='OnDemand'`).
|
|
20
|
+
* 2. **Run / schedule** it later via the GENERIC surfaces — the existing
|
|
21
|
+
* "Run Record Process" Remote Op for run-now, and the generic
|
|
22
|
+
* `@memberjunction/ng-scheduling` dialog for scheduling (which creates its own
|
|
23
|
+
* "Run Record Process" scheduled job). Neither needs ML-specific server code.
|
|
24
|
+
*
|
|
25
|
+
* So the only ML-specific server piece is creating the row in step 1 — exactly what
|
|
26
|
+
* this helper does. It shares the scope model, value-kind → result-ref mapping,
|
|
27
|
+
* `Configuration`/`OutputMapping` serialization, scope application, validation, entity
|
|
28
|
+
* resolution, and lineage-binding creation with the scheduled sibling (in
|
|
29
|
+
* {@link module:scoring/scoring-process-shared}); it owns only the on-demand-trigger
|
|
30
|
+
* difference (no cron, `ScheduleEnabled=false`, binding `Mode='OnDemand'`).
|
|
31
|
+
*
|
|
32
|
+
* The `'ML Model'` `WorkType` is a runtime-registered extension (PS2-1) that the
|
|
33
|
+
* CodeGen'd `WorkType` value-list union (`'Action' | 'Agent' | 'FieldRules' |
|
|
34
|
+
* 'Infer'`) cannot represent, so it is set via `rp.Set('WorkType', 'ML Model')` —
|
|
35
|
+
* the same legitimate, documented exception PS2-1's scoring path uses.
|
|
36
|
+
*/
|
|
37
|
+
import { Metadata } from '@memberjunction/core';
|
|
38
|
+
import { ML_MODEL_WORK_TYPE, applyScope, modelConfiguration, writeBackOutputMapping, createScoringBinding, countScopeSelectors, resolveTargetEntityID, isNonEmpty, } from './scoring-process-shared.js';
|
|
39
|
+
/** The helper name used to prefix this module's errors + binding-failure logs. */
|
|
40
|
+
const HELPER_NAME = 'createScoringProcess';
|
|
41
|
+
/**
|
|
42
|
+
* Create and save an **on-demand** Record Process that scores `targetEntity`'s rows
|
|
43
|
+
* with `modelId` — no schedule. The generic "Run Record Process" run-now Remote Op
|
|
44
|
+
* and the generic scheduling dialog target the returned row later. Operates in one of
|
|
45
|
+
* two modes, driven by whether `opts.outputField` is supplied:
|
|
46
|
+
*
|
|
47
|
+
* - **Write-back** (`outputField` present): a run writes the prediction into that
|
|
48
|
+
* target column (via the Record Process `OutputMapping`), AND this helper records a
|
|
49
|
+
* `MJ: ML Model Scoring Bindings` lineage row (`Mode='OnDemand'`) tying the model →
|
|
50
|
+
* Record Process → target entity/column so the operationalized model is discoverable
|
|
51
|
+
* by the UX surfaces that read those bindings. `result.binding` is the saved row.
|
|
52
|
+
* - **Generic** (`outputField` omitted): no `OutputMapping` is set and no binding is
|
|
53
|
+
* created — a run's predictions are recorded in the process run history
|
|
54
|
+
* (`MJ: Process Run Details`) only. `result.binding` is `null`.
|
|
55
|
+
*
|
|
56
|
+
* Unlike the scheduled sibling, this row carries `ScheduleEnabled=false` and NO cron,
|
|
57
|
+
* so saving it does NOT create an owned `MJ: Scheduled Jobs` row — it stays purely
|
|
58
|
+
* on-demand until a generic scheduler dialog (optionally) schedules it.
|
|
59
|
+
*
|
|
60
|
+
* @param opts the model + target + scope (+ optional write-back column); see
|
|
61
|
+
* {@link CreateScoringProcessOptions}
|
|
62
|
+
* @returns the saved Record Process AND — in write-back mode — its scoring binding
|
|
63
|
+
* (`null` in generic mode); see {@link CreateScoringProcessResult}
|
|
64
|
+
* @throws if a required input is missing, the scope is not exactly one selector, the
|
|
65
|
+
* target entity is unknown, the Record Process fails to save, or — in write-back mode,
|
|
66
|
+
* after the Record Process was saved — the binding fails to save (the message carries
|
|
67
|
+
* the cause). The binding save is intentionally fail-loud (not swallowed): a saved RP
|
|
68
|
+
* without a binding would run invisibly to the lineage UX, so we surface the inconsistency.
|
|
69
|
+
*/
|
|
70
|
+
export async function createScoringProcess(opts) {
|
|
71
|
+
validateOptions(opts);
|
|
72
|
+
const provider = opts.provider ?? Metadata.Provider;
|
|
73
|
+
const entityID = resolveTargetEntityID(opts.targetEntityName, provider, HELPER_NAME);
|
|
74
|
+
const rp = await provider.GetEntityObject('MJ: Record Processes', opts.contextUser);
|
|
75
|
+
rp.NewRecord();
|
|
76
|
+
applyRecordProcessFields(rp, opts, entityID);
|
|
77
|
+
if (!(await rp.Save())) {
|
|
78
|
+
throw new Error(`${HELPER_NAME}: failed to save Record Process for model '${opts.modelId}': ` +
|
|
79
|
+
`${rp.LatestResult?.CompleteMessage ?? 'unknown error'}`);
|
|
80
|
+
}
|
|
81
|
+
// Lineage binding only in write-back mode — generic output has no column to bind.
|
|
82
|
+
const binding = isNonEmpty(opts.outputField)
|
|
83
|
+
? await createScoringBinding(opts.modelId, opts.outputField, rp.ID, entityID, 'OnDemand', provider, opts.contextUser, HELPER_NAME)
|
|
84
|
+
: null;
|
|
85
|
+
return { recordProcess: rp, binding };
|
|
86
|
+
}
|
|
87
|
+
// ----- field population --------------------------------------------------------
|
|
88
|
+
/**
|
|
89
|
+
* Populate the on-demand Record Process row from the (validated) options. Sets the
|
|
90
|
+
* lifecycle + work-type, the scope, the model `Configuration`, and enables on-demand
|
|
91
|
+
* runs — but leaves scheduling OFF (`ScheduleEnabled=false`, no cron), the one
|
|
92
|
+
* difference from the scheduled sibling.
|
|
93
|
+
*
|
|
94
|
+
* The write-back `OutputMapping` is set ONLY in write-back mode (`opts.outputField`
|
|
95
|
+
* present). In generic mode it is left unset, so a run records its predictions in the
|
|
96
|
+
* process run history (`MJ: Process Run Details`) only — there is no target column.
|
|
97
|
+
*/
|
|
98
|
+
function applyRecordProcessFields(rp, opts, entityID) {
|
|
99
|
+
rp.Name = opts.name ?? defaultName(opts);
|
|
100
|
+
rp.EntityID = entityID;
|
|
101
|
+
rp.Status = 'Active';
|
|
102
|
+
// 'ML Model' is the runtime-registered scoring work-type (PS2-1); the generated
|
|
103
|
+
// WorkType union (`'Action' | 'Agent' | 'FieldRules' | 'Infer'`) can't represent
|
|
104
|
+
// it, so Set() is the legitimate, documented exception (same as PS2-1's path).
|
|
105
|
+
rp.Set('WorkType', ML_MODEL_WORK_TYPE);
|
|
106
|
+
applyScope(rp, opts.scope);
|
|
107
|
+
rp.Configuration = modelConfiguration(opts.modelId, opts.primaryKeyField);
|
|
108
|
+
// Write-back mode only: map the prediction into the target column. Generic mode
|
|
109
|
+
// (no outputField) leaves OutputMapping unset — predictions land in run history only.
|
|
110
|
+
if (isNonEmpty(opts.outputField)) {
|
|
111
|
+
rp.OutputMapping = writeBackOutputMapping(opts.outputField, opts.valueKind);
|
|
112
|
+
}
|
|
113
|
+
// On-demand only: enable run-now, leave the schedule off (no cron → no owned job).
|
|
114
|
+
rp.OnDemandEnabled = true;
|
|
115
|
+
rp.ScheduleEnabled = false;
|
|
116
|
+
}
|
|
117
|
+
// ----- naming ------------------------------------------------------------------
|
|
118
|
+
/**
|
|
119
|
+
* A descriptive default Record Process name. The base shape never implies a column —
|
|
120
|
+
* `Score <entity> with model <id> (On Demand)` — which is exactly right for generic
|
|
121
|
+
* mode (no `outputField`). In write-back mode the target column is appended so the
|
|
122
|
+
* name records where the prediction lands (e.g.
|
|
123
|
+
* `Score Memberships with model <id> → RenewalScore (On Demand)`).
|
|
124
|
+
*/
|
|
125
|
+
function defaultName(opts) {
|
|
126
|
+
const writeBack = isNonEmpty(opts.outputField) ? ` → ${opts.outputField}` : '';
|
|
127
|
+
return `Score ${opts.targetEntityName} with model ${opts.modelId}${writeBack} (On Demand)`;
|
|
128
|
+
}
|
|
129
|
+
// ----- validation --------------------------------------------------------------
|
|
130
|
+
/**
|
|
131
|
+
* Validate the required inputs + exactly-one-scope rule, throwing a clear error on the
|
|
132
|
+
* first problem. `outputField` is NOT required — omitting it selects generic output
|
|
133
|
+
* (predictions recorded in run history only; see {@link createScoringProcess}).
|
|
134
|
+
*/
|
|
135
|
+
function validateOptions(opts) {
|
|
136
|
+
if (!isNonEmpty(opts.modelId)) {
|
|
137
|
+
throw new Error(`${HELPER_NAME}: \`modelId\` is required.`);
|
|
138
|
+
}
|
|
139
|
+
if (!isNonEmpty(opts.targetEntityName)) {
|
|
140
|
+
throw new Error(`${HELPER_NAME}: \`targetEntityName\` is required.`);
|
|
141
|
+
}
|
|
142
|
+
if (countScopeSelectors(opts.scope) !== 1) {
|
|
143
|
+
throw new Error(`${HELPER_NAME}: \`scope\` must populate exactly one of: filter, viewId, listId, all.`);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
//# sourceMappingURL=scoring-process.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scoring-process.js","sourceRoot":"","sources":["../../src/scoring/scoring-process.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module scoring/seams
|
|
3
|
+
*
|
|
4
|
+
* Production implementations of the {@link MLInferenceDeps} seams — thin adapters
|
|
5
|
+
* over `RunView`, `MJ: Files`, and the Python sidecar ({@link MLSidecar} from
|
|
6
|
+
* `@memberjunction/predictive-studio-sidecar`). These are the only place the
|
|
7
|
+
* scorer touches MJ's live data/inference plumbing; the processor itself depends
|
|
8
|
+
* solely on the narrow interfaces, so unit tests substitute in-memory fakes and
|
|
9
|
+
* never need a DB or sidecar.
|
|
10
|
+
*/
|
|
11
|
+
import { type UserInfo, type IMetadataProvider } from '@memberjunction/core';
|
|
12
|
+
import type { MJMLModelEntity } from '@memberjunction/core-entities';
|
|
13
|
+
import type { PredictRequest, PredictResponse } from '@memberjunction/predictive-studio-core';
|
|
14
|
+
import { MLSidecar } from '@memberjunction/predictive-studio-sidecar';
|
|
15
|
+
import type { IMLModelLoader, ISidecarPredictor } from './types.js';
|
|
16
|
+
/**
|
|
17
|
+
* `RunView`-backed {@link IMLModelLoader}. Loads the model as a full
|
|
18
|
+
* `entity_object` (it is read for its frozen contract, not mutated) and returns
|
|
19
|
+
* `null` when not found.
|
|
20
|
+
*/
|
|
21
|
+
export declare class RunViewMLModelLoader implements IMLModelLoader {
|
|
22
|
+
/** @inheritdoc */
|
|
23
|
+
loadModel(modelId: string, contextUser?: UserInfo, provider?: IMetadataProvider): Promise<MJMLModelEntity | null>;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* {@link ISidecarPredictor} backed by the self-managing {@link MLSidecar} client.
|
|
27
|
+
* Lazily starts the sidecar on first use (managed or remote mode is decided by
|
|
28
|
+
* `MLSidecar` from options/env), then warm-caches the connection for the run.
|
|
29
|
+
*/
|
|
30
|
+
export declare class MJSidecarPredictor implements ISidecarPredictor {
|
|
31
|
+
private readonly sidecar;
|
|
32
|
+
private started;
|
|
33
|
+
/**
|
|
34
|
+
* @param sidecar an `MLSidecar` instance (managed or remote)
|
|
35
|
+
*/
|
|
36
|
+
constructor(sidecar?: MLSidecar);
|
|
37
|
+
/** @inheritdoc */
|
|
38
|
+
predict(req: PredictRequest): Promise<PredictResponse>;
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=seams.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"seams.d.ts","sourceRoot":"","sources":["../../src/scoring/seams.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAW,KAAK,QAAQ,EAAE,KAAK,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACtF,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AACrE,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,wCAAwC,CAAC;AAC9F,OAAO,EAAE,SAAS,EAAE,MAAM,2CAA2C,CAAC;AAEtE,OAAO,KAAK,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAEjE;;;;GAIG;AACH,qBAAa,oBAAqB,YAAW,cAAc;IACzD,kBAAkB;IACL,SAAS,CACpB,OAAO,EAAE,MAAM,EACf,WAAW,CAAC,EAAE,QAAQ,EACtB,QAAQ,CAAC,EAAE,iBAAiB,GAC3B,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC;CAgBnC;AAED;;;;GAIG;AACH,qBAAa,kBAAmB,YAAW,iBAAiB;IAM9C,OAAO,CAAC,QAAQ,CAAC,OAAO;IALpC,OAAO,CAAC,OAAO,CAAS;IAExB;;OAEG;gBAC0B,OAAO,GAAE,SAA2B;IAEjE,kBAAkB;IACL,OAAO,CAAC,GAAG,EAAE,cAAc,GAAG,OAAO,CAAC,eAAe,CAAC;CAOpE"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module scoring/seams
|
|
3
|
+
*
|
|
4
|
+
* Production implementations of the {@link MLInferenceDeps} seams — thin adapters
|
|
5
|
+
* over `RunView`, `MJ: Files`, and the Python sidecar ({@link MLSidecar} from
|
|
6
|
+
* `@memberjunction/predictive-studio-sidecar`). These are the only place the
|
|
7
|
+
* scorer touches MJ's live data/inference plumbing; the processor itself depends
|
|
8
|
+
* solely on the narrow interfaces, so unit tests substitute in-memory fakes and
|
|
9
|
+
* never need a DB or sidecar.
|
|
10
|
+
*/
|
|
11
|
+
import { RunView } from '@memberjunction/core';
|
|
12
|
+
import { MLSidecar } from '@memberjunction/predictive-studio-sidecar';
|
|
13
|
+
/**
|
|
14
|
+
* `RunView`-backed {@link IMLModelLoader}. Loads the model as a full
|
|
15
|
+
* `entity_object` (it is read for its frozen contract, not mutated) and returns
|
|
16
|
+
* `null` when not found.
|
|
17
|
+
*/
|
|
18
|
+
export class RunViewMLModelLoader {
|
|
19
|
+
/** @inheritdoc */
|
|
20
|
+
async loadModel(modelId, contextUser, provider) {
|
|
21
|
+
const rv = provider ? RunView.FromMetadataProvider(provider) : new RunView();
|
|
22
|
+
const result = await rv.RunView({
|
|
23
|
+
EntityName: 'MJ: ML Models',
|
|
24
|
+
ExtraFilter: `ID='${modelId}'`,
|
|
25
|
+
ResultType: 'entity_object',
|
|
26
|
+
MaxRows: 1,
|
|
27
|
+
}, contextUser);
|
|
28
|
+
if (!result.Success || result.Results.length === 0) {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
return result.Results[0];
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* {@link ISidecarPredictor} backed by the self-managing {@link MLSidecar} client.
|
|
36
|
+
* Lazily starts the sidecar on first use (managed or remote mode is decided by
|
|
37
|
+
* `MLSidecar` from options/env), then warm-caches the connection for the run.
|
|
38
|
+
*/
|
|
39
|
+
export class MJSidecarPredictor {
|
|
40
|
+
/**
|
|
41
|
+
* @param sidecar an `MLSidecar` instance (managed or remote)
|
|
42
|
+
*/
|
|
43
|
+
constructor(sidecar = new MLSidecar()) {
|
|
44
|
+
this.sidecar = sidecar;
|
|
45
|
+
this.started = false;
|
|
46
|
+
}
|
|
47
|
+
/** @inheritdoc */
|
|
48
|
+
async predict(req) {
|
|
49
|
+
if (!this.started) {
|
|
50
|
+
await this.sidecar.start();
|
|
51
|
+
this.started = true;
|
|
52
|
+
}
|
|
53
|
+
return this.sidecar.predict(req);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
// NOTE on `IArtifactLoader`:
|
|
57
|
+
//
|
|
58
|
+
// The read-side artifact loader is the counterpart to the training
|
|
59
|
+
// `MJFilesArtifactStore.save`. Like the training store, the byte transfer to
|
|
60
|
+
// MJStorage is wired by the layer that owns the storage binding (provider id +
|
|
61
|
+
// MJStorage driver). The Engine package deliberately does NOT import MJStorage
|
|
62
|
+
// drivers (keeping it slim + trivially mockable), so the production
|
|
63
|
+
// `IArtifactLoader` is supplied by that higher layer (or by the sidecar's own
|
|
64
|
+
// warm artifact cache keyed by model id). Tests inject an in-memory loader; see
|
|
65
|
+
// `./artifact-loader` for the in-memory implementation.
|
|
66
|
+
//# sourceMappingURL=seams.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"seams.js","sourceRoot":"","sources":["../../src/scoring/seams.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,OAAO,EAAyC,MAAM,sBAAsB,CAAC;AAGtF,OAAO,EAAE,SAAS,EAAE,MAAM,2CAA2C,CAAC;AAItE;;;;GAIG;AACH,MAAM,OAAO,oBAAoB;IAC/B,kBAAkB;IACX,KAAK,CAAC,SAAS,CACpB,OAAe,EACf,WAAsB,EACtB,QAA4B;QAE5B,MAAM,EAAE,GAAG,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,oBAAoB,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,IAAI,OAAO,EAAE,CAAC;QAC7E,MAAM,MAAM,GAAG,MAAM,EAAE,CAAC,OAAO,CAC7B;YACE,UAAU,EAAE,eAAe;YAC3B,WAAW,EAAE,OAAO,OAAO,GAAG;YAC9B,UAAU,EAAE,eAAe;YAC3B,OAAO,EAAE,CAAC;SACX,EACD,WAAW,CACZ,CAAC;QACF,IAAI,CAAC,MAAM,CAAC,OAAO,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACnD,OAAO,IAAI,CAAC;QACd,CAAC;QACD,OAAO,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;IAC3B,CAAC;CACF;AAED;;;;GAIG;AACH,MAAM,OAAO,kBAAkB;IAG7B;;OAEG;IACH,YAA6B,UAAqB,IAAI,SAAS,EAAE;QAApC,YAAO,GAAP,OAAO,CAA6B;QALzD,YAAO,GAAG,KAAK,CAAC;IAK4C,CAAC;IAErE,kBAAkB;IACX,KAAK,CAAC,OAAO,CAAC,GAAmB;QACtC,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;YAClB,MAAM,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;YAC3B,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;QACtB,CAAC;QACD,OAAO,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IACnC,CAAC;CACF;AAED,6BAA6B;AAC7B,EAAE;AACF,mEAAmE;AACnE,6EAA6E;AAC7E,+EAA+E;AAC/E,+EAA+E;AAC/E,oEAAoE;AACpE,8EAA8E;AAC9E,gFAAgF;AAChF,wDAAwD"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module scoring/startup-register
|
|
3
|
+
*
|
|
4
|
+
* Startup wiring that connects the Predictive Studio `'ML Model'` scoring processor to the
|
|
5
|
+
* Record Set Processing substrate at application boot — closing the gap between the processor's
|
|
6
|
+
* `@RegisterClass` decoration (which only makes it *resolvable* through the ClassFactory) and the
|
|
7
|
+
* substrate actually *routing* a saved `MJ: Record Processes` row whose `WorkType='ML Model'` to it.
|
|
8
|
+
*
|
|
9
|
+
* ## Why a startup sink
|
|
10
|
+
*
|
|
11
|
+
* {@link registerMLScoringProcessor} installs the factory into the substrate's
|
|
12
|
+
* {@link RecordProcessorRegistry}, after which `RecordProcessExecutor.buildProcessor()` resolves the
|
|
13
|
+
* ML work type with no substrate change. But that call was never made at boot — so a Record Process
|
|
14
|
+
* with `WorkType='ML Model'` fell through to "unknown work type". This {@link IStartupSink} makes the
|
|
15
|
+
* call once during MJAPI bootstrap (mirroring `RemoteBrowserEngine`'s `@RegisterForStartup` pattern),
|
|
16
|
+
* wiring the production {@link MLInferenceDeps} bundle ({@link buildProductionMLInferenceDeps}) the
|
|
17
|
+
* Score action / Remote Op also use — so a model is always scored the same way it was trained.
|
|
18
|
+
*
|
|
19
|
+
* Unlike `RemoteBrowserEngine`, this sink warms NO `BaseEngine` cache and touches NO database: the
|
|
20
|
+
* injected seams take their `provider` + `user` per-call, not at construction. The work is a cheap,
|
|
21
|
+
* synchronous in-memory map write, so it is **not** `deferred` — it joins the synchronous startup
|
|
22
|
+
* batch and completes instantly.
|
|
23
|
+
*/
|
|
24
|
+
import { IMetadataProvider, IStartupSink, UserInfo } from '@memberjunction/core';
|
|
25
|
+
import { BaseSingleton } from '@memberjunction/global';
|
|
26
|
+
/**
|
|
27
|
+
* Startup sink that registers the Predictive Studio `'ML Model'` (and `'MLModelInference'` alias)
|
|
28
|
+
* scoring processor into the Record Set Processing {@link RecordProcessorRegistry}, so a saved
|
|
29
|
+
* `MJ: Record Processes` row with `WorkType='ML Model'` routes to the scorer live.
|
|
30
|
+
*
|
|
31
|
+
* The registration is idempotent (last-wins) and provider-agnostic — the injected seams receive
|
|
32
|
+
* their `provider` + `user` per scoring call — so {@link HandleStartup} needs no body beyond the
|
|
33
|
+
* single register call. Discovered via the `@RegisterForStartup` decorator + the class manifest.
|
|
34
|
+
*/
|
|
35
|
+
export declare class PredictiveStudioScoringStartup extends BaseSingleton<PredictiveStudioScoringStartup> implements IStartupSink {
|
|
36
|
+
/** The singleton accessor, keyed by this class's name in the Global Object Store (via {@link BaseSingleton}). */
|
|
37
|
+
static get Instance(): PredictiveStudioScoringStartup;
|
|
38
|
+
/**
|
|
39
|
+
* Boot entry point (per {@link IStartupSink}). Registers the ML scoring processor for the
|
|
40
|
+
* `'ML Model'` work type with the production deps bundle. No-op-safe to call more than once
|
|
41
|
+
* (the registry last-wins), and needs neither the `contextUser` nor `provider` — the deps are
|
|
42
|
+
* constructed without them and take a `provider`/`user` per scoring call.
|
|
43
|
+
*
|
|
44
|
+
* @param _contextUser unused — the registration is provider/user-agnostic at construction time
|
|
45
|
+
* @param _provider unused — see above
|
|
46
|
+
*/
|
|
47
|
+
HandleStartup(_contextUser?: UserInfo, _provider?: IMetadataProvider): Promise<void>;
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=startup-register.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"startup-register.d.ts","sourceRoot":"","sources":["../../src/scoring/startup-register.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,EAAE,iBAAiB,EAAE,YAAY,EAAmC,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAClH,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAKvD;;;;;;;;GAQG;AACH,qBAGa,8BAA+B,SAAQ,aAAa,CAAC,8BAA8B,CAAE,YAAW,YAAY;IACvH,iHAAiH;IACjH,WAAkB,QAAQ,IAAI,8BAA8B,CAE3D;IAED;;;;;;;;OAQG;IACU,aAAa,CAAC,YAAY,CAAC,EAAE,QAAQ,EAAE,SAAS,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC;CAQlG"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module scoring/startup-register
|
|
3
|
+
*
|
|
4
|
+
* Startup wiring that connects the Predictive Studio `'ML Model'` scoring processor to the
|
|
5
|
+
* Record Set Processing substrate at application boot — closing the gap between the processor's
|
|
6
|
+
* `@RegisterClass` decoration (which only makes it *resolvable* through the ClassFactory) and the
|
|
7
|
+
* substrate actually *routing* a saved `MJ: Record Processes` row whose `WorkType='ML Model'` to it.
|
|
8
|
+
*
|
|
9
|
+
* ## Why a startup sink
|
|
10
|
+
*
|
|
11
|
+
* {@link registerMLScoringProcessor} installs the factory into the substrate's
|
|
12
|
+
* {@link RecordProcessorRegistry}, after which `RecordProcessExecutor.buildProcessor()` resolves the
|
|
13
|
+
* ML work type with no substrate change. But that call was never made at boot — so a Record Process
|
|
14
|
+
* with `WorkType='ML Model'` fell through to "unknown work type". This {@link IStartupSink} makes the
|
|
15
|
+
* call once during MJAPI bootstrap (mirroring `RemoteBrowserEngine`'s `@RegisterForStartup` pattern),
|
|
16
|
+
* wiring the production {@link MLInferenceDeps} bundle ({@link buildProductionMLInferenceDeps}) the
|
|
17
|
+
* Score action / Remote Op also use — so a model is always scored the same way it was trained.
|
|
18
|
+
*
|
|
19
|
+
* Unlike `RemoteBrowserEngine`, this sink warms NO `BaseEngine` cache and touches NO database: the
|
|
20
|
+
* injected seams take their `provider` + `user` per-call, not at construction. The work is a cheap,
|
|
21
|
+
* synchronous in-memory map write, so it is **not** `deferred` — it joins the synchronous startup
|
|
22
|
+
* batch and completes instantly.
|
|
23
|
+
*/
|
|
24
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
25
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
26
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
27
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
28
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
29
|
+
};
|
|
30
|
+
import { LogStatusEx, RegisterForStartup } from '@memberjunction/core';
|
|
31
|
+
import { BaseSingleton } from '@memberjunction/global';
|
|
32
|
+
import { registerMLScoringProcessor } from './register.js';
|
|
33
|
+
import { buildProductionMLInferenceDeps } from '../operations/delegation.js';
|
|
34
|
+
/**
|
|
35
|
+
* Startup sink that registers the Predictive Studio `'ML Model'` (and `'MLModelInference'` alias)
|
|
36
|
+
* scoring processor into the Record Set Processing {@link RecordProcessorRegistry}, so a saved
|
|
37
|
+
* `MJ: Record Processes` row with `WorkType='ML Model'` routes to the scorer live.
|
|
38
|
+
*
|
|
39
|
+
* The registration is idempotent (last-wins) and provider-agnostic — the injected seams receive
|
|
40
|
+
* their `provider` + `user` per scoring call — so {@link HandleStartup} needs no body beyond the
|
|
41
|
+
* single register call. Discovered via the `@RegisterForStartup` decorator + the class manifest.
|
|
42
|
+
*/
|
|
43
|
+
let PredictiveStudioScoringStartup = class PredictiveStudioScoringStartup extends BaseSingleton {
|
|
44
|
+
/** The singleton accessor, keyed by this class's name in the Global Object Store (via {@link BaseSingleton}). */
|
|
45
|
+
static get Instance() {
|
|
46
|
+
return super.getInstance();
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Boot entry point (per {@link IStartupSink}). Registers the ML scoring processor for the
|
|
50
|
+
* `'ML Model'` work type with the production deps bundle. No-op-safe to call more than once
|
|
51
|
+
* (the registry last-wins), and needs neither the `contextUser` nor `provider` — the deps are
|
|
52
|
+
* constructed without them and take a `provider`/`user` per scoring call.
|
|
53
|
+
*
|
|
54
|
+
* @param _contextUser unused — the registration is provider/user-agnostic at construction time
|
|
55
|
+
* @param _provider unused — see above
|
|
56
|
+
*/
|
|
57
|
+
async HandleStartup(_contextUser, _provider) {
|
|
58
|
+
registerMLScoringProcessor(buildProductionMLInferenceDeps());
|
|
59
|
+
// Routine boot registration — only surface it under verbose logging to keep startup quiet.
|
|
60
|
+
LogStatusEx({
|
|
61
|
+
message: '[PredictiveStudioScoringStartup] Registered ML Model scoring processor for Record Set Processing.',
|
|
62
|
+
verboseOnly: true,
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
PredictiveStudioScoringStartup = __decorate([
|
|
67
|
+
RegisterForStartup({
|
|
68
|
+
description: 'Predictive Studio ML Model scoring processor registration',
|
|
69
|
+
})
|
|
70
|
+
], PredictiveStudioScoringStartup);
|
|
71
|
+
export { PredictiveStudioScoringStartup };
|
|
72
|
+
//# sourceMappingURL=startup-register.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"startup-register.js","sourceRoot":"","sources":["../../src/scoring/startup-register.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;;;;;;;AAEH,OAAO,EAAmC,WAAW,EAAE,kBAAkB,EAAY,MAAM,sBAAsB,CAAC;AAClH,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAEvD,OAAO,EAAE,0BAA0B,EAAE,MAAM,YAAY,CAAC;AACxD,OAAO,EAAE,8BAA8B,EAAE,MAAM,0BAA0B,CAAC;AAE1E;;;;;;;;GAQG;AAII,IAAM,8BAA8B,GAApC,MAAM,8BAA+B,SAAQ,aAA6C;IAC/F,iHAAiH;IAC1G,MAAM,KAAK,QAAQ;QACxB,OAAO,KAAK,CAAC,WAAW,EAAkC,CAAC;IAC7D,CAAC;IAED;;;;;;;;OAQG;IACI,KAAK,CAAC,aAAa,CAAC,YAAuB,EAAE,SAA6B;QAC/E,0BAA0B,CAAC,8BAA8B,EAAE,CAAC,CAAC;QAC7D,2FAA2F;QAC3F,WAAW,CAAC;YACV,OAAO,EAAE,mGAAmG;YAC5G,WAAW,EAAE,IAAI;SAClB,CAAC,CAAC;IACL,CAAC;CACF,CAAA;AAvBY,8BAA8B;IAH1C,kBAAkB,CAAC;QAClB,WAAW,EAAE,2DAA2D;KACzE,CAAC;GACW,8BAA8B,CAuB1C"}
|