agent-contracts 0.22.6 → 0.22.8

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<{
@@ -1247,7 +1251,7 @@ declare function mergeDsl(base: AnyRecord, project: AnyRecord): AnyRecord;
1247
1251
  interface ResolveResult {
1248
1252
  data: Record<string, unknown>;
1249
1253
  projectPath: string;
1250
- basePath?: string;
1254
+ basePaths: string[];
1251
1255
  }
1252
1256
  declare function resolve(projectDirOrFile: string): Promise<ResolveResult>;
1253
1257
 
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"];
@@ -50090,24 +50114,39 @@ function mergeDsl(base, project) {
50090
50114
 
50091
50115
  // src/resolver/resolve.ts
50092
50116
  import { dirname as dirname2, resolve as resolvePath } from "path";
50093
- async function resolve3(projectDirOrFile) {
50094
- const absPath = resolvePath(projectDirOrFile);
50095
- const projectResult = await loadDsl(absPath);
50096
- const projectData = projectResult.data;
50097
- const extendsValue = projectData["extends"];
50117
+ async function resolveExtendsChain(data, filePath, seen) {
50118
+ const extendsValue = data["extends"];
50098
50119
  if (typeof extendsValue !== "string") {
50099
- return {
50100
- data: projectData,
50101
- projectPath: projectResult.filePath
50102
- };
50120
+ return { data, basePaths: [] };
50103
50121
  }
50104
- const projectDir = dirname2(projectResult.filePath);
50122
+ const projectDir = dirname2(filePath);
50105
50123
  const baseResult = await resolveBase(extendsValue, projectDir);
50106
- const merged = mergeDsl(baseResult.data, projectData);
50124
+ const basePath = baseResult.filePath;
50125
+ if (seen.has(basePath)) {
50126
+ throw new BaseResolveError(
50127
+ `Circular extends detected: ${basePath}`
50128
+ );
50129
+ }
50130
+ seen.add(basePath);
50131
+ const { data: resolvedBase, basePaths: ancestorPaths } = await resolveExtendsChain(baseResult.data, basePath, seen);
50132
+ const merged = mergeDsl(resolvedBase, data);
50107
50133
  return {
50108
50134
  data: merged,
50135
+ basePaths: [...ancestorPaths, basePath]
50136
+ };
50137
+ }
50138
+ async function resolve3(projectDirOrFile) {
50139
+ const absPath = resolvePath(projectDirOrFile);
50140
+ const projectResult = await loadDsl(absPath);
50141
+ const { data, basePaths } = await resolveExtendsChain(
50142
+ projectResult.data,
50143
+ projectResult.filePath,
50144
+ /* @__PURE__ */ new Set()
50145
+ );
50146
+ return {
50147
+ data,
50109
50148
  projectPath: projectResult.filePath,
50110
- basePath: baseResult.filePath
50149
+ basePaths
50111
50150
  };
50112
50151
  }
50113
50152