@memberjunction/record-set-processor 6.2.0-edge.4 → 6.2.0-edge.5
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 +36 -1
- package/dist/RecordProcessExecutor.d.ts +29 -15
- package/dist/RecordProcessExecutor.d.ts.map +1 -1
- package/dist/RecordProcessExecutor.js +59 -62
- package/dist/RecordProcessExecutor.js.map +1 -1
- package/dist/RecordSetProcessor.d.ts +9 -0
- package/dist/RecordSetProcessor.d.ts.map +1 -1
- package/dist/RecordSetProcessor.js +140 -81
- package/dist/RecordSetProcessor.js.map +1 -1
- package/dist/index.d.ts +0 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -4
- package/dist/index.js.map +1 -1
- package/dist/operations/RecordProcessControlOperations.d.ts.map +1 -1
- package/dist/operations/RecordProcessControlOperations.js +9 -7
- package/dist/operations/RecordProcessControlOperations.js.map +1 -1
- package/dist/processors/ActionRecordProcessor.js +2 -2
- package/dist/processors/AgentRecordProcessor.d.ts.map +1 -1
- package/dist/processors/AgentRecordProcessor.js +5 -2
- package/dist/processors/AgentRecordProcessor.js.map +1 -1
- package/dist/processors/FieldRulesProcessor.d.ts +8 -7
- package/dist/processors/FieldRulesProcessor.d.ts.map +1 -1
- package/dist/processors/FieldRulesProcessor.js +23 -13
- package/dist/processors/FieldRulesProcessor.js.map +1 -1
- package/dist/processors/WriteBackProcessor.d.ts +62 -2
- package/dist/processors/WriteBackProcessor.d.ts.map +1 -1
- package/dist/processors/WriteBackProcessor.js +134 -58
- package/dist/processors/WriteBackProcessor.js.map +1 -1
- package/dist/trackers/GenericProcessRunTracker.d.ts.map +1 -1
- package/dist/trackers/GenericProcessRunTracker.js +5 -0
- package/dist/trackers/GenericProcessRunTracker.js.map +1 -1
- package/dist/watermark/WatermarkService.d.ts +62 -24
- package/dist/watermark/WatermarkService.d.ts.map +1 -1
- package/dist/watermark/WatermarkService.js +123 -70
- package/dist/watermark/WatermarkService.js.map +1 -1
- package/dist/writeBack.d.ts +358 -42
- package/dist/writeBack.d.ts.map +1 -1
- package/dist/writeBack.js +848 -208
- package/dist/writeBack.js.map +1 -1
- package/package.json +16 -17
- package/dist/feature-pipeline-drivers/BaseFeaturePipelineDriver.d.ts +0 -92
- package/dist/feature-pipeline-drivers/BaseFeaturePipelineDriver.d.ts.map +0 -1
- package/dist/feature-pipeline-drivers/BaseFeaturePipelineDriver.js +0 -26
- package/dist/feature-pipeline-drivers/BaseFeaturePipelineDriver.js.map +0 -1
- package/dist/feature-pipeline-drivers/DecisionFeaturePipelineDriver.d.ts +0 -79
- package/dist/feature-pipeline-drivers/DecisionFeaturePipelineDriver.d.ts.map +0 -1
- package/dist/feature-pipeline-drivers/DecisionFeaturePipelineDriver.js +0 -257
- package/dist/feature-pipeline-drivers/DecisionFeaturePipelineDriver.js.map +0 -1
- package/dist/feature-pipeline-drivers/LLMFeaturePipelineDriver.d.ts +0 -23
- package/dist/feature-pipeline-drivers/LLMFeaturePipelineDriver.d.ts.map +0 -1
- package/dist/feature-pipeline-drivers/LLMFeaturePipelineDriver.js +0 -85
- package/dist/feature-pipeline-drivers/LLMFeaturePipelineDriver.js.map +0 -1
- package/dist/processors/FeaturePipelineEscalation.d.ts +0 -155
- package/dist/processors/FeaturePipelineEscalation.d.ts.map +0 -1
- package/dist/processors/FeaturePipelineEscalation.js +0 -208
- package/dist/processors/FeaturePipelineEscalation.js.map +0 -1
- package/dist/processors/InferProcessor.d.ts +0 -306
- package/dist/processors/InferProcessor.d.ts.map +0 -1
- package/dist/processors/InferProcessor.js +0 -1210
- package/dist/processors/InferProcessor.js.map +0 -1
|
@@ -1,208 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Escalation for Decision Feature Pipelines (§3.6 rule 8, in bulk). A record the decision
|
|
3
|
-
* model answers below the spec's `Escalation.BelowConfidence` floor is re-run through an LLM Feature
|
|
4
|
-
* Pipeline, and that pipeline's answer replaces the decision's.
|
|
5
|
-
*
|
|
6
|
-
* {@link FeaturePipelineEscalator} loads and checks the escalation target once per run, and runs the
|
|
7
|
-
* records that escalate through the target's normal batch path, in the target's own context. Each
|
|
8
|
-
* pipeline caches only its own answers: the target's Dedup Cache holds the LLM answers, and the Decision
|
|
9
|
-
* pipeline's holds only the answers its decision model gave with confidence. `InferProcessor` decides
|
|
10
|
-
* which records escalate, and records their final answers in `MJ: Feature Values`.
|
|
11
|
-
*
|
|
12
|
-
* @module @memberjunction/record-set-processor
|
|
13
|
-
*/
|
|
14
|
-
import { FindEscalationTargetRowProblem, FindEscalationTargetSpecProblem, } from '@memberjunction/feature-pipelines';
|
|
15
|
-
/**
|
|
16
|
-
* Escalates a Decision pipeline's borderline records to an LLM Feature Pipeline. One instance serves one
|
|
17
|
-
* processor instance, which is one run, so the target is loaded and checked once per run.
|
|
18
|
-
*/
|
|
19
|
-
export class FeaturePipelineEscalator {
|
|
20
|
-
/**
|
|
21
|
-
* @param settings - The Decision pipeline's `Escalation` settings.
|
|
22
|
-
* @param decisionOutputs - The Decision pipeline's outputs: each one's confidence is checked, and the target must produce each one.
|
|
23
|
-
* @param buildTarget - Builds the target's processor from its row, as `RecordProcessExecutor` does.
|
|
24
|
-
*/
|
|
25
|
-
constructor(settings, decisionOutputs, buildTarget) {
|
|
26
|
-
this.settings = settings;
|
|
27
|
-
this.decisionOutputs = decisionOutputs;
|
|
28
|
-
this.buildTarget = buildTarget;
|
|
29
|
-
}
|
|
30
|
-
/** The `MJ: Record Processes` ID of the LLM pipeline records escalate to. */
|
|
31
|
-
get PipelineID() {
|
|
32
|
-
return this.settings.PipelineID;
|
|
33
|
-
}
|
|
34
|
-
/** The confidence floor. */
|
|
35
|
-
get BelowConfidence() {
|
|
36
|
-
return this.settings.BelowConfidence;
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* The outputs whose confidence is below the floor, or missing. Any one of them escalates the whole
|
|
40
|
-
* record; an empty list means the decision stands.
|
|
41
|
-
*/
|
|
42
|
-
BelowFloor(confidence) {
|
|
43
|
-
const below = [];
|
|
44
|
-
for (const output of this.decisionOutputs) {
|
|
45
|
-
const value = confidence?.[output.Name];
|
|
46
|
-
if (typeof value !== 'number' || !Number.isFinite(value)) {
|
|
47
|
-
below.push({ OutputName: output.Name });
|
|
48
|
-
}
|
|
49
|
-
else if (value < this.settings.BelowConfidence) {
|
|
50
|
-
below.push({ OutputName: output.Name, Confidence: value });
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
return below;
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* Runs the records through the target together, through its normal batch path. Every request gets an
|
|
57
|
-
* outcome. When the target cannot be loaded or used, every request fails, naming the pipeline and why.
|
|
58
|
-
*/
|
|
59
|
-
async Escalate(requests, context) {
|
|
60
|
-
const outcomes = new Map();
|
|
61
|
-
if (requests.length === 0) {
|
|
62
|
-
return outcomes;
|
|
63
|
-
}
|
|
64
|
-
const resolution = await this.resolveTargetOrError(context, context.entityID ?? requests[0].Record.EntityID);
|
|
65
|
-
if ('ErrorMessage' in resolution) {
|
|
66
|
-
for (const request of requests) {
|
|
67
|
-
outcomes.set(request.Record.RecordID, { ErrorMessage: `${this.escalationReason(request.BelowFloor)}; ${resolution.ErrorMessage}` });
|
|
68
|
-
}
|
|
69
|
-
return outcomes;
|
|
70
|
-
}
|
|
71
|
-
const results = await this.runTarget(resolution, requests, context);
|
|
72
|
-
for (const request of requests) {
|
|
73
|
-
outcomes.set(request.Record.RecordID, this.toOutcome(request, results.get(request.Record.RecordID), resolution));
|
|
74
|
-
}
|
|
75
|
-
return outcomes;
|
|
76
|
-
}
|
|
77
|
-
/** Why a record escalated, for its failure message. */
|
|
78
|
-
escalationReason(belowFloor) {
|
|
79
|
-
return `Decision confidence below ${this.settings.BelowConfidence} (${DescribeBelowFloor(belowFloor)})`;
|
|
80
|
-
}
|
|
81
|
-
/** Loads and checks the target once per instance; every later call shares the result, success or failure. */
|
|
82
|
-
async resolveTarget(context, entityID) {
|
|
83
|
-
this.targetResolution ??= this.loadTarget(context, entityID);
|
|
84
|
-
return this.targetResolution;
|
|
85
|
-
}
|
|
86
|
-
/** Runs {@link resolveTarget}, turning a failure into the message each escalating record fails with. */
|
|
87
|
-
async resolveTargetOrError(context, entityID) {
|
|
88
|
-
try {
|
|
89
|
-
return await this.resolveTarget(context, entityID);
|
|
90
|
-
}
|
|
91
|
-
catch (e) {
|
|
92
|
-
return { ErrorMessage: e instanceof Error ? e.message : String(e) };
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
/** Loads the target row, checks it, builds its processor and checks its spec. */
|
|
96
|
-
async loadTarget(context, entityID) {
|
|
97
|
-
const row = await this.loadTargetRow(context);
|
|
98
|
-
const label = `Escalation pipeline '${row.Name}' (${row.ID})`;
|
|
99
|
-
const rowProblem = FindEscalationTargetRowProblem(row, entityID);
|
|
100
|
-
if (rowProblem) {
|
|
101
|
-
throw new Error(`${label} ${rowProblem}.`);
|
|
102
|
-
}
|
|
103
|
-
const processor = this.buildTargetProcessor(row, context, label);
|
|
104
|
-
const specProblem = FindEscalationTargetSpecProblem(processor.Spec, this.decisionOutputs);
|
|
105
|
-
if (specProblem) {
|
|
106
|
-
throw new Error(`${label} ${specProblem}.`);
|
|
107
|
-
}
|
|
108
|
-
// The Decision pipeline records each escalated record's final answer, so the target records none
|
|
109
|
-
processor.WritesHistory = false;
|
|
110
|
-
return { Processor: processor, ID: row.ID, Name: row.Name };
|
|
111
|
-
}
|
|
112
|
-
/** Loads the target's `MJ: Record Processes` row through the run's provider. */
|
|
113
|
-
async loadTargetRow(context) {
|
|
114
|
-
const pipelineID = this.settings.PipelineID;
|
|
115
|
-
const row = await context.provider.GetEntityObject('MJ: Record Processes', context.contextUser);
|
|
116
|
-
const loaded = await row.Load(pipelineID);
|
|
117
|
-
if (!loaded) {
|
|
118
|
-
throw new Error(`Escalation pipeline '${pipelineID}' was not found in MJ: Record Processes.`);
|
|
119
|
-
}
|
|
120
|
-
return row;
|
|
121
|
-
}
|
|
122
|
-
/** Builds the target's processor, naming the pipeline when it cannot be built. */
|
|
123
|
-
buildTargetProcessor(row, context, label) {
|
|
124
|
-
try {
|
|
125
|
-
return this.buildTarget(row, context.provider);
|
|
126
|
-
}
|
|
127
|
-
catch (e) {
|
|
128
|
-
throw new Error(`${label} could not be built: ${e instanceof Error ? e.message : String(e)}`);
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
/**
|
|
132
|
-
* Runs the requests' records through the target's batch path, in the target's own context: the run's
|
|
133
|
-
* context with `recordProcessID` set to the target pipeline, so the target's Dedup Cache lookups and
|
|
134
|
-
* writes use its own entries. A thrown error fails each of the records.
|
|
135
|
-
*/
|
|
136
|
-
async runTarget(target, requests, context) {
|
|
137
|
-
const targetContext = { ...context, recordProcessID: target.ID };
|
|
138
|
-
try {
|
|
139
|
-
return await target.Processor.ProcessBatch(requests.map((r) => r.Record), targetContext);
|
|
140
|
-
}
|
|
141
|
-
catch (e) {
|
|
142
|
-
const message = e instanceof Error ? e.message : String(e);
|
|
143
|
-
return new Map(requests.map((r) => [r.Record.RecordID, { Status: 'Failed', ErrorMessage: message }]));
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
/** Turns the target's result for one record into its outcome. */
|
|
147
|
-
toOutcome(request, result, target) {
|
|
148
|
-
if (!result || result.Status !== 'Succeeded') {
|
|
149
|
-
return {
|
|
150
|
-
ErrorMessage: DescribeEscalationFailure(this.escalationReason(request.BelowFloor), target.Name, result?.ErrorMessage ?? 'it returned no result'),
|
|
151
|
-
AIPromptRunID: result?.AIPromptRunID,
|
|
152
|
-
};
|
|
153
|
-
}
|
|
154
|
-
return {
|
|
155
|
-
Payload: result.ResultPayload,
|
|
156
|
-
TargetOutputs: target.Processor.Spec?.Outputs ?? [],
|
|
157
|
-
PromptID: target.Processor.PromptID,
|
|
158
|
-
AIPromptRunID: result.AIPromptRunID,
|
|
159
|
-
PromptVersionHash: result.PromptVersionHash,
|
|
160
|
-
ConstraintHash: target.Processor.ConstraintHash,
|
|
161
|
-
FeatureValueCacheID: result.FeatureValueCacheID,
|
|
162
|
-
Note: BuildEscalationNote(target.Name, this.settings.BelowConfidence, request.BelowFloor, result.ResultPayload),
|
|
163
|
-
EscalationReason: this.escalationReason(request.BelowFloor),
|
|
164
|
-
PipelineName: target.Name,
|
|
165
|
-
SupersededNote: BuildSupersededDecisionNote(target.Name, this.settings.BelowConfidence, request.BelowFloor),
|
|
166
|
-
};
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
/** The outputs below the floor, for a message: `Seniority 0.42, IsVIP none`. */
|
|
170
|
-
export function DescribeBelowFloor(belowFloor) {
|
|
171
|
-
return belowFloor
|
|
172
|
-
.map((b) => `${b.OutputName} ${b.Confidence === undefined ? 'none' : Number(b.Confidence.toFixed(4))}`)
|
|
173
|
-
.join(', ');
|
|
174
|
-
}
|
|
175
|
-
/**
|
|
176
|
-
* The history note for an escalated record: that it escalated, to which pipeline, and from what
|
|
177
|
-
* confidence. When the target's payload carries its own `reasoning`, it follows the note.
|
|
178
|
-
*/
|
|
179
|
-
export function BuildEscalationNote(pipelineName, floor, belowFloor, targetPayload) {
|
|
180
|
-
const note = `Escalated to LLM pipeline '${pipelineName}': decision confidence below ${floor} (${DescribeBelowFloor(belowFloor)}).`;
|
|
181
|
-
const reasoning = readReasoning(targetPayload);
|
|
182
|
-
return reasoning ? `${note}\n\n${reasoning}` : note;
|
|
183
|
-
}
|
|
184
|
-
/**
|
|
185
|
-
* Why an escalated record failed: why it escalated (`Decision confidence below 0.7 (IsVIP 0.4)`), and why
|
|
186
|
-
* its escalation to the named LLM pipeline failed.
|
|
187
|
-
*/
|
|
188
|
-
export function DescribeEscalationFailure(escalationReason, pipelineName, reason) {
|
|
189
|
-
return `${escalationReason}; escalation to LLM pipeline '${pipelineName}' failed: ${reason}`;
|
|
190
|
-
}
|
|
191
|
-
/**
|
|
192
|
-
* The reasoning of the history row that records a superseded decision. That row carries the decision
|
|
193
|
-
* model's prompt run and its confidence, with no values, so the process run accounts for both model calls
|
|
194
|
-
* an escalated record made; the escalated answer is the record's value.
|
|
195
|
-
*/
|
|
196
|
-
export function BuildSupersededDecisionNote(pipelineName, floor, belowFloor) {
|
|
197
|
-
return (`Superseded: decision confidence below ${floor} (${DescribeBelowFloor(belowFloor)}), so the record escalated to ` +
|
|
198
|
-
`LLM pipeline '${pipelineName}', whose answer is the record's value. This row records the decision model's prompt run.`);
|
|
199
|
-
}
|
|
200
|
-
/** The `reasoning` a payload carries, when it is a non-empty string. */
|
|
201
|
-
function readReasoning(payload) {
|
|
202
|
-
if (typeof payload !== 'object' || payload === null || !('reasoning' in payload)) {
|
|
203
|
-
return undefined;
|
|
204
|
-
}
|
|
205
|
-
const reasoning = payload.reasoning;
|
|
206
|
-
return typeof reasoning === 'string' && reasoning.trim().length > 0 ? reasoning : undefined;
|
|
207
|
-
}
|
|
208
|
-
//# sourceMappingURL=FeaturePipelineEscalation.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"FeaturePipelineEscalation.js","sourceRoot":"","sources":["../../src/processors/FeaturePipelineEscalation.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAKH,OAAO,EAGH,8BAA8B,EAC9B,+BAA+B,GAClC,MAAM,mCAAmC,CAAC;AAqF3C;;;GAGG;AACH,MAAM,OAAO,wBAAwB;IAIjC;;;;OAIG;IACH,YACqB,QAA2C,EAC3C,eAAoC,EACpC,WAAoC;QAFpC,aAAQ,GAAR,QAAQ,CAAmC;QAC3C,oBAAe,GAAf,eAAe,CAAqB;QACpC,gBAAW,GAAX,WAAW,CAAyB;IACtD,CAAC;IAEJ,6EAA6E;IAC7E,IAAW,UAAU;QACjB,OAAO,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC;IACpC,CAAC;IAED,4BAA4B;IAC5B,IAAW,eAAe;QACtB,OAAO,IAAI,CAAC,QAAQ,CAAC,eAAe,CAAC;IACzC,CAAC;IAED;;;OAGG;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AAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC;AAChG,CAAC"}
|
|
@@ -1,306 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Infer processor — for each record, runs an AI Prompt over the record's data and
|
|
3
|
-
* returns the structured result as the record's `ResultPayload`. Write-back is NOT done here: the
|
|
4
|
-
* `WriteBackProcessor` wrapper (added by `RecordProcessExecutor` when an OutputMapping is set)
|
|
5
|
-
* applies the Record Process's OutputMapping uniformly across Action / Agent / Infer work types.
|
|
6
|
-
*
|
|
7
|
-
* Supports DataFeatureSpec context (EntityDocumentID template rendering with __Parent context,
|
|
8
|
-
* QueryID parameterized execution, Field projections), Layer-1 constraint injection, Layer-2
|
|
9
|
-
* constraint validation with OnViolation policies, and lifecycle hooks (P1-6). A Decision pipeline
|
|
10
|
-
* whose spec sets `Escalation` re-runs its below-floor records through an LLM pipeline
|
|
11
|
-
* (see `FeaturePipelineEscalation`).
|
|
12
|
-
*
|
|
13
|
-
* @module @memberjunction/record-set-processor
|
|
14
|
-
*/
|
|
15
|
-
import { type IMetadataProvider } from '@memberjunction/core';
|
|
16
|
-
import { type MJRecordProcessEntity } from '@memberjunction/core-entities';
|
|
17
|
-
import { AIPromptParams, type AIPromptRunResult, type MJAIPromptEntityExtended } from '@memberjunction/ai-core-plus';
|
|
18
|
-
import { IRecordProcessor, RecordProcessorContext, RecordRef, RecordResult } from '@memberjunction/record-set-processor-base';
|
|
19
|
-
import { DataFeatureSpec, DataFeatureOutput, type CacheKeyResult } from '@memberjunction/feature-pipelines';
|
|
20
|
-
import type { OutputMappingConfig } from '../writeBack.js';
|
|
21
|
-
import { BaseFeaturePipelineDriver } from '../feature-pipeline-drivers/BaseFeaturePipelineDriver.js';
|
|
22
|
-
/**
|
|
23
|
-
* Runs an AI Prompt per record and returns its structured output (write-back is the wrapper's job).
|
|
24
|
-
* A pipeline whose spec sets `Escalation` computes a whole batch before recording any of it, so its batch
|
|
25
|
-
* path does not call {@link ProcessRecord} once per record: an extension that overrides `ProcessRecord`
|
|
26
|
-
* does not see those records.
|
|
27
|
-
*/
|
|
28
|
-
export declare class InferProcessor implements IRecordProcessor {
|
|
29
|
-
protected readonly promptID: string;
|
|
30
|
-
protected readonly inputMapping?: Record<string, string>;
|
|
31
|
-
protected readonly spec?: DataFeatureSpec;
|
|
32
|
-
/** The driver resolution, started on first use and shared by every record this processor runs. */
|
|
33
|
-
private driverResolution?;
|
|
34
|
-
/** The escalation of below-floor decisions, created on first use when the spec has `Escalation`. */
|
|
35
|
-
private _escalator?;
|
|
36
|
-
/** How many records this processor has escalated. */
|
|
37
|
-
private escalatedRecordCount;
|
|
38
|
-
/**
|
|
39
|
-
* Whether this processor writes `MJ: Feature Values` history rows. On for every pipeline run. A
|
|
40
|
-
* Decision pipeline turns it off on its escalation target, because it records the final answers of
|
|
41
|
-
* the records it escalates itself.
|
|
42
|
-
*/
|
|
43
|
-
WritesHistory: boolean;
|
|
44
|
-
/**
|
|
45
|
-
* @param promptID - The `MJ: AI Prompts` ID to run for each record.
|
|
46
|
-
* @param inputMapping - Optional mapping shaping the data passed to the prompt (default: `{ record }`).
|
|
47
|
-
* @param spec - Optional DataFeatureSpec defining outputs, constraints, and caching policy.
|
|
48
|
-
*/
|
|
49
|
-
constructor(promptID: string, inputMapping?: Record<string, string>, spec?: DataFeatureSpec);
|
|
50
|
-
/**
|
|
51
|
-
* Builds the processor for an Infer Feature Pipeline from its `MJ: Record Processes` row: parses and
|
|
52
|
-
* validates the DataFeatureSpec in `Configuration` (and its materialization targets), and creates the
|
|
53
|
-
* spec's `ProcessorExtensionKey` subclass when it names one. `RecordProcessExecutor` builds every
|
|
54
|
-
* Infer pipeline this way, and so does a Decision pipeline's escalation to an LLM pipeline.
|
|
55
|
-
*
|
|
56
|
-
* @param rp - The pipeline's row (WorkType `Infer`).
|
|
57
|
-
* @param provider - The provider whose metadata the materialization targets are checked against (default: the global one).
|
|
58
|
-
* @throws Error when the row has no PromptID, its Configuration is not valid JSON, its spec or
|
|
59
|
-
* materialization targets are invalid, or its ProcessorExtensionKey is not registered.
|
|
60
|
-
*/
|
|
61
|
-
static FromRecordProcess(rp: MJRecordProcessEntity, provider?: IMetadataProvider): InferProcessor;
|
|
62
|
-
/** Parses and validates the DataFeatureSpec in an Infer pipeline row's `Configuration`; undefined when it has none. */
|
|
63
|
-
private static parseSpec;
|
|
64
|
-
/** The pipeline's DataFeatureSpec, when it has one. */
|
|
65
|
-
get Spec(): DataFeatureSpec | undefined;
|
|
66
|
-
/** The `MJ: AI Prompts` ID this processor runs for each record. */
|
|
67
|
-
get PromptID(): string;
|
|
68
|
-
/** The hash that versions this pipeline's output constraints, as its Dedup Cache and history record it. */
|
|
69
|
-
get ConstraintHash(): string;
|
|
70
|
-
/**
|
|
71
|
-
* How many records this processor has escalated to its spec's `Escalation` pipeline. A processor
|
|
72
|
-
* serves one run, so this is the run's count. It counts every record whose answer was escalated,
|
|
73
|
-
* including the records that shared a Dedup Cache key with one, and the escalations that failed.
|
|
74
|
-
*/
|
|
75
|
-
get EscalatedRecordCount(): number;
|
|
76
|
-
ProcessRecord(record: RecordRef, context: RecordProcessorContext, options?: {
|
|
77
|
-
skipLookup?: boolean;
|
|
78
|
-
keyInfo?: CacheKeyResult;
|
|
79
|
-
}): Promise<RecordResult>;
|
|
80
|
-
/** Runs the driver on a key group's first record, and notes which outputs, if any, are below the escalation floor. */
|
|
81
|
-
private computeSample;
|
|
82
|
-
/**
|
|
83
|
-
* Finishes a computed sample: a driver failure fails it, a below-floor decision takes its escalation's
|
|
84
|
-
* outcome, and any other answer is validated, cached and recorded.
|
|
85
|
-
*/
|
|
86
|
-
private finalizeSample;
|
|
87
|
-
/**
|
|
88
|
-
* Validates a driver's outputs against the constraints (applying each OnViolation policy), stores
|
|
89
|
-
* them in the Dedup Cache, and records their history.
|
|
90
|
-
*/
|
|
91
|
-
private finalizeComputed;
|
|
92
|
-
/**
|
|
93
|
-
* Two-phase batch execution (P1-7c). Resolves distinct keys across the batch first,
|
|
94
|
-
* checks the dedup cache in one batch query, executes LLM prompts ONCE per distinct key,
|
|
95
|
-
* and fans results back across all matching rows.
|
|
96
|
-
*/
|
|
97
|
-
ProcessBatch(records: RecordRef[], context: RecordProcessorContext): Promise<Map<string, RecordResult>>;
|
|
98
|
-
/** Fails every record with one message. */
|
|
99
|
-
private failEvery;
|
|
100
|
-
/**
|
|
101
|
-
* Resolves what one processing pass needs: the prompt, the driver, and the hashes that version the
|
|
102
|
-
* pipeline's answers. Returns why the pipeline cannot run instead, when the prompt is missing or the
|
|
103
|
-
* driver cannot be resolved.
|
|
104
|
-
*/
|
|
105
|
-
private resolveRunState;
|
|
106
|
-
/**
|
|
107
|
-
* Gives every record in a key group its sample's result. The other records get a copy of it, and their
|
|
108
|
-
* own history row from `history` (which is absent when the sample failed).
|
|
109
|
-
*/
|
|
110
|
-
private fanOutGroupResult;
|
|
111
|
-
/** The history a key group's other records get from its sample's computed result: none when it failed. */
|
|
112
|
-
private missFanOutHistory;
|
|
113
|
-
/**
|
|
114
|
-
* The escalation of below-floor decisions, when the spec is a Decision pipeline's and has `Escalation`;
|
|
115
|
-
* created once. `ValidateSpec` already refuses `Escalation` on any other type, but a processor built
|
|
116
|
-
* directly from a spec skips it, and an LLM pipeline returns no confidence, so every record would escalate.
|
|
117
|
-
*/
|
|
118
|
-
private get escalator();
|
|
119
|
-
/** A successful decision's outputs below the escalation floor; empty when the pipeline does not escalate. */
|
|
120
|
-
private belowFloor;
|
|
121
|
-
/** An uncached batch of a pipeline that escalates: every record is its own group, computed together. */
|
|
122
|
-
private processUncachedBatchWithEscalation;
|
|
123
|
-
/**
|
|
124
|
-
* Computes key groups for a pipeline that escalates. The driver answers each group's first record; the
|
|
125
|
-
* below-floor answers escalate together, in one pass through the target; then each group's final
|
|
126
|
-
* answer is recorded once and fanned out to its records.
|
|
127
|
-
*/
|
|
128
|
-
private computeGroupsWithEscalation;
|
|
129
|
-
/**
|
|
130
|
-
* Escalates the below-floor samples together, then finalizes every sample, in order. The escalations are
|
|
131
|
-
* counted and logged by each escalated sample's final result, so an escalated answer that fails this
|
|
132
|
-
* pipeline's own constraints counts as failed.
|
|
133
|
-
*/
|
|
134
|
-
private finalizeSamples;
|
|
135
|
-
/**
|
|
136
|
-
* Escalates, together, the samples whose decision was below the floor. Returns each escalated sample's
|
|
137
|
-
* outcome by record ID; empty when none escalated.
|
|
138
|
-
*/
|
|
139
|
-
private escalateBelowFloor;
|
|
140
|
-
/**
|
|
141
|
-
* Adds a pass's escalated records (each group's records, fan-out included) to the run's count, and logs
|
|
142
|
-
* it, counting as failed each escalated group whose final result failed.
|
|
143
|
-
*/
|
|
144
|
-
private countEscalations;
|
|
145
|
-
/**
|
|
146
|
-
* Finishes a record whose decision was below the escalation floor. A failed escalation fails the record
|
|
147
|
-
* with both reasons, and the low-confidence decision is never cached, recorded or returned. A successful
|
|
148
|
-
* one replaces the decision: the target's validated payload, in this pipeline's shape, is recorded in
|
|
149
|
-
* history under the target's prompt, prompt run, hashes and cache entry, with the escalation note as the
|
|
150
|
-
* history row's reasoning, and the record's result names the target's prompt with that prompt run and
|
|
151
|
-
* hash, so write-back's `$run` provenance describes one run. It is not written to this pipeline's Dedup
|
|
152
|
-
* Cache, which holds only answers the decision model gave with confidence; the target caches its own answers.
|
|
153
|
-
*
|
|
154
|
-
* The target validated its answer against its own constraints only, and those may be looser than this
|
|
155
|
-
* pipeline's (a wider enum, or none). So the answer, in this pipeline's shape, is validated again against
|
|
156
|
-
* this pipeline's own output constraints, with each output's OnViolation policy, exactly as a decision's
|
|
157
|
-
* answer is: `fail` fails the record with both reasons, `null` and `coerce-to-other` apply. A value
|
|
158
|
-
* outside the Decision pipeline's domain is never recorded or written back.
|
|
159
|
-
*
|
|
160
|
-
* The record paid for two model calls, and `MJ: Feature Values` is what links a prompt run to the process
|
|
161
|
-
* run. So before the answer's row, one more history row records the superseded decision: its prompt run,
|
|
162
|
-
* prompt, hashes and confidence, with no values (the low-confidence answer is never recorded as a value)
|
|
163
|
-
* and a reasoning that says it was superseded. It is written once per decision call: a key group's other
|
|
164
|
-
* records get only the answer's row.
|
|
165
|
-
*/
|
|
166
|
-
private finalizeEscalated;
|
|
167
|
-
/**
|
|
168
|
-
* Records the history row of a decision an escalation superseded: the decision model's prompt run and
|
|
169
|
-
* confidence under this pipeline's prompt and hashes, no values, and a reasoning saying it was superseded.
|
|
170
|
-
* Nothing is recorded when the decision has no prompt run to link.
|
|
171
|
-
*/
|
|
172
|
-
private recordSupersededDecision;
|
|
173
|
-
/**
|
|
174
|
-
* The escalated payload in this pipeline's shape: the target's validated payload, with each output's
|
|
175
|
-
* value also placed at this pipeline's Ref for it, so write-back and history (which read this
|
|
176
|
-
* pipeline's Refs) find the escalated values. When both pipelines use the same Refs, it is the target's
|
|
177
|
-
* payload as is.
|
|
178
|
-
*/
|
|
179
|
-
private projectEscalatedPayload;
|
|
180
|
-
/**
|
|
181
|
-
* Computes a deterministic SHA-256 hash representing the prompt version and constraint instructions.
|
|
182
|
-
* A pipeline type other than `LLM` is part of the hash, so switching a pipeline's type never serves
|
|
183
|
-
* the old type's cached values. An LLM pipeline's hash is unchanged by the type's introduction.
|
|
184
|
-
* So are the `Escalation` settings: the floor decides which decision answers are confident enough to
|
|
185
|
-
* keep, so changing it (or the target) invalidates the answers cached under the old settings. A
|
|
186
|
-
* pipeline without `Escalation` keeps its hash.
|
|
187
|
-
*/
|
|
188
|
-
protected computePromptVersionHash(prompt: MJAIPromptEntityExtended, spec?: DataFeatureSpec): string;
|
|
189
|
-
/** The pipeline type's part of the prompt version hash: empty when the type is absent or `LLM`. */
|
|
190
|
-
private pipelineTypeHashSuffix;
|
|
191
|
-
/** The escalation settings' part of the prompt version hash: empty without `Escalation`. */
|
|
192
|
-
private escalationHashSuffix;
|
|
193
|
-
/** Computes a deterministic SHA-256 hash representing the output constraints. */
|
|
194
|
-
protected computeConstraintHash(spec?: DataFeatureSpec): string;
|
|
195
|
-
/**
|
|
196
|
-
* Records historical audit rows in MJ: Feature Values for all outputs on a record.
|
|
197
|
-
* `outputConfidence` (from a driver that produces confidence) sets each output's confidence by
|
|
198
|
-
* output name, ahead of the single `confidence`. `omitValues` records every output's value as null,
|
|
199
|
-
* whatever the payload holds (a superseded decision's row). Records nothing when {@link WritesHistory} is off.
|
|
200
|
-
*/
|
|
201
|
-
protected recordFeatureValuesHistory(params: {
|
|
202
|
-
record: RecordRef;
|
|
203
|
-
context: RecordProcessorContext;
|
|
204
|
-
payload: unknown;
|
|
205
|
-
omitValues?: boolean;
|
|
206
|
-
reasoning?: string | null;
|
|
207
|
-
confidence?: number | null;
|
|
208
|
-
outputConfidence?: Record<string, number>;
|
|
209
|
-
promptID?: string | null;
|
|
210
|
-
promptVersionHash?: string | null;
|
|
211
|
-
constraintHash?: string | null;
|
|
212
|
-
aiPromptRunID?: string | null;
|
|
213
|
-
featureValueCacheID?: string | null;
|
|
214
|
-
}): Promise<void>;
|
|
215
|
-
/**
|
|
216
|
-
* Computes the watermark basis hash for Checksum strategy:
|
|
217
|
-
* SHA-256 over canonical { promptData, promptVersionHash }.
|
|
218
|
-
*/
|
|
219
|
-
ComputeBasisHash(record: RecordRef, context: RecordProcessorContext): Promise<string>;
|
|
220
|
-
/**
|
|
221
|
-
* Resolves the driver for this pipeline's type, once per processor instance.
|
|
222
|
-
*
|
|
223
|
-
* The type is `DataFeatureSpec.PipelineType`, or `LLM` when absent. It is matched by name
|
|
224
|
-
* (case-insensitive, trimmed) against the `MJ: Feature Pipeline Types` catalog cached by
|
|
225
|
-
* `KnowledgeHubMetadataEngine`, and its `DriverClass` is created through the ClassFactory. `LLM`
|
|
226
|
-
* resolves to {@link LLMFeaturePipelineDriver} when the catalog has no `LLM` row, or cannot be read,
|
|
227
|
-
* so a database without the seed row keeps working. The driver's `ValidateOutputs` then runs once.
|
|
228
|
-
*
|
|
229
|
-
* @throws Error when the type is not in the catalog (and is not `LLM`), is not Active, names a
|
|
230
|
-
* DriverClass that is not registered, or cannot produce every output (naming each one).
|
|
231
|
-
*/
|
|
232
|
-
protected ResolveDriver(context: RecordProcessorContext): Promise<BaseFeaturePipelineDriver>;
|
|
233
|
-
/** Runs {@link ResolveDriver}, turning a resolution error into a message the caller fails the record with. */
|
|
234
|
-
private resolveDriverOrError;
|
|
235
|
-
/** Finds the pipeline's type in the catalog, creates its driver, and checks it can produce every output. */
|
|
236
|
-
private resolveDriverFromCatalog;
|
|
237
|
-
/**
|
|
238
|
-
* Looks the type up by name in the catalog. If the catalog cannot be read, `LLM` is treated as not
|
|
239
|
-
* found (and so still resolves); any other type fails, because only the catalog names its driver.
|
|
240
|
-
*/
|
|
241
|
-
private findPipelineType;
|
|
242
|
-
/** The driver for a type with no catalog row: `LLM` still runs; any other name is an error. */
|
|
243
|
-
private createDriverWithoutCatalogRow;
|
|
244
|
-
/** Creates an Active type's driver from its registered `DriverClass`. */
|
|
245
|
-
private createDriver;
|
|
246
|
-
/**
|
|
247
|
-
* The value lists of the pipeline's own entity (`context.entityID`), for the output check and the
|
|
248
|
-
* driver. Consults only that entity's fields, so a same-named field elsewhere is never read; undefined
|
|
249
|
-
* when the run names no entity or the provider does not know it.
|
|
250
|
-
*/
|
|
251
|
-
private buildFieldValuesLookup;
|
|
252
|
-
/** Fails when the driver cannot produce one or more of the spec's outputs, naming every one. */
|
|
253
|
-
private assertDriverProducesOutputs;
|
|
254
|
-
/** The driver's callbacks into this processor's overridable steps, so extensions keep working. */
|
|
255
|
-
private buildComputeHooks;
|
|
256
|
-
/** Lifecycle hook called before prompt data context is constructed. */
|
|
257
|
-
protected beforeBuildContext(record: RecordRef, ctx: RecordProcessorContext): Promise<void>;
|
|
258
|
-
/** Lifecycle hook called immediately before ExecutePrompt is invoked. */
|
|
259
|
-
protected beforePromptExecute(params: AIPromptParams, record: RecordRef, ctx: RecordProcessorContext): Promise<void>;
|
|
260
|
-
/** Lifecycle hook called after prompt execution returns successfully. Defaults to returning result.result. */
|
|
261
|
-
protected afterPromptExecute(result: AIPromptRunResult<unknown>, record: RecordRef, ctx: RecordProcessorContext): Promise<unknown>;
|
|
262
|
-
/**
|
|
263
|
-
* Layer 2 output validation hook. Evaluates outputs against declared constraints, applies OnViolation
|
|
264
|
-
* policies (fail, null, coerce-to-other), and builds the processed payload. `replacedOutputs` names
|
|
265
|
-
* the outputs whose value a `null` or `coerce-to-other` policy replaced.
|
|
266
|
-
*/
|
|
267
|
-
protected validateOutputs(outputs: DataFeatureOutput[], rawResult: unknown, record: RecordRef, ctx: RecordProcessorContext): Promise<{
|
|
268
|
-
valid: boolean;
|
|
269
|
-
payload?: unknown;
|
|
270
|
-
errorMessage?: string;
|
|
271
|
-
replacedOutputs?: string[];
|
|
272
|
-
}>;
|
|
273
|
-
/**
|
|
274
|
-
* The driver's per-output confidences, less those of outputs whose value the constraint check replaced:
|
|
275
|
-
* a confidence belongs to the value the model gave, not to a null or 'Other' written in its place.
|
|
276
|
-
* Undefined when none remain.
|
|
277
|
-
*/
|
|
278
|
-
private confidenceOfKeptValues;
|
|
279
|
-
/** Lifecycle hook to resolve a dedup cache key for this record. Default returns null (computed by cache service). */
|
|
280
|
-
protected resolveCacheKey(record: RecordRef, spec: DataFeatureSpec | undefined, ctx: RecordProcessorContext): Promise<string | null>;
|
|
281
|
-
/** Lifecycle hook called before write-back is executed on this record. */
|
|
282
|
-
beforeWriteBack(// case-violation-ok-legacy-back-compat: a subclass overrides this; a stub preserves CALLING the old name but not OVERRIDING it, and WriteBackProcessor also probes for it by string
|
|
283
|
-
mapping: OutputMappingConfig | undefined, result: unknown, record: RecordRef, ctx: RecordProcessorContext): Promise<void>;
|
|
284
|
-
/**
|
|
285
|
-
* Builds the data object passed to the prompt.
|
|
286
|
-
* Incorporates spec.Context (EntityDocumentID rendering, QueryID parameterized execution, Field filtering),
|
|
287
|
-
* input mapping, and Layer-1 constraint instructions.
|
|
288
|
-
*/
|
|
289
|
-
protected buildPromptData(record: RecordRef, ctx?: RecordProcessorContext): Promise<Record<string, unknown>>;
|
|
290
|
-
/** Extracts a plain field map from the record (BaseEntity → GetAll(), plain object → as-is). */
|
|
291
|
-
protected recordToPlain(record: RecordRef): Record<string, unknown>;
|
|
292
|
-
/**
|
|
293
|
-
* Ensures that every record in the batch has its full field data loaded on `record.Record`.
|
|
294
|
-
* If records only have primary keys (as yielded by source pagination), batch-fetches the
|
|
295
|
-
* full records via RunView in a single query per entity.
|
|
296
|
-
*/
|
|
297
|
-
protected ensureRecordsLoaded(records: RecordRef[], context: RecordProcessorContext): Promise<void>;
|
|
298
|
-
}
|
|
299
|
-
/**
|
|
300
|
-
* Sets a value at a dot-delimited path (e.g. 'a.b' or 'items[0].name') on an object,
|
|
301
|
-
* mutating the object in-place and creating intermediate objects or arrays as needed.
|
|
302
|
-
*/
|
|
303
|
-
export declare function SetNestedValue(obj: Record<string, unknown>, path: string, value: unknown): void;
|
|
304
|
-
/** @deprecated Use {@link SetNestedValue}. */
|
|
305
|
-
export declare function setNestedValue(obj: Record<string, unknown>, path: string, value: unknown): void;
|
|
306
|
-
//# sourceMappingURL=InferProcessor.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"InferProcessor.d.ts","sourceRoot":"","sources":["../../src/processors/InferProcessor.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAGH,OAAO,EAAE,KAAK,iBAAiB,EAAoD,MAAM,sBAAsB,CAAC;AAEhH,OAAO,EAAgE,KAAK,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AAEzI,OAAO,EAAE,cAAc,EAAE,KAAK,iBAAiB,EAAE,KAAK,wBAAwB,EAAE,MAAM,8BAA8B,CAAC;AACrH,OAAO,EACH,gBAAgB,EAChB,sBAAsB,EACtB,SAAS,EACT,YAAY,EACf,MAAM,2CAA2C,CAAC;AACnD,OAAO,EACH,eAAe,EACf,iBAAiB,EAIjB,KAAK,cAAc,EAWtB,MAAM,mCAAmC,CAAC;AAE3C,OAAO,KAAK,EAAE,mBAAmB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