@memberjunction/record-set-processor 6.1.2 → 6.2.0-edge.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 (34) hide show
  1. package/dist/RecordProcessExecutor.d.ts +3 -1
  2. package/dist/RecordProcessExecutor.d.ts.map +1 -1
  3. package/dist/RecordProcessExecutor.js +86 -7
  4. package/dist/RecordProcessExecutor.js.map +1 -1
  5. package/dist/RecordSetProcessor.d.ts.map +1 -1
  6. package/dist/RecordSetProcessor.js +134 -2
  7. package/dist/RecordSetProcessor.js.map +1 -1
  8. package/dist/index.d.ts +1 -0
  9. package/dist/index.d.ts.map +1 -1
  10. package/dist/index.js +1 -0
  11. package/dist/index.js.map +1 -1
  12. package/dist/processors/ActionRecordProcessor.d.ts +2 -2
  13. package/dist/processors/ActionRecordProcessor.d.ts.map +1 -1
  14. package/dist/processors/ActionRecordProcessor.js.map +1 -1
  15. package/dist/processors/AgentRecordProcessor.d.ts +2 -2
  16. package/dist/processors/AgentRecordProcessor.d.ts.map +1 -1
  17. package/dist/processors/AgentRecordProcessor.js.map +1 -1
  18. package/dist/processors/InferProcessor.d.ts +84 -7
  19. package/dist/processors/InferProcessor.d.ts.map +1 -1
  20. package/dist/processors/InferProcessor.js +652 -14
  21. package/dist/processors/InferProcessor.js.map +1 -1
  22. package/dist/processors/WriteBackProcessor.d.ts +16 -2
  23. package/dist/processors/WriteBackProcessor.d.ts.map +1 -1
  24. package/dist/processors/WriteBackProcessor.js +85 -1
  25. package/dist/processors/WriteBackProcessor.js.map +1 -1
  26. package/dist/watermark/WatermarkService.d.ts +81 -0
  27. package/dist/watermark/WatermarkService.d.ts.map +1 -0
  28. package/dist/watermark/WatermarkService.js +224 -0
  29. package/dist/watermark/WatermarkService.js.map +1 -0
  30. package/dist/writeBack.d.ts +82 -19
  31. package/dist/writeBack.d.ts.map +1 -1
  32. package/dist/writeBack.js +372 -35
  33. package/dist/writeBack.js.map +1 -1
  34. package/package.json +16 -13
@@ -3,22 +3,99 @@
3
3
  * returns the structured result as the record's `ResultPayload`. Write-back is NOT done here: the
4
4
  * `WriteBackProcessor` wrapper (added by `RecordProcessExecutor` when an OutputMapping is set)
5
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).
10
+ *
6
11
  * @module @memberjunction/record-set-processor
7
12
  */
13
+ import { AIPromptParams, type AIPromptRunResult, type MJAIPromptEntityExtended } from '@memberjunction/ai-core-plus';
8
14
  import { IRecordProcessor, RecordProcessorContext, RecordRef, RecordResult } from '@memberjunction/record-set-processor-base';
15
+ import { DataFeatureSpec, DataFeatureOutput, type CacheKeyResult } from '@memberjunction/feature-pipelines';
16
+ import type { OutputMappingConfig } from '../writeBack.js';
9
17
  /** Runs an AI Prompt per record and returns its structured output (write-back is the wrapper's job). */
10
18
  export declare class InferProcessor implements IRecordProcessor {
11
- private readonly promptID;
12
- private readonly inputMapping?;
19
+ protected readonly promptID: string;
20
+ protected readonly inputMapping?: Record<string, string>;
21
+ protected readonly spec?: DataFeatureSpec;
13
22
  /**
14
23
  * @param promptID - The `MJ: AI Prompts` ID to run for each record.
15
24
  * @param inputMapping - Optional mapping shaping the data passed to the prompt (default: `{ record }`).
25
+ * @param spec - Optional DataFeatureSpec defining outputs, constraints, and caching policy.
16
26
  */
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;
27
+ constructor(promptID: string, inputMapping?: Record<string, string>, spec?: DataFeatureSpec);
28
+ ProcessRecord(record: RecordRef, context: RecordProcessorContext, options?: {
29
+ skipLookup?: boolean;
30
+ keyInfo?: CacheKeyResult;
31
+ }): Promise<RecordResult>;
32
+ /**
33
+ * Two-phase batch execution (P1-7c). Resolves distinct keys across the batch first,
34
+ * checks the dedup cache in one batch query, executes LLM prompts ONCE per distinct key,
35
+ * and fans results back across all matching rows.
36
+ */
37
+ ProcessBatch(records: RecordRef[], context: RecordProcessorContext): Promise<Map<string, RecordResult>>;
38
+ /** Computes a deterministic SHA-256 hash representing the prompt version and constraint instructions. */
39
+ protected computePromptVersionHash(prompt: MJAIPromptEntityExtended, spec?: DataFeatureSpec): string;
40
+ /** Computes a deterministic SHA-256 hash representing the output constraints. */
41
+ protected computeConstraintHash(spec?: DataFeatureSpec): string;
42
+ /**
43
+ * Records historical audit rows in MJ: Feature Values for all outputs on a record.
44
+ */
45
+ protected recordFeatureValuesHistory(params: {
46
+ record: RecordRef;
47
+ context: RecordProcessorContext;
48
+ payload: unknown;
49
+ reasoning?: string | null;
50
+ confidence?: number | null;
51
+ promptID?: string | null;
52
+ promptVersionHash?: string | null;
53
+ constraintHash?: string | null;
54
+ aiPromptRunID?: string | null;
55
+ featureValueCacheID?: string | null;
56
+ }): Promise<void>;
57
+ /**
58
+ * Computes the watermark basis hash for Checksum strategy:
59
+ * SHA-256 over canonical { promptData, promptVersionHash }.
60
+ */
61
+ ComputeBasisHash(record: RecordRef, context: RecordProcessorContext): Promise<string>;
62
+ /** Lifecycle hook called before prompt data context is constructed. */
63
+ protected beforeBuildContext(record: RecordRef, ctx: RecordProcessorContext): Promise<void>;
64
+ /** Lifecycle hook called immediately before ExecutePrompt is invoked. */
65
+ protected beforePromptExecute(params: AIPromptParams, record: RecordRef, ctx: RecordProcessorContext): Promise<void>;
66
+ /** Lifecycle hook called after prompt execution returns successfully. Defaults to returning result.result. */
67
+ protected afterPromptExecute(result: AIPromptRunResult<unknown>, record: RecordRef, ctx: RecordProcessorContext): Promise<unknown>;
68
+ /**
69
+ * Layer 2 output validation hook. Evaluates outputs against declared constraints, applies OnViolation
70
+ * policies (fail, null, coerce-to-other), and builds the processed payload.
71
+ */
72
+ protected validateOutputs(outputs: DataFeatureOutput[], rawResult: unknown, record: RecordRef, ctx: RecordProcessorContext): Promise<{
73
+ valid: boolean;
74
+ payload?: unknown;
75
+ errorMessage?: string;
76
+ }>;
77
+ /** Lifecycle hook to resolve a dedup cache key for this record. Default returns null (computed by cache service). */
78
+ protected resolveCacheKey(record: RecordRef, spec: DataFeatureSpec | undefined, ctx: RecordProcessorContext): Promise<string | null>;
79
+ /** Lifecycle hook called before write-back is executed on this record. */
80
+ beforeWriteBack(mapping: OutputMappingConfig | undefined, result: unknown, record: RecordRef, ctx: RecordProcessorContext): Promise<void>;
81
+ /**
82
+ * Builds the data object passed to the prompt.
83
+ * Incorporates spec.Context (EntityDocumentID rendering, QueryID parameterized execution, Field filtering),
84
+ * input mapping, and Layer-1 constraint instructions.
85
+ */
86
+ protected buildPromptData(record: RecordRef, ctx?: RecordProcessorContext): Promise<Record<string, unknown>>;
21
87
  /** Extracts a plain field map from the record (BaseEntity → GetAll(), plain object → as-is). */
22
- private recordToPlain;
88
+ protected recordToPlain(record: RecordRef): Record<string, unknown>;
89
+ /**
90
+ * Ensures that every record in the batch has its full field data loaded on `record.Record`.
91
+ * If records only have primary keys (as yielded by source pagination), batch-fetches the
92
+ * full records via RunView in a single query per entity.
93
+ */
94
+ protected ensureRecordsLoaded(records: RecordRef[], context: RecordProcessorContext): Promise<void>;
23
95
  }
96
+ /**
97
+ * Sets a value at a dot-delimited path (e.g. 'a.b' or 'items[0].name') on an object,
98
+ * mutating the object in-place and creating intermediate objects or arrays as needed.
99
+ */
100
+ export declare function setNestedValue(obj: Record<string, unknown>, path: string, value: unknown): void;
24
101
  //# sourceMappingURL=InferProcessor.d.ts.map
@@ -1 +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,YA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