agent-contracts 0.23.0 → 0.23.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/dist/index.js CHANGED
@@ -50032,7 +50032,12 @@ function deepMergeEntities(base, project, path, hasExtends) {
50032
50032
  } else if (isRecord2(baseVal)) {
50033
50033
  result[key] = applyMapMergeOperator(baseVal, projVal, `${path}.${key}`);
50034
50034
  } else {
50035
- result[key] = applyArrayMergeOperator([], projVal, `${path}.${key}`);
50035
+ const op = hasOperator(projVal, `${path}.${key}`);
50036
+ if (op === "$replace") {
50037
+ result[key] = projVal["$replace"];
50038
+ } else {
50039
+ result[key] = applyArrayMergeOperator([], projVal, `${path}.${key}`);
50040
+ }
50036
50041
  }
50037
50042
  } else if (isRecord2(projVal) && isRecord2(baseVal) && !Array.isArray(projVal) && !Array.isArray(baseVal)) {
50038
50043
  result[key] = deepMergeEntities(
@@ -50048,6 +50053,40 @@ function deepMergeEntities(base, project, path, hasExtends) {
50048
50053
  return result;
50049
50054
  }
50050
50055
  var OPERATOR_KEYS = /* @__PURE__ */ new Set(["$append", "$prepend", "$insert_after", "$replace", "$remove"]);
50056
+ function mergeSection(base, project, path, hasExtends, mode) {
50057
+ switch (mode) {
50058
+ case "map": {
50059
+ const baseMap = isRecord2(base) ? base : {};
50060
+ return mergeEntityMaps(baseMap, project, path, hasExtends);
50061
+ }
50062
+ case "array": {
50063
+ const baseArr = Array.isArray(base) ? base : [];
50064
+ if (isRecord2(project) && hasOperator(project, path)) {
50065
+ if (!hasExtends) {
50066
+ throw new MergeError(
50067
+ `Merge operator used without extends at ${path}`
50068
+ );
50069
+ }
50070
+ return applyArrayMergeOperator(baseArr, project, path);
50071
+ }
50072
+ const projArr = Array.isArray(project) ? project : [];
50073
+ return [...baseArr, ...projArr];
50074
+ }
50075
+ case "object": {
50076
+ const baseObj = isRecord2(base) ? base : {};
50077
+ const projObj = isRecord2(project) ? project : {};
50078
+ if (hasOperator(projObj, path)) {
50079
+ if (!hasExtends) {
50080
+ throw new MergeError(
50081
+ `Merge operator used without extends at ${path}`
50082
+ );
50083
+ }
50084
+ return applyMapMergeOperator(baseObj, projObj, path);
50085
+ }
50086
+ return deepMergeEntities(baseObj, projObj, path, hasExtends);
50087
+ }
50088
+ }
50089
+ }
50051
50090
  function mergeEntityMaps(baseMap, projectMap, path, hasExtends) {
50052
50091
  let result;
50053
50092
  if (isRecord2(projectMap) && !Array.isArray(projectMap)) {
@@ -50068,9 +50107,10 @@ function mergeEntityMaps(baseMap, projectMap, path, hasExtends) {
50068
50107
  for (const [key, projVal] of Object.entries(projectMap)) {
50069
50108
  if (OPERATOR_KEYS.has(key)) continue;
50070
50109
  const baseVal = result[key];
50071
- if (baseVal !== void 0 && isRecord2(baseVal) && isRecord2(projVal)) {
50110
+ if (isRecord2(projVal) && !Array.isArray(projVal)) {
50111
+ const baseObj = isRecord2(baseVal) ? baseVal : {};
50072
50112
  result[key] = deepMergeEntities(
50073
- baseVal,
50113
+ baseObj,
50074
50114
  projVal,
50075
50115
  `${path}.${key}`,
50076
50116
  hasExtends
@@ -50081,44 +50121,33 @@ function mergeEntityMaps(baseMap, projectMap, path, hasExtends) {
50081
50121
  }
50082
50122
  return result;
50083
50123
  }
50084
- var MERGE_SECTIONS = [
50085
- "agents",
50086
- "tasks",
50087
- "artifacts",
50088
- "tools",
50089
- "validations",
50090
- "handoff_types",
50091
- "imports",
50092
- "workflow",
50093
- "policies",
50094
- "guardrails",
50095
- "guardrail_policies",
50096
- "components",
50097
- "extensions"
50098
- ];
50124
+ var DSL_SECTIONS = {
50125
+ agents: "map",
50126
+ tasks: "map",
50127
+ artifacts: "map",
50128
+ tools: "map",
50129
+ validations: "map",
50130
+ handoff_types: "map",
50131
+ imports: "map",
50132
+ workflow: "map",
50133
+ policies: "map",
50134
+ guardrails: "map",
50135
+ guardrail_policies: "map",
50136
+ components: "map",
50137
+ extensions: "map",
50138
+ system: "object"
50139
+ };
50099
50140
  function mergeDsl(base, project) {
50100
50141
  const hasExtends = typeof project["extends"] === "string";
50101
50142
  const result = { ...base, ...project };
50102
- if (project["system"] && base["system"]) {
50103
- result["system"] = deepMergeEntities(
50104
- base["system"],
50105
- project["system"],
50106
- "system",
50107
- hasExtends
50108
- );
50109
- }
50110
- for (const section of MERGE_SECTIONS) {
50111
- const baseVal = base[section];
50112
- const projVal = project[section];
50113
- if (projVal === void 0) {
50114
- continue;
50115
- }
50116
- const baseMap = isRecord2(baseVal) ? baseVal : {};
50117
- result[section] = mergeEntityMaps(
50118
- baseMap,
50119
- projVal,
50143
+ for (const [section, mode] of Object.entries(DSL_SECTIONS)) {
50144
+ if (project[section] === void 0) continue;
50145
+ result[section] = mergeSection(
50146
+ base[section],
50147
+ project[section],
50120
50148
  section,
50121
- hasExtends
50149
+ hasExtends,
50150
+ mode
50122
50151
  );
50123
50152
  }
50124
50153
  delete result["extends"];
@@ -54471,42 +54500,23 @@ function resolveDslPath(dirArg, dirArgDefault, config) {
54471
54500
  }
54472
54501
 
54473
54502
  // src/config/binding-merger.ts
54474
- function isRecord5(v2) {
54475
- return typeof v2 === "object" && v2 !== null && !Array.isArray(v2);
54476
- }
54477
- var BINDING_MAP_MERGE_SECTIONS = ["guardrail_impl", "outputs"];
54478
- var BINDING_ARRAY_MERGE_SECTIONS = ["renders"];
54503
+ var BINDING_SECTIONS = {
54504
+ guardrail_impl: "map",
54505
+ outputs: "map",
54506
+ renders: "array",
54507
+ reporting: "object"
54508
+ };
54479
54509
  function mergeBinding(base, project) {
54480
54510
  const hasExtends = typeof project["extends"] === "string";
54481
54511
  const result = { ...base, ...project };
54482
- for (const section of BINDING_MAP_MERGE_SECTIONS) {
54483
- const baseVal = base[section];
54484
- const projVal = project[section];
54485
- if (projVal === void 0) {
54486
- continue;
54487
- }
54488
- const baseMap = isRecord5(baseVal) ? baseVal : {};
54489
- result[section] = mergeEntityMaps(
54490
- baseMap,
54491
- projVal,
54512
+ for (const [section, mode] of Object.entries(BINDING_SECTIONS)) {
54513
+ if (project[section] === void 0) continue;
54514
+ result[section] = mergeSection(
54515
+ base[section],
54516
+ project[section],
54492
54517
  section,
54493
- hasExtends
54494
- );
54495
- }
54496
- for (const section of BINDING_ARRAY_MERGE_SECTIONS) {
54497
- const baseVal = base[section];
54498
- const projVal = project[section];
54499
- if (projVal === void 0) continue;
54500
- const baseArr = Array.isArray(baseVal) ? baseVal : [];
54501
- const projArr = Array.isArray(projVal) ? projVal : [];
54502
- result[section] = [...baseArr, ...projArr];
54503
- }
54504
- if (project["reporting"] !== void 0 && isRecord5(base["reporting"]) && isRecord5(project["reporting"])) {
54505
- result["reporting"] = deepMergeEntities(
54506
- base["reporting"],
54507
- project["reporting"],
54508
- "reporting",
54509
- hasExtends
54518
+ hasExtends,
54519
+ mode
54510
54520
  );
54511
54521
  }
54512
54522
  delete result["extends"];
@@ -54997,7 +55007,7 @@ function formatDslOverview(dsl) {
54997
55007
  `- Validations: ${Object.keys(dsl.validations).join(", ")}`
54998
55008
  ].join("\n");
54999
55009
  }
55000
- function isRecord6(v2) {
55010
+ function isRecord5(v2) {
55001
55011
  return typeof v2 === "object" && v2 !== null && !Array.isArray(v2);
55002
55012
  }
55003
55013
  function collectAllXUsages(dsl) {
@@ -55010,7 +55020,7 @@ function collectAllXUsages(dsl) {
55010
55020
  }
55011
55021
  }
55012
55022
  walk(dsl, "", "root");
55013
- if (isRecord6(dsl.system)) walk(dsl.system, "system", "system");
55023
+ if (isRecord5(dsl.system)) walk(dsl.system, "system", "system");
55014
55024
  for (const [id, a3] of Object.entries(dsl.agents))
55015
55025
  walk(a3, `agents.${id}`, "agent");
55016
55026
  for (const [id, t3] of Object.entries(dsl.tasks))