@agentforge/tools 0.16.24 → 0.16.26

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.cjs CHANGED
@@ -1941,11 +1941,52 @@ var objectOmitSchema = zod.z.object({
1941
1941
  object: zod.z.record(zod.z.any().describe("Property value")).describe("Source object"),
1942
1942
  properties: zod.z.array(zod.z.string().describe("String value")).describe("List of property names to omit")
1943
1943
  });
1944
+
1945
+ // src/data/transformer/tools/shared.ts
1946
+ function getNestedValue(value, path12) {
1947
+ return path12.split(".").reduce((current, key) => {
1948
+ if (current == null) {
1949
+ return void 0;
1950
+ }
1951
+ return Reflect.get(Object(current), key);
1952
+ }, value);
1953
+ }
1954
+ function compareRelationalValues(left, right) {
1955
+ const leftOperand = left;
1956
+ const rightOperand = right;
1957
+ if (leftOperand < rightOperand) {
1958
+ return -1;
1959
+ }
1960
+ if (leftOperand > rightOperand) {
1961
+ return 1;
1962
+ }
1963
+ return 0;
1964
+ }
1965
+ function pickObjectProperties(source, properties) {
1966
+ const picked = {};
1967
+ for (const property of properties) {
1968
+ if (property in source) {
1969
+ Object.defineProperty(picked, property, {
1970
+ value: source[property],
1971
+ enumerable: true,
1972
+ configurable: true,
1973
+ writable: true
1974
+ });
1975
+ }
1976
+ }
1977
+ return picked;
1978
+ }
1979
+ function omitObjectProperties(source, properties) {
1980
+ const omitted = { ...source };
1981
+ for (const property of properties) {
1982
+ delete omitted[property];
1983
+ }
1984
+ return omitted;
1985
+ }
1986
+
1987
+ // src/data/transformer/tools/array-filter.ts
1944
1988
  function createArrayFilterTool() {
1945
1989
  return core.toolBuilder().name("array-filter").description("Filter an array based on a property value. Supports equality, comparison, and contains operations.").category(core.ToolCategory.UTILITY).tags(["array", "filter", "data", "transform"]).schema(arrayFilterSchema).implement(async (input) => {
1946
- const getNestedValue = (obj, path12) => {
1947
- return path12.split(".").reduce((current, key) => current?.[key], obj);
1948
- };
1949
1990
  const filtered = input.array.filter((item) => {
1950
1991
  const itemValue = getNestedValue(item, input.property);
1951
1992
  switch (input.operator) {
@@ -1954,9 +1995,9 @@ function createArrayFilterTool() {
1954
1995
  case "not-equals":
1955
1996
  return itemValue !== input.value;
1956
1997
  case "greater-than":
1957
- return itemValue > input.value;
1998
+ return compareRelationalValues(itemValue, input.value) > 0;
1958
1999
  case "less-than":
1959
- return itemValue < input.value;
2000
+ return compareRelationalValues(itemValue, input.value) < 0;
1960
2001
  case "contains":
1961
2002
  return String(itemValue).includes(String(input.value));
1962
2003
  case "starts-with":
@@ -1992,15 +2033,14 @@ function createArrayMapTool() {
1992
2033
  }
1993
2034
  function createArraySortTool() {
1994
2035
  return core.toolBuilder().name("array-sort").description("Sort an array by a property value. Supports ascending and descending order.").category(core.ToolCategory.UTILITY).tags(["array", "sort", "data", "transform"]).schema(arraySortSchema).implement(async (input) => {
1995
- const getNestedValue = (obj, path12) => {
1996
- return path12.split(".").reduce((current, key) => current?.[key], obj);
1997
- };
1998
2036
  const sorted = [...input.array].sort((a, b) => {
1999
2037
  const aValue = getNestedValue(a, input.property);
2000
2038
  const bValue = getNestedValue(b, input.property);
2001
- if (aValue < bValue) return input.order === "asc" ? -1 : 1;
2002
- if (aValue > bValue) return input.order === "asc" ? 1 : -1;
2003
- return 0;
2039
+ const comparison = compareRelationalValues(aValue, bValue);
2040
+ if (comparison === 0) {
2041
+ return 0;
2042
+ }
2043
+ return input.order === "asc" ? comparison : comparison * -1;
2004
2044
  });
2005
2045
  return {
2006
2046
  sorted,
@@ -2026,24 +2066,10 @@ function createArrayGroupByTool() {
2026
2066
  }).build();
2027
2067
  }
2028
2068
  function createObjectPickTool() {
2029
- return core.toolBuilder().name("object-pick").description("Create a new object with only the specified properties from the source object.").category(core.ToolCategory.UTILITY).tags(["object", "pick", "data", "transform"]).schema(objectPickSchema).implement(async (input) => {
2030
- const picked = {};
2031
- for (const prop of input.properties) {
2032
- if (prop in input.object) {
2033
- picked[prop] = input.object[prop];
2034
- }
2035
- }
2036
- return picked;
2037
- }).build();
2069
+ return core.toolBuilder().name("object-pick").description("Create a new object with only the specified properties from the source object.").category(core.ToolCategory.UTILITY).tags(["object", "pick", "data", "transform"]).schema(objectPickSchema).implement(async (input) => pickObjectProperties(input.object, input.properties)).build();
2038
2070
  }
2039
2071
  function createObjectOmitTool() {
2040
- return core.toolBuilder().name("object-omit").description("Create a new object excluding the specified properties from the source object.").category(core.ToolCategory.UTILITY).tags(["object", "omit", "data", "transform"]).schema(objectOmitSchema).implement(async (input) => {
2041
- const omitted = { ...input.object };
2042
- for (const prop of input.properties) {
2043
- delete omitted[prop];
2044
- }
2045
- return omitted;
2046
- }).build();
2072
+ return core.toolBuilder().name("object-omit").description("Create a new object excluding the specified properties from the source object.").category(core.ToolCategory.UTILITY).tags(["object", "omit", "data", "transform"]).schema(objectOmitSchema).implement(async (input) => omitObjectProperties(input.object, input.properties)).build();
2047
2073
  }
2048
2074
 
2049
2075
  // src/data/transformer/index.ts