@memberjunction/record-set-processor 0.0.1 → 5.43.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. package/README.md +58 -43
  2. package/dist/RateLimiter.d.ts +46 -0
  3. package/dist/RateLimiter.d.ts.map +1 -0
  4. package/dist/RateLimiter.js +71 -0
  5. package/dist/RateLimiter.js.map +1 -0
  6. package/dist/RecordProcessExecutor.d.ts +53 -0
  7. package/dist/RecordProcessExecutor.d.ts.map +1 -0
  8. package/dist/RecordProcessExecutor.js +141 -0
  9. package/dist/RecordProcessExecutor.js.map +1 -0
  10. package/dist/RecordSetProcessor.d.ts +36 -0
  11. package/dist/RecordSetProcessor.d.ts.map +1 -0
  12. package/dist/RecordSetProcessor.js +216 -0
  13. package/dist/RecordSetProcessor.js.map +1 -0
  14. package/dist/index.d.ts +21 -0
  15. package/dist/index.d.ts.map +1 -0
  16. package/dist/index.js +21 -0
  17. package/dist/index.js.map +1 -0
  18. package/dist/operations/RecordProcessControlOperations.d.ts +33 -0
  19. package/dist/operations/RecordProcessControlOperations.d.ts.map +1 -0
  20. package/dist/operations/RecordProcessControlOperations.js +117 -0
  21. package/dist/operations/RecordProcessControlOperations.js.map +1 -0
  22. package/dist/operations/RecordProcessGetRunStatusOperation.d.ts +19 -0
  23. package/dist/operations/RecordProcessGetRunStatusOperation.d.ts.map +1 -0
  24. package/dist/operations/RecordProcessGetRunStatusOperation.js +51 -0
  25. package/dist/operations/RecordProcessGetRunStatusOperation.js.map +1 -0
  26. package/dist/processors/ActionRecordProcessor.d.ts +27 -0
  27. package/dist/processors/ActionRecordProcessor.d.ts.map +1 -0
  28. package/dist/processors/ActionRecordProcessor.js +61 -0
  29. package/dist/processors/ActionRecordProcessor.js.map +1 -0
  30. package/dist/processors/AgentRecordProcessor.d.ts +23 -0
  31. package/dist/processors/AgentRecordProcessor.d.ts.map +1 -0
  32. package/dist/processors/AgentRecordProcessor.js +51 -0
  33. package/dist/processors/AgentRecordProcessor.js.map +1 -0
  34. package/dist/processors/FieldRulesProcessor.d.ts +44 -0
  35. package/dist/processors/FieldRulesProcessor.d.ts.map +1 -0
  36. package/dist/processors/FieldRulesProcessor.js +130 -0
  37. package/dist/processors/FieldRulesProcessor.js.map +1 -0
  38. package/dist/processors/FunctionRecordProcessor.d.ts +16 -0
  39. package/dist/processors/FunctionRecordProcessor.d.ts.map +1 -0
  40. package/dist/processors/FunctionRecordProcessor.js +16 -0
  41. package/dist/processors/FunctionRecordProcessor.js.map +1 -0
  42. package/dist/processors/InferProcessor.d.ts +24 -0
  43. package/dist/processors/InferProcessor.d.ts.map +1 -0
  44. package/dist/processors/InferProcessor.js +60 -0
  45. package/dist/processors/InferProcessor.js.map +1 -0
  46. package/dist/processors/WriteBackProcessor.d.ts +20 -0
  47. package/dist/processors/WriteBackProcessor.d.ts.map +1 -0
  48. package/dist/processors/WriteBackProcessor.js +41 -0
  49. package/dist/processors/WriteBackProcessor.js.map +1 -0
  50. package/dist/trackers/GenericProcessRunTracker.d.ts +24 -0
  51. package/dist/trackers/GenericProcessRunTracker.d.ts.map +1 -0
  52. package/dist/trackers/GenericProcessRunTracker.js +133 -0
  53. package/dist/trackers/GenericProcessRunTracker.js.map +1 -0
  54. package/dist/trackers/NoOpTracker.d.ts +15 -0
  55. package/dist/trackers/NoOpTracker.d.ts.map +1 -0
  56. package/dist/trackers/NoOpTracker.js +24 -0
  57. package/dist/trackers/NoOpTracker.js.map +1 -0
  58. package/dist/writeBack.d.ts +42 -0
  59. package/dist/writeBack.d.ts.map +1 -0
  60. package/dist/writeBack.js +59 -0
  61. package/dist/writeBack.js.map +1 -0
  62. package/package.json +39 -7
@@ -0,0 +1,23 @@
1
+ /**
2
+ * @fileoverview Processor that runs an Agent (top-level, ExposeAsAction) over each record. The
3
+ * record is mapped into the agent's `data` via the generic value-mapping resolver (`InputMapping`),
4
+ * and the agent's structured output payload becomes the record result; the AI Agent Run is captured
5
+ * for tracing.
6
+ * @module @memberjunction/record-set-processor
7
+ */
8
+ import { IRecordProcessor, RecordProcessorContext, RecordRef, RecordResult } from '@memberjunction/record-set-processor-base';
9
+ /** Runs an Agent for each record, mapping the record into the agent's input data. */
10
+ export declare class AgentRecordProcessor implements IRecordProcessor {
11
+ private readonly agentID;
12
+ private readonly inputMapping?;
13
+ /**
14
+ * @param agentID - ID of the Agent to run (must be top-level + `ExposeAsAction`).
15
+ * @param inputMapping - Optional mapping config resolved against `{ record, recordId, entityId }`
16
+ * to build the agent's `data`. When omitted, the whole record is passed as `data`.
17
+ */
18
+ constructor(agentID: string, inputMapping?: unknown);
19
+ /** Builds the agent `data` payload from the record + optional input mapping. */
20
+ static buildData(inputMapping: unknown, record: RecordRef): Record<string, unknown>;
21
+ ProcessRecord(record: RecordRef, context: RecordProcessorContext): Promise<RecordResult>;
22
+ }
23
+ //# sourceMappingURL=AgentRecordProcessor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AgentRecordProcessor.d.ts","sourceRoot":"","sources":["../../src/processors/AgentRecordProcessor.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAKH,OAAO,EACH,gBAAgB,EAChB,sBAAsB,EACtB,SAAS,EACT,YAAY,EACf,MAAM,2CAA2C,CAAC;AAEnD,qFAAqF;AACrF,qBAAa,oBAAqB,YAAW,gBAAgB;IAM7C,OAAO,CAAC,QAAQ,CAAC,OAAO;IAAU,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAC;IAL5E;;;;OAIG;gBAC0B,OAAO,EAAE,MAAM,EAAmB,YAAY,CAAC,EAAE,OAAO;IAErF,gFAAgF;WAClE,SAAS,CAAC,YAAY,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAQ7E,aAAa,CAAC,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,sBAAsB,GAAG,OAAO,CAAC,YAAY,CAAC;CAsBxG"}
@@ -0,0 +1,51 @@
1
+ /**
2
+ * @fileoverview Processor that runs an Agent (top-level, ExposeAsAction) over each record. The
3
+ * record is mapped into the agent's `data` via the generic value-mapping resolver (`InputMapping`),
4
+ * and the agent's structured output payload becomes the record result; the AI Agent Run is captured
5
+ * for tracing.
6
+ * @module @memberjunction/record-set-processor
7
+ */
8
+ import { UUIDsEqual, resolveValueMapping } from '@memberjunction/global';
9
+ import { AIEngine } from '@memberjunction/aiengine';
10
+ import { AgentRunner } from '@memberjunction/ai-agents';
11
+ /** Runs an Agent for each record, mapping the record into the agent's input data. */
12
+ export class AgentRecordProcessor {
13
+ /**
14
+ * @param agentID - ID of the Agent to run (must be top-level + `ExposeAsAction`).
15
+ * @param inputMapping - Optional mapping config resolved against `{ record, recordId, entityId }`
16
+ * to build the agent's `data`. When omitted, the whole record is passed as `data`.
17
+ */
18
+ constructor(agentID, inputMapping) {
19
+ this.agentID = agentID;
20
+ this.inputMapping = inputMapping;
21
+ }
22
+ /** Builds the agent `data` payload from the record + optional input mapping. */
23
+ static buildData(inputMapping, record) {
24
+ if (!inputMapping) {
25
+ return { record: record.Record ?? {}, recordId: record.RecordID, entityId: record.EntityID };
26
+ }
27
+ const sources = { record: record.Record ?? {}, recordId: record.RecordID, entityId: record.EntityID };
28
+ return resolveValueMapping(inputMapping, sources);
29
+ }
30
+ async ProcessRecord(record, context) {
31
+ await AIEngine.Instance.Config(false, context.contextUser);
32
+ const agent = AIEngine.Instance.Agents.find((a) => UUIDsEqual(a.ID, this.agentID));
33
+ if (!agent) {
34
+ return { Status: 'Failed', ErrorMessage: `Agent '${this.agentID}' not found` };
35
+ }
36
+ const runner = new AgentRunner();
37
+ const result = await runner.RunAgent({
38
+ agent,
39
+ conversationMessages: [],
40
+ contextUser: context.contextUser,
41
+ data: AgentRecordProcessor.buildData(this.inputMapping, record),
42
+ });
43
+ return {
44
+ Status: result.success ? 'Succeeded' : 'Failed',
45
+ ResultPayload: result.payload,
46
+ ErrorMessage: result.success ? undefined : (result.agentRun?.ErrorMessage ?? 'Agent failed'),
47
+ AIAgentRunID: result.agentRun?.ID,
48
+ };
49
+ }
50
+ }
51
+ //# sourceMappingURL=AgentRecordProcessor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AgentRecordProcessor.js","sourceRoot":"","sources":["../../src/processors/AgentRecordProcessor.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,UAAU,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AACzE,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACpD,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAQxD,qFAAqF;AACrF,MAAM,OAAO,oBAAoB;IAC7B;;;;OAIG;IACH,YAA6B,OAAe,EAAmB,YAAsB;QAAxD,YAAO,GAAP,OAAO,CAAQ;QAAmB,iBAAY,GAAZ,YAAY,CAAU;IAAG,CAAC;IAEzF,gFAAgF;IACzE,MAAM,CAAC,SAAS,CAAC,YAAqB,EAAE,MAAiB;QAC5D,IAAI,CAAC,YAAY,EAAE,CAAC;YAChB,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,IAAI,EAAE,EAAE,QAAQ,EAAE,MAAM,CAAC,QAAQ,EAAE,QAAQ,EAAE,MAAM,CAAC,QAAQ,EAAE,CAAC;QACjG,CAAC;QACD,MAAM,OAAO,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,IAAI,EAAE,EAAE,QAAQ,EAAE,MAAM,CAAC,QAAQ,EAAE,QAAQ,EAAE,MAAM,CAAC,QAAQ,EAAE,CAAC;QACtG,OAAO,mBAAmB,CAA0B,YAAY,EAAE,OAAO,CAAC,CAAC;IAC/E,CAAC;IAEM,KAAK,CAAC,aAAa,CAAC,MAAiB,EAAE,OAA+B;QACzE,MAAM,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,KAAK,EAAE,OAAO,CAAC,WAAW,CAAC,CAAC;QAC3D,MAAM,KAAK,GAAG,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;QACnF,IAAI,CAAC,KAAK,EAAE,CAAC;YACT,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,YAAY,EAAE,UAAU,IAAI,CAAC,OAAO,aAAa,EAAE,CAAC;QACnF,CAAC;QAED,MAAM,MAAM,GAAG,IAAI,WAAW,EAAE,CAAC;QACjC,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,QAAQ,CAAC;YACjC,KAAK;YACL,oBAAoB,EAAE,EAAE;YACxB,WAAW,EAAE,OAAO,CAAC,WAAW;YAChC,IAAI,EAAE,oBAAoB,CAAC,SAAS,CAAC,IAAI,CAAC,YAAY,EAAE,MAAM,CAAC;SAClE,CAAC,CAAC;QAEH,OAAO;YACH,MAAM,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,QAAQ;YAC/C,aAAa,EAAE,MAAM,CAAC,OAAO;YAC7B,YAAY,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,QAAQ,EAAE,YAAY,IAAI,cAAc,CAAC;YAC5F,YAAY,EAAE,MAAM,CAAC,QAAQ,EAAE,EAAE;SACpC,CAAC;IACN,CAAC;CACJ"}
@@ -0,0 +1,44 @@
1
+ import { type FieldChange, type FieldRuleSet } from '@memberjunction/global';
2
+ import { type IRecordProcessor, type RecordProcessorContext, type RecordRef, type RecordResult } from '@memberjunction/record-set-processor-base';
3
+ /** Options for a {@link FieldRulesProcessor}. */
4
+ export interface FieldRulesProcessorOptions {
5
+ /** The rules to apply to each record. */
6
+ RuleSet: FieldRuleSet;
7
+ /** When true, COMPUTE the changes but do NOT save — each result payload carries the per-field diff. */
8
+ DryRun?: boolean;
9
+ }
10
+ /** The structured payload recorded on each Process Run Detail (the per-record diff). */
11
+ export interface FieldRulesResultPayload {
12
+ DryRun: boolean;
13
+ Changes: FieldChange[];
14
+ ChangedFields: string[];
15
+ }
16
+ /**
17
+ * Applies field rules to a single record via {@link EntityFieldRules}. Single-primary-key entities only
18
+ * (composite keys return a clear Failed result). On a real run the record is persisted via
19
+ * `BaseEntity.Save()`, so MJ's built-in Record Changes versioning captures the before/after automatically.
20
+ */
21
+ export declare class FieldRulesProcessor implements IRecordProcessor {
22
+ private readonly options;
23
+ constructor(options: FieldRulesProcessorOptions);
24
+ ProcessRecord(record: RecordRef, context: RecordProcessorContext): Promise<RecordResult>;
25
+ /** Maps the entity-level apply result onto the record-level outcome. */
26
+ private toRecordResult;
27
+ /** Loads the BaseEntity for a record, or returns an error string. */
28
+ private loadRecord;
29
+ /**
30
+ * Supplies core's `EntityFieldRules` with a real `AIPromptRunner`-backed resolver for `prompt` rule
31
+ * sources (core can't depend on the AI stack itself). Each prompt source runs the named prompt with
32
+ * the record (or its shaped data) as input; the prompt's output becomes the field value. One model
33
+ * call per record per prompt-rule — pair with dry-run + bounded concurrency on large sets.
34
+ */
35
+ private buildPromptResolver;
36
+ /**
37
+ * Supplies core's `EntityFieldRules` with a resolver for `entityDocument` rule sources, backed by the
38
+ * existing Entity Document + Template render infrastructure (core can't depend on templates itself).
39
+ * Renders the named Entity Document's template against the record and returns the text — typically
40
+ * fed into a `prompt` source's `Data` to give the LLM a curated rendering of the record.
41
+ */
42
+ private buildEntityDocumentResolver;
43
+ }
44
+ //# sourceMappingURL=FieldRulesProcessor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FieldRulesProcessor.d.ts","sourceRoot":"","sources":["../../src/processors/FieldRulesProcessor.ts"],"names":[],"mappings":"AAaA,OAAO,EAAc,KAAK,WAAW,EAAE,KAAK,YAAY,EAAuB,MAAM,wBAAwB,CAAC;AAO9G,OAAO,EACH,KAAK,gBAAgB,EACrB,KAAK,sBAAsB,EAC3B,KAAK,SAAS,EACd,KAAK,YAAY,EACpB,MAAM,2CAA2C,CAAC;AAEnD,iDAAiD;AACjD,MAAM,WAAW,0BAA0B;IACvC,yCAAyC;IACzC,OAAO,EAAE,YAAY,CAAC;IACtB,uGAAuG;IACvG,MAAM,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,wFAAwF;AACxF,MAAM,WAAW,uBAAuB;IACpC,MAAM,EAAE,OAAO,CAAC;IAChB,OAAO,EAAE,WAAW,EAAE,CAAC;IACvB,aAAa,EAAE,MAAM,EAAE,CAAC;CAC3B;AAED;;;;GAIG;AACH,qBAAa,mBAAoB,YAAW,gBAAgB;IAC5C,OAAO,CAAC,QAAQ,CAAC,OAAO;gBAAP,OAAO,EAAE,0BAA0B;IAMnD,aAAa,CAAC,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,sBAAsB,GAAG,OAAO,CAAC,YAAY,CAAC;IAerG,wEAAwE;IACxE,OAAO,CAAC,cAAc;IAkBtB,qEAAqE;YACvD,UAAU;IAgBxB;;;;;OAKG;IACH,OAAO,CAAC,mBAAmB;IAmB3B;;;;;OAKG;IACH,OAAO,CAAC,2BAA2B;CAkBtC"}
@@ -0,0 +1,130 @@
1
+ /**
2
+ * @fileoverview FieldRulesProcessor — applies a declarative {@link FieldRuleSet} to each record: the
3
+ * rules-based bulk-update unit of work for the Record Set Processor.
4
+ *
5
+ * It is intentionally thin: the record set + batching / concurrency / pause-resume come from the engine,
6
+ * and the actual rule logic (compute → metadata-validate → type-coerce → write/preview, plus the
7
+ * RunView-backed lookup resolver) lives in {@link EntityFieldRules} in `@memberjunction/core`. This
8
+ * processor just maps a {@link RecordRef} to a loaded entity and translates the apply result into a
9
+ * {@link RecordResult}. The transform/rule substrate beneath `EntityFieldRules` is the pure
10
+ * field-rules engine in `@memberjunction/global` — the same one the integration field-mapping engine uses.
11
+ * @module @memberjunction/record-set-processor
12
+ */
13
+ import { CompositeKey, EntityFieldRules } from '@memberjunction/core';
14
+ import { UUIDsEqual } from '@memberjunction/global';
15
+ import { AIEngine } from '@memberjunction/aiengine';
16
+ import { AIPromptRunner } from '@memberjunction/ai-prompts';
17
+ import { AIPromptParams } from '@memberjunction/ai-core-plus';
18
+ import { TemplateEngineServer } from '@memberjunction/templates';
19
+ import { RegisterFieldRulesTransforms } from '@memberjunction/field-rules-transforms';
20
+ /**
21
+ * Applies field rules to a single record via {@link EntityFieldRules}. Single-primary-key entities only
22
+ * (composite keys return a clear Failed result). On a real run the record is persisted via
23
+ * `BaseEntity.Save()`, so MJ's built-in Record Changes versioning captures the before/after automatically.
24
+ */
25
+ export class FieldRulesProcessor {
26
+ constructor(options) {
27
+ this.options = options;
28
+ // Make the extended transforms (jsonpath / xpath) available to rules. Idempotent — registers
29
+ // the plugins into the global transform registry the first time a processor is created.
30
+ RegisterFieldRulesTransforms();
31
+ }
32
+ async ProcessRecord(record, context) {
33
+ const started = Date.now();
34
+ try {
35
+ const obj = await this.loadRecord(record, context);
36
+ if (typeof obj === 'string') {
37
+ return { Status: 'Failed', ErrorMessage: obj, DurationMs: Date.now() - started };
38
+ }
39
+ const rules = new EntityFieldRules(context.contextUser, this.buildPromptResolver(context), this.buildEntityDocumentResolver(context));
40
+ const result = await rules.ApplyToEntity(obj, this.options.RuleSet, { DryRun: this.options.DryRun });
41
+ return this.toRecordResult(result, started);
42
+ }
43
+ catch (err) {
44
+ return { Status: 'Failed', ErrorMessage: err instanceof Error ? err.message : String(err), DurationMs: Date.now() - started };
45
+ }
46
+ }
47
+ /** Maps the entity-level apply result onto the record-level outcome. */
48
+ toRecordResult(result, started) {
49
+ const ResultPayload = { DryRun: result.DryRun, Changes: result.Changes, ChangedFields: result.AppliedFields };
50
+ const DurationMs = Date.now() - started;
51
+ if (result.Errors.length > 0) {
52
+ return { Status: 'Failed', ResultPayload, ErrorMessage: result.Errors.join('; '), DurationMs };
53
+ }
54
+ if (result.DryRun) {
55
+ return { Status: 'Succeeded', ResultPayload, DurationMs }; // preview — the diff is the deliverable
56
+ }
57
+ if (result.AppliedFields.length === 0) {
58
+ return { Status: 'Skipped', ResultPayload, DurationMs };
59
+ }
60
+ if (!result.Saved) {
61
+ return { Status: 'Failed', ResultPayload, ErrorMessage: result.SaveError ?? 'save failed', DurationMs };
62
+ }
63
+ return { Status: 'Succeeded', ResultPayload, DurationMs };
64
+ }
65
+ /** Loads the BaseEntity for a record, or returns an error string. */
66
+ async loadRecord(record, context) {
67
+ const entity = context.provider.EntityByID(record.EntityID);
68
+ if (!entity) {
69
+ return `entity '${record.EntityID}' not found in metadata`;
70
+ }
71
+ if (entity.PrimaryKeys.length !== 1) {
72
+ return `field-rules updates support single-primary-key entities only ('${entity.Name}')`;
73
+ }
74
+ const obj = await context.provider.GetEntityObject(entity.Name, context.contextUser);
75
+ const loaded = await obj.InnerLoad(CompositeKey.FromKeyValuePair(entity.FirstPrimaryKey.Name, record.RecordID));
76
+ if (!loaded) {
77
+ return `record '${record.RecordID}' of '${entity.Name}' not found`;
78
+ }
79
+ return obj;
80
+ }
81
+ /**
82
+ * Supplies core's `EntityFieldRules` with a real `AIPromptRunner`-backed resolver for `prompt` rule
83
+ * sources (core can't depend on the AI stack itself). Each prompt source runs the named prompt with
84
+ * the record (or its shaped data) as input; the prompt's output becomes the field value. One model
85
+ * call per record per prompt-rule — pair with dry-run + bounded concurrency on large sets.
86
+ */
87
+ buildPromptResolver(context) {
88
+ return async ({ PromptID, Data }) => {
89
+ await AIEngine.Instance.Config(false, context.contextUser);
90
+ const prompt = AIEngine.Instance.Prompts.find((p) => UUIDsEqual(p.ID, PromptID));
91
+ if (!prompt) {
92
+ throw new Error(`AI Prompt '${PromptID}' not found`);
93
+ }
94
+ const params = new AIPromptParams();
95
+ params.prompt = prompt;
96
+ params.data = Data;
97
+ params.contextUser = context.contextUser;
98
+ const result = await new AIPromptRunner().ExecutePrompt(params);
99
+ if (!result.success) {
100
+ throw new Error(result.errorMessage ?? 'AI prompt execution failed');
101
+ }
102
+ return result.result;
103
+ };
104
+ }
105
+ /**
106
+ * Supplies core's `EntityFieldRules` with a resolver for `entityDocument` rule sources, backed by the
107
+ * existing Entity Document + Template render infrastructure (core can't depend on templates itself).
108
+ * Renders the named Entity Document's template against the record and returns the text — typically
109
+ * fed into a `prompt` source's `Data` to give the LLM a curated rendering of the record.
110
+ */
111
+ buildEntityDocumentResolver(context) {
112
+ return async ({ EntityDocumentID, Record }) => {
113
+ if (!EntityDocumentID) {
114
+ throw new Error('an entityDocument source requires an EntityDocumentID');
115
+ }
116
+ // Configure the template engine first so the EntityDocument's virtual TemplateText resolves.
117
+ await TemplateEngineServer.Instance.Config(false, context.contextUser);
118
+ const doc = await context.provider.GetEntityObject('MJ: Entity Documents', context.contextUser);
119
+ if (!(await doc.Load(EntityDocumentID))) {
120
+ throw new Error(`Entity Document '${EntityDocumentID}' not found`);
121
+ }
122
+ const rendered = await TemplateEngineServer.Instance.RenderTemplateSimple(doc.TemplateText, Record);
123
+ if (!rendered.Success) {
124
+ throw new Error(rendered.Message ?? 'entity document render failed');
125
+ }
126
+ return rendered.Output ?? '';
127
+ };
128
+ }
129
+ }
130
+ //# sourceMappingURL=FieldRulesProcessor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FieldRulesProcessor.js","sourceRoot":"","sources":["../../src/processors/FieldRulesProcessor.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EAAc,YAAY,EAAE,gBAAgB,EAA+B,MAAM,sBAAsB,CAAC;AAC/G,OAAO,EAAE,UAAU,EAA4D,MAAM,wBAAwB,CAAC;AAC9G,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACpD,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,EAAE,cAAc,EAAkC,MAAM,8BAA8B,CAAC;AAC9F,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,4BAA4B,EAAE,MAAM,wCAAwC,CAAC;AAwBt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I,EAAE,CAAC;QACjC,CAAC,CAAC;IACN,CAAC;CACJ"}
@@ -0,0 +1,16 @@
1
+ /**
2
+ * @fileoverview A processor that delegates to a plain function — the simplest executor seam, useful
3
+ * for inline logic and tests. Action / Agent / Infer-&-Write-Back processors are added alongside
4
+ * their consuming features.
5
+ * @module @memberjunction/record-set-processor
6
+ */
7
+ import { IRecordProcessor, RecordProcessorContext, RecordRef, RecordResult } from '@memberjunction/record-set-processor-base';
8
+ /** Per-record handler function wrapped by {@link FunctionRecordProcessor}. */
9
+ export type RecordProcessorFn = (record: RecordRef, context: RecordProcessorContext) => Promise<RecordResult> | RecordResult;
10
+ /** An {@link IRecordProcessor} backed by a function. */
11
+ export declare class FunctionRecordProcessor implements IRecordProcessor {
12
+ private readonly fn;
13
+ constructor(fn: RecordProcessorFn);
14
+ ProcessRecord(record: RecordRef, context: RecordProcessorContext): Promise<RecordResult>;
15
+ }
16
+ //# sourceMappingURL=FunctionRecordProcessor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FunctionRecordProcessor.d.ts","sourceRoot":"","sources":["../../src/processors/FunctionRecordProcessor.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EACH,gBAAgB,EAChB,sBAAsB,EACtB,SAAS,EACT,YAAY,EACf,MAAM,2CAA2C,CAAC;AAEnD,8EAA8E;AAC9E,MAAM,MAAM,iBAAiB,GAAG,CAAC,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,sBAAsB,KAAK,OAAO,CAAC,YAAY,CAAC,GAAG,YAAY,CAAC;AAE7H,wDAAwD;AACxD,qBAAa,uBAAwB,YAAW,gBAAgB;IAChD,OAAO,CAAC,QAAQ,CAAC,EAAE;gBAAF,EAAE,EAAE,iBAAiB;IAErC,aAAa,CAAC,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,sBAAsB,GAAG,OAAO,CAAC,YAAY,CAAC;CAGxG"}
@@ -0,0 +1,16 @@
1
+ /**
2
+ * @fileoverview A processor that delegates to a plain function — the simplest executor seam, useful
3
+ * for inline logic and tests. Action / Agent / Infer-&-Write-Back processors are added alongside
4
+ * their consuming features.
5
+ * @module @memberjunction/record-set-processor
6
+ */
7
+ /** An {@link IRecordProcessor} backed by a function. */
8
+ export class FunctionRecordProcessor {
9
+ constructor(fn) {
10
+ this.fn = fn;
11
+ }
12
+ async ProcessRecord(record, context) {
13
+ return this.fn(record, context);
14
+ }
15
+ }
16
+ //# sourceMappingURL=FunctionRecordProcessor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FunctionRecordProcessor.js","sourceRoot":"","sources":["../../src/processors/FunctionRecordProcessor.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAYH,wDAAwD;AACxD,MAAM,OAAO,uBAAuB;IAChC,YAA6B,EAAqB;QAArB,OAAE,GAAF,EAAE,CAAmB;IAAG,CAAC;IAE/C,KAAK,CAAC,aAAa,CAAC,MAAiB,EAAE,OAA+B;QACzE,OAAO,IAAI,CAAC,EAAE,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACpC,CAAC;CACJ"}
@@ -0,0 +1,24 @@
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
+ * @module @memberjunction/record-set-processor
7
+ */
8
+ import { IRecordProcessor, RecordProcessorContext, RecordRef, RecordResult } from '@memberjunction/record-set-processor-base';
9
+ /** Runs an AI Prompt per record and returns its structured output (write-back is the wrapper's job). */
10
+ export declare class InferProcessor implements IRecordProcessor {
11
+ private readonly promptID;
12
+ private readonly inputMapping?;
13
+ /**
14
+ * @param promptID - The `MJ: AI Prompts` ID to run for each record.
15
+ * @param inputMapping - Optional mapping shaping the data passed to the prompt (default: `{ record }`).
16
+ */
17
+ constructor(promptID: string, inputMapping?: Record<string, string>);
18
+ ProcessRecord(record: RecordRef, context: RecordProcessorContext): Promise<RecordResult>;
19
+ /** Builds the data object passed to the prompt — the record's fields under `record`, optionally remapped. */
20
+ private buildPromptData;
21
+ /** Extracts a plain field map from the record (BaseEntity → GetAll(), plain object → as-is). */
22
+ private recordToPlain;
23
+ }
24
+ //# sourceMappingURL=InferProcessor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"InferProcessor.d.ts","sourceRoot":"","sources":["../../src/processors/InferProcessor.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAMH,OAAO,EACH,gBAAgB,EAChB,sBAAsB,EACtB,SAAS,EACT,YAAY,EACf,MAAM,2CAA2C,CAAC;AAEnD,wGAAwG;AACxG,qBAAa,cAAe,YAAW,gBAAgB;IAM/C,OAAO,CAAC,QAAQ,CAAC,QAAQ;IACzB,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAC;IANlC;;;OAGG;gBAEkB,QAAQ,EAAE,MAAM,EAChB,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;IAG7C,aAAa,CAAC,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,sBAAsB,GAAG,OAAO,CAAC,YAAY,CAAC;IAoBrG,6GAA6G;IAC7G,OAAO,CAAC,eAAe;IASvB,gGAAgG;IAChG,OAAO,CAAC,aAAa;CAUxB"}
@@ -0,0 +1,60 @@
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
+ * @module @memberjunction/record-set-processor
7
+ */
8
+ import { UUIDsEqual, resolveValueMapping } from '@memberjunction/global';
9
+ import { AIEngine } from '@memberjunction/aiengine';
10
+ import { AIPromptRunner } from '@memberjunction/ai-prompts';
11
+ import { AIPromptParams } from '@memberjunction/ai-core-plus';
12
+ /** Runs an AI Prompt per record and returns its structured output (write-back is the wrapper's job). */
13
+ export class InferProcessor {
14
+ /**
15
+ * @param promptID - The `MJ: AI Prompts` ID to run for each record.
16
+ * @param inputMapping - Optional mapping shaping the data passed to the prompt (default: `{ record }`).
17
+ */
18
+ constructor(promptID, inputMapping) {
19
+ this.promptID = promptID;
20
+ this.inputMapping = inputMapping;
21
+ }
22
+ async ProcessRecord(record, context) {
23
+ await AIEngine.Instance.Config(false, context.contextUser);
24
+ const prompt = AIEngine.Instance.Prompts.find((p) => UUIDsEqual(p.ID, this.promptID));
25
+ if (!prompt) {
26
+ return { Status: 'Failed', ErrorMessage: `AI Prompt '${this.promptID}' not found` };
27
+ }
28
+ const params = new AIPromptParams();
29
+ params.prompt = prompt;
30
+ params.data = this.buildPromptData(record);
31
+ params.contextUser = context.contextUser;
32
+ const result = await new AIPromptRunner().ExecutePrompt(params);
33
+ const aiPromptRunID = result.promptRun?.ID;
34
+ if (!result.success) {
35
+ return { Status: 'Failed', ErrorMessage: result.errorMessage ?? 'AI prompt execution failed', AIPromptRunID: aiPromptRunID };
36
+ }
37
+ return { Status: 'Succeeded', ResultPayload: result.result ?? {}, AIPromptRunID: aiPromptRunID };
38
+ }
39
+ /** Builds the data object passed to the prompt — the record's fields under `record`, optionally remapped. */
40
+ buildPromptData(record) {
41
+ const recordData = this.recordToPlain(record);
42
+ if (!this.inputMapping) {
43
+ return { record: recordData };
44
+ }
45
+ const mapped = resolveValueMapping(this.inputMapping, { record: recordData });
46
+ return mapped && typeof mapped === 'object' ? mapped : { record: recordData };
47
+ }
48
+ /** Extracts a plain field map from the record (BaseEntity → GetAll(), plain object → as-is). */
49
+ recordToPlain(record) {
50
+ const r = record.Record;
51
+ if (r && typeof r.GetAll === 'function') {
52
+ return r.GetAll();
53
+ }
54
+ if (r && typeof r === 'object') {
55
+ return r;
56
+ }
57
+ return { RecordID: record.RecordID, EntityID: record.EntityID };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,CAAC;QACD,OAAO,EAAE,QAAQ,EAAE,MAAM,CAAC,QAAQ,EAAE,QAAQ,EAAE,MAAM,CAAC,QAAQ,EAAE,CAAC;IACpE,CAAC;CACJ"}
@@ -0,0 +1,20 @@
1
+ /**
2
+ * @fileoverview A processor decorator that runs an inner processor (Action/Agent/Infer) and then
3
+ * applies the Record Process's `OutputMapping` write-back (fields / child record) using the inner
4
+ * result's payload. Lets any work type share the same declarative write-back.
5
+ * @module @memberjunction/record-set-processor
6
+ */
7
+ import { IRecordProcessor, RecordProcessorContext, RecordRef, RecordResult } from '@memberjunction/record-set-processor-base';
8
+ import { OutputMappingConfig } from '../writeBack.js';
9
+ /** Wraps a processor and applies output-mapping write-back to each successful result. */
10
+ export declare class WriteBackProcessor implements IRecordProcessor {
11
+ private readonly inner;
12
+ private readonly outputMapping;
13
+ /**
14
+ * @param inner - The processor that produces the work result.
15
+ * @param outputMapping - The `OutputMapping` config to apply to each successful result.
16
+ */
17
+ constructor(inner: IRecordProcessor, outputMapping: OutputMappingConfig);
18
+ ProcessRecord(record: RecordRef, context: RecordProcessorContext): Promise<RecordResult>;
19
+ }
20
+ //# sourceMappingURL=WriteBackProcessor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"WriteBackProcessor.d.ts","sourceRoot":"","sources":["../../src/processors/WriteBackProcessor.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EACH,gBAAgB,EAChB,sBAAsB,EACtB,SAAS,EACT,YAAY,EACf,MAAM,2CAA2C,CAAC;AACnD,OAAO,EAAE,mBAAmB,EAAsB,MAAM,cAAc,CAAC;AAEvE,yFAAyF;AACzF,qBAAa,kBAAmB,YAAW,gBAAgB;IAK3C,OAAO,CAAC,QAAQ,CAAC,KAAK;IAAoB,OAAO,CAAC,QAAQ,CAAC,aAAa;IAJpF;;;OAGG;gBAC0B,KAAK,EAAE,gBAAgB,EAAmB,aAAa,EAAE,mBAAmB;IAE5F,aAAa,CAAC,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,sBAAsB,GAAG,OAAO,CAAC,YAAY,CAAC;CAoBxG"}
@@ -0,0 +1,41 @@
1
+ /**
2
+ * @fileoverview A processor decorator that runs an inner processor (Action/Agent/Infer) and then
3
+ * applies the Record Process's `OutputMapping` write-back (fields / child record) using the inner
4
+ * result's payload. Lets any work type share the same declarative write-back.
5
+ * @module @memberjunction/record-set-processor
6
+ */
7
+ import { LogError } from '@memberjunction/core';
8
+ import { applyOutputMapping } from '../writeBack.js';
9
+ /** Wraps a processor and applies output-mapping write-back to each successful result. */
10
+ export class WriteBackProcessor {
11
+ /**
12
+ * @param inner - The processor that produces the work result.
13
+ * @param outputMapping - The `OutputMapping` config to apply to each successful result.
14
+ */
15
+ constructor(inner, outputMapping) {
16
+ this.inner = inner;
17
+ this.outputMapping = outputMapping;
18
+ }
19
+ async ProcessRecord(record, context) {
20
+ const result = await this.inner.ProcessRecord(record, context);
21
+ if (result.Status !== 'Succeeded') {
22
+ return result;
23
+ }
24
+ try {
25
+ const writeBack = await applyOutputMapping({
26
+ outputMapping: this.outputMapping,
27
+ result: result.ResultPayload,
28
+ record,
29
+ contextUser: context.contextUser,
30
+ provider: context.provider,
31
+ });
32
+ return { ...result, ResultPayload: { output: result.ResultPayload, writeBack } };
33
+ }
34
+ catch (e) {
35
+ const message = e instanceof Error ? e.message : String(e);
36
+ LogError(`WriteBackProcessor: write-back failed for record '${record.RecordID}': ${message}`);
37
+ return { ...result, Status: 'Failed', ErrorMessage: `Write-back failed: ${message}` };
38
+ }
39
+ }
40
+ }
41
+ //# sourceMappingURL=WriteBackProcessor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"WriteBackProcessor.js","sourceRoot":"","sources":["../../src/processors/WriteBackProcessor.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAOhD,OAAO,EAAuB,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAE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J: Process Run Details` (one row per processed record), and implements the pause/cancel
4
+ * handshake by re-reading the run row's `CancellationRequested` flag at each checkpoint.
5
+ * @module @memberjunction/record-set-processor
6
+ */
7
+ import { IMetadataProvider, UserInfo } from '@memberjunction/core';
8
+ import { IProcessRunTracker, ProcessCursor, ProcessRunMeta, ProcessRunSummary, RecordRef, RecordResult, RunCounts, RunHandle } from '@memberjunction/record-set-processor-base';
9
+ /** The default tracker, persisting to the generic `MJ: Process Runs` / `MJ: Process Run Details` tables. */
10
+ export declare class GenericProcessRunTracker implements IProcessRunTracker {
11
+ /**
12
+ * Fire-and-forget queue for per-record detail INSERTs. Each detail is its own entity instance (a
13
+ * distinct key), so detail writes run concurrently without blocking the per-record loop; `CompleteRun`
14
+ * flushes them before finalizing the run. (Reliable/insert-before-fire mode is a future enhancement —
15
+ * it needs a per-record start hook on `IProcessRunTracker`.)
16
+ */
17
+ private readonly detailQueue;
18
+ BeginRun(meta: ProcessRunMeta, contextUser: UserInfo, provider?: IMetadataProvider): Promise<RunHandle>;
19
+ RecordResult(handle: RunHandle, record: RecordRef, result: RecordResult, contextUser: UserInfo, provider?: IMetadataProvider): Promise<void>;
20
+ Checkpoint(handle: RunHandle, cursor: ProcessCursor, counts: RunCounts, _contextUser: UserInfo, _provider?: IMetadataProvider): Promise<boolean>;
21
+ CompleteRun(handle: RunHandle, summary: ProcessRunSummary, _contextUser: UserInfo, _provider?: IMetadataProvider): Promise<void>;
22
+ LoadResumeCursor(handle: RunHandle, _contextUser: UserInfo, _provider?: IMetadataProvider): Promise<ProcessCursor | undefined>;
23
+ }
24
+ //# sourceMappingURL=GenericProcessRunTracker.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GenericProcessRunTracker.d.ts","sourceRoot":"","sources":["../../src/trackers/GenericProcessRunTracker.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAuB,iBAAiB,EAAsB,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAE5G,OAAO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