agent-contracts 0.22.7 → 0.22.9

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/index.d.ts CHANGED
@@ -854,7 +854,9 @@ declare const ReplaceOperatorSchema: z.ZodObject<{
854
854
  }, z.core.$strip>;
855
855
  type ReplaceOperator = z.infer<typeof ReplaceOperatorSchema>;
856
856
  declare const RemoveOperatorSchema: z.ZodObject<{
857
- $remove: z.ZodArray<z.ZodString>;
857
+ $remove: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
858
+ id: z.ZodString;
859
+ }, z.core.$strip>]>>;
858
860
  }, z.core.$strip>;
859
861
  type RemoveOperator = z.infer<typeof RemoveOperatorSchema>;
860
862
  type MergeableRecord<T> = Record<string, T> | {
@@ -869,7 +871,9 @@ type MergeableRecord<T> = Record<string, T> | {
869
871
  } | {
870
872
  $replace: unknown;
871
873
  } | {
872
- $remove: string[];
874
+ $remove: (string | {
875
+ id: string;
876
+ })[];
873
877
  };
874
878
 
875
879
  declare const PolicyWhenSchema: z.ZodObject<{
package/dist/index.js CHANGED
@@ -49451,7 +49451,7 @@ var InsertAfterOperatorSchema = z16.object({
49451
49451
  });
49452
49452
  var ReplaceOperatorSchema = z16.object({ $replace: z16.any() });
49453
49453
  var RemoveOperatorSchema = z16.object({
49454
- $remove: z16.array(z16.string())
49454
+ $remove: z16.array(z16.union([z16.string(), z16.object({ id: z16.string() })]))
49455
49455
  });
49456
49456
 
49457
49457
  // src/loader/loader.ts
@@ -49863,10 +49863,13 @@ function hasOperator(obj) {
49863
49863
  }
49864
49864
  return null;
49865
49865
  }
49866
- function findIndexById(arr, id) {
49867
- return arr.findIndex(
49868
- (item) => isRecord2(item) && item["id"] === id
49869
- );
49866
+ function findIndexByIdOrValue(arr, target) {
49867
+ return arr.findIndex((item) => {
49868
+ if (typeof item === "string") {
49869
+ return item === target;
49870
+ }
49871
+ return isRecord2(item) && item["id"] === target;
49872
+ });
49870
49873
  }
49871
49874
  function applyArrayMergeOperator(baseArray, operatorObj, path) {
49872
49875
  const op = hasOperator(operatorObj);
@@ -49884,7 +49887,7 @@ function applyArrayMergeOperator(baseArray, operatorObj, path) {
49884
49887
  const spec = operatorObj["$insert_after"];
49885
49888
  const target = spec["target"];
49886
49889
  const items = spec["items"];
49887
- const idx = findIndexById(baseArray, target);
49890
+ const idx = findIndexByIdOrValue(baseArray, target);
49888
49891
  if (idx === -1) {
49889
49892
  throw new MergeError(
49890
49893
  `$insert_after target "${target}" not found in base at ${path}`
@@ -49899,7 +49902,28 @@ function applyArrayMergeOperator(baseArray, operatorObj, path) {
49899
49902
  }
49900
49903
  case "$remove": {
49901
49904
  const removeList = operatorObj["$remove"];
49902
- const idsToRemove = new Set(removeList.map((r3) => r3["id"]));
49905
+ if (removeList.length === 0) {
49906
+ return baseArray;
49907
+ }
49908
+ if (typeof removeList[0] === "string") {
49909
+ const valuesToRemove = new Set(removeList);
49910
+ const result2 = baseArray.filter((item) => {
49911
+ if (typeof item === "string" && valuesToRemove.has(item)) {
49912
+ valuesToRemove.delete(item);
49913
+ return false;
49914
+ }
49915
+ return true;
49916
+ });
49917
+ if (valuesToRemove.size > 0) {
49918
+ throw new MergeError(
49919
+ `$remove values not found in base at ${path}: ${[...valuesToRemove].join(", ")}`
49920
+ );
49921
+ }
49922
+ return result2;
49923
+ }
49924
+ const idsToRemove = new Set(
49925
+ removeList.map((r3) => r3["id"])
49926
+ );
49903
49927
  const result = baseArray.filter((item) => {
49904
49928
  if (isRecord2(item) && typeof item["id"] === "string") {
49905
49929
  const itemId = item["id"];
@@ -50016,7 +50040,9 @@ function deepMergeEntities(base, project, path, hasExtends) {
50016
50040
  }
50017
50041
  return result;
50018
50042
  }
50043
+ var OPERATOR_KEYS = /* @__PURE__ */ new Set(["$append", "$prepend", "$insert_after", "$replace", "$remove"]);
50019
50044
  function mergeEntityMaps(baseMap, projectMap, path, hasExtends) {
50045
+ let result;
50020
50046
  if (isRecord2(projectMap) && !Array.isArray(projectMap)) {
50021
50047
  const op = hasOperator(projectMap);
50022
50048
  if (op) {
@@ -50025,11 +50051,15 @@ function mergeEntityMaps(baseMap, projectMap, path, hasExtends) {
50025
50051
  `Merge operator used without extends at ${path}`
50026
50052
  );
50027
50053
  }
50028
- return applyMapMergeOperator(baseMap, projectMap, path);
50054
+ result = applyMapMergeOperator(baseMap, projectMap, path);
50055
+ } else {
50056
+ result = { ...baseMap };
50029
50057
  }
50058
+ } else {
50059
+ result = { ...baseMap };
50030
50060
  }
50031
- const result = { ...baseMap };
50032
50061
  for (const [key, projVal] of Object.entries(projectMap)) {
50062
+ if (OPERATOR_KEYS.has(key)) continue;
50033
50063
  const baseVal = result[key];
50034
50064
  if (baseVal !== void 0 && isRecord2(baseVal) && isRecord2(projVal)) {
50035
50065
  result[key] = deepMergeEntities(