@memberjunction/record-set-processor 6.2.0-edge.4 → 6.2.0-edge.6

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 (62) hide show
  1. package/README.md +36 -1
  2. package/dist/RecordProcessExecutor.d.ts +35 -17
  3. package/dist/RecordProcessExecutor.d.ts.map +1 -1
  4. package/dist/RecordProcessExecutor.js +79 -63
  5. package/dist/RecordProcessExecutor.js.map +1 -1
  6. package/dist/RecordSetProcessor.d.ts +15 -0
  7. package/dist/RecordSetProcessor.d.ts.map +1 -1
  8. package/dist/RecordSetProcessor.js +161 -81
  9. package/dist/RecordSetProcessor.js.map +1 -1
  10. package/dist/index.d.ts +0 -4
  11. package/dist/index.d.ts.map +1 -1
  12. package/dist/index.js +0 -4
  13. package/dist/index.js.map +1 -1
  14. package/dist/operations/RecordProcessControlOperations.d.ts.map +1 -1
  15. package/dist/operations/RecordProcessControlOperations.js +9 -7
  16. package/dist/operations/RecordProcessControlOperations.js.map +1 -1
  17. package/dist/processors/ActionRecordProcessor.d.ts.map +1 -1
  18. package/dist/processors/ActionRecordProcessor.js +6 -2
  19. package/dist/processors/ActionRecordProcessor.js.map +1 -1
  20. package/dist/processors/AgentRecordProcessor.d.ts.map +1 -1
  21. package/dist/processors/AgentRecordProcessor.js +5 -2
  22. package/dist/processors/AgentRecordProcessor.js.map +1 -1
  23. package/dist/processors/FieldRulesProcessor.d.ts +22 -7
  24. package/dist/processors/FieldRulesProcessor.d.ts.map +1 -1
  25. package/dist/processors/FieldRulesProcessor.js +24 -13
  26. package/dist/processors/FieldRulesProcessor.js.map +1 -1
  27. package/dist/processors/WriteBackProcessor.d.ts +62 -2
  28. package/dist/processors/WriteBackProcessor.d.ts.map +1 -1
  29. package/dist/processors/WriteBackProcessor.js +134 -58
  30. package/dist/processors/WriteBackProcessor.js.map +1 -1
  31. package/dist/trackers/GenericProcessRunTracker.d.ts.map +1 -1
  32. package/dist/trackers/GenericProcessRunTracker.js +22 -3
  33. package/dist/trackers/GenericProcessRunTracker.js.map +1 -1
  34. package/dist/watermark/WatermarkService.d.ts +62 -24
  35. package/dist/watermark/WatermarkService.d.ts.map +1 -1
  36. package/dist/watermark/WatermarkService.js +123 -70
  37. package/dist/watermark/WatermarkService.js.map +1 -1
  38. package/dist/writeBack.d.ts +358 -42
  39. package/dist/writeBack.d.ts.map +1 -1
  40. package/dist/writeBack.js +848 -208
  41. package/dist/writeBack.js.map +1 -1
  42. package/package.json +16 -17
  43. package/dist/feature-pipeline-drivers/BaseFeaturePipelineDriver.d.ts +0 -92
  44. package/dist/feature-pipeline-drivers/BaseFeaturePipelineDriver.d.ts.map +0 -1
  45. package/dist/feature-pipeline-drivers/BaseFeaturePipelineDriver.js +0 -26
  46. package/dist/feature-pipeline-drivers/BaseFeaturePipelineDriver.js.map +0 -1
  47. package/dist/feature-pipeline-drivers/DecisionFeaturePipelineDriver.d.ts +0 -79
  48. package/dist/feature-pipeline-drivers/DecisionFeaturePipelineDriver.d.ts.map +0 -1
  49. package/dist/feature-pipeline-drivers/DecisionFeaturePipelineDriver.js +0 -257
  50. package/dist/feature-pipeline-drivers/DecisionFeaturePipelineDriver.js.map +0 -1
  51. package/dist/feature-pipeline-drivers/LLMFeaturePipelineDriver.d.ts +0 -23
  52. package/dist/feature-pipeline-drivers/LLMFeaturePipelineDriver.d.ts.map +0 -1
  53. package/dist/feature-pipeline-drivers/LLMFeaturePipelineDriver.js +0 -85
  54. package/dist/feature-pipeline-drivers/LLMFeaturePipelineDriver.js.map +0 -1
  55. package/dist/processors/FeaturePipelineEscalation.d.ts +0 -155
  56. package/dist/processors/FeaturePipelineEscalation.d.ts.map +0 -1
  57. package/dist/processors/FeaturePipelineEscalation.js +0 -208
  58. package/dist/processors/FeaturePipelineEscalation.js.map +0 -1
  59. package/dist/processors/InferProcessor.d.ts +0 -306
  60. package/dist/processors/InferProcessor.d.ts.map +0 -1
  61. package/dist/processors/InferProcessor.js +0 -1210
  62. package/dist/processors/InferProcessor.js.map +0 -1
@@ -1,257 +0,0 @@
1
- /**
2
- * @fileoverview The `Decision` Feature Pipeline type's driver: runs the pipeline's prompt
3
- * on a typed decision model for each record, answering Likelihood, Choice, and Score questions
4
- * together in a single call via `AIDecisionRunner`.
5
- *
6
- * Produces calibrated per-output confidence scores for field targets, without model reasoning.
7
- *
8
- * Prompt-execution hooks (beforePromptExecute / afterPromptExecute) are LLM-specific and are not
9
- * called for Decision pipelines.
10
- *
11
- * NOTE ON CONFIDENCE & CACHING:
12
- * Direct computations by this driver produce per-output confidence scores returned in
13
- * {@link FeaturePipelineComputeSuccess.Confidence} and persisted to `MJ: Feature Values` history.
14
- * However, cache hits served from `MJ: Feature Value Cache` carry no confidence because the cache
15
- * table schema stores only input key hashes, prompt version hashes, and serialized output JSON;
16
- * it has no confidence column. Consumers should note that cached evaluations do not retain confidence.
17
- *
18
- * @module @memberjunction/record-set-processor
19
- */
20
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
21
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
22
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
23
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
24
- return c > 3 && r && Object.defineProperty(target, key, r), r;
25
- };
26
- import { RegisterClass, Canonicalize, UUIDsEqual, NormalizeUUID } from '@memberjunction/global';
27
- import { Metadata } from '@memberjunction/core';
28
- import { AIEngine } from '@memberjunction/aiengine';
29
- import { AIDecisionRunner, AIDecisionParams, } from '@memberjunction/ai-prompts';
30
- import { BuildEntityFieldValueLookup, DECISION_FEATURE_PIPELINE_CAPABILITIES, ResolveEnumChoices, } from '@memberjunction/feature-pipelines';
31
- import { BaseFeaturePipelineDriver, } from './BaseFeaturePipelineDriver.js';
32
- import { SetNestedValue } from '../processors/InferProcessor.js';
33
- /** The model type `AIDecisionRunner` requires, by name. */
34
- const DECISION_MODEL_TYPE = 'Decision';
35
- /**
36
- * Runs the pipeline's prompt on a typed decision model for each record, mapping outputs to
37
- * Likelihood, Choice, or Score questions and extracting calibrated confidence scores.
38
- */
39
- let DecisionFeaturePipelineDriver = class DecisionFeaturePipelineDriver extends BaseFeaturePipelineDriver {
40
- /** Supported constraint types (boolean, enum, numeric) and field targets; produces confidence, no reasoning. */
41
- get Capabilities() {
42
- return DECISION_FEATURE_PIPELINE_CAPABILITIES;
43
- }
44
- /**
45
- * Executes the Decision pipeline for a single record:
46
- * 1. Validates that the prompt runs on Decision models ({@link IsDecisionPrompt}).
47
- * 2. Renders the record state via `BeforeBuildContext` and `BuildPromptData`, canonicalizing it.
48
- * 3. Checks estimated state tokens against the strictest `Decision.MaxStateTokens` limit of the models the prompt may run on (fails if exceeded, never truncates).
49
- * 4. Builds typed decision questions (Likelihood, Choice, Score) from the spec's outputs.
50
- * 5. Executes the decision via `AIDecisionRunner.ExecuteDecision`.
51
- * 6. Maps answers back to output values (applying boolean constraint threshold and score rubric rescaling) and confidences.
52
- */
53
- async ComputeOutputs(request) {
54
- const { Record: record, Context: context, Prompt: prompt, Spec: spec, Hooks: hooks } = request;
55
- if (!this.IsDecisionPrompt(prompt)) {
56
- return {
57
- Success: false,
58
- ErrorMessage: `Prompt '${prompt?.Name ?? prompt?.ID}' is not a Decision prompt; Decision pipelines require a prompt whose model type is Decision, or that has no model type and a Decision model bound to it.`,
59
- AIPromptRunID: undefined,
60
- };
61
- }
62
- // Hook: beforeBuildContext
63
- await hooks.BeforeBuildContext(record, context);
64
- const promptData = await hooks.BuildPromptData(record, context);
65
- const serializedState = Canonicalize(promptData);
66
- const estimatedTokens = Math.ceil(serializedState.length / 4);
67
- const maxStateTokens = this.ResolveMaxStateTokens(prompt);
68
- if (maxStateTokens !== undefined && maxStateTokens > 0 && estimatedTokens > maxStateTokens) {
69
- return {
70
- Success: false,
71
- ErrorMessage: `Rendered state token estimate (${estimatedTokens} tokens, ~${serializedState.length} characters / 4) exceeds the model's Decision.MaxStateTokens limit of ${maxStateTokens}. Narrow Context.Fields or use a smaller entity document.`,
72
- AIPromptRunID: undefined,
73
- };
74
- }
75
- const questions = this.BuildQuestions(request);
76
- const params = new AIDecisionParams();
77
- params.prompt = prompt;
78
- params.contextUser = context.contextUser;
79
- params.State = serializedState;
80
- params.Questions = questions;
81
- const runner = this.CreateDecisionRunner();
82
- const result = await runner.ExecuteDecision(params);
83
- const aiPromptRunID = result.promptRun?.ID;
84
- if (!result.success) {
85
- return {
86
- Success: false,
87
- ErrorMessage: result.errorMessage ?? 'Decision execution failed',
88
- AIPromptRunID: aiPromptRunID,
89
- };
90
- }
91
- const { rawResult, confidence } = this.MapAnswers(spec?.Outputs ?? [], result.Answers);
92
- return {
93
- Success: true,
94
- RawResult: rawResult,
95
- Confidence: confidence,
96
- AIPromptRunID: aiPromptRunID,
97
- };
98
- }
99
- /**
100
- * Whether the prompt is meant for Decision models: its model type is Decision or, when it has none (so
101
- * `AIDecisionRunner` applies its own Decision floor), a Decision model is bound to it. Model types are
102
- * compared by ID. The prompt's name plays no part, so a prompt whose type is LLM is refused here, before
103
- * the record's state is rendered, whatever it is called.
104
- */
105
- IsDecisionPrompt(prompt) {
106
- const decisionTypeID = this.decisionModelTypeID();
107
- if (!prompt || !decisionTypeID) {
108
- return false;
109
- }
110
- if (prompt.AIModelTypeID) {
111
- return UUIDsEqual(prompt.AIModelTypeID, decisionTypeID);
112
- }
113
- return this.boundDecisionModels(prompt, decisionTypeID).length > 0;
114
- }
115
- /**
116
- * The strictest `Decision.MaxStateTokens` among the models the prompt may run on, or undefined when none
117
- * declares one. The runner picks the model per call, by credentials and failover, so the state is
118
- * checked against every model it may pick rather than against whichever binding is read first. Those
119
- * models are the Decision models bound to the prompt or, when none is bound, every active Decision model.
120
- */
121
- ResolveMaxStateTokens(prompt) {
122
- const limits = this.eligibleDecisionModels(prompt)
123
- .map((model) => AIEngine.Instance.GetEffectiveModelConfiguration(model.ID)?.Decision?.MaxStateTokens)
124
- .filter((limit) => typeof limit === 'number' && limit > 0);
125
- return limits.length > 0 ? Math.min(...limits) : undefined;
126
- }
127
- /** The ID of the model type `AIDecisionRunner` requires, matched by name as the runner matches it. */
128
- decisionModelTypeID() {
129
- const wanted = DECISION_MODEL_TYPE.toLowerCase();
130
- return AIEngine.Instance.ModelTypes.find((type) => type.Name?.trim().toLowerCase() === wanted)?.ID;
131
- }
132
- /** The active Decision models bound to the prompt through its active or preview `MJ: AI Prompt Models` rows. */
133
- boundDecisionModels(prompt, decisionTypeID) {
134
- return AIEngine.Instance.PromptModels
135
- .filter((binding) => UUIDsEqual(binding.PromptID, prompt.ID) && (binding.Status === 'Active' || binding.Status === 'Preview'))
136
- .map((binding) => AIEngine.Instance.ModelsByID.get(NormalizeUUID(binding.ModelID)))
137
- .filter((model) => model !== undefined && this.isActiveOfType(model, decisionTypeID));
138
- }
139
- /** The models the prompt may run on: its bound Decision models, or every active Decision model when none is bound. */
140
- eligibleDecisionModels(prompt) {
141
- const decisionTypeID = this.decisionModelTypeID();
142
- if (!decisionTypeID) {
143
- return [];
144
- }
145
- const bound = this.boundDecisionModels(prompt, decisionTypeID);
146
- return bound.length > 0 ? bound : AIEngine.Instance.Models.filter((model) => this.isActiveOfType(model, decisionTypeID));
147
- }
148
- /** Whether the model is active and of the given model type. */
149
- isActiveOfType(model, modelTypeID) {
150
- return model.IsActive && UUIDsEqual(model.AIModelTypeID, modelTypeID);
151
- }
152
- /** Factory method to create an AIDecisionRunner instance (extension point for unit testing). */
153
- CreateDecisionRunner() {
154
- return new AIDecisionRunner();
155
- }
156
- /** Builds decision questions (Likelihood, Choice, Score) from the spec outputs. */
157
- BuildQuestions(request) {
158
- const questions = {};
159
- for (const output of request.Spec?.Outputs ?? []) {
160
- const constraint = output.Constraint;
161
- if (!constraint) {
162
- continue;
163
- }
164
- const instructions = output.Description || output.Name;
165
- if (constraint.Type === 'boolean') {
166
- const question = {
167
- Kind: 'Likelihood',
168
- Instructions: instructions,
169
- };
170
- questions[output.Name] = question;
171
- }
172
- else if (constraint.Type === 'enum') {
173
- // The same choices the output check resolved, so the options asked are the values allowed
174
- const choices = ResolveEnumChoices(output, request.FieldValues ?? this.recordEntityFieldValues(request));
175
- const question = {
176
- Kind: 'Choice',
177
- Instructions: instructions,
178
- Options: (choices?.Values ?? []).map((v) => ({
179
- Value: v,
180
- Description: choices?.Descriptions[v] || v,
181
- })),
182
- };
183
- questions[output.Name] = question;
184
- }
185
- else if (constraint.Type === 'numeric') {
186
- const question = {
187
- Kind: 'Score',
188
- Instructions: instructions,
189
- Levels: constraint.Levels ?? [],
190
- };
191
- questions[output.Name] = question;
192
- }
193
- }
194
- return questions;
195
- }
196
- /**
197
- * The value lists of the record's entity, for a request the processor sent without its lookup (a driver
198
- * called on its own). Reads the run's provider, and the global one only when the run has none.
199
- */
200
- recordEntityFieldValues(request) {
201
- const entityID = request.Context.entityID ?? request.Record.EntityID;
202
- const provider = request.Context.provider ?? Metadata.Provider; // global-provider-ok: last-resort fallback for a context built without its provider
203
- return entityID && provider ? BuildEntityFieldValueLookup(provider.EntityByID(entityID)) : undefined;
204
- }
205
- /** Maps the decision model's answers back to structured output values and per-output confidences. */
206
- MapAnswers(outputs, answers) {
207
- const rawResult = {};
208
- const confidence = {};
209
- for (const output of outputs) {
210
- const answer = answers[output.Name];
211
- if (!answer) {
212
- continue;
213
- }
214
- let val;
215
- let conf;
216
- if (answer.Kind === 'Likelihood') {
217
- const threshold = (output.Constraint?.Type === 'boolean' ? output.Constraint.Threshold : undefined) ?? 0.5;
218
- const probability = answer.Probability;
219
- val = probability >= threshold;
220
- // Confidence is always in the value written: P(yes) for true, P(no) for false. A
221
- // confident "no" (P(yes) = 0.03) is 0.97, not 0.03.
222
- conf = val ? probability : 1 - probability;
223
- }
224
- else if (answer.Kind === 'Choice') {
225
- val = answer.Value;
226
- conf = answer.Confidence;
227
- }
228
- else if (answer.Kind === 'Score') {
229
- const constraint = output.Constraint;
230
- const levelsCount = constraint?.Type === 'numeric' && constraint.Levels ? constraint.Levels.length : 2;
231
- const t = levelsCount > 1 ? Math.max(0, Math.min(1, answer.Value / (levelsCount - 1))) : 0;
232
- const min = (constraint?.Type === 'numeric' ? constraint.Min : undefined) ?? 0;
233
- const max = (constraint?.Type === 'numeric' ? constraint.Max : undefined) ?? (levelsCount - 1);
234
- let scaled = min + t * (max - min);
235
- if (constraint?.Type === 'numeric' && constraint.Integer) {
236
- scaled = Math.round(scaled);
237
- }
238
- val = scaled;
239
- conf = answer.Confidence;
240
- }
241
- rawResult[output.Name] = val;
242
- if (output.Ref?.startsWith('$.')) {
243
- // Along the path, so a nested Ref ('$.flags.hot') resolves where the processor reads it
244
- SetNestedValue(rawResult, output.Ref.substring(2), val);
245
- }
246
- if (conf !== undefined) {
247
- confidence[output.Name] = conf;
248
- }
249
- }
250
- return { rawResult, confidence };
251
- }
252
- };
253
- DecisionFeaturePipelineDriver = __decorate([
254
- RegisterClass(BaseFeaturePipelineDriver, 'DecisionFeaturePipelineDriver')
255
- ], DecisionFeaturePipelineDriver);
256
- export { DecisionFeaturePipelineDriver };
257
- //# sourceMappingURL=DecisionFeaturePipelineDriver.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"DecisionFeaturePipelineDriver.js","sourceRoot":"","sources":["../../src/feature-pipeline-drivers/DecisionFeaturePipelineDriver.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;;;;;;;AAEH,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAChG,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAChD,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACpD,OAAO,EACH,gBAAgB,EAChB,gBAAgB,GACnB,MAAM,4BAA4B,CAAC;AASpC,OAAO,EACH,2BAA2B,EAC3B,sCAAsC,E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;gBACnC,IAAI,UAAU,EAAE,IAAI,KAAK,SAAS,IAAI,UAAU,CAAC,OAAO,EAAE,CAAC;oBACvD,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;gBAChC,CAAC;gBACD,GAAG,GAAG,MAAM,CAAC;gBACb,IAAI,GAAG,MAAM,CAAC,UAAU,CAAC;YAC7B,CAAC;YAED,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,GAAG,CAAC;YAC7B,IAAI,MAAM,CAAC,GAAG,EAAE,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;gBAC/B,wFAAwF;gBACxF,cAAc,CAAC,SAAS,EAAE,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;YAC5D,CAAC;YACD,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;gBACrB,UAAU,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;YACnC,CAAC;QACL,CAAC;QAED,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,CAAC;IACrC,CAAC;CACJ,CAAA;AAjPY,6BAA6B;IADzC,aAAa,CAAC,yBAAyB,EAAE,+BAA+B,CAAC;GAC7D,6BAA6B,CAiPzC"}
@@ -1,23 +0,0 @@
1
- /**
2
- * @fileoverview The `LLM` Feature Pipeline type's driver: runs the pipeline's AI Prompt over the
3
- * record and returns the model's result. This is the step `InferProcessor.ProcessRecord` ran inline
4
- * before pipeline types existed, moved here unchanged in behaviour.
5
- *
6
- * @module @memberjunction/record-set-processor
7
- */
8
- import { type FeaturePipelineDriverCapabilities } from '@memberjunction/feature-pipelines';
9
- import { BaseFeaturePipelineDriver, type FeaturePipelineComputeRequest, type FeaturePipelineComputeResult } from './BaseFeaturePipelineDriver.js';
10
- /** Runs the pipeline's AI Prompt for each record. Every pipeline that names no type uses it. */
11
- export declare class LLMFeaturePipelineDriver extends BaseFeaturePipelineDriver {
12
- /** Every constraint type and target mode, with reasoning and without confidence. */
13
- get Capabilities(): FeaturePipelineDriverCapabilities;
14
- /**
15
- * Runs the prompt, calling the processor's hooks in the order `InferProcessor` always has:
16
- * `BeforeBuildContext`, `BuildPromptData`, `BeforePromptExecute`, then `AfterPromptExecute`.
17
- * A string result is JSON-parsed when it parses; otherwise it is returned as the raw string.
18
- */
19
- ComputeOutputs(request: FeaturePipelineComputeRequest): Promise<FeaturePipelineComputeResult>;
20
- /** Builds the prompt's parameters, with the prompt data from the processor's `BuildPromptData` hook. */
21
- private buildPromptParams;
22
- }
23
- //# sourceMappingURL=LLMFeaturePipelineDriver.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"LLMFeaturePipelineDriver.d.ts","sourceRoot":"","sources":["../../src/feature-pipeline-drivers/LLMFeaturePipelineDriver.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAKH,OAAO,EAAqC,KAAK,iCAAiC,EAAE,MAAM,mCAAmC,CAAC;AAC9H,OAAO,EACH,yBAAyB,EACzB,KAAK,6BAA6B,EAClC,KAAK,4BAA4B,EACpC,MAAM,6BAA6B,CAAC;AAErC,gGAAgG;AAChG,qBACa,wBAAyB,SAAQ,yBAAyB;IACnE,oFAAoF;IACpF,IAAW,YAAY,IAAI,iCAAiC,CAE3D;IAED;;;;OAIG;IACU,cAAc,CAAC,OAAO,EAAE,6BAA6B,GAAG,OAAO,CAAC,4BAA4B,CAAC;IAmC1G,wGAAwG;YAC1F,iBAAiB;CAwBlC"}
@@ -1,85 +0,0 @@
1
- /**
2
- * @fileoverview The `LLM` Feature Pipeline type's driver: runs the pipeline's AI Prompt over the
3
- * record and returns the model's result. This is the step `InferProcessor.ProcessRecord` ran inline
4
- * before pipeline types existed, moved here unchanged in behaviour.
5
- *
6
- * @module @memberjunction/record-set-processor
7
- */
8
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
9
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
10
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
11
- 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;
12
- return c > 3 && r && Object.defineProperty(target, key, r), r;
13
- };
14
- import { RegisterClass } from '@memberjunction/global';
15
- import { AIPromptRunner } from '@memberjunction/ai-prompts';
16
- import { AIPromptParams } from '@memberjunction/ai-core-plus';
17
- import { LLM_FEATURE_PIPELINE_CAPABILITIES } from '@memberjunction/feature-pipelines';
18
- import { BaseFeaturePipelineDriver, } from './BaseFeaturePipelineDriver.js';
19
- /** Runs the pipeline's AI Prompt for each record. Every pipeline that names no type uses it. */
20
- let LLMFeaturePipelineDriver = class LLMFeaturePipelineDriver extends BaseFeaturePipelineDriver {
21
- /** Every constraint type and target mode, with reasoning and without confidence. */
22
- get Capabilities() {
23
- return LLM_FEATURE_PIPELINE_CAPABILITIES;
24
- }
25
- /**
26
- * Runs the prompt, calling the processor's hooks in the order `InferProcessor` always has:
27
- * `BeforeBuildContext`, `BuildPromptData`, `BeforePromptExecute`, then `AfterPromptExecute`.
28
- * A string result is JSON-parsed when it parses; otherwise it is returned as the raw string.
29
- */
30
- async ComputeOutputs(request) {
31
- const { Record: record, Context: context, Hooks: hooks } = request;
32
- // P1-6 Hook: beforeBuildContext
33
- await hooks.BeforeBuildContext(record, context);
34
- const params = await this.buildPromptParams(request);
35
- // P1-6 Hook: beforePromptExecute
36
- await hooks.BeforePromptExecute(params, record, context);
37
- const result = await new AIPromptRunner().ExecutePrompt(params);
38
- const aiPromptRunID = result.promptRun?.ID;
39
- if (!result.success) {
40
- return {
41
- Success: false,
42
- ErrorMessage: result.errorMessage ?? 'AI prompt execution failed',
43
- AIPromptRunID: aiPromptRunID,
44
- };
45
- }
46
- // P1-6 Hook: afterPromptExecute
47
- let rawResult = await hooks.AfterPromptExecute(result, record, context);
48
- if (typeof rawResult === 'string') {
49
- try {
50
- rawResult = JSON.parse(rawResult);
51
- }
52
- catch {
53
- // leave as raw string if not JSON
54
- }
55
- }
56
- return { Success: true, RawResult: rawResult, AIPromptRunID: aiPromptRunID };
57
- }
58
- /** Builds the prompt's parameters, with the prompt data from the processor's `BuildPromptData` hook. */
59
- async buildPromptParams(request) {
60
- const { Record: record, Context: context, Prompt: prompt, Spec: spec, Hooks: hooks } = request;
61
- // Carry ValidationBehavior on the execution run (AIPromptParams.validationBehavior)
62
- // and wrap the prompt in an execution-scoped Proxy so reads of params.prompt.ValidationBehavior
63
- // see the execution's behavior without mutating the shared entity in AIEngine cache (R11-B).
64
- const targetValidationBehavior = (spec?.Outputs && spec.Outputs.length > 0) ? 'Strict' : prompt.ValidationBehavior;
65
- const executionPrompt = new Proxy(prompt, {
66
- get(target, prop, receiver) {
67
- if (prop === 'ValidationBehavior') {
68
- return targetValidationBehavior;
69
- }
70
- return Reflect.get(target, prop, receiver);
71
- }
72
- });
73
- const params = new AIPromptParams();
74
- params.prompt = executionPrompt;
75
- params.validationBehavior = targetValidationBehavior;
76
- params.data = await hooks.BuildPromptData(record, context);
77
- params.contextUser = context.contextUser;
78
- return params;
79
- }
80
- };
81
- LLMFeaturePipelineDriver = __decorate([
82
- RegisterClass(BaseFeaturePipelineDriver, 'LLMFeaturePipelineDriver')
83
- ], LLMFeaturePipelineDriver);
84
- export { LLMFeaturePipelineDriver };
85
- //# sourceMappingURL=LLMFeaturePipelineDriver.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"LLMFeaturePipelineDriver.js","sourceRoot":"","sources":["../../src/feature-pipeline-drivers/LLMFeaturePipelineDriver.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;;;;;;;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,EAAE,cAAc,EAA0B,MAAM,8BAA8B,CAAC;AACtF,OAAO,EAAE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vEY,wBAAwB;IADpC,aAAa,CAAC,yBAAyB,EAAE,0BAA0B,CAAC;GACxD,wBAAwB,CAuEpC"}
@@ -1,155 +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 type { IMetadataProvider } from '@memberjunction/core';
15
- import type { MJRecordProcessEntity } from '@memberjunction/core-entities';
16
- import type { RecordProcessorContext, RecordRef, RecordResult } from '@memberjunction/record-set-processor-base';
17
- import { type DataFeatureOutput, type DataFeatureSpec } from '@memberjunction/feature-pipelines';
18
- /** A Decision pipeline's escalation settings (`DataFeatureSpec.Escalation`). */
19
- export type FeaturePipelineEscalationSettings = NonNullable<DataFeatureSpec['Escalation']>;
20
- /**
21
- * The processor an escalated record runs through. It is the escalation target's `InferProcessor`, built
22
- * from its `MJ: Record Processes` row exactly as `RecordProcessExecutor` builds any Infer pipeline.
23
- */
24
- export interface EscalationTargetProcessor {
25
- /** The target pipeline's spec. */
26
- readonly Spec: DataFeatureSpec | undefined;
27
- /** The `MJ: AI Prompts` ID the target runs. */
28
- readonly PromptID: string;
29
- /** The hash that versions the target's output constraints. */
30
- readonly ConstraintHash: string;
31
- /** Whether the target writes `MJ: Feature Values` history. Off for an escalation target: the Decision pipeline records the final answer. */
32
- WritesHistory: boolean;
33
- /** The target's normal batch path: validation and violation policy apply exactly as when it runs on its own. */
34
- ProcessBatch(records: RecordRef[], context: RecordProcessorContext): Promise<Map<string, RecordResult>>;
35
- }
36
- /** Builds an Infer Feature Pipeline's processor from its `MJ: Record Processes` row. */
37
- export type EscalationTargetBuilder = (pipeline: MJRecordProcessEntity, provider: IMetadataProvider) => EscalationTargetProcessor;
38
- /** One output the decision model answered below the floor, or without a confidence. */
39
- export interface BelowFloorOutput {
40
- /** The output's name. */
41
- OutputName: string;
42
- /** The decision model's confidence; absent when it returned none. */
43
- Confidence?: number;
44
- }
45
- /** A record to escalate, and the outputs that sent it. */
46
- export interface EscalationRequest {
47
- /** The record. */
48
- Record: RecordRef;
49
- /** The outputs below the floor. Never empty. */
50
- BelowFloor: BelowFloorOutput[];
51
- }
52
- /** An escalated record's answer from the target pipeline, already validated by it. */
53
- export interface EscalatedAnswer {
54
- /** The target's validated payload, shaped by the target's output Refs. */
55
- Payload: unknown;
56
- /** The target pipeline's outputs, so the payload can be read by output name. */
57
- TargetOutputs: DataFeatureOutput[];
58
- /** The `MJ: AI Prompts` ID of the target's prompt. */
59
- PromptID: string;
60
- /** The target's `MJ: AI Prompt Runs` row (from its cache, when its answer was cached). */
61
- AIPromptRunID?: string;
62
- /** The target's prompt version hash for the answer. */
63
- PromptVersionHash?: string;
64
- /** The target's constraint hash. */
65
- ConstraintHash: string;
66
- /** The target's own Dedup Cache entry for the answer, when the target caches. */
67
- FeatureValueCacheID?: string;
68
- /** For the history row's reasoning: that the record escalated, to which pipeline, and from what confidence. */
69
- Note: string;
70
- /** Why the record escalated (`Decision confidence below 0.7 (IsVIP 0.4)`), for a failure message. */
71
- EscalationReason: string;
72
- /** The target pipeline's name, for a failure message. */
73
- PipelineName: string;
74
- /** The reasoning of the history row that links the superseded decision's prompt run to the process run. */
75
- SupersededNote: string;
76
- }
77
- /** Why an escalation failed. The message carries both reasons: why the record escalated, and why that failed. */
78
- export interface EscalationFailure {
79
- /** Both reasons. */
80
- ErrorMessage: string;
81
- /** The target's failed `MJ: AI Prompt Runs` row, when there is one. */
82
- AIPromptRunID?: string;
83
- }
84
- /** The outcome of escalating one record. Narrow it with `'ErrorMessage' in outcome`. */
85
- export type EscalationOutcome = EscalatedAnswer | EscalationFailure;
86
- /**
87
- * Escalates a Decision pipeline's borderline records to an LLM Feature Pipeline. One instance serves one
88
- * processor instance, which is one run, so the target is loaded and checked once per run.
89
- */
90
- export declare class FeaturePipelineEscalator {
91
- private readonly settings;
92
- private readonly decisionOutputs;
93
- private readonly buildTarget;
94
- /** The target resolution, started on first use and shared by every record that escalates. */
95
- private targetResolution?;
96
- /**
97
- * @param settings - The Decision pipeline's `Escalation` settings.
98
- * @param decisionOutputs - The Decision pipeline's outputs: each one's confidence is checked, and the target must produce each one.
99
- * @param buildTarget - Builds the target's processor from its row, as `RecordProcessExecutor` does.
100
- */
101
- constructor(settings: FeaturePipelineEscalationSettings, decisionOutputs: DataFeatureOutput[], buildTarget: EscalationTargetBuilder);
102
- /** The `MJ: Record Processes` ID of the LLM pipeline records escalate to. */
103
- get PipelineID(): string;
104
- /** The confidence floor. */
105
- get BelowConfidence(): number;
106
- /**
107
- * The outputs whose confidence is below the floor, or missing. Any one of them escalates the whole
108
- * record; an empty list means the decision stands.
109
- */
110
- BelowFloor(confidence: Record<string, number> | undefined): BelowFloorOutput[];
111
- /**
112
- * Runs the records through the target together, through its normal batch path. Every request gets an
113
- * outcome. When the target cannot be loaded or used, every request fails, naming the pipeline and why.
114
- */
115
- Escalate(requests: EscalationRequest[], context: RecordProcessorContext): Promise<Map<string, EscalationOutcome>>;
116
- /** Why a record escalated, for its failure message. */
117
- private escalationReason;
118
- /** Loads and checks the target once per instance; every later call shares the result, success or failure. */
119
- private resolveTarget;
120
- /** Runs {@link resolveTarget}, turning a failure into the message each escalating record fails with. */
121
- private resolveTargetOrError;
122
- /** Loads the target row, checks it, builds its processor and checks its spec. */
123
- private loadTarget;
124
- /** Loads the target's `MJ: Record Processes` row through the run's provider. */
125
- private loadTargetRow;
126
- /** Builds the target's processor, naming the pipeline when it cannot be built. */
127
- private buildTargetProcessor;
128
- /**
129
- * Runs the requests' records through the target's batch path, in the target's own context: the run's
130
- * context with `recordProcessID` set to the target pipeline, so the target's Dedup Cache lookups and
131
- * writes use its own entries. A thrown error fails each of the records.
132
- */
133
- private runTarget;
134
- /** Turns the target's result for one record into its outcome. */
135
- private toOutcome;
136
- }
137
- /** The outputs below the floor, for a message: `Seniority 0.42, IsVIP none`. */
138
- export declare function DescribeBelowFloor(belowFloor: BelowFloorOutput[]): string;
139
- /**
140
- * The history note for an escalated record: that it escalated, to which pipeline, and from what
141
- * confidence. When the target's payload carries its own `reasoning`, it follows the note.
142
- */
143
- export declare function BuildEscalationNote(pipelineName: string, floor: number, belowFloor: BelowFloorOutput[], targetPayload: unknown): string;
144
- /**
145
- * Why an escalated record failed: why it escalated (`Decision confidence below 0.7 (IsVIP 0.4)`), and why
146
- * its escalation to the named LLM pipeline failed.
147
- */
148
- export declare function DescribeEscalationFailure(escalationReason: string, pipelineName: string, reason: string): string;
149
- /**
150
- * The reasoning of the history row that records a superseded decision. That row carries the decision
151
- * model's prompt run and its confidence, with no values, so the process run accounts for both model calls
152
- * an escalated record made; the escalated answer is the record's value.
153
- */
154
- export declare function BuildSupersededDecisionNote(pipelineName: string, floor: number, belowFloor: BelowFloorOutput[]): string;
155
- //# sourceMappingURL=FeaturePipelineEscalation.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"FeaturePipelineEscalation.d.ts","sourceRoot":"","sources":["../../src/processors/FeaturePipelineEscalation.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAC9D,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AAC3E,OAAO,KAAK,EAAE,sBAAsB,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,2CAA2C,CAAC;AACjH,OAAO,EACH,KAAK,iBAAiB,EACtB,KAAK,eAAe,EAGvB,MAAM,mCAAmC,CAAC;AAE3C,g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