@memberjunction/ai-agents 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.
- package/README.md +154 -7
- package/dist/AgentDataPreloader.d.ts +4 -2
- package/dist/AgentDataPreloader.d.ts.map +1 -1
- package/dist/AgentDataPreloader.js +21 -12
- package/dist/AgentDataPreloader.js.map +1 -1
- package/dist/AgentRunner.d.ts +61 -6
- package/dist/AgentRunner.d.ts.map +1 -1
- package/dist/AgentRunner.js +313 -68
- package/dist/AgentRunner.js.map +1 -1
- package/dist/AgentWakeTriggerService.d.ts +183 -0
- package/dist/AgentWakeTriggerService.d.ts.map +1 -0
- package/dist/AgentWakeTriggerService.js +478 -0
- package/dist/AgentWakeTriggerService.js.map +1 -0
- package/dist/ArtifactToolManager.d.ts +12 -3
- package/dist/ArtifactToolManager.d.ts.map +1 -1
- package/dist/ArtifactToolManager.js +77 -6
- package/dist/ArtifactToolManager.js.map +1 -1
- package/dist/ClientToolRequestManager.d.ts +11 -1
- package/dist/ClientToolRequestManager.d.ts.map +1 -1
- package/dist/ClientToolRequestManager.js +19 -6
- package/dist/ClientToolRequestManager.js.map +1 -1
- package/dist/ConversationToolManager.d.ts +1 -1
- package/dist/ConversationToolManager.d.ts.map +1 -1
- package/dist/ConversationToolManager.js +10 -4
- package/dist/ConversationToolManager.js.map +1 -1
- package/dist/MJAIAgentRequestEntityServer.d.ts.map +1 -1
- package/dist/MJAIAgentRequestEntityServer.js +20 -0
- package/dist/MJAIAgentRequestEntityServer.js.map +1 -1
- package/dist/PayloadChangeAnalyzer.d.ts.map +1 -1
- package/dist/PayloadChangeAnalyzer.js +53 -30
- package/dist/PayloadChangeAnalyzer.js.map +1 -1
- package/dist/PayloadManager.d.ts +35 -2
- package/dist/PayloadManager.d.ts.map +1 -1
- package/dist/PayloadManager.js +250 -149
- package/dist/PayloadManager.js.map +1 -1
- package/dist/ScratchpadManager.d.ts +18 -0
- package/dist/ScratchpadManager.d.ts.map +1 -1
- package/dist/ScratchpadManager.js +61 -0
- package/dist/ScratchpadManager.js.map +1 -1
- package/dist/agent-audience.d.ts +38 -0
- package/dist/agent-audience.d.ts.map +1 -0
- package/dist/agent-audience.js +99 -0
- package/dist/agent-audience.js.map +1 -0
- package/dist/agent-context-injector.d.ts +38 -6
- package/dist/agent-context-injector.d.ts.map +1 -1
- package/dist/agent-context-injector.js +72 -20
- package/dist/agent-context-injector.js.map +1 -1
- package/dist/agent-memory-context-builder.d.ts +7 -2
- package/dist/agent-memory-context-builder.d.ts.map +1 -1
- package/dist/agent-memory-context-builder.js +14 -5
- package/dist/agent-memory-context-builder.js.map +1 -1
- package/dist/agent-pre-execution-rag.d.ts +101 -9
- package/dist/agent-pre-execution-rag.d.ts.map +1 -1
- package/dist/agent-pre-execution-rag.js +227 -29
- package/dist/agent-pre-execution-rag.js.map +1 -1
- package/dist/agent-run-watchdog.d.ts +23 -8
- package/dist/agent-run-watchdog.d.ts.map +1 -1
- package/dist/agent-run-watchdog.js +141 -76
- package/dist/agent-run-watchdog.js.map +1 -1
- package/dist/agent-types/flow-agent-type.d.ts +15 -0
- package/dist/agent-types/flow-agent-type.d.ts.map +1 -1
- package/dist/agent-types/flow-agent-type.js +129 -13
- package/dist/agent-types/flow-agent-type.js.map +1 -1
- package/dist/agent-types/loop-agent-prompt-params.d.ts +6 -2
- package/dist/agent-types/loop-agent-prompt-params.d.ts.map +1 -1
- package/dist/agent-types/loop-agent-prompt-params.js.map +1 -1
- package/dist/agent-types/loop-agent-response-type.d.ts +8 -2
- package/dist/agent-types/loop-agent-response-type.d.ts.map +1 -1
- package/dist/agent-types/loop-agent-response-type.js.map +1 -1
- package/dist/agent-types/loop-agent-type.d.ts +85 -7
- package/dist/agent-types/loop-agent-type.d.ts.map +1 -1
- package/dist/agent-types/loop-agent-type.js +290 -66
- package/dist/agent-types/loop-agent-type.js.map +1 -1
- package/dist/base-agent.d.ts +809 -38
- package/dist/base-agent.d.ts.map +1 -1
- package/dist/base-agent.js +3308 -609
- package/dist/base-agent.js.map +1 -1
- package/dist/bound-action-params.d.ts +57 -0
- package/dist/bound-action-params.d.ts.map +1 -0
- package/dist/bound-action-params.js +91 -0
- package/dist/bound-action-params.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -1
- package/dist/memory-cleanup-agent.d.ts.map +1 -1
- package/dist/memory-cleanup-agent.js +3 -0
- package/dist/memory-cleanup-agent.js.map +1 -1
- package/dist/memory-manager-agent.d.ts.map +1 -1
- package/dist/memory-manager-agent.js +52 -35
- package/dist/memory-manager-agent.js.map +1 -1
- package/dist/native-tools/action-param-schema.d.ts +57 -0
- package/dist/native-tools/action-param-schema.d.ts.map +1 -0
- package/dist/native-tools/action-param-schema.js +238 -0
- package/dist/native-tools/action-param-schema.js.map +1 -0
- package/dist/native-tools/action-tool-builder.d.ts +5 -4
- package/dist/native-tools/action-tool-builder.d.ts.map +1 -1
- package/dist/native-tools/action-tool-builder.js +29 -71
- package/dist/native-tools/action-tool-builder.js.map +1 -1
- package/dist/native-tools/agent-tools.d.ts +64 -0
- package/dist/native-tools/agent-tools.d.ts.map +1 -0
- package/dist/native-tools/agent-tools.js +23 -0
- package/dist/native-tools/agent-tools.js.map +1 -0
- package/dist/native-tools/control-tools.d.ts +26 -4
- package/dist/native-tools/control-tools.d.ts.map +1 -1
- package/dist/native-tools/control-tools.js +114 -42
- package/dist/native-tools/control-tools.js.map +1 -1
- package/dist/native-tools/framework-tools.d.ts +47 -0
- package/dist/native-tools/framework-tools.d.ts.map +1 -0
- package/dist/native-tools/framework-tools.js +187 -0
- package/dist/native-tools/framework-tools.js.map +1 -0
- package/dist/native-tools/json-argument.d.ts +41 -0
- package/dist/native-tools/json-argument.d.ts.map +1 -0
- package/dist/native-tools/json-argument.js +79 -0
- package/dist/native-tools/json-argument.js.map +1 -0
- package/dist/native-tools/native-control-config.d.ts +93 -0
- package/dist/native-tools/native-control-config.d.ts.map +1 -0
- package/dist/native-tools/native-control-config.js +104 -0
- package/dist/native-tools/native-control-config.js.map +1 -0
- package/dist/native-tools/tool-result-turns.d.ts +41 -8
- package/dist/native-tools/tool-result-turns.d.ts.map +1 -1
- package/dist/native-tools/tool-result-turns.js +76 -2
- package/dist/native-tools/tool-result-turns.js.map +1 -1
- package/dist/native-tools/turn-mode.d.ts +8 -0
- package/dist/native-tools/turn-mode.d.ts.map +1 -0
- package/dist/native-tools/turn-mode.js +14 -0
- package/dist/native-tools/turn-mode.js.map +1 -0
- package/dist/query-builder-agent.d.ts +33 -5
- package/dist/query-builder-agent.d.ts.map +1 -1
- package/dist/query-builder-agent.js +137 -30
- package/dist/query-builder-agent.js.map +1 -1
- package/dist/realtime/bridge-room-transcript-sink.js +1 -0
- package/dist/realtime/bridge-room-transcript-sink.js.map +1 -1
- package/dist/realtime/bridge-session-transcript-sink.js +1 -0
- package/dist/realtime/bridge-session-transcript-sink.js.map +1 -1
- package/dist/realtime/realtime-client-session-service.d.ts +5 -4
- package/dist/realtime/realtime-client-session-service.d.ts.map +1 -1
- package/dist/realtime/realtime-client-session-service.js +42 -30
- package/dist/realtime/realtime-client-session-service.js.map +1 -1
- package/dist/realtime/realtime-coagent-config.d.ts +8 -1
- package/dist/realtime/realtime-coagent-config.d.ts.map +1 -1
- package/dist/realtime/realtime-coagent-config.js +17 -1
- package/dist/realtime/realtime-coagent-config.js.map +1 -1
- package/dist/realtime/realtime-recording-ledger.d.ts +150 -0
- package/dist/realtime/realtime-recording-ledger.d.ts.map +1 -0
- package/dist/realtime/realtime-recording-ledger.js +206 -0
- package/dist/realtime/realtime-recording-ledger.js.map +1 -0
- package/dist/realtime/realtime-recording-opus-assembly.d.ts +211 -0
- package/dist/realtime/realtime-recording-opus-assembly.d.ts.map +1 -0
- package/dist/realtime/realtime-recording-opus-assembly.js +706 -0
- package/dist/realtime/realtime-recording-opus-assembly.js.map +1 -0
- package/dist/realtime/realtime-recording-store.d.ts +44 -6
- package/dist/realtime/realtime-recording-store.d.ts.map +1 -1
- package/dist/realtime/realtime-recording-store.js +105 -51
- package/dist/realtime/realtime-recording-store.js.map +1 -1
- package/dist/realtime/realtime-turn-moderator.d.ts +2 -1
- package/dist/realtime/realtime-turn-moderator.d.ts.map +1 -1
- package/dist/realtime/realtime-turn-moderator.js +7 -1
- package/dist/realtime/realtime-turn-moderator.js.map +1 -1
- package/dist/volatile-child-prompt.js +3 -3
- package/package.json +21 -19
package/dist/PayloadManager.js
CHANGED
|
@@ -35,7 +35,7 @@ import { LogError, LogStatus } from '@memberjunction/core';
|
|
|
35
35
|
import { DeepDiffer } from '@memberjunction/global';
|
|
36
36
|
import _ from 'lodash';
|
|
37
37
|
import { PayloadChangeAnalyzer } from './PayloadChangeAnalyzer.js';
|
|
38
|
-
import { ParsePathWithOperations,
|
|
38
|
+
import { ParsePathWithOperations, isOperationAllowed } from './types/payload-operations.js';
|
|
39
39
|
/**
|
|
40
40
|
* Manages payload access control for agent hierarchies.
|
|
41
41
|
*
|
|
@@ -51,6 +51,11 @@ import { ParsePathWithOperations, ParsePathsWithOperations, isOperationAllowed }
|
|
|
51
51
|
* - Root wildcard: "*" (entire payload)
|
|
52
52
|
*/
|
|
53
53
|
export class PayloadManager {
|
|
54
|
+
constructor() {
|
|
55
|
+
this._defaultAnalyzer = new PayloadChangeAnalyzer();
|
|
56
|
+
this._defaultDiffer = new DeepDiffer();
|
|
57
|
+
this._pathPatternRegexCache = new Map();
|
|
58
|
+
}
|
|
54
59
|
/**
|
|
55
60
|
* Extracts only the allowed paths from a payload for downstream transmission.
|
|
56
61
|
*
|
|
@@ -139,12 +144,10 @@ export class PayloadManager {
|
|
|
139
144
|
blockedOperations
|
|
140
145
|
};
|
|
141
146
|
}
|
|
142
|
-
// Start with a deep clone of the parent payload
|
|
143
|
-
const result = _.cloneDeep(parentPayload || {});
|
|
144
147
|
const counts = { additions: 0, updates: 0, deletions: 0 };
|
|
145
|
-
// Handle wildcard - merge everything
|
|
148
|
+
// Handle wildcard - merge everything (DeepMerge already returns a newly cloned object)
|
|
146
149
|
if (upstreamPaths.includes('*')) {
|
|
147
|
-
const merged = this.DeepMerge(
|
|
150
|
+
const merged = this.DeepMerge((parentPayload || {}), subAgentPayload);
|
|
148
151
|
// Count changes
|
|
149
152
|
this.countChanges(parentPayload, merged, counts);
|
|
150
153
|
return {
|
|
@@ -155,6 +158,8 @@ export class PayloadManager {
|
|
|
155
158
|
blockedOperations
|
|
156
159
|
};
|
|
157
160
|
}
|
|
161
|
+
// Start with a fast deep clone of the parent payload
|
|
162
|
+
const result = this.fastCloneDeep(parentPayload || {});
|
|
158
163
|
// Check each path in the sub-agent payload
|
|
159
164
|
const mergeResult = this.mergeAllowedPaths(result, subAgentPayload, upstreamPaths, subAgentName, verbose);
|
|
160
165
|
return {
|
|
@@ -315,6 +320,8 @@ export class PayloadManager {
|
|
|
315
320
|
mergeAllowedPaths(result, subAgentPayload, upstreamPaths, subAgentName, verbose) {
|
|
316
321
|
// Get all paths from sub-agent payload
|
|
317
322
|
const subAgentPaths = this.getAllPaths(subAgentPayload);
|
|
323
|
+
const parsedUpstreamRules = this.getParsedPatternRules(upstreamPaths);
|
|
324
|
+
const counts = { additions: 0, updates: 0, deletions: 0 };
|
|
318
325
|
// Track unauthorized changes for consolidated warning
|
|
319
326
|
const unauthorizedChanges = [];
|
|
320
327
|
// Check each path against allowed patterns
|
|
@@ -324,15 +331,21 @@ export class PayloadManager {
|
|
|
324
331
|
// Determine the operation type
|
|
325
332
|
const operation = originalValue === undefined ? 'add' : 'update';
|
|
326
333
|
// Check if the operation is allowed for this path
|
|
327
|
-
const isOperationAllowed = this.isOperationAllowedForPath(actualPath, operation, upstreamPaths);
|
|
334
|
+
const isOperationAllowed = this.isOperationAllowedForPath(actualPath, operation, upstreamPaths, parsedUpstreamRules);
|
|
328
335
|
if (isOperationAllowed) {
|
|
329
|
-
|
|
336
|
+
if (operation === 'add') {
|
|
337
|
+
counts.additions++;
|
|
338
|
+
}
|
|
339
|
+
else if (!_.isEqual(originalValue, subAgentValue)) {
|
|
340
|
+
counts.updates++;
|
|
341
|
+
}
|
|
342
|
+
_.set(result, actualPath, this.fastCloneDeep(subAgentValue));
|
|
330
343
|
}
|
|
331
344
|
else {
|
|
332
345
|
// Only track if the sub-agent is trying to change the value
|
|
333
346
|
if (!_.isEqual(subAgentValue, originalValue)) {
|
|
334
347
|
// Check if any operation is allowed on this path
|
|
335
|
-
const isPathAllowed = this.isPathAllowed(actualPath, upstreamPaths);
|
|
348
|
+
const isPathAllowed = this.isPathAllowed(actualPath, upstreamPaths, parsedUpstreamRules);
|
|
336
349
|
unauthorizedChanges.push({
|
|
337
350
|
path: actualPath,
|
|
338
351
|
from: originalValue,
|
|
@@ -355,14 +368,15 @@ export class PayloadManager {
|
|
|
355
368
|
// If the path exists in result but not in subAgentPayload, it's a deletion attempt
|
|
356
369
|
if (resultValue !== undefined && subAgentValue === undefined) {
|
|
357
370
|
// Check if delete operation is allowed
|
|
358
|
-
const isDeleteAllowed = this.isOperationAllowedForPath(resultPath, 'delete', upstreamPaths);
|
|
371
|
+
const isDeleteAllowed = this.isOperationAllowedForPath(resultPath, 'delete', upstreamPaths, parsedUpstreamRules);
|
|
359
372
|
if (isDeleteAllowed) {
|
|
360
373
|
// Delete the path from result
|
|
361
374
|
_.unset(result, resultPath);
|
|
362
375
|
vacatedPaths.push(resultPath);
|
|
376
|
+
counts.deletions++;
|
|
363
377
|
}
|
|
364
378
|
else {
|
|
365
|
-
const isPathAllowed = this.isPathAllowed(resultPath, upstreamPaths);
|
|
379
|
+
const isPathAllowed = this.isPathAllowed(resultPath, upstreamPaths, parsedUpstreamRules);
|
|
366
380
|
unauthorizedChanges.push({
|
|
367
381
|
path: resultPath,
|
|
368
382
|
from: resultValue,
|
|
@@ -379,26 +393,8 @@ export class PayloadManager {
|
|
|
379
393
|
this.pruneVacatedArrayElements(result, vacatedPaths);
|
|
380
394
|
// Clean up any empty objects that resulted from property deletions in arrays
|
|
381
395
|
this.cleanupEmptyArrayElements(result);
|
|
382
|
-
// Initialize counts
|
|
383
|
-
const counts = { additions: 0, updates: 0, deletions: 0 };
|
|
384
396
|
const warnings = [];
|
|
385
397
|
const blockedOperations = [];
|
|
386
|
-
// Count successful operations
|
|
387
|
-
const parentPayload = arguments[2]; // The original parent payload parameter
|
|
388
|
-
for (const path of subAgentPaths) {
|
|
389
|
-
const mergedValue = _.get(result, path);
|
|
390
|
-
const subAgentValue = _.get(subAgentPayload, path);
|
|
391
|
-
if (_.isEqual(mergedValue, subAgentValue)) {
|
|
392
|
-
// This change was allowed and applied
|
|
393
|
-
const originalParentValue = _.get(parentPayload || {}, path);
|
|
394
|
-
if (originalParentValue === undefined) {
|
|
395
|
-
counts.additions++;
|
|
396
|
-
}
|
|
397
|
-
else if (!_.isEqual(originalParentValue, subAgentValue)) {
|
|
398
|
-
counts.updates++;
|
|
399
|
-
}
|
|
400
|
-
}
|
|
401
|
-
}
|
|
402
398
|
// Output consolidated warning if there were unauthorized changes
|
|
403
399
|
if (unauthorizedChanges.length > 0) {
|
|
404
400
|
// Convert to blocked operations format
|
|
@@ -714,51 +710,76 @@ export class PayloadManager {
|
|
|
714
710
|
}
|
|
715
711
|
}
|
|
716
712
|
}
|
|
713
|
+
getPathPatternRegex(pathPattern) {
|
|
714
|
+
let compiled = this._pathPatternRegexCache.get(pathPattern);
|
|
715
|
+
if (compiled) {
|
|
716
|
+
return compiled;
|
|
717
|
+
}
|
|
718
|
+
if (pathPattern.includes('**')) {
|
|
719
|
+
const regexStr = pathPattern
|
|
720
|
+
.replace(/\\/g, '\\\\')
|
|
721
|
+
.replace(/\./g, '\\.')
|
|
722
|
+
.replace(/\*\*/g, '.*')
|
|
723
|
+
.replace(/\*/g, '[^.]+');
|
|
724
|
+
compiled = new RegExp(`^${regexStr}$`);
|
|
725
|
+
}
|
|
726
|
+
else if (pathPattern.endsWith('.*')) {
|
|
727
|
+
const basePath = pathPattern.slice(0, -2);
|
|
728
|
+
const escapedBase = basePath.replace(/\\/g, '\\\\').replace(/\./g, '\\.');
|
|
729
|
+
compiled = new RegExp(`^${escapedBase}(\\..*)?$`);
|
|
730
|
+
}
|
|
731
|
+
else {
|
|
732
|
+
const regexStr = pathPattern
|
|
733
|
+
.replace(/\\/g, '\\\\')
|
|
734
|
+
.replace(/\./g, '\\.')
|
|
735
|
+
.replace(/\*/g, '[^.]+')
|
|
736
|
+
.replace(/\[(\*|\d+)\]/g, '\\[(\\*|\\d+)\\]');
|
|
737
|
+
compiled = new RegExp(`^${regexStr}$`);
|
|
738
|
+
}
|
|
739
|
+
this._pathPatternRegexCache.set(pathPattern, compiled);
|
|
740
|
+
return compiled;
|
|
741
|
+
}
|
|
742
|
+
/**
|
|
743
|
+
* Static cache for parsed path specifications (`ParsePathWithOperations`).
|
|
744
|
+
* Avoids re-parsing pattern strings on every payload path during upstream merges
|
|
745
|
+
* and change-request validation.
|
|
746
|
+
*
|
|
747
|
+
* @private
|
|
748
|
+
*/
|
|
749
|
+
static { this._parsedPathSpecCache = new Map(); }
|
|
750
|
+
/**
|
|
751
|
+
* Returns the parsed `ParsedPathWithOperations` list for `allowedPatterns`, using the static
|
|
752
|
+
* per-spec cache (or returning `preParsedPatterns` directly when already computed by the caller).
|
|
753
|
+
*
|
|
754
|
+
* @private
|
|
755
|
+
*/
|
|
756
|
+
getParsedPatternRules(allowedPatterns, preParsedPatterns) {
|
|
757
|
+
if (preParsedPatterns) {
|
|
758
|
+
return preParsedPatterns;
|
|
759
|
+
}
|
|
760
|
+
return allowedPatterns.map((spec) => {
|
|
761
|
+
let cached = PayloadManager._parsedPathSpecCache.get(spec);
|
|
762
|
+
if (!cached) {
|
|
763
|
+
cached = ParsePathWithOperations(spec);
|
|
764
|
+
PayloadManager._parsedPathSpecCache.set(spec, cached);
|
|
765
|
+
}
|
|
766
|
+
return cached;
|
|
767
|
+
});
|
|
768
|
+
}
|
|
717
769
|
/**
|
|
718
770
|
* Checks if a path matches any of the allowed patterns.
|
|
719
771
|
*
|
|
720
772
|
* @private
|
|
721
773
|
*/
|
|
722
|
-
isPathAllowed(actualPath, allowedPatterns) {
|
|
774
|
+
isPathAllowed(actualPath, allowedPatterns, preParsedPatterns) {
|
|
723
775
|
const normalizedPath = actualPath.replace(/\[(\d+)\]/g, '.$1');
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
const parsedPattern = ParsePathWithOperations(pattern);
|
|
776
|
+
const parsedPatterns = this.getParsedPatternRules(allowedPatterns, preParsedPatterns);
|
|
777
|
+
for (const parsedPattern of parsedPatterns) {
|
|
727
778
|
const pathPattern = parsedPattern.path;
|
|
728
779
|
if (pathPattern === '*')
|
|
729
780
|
return true;
|
|
730
|
-
if (pathPattern.
|
|
731
|
-
|
|
732
|
-
const regex = pathPattern
|
|
733
|
-
.replace(/\./g, '\\.')
|
|
734
|
-
.replace(/\*\*/g, '.*')
|
|
735
|
-
.replace(/\*/g, '[^.]+');
|
|
736
|
-
if (new RegExp(`^${regex}$`).test(normalizedPath)) {
|
|
737
|
-
return true;
|
|
738
|
-
}
|
|
739
|
-
}
|
|
740
|
-
else {
|
|
741
|
-
// Handle regular patterns
|
|
742
|
-
// Check if pattern ends with .* which means "everything under this path"
|
|
743
|
-
if (pathPattern.endsWith('.*')) {
|
|
744
|
-
const basePath = pathPattern.slice(0, -2); // Remove the .*
|
|
745
|
-
const escapedBase = basePath.replace(/\./g, '\\.');
|
|
746
|
-
// Match the base path followed by a dot and anything after
|
|
747
|
-
const regex = `^${escapedBase}(\\..*)?$`;
|
|
748
|
-
if (new RegExp(regex).test(normalizedPath)) {
|
|
749
|
-
return true;
|
|
750
|
-
}
|
|
751
|
-
}
|
|
752
|
-
else {
|
|
753
|
-
// Handle other wildcard patterns
|
|
754
|
-
const regex = pathPattern
|
|
755
|
-
.replace(/\./g, '\\.')
|
|
756
|
-
.replace(/\*/g, '[^.]+')
|
|
757
|
-
.replace(/\[(\*|\d+)\]/g, '\\[(\\*|\\d+)\\]');
|
|
758
|
-
if (new RegExp(`^${regex}$`).test(normalizedPath)) {
|
|
759
|
-
return true;
|
|
760
|
-
}
|
|
761
|
-
}
|
|
781
|
+
if (this.getPathPatternRegex(pathPattern).test(normalizedPath)) {
|
|
782
|
+
return true;
|
|
762
783
|
}
|
|
763
784
|
}
|
|
764
785
|
return false;
|
|
@@ -769,41 +790,15 @@ export class PayloadManager {
|
|
|
769
790
|
* @param actualPath The actual path to check
|
|
770
791
|
* @param operation The operation to check
|
|
771
792
|
* @param allowedPatterns Array of allowed patterns with optional operations
|
|
793
|
+
* @param preParsedPatterns Optional pre-parsed pattern rules to avoid re-parsing in hot loops
|
|
772
794
|
* @returns True if the operation is allowed on this path
|
|
773
795
|
*/
|
|
774
|
-
isOperationAllowedForPath(actualPath, operation, allowedPatterns) {
|
|
796
|
+
isOperationAllowedForPath(actualPath, operation, allowedPatterns, preParsedPatterns) {
|
|
775
797
|
const normalizedPath = actualPath.replace(/\[(\d+)\]/g, '.$1');
|
|
776
|
-
const parsedPatterns =
|
|
798
|
+
const parsedPatterns = this.getParsedPatternRules(allowedPatterns, preParsedPatterns);
|
|
777
799
|
for (const parsedPattern of parsedPatterns) {
|
|
778
800
|
const pathPattern = parsedPattern.path;
|
|
779
|
-
|
|
780
|
-
if (pathPattern === '*') {
|
|
781
|
-
pathMatches = true;
|
|
782
|
-
}
|
|
783
|
-
else if (pathPattern.includes('**')) {
|
|
784
|
-
// Handle deep wildcards
|
|
785
|
-
const regex = pathPattern
|
|
786
|
-
.replace(/\./g, '\\.')
|
|
787
|
-
.replace(/\*\*/g, '.*')
|
|
788
|
-
.replace(/\*/g, '[^.]+');
|
|
789
|
-
pathMatches = new RegExp(`^${regex}$`).test(normalizedPath);
|
|
790
|
-
}
|
|
791
|
-
else {
|
|
792
|
-
// Handle regular patterns
|
|
793
|
-
if (pathPattern.endsWith('.*')) {
|
|
794
|
-
const basePath = pathPattern.slice(0, -2);
|
|
795
|
-
const escapedBase = basePath.replace(/\./g, '\\.');
|
|
796
|
-
const regex = `^${escapedBase}(\\..*)?$`;
|
|
797
|
-
pathMatches = new RegExp(regex).test(normalizedPath);
|
|
798
|
-
}
|
|
799
|
-
else {
|
|
800
|
-
const regex = pathPattern
|
|
801
|
-
.replace(/\./g, '\\.')
|
|
802
|
-
.replace(/\*/g, '[^.]+')
|
|
803
|
-
.replace(/\[(\*|\d+)\]/g, '\\[(\\*|\\d+)\\]');
|
|
804
|
-
pathMatches = new RegExp(`^${regex}$`).test(normalizedPath);
|
|
805
|
-
}
|
|
806
|
-
}
|
|
801
|
+
const pathMatches = pathPattern === '*' || this.getPathPatternRegex(pathPattern).test(normalizedPath);
|
|
807
802
|
// If path matches, check if operation is allowed
|
|
808
803
|
if (pathMatches && isOperationAllowed(parsedPattern, operation)) {
|
|
809
804
|
return true;
|
|
@@ -870,18 +865,29 @@ export class PayloadManager {
|
|
|
870
865
|
if (!source)
|
|
871
866
|
return destination;
|
|
872
867
|
if (!destination)
|
|
873
|
-
return
|
|
874
|
-
const
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
868
|
+
return this.fastCloneDeep(source);
|
|
869
|
+
const destObj = destination;
|
|
870
|
+
const srcObj = source;
|
|
871
|
+
const result = {};
|
|
872
|
+
for (const key of Object.keys(destObj)) {
|
|
873
|
+
if (!Object.prototype.hasOwnProperty.call(srcObj, key)) {
|
|
874
|
+
result[key] = this.fastCloneDeep(destObj[key]);
|
|
875
|
+
}
|
|
876
|
+
else {
|
|
877
|
+
result[key] = undefined;
|
|
878
|
+
}
|
|
879
|
+
}
|
|
880
|
+
for (const key of Object.keys(srcObj)) {
|
|
881
|
+
const srcVal = srcObj[key];
|
|
882
|
+
const destVal = destObj[key];
|
|
883
|
+
// Only plain objects merge key by key. A Date or class instance has no own keys to merge,
|
|
884
|
+
// so recursing would collapse it to `{}`; like an array or primitive, it replaces the
|
|
885
|
+
// destination value.
|
|
886
|
+
if (this.isPlainObject(srcVal) && this.isPlainObject(destVal)) {
|
|
887
|
+
result[key] = this.DeepMerge(destVal, srcVal);
|
|
888
|
+
}
|
|
889
|
+
else {
|
|
890
|
+
result[key] = this.fastCloneDeep(srcVal);
|
|
885
891
|
}
|
|
886
892
|
}
|
|
887
893
|
return result;
|
|
@@ -890,6 +896,67 @@ export class PayloadManager {
|
|
|
890
896
|
deepMerge(destination, source) {
|
|
891
897
|
return this.DeepMerge(destination, source);
|
|
892
898
|
}
|
|
899
|
+
/** True for an object literal or `Object.create(null)` object: not an array, Date or class instance. */
|
|
900
|
+
isPlainObject(value) {
|
|
901
|
+
if (value === null || typeof value !== 'object' || Array.isArray(value)) {
|
|
902
|
+
return false;
|
|
903
|
+
}
|
|
904
|
+
const proto = Object.getPrototypeOf(value);
|
|
905
|
+
return proto === Object.prototype || proto === null;
|
|
906
|
+
}
|
|
907
|
+
/**
|
|
908
|
+
* Fast deep-clone for JSON-like payload trees (plain objects, arrays, primitives),
|
|
909
|
+
* falling back to lodash `_.cloneDeep` for exotic instances (Date, Map, Set, etc.).
|
|
910
|
+
*/
|
|
911
|
+
fastCloneDeep(value) {
|
|
912
|
+
if (value === null || typeof value !== 'object') {
|
|
913
|
+
return value;
|
|
914
|
+
}
|
|
915
|
+
if (Array.isArray(value)) {
|
|
916
|
+
const len = value.length;
|
|
917
|
+
const copy = new Array(len);
|
|
918
|
+
for (let i = 0; i < len; i++) {
|
|
919
|
+
const item = value[i];
|
|
920
|
+
copy[i] = (item !== null && typeof item === 'object') ? this.fastCloneDeep(item) : item;
|
|
921
|
+
}
|
|
922
|
+
return copy;
|
|
923
|
+
}
|
|
924
|
+
if (this.isPlainObject(value)) {
|
|
925
|
+
const copy = {};
|
|
926
|
+
const keys = Object.keys(value);
|
|
927
|
+
for (let i = 0; i < keys.length; i++) {
|
|
928
|
+
const k = keys[i];
|
|
929
|
+
const val = value[k];
|
|
930
|
+
copy[k] = (val !== null && typeof val === 'object') ? this.fastCloneDeep(val) : val;
|
|
931
|
+
}
|
|
932
|
+
return copy;
|
|
933
|
+
}
|
|
934
|
+
return _.cloneDeep(value);
|
|
935
|
+
}
|
|
936
|
+
/**
|
|
937
|
+
* Returns true if any property key inside a changeRequest bucket contains '.' or '['
|
|
938
|
+
* (e.g. from TransformChangeRequestPaths).
|
|
939
|
+
*/
|
|
940
|
+
hasDottedKeys(obj) {
|
|
941
|
+
if (!obj || typeof obj !== 'object')
|
|
942
|
+
return false;
|
|
943
|
+
if (Array.isArray(obj)) {
|
|
944
|
+
for (let i = 0; i < obj.length; i++) {
|
|
945
|
+
if (this.hasDottedKeys(obj[i]))
|
|
946
|
+
return true;
|
|
947
|
+
}
|
|
948
|
+
return false;
|
|
949
|
+
}
|
|
950
|
+
const keys = Object.keys(obj);
|
|
951
|
+
for (let i = 0; i < keys.length; i++) {
|
|
952
|
+
const k = keys[i];
|
|
953
|
+
if (k.includes('.') || k.includes('['))
|
|
954
|
+
return true;
|
|
955
|
+
if (this.hasDottedKeys(obj[k]))
|
|
956
|
+
return true;
|
|
957
|
+
}
|
|
958
|
+
return false;
|
|
959
|
+
}
|
|
893
960
|
/**
|
|
894
961
|
* Applies an AgentPayloadChangeRequest to a payload
|
|
895
962
|
*
|
|
@@ -906,12 +973,16 @@ export class PayloadManager {
|
|
|
906
973
|
// siblings of updateElements/newElements instead of inside them. This detects those
|
|
907
974
|
// stray keys and moves them into the appropriate bucket so the changes aren't silently lost.
|
|
908
975
|
if (!options?.ignoreStrayKeys) {
|
|
909
|
-
this.autoCorrectStrayKeys(changeRequest, originalPayload, warnings, options?.agentName);
|
|
976
|
+
this.autoCorrectStrayKeys(changeRequest, originalPayload, warnings, options?.agentName, options?.allowedPaths);
|
|
910
977
|
}
|
|
911
|
-
const result =
|
|
978
|
+
const result = this.fastCloneDeep(originalPayload) || {};
|
|
912
979
|
const counts = { additions: 0, updates: 0, deletions: 0 };
|
|
980
|
+
const requestHasDottedKeys = this.hasDottedKeys(changeRequest.newElements) ||
|
|
981
|
+
this.hasDottedKeys(changeRequest.updateElements) ||
|
|
982
|
+
this.hasDottedKeys(changeRequest.removeElements) ||
|
|
983
|
+
this.hasDottedKeys(changeRequest.replaceElements);
|
|
913
984
|
// Process all changes recursively
|
|
914
|
-
this.processChangeRequest(result, originalPayload, changeRequest, [], counts, warnings, options?.allowedPaths, blockedOperations);
|
|
985
|
+
this.processChangeRequest(result, originalPayload, changeRequest, [], counts, warnings, options?.allowedPaths, blockedOperations, requestHasDottedKeys);
|
|
915
986
|
// Log if requested and in verbose mode
|
|
916
987
|
if (options?.logChanges && options?.verbose) {
|
|
917
988
|
this.logChangesSummary(counts, changeRequest.reasoning, options.agentName);
|
|
@@ -919,8 +990,7 @@ export class PayloadManager {
|
|
|
919
990
|
// Analyze changes if requested
|
|
920
991
|
let analysis;
|
|
921
992
|
if (options?.analyzeChanges !== false) { // Default to true
|
|
922
|
-
|
|
923
|
-
analysis = analyzer.analyzeChangeRequest(originalPayload, changeRequest, result);
|
|
993
|
+
analysis = this._defaultAnalyzer.AnalyzeChangeRequest(originalPayload, changeRequest, result);
|
|
924
994
|
// Add analysis warnings to the main warnings array
|
|
925
995
|
if (analysis.warnings.length > 0) {
|
|
926
996
|
warnings.push(...analysis.warnings.map(w => `[${w.severity}] ${w.message}`));
|
|
@@ -929,8 +999,7 @@ export class PayloadManager {
|
|
|
929
999
|
// Generate diff if requested
|
|
930
1000
|
let diff;
|
|
931
1001
|
if (options?.generateDiff !== false) { // Default to true
|
|
932
|
-
|
|
933
|
-
diff = differ.diff(originalPayload, result);
|
|
1002
|
+
diff = this._defaultDiffer.Diff(originalPayload, result);
|
|
934
1003
|
}
|
|
935
1004
|
return {
|
|
936
1005
|
result,
|
|
@@ -950,26 +1019,31 @@ export class PayloadManager {
|
|
|
950
1019
|
/**
|
|
951
1020
|
* Process a change request recursively through the payload structure
|
|
952
1021
|
*/
|
|
953
|
-
processChangeRequest(target, original, changeRequest, path, counts, warnings, allowedPaths, blockedOperations) {
|
|
1022
|
+
processChangeRequest(target, original, changeRequest, path, counts, warnings, allowedPaths, blockedOperations, requestHasDottedKeys = false) {
|
|
954
1023
|
if (Array.isArray(target)) {
|
|
955
|
-
this.processArrayChanges(target, original, changeRequest, path, counts, warnings, allowedPaths, blockedOperations);
|
|
1024
|
+
this.processArrayChanges(target, original, changeRequest, path, counts, warnings, allowedPaths, blockedOperations, requestHasDottedKeys);
|
|
956
1025
|
}
|
|
957
1026
|
else if (typeof target === 'object' && target !== null) {
|
|
958
|
-
this.processObjectChanges(target, original, changeRequest, path, counts, warnings, allowedPaths, blockedOperations);
|
|
1027
|
+
this.processObjectChanges(target, original, changeRequest, path, counts, warnings, allowedPaths, blockedOperations, requestHasDottedKeys);
|
|
959
1028
|
}
|
|
960
1029
|
}
|
|
961
1030
|
/**
|
|
962
1031
|
* Detects and auto-corrects stray keys in a payloadChangeRequest.
|
|
963
1032
|
* LLMs sometimes place payload properties as siblings of updateElements/newElements
|
|
964
|
-
* instead of nesting them inside
|
|
1033
|
+
* instead of nesting them inside, or wrap payload properties inside an alias object
|
|
1034
|
+
* such as `setFields` / `setElements`. This method moves those stray keys into the
|
|
965
1035
|
* appropriate bucket (updateElements if the key exists on the payload, newElements if not).
|
|
966
1036
|
*
|
|
967
1037
|
* Only keys starting with a letter (a-z, A-Z) are considered — keys starting with
|
|
968
1038
|
* underscore, dollar sign, or other non-letter characters are left alone as they may
|
|
969
1039
|
* be internal markers.
|
|
970
1040
|
*/
|
|
971
|
-
autoCorrectStrayKeys(changeRequest, originalPayload, warnings, agentName) {
|
|
1041
|
+
autoCorrectStrayKeys(changeRequest, originalPayload, warnings, agentName, allowedPaths) {
|
|
972
1042
|
const recognizedKeys = new Set(['newElements', 'updateElements', 'replaceElements', 'removeElements', 'reasoning']);
|
|
1043
|
+
const wrapperAliasKeys = new Set([
|
|
1044
|
+
'setFields', 'setElements', 'createElements', 'addElements',
|
|
1045
|
+
'modifyElements', 'patchElements', 'updates', 'fields', 'set', 'add'
|
|
1046
|
+
]);
|
|
973
1047
|
const strayKeys = [];
|
|
974
1048
|
for (const key of Object.keys(changeRequest)) {
|
|
975
1049
|
if (recognizedKeys.has(key))
|
|
@@ -982,9 +1056,8 @@ export class PayloadManager {
|
|
|
982
1056
|
if (strayKeys.length === 0)
|
|
983
1057
|
return;
|
|
984
1058
|
const prefix = agentName ? `[PayloadManager:${agentName}]` : '[PayloadManager]';
|
|
985
|
-
|
|
986
|
-
const
|
|
987
|
-
const existsOnPayload = originalPayload && typeof originalPayload === 'object' && key in originalPayload;
|
|
1059
|
+
const placeKeyInBucket = (targetKey, targetValue, unwrappedFrom) => {
|
|
1060
|
+
const existsOnPayload = originalPayload && typeof originalPayload === 'object' && targetKey in originalPayload;
|
|
988
1061
|
const targetBucket = existsOnPayload ? 'updateElements' : 'newElements';
|
|
989
1062
|
// Ensure the target bucket exists
|
|
990
1063
|
if (!changeRequest[targetBucket]) {
|
|
@@ -992,24 +1065,50 @@ export class PayloadManager {
|
|
|
992
1065
|
}
|
|
993
1066
|
// Deep-merge the stray value into the target bucket (don't overwrite existing explicit entries)
|
|
994
1067
|
const bucket = changeRequest[targetBucket];
|
|
995
|
-
if (
|
|
1068
|
+
if (targetKey in bucket) {
|
|
996
1069
|
// Existing explicit entry takes precedence — merge stray value underneath
|
|
997
|
-
if (typeof bucket[
|
|
998
|
-
typeof
|
|
999
|
-
!Array.isArray(bucket[
|
|
1070
|
+
if (typeof bucket[targetKey] === 'object' && bucket[targetKey] !== null &&
|
|
1071
|
+
typeof targetValue === 'object' && targetValue !== null &&
|
|
1072
|
+
!Array.isArray(bucket[targetKey]) && !Array.isArray(targetValue)) {
|
|
1000
1073
|
// Deep merge: stray values fill in gaps, explicit values win
|
|
1001
|
-
bucket[
|
|
1074
|
+
bucket[targetKey] = _.defaultsDeep(bucket[targetKey], targetValue);
|
|
1002
1075
|
}
|
|
1003
1076
|
// For primitives or mismatched types, explicit entry wins — skip
|
|
1004
1077
|
}
|
|
1005
1078
|
else {
|
|
1006
|
-
bucket[
|
|
1079
|
+
bucket[targetKey] = targetValue;
|
|
1007
1080
|
}
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1081
|
+
const warningMsg = unwrappedFrom
|
|
1082
|
+
? `${prefix} Auto-corrected stray key "${targetKey}" (unwrapped from "${unwrappedFrom}") in payloadChangeRequest — moved to ${targetBucket}`
|
|
1083
|
+
: `${prefix} Auto-corrected stray key "${targetKey}" in payloadChangeRequest — moved to ${targetBucket}`;
|
|
1011
1084
|
warnings.push(warningMsg);
|
|
1012
1085
|
console.warn(`⚠️ ${warningMsg}`);
|
|
1086
|
+
};
|
|
1087
|
+
for (const key of strayKeys) {
|
|
1088
|
+
const value = changeRequest[key];
|
|
1089
|
+
const existsOnPayload = originalPayload && typeof originalPayload === 'object' && key in originalPayload;
|
|
1090
|
+
const isPlainObject = typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
1091
|
+
if (isPlainObject && !existsOnPayload) {
|
|
1092
|
+
const innerEntries = Object.entries(value);
|
|
1093
|
+
const isExplicitlyInAllowedPaths = Boolean(allowedPaths &&
|
|
1094
|
+
allowedPaths.some(p => p === key || p.startsWith(`${key}.`) || p.startsWith(`${key}:`)));
|
|
1095
|
+
const isAllowedDirectly = !allowedPaths || this.isOperationAllowedForPath(key, 'add', allowedPaths);
|
|
1096
|
+
const isKnownWrapperAlias = wrapperAliasKeys.has(key) && !isExplicitlyInAllowedPaths;
|
|
1097
|
+
const isDisallowedWrapperOfAllowedKeys = Boolean(allowedPaths &&
|
|
1098
|
+
!isAllowedDirectly &&
|
|
1099
|
+
innerEntries.length > 0 &&
|
|
1100
|
+
innerEntries.every(([ik]) => this.isOperationAllowedForPath(ik, 'add', allowedPaths) ||
|
|
1101
|
+
this.isOperationAllowedForPath(ik, 'update', allowedPaths)));
|
|
1102
|
+
if (isKnownWrapperAlias || isDisallowedWrapperOfAllowedKeys) {
|
|
1103
|
+
for (const [innerKey, innerValue] of innerEntries) {
|
|
1104
|
+
placeKeyInBucket(innerKey, innerValue, key);
|
|
1105
|
+
}
|
|
1106
|
+
delete changeRequest[key];
|
|
1107
|
+
continue;
|
|
1108
|
+
}
|
|
1109
|
+
}
|
|
1110
|
+
placeKeyInBucket(key, value);
|
|
1111
|
+
delete changeRequest[key];
|
|
1013
1112
|
}
|
|
1014
1113
|
}
|
|
1015
1114
|
/**
|
|
@@ -1026,12 +1125,13 @@ export class PayloadManager {
|
|
|
1026
1125
|
*
|
|
1027
1126
|
* Arrays of primitives still use replacement behavior for backwards compatibility.
|
|
1028
1127
|
*/
|
|
1029
|
-
processArrayChanges(target, original, changeRequest, path, counts, warnings, allowedPaths, blockedOperations) {
|
|
1128
|
+
processArrayChanges(target, original, changeRequest, path, counts, warnings, allowedPaths, blockedOperations, requestHasDottedKeys = false) {
|
|
1030
1129
|
const pathStr = path.join('.');
|
|
1031
1130
|
// Get change arrays for this path
|
|
1032
1131
|
const removeArray = pathStr ? _.get(changeRequest.removeElements, pathStr) : changeRequest.removeElements;
|
|
1033
1132
|
const updateArray = pathStr ? _.get(changeRequest.updateElements, pathStr) : changeRequest.updateElements;
|
|
1034
1133
|
const newArray = pathStr ? _.get(changeRequest.newElements, pathStr) : changeRequest.newElements;
|
|
1134
|
+
const replaceArray = pathStr ? _.get(changeRequest.replaceElements, pathStr) : changeRequest.replaceElements;
|
|
1035
1135
|
// Build a new array with all changes applied
|
|
1036
1136
|
const newTargetArray = [];
|
|
1037
1137
|
// Process existing elements
|
|
@@ -1052,15 +1152,13 @@ export class PayloadManager {
|
|
|
1052
1152
|
if (typeof updateArray[i] === 'object' && typeof elementToAdd === 'object' &&
|
|
1053
1153
|
!Array.isArray(updateArray[i]) && !Array.isArray(elementToAdd) &&
|
|
1054
1154
|
updateArray[i] !== null && elementToAdd !== null) {
|
|
1055
|
-
// Deep merge for object elements - preserve existing properties
|
|
1056
|
-
elementToAdd = _.cloneDeep(elementToAdd);
|
|
1057
1155
|
// Create a synthetic change request with just this update
|
|
1058
1156
|
// The updateElements should be the object itself at the root level
|
|
1059
1157
|
const elementChangeRequest = {
|
|
1060
1158
|
updateElements: updateArray[i]
|
|
1061
1159
|
};
|
|
1062
1160
|
this.processChangeRequest(elementToAdd, original ? original[i] : undefined, elementChangeRequest, [], // Empty path since updateArray[i] is already at the element level
|
|
1063
|
-
counts, warnings, allowedPaths, blockedOperations);
|
|
1161
|
+
counts, warnings, allowedPaths, blockedOperations, requestHasDottedKeys);
|
|
1064
1162
|
}
|
|
1065
1163
|
else {
|
|
1066
1164
|
// For primitives or arrays, replace entirely (existing behavior)
|
|
@@ -1068,11 +1166,12 @@ export class PayloadManager {
|
|
|
1068
1166
|
counts.updates++;
|
|
1069
1167
|
}
|
|
1070
1168
|
}
|
|
1071
|
-
else if (typeof elementToAdd === 'object' &&
|
|
1072
|
-
|
|
1169
|
+
else if (typeof elementToAdd === 'object' &&
|
|
1170
|
+
elementToAdd !== null &&
|
|
1171
|
+
(requestHasDottedKeys || (removeArray && removeArray[i] !== undefined) || (replaceArray && replaceArray[i] !== undefined))) {
|
|
1172
|
+
// For objects/arrays that aren't being replaced, process nested changes only when changes exist
|
|
1073
1173
|
// IMPORTANT: Don't pass newElements for existing array elements -
|
|
1074
1174
|
// newElements items should be appended to the array, not merged into existing items
|
|
1075
|
-
elementToAdd = _.cloneDeep(elementToAdd);
|
|
1076
1175
|
const changeRequestWithoutNew = {
|
|
1077
1176
|
updateElements: changeRequest.updateElements,
|
|
1078
1177
|
removeElements: changeRequest.removeElements,
|
|
@@ -1080,7 +1179,7 @@ export class PayloadManager {
|
|
|
1080
1179
|
reasoning: changeRequest.reasoning
|
|
1081
1180
|
// Intentionally omit newElements
|
|
1082
1181
|
};
|
|
1083
|
-
this.processChangeRequest(elementToAdd, original ? original[i] : undefined, changeRequestWithoutNew, [...path, i.toString()], counts, warnings, allowedPaths, blockedOperations);
|
|
1182
|
+
this.processChangeRequest(elementToAdd, original ? original[i] : undefined, changeRequestWithoutNew, [...path, i.toString()], counts, warnings, allowedPaths, blockedOperations, requestHasDottedKeys);
|
|
1084
1183
|
}
|
|
1085
1184
|
newTargetArray.push(elementToAdd);
|
|
1086
1185
|
}
|
|
@@ -1110,12 +1209,12 @@ export class PayloadManager {
|
|
|
1110
1209
|
/**
|
|
1111
1210
|
* Process changes for object properties
|
|
1112
1211
|
*/
|
|
1113
|
-
processObjectChanges(target, original, changeRequest, path, counts, warnings, allowedPaths, blockedOperations) {
|
|
1212
|
+
processObjectChanges(target, original, changeRequest, path, counts, warnings, allowedPaths, blockedOperations, requestHasDottedKeys = false) {
|
|
1114
1213
|
// Get all unique keys from change request
|
|
1115
1214
|
const changeKeys = this.getChangeKeys(changeRequest, path);
|
|
1116
1215
|
// Process changes for each key
|
|
1117
1216
|
for (const key of changeKeys) {
|
|
1118
|
-
this.processKeyChange(target, original, changeRequest, [...path, key], key, counts, warnings, allowedPaths, blockedOperations);
|
|
1217
|
+
this.processKeyChange(target, original, changeRequest, [...path, key], key, counts, warnings, allowedPaths, blockedOperations, requestHasDottedKeys);
|
|
1119
1218
|
}
|
|
1120
1219
|
// After processing all changes, check for "_DELETE_" values in updateElements
|
|
1121
1220
|
// This allows deletion within update operations at any depth
|
|
@@ -1134,17 +1233,19 @@ export class PayloadManager {
|
|
|
1134
1233
|
counts.deletions++;
|
|
1135
1234
|
}
|
|
1136
1235
|
}
|
|
1137
|
-
//
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1236
|
+
// Only recurse into keys not in changeKeys if the changeRequest contains dotted/bracketed keys
|
|
1237
|
+
if (requestHasDottedKeys) {
|
|
1238
|
+
for (const key of Object.keys(target)) {
|
|
1239
|
+
if (!changeKeys.has(key) && typeof target[key] === 'object' && target[key] !== null) {
|
|
1240
|
+
this.processChangeRequest(target[key], original ? original[key] : undefined, changeRequest, [...path, key], counts, warnings, allowedPaths, blockedOperations, requestHasDottedKeys);
|
|
1241
|
+
}
|
|
1141
1242
|
}
|
|
1142
1243
|
}
|
|
1143
1244
|
}
|
|
1144
1245
|
/**
|
|
1145
1246
|
* Process a single key change (add, update, or delete)
|
|
1146
1247
|
*/
|
|
1147
|
-
processKeyChange(target, original, changeRequest, keyPath, key, counts, warnings, allowedPaths, blockedOperations) {
|
|
1248
|
+
processKeyChange(target, original, changeRequest, keyPath, key, counts, warnings, allowedPaths, blockedOperations, requestHasDottedKeys = false) {
|
|
1148
1249
|
const pathStr = keyPath.join('.');
|
|
1149
1250
|
// Check for replacement first (complete replacement - remove then add)
|
|
1150
1251
|
const replaceValue = _.get(changeRequest.replaceElements, pathStr);
|
|
@@ -1265,7 +1366,7 @@ export class PayloadManager {
|
|
|
1265
1366
|
if (typeof effectiveUpdateValue === 'object' && effectiveUpdateValue !== null &&
|
|
1266
1367
|
typeof target[key] === 'object' && target[key] !== null) {
|
|
1267
1368
|
// Recursively process nested updates for both objects and arrays
|
|
1268
|
-
this.processChangeRequest(target[key], original ? original[key] : undefined, changeRequest, keyPath, counts, warnings, allowedPaths, blockedOperations);
|
|
1369
|
+
this.processChangeRequest(target[key], original ? original[key] : undefined, changeRequest, keyPath, counts, warnings, allowedPaths, blockedOperations, requestHasDottedKeys);
|
|
1269
1370
|
}
|
|
1270
1371
|
else {
|
|
1271
1372
|
// For primitives or type mismatches, replace the value
|
|
@@ -1304,17 +1405,17 @@ export class PayloadManager {
|
|
|
1304
1405
|
// Handle case where removeValue exists but isn't a direct deletion
|
|
1305
1406
|
// This happens with arrays where removeValue is like [{}, '_DELETE_', {}]
|
|
1306
1407
|
// We need to recurse to process the array removals
|
|
1307
|
-
this.processChangeRequest(target[key], original ? original[key] : undefined, changeRequest, keyPath, counts, warnings, allowedPaths, blockedOperations);
|
|
1408
|
+
this.processChangeRequest(target[key], original ? original[key] : undefined, changeRequest, keyPath, counts, warnings, allowedPaths, blockedOperations, requestHasDottedKeys);
|
|
1308
1409
|
}
|
|
1309
1410
|
else if (newValue !== undefined && Array.isArray(newValue) && Array.isArray(target[key])) {
|
|
1310
1411
|
// Handle array append: newElements has an array for an existing array key
|
|
1311
1412
|
// Recurse to let processArrayChanges handle the append
|
|
1312
|
-
this.processChangeRequest(target[key], original ? original[key] : undefined, changeRequest, keyPath, counts, warnings, allowedPaths, blockedOperations);
|
|
1413
|
+
this.processChangeRequest(target[key], original ? original[key] : undefined, changeRequest, keyPath, counts, warnings, allowedPaths, blockedOperations, requestHasDottedKeys);
|
|
1313
1414
|
}
|
|
1314
1415
|
else if (bothAreObjects) {
|
|
1315
1416
|
// Handle object in newElements for existing object key
|
|
1316
1417
|
// Recurse to find nested arrays that need append semantics
|
|
1317
|
-
this.processChangeRequest(target[key], original ? original[key] : undefined, changeRequest, keyPath, counts, warnings, allowedPaths, blockedOperations);
|
|
1418
|
+
this.processChangeRequest(target[key], original ? original[key] : undefined, changeRequest, keyPath, counts, warnings, allowedPaths, blockedOperations, requestHasDottedKeys);
|
|
1318
1419
|
}
|
|
1319
1420
|
}
|
|
1320
1421
|
/**
|