@memberjunction/ai-agents 6.3.0-edge.0 → 6.3.0-edge.1
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 +8 -5
- package/dist/AgentDataPreloader.d.ts +9 -2
- package/dist/AgentDataPreloader.d.ts.map +1 -1
- package/dist/AgentDataPreloader.js +134 -15
- package/dist/AgentDataPreloader.js.map +1 -1
- package/dist/AgentDecisionService.d.ts +10 -1
- package/dist/AgentDecisionService.d.ts.map +1 -1
- package/dist/AgentDecisionService.js +28 -13
- package/dist/AgentDecisionService.js.map +1 -1
- package/dist/AgentRunner.d.ts +57 -15
- package/dist/AgentRunner.d.ts.map +1 -1
- package/dist/AgentRunner.js +692 -101
- package/dist/AgentRunner.js.map +1 -1
- package/dist/ArtifactToolManager.d.ts +134 -39
- package/dist/ArtifactToolManager.d.ts.map +1 -1
- package/dist/ArtifactToolManager.js +2761 -321
- package/dist/ArtifactToolManager.js.map +1 -1
- package/dist/GovernedArtifactService.d.ts +367 -0
- package/dist/GovernedArtifactService.d.ts.map +1 -0
- package/dist/GovernedArtifactService.js +2569 -0
- package/dist/GovernedArtifactService.js.map +1 -0
- package/dist/PayloadManager.d.ts +46 -0
- package/dist/PayloadManager.d.ts.map +1 -1
- package/dist/PayloadManager.js +284 -66
- package/dist/PayloadManager.js.map +1 -1
- package/dist/SkillMarkdownConverter.d.ts.map +1 -1
- package/dist/SkillMarkdownConverter.js +4 -2
- package/dist/SkillMarkdownConverter.js.map +1 -1
- package/dist/agent-context-injector.d.ts +2 -25
- package/dist/agent-context-injector.d.ts.map +1 -1
- package/dist/agent-context-injector.js +38 -153
- package/dist/agent-context-injector.js.map +1 -1
- package/dist/agent-instance.d.ts +28 -0
- package/dist/agent-instance.d.ts.map +1 -0
- package/dist/agent-instance.js +39 -0
- package/dist/agent-instance.js.map +1 -0
- package/dist/agent-memory-context-builder.d.ts.map +1 -1
- package/dist/agent-memory-context-builder.js +46 -42
- package/dist/agent-memory-context-builder.js.map +1 -1
- package/dist/agent-pre-execution-rag.d.ts.map +1 -1
- package/dist/agent-pre-execution-rag.js +5 -0
- package/dist/agent-pre-execution-rag.js.map +1 -1
- package/dist/agent-run-watchdog.d.ts +38 -6
- package/dist/agent-run-watchdog.d.ts.map +1 -1
- package/dist/agent-run-watchdog.js +75 -13
- package/dist/agent-run-watchdog.js.map +1 -1
- package/dist/agent-types/flow-agent-type.d.ts +6 -1
- package/dist/agent-types/flow-agent-type.d.ts.map +1 -1
- package/dist/agent-types/flow-agent-type.js +30 -7
- package/dist/agent-types/flow-agent-type.js.map +1 -1
- package/dist/agent-types/loop-agent-type.d.ts +4 -0
- package/dist/agent-types/loop-agent-type.d.ts.map +1 -1
- package/dist/agent-types/loop-agent-type.js +29 -0
- package/dist/agent-types/loop-agent-type.js.map +1 -1
- package/dist/artifact-presence-locator.d.ts +132 -0
- package/dist/artifact-presence-locator.d.ts.map +1 -0
- package/dist/artifact-presence-locator.js +472 -0
- package/dist/artifact-presence-locator.js.map +1 -0
- package/dist/artifact-tools/CSVToolLibrary.d.ts +2 -2
- package/dist/artifact-tools/CSVToolLibrary.d.ts.map +1 -1
- package/dist/artifact-tools/CSVToolLibrary.js +41 -14
- package/dist/artifact-tools/CSVToolLibrary.js.map +1 -1
- package/dist/artifact-tools/DataSnapshotToolLibrary.d.ts +2 -2
- package/dist/artifact-tools/DataSnapshotToolLibrary.d.ts.map +1 -1
- package/dist/artifact-tools/DataSnapshotToolLibrary.js +53 -21
- package/dist/artifact-tools/DataSnapshotToolLibrary.js.map +1 -1
- package/dist/artifact-tools/DocumentToolLibrary.d.ts +101 -0
- package/dist/artifact-tools/DocumentToolLibrary.d.ts.map +1 -0
- package/dist/artifact-tools/DocumentToolLibrary.js +1846 -0
- package/dist/artifact-tools/DocumentToolLibrary.js.map +1 -0
- package/dist/artifact-tools/DocxToolLibrary.d.ts +2 -4
- package/dist/artifact-tools/DocxToolLibrary.d.ts.map +1 -1
- package/dist/artifact-tools/DocxToolLibrary.js +42 -30
- package/dist/artifact-tools/DocxToolLibrary.js.map +1 -1
- package/dist/artifact-tools/ExcelToolLibrary.d.ts +2 -3
- package/dist/artifact-tools/ExcelToolLibrary.d.ts.map +1 -1
- package/dist/artifact-tools/ExcelToolLibrary.js +105 -49
- package/dist/artifact-tools/ExcelToolLibrary.js.map +1 -1
- package/dist/artifact-tools/GenericBinaryToolLibrary.d.ts +2 -2
- package/dist/artifact-tools/GenericBinaryToolLibrary.d.ts.map +1 -1
- package/dist/artifact-tools/GenericBinaryToolLibrary.js +3 -2
- package/dist/artifact-tools/GenericBinaryToolLibrary.js.map +1 -1
- package/dist/artifact-tools/JSONToolLibrary.d.ts +4 -4
- package/dist/artifact-tools/JSONToolLibrary.d.ts.map +1 -1
- package/dist/artifact-tools/JSONToolLibrary.js +32 -11
- package/dist/artifact-tools/JSONToolLibrary.js.map +1 -1
- package/dist/artifact-tools/PDFToolLibrary.d.ts +27 -3
- package/dist/artifact-tools/PDFToolLibrary.d.ts.map +1 -1
- package/dist/artifact-tools/PDFToolLibrary.js +36 -21
- package/dist/artifact-tools/PDFToolLibrary.js.map +1 -1
- package/dist/artifact-tools/SearchResultSetToolLibrary.d.ts +2 -2
- package/dist/artifact-tools/SearchResultSetToolLibrary.d.ts.map +1 -1
- package/dist/artifact-tools/SearchResultSetToolLibrary.js +83 -24
- package/dist/artifact-tools/SearchResultSetToolLibrary.js.map +1 -1
- package/dist/artifact-tools/SlideDeckToolLibrary.d.ts +50 -0
- package/dist/artifact-tools/SlideDeckToolLibrary.d.ts.map +1 -0
- package/dist/artifact-tools/SlideDeckToolLibrary.js +1617 -0
- package/dist/artifact-tools/SlideDeckToolLibrary.js.map +1 -0
- package/dist/artifact-tools/SpreadsheetToolLibrary.d.ts +87 -0
- package/dist/artifact-tools/SpreadsheetToolLibrary.d.ts.map +1 -0
- package/dist/artifact-tools/SpreadsheetToolLibrary.js +3351 -0
- package/dist/artifact-tools/SpreadsheetToolLibrary.js.map +1 -0
- package/dist/artifact-tools/TextToolLibrary.d.ts +3 -3
- package/dist/artifact-tools/TextToolLibrary.d.ts.map +1 -1
- package/dist/artifact-tools/TextToolLibrary.js +34 -24
- package/dist/artifact-tools/TextToolLibrary.js.map +1 -1
- package/dist/artifact-tools/WhiteboardToolLibrary.d.ts +69 -0
- package/dist/artifact-tools/WhiteboardToolLibrary.d.ts.map +1 -0
- package/dist/artifact-tools/WhiteboardToolLibrary.js +555 -0
- package/dist/artifact-tools/WhiteboardToolLibrary.js.map +1 -0
- package/dist/artifact-tools/artifact-comment-suggestion-helper.d.ts +98 -0
- package/dist/artifact-tools/artifact-comment-suggestion-helper.d.ts.map +1 -0
- package/dist/artifact-tools/artifact-comment-suggestion-helper.js +851 -0
- package/dist/artifact-tools/artifact-comment-suggestion-helper.js.map +1 -0
- package/dist/artifact-tools/artifact-tool-helpers.d.ts +21 -0
- package/dist/artifact-tools/artifact-tool-helpers.d.ts.map +1 -0
- package/dist/artifact-tools/artifact-tool-helpers.js +74 -0
- package/dist/artifact-tools/artifact-tool-helpers.js.map +1 -0
- package/dist/artifact-tools/grepHelper.d.ts +27 -0
- package/dist/artifact-tools/grepHelper.d.ts.map +1 -0
- package/dist/artifact-tools/grepHelper.js +229 -0
- package/dist/artifact-tools/grepHelper.js.map +1 -0
- package/dist/artifact-tools/node-vm-safe-regex.d.ts +10 -0
- package/dist/artifact-tools/node-vm-safe-regex.d.ts.map +1 -0
- package/dist/artifact-tools/node-vm-safe-regex.js +148 -0
- package/dist/artifact-tools/node-vm-safe-regex.js.map +1 -0
- package/dist/base-agent.d.ts +119 -14
- package/dist/base-agent.d.ts.map +1 -1
- package/dist/base-agent.js +529 -112
- package/dist/base-agent.js.map +1 -1
- package/dist/decision-discovery.d.ts +42 -15
- package/dist/decision-discovery.d.ts.map +1 -1
- package/dist/decision-discovery.js +90 -20
- package/dist/decision-discovery.js.map +1 -1
- package/dist/index.d.ts +12 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +12 -2
- package/dist/index.js.map +1 -1
- package/dist/memory-decision-uses.d.ts +206 -0
- package/dist/memory-decision-uses.d.ts.map +1 -0
- package/dist/memory-decision-uses.js +259 -0
- package/dist/memory-decision-uses.js.map +1 -0
- package/dist/memory-manager-agent.d.ts +66 -6
- package/dist/memory-manager-agent.d.ts.map +1 -1
- package/dist/memory-manager-agent.js +184 -31
- package/dist/memory-manager-agent.js.map +1 -1
- package/dist/memory-note-gate.d.ts +12 -9
- package/dist/memory-note-gate.d.ts.map +1 -1
- package/dist/memory-note-gate.js +16 -11
- package/dist/memory-note-gate.js.map +1 -1
- package/dist/native-tools/agent-tool-circuit-breaker.d.ts +44 -0
- package/dist/native-tools/agent-tool-circuit-breaker.d.ts.map +1 -0
- package/dist/native-tools/agent-tool-circuit-breaker.js +71 -0
- package/dist/native-tools/agent-tool-circuit-breaker.js.map +1 -0
- package/dist/native-tools/agent-tools.d.ts +7 -0
- package/dist/native-tools/agent-tools.d.ts.map +1 -1
- package/dist/native-tools/agent-tools.js.map +1 -1
- package/dist/native-tools/control-tools.d.ts +8 -1
- package/dist/native-tools/control-tools.d.ts.map +1 -1
- package/dist/native-tools/control-tools.js +38 -5
- package/dist/native-tools/control-tools.js.map +1 -1
- package/dist/native-tools/framework-tools.d.ts +3 -3
- package/dist/native-tools/framework-tools.d.ts.map +1 -1
- package/dist/native-tools/framework-tools.js +20 -8
- package/dist/native-tools/framework-tools.js.map +1 -1
- package/dist/payload-path-keys.d.ts +54 -0
- package/dist/payload-path-keys.d.ts.map +1 -0
- package/dist/payload-path-keys.js +126 -0
- package/dist/payload-path-keys.js.map +1 -0
- package/dist/pipeline/template.d.ts +9 -4
- package/dist/pipeline/template.d.ts.map +1 -1
- package/dist/pipeline/template.js +29 -30
- package/dist/pipeline/template.js.map +1 -1
- package/dist/realtime/artifact-workspace-channel-server.d.ts +27 -0
- package/dist/realtime/artifact-workspace-channel-server.d.ts.map +1 -0
- package/dist/realtime/artifact-workspace-channel-server.js +43 -0
- package/dist/realtime/artifact-workspace-channel-server.js.map +1 -0
- package/dist/realtime/bridge-realtime-session-factory.d.ts +2 -2
- package/dist/realtime/bridge-realtime-session-factory.d.ts.map +1 -1
- package/dist/realtime/bridge-realtime-session-factory.js +7 -56
- package/dist/realtime/bridge-realtime-session-factory.js.map +1 -1
- package/dist/realtime/realtime-artifact-helpers.d.ts +37 -0
- package/dist/realtime/realtime-artifact-helpers.d.ts.map +1 -0
- package/dist/realtime/realtime-artifact-helpers.js +150 -0
- package/dist/realtime/realtime-artifact-helpers.js.map +1 -0
- package/dist/realtime/realtime-client-session-service.d.ts +87 -17
- package/dist/realtime/realtime-client-session-service.d.ts.map +1 -1
- package/dist/realtime/realtime-client-session-service.js +259 -39
- package/dist/realtime/realtime-client-session-service.js.map +1 -1
- package/dist/realtime/realtime-coagent-config.d.ts +22 -7
- package/dist/realtime/realtime-coagent-config.d.ts.map +1 -1
- package/dist/realtime/realtime-coagent-config.js +20 -22
- package/dist/realtime/realtime-coagent-config.js.map +1 -1
- package/dist/realtime/realtime-moderator-decision.d.ts +86 -0
- package/dist/realtime/realtime-moderator-decision.d.ts.map +1 -0
- package/dist/realtime/realtime-moderator-decision.js +131 -0
- package/dist/realtime/realtime-moderator-decision.js.map +1 -0
- package/dist/realtime/realtime-tool-broker.d.ts +6 -0
- package/dist/realtime/realtime-tool-broker.d.ts.map +1 -1
- package/dist/realtime/realtime-tool-broker.js +4 -2
- package/dist/realtime/realtime-tool-broker.js.map +1 -1
- package/dist/realtime/realtime-turn-moderator.d.ts +20 -0
- package/dist/realtime/realtime-turn-moderator.d.ts.map +1 -1
- package/dist/realtime/realtime-turn-moderator.js +63 -8
- package/dist/realtime/realtime-turn-moderator.js.map +1 -1
- package/dist/repeated-failing-step.d.ts +50 -0
- package/dist/repeated-failing-step.d.ts.map +1 -0
- package/dist/repeated-failing-step.js +130 -0
- package/dist/repeated-failing-step.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +20 -20
package/dist/PayloadManager.js
CHANGED
|
@@ -37,6 +37,15 @@ import _ from 'lodash';
|
|
|
37
37
|
import { PayloadChangeAnalyzer } from './PayloadChangeAnalyzer.js';
|
|
38
38
|
import { ParsePathWithOperations, isOperationAllowed } from './types/payload-operations.js';
|
|
39
39
|
import { IsUnsafeObjectKey, StripUnsafeObjectKeys } from './unsafe-object-keys.js';
|
|
40
|
+
import { BuildNestedValue, FormatPayloadPath, IsPathKey, ParsePathKey, ResolvePayloadPath } from './payload-path-keys.js';
|
|
41
|
+
const CHANGE_BUCKETS = ['updateElements', 'newElements', 'removeElements', 'replaceElements'];
|
|
42
|
+
/** The operation each bucket performs, used when a path key in it is refused. */
|
|
43
|
+
const BUCKET_OPERATION = {
|
|
44
|
+
updateElements: 'update',
|
|
45
|
+
newElements: 'add',
|
|
46
|
+
removeElements: 'delete',
|
|
47
|
+
replaceElements: 'update'
|
|
48
|
+
};
|
|
40
49
|
/**
|
|
41
50
|
* Manages payload access control for agent hierarchies.
|
|
42
51
|
*
|
|
@@ -716,26 +725,23 @@ export class PayloadManager {
|
|
|
716
725
|
if (compiled) {
|
|
717
726
|
return compiled;
|
|
718
727
|
}
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
728
|
+
// Paths are checked in dot form (`items.0.price`), so `items[*]` / `items[0]` become `items.*` / `items.0`.
|
|
729
|
+
const pattern = pathPattern.replace(/\[(\*|\d+)\]/g, '.$1');
|
|
730
|
+
const toSegmentRegex = (part) => part
|
|
731
|
+
.replace(/\\/g, '\\\\')
|
|
732
|
+
.replace(/\./g, '\\.')
|
|
733
|
+
.replace(/\*/g, '[^.]+');
|
|
734
|
+
if (pattern.includes('**')) {
|
|
735
|
+
// `**` spans any number of segments; it is split out first so the single-`*` rule can't rewrite it
|
|
736
|
+
compiled = new RegExp(`^${pattern.split('**').map(toSegmentRegex).join('.*')}$`);
|
|
737
|
+
}
|
|
738
|
+
else if (pattern.endsWith('.*')) {
|
|
739
|
+
const basePath = pattern.slice(0, -2);
|
|
729
740
|
const escapedBase = basePath.replace(/\\/g, '\\\\').replace(/\./g, '\\.');
|
|
730
741
|
compiled = new RegExp(`^${escapedBase}(\\..*)?$`);
|
|
731
742
|
}
|
|
732
743
|
else {
|
|
733
|
-
|
|
734
|
-
.replace(/\\/g, '\\\\')
|
|
735
|
-
.replace(/\./g, '\\.')
|
|
736
|
-
.replace(/\*/g, '[^.]+')
|
|
737
|
-
.replace(/\[(\*|\d+)\]/g, '\\[(\\*|\\d+)\\]');
|
|
738
|
-
compiled = new RegExp(`^${regexStr}$`);
|
|
744
|
+
compiled = new RegExp(`^${toSegmentRegex(pattern)}$`);
|
|
739
745
|
}
|
|
740
746
|
this._pathPatternRegexCache.set(pathPattern, compiled);
|
|
741
747
|
return compiled;
|
|
@@ -965,6 +971,154 @@ export class PayloadManager {
|
|
|
965
971
|
}
|
|
966
972
|
return false;
|
|
967
973
|
}
|
|
974
|
+
/**
|
|
975
|
+
* Resolves path keys at the top of each bucket (`"meta.title"`, `"dependencies[2].code"`), so a
|
|
976
|
+
* change can name one nested field without restating the objects and arrays around it.
|
|
977
|
+
*
|
|
978
|
+
* - A key the payload already holds as a literal property name is left as it is.
|
|
979
|
+
* - Path keys in updateElements, newElements and removeElements become the nested form the merge
|
|
980
|
+
* already handles. A newElements path that already holds a value is treated as an update.
|
|
981
|
+
* - Path keys in replaceElements are set at their exact location after the rest of the change,
|
|
982
|
+
* because the nested form would replace the whole top-level property.
|
|
983
|
+
* - A path that can't be written (index out of range, a step through a string) is refused as a
|
|
984
|
+
* blocked operation with a warning. It is never written as a literal key.
|
|
985
|
+
*/
|
|
986
|
+
normalizePathKeys(changeRequest, originalPayload, warnings, blockedOperations) {
|
|
987
|
+
const root = this.isPlainObject(originalPayload) ? originalPayload : {};
|
|
988
|
+
const replacements = [];
|
|
989
|
+
if (!CHANGE_BUCKETS.some(bucket => this.bucketHasPathKeys(changeRequest[bucket], root))) {
|
|
990
|
+
return { Request: changeRequest, Replacements: replacements };
|
|
991
|
+
}
|
|
992
|
+
const request = { ...changeRequest };
|
|
993
|
+
const expansions = [];
|
|
994
|
+
for (const bucket of CHANGE_BUCKETS) {
|
|
995
|
+
const source = changeRequest[bucket];
|
|
996
|
+
if (!this.isPlainObject(source) || !this.bucketHasPathKeys(source, root))
|
|
997
|
+
continue;
|
|
998
|
+
const kept = {};
|
|
999
|
+
for (const [key, value] of Object.entries(source)) {
|
|
1000
|
+
if (IsPathKey(key) && !(key in root)) {
|
|
1001
|
+
this.routePathKey({ Bucket: bucket, Key: key, Value: value, Root: root, Expansions: expansions, Replacements: replacements, Warnings: warnings, BlockedOperations: blockedOperations });
|
|
1002
|
+
}
|
|
1003
|
+
else {
|
|
1004
|
+
kept[key] = value;
|
|
1005
|
+
}
|
|
1006
|
+
}
|
|
1007
|
+
request[bucket] = kept;
|
|
1008
|
+
}
|
|
1009
|
+
for (const expansion of expansions) {
|
|
1010
|
+
this.mergePathExpansion(request, expansion);
|
|
1011
|
+
}
|
|
1012
|
+
return { Request: request, Replacements: replacements };
|
|
1013
|
+
}
|
|
1014
|
+
/** True when a bucket has a top-level path key that is not a literal property of the payload. */
|
|
1015
|
+
bucketHasPathKeys(bucket, root) {
|
|
1016
|
+
if (!this.isPlainObject(bucket))
|
|
1017
|
+
return false;
|
|
1018
|
+
return Object.keys(bucket).some(key => IsPathKey(key) && !(key in root));
|
|
1019
|
+
}
|
|
1020
|
+
/** Checks one path key against the payload and sends it to the bucket that will apply it. */
|
|
1021
|
+
routePathKey(route) {
|
|
1022
|
+
const segments = ParsePathKey(route.Key);
|
|
1023
|
+
// A path segment named like a prototype key would walk into Object.prototype when the
|
|
1024
|
+
// change is applied, the same hole StripUnsafeObjectKeys closes for whole keys.
|
|
1025
|
+
const unsafe = segments?.find(segment => typeof segment === 'string' && IsUnsafeObjectKey(segment));
|
|
1026
|
+
if (unsafe !== undefined) {
|
|
1027
|
+
this.refusePathKey(route, `Cannot apply '${route.Key}' in ${route.Bucket}: '${unsafe}' is not a data key`);
|
|
1028
|
+
return;
|
|
1029
|
+
}
|
|
1030
|
+
const resolved = segments ? ResolvePayloadPath(route.Root, segments) : null;
|
|
1031
|
+
if (!resolved || resolved.Error) {
|
|
1032
|
+
const reason = resolved?.Error ?? 'the path is malformed';
|
|
1033
|
+
this.refusePathKey(route, `Cannot apply '${route.Key}' in ${route.Bucket}: ${reason}`);
|
|
1034
|
+
return;
|
|
1035
|
+
}
|
|
1036
|
+
switch (route.Bucket) {
|
|
1037
|
+
case 'replaceElements':
|
|
1038
|
+
route.Replacements.push({ Key: route.Key, Segments: resolved.Segments, Value: route.Value });
|
|
1039
|
+
return;
|
|
1040
|
+
case 'removeElements':
|
|
1041
|
+
if (!resolved.Exists) {
|
|
1042
|
+
route.Warnings.push(`Nothing to remove at '${route.Key}': the payload has no value there`);
|
|
1043
|
+
return;
|
|
1044
|
+
}
|
|
1045
|
+
break;
|
|
1046
|
+
case 'newElements':
|
|
1047
|
+
if (resolved.Exists) {
|
|
1048
|
+
route.Warnings.push(`Auto-corrected: '${route.Key}' was in newElements but already exists (treated as update)`);
|
|
1049
|
+
route.Expansions.push({ Bucket: 'updateElements', Segments: resolved.Segments, Value: route.Value });
|
|
1050
|
+
return;
|
|
1051
|
+
}
|
|
1052
|
+
break;
|
|
1053
|
+
}
|
|
1054
|
+
route.Expansions.push({ Bucket: route.Bucket, Segments: resolved.Segments, Value: route.Value });
|
|
1055
|
+
}
|
|
1056
|
+
/** Records a path key that can't be applied, so the caller sees a refusal, not a silent no-op. */
|
|
1057
|
+
refusePathKey(route, message) {
|
|
1058
|
+
route.Warnings.push(message);
|
|
1059
|
+
route.BlockedOperations.push({
|
|
1060
|
+
path: route.Key,
|
|
1061
|
+
operation: BUCKET_OPERATION[route.Bucket],
|
|
1062
|
+
to: route.Value,
|
|
1063
|
+
reason: message,
|
|
1064
|
+
timestamp: new Date().toISOString()
|
|
1065
|
+
});
|
|
1066
|
+
}
|
|
1067
|
+
/**
|
|
1068
|
+
* Merges one resolved path into its bucket as nested objects and sparse arrays. A top-level
|
|
1069
|
+
* property the bucket already had is copied before the merge, so the caller's request is not
|
|
1070
|
+
* changed.
|
|
1071
|
+
*/
|
|
1072
|
+
mergePathExpansion(request, expansion) {
|
|
1073
|
+
const existing = request[expansion.Bucket];
|
|
1074
|
+
const bucket = this.isPlainObject(existing) ? existing : {};
|
|
1075
|
+
const rootKey = String(expansion.Segments[0]);
|
|
1076
|
+
if (rootKey in bucket) {
|
|
1077
|
+
bucket[rootKey] = this.fastCloneDeep(bucket[rootKey]);
|
|
1078
|
+
}
|
|
1079
|
+
_.merge(bucket, BuildNestedValue(expansion.Segments, expansion.Value));
|
|
1080
|
+
request[expansion.Bucket] = bucket;
|
|
1081
|
+
}
|
|
1082
|
+
/**
|
|
1083
|
+
* Sets each replaceElements path key at its exact location in `result`, after the rest of the
|
|
1084
|
+
* change is applied. Missing parent objects are created. Each write is checked against
|
|
1085
|
+
* `allowedPaths` as an add (nothing there yet) or an update.
|
|
1086
|
+
*/
|
|
1087
|
+
applyPathReplacements(result, replacements, counts, warnings, allowedPaths, blockedOperations) {
|
|
1088
|
+
for (const replacement of replacements) {
|
|
1089
|
+
const resolved = ResolvePayloadPath(result, replacement.Segments);
|
|
1090
|
+
if (resolved.Error) {
|
|
1091
|
+
const message = `Cannot apply '${replacement.Key}' in replaceElements: ${resolved.Error}`;
|
|
1092
|
+
warnings.push(message);
|
|
1093
|
+
blockedOperations.push({ path: replacement.Key, operation: 'update', to: replacement.Value, reason: message, timestamp: new Date().toISOString() });
|
|
1094
|
+
continue;
|
|
1095
|
+
}
|
|
1096
|
+
const operation = resolved.Exists ? 'update' : 'add';
|
|
1097
|
+
const permissionPath = replacement.Segments.join('.');
|
|
1098
|
+
if (allowedPaths && !this.isOperationAllowedForPath(permissionPath, operation, allowedPaths)) {
|
|
1099
|
+
const message = `Operation denied: Cannot replace '${FormatPayloadPath(replacement.Segments)}' - operation '${operation}' not allowed`;
|
|
1100
|
+
warnings.push(message);
|
|
1101
|
+
blockedOperations.push({ path: permissionPath, operation, to: replacement.Value, reason: `operation '${operation}' not allowed`, timestamp: new Date().toISOString() });
|
|
1102
|
+
continue;
|
|
1103
|
+
}
|
|
1104
|
+
this.setAtPath(result, replacement.Segments, replacement.Value);
|
|
1105
|
+
if (resolved.Exists)
|
|
1106
|
+
counts.deletions++;
|
|
1107
|
+
counts.additions++;
|
|
1108
|
+
}
|
|
1109
|
+
}
|
|
1110
|
+
/** Writes `value` at `segments`, creating missing parent objects. The path must already resolve. */
|
|
1111
|
+
setAtPath(root, segments, value) {
|
|
1112
|
+
let node = root;
|
|
1113
|
+
for (let i = 0; i < segments.length - 1; i++) {
|
|
1114
|
+
const segment = segments[i];
|
|
1115
|
+
if (node[segment] === undefined) {
|
|
1116
|
+
node[segment] = {};
|
|
1117
|
+
}
|
|
1118
|
+
node = node[segment];
|
|
1119
|
+
}
|
|
1120
|
+
node[segments[segments.length - 1]] = value;
|
|
1121
|
+
}
|
|
968
1122
|
/**
|
|
969
1123
|
* Applies an AgentPayloadChangeRequest to a payload
|
|
970
1124
|
*
|
|
@@ -988,14 +1142,18 @@ export class PayloadManager {
|
|
|
988
1142
|
if (!options?.ignoreStrayKeys) {
|
|
989
1143
|
this.autoCorrectStrayKeys(changeRequest, originalPayload, warnings, options?.agentName, options?.allowedPaths);
|
|
990
1144
|
}
|
|
1145
|
+
// Resolve path keys ("meta.title", "dependencies[2].code") into nested form. The caller's
|
|
1146
|
+
// request is left as it was; `request` is a copy whenever anything had to change.
|
|
1147
|
+
const { Request: request, Replacements: replacements } = this.normalizePathKeys(changeRequest, originalPayload, warnings, blockedOperations);
|
|
991
1148
|
const result = this.fastCloneDeep(originalPayload) || {};
|
|
992
1149
|
const counts = { additions: 0, updates: 0, deletions: 0 };
|
|
993
|
-
const requestHasDottedKeys = this.hasDottedKeys(
|
|
994
|
-
this.hasDottedKeys(
|
|
995
|
-
this.hasDottedKeys(
|
|
996
|
-
this.hasDottedKeys(
|
|
1150
|
+
const requestHasDottedKeys = this.hasDottedKeys(request.newElements) ||
|
|
1151
|
+
this.hasDottedKeys(request.updateElements) ||
|
|
1152
|
+
this.hasDottedKeys(request.removeElements) ||
|
|
1153
|
+
this.hasDottedKeys(request.replaceElements);
|
|
997
1154
|
// Process all changes recursively
|
|
998
|
-
this.processChangeRequest(result, originalPayload,
|
|
1155
|
+
this.processChangeRequest(result, originalPayload, request, [], counts, warnings, options?.allowedPaths, blockedOperations, requestHasDottedKeys);
|
|
1156
|
+
this.applyPathReplacements(result, replacements, counts, warnings, options?.allowedPaths, blockedOperations);
|
|
999
1157
|
// Log if requested and in verbose mode
|
|
1000
1158
|
if (options?.logChanges && options?.verbose) {
|
|
1001
1159
|
this.logChangesSummary(counts, changeRequest.reasoning, options.agentName);
|
|
@@ -1003,7 +1161,7 @@ export class PayloadManager {
|
|
|
1003
1161
|
// Analyze changes if requested
|
|
1004
1162
|
let analysis;
|
|
1005
1163
|
if (options?.analyzeChanges !== false) { // Default to true
|
|
1006
|
-
analysis = this._defaultAnalyzer.AnalyzeChangeRequest(originalPayload,
|
|
1164
|
+
analysis = this._defaultAnalyzer.AnalyzeChangeRequest(originalPayload, request, result);
|
|
1007
1165
|
// Add analysis warnings to the main warnings array
|
|
1008
1166
|
if (analysis.warnings.length > 0) {
|
|
1009
1167
|
warnings.push(...analysis.warnings.map(w => `[${w.severity}] ${w.message}`));
|
|
@@ -1032,12 +1190,12 @@ export class PayloadManager {
|
|
|
1032
1190
|
/**
|
|
1033
1191
|
* Process a change request recursively through the payload structure
|
|
1034
1192
|
*/
|
|
1035
|
-
processChangeRequest(target, original, changeRequest, path, counts, warnings, allowedPaths, blockedOperations, requestHasDottedKeys = false) {
|
|
1193
|
+
processChangeRequest(target, original, changeRequest, path, counts, warnings, allowedPaths, blockedOperations, requestHasDottedKeys = false, basePath = []) {
|
|
1036
1194
|
if (Array.isArray(target)) {
|
|
1037
|
-
this.processArrayChanges(target, original, changeRequest, path, counts, warnings, allowedPaths, blockedOperations, requestHasDottedKeys);
|
|
1195
|
+
this.processArrayChanges(target, original, changeRequest, path, counts, warnings, allowedPaths, blockedOperations, requestHasDottedKeys, basePath);
|
|
1038
1196
|
}
|
|
1039
1197
|
else if (typeof target === 'object' && target !== null) {
|
|
1040
|
-
this.processObjectChanges(target, original, changeRequest, path, counts, warnings, allowedPaths, blockedOperations, requestHasDottedKeys);
|
|
1198
|
+
this.processObjectChanges(target, original, changeRequest, path, counts, warnings, allowedPaths, blockedOperations, requestHasDottedKeys, basePath);
|
|
1041
1199
|
}
|
|
1042
1200
|
}
|
|
1043
1201
|
/**
|
|
@@ -1138,7 +1296,7 @@ export class PayloadManager {
|
|
|
1138
1296
|
*
|
|
1139
1297
|
* Arrays of primitives still use replacement behavior for backwards compatibility.
|
|
1140
1298
|
*/
|
|
1141
|
-
processArrayChanges(target, original, changeRequest, path, counts, warnings, allowedPaths, blockedOperations, requestHasDottedKeys = false) {
|
|
1299
|
+
processArrayChanges(target, original, changeRequest, path, counts, warnings, allowedPaths, blockedOperations, requestHasDottedKeys = false, basePath = []) {
|
|
1142
1300
|
const pathStr = path.join('.');
|
|
1143
1301
|
// Get change arrays for this path
|
|
1144
1302
|
const removeArray = pathStr ? _.get(changeRequest.removeElements, pathStr) : changeRequest.removeElements;
|
|
@@ -1147,16 +1305,21 @@ export class PayloadManager {
|
|
|
1147
1305
|
const replaceArray = pathStr ? _.get(changeRequest.replaceElements, pathStr) : changeRequest.replaceElements;
|
|
1148
1306
|
// Build a new array with all changes applied
|
|
1149
1307
|
const newTargetArray = [];
|
|
1308
|
+
const arrayPath = [...basePath, ...path].join('.');
|
|
1309
|
+
const blocked = { warnings, blockedOperations };
|
|
1150
1310
|
// Process existing elements
|
|
1151
1311
|
for (let i = 0; i < target.length; i++) {
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1312
|
+
// __DELETE__ may come from removeElements or, forgivingly, from updateElements
|
|
1313
|
+
const deleteRequested = (removeArray && removeArray[i] === '__DELETE__') ||
|
|
1314
|
+
(updateArray && updateArray[i] === '__DELETE__');
|
|
1315
|
+
if (deleteRequested) {
|
|
1316
|
+
if (this.isArrayElementOperationAllowed(arrayPath, i, 'delete', allowedPaths)) {
|
|
1317
|
+
counts.deletions++;
|
|
1318
|
+
continue; // Skip deleted items
|
|
1319
|
+
}
|
|
1320
|
+
this.recordBlockedOperation(blocked, `${arrayPath}.${i}`, 'delete', target[i], undefined);
|
|
1321
|
+
newTargetArray.push(target[i]); // A refused delete keeps the element unchanged
|
|
1322
|
+
continue;
|
|
1160
1323
|
}
|
|
1161
1324
|
// Use updated value if provided, otherwise keep original
|
|
1162
1325
|
let elementToAdd = target[i];
|
|
@@ -1171,13 +1334,17 @@ export class PayloadManager {
|
|
|
1171
1334
|
updateElements: updateArray[i]
|
|
1172
1335
|
};
|
|
1173
1336
|
this.processChangeRequest(elementToAdd, original ? original[i] : undefined, elementChangeRequest, [], // Empty path since updateArray[i] is already at the element level
|
|
1174
|
-
counts, warnings, allowedPaths, blockedOperations, requestHasDottedKeys)
|
|
1337
|
+
counts, warnings, allowedPaths, blockedOperations, requestHasDottedKeys, [...basePath, ...path, i.toString()] // ...so permissions see the element's full path
|
|
1338
|
+
);
|
|
1175
1339
|
}
|
|
1176
|
-
else {
|
|
1340
|
+
else if (this.isArrayElementOperationAllowed(arrayPath, i, 'update', allowedPaths)) {
|
|
1177
1341
|
// For primitives or arrays, replace entirely (existing behavior)
|
|
1178
1342
|
elementToAdd = updateArray[i];
|
|
1179
1343
|
counts.updates++;
|
|
1180
1344
|
}
|
|
1345
|
+
else {
|
|
1346
|
+
this.recordBlockedOperation(blocked, `${arrayPath}.${i}`, 'update', elementToAdd, updateArray[i]);
|
|
1347
|
+
}
|
|
1181
1348
|
}
|
|
1182
1349
|
else if (typeof elementToAdd === 'object' &&
|
|
1183
1350
|
elementToAdd !== null &&
|
|
@@ -1192,7 +1359,7 @@ export class PayloadManager {
|
|
|
1192
1359
|
reasoning: changeRequest.reasoning
|
|
1193
1360
|
// Intentionally omit newElements
|
|
1194
1361
|
};
|
|
1195
|
-
this.processChangeRequest(elementToAdd, original ? original[i] : undefined, changeRequestWithoutNew, [...path, i.toString()], counts, warnings, allowedPaths, blockedOperations, requestHasDottedKeys);
|
|
1362
|
+
this.processChangeRequest(elementToAdd, original ? original[i] : undefined, changeRequestWithoutNew, [...path, i.toString()], counts, warnings, allowedPaths, blockedOperations, requestHasDottedKeys, basePath);
|
|
1196
1363
|
}
|
|
1197
1364
|
newTargetArray.push(elementToAdd);
|
|
1198
1365
|
}
|
|
@@ -1200,13 +1367,18 @@ export class PayloadManager {
|
|
|
1200
1367
|
// These should be treated as additions (AI put new items in updateElements)
|
|
1201
1368
|
if (updateArray && Array.isArray(updateArray)) {
|
|
1202
1369
|
for (let i = target.length; i < updateArray.length; i++) {
|
|
1203
|
-
if (this.isSignificantValue(updateArray[i]))
|
|
1370
|
+
if (!this.isSignificantValue(updateArray[i]))
|
|
1371
|
+
continue;
|
|
1372
|
+
if (this.isArrayElementOperationAllowed(arrayPath, i, 'add', allowedPaths)) {
|
|
1204
1373
|
newTargetArray.push(updateArray[i]);
|
|
1205
1374
|
counts.additions++;
|
|
1206
1375
|
}
|
|
1376
|
+
else {
|
|
1377
|
+
this.recordBlockedOperation(blocked, `${arrayPath}.${i}`, 'add', undefined, updateArray[i]);
|
|
1378
|
+
}
|
|
1207
1379
|
}
|
|
1208
1380
|
}
|
|
1209
|
-
// Add new elements
|
|
1381
|
+
// Add new elements. Appends are not checked against allowedPaths (they never have been).
|
|
1210
1382
|
if (newArray && Array.isArray(newArray)) {
|
|
1211
1383
|
for (const item of newArray) {
|
|
1212
1384
|
if (this.isSignificantValue(item)) {
|
|
@@ -1219,15 +1391,50 @@ export class PayloadManager {
|
|
|
1219
1391
|
target.length = 0;
|
|
1220
1392
|
target.push(...newTargetArray);
|
|
1221
1393
|
}
|
|
1394
|
+
/**
|
|
1395
|
+
* Whether an operation on one array element is allowed. Element operations used to be gated only
|
|
1396
|
+
* by 'update' on the array itself, so that permission still allows them. A pattern naming the
|
|
1397
|
+
* element path (for example `dependencies.*`) allows them too.
|
|
1398
|
+
*/
|
|
1399
|
+
isArrayElementOperationAllowed(arrayPath, index, operation, allowedPaths) {
|
|
1400
|
+
if (!allowedPaths)
|
|
1401
|
+
return true;
|
|
1402
|
+
return this.isOperationAllowedForPath(arrayPath, 'update', allowedPaths) ||
|
|
1403
|
+
this.isOperationAllowedForPath(`${arrayPath}.${index}`, operation, allowedPaths);
|
|
1404
|
+
}
|
|
1405
|
+
/**
|
|
1406
|
+
* Whether a `"__DELETE__"` value in updateElements may delete `key`. It needs 'delete' or 'update'
|
|
1407
|
+
* on the key itself, or 'update' on the object that holds it (the gate it used to pass through).
|
|
1408
|
+
*/
|
|
1409
|
+
isUpdateDeleteAllowed(containerPath, key, allowedPaths) {
|
|
1410
|
+
if (!allowedPaths)
|
|
1411
|
+
return true;
|
|
1412
|
+
const keyPath = [...containerPath, key].join('.');
|
|
1413
|
+
return this.isOperationAllowedForPath(keyPath, 'delete', allowedPaths) ||
|
|
1414
|
+
this.isOperationAllowedForPath(keyPath, 'update', allowedPaths) ||
|
|
1415
|
+
(containerPath.length > 0 && this.isOperationAllowedForPath(containerPath.join('.'), 'update', allowedPaths));
|
|
1416
|
+
}
|
|
1417
|
+
/** Adds a warning and a blocked-operation record for an operation `allowedPaths` refused. */
|
|
1418
|
+
recordBlockedOperation(sink, path, operation, from, to) {
|
|
1419
|
+
sink.warnings.push(`Operation denied: Cannot ${operation} '${path}' - operation '${operation}' not allowed`);
|
|
1420
|
+
sink.blockedOperations?.push({
|
|
1421
|
+
path,
|
|
1422
|
+
operation,
|
|
1423
|
+
from,
|
|
1424
|
+
to,
|
|
1425
|
+
reason: `operation '${operation}' not allowed`,
|
|
1426
|
+
timestamp: new Date().toISOString()
|
|
1427
|
+
});
|
|
1428
|
+
}
|
|
1222
1429
|
/**
|
|
1223
1430
|
* Process changes for object properties
|
|
1224
1431
|
*/
|
|
1225
|
-
processObjectChanges(target, original, changeRequest, path, counts, warnings, allowedPaths, blockedOperations, requestHasDottedKeys = false) {
|
|
1432
|
+
processObjectChanges(target, original, changeRequest, path, counts, warnings, allowedPaths, blockedOperations, requestHasDottedKeys = false, basePath = []) {
|
|
1226
1433
|
// Get all unique keys from change request
|
|
1227
1434
|
const changeKeys = this.getChangeKeys(changeRequest, path);
|
|
1228
1435
|
// Process changes for each key
|
|
1229
1436
|
for (const key of changeKeys) {
|
|
1230
|
-
this.processKeyChange(target, original, changeRequest, [...path, key], key, counts, warnings, allowedPaths, blockedOperations, requestHasDottedKeys);
|
|
1437
|
+
this.processKeyChange(target, original, changeRequest, [...path, key], key, counts, warnings, allowedPaths, blockedOperations, requestHasDottedKeys, basePath);
|
|
1231
1438
|
}
|
|
1232
1439
|
// After processing all changes, check for "_DELETE_" values in updateElements
|
|
1233
1440
|
// This allows deletion within update operations at any depth
|
|
@@ -1237,7 +1444,12 @@ export class PayloadManager {
|
|
|
1237
1444
|
const keysToDelete = [];
|
|
1238
1445
|
for (const [key, value] of Object.entries(updateObj)) {
|
|
1239
1446
|
if (value === '__DELETE__' && key in target) {
|
|
1240
|
-
|
|
1447
|
+
if (this.isUpdateDeleteAllowed([...basePath, ...path], key, allowedPaths)) {
|
|
1448
|
+
keysToDelete.push(key);
|
|
1449
|
+
}
|
|
1450
|
+
else {
|
|
1451
|
+
this.recordBlockedOperation({ warnings, blockedOperations }, [...basePath, ...path, key].join('.'), 'delete', target[key], undefined);
|
|
1452
|
+
}
|
|
1241
1453
|
}
|
|
1242
1454
|
}
|
|
1243
1455
|
// Delete the keys after iteration to avoid modification during iteration
|
|
@@ -1250,7 +1462,7 @@ export class PayloadManager {
|
|
|
1250
1462
|
if (requestHasDottedKeys) {
|
|
1251
1463
|
for (const key of Object.keys(target)) {
|
|
1252
1464
|
if (!changeKeys.has(key) && typeof target[key] === 'object' && target[key] !== null) {
|
|
1253
|
-
this.processChangeRequest(target[key], original ? original[key] : undefined, changeRequest, [...path, key], counts, warnings, allowedPaths, blockedOperations, requestHasDottedKeys);
|
|
1465
|
+
this.processChangeRequest(target[key], original ? original[key] : undefined, changeRequest, [...path, key], counts, warnings, allowedPaths, blockedOperations, requestHasDottedKeys, basePath);
|
|
1254
1466
|
}
|
|
1255
1467
|
}
|
|
1256
1468
|
}
|
|
@@ -1258,19 +1470,22 @@ export class PayloadManager {
|
|
|
1258
1470
|
/**
|
|
1259
1471
|
* Process a single key change (add, update, or delete)
|
|
1260
1472
|
*/
|
|
1261
|
-
processKeyChange(target, original, changeRequest, keyPath, key, counts, warnings, allowedPaths, blockedOperations, requestHasDottedKeys = false) {
|
|
1473
|
+
processKeyChange(target, original, changeRequest, keyPath, key, counts, warnings, allowedPaths, blockedOperations, requestHasDottedKeys = false, basePath = []) {
|
|
1262
1474
|
const pathStr = keyPath.join('.');
|
|
1475
|
+
// The path checked against allowedPaths and reported when blocked. It differs from pathStr
|
|
1476
|
+
// inside an array element merge, where keyPath is relative to the element.
|
|
1477
|
+
const permissionPath = [...basePath, ...keyPath].join('.');
|
|
1263
1478
|
// Check for replacement first (complete replacement - remove then add)
|
|
1264
1479
|
const replaceValue = _.get(changeRequest.replaceElements, pathStr);
|
|
1265
1480
|
if (replaceValue !== undefined) {
|
|
1266
1481
|
// Check if appropriate operation is allowed (delete if exists, add if not)
|
|
1267
1482
|
const operation = key in target ? 'update' : 'add';
|
|
1268
|
-
if (allowedPaths && !this.isOperationAllowedForPath(
|
|
1269
|
-
const warning = `Operation denied: Cannot replace '${
|
|
1483
|
+
if (allowedPaths && !this.isOperationAllowedForPath(permissionPath, operation, allowedPaths)) {
|
|
1484
|
+
const warning = `Operation denied: Cannot replace '${permissionPath}' - operation '${operation}' not allowed`;
|
|
1270
1485
|
warnings.push(warning);
|
|
1271
1486
|
if (blockedOperations) {
|
|
1272
1487
|
blockedOperations.push({
|
|
1273
|
-
path:
|
|
1488
|
+
path: permissionPath,
|
|
1274
1489
|
operation: operation,
|
|
1275
1490
|
from: target[key],
|
|
1276
1491
|
to: replaceValue,
|
|
@@ -1296,12 +1511,12 @@ export class PayloadManager {
|
|
|
1296
1511
|
const removeValue = _.get(changeRequest.removeElements, pathStr);
|
|
1297
1512
|
if (removeValue === '__DELETE__') {
|
|
1298
1513
|
// Check if delete operation is allowed
|
|
1299
|
-
if (allowedPaths && !this.isOperationAllowedForPath(
|
|
1300
|
-
const warning = `Operation denied: Cannot delete '${
|
|
1514
|
+
if (allowedPaths && !this.isOperationAllowedForPath(permissionPath, 'delete', allowedPaths)) {
|
|
1515
|
+
const warning = `Operation denied: Cannot delete '${permissionPath}' - operation 'delete' not allowed`;
|
|
1301
1516
|
warnings.push(warning);
|
|
1302
1517
|
if (blockedOperations) {
|
|
1303
1518
|
blockedOperations.push({
|
|
1304
|
-
path:
|
|
1519
|
+
path: permissionPath,
|
|
1305
1520
|
operation: 'delete',
|
|
1306
1521
|
from: target[key],
|
|
1307
1522
|
to: undefined,
|
|
@@ -1320,12 +1535,12 @@ export class PayloadManager {
|
|
|
1320
1535
|
const newValue = _.get(changeRequest.newElements, pathStr);
|
|
1321
1536
|
if (newValue !== undefined && !(key in target)) {
|
|
1322
1537
|
// Check if add operation is allowed
|
|
1323
|
-
if (allowedPaths && !this.isOperationAllowedForPath(
|
|
1324
|
-
const warning = `Operation denied: Cannot add '${
|
|
1538
|
+
if (allowedPaths && !this.isOperationAllowedForPath(permissionPath, 'add', allowedPaths)) {
|
|
1539
|
+
const warning = `Operation denied: Cannot add '${permissionPath}' - operation 'add' not allowed`;
|
|
1325
1540
|
warnings.push(warning);
|
|
1326
1541
|
if (blockedOperations) {
|
|
1327
1542
|
blockedOperations.push({
|
|
1328
|
-
path:
|
|
1543
|
+
path: permissionPath,
|
|
1329
1544
|
operation: 'add',
|
|
1330
1545
|
from: undefined,
|
|
1331
1546
|
to: newValue,
|
|
@@ -1359,13 +1574,17 @@ export class PayloadManager {
|
|
|
1359
1574
|
shouldTreatNewAsUpdate ? newValue :
|
|
1360
1575
|
undefined;
|
|
1361
1576
|
if (effectiveUpdateValue !== undefined && key in target) {
|
|
1362
|
-
//
|
|
1363
|
-
|
|
1364
|
-
|
|
1577
|
+
// When the update merges into an existing object or array, permission is checked on each
|
|
1578
|
+
// value it writes inside, not on the container: allowing `dependencies.*.code` must let a
|
|
1579
|
+
// change write that code without also allowing every other update to `dependencies`.
|
|
1580
|
+
const mergesIntoContainer = typeof effectiveUpdateValue === 'object' && effectiveUpdateValue !== null &&
|
|
1581
|
+
typeof target[key] === 'object' && target[key] !== null;
|
|
1582
|
+
if (!mergesIntoContainer && allowedPaths && !this.isOperationAllowedForPath(permissionPath, 'update', allowedPaths)) {
|
|
1583
|
+
const warning = `Operation denied: Cannot update '${permissionPath}' - operation 'update' not allowed`;
|
|
1365
1584
|
warnings.push(warning);
|
|
1366
1585
|
if (blockedOperations) {
|
|
1367
1586
|
blockedOperations.push({
|
|
1368
|
-
path:
|
|
1587
|
+
path: permissionPath,
|
|
1369
1588
|
operation: 'update',
|
|
1370
1589
|
from: target[key],
|
|
1371
1590
|
to: effectiveUpdateValue,
|
|
@@ -1376,10 +1595,9 @@ export class PayloadManager {
|
|
|
1376
1595
|
return;
|
|
1377
1596
|
}
|
|
1378
1597
|
// If both values are objects or arrays, we need to recursively process the update
|
|
1379
|
-
if (
|
|
1380
|
-
typeof target[key] === 'object' && target[key] !== null) {
|
|
1598
|
+
if (mergesIntoContainer) {
|
|
1381
1599
|
// Recursively process nested updates for both objects and arrays
|
|
1382
|
-
this.processChangeRequest(target[key], original ? original[key] : undefined, changeRequest, keyPath, counts, warnings, allowedPaths, blockedOperations, requestHasDottedKeys);
|
|
1600
|
+
this.processChangeRequest(target[key], original ? original[key] : undefined, changeRequest, keyPath, counts, warnings, allowedPaths, blockedOperations, requestHasDottedKeys, basePath);
|
|
1383
1601
|
}
|
|
1384
1602
|
else {
|
|
1385
1603
|
// For primitives or type mismatches, replace the value
|
|
@@ -1394,12 +1612,12 @@ export class PayloadManager {
|
|
|
1394
1612
|
else if (updateValue !== undefined && !(key in target)) {
|
|
1395
1613
|
// Be forgiving: if AI put an addition in updateElements by mistake, treat it as an addition
|
|
1396
1614
|
// Check if add operation is allowed
|
|
1397
|
-
if (allowedPaths && !this.isOperationAllowedForPath(
|
|
1398
|
-
const warning = `Operation denied: Cannot add '${
|
|
1615
|
+
if (allowedPaths && !this.isOperationAllowedForPath(permissionPath, 'add', allowedPaths)) {
|
|
1616
|
+
const warning = `Operation denied: Cannot add '${permissionPath}' - operation 'add' not allowed`;
|
|
1399
1617
|
warnings.push(warning);
|
|
1400
1618
|
if (blockedOperations) {
|
|
1401
1619
|
blockedOperations.push({
|
|
1402
|
-
path:
|
|
1620
|
+
path: permissionPath,
|
|
1403
1621
|
operation: 'add',
|
|
1404
1622
|
from: undefined,
|
|
1405
1623
|
to: updateValue,
|
|
@@ -1418,17 +1636,17 @@ export class PayloadManager {
|
|
|
1418
1636
|
// Handle case where removeValue exists but isn't a direct deletion
|
|
1419
1637
|
// This happens with arrays where removeValue is like [{}, '_DELETE_', {}]
|
|
1420
1638
|
// We need to recurse to process the array removals
|
|
1421
|
-
this.processChangeRequest(target[key], original ? original[key] : undefined, changeRequest, keyPath, counts, warnings, allowedPaths, blockedOperations, requestHasDottedKeys);
|
|
1639
|
+
this.processChangeRequest(target[key], original ? original[key] : undefined, changeRequest, keyPath, counts, warnings, allowedPaths, blockedOperations, requestHasDottedKeys, basePath);
|
|
1422
1640
|
}
|
|
1423
1641
|
else if (newValue !== undefined && Array.isArray(newValue) && Array.isArray(target[key])) {
|
|
1424
1642
|
// Handle array append: newElements has an array for an existing array key
|
|
1425
1643
|
// Recurse to let processArrayChanges handle the append
|
|
1426
|
-
this.processChangeRequest(target[key], original ? original[key] : undefined, changeRequest, keyPath, counts, warnings, allowedPaths, blockedOperations, requestHasDottedKeys);
|
|
1644
|
+
this.processChangeRequest(target[key], original ? original[key] : undefined, changeRequest, keyPath, counts, warnings, allowedPaths, blockedOperations, requestHasDottedKeys, basePath);
|
|
1427
1645
|
}
|
|
1428
1646
|
else if (bothAreObjects) {
|
|
1429
1647
|
// Handle object in newElements for existing object key
|
|
1430
1648
|
// Recurse to find nested arrays that need append semantics
|
|
1431
|
-
this.processChangeRequest(target[key], original ? original[key] : undefined, changeRequest, keyPath, counts, warnings, allowedPaths, blockedOperations, requestHasDottedKeys);
|
|
1649
|
+
this.processChangeRequest(target[key], original ? original[key] : undefined, changeRequest, keyPath, counts, warnings, allowedPaths, blockedOperations, requestHasDottedKeys, basePath);
|
|
1432
1650
|
}
|
|
1433
1651
|
}
|
|
1434
1652
|
/**
|