agent-contracts 0.22.9 → 0.23.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.js CHANGED
@@ -50829,12 +50829,18 @@ var MergeError = class extends Error {
50829
50829
  function isRecord2(v2) {
50830
50830
  return typeof v2 === "object" && v2 !== null && !Array.isArray(v2);
50831
50831
  }
50832
- function hasOperator(obj) {
50832
+ function hasOperator(obj, path) {
50833
50833
  const ops = ["$append", "$prepend", "$insert_after", "$replace", "$remove"];
50834
+ const found = [];
50834
50835
  for (const op of ops) {
50835
- if (op in obj) return op;
50836
+ if (op in obj) found.push(op);
50836
50837
  }
50837
- return null;
50838
+ if (found.length > 1) {
50839
+ throw new MergeError(
50840
+ `Multiple merge operators in the same object at ${path ?? "unknown"}: ${found.join(", ")}`
50841
+ );
50842
+ }
50843
+ return found.length === 1 ? found[0] : null;
50838
50844
  }
50839
50845
  function findIndexByIdOrValue(arr, target) {
50840
50846
  return arr.findIndex((item) => {
@@ -50845,7 +50851,7 @@ function findIndexByIdOrValue(arr, target) {
50845
50851
  });
50846
50852
  }
50847
50853
  function applyArrayMergeOperator(baseArray, operatorObj, path) {
50848
- const op = hasOperator(operatorObj);
50854
+ const op = hasOperator(operatorObj, path);
50849
50855
  if (!op) return baseArray;
50850
50856
  switch (op) {
50851
50857
  case "$append": {
@@ -50919,9 +50925,13 @@ function applyArrayMergeOperator(baseArray, operatorObj, path) {
50919
50925
  }
50920
50926
  }
50921
50927
  function orderedInsertAfter(base, afterKey, entries) {
50928
+ const entryKeys = new Set(Object.keys(entries));
50922
50929
  const result = {};
50923
50930
  let inserted = false;
50924
50931
  for (const key of Object.keys(base)) {
50932
+ if (inserted && entryKeys.has(key)) {
50933
+ continue;
50934
+ }
50925
50935
  result[key] = base[key];
50926
50936
  if (key === afterKey) {
50927
50937
  for (const [ek, ev] of Object.entries(entries)) {
@@ -50930,13 +50940,10 @@ function orderedInsertAfter(base, afterKey, entries) {
50930
50940
  inserted = true;
50931
50941
  }
50932
50942
  }
50933
- if (!inserted) {
50934
- return result;
50935
- }
50936
50943
  return result;
50937
50944
  }
50938
50945
  function applyMapMergeOperator(baseMap, operatorObj, path) {
50939
- const op = hasOperator(operatorObj);
50946
+ const op = hasOperator(operatorObj, path);
50940
50947
  if (!op) return baseMap;
50941
50948
  switch (op) {
50942
50949
  case "$append": {
@@ -50987,7 +50994,7 @@ function deepMergeEntities(base, project, path, hasExtends) {
50987
50994
  for (const key of Object.keys(project)) {
50988
50995
  const baseVal = result[key];
50989
50996
  const projVal = project[key];
50990
- if (isRecord2(projVal) && hasOperator(projVal)) {
50997
+ if (isRecord2(projVal) && hasOperator(projVal, `${path}.${key}`)) {
50991
50998
  if (!hasExtends) {
50992
50999
  throw new MergeError(
50993
51000
  `Merge operator used without extends at ${path}.${key}`
@@ -51017,7 +51024,7 @@ var OPERATOR_KEYS = /* @__PURE__ */ new Set(["$append", "$prepend", "$insert_aft
51017
51024
  function mergeEntityMaps(baseMap, projectMap, path, hasExtends) {
51018
51025
  let result;
51019
51026
  if (isRecord2(projectMap) && !Array.isArray(projectMap)) {
51020
- const op = hasOperator(projectMap);
51027
+ const op = hasOperator(projectMap, path);
51021
51028
  if (op) {
51022
51029
  if (!hasExtends) {
51023
51030
  throw new MergeError(