MCPcopy Create free account
hub / github.com/ScaleML/AgentSPEX / adjustTargetPath

Function adjustTargetPath

yaml-flow-editor/src/utils/flow-utils.ts:128–156  ·  view source on GitHub ↗
(sourceBranch: string, sourceIndex: number, targetBranch: string)

Source from the content-addressed store, hash-verified

126
127// Adjust target path if it was affected by source removal
128export const adjustTargetPath = (sourceBranch: string, sourceIndex: number, targetBranch: string): string => {
129 const sourceParts = sourceBranch.split('.');
130 const targetParts = targetBranch.split('.');
131
132 // If target path is shorter or equal to source path, it's not a descendant (unless same list, handled elsewhere)
133 if (targetParts.length <= sourceParts.length) return targetBranch;
134
135 // Check if target is a descendant of the source list
136 // i.e. sourcePath prefix matches targetPath prefix
137 for (let i = 0; i < sourceParts.length; i++) {
138 if (sourceParts[i] !== targetParts[i]) return targetBranch;
139 }
140
141 // sourceParts points to the list that was modified.
142 // targetParts[sourceParts.length] is the index in that list that leads to the target.
143 const affectedIndexStr = targetParts[sourceParts.length];
144 const affectedIndex = Number(affectedIndexStr);
145
146 if (isNaN(affectedIndex)) return targetBranch;
147
148 // If the item removed was before the path to the target, shift the index down
149 if (sourceIndex < affectedIndex) {
150 const newParts = [...targetParts];
151 newParts[sourceParts.length] = String(affectedIndex - 1);
152 return newParts.join('.');
153 }
154
155 return targetBranch;
156};
157
158// Insert item at specific path and index
159export const insertNestedItem = (

Callers 5

SwitchContainerNodeFunction · 0.90
ParallelNodeFunction · 0.90
WhileContainerNodeFunction · 0.90
ForEachContainerNodeFunction · 0.90
IfContainerNodeFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected