@agentforge/tools 0.16.34 → 0.16.35
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 +79 -26
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +49 -42
- package/dist/index.d.ts +49 -42
- package/dist/index.js +79 -26
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -26,7 +26,7 @@ var httpRequestSchema = z.object({
|
|
|
26
26
|
url: z.string().url().describe("The URL to make the request to"),
|
|
27
27
|
method: HttpMethod.default("GET").describe("HTTP method to use"),
|
|
28
28
|
headers: z.record(z.string()).optional().describe("Optional HTTP headers"),
|
|
29
|
-
body: z.
|
|
29
|
+
body: z.unknown().optional().describe("Optional request body (for POST, PUT, PATCH)"),
|
|
30
30
|
timeout: z.number().default(3e4).describe("Request timeout in milliseconds"),
|
|
31
31
|
params: z.record(z.string()).optional().describe("Optional URL query parameters")
|
|
32
32
|
});
|
|
@@ -37,7 +37,7 @@ var httpGetSchema = z.object({
|
|
|
37
37
|
});
|
|
38
38
|
var httpPostSchema = z.object({
|
|
39
39
|
url: z.string().url().describe("The URL to post to"),
|
|
40
|
-
body: z.
|
|
40
|
+
body: z.unknown().describe("The request body (will be sent as JSON)"),
|
|
41
41
|
headers: z.record(z.string()).optional().describe("Optional HTTP headers")
|
|
42
42
|
});
|
|
43
43
|
|
|
@@ -1644,19 +1644,21 @@ var jsonParserSchema = z.object({
|
|
|
1644
1644
|
strict: z.boolean().default(true).describe("Use strict JSON parsing (no trailing commas, etc.)")
|
|
1645
1645
|
});
|
|
1646
1646
|
var jsonStringifySchema = z.object({
|
|
1647
|
-
data: z.
|
|
1647
|
+
data: z.unknown().describe("Data to convert to JSON string"),
|
|
1648
1648
|
pretty: z.boolean().default(false).describe("Format with indentation for readability"),
|
|
1649
1649
|
indent: z.number().default(2).describe("Number of spaces for indentation (when pretty is true)")
|
|
1650
1650
|
});
|
|
1651
1651
|
var jsonQuerySchema = z.object({
|
|
1652
|
-
data: z.
|
|
1652
|
+
data: z.unknown().describe("JSON data to query"),
|
|
1653
1653
|
path: z.string().describe('Dot notation path to query (e.g., "user.name" or "items[0].id")')
|
|
1654
1654
|
});
|
|
1655
1655
|
var jsonValidatorSchema = z.object({
|
|
1656
1656
|
json: z.string().describe("JSON string to validate")
|
|
1657
1657
|
});
|
|
1658
1658
|
var jsonMergeSchema = z.object({
|
|
1659
|
-
objects: z.array(
|
|
1659
|
+
objects: z.array(
|
|
1660
|
+
z.record(z.unknown().describe("Value associated with the object key")).describe("Object to merge")
|
|
1661
|
+
).describe("Array of objects to merge"),
|
|
1660
1662
|
deep: z.boolean().default(false).describe("Perform deep merge (nested objects)")
|
|
1661
1663
|
});
|
|
1662
1664
|
function createJsonParserTool() {
|
|
@@ -1679,18 +1681,33 @@ function createJsonStringifyTool(defaultIndent = 2, defaultPretty = false) {
|
|
|
1679
1681
|
};
|
|
1680
1682
|
}).build();
|
|
1681
1683
|
}
|
|
1684
|
+
function isRecord(value) {
|
|
1685
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1686
|
+
}
|
|
1687
|
+
function getPathValue(current, part) {
|
|
1688
|
+
const arrayMatch = part.match(/^(\w+)\[(\d+)\]$/);
|
|
1689
|
+
if (arrayMatch) {
|
|
1690
|
+
const [, key, index] = arrayMatch;
|
|
1691
|
+
if (!isRecord(current)) {
|
|
1692
|
+
return void 0;
|
|
1693
|
+
}
|
|
1694
|
+
const candidate = current[key];
|
|
1695
|
+
if (!Array.isArray(candidate)) {
|
|
1696
|
+
return void 0;
|
|
1697
|
+
}
|
|
1698
|
+
return candidate[parseInt(index, 10)];
|
|
1699
|
+
}
|
|
1700
|
+
if (!isRecord(current)) {
|
|
1701
|
+
return void 0;
|
|
1702
|
+
}
|
|
1703
|
+
return current[part];
|
|
1704
|
+
}
|
|
1682
1705
|
function createJsonQueryTool() {
|
|
1683
1706
|
return toolBuilder().name("json-query").description('Query JSON data using dot notation path (e.g., "user.address.city"). Supports array indexing.').category(ToolCategory.UTILITY).tags(["json", "query", "path", "data"]).schema(jsonQuerySchema).implementSafe(async (input) => {
|
|
1684
1707
|
const parts = input.path.split(".");
|
|
1685
1708
|
let current = input.data;
|
|
1686
1709
|
for (const part of parts) {
|
|
1687
|
-
|
|
1688
|
-
if (arrayMatch) {
|
|
1689
|
-
const [, key, index] = arrayMatch;
|
|
1690
|
-
current = current[key][parseInt(index, 10)];
|
|
1691
|
-
} else {
|
|
1692
|
-
current = current[part];
|
|
1693
|
-
}
|
|
1710
|
+
current = getPathValue(current, part);
|
|
1694
1711
|
if (current === void 0) {
|
|
1695
1712
|
throw new Error(`Path not found: ${input.path}`);
|
|
1696
1713
|
}
|
|
@@ -1710,23 +1727,59 @@ function createJsonValidatorTool() {
|
|
|
1710
1727
|
};
|
|
1711
1728
|
}).build();
|
|
1712
1729
|
}
|
|
1730
|
+
function isMergeObject(value) {
|
|
1731
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1732
|
+
}
|
|
1733
|
+
function setMergeProperty(target, key, value) {
|
|
1734
|
+
Object.defineProperty(target, key, {
|
|
1735
|
+
value,
|
|
1736
|
+
enumerable: true,
|
|
1737
|
+
configurable: true,
|
|
1738
|
+
writable: true
|
|
1739
|
+
});
|
|
1740
|
+
}
|
|
1741
|
+
function cloneMergeObject(source) {
|
|
1742
|
+
const output = {};
|
|
1743
|
+
for (const [key, value] of Object.entries(source)) {
|
|
1744
|
+
if (isMergeObject(value)) {
|
|
1745
|
+
setMergeProperty(output, key, cloneMergeObject(value));
|
|
1746
|
+
continue;
|
|
1747
|
+
}
|
|
1748
|
+
setMergeProperty(output, key, value);
|
|
1749
|
+
}
|
|
1750
|
+
return output;
|
|
1751
|
+
}
|
|
1752
|
+
function deepMerge(target, source) {
|
|
1753
|
+
const output = cloneMergeObject(target);
|
|
1754
|
+
for (const [key, sourceValue] of Object.entries(source)) {
|
|
1755
|
+
const targetValue = output[key];
|
|
1756
|
+
if (isMergeObject(sourceValue) && isMergeObject(targetValue)) {
|
|
1757
|
+
setMergeProperty(output, key, deepMerge(targetValue, sourceValue));
|
|
1758
|
+
continue;
|
|
1759
|
+
}
|
|
1760
|
+
if (isMergeObject(sourceValue)) {
|
|
1761
|
+
setMergeProperty(output, key, cloneMergeObject(sourceValue));
|
|
1762
|
+
continue;
|
|
1763
|
+
}
|
|
1764
|
+
setMergeProperty(output, key, sourceValue);
|
|
1765
|
+
}
|
|
1766
|
+
return output;
|
|
1767
|
+
}
|
|
1768
|
+
function shallowMerge(objects) {
|
|
1769
|
+
const output = {};
|
|
1770
|
+
for (const object of objects) {
|
|
1771
|
+
for (const [key, value] of Object.entries(object)) {
|
|
1772
|
+
setMergeProperty(output, key, value);
|
|
1773
|
+
}
|
|
1774
|
+
}
|
|
1775
|
+
return output;
|
|
1776
|
+
}
|
|
1713
1777
|
function createJsonMergeTool() {
|
|
1714
1778
|
return toolBuilder().name("json-merge").description("Merge two or more JSON objects. Later objects override earlier ones for conflicting keys.").category(ToolCategory.UTILITY).tags(["json", "merge", "combine", "data"]).schema(jsonMergeSchema).implement(async (input) => {
|
|
1715
1779
|
if (input.deep) {
|
|
1716
|
-
const deepMerge = (target, source) => {
|
|
1717
|
-
const output = { ...target };
|
|
1718
|
-
for (const key in source) {
|
|
1719
|
-
if (source[key] && typeof source[key] === "object" && !Array.isArray(source[key])) {
|
|
1720
|
-
output[key] = deepMerge(output[key] || {}, source[key]);
|
|
1721
|
-
} else {
|
|
1722
|
-
output[key] = source[key];
|
|
1723
|
-
}
|
|
1724
|
-
}
|
|
1725
|
-
return output;
|
|
1726
|
-
};
|
|
1727
1780
|
return input.objects.reduce((acc, obj) => deepMerge(acc, obj), {});
|
|
1728
1781
|
} else {
|
|
1729
|
-
return
|
|
1782
|
+
return shallowMerge(input.objects);
|
|
1730
1783
|
}
|
|
1731
1784
|
}).build();
|
|
1732
1785
|
}
|
|
@@ -10150,11 +10203,11 @@ var AskHumanInputSchema = z.object({
|
|
|
10150
10203
|
});
|
|
10151
10204
|
var logLevel3 = process.env.LOG_LEVEL?.toLowerCase() || LogLevel.INFO;
|
|
10152
10205
|
var logger22 = createLogger("agentforge:tools:agent:ask-human", { level: logLevel3 });
|
|
10153
|
-
function
|
|
10206
|
+
function isRecord2(value) {
|
|
10154
10207
|
return typeof value === "object" && value !== null;
|
|
10155
10208
|
}
|
|
10156
10209
|
function resolveInterrupt(module) {
|
|
10157
|
-
if (!
|
|
10210
|
+
if (!isRecord2(module)) {
|
|
10158
10211
|
return void 0;
|
|
10159
10212
|
}
|
|
10160
10213
|
const candidate = module.interrupt;
|