@easynet/agent-tool 1.0.19 → 1.0.20
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/api/main.cjs +15 -15
- package/dist/api/main.js +4 -4
- package/dist/api/runtimeFromConfig.d.ts.map +1 -1
- package/dist/canonicalCoreSchemas-JPTOIQKR.js +4 -0
- package/dist/{canonicalCoreSchemas-DNBAHSUC.js.map → canonicalCoreSchemas-JPTOIQKR.js.map} +1 -1
- package/dist/canonicalCoreSchemas-K57HKGZJ.cjs +21 -0
- package/dist/{canonicalCoreSchemas-IBTSIPJV.cjs.map → canonicalCoreSchemas-K57HKGZJ.cjs.map} +1 -1
- package/dist/{chunk-EAI37B5W.cjs → chunk-6JWQVVL2.cjs} +4 -3
- package/dist/chunk-6JWQVVL2.cjs.map +1 -0
- package/dist/{chunk-NNOTTUB2.cjs → chunk-6WQYJLVU.cjs} +132 -29
- package/dist/chunk-6WQYJLVU.cjs.map +1 -0
- package/dist/{chunk-TTYAOTOR.js → chunk-IGMDLCV7.js} +132 -30
- package/dist/chunk-IGMDLCV7.js.map +1 -0
- package/dist/{chunk-H2UMNHDE.cjs → chunk-INYWD3OJ.cjs} +10 -10
- package/dist/{chunk-H2UMNHDE.cjs.map → chunk-INYWD3OJ.cjs.map} +1 -1
- package/dist/{chunk-Y33OLGAJ.js → chunk-NNMMUG2X.js} +3 -3
- package/dist/{chunk-Y33OLGAJ.js.map → chunk-NNMMUG2X.js.map} +1 -1
- package/dist/{chunk-QB5ALDM3.js → chunk-OHDIMQ22.js} +3 -3
- package/dist/{chunk-QB5ALDM3.js.map → chunk-OHDIMQ22.js.map} +1 -1
- package/dist/{chunk-46XYOB3H.js → chunk-P5UPHQ7N.js} +4 -3
- package/dist/chunk-P5UPHQ7N.js.map +1 -0
- package/dist/{chunk-TPWEGGKQ.cjs → chunk-QP6JJF76.cjs} +9 -9
- package/dist/{chunk-TPWEGGKQ.cjs.map → chunk-QP6JJF76.cjs.map} +1 -1
- package/dist/{chunk-HISF2FEL.cjs → chunk-TAW4FP3A.cjs} +18 -18
- package/dist/{chunk-HISF2FEL.cjs.map → chunk-TAW4FP3A.cjs.map} +1 -1
- package/dist/{chunk-GGKQQR54.js → chunk-WKWSXCS4.js} +5 -5
- package/dist/{chunk-GGKQQR54.js.map → chunk-WKWSXCS4.js.map} +1 -1
- package/dist/index.cjs +52 -48
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -6
- package/dist/tools/util/canonicalCoreSchemas.d.ts.map +1 -1
- package/dist/tools/util/index.d.ts +1 -1
- package/dist/tools/util/index.d.ts.map +1 -1
- package/dist/tools/util/toolDescriptor.d.ts +9 -0
- package/dist/tools/util/toolDescriptor.d.ts.map +1 -1
- package/dist/utils/cli/index.cjs +19 -19
- package/dist/utils/cli/index.js +4 -4
- package/package.json +1 -1
- package/dist/canonicalCoreSchemas-DNBAHSUC.js +0 -4
- package/dist/canonicalCoreSchemas-IBTSIPJV.cjs +0 -21
- package/dist/chunk-46XYOB3H.js.map +0 -1
- package/dist/chunk-EAI37B5W.cjs.map +0 -1
- package/dist/chunk-NNOTTUB2.cjs.map +0 -1
- package/dist/chunk-TTYAOTOR.js.map +0 -1
|
@@ -7,7 +7,7 @@ import { EventEmitter } from 'eventemitter3';
|
|
|
7
7
|
import { v4 } from 'uuid';
|
|
8
8
|
import pTimeout from 'p-timeout';
|
|
9
9
|
import { readFileSync, existsSync, mkdirSync, readdirSync, rmSync, renameSync } from 'fs';
|
|
10
|
-
import { join, resolve, dirname, isAbsolute } from 'path';
|
|
10
|
+
import { join, resolve, dirname, isAbsolute, basename } from 'path';
|
|
11
11
|
import { homedir } from 'os';
|
|
12
12
|
import yaml from 'js-yaml';
|
|
13
13
|
import { execSync } from 'child_process';
|
|
@@ -1500,6 +1500,26 @@ function parseToolPath(descriptor) {
|
|
|
1500
1500
|
toolName: m[5] ?? ""
|
|
1501
1501
|
};
|
|
1502
1502
|
}
|
|
1503
|
+
function npmDescriptorToRegistryPrefix(descriptor, resolvedVersion) {
|
|
1504
|
+
const s = descriptor.trim();
|
|
1505
|
+
if (typeof s !== "string" || !s.startsWith("npm:")) return "";
|
|
1506
|
+
const rest = s.slice(4).trim();
|
|
1507
|
+
const hashIdx = rest.indexOf("#");
|
|
1508
|
+
const beforeHash = hashIdx < 0 ? rest : rest.slice(0, hashIdx);
|
|
1509
|
+
const lastAt = beforeHash.lastIndexOf("@");
|
|
1510
|
+
const scopeAndPackage = lastAt <= 0 ? beforeHash : beforeHash.slice(0, lastAt);
|
|
1511
|
+
let version = lastAt <= 0 ? "latest" : beforeHash.slice(lastAt + 1).trim() || "latest";
|
|
1512
|
+
if ((version === "latest" || !version) && resolvedVersion != null && resolvedVersion !== "") {
|
|
1513
|
+
version = resolvedVersion;
|
|
1514
|
+
}
|
|
1515
|
+
const slashIdx = scopeAndPackage.indexOf("/");
|
|
1516
|
+
const scope = slashIdx < 0 ? scopeAndPackage : scopeAndPackage.slice(0, slashIdx).replace(/^@/, "");
|
|
1517
|
+
const pkg = slashIdx < 0 ? "" : scopeAndPackage.slice(slashIdx + 1);
|
|
1518
|
+
const segment = [scope, pkg, version].filter(Boolean).join(".");
|
|
1519
|
+
const normalized = normalizeToolName(segment);
|
|
1520
|
+
if (!normalized) return "";
|
|
1521
|
+
return "npm." + normalized + ".";
|
|
1522
|
+
}
|
|
1503
1523
|
function isNpmToolDescriptor(descriptor) {
|
|
1504
1524
|
return isToolPath(descriptor) && parseToolPath(descriptor)?.protocol === "npm";
|
|
1505
1525
|
}
|
|
@@ -1522,15 +1542,31 @@ function expandToolDescriptorsToRegistryNames(descriptors, registryNames) {
|
|
|
1522
1542
|
const out = [];
|
|
1523
1543
|
const seen = /* @__PURE__ */ new Set();
|
|
1524
1544
|
function add(name) {
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1545
|
+
const key = normalizeToolName(name);
|
|
1546
|
+
if (registryNames.includes(key) && !seen.has(key)) {
|
|
1547
|
+
seen.add(key);
|
|
1548
|
+
out.push(key);
|
|
1549
|
+
return;
|
|
1550
|
+
}
|
|
1551
|
+
const matched = registryNames.filter((r) => r === key || r.endsWith("." + key));
|
|
1552
|
+
for (const m of matched) {
|
|
1553
|
+
if (!seen.has(m)) {
|
|
1554
|
+
seen.add(m);
|
|
1555
|
+
out.push(m);
|
|
1556
|
+
}
|
|
1528
1557
|
}
|
|
1529
1558
|
}
|
|
1530
1559
|
for (const d of descriptors) {
|
|
1531
1560
|
const s = d.trim();
|
|
1532
1561
|
if (!s) continue;
|
|
1533
|
-
|
|
1562
|
+
if (isToolPath(s)) {
|
|
1563
|
+
if (registryNames.includes(s) && !seen.has(s)) {
|
|
1564
|
+
seen.add(s);
|
|
1565
|
+
out.push(s);
|
|
1566
|
+
}
|
|
1567
|
+
continue;
|
|
1568
|
+
}
|
|
1569
|
+
const name = normalizeToolName(s);
|
|
1534
1570
|
add(name);
|
|
1535
1571
|
}
|
|
1536
1572
|
return out;
|
|
@@ -1697,6 +1733,22 @@ var BUILTIN_PKG_NAMES = [
|
|
|
1697
1733
|
"@easynet/agent-tool-builtin",
|
|
1698
1734
|
"@easynet/agent-tool-buildin"
|
|
1699
1735
|
];
|
|
1736
|
+
function getInstalledPackageVersion(packageName) {
|
|
1737
|
+
const projectRequire = getProjectRequire();
|
|
1738
|
+
const requirers = [requireFromPackage];
|
|
1739
|
+
if (projectRequire) requirers.push(projectRequire);
|
|
1740
|
+
for (const req of requirers) {
|
|
1741
|
+
try {
|
|
1742
|
+
const pkgJsonPath = req.resolve(`${packageName}/package.json`);
|
|
1743
|
+
const json = readFileSync(pkgJsonPath, "utf-8");
|
|
1744
|
+
const pkg = JSON.parse(json);
|
|
1745
|
+
return pkg.version ?? null;
|
|
1746
|
+
} catch {
|
|
1747
|
+
continue;
|
|
1748
|
+
}
|
|
1749
|
+
}
|
|
1750
|
+
return null;
|
|
1751
|
+
}
|
|
1700
1752
|
function loadBuiltinTools() {
|
|
1701
1753
|
const projectRequire = getProjectRequire();
|
|
1702
1754
|
const requirers = [requireFromPackage];
|
|
@@ -1705,7 +1757,7 @@ function loadBuiltinTools() {
|
|
|
1705
1757
|
for (const pkg of BUILTIN_PKG_NAMES) {
|
|
1706
1758
|
try {
|
|
1707
1759
|
const mod = req(pkg);
|
|
1708
|
-
if (mod && typeof mod.registerCoreTools === "function") return mod;
|
|
1760
|
+
if (mod && typeof mod.registerCoreTools === "function") return { registerCoreTools: mod.registerCoreTools, packageName: pkg };
|
|
1709
1761
|
} catch {
|
|
1710
1762
|
continue;
|
|
1711
1763
|
}
|
|
@@ -1713,6 +1765,40 @@ function loadBuiltinTools() {
|
|
|
1713
1765
|
}
|
|
1714
1766
|
return null;
|
|
1715
1767
|
}
|
|
1768
|
+
function createPrefixingRegistry(registry, prefix) {
|
|
1769
|
+
return {
|
|
1770
|
+
register(spec) {
|
|
1771
|
+
registry.register({ ...spec, name: prefix + normalizeToolName(spec.name) });
|
|
1772
|
+
},
|
|
1773
|
+
bulkRegister(specs) {
|
|
1774
|
+
specs.forEach((s) => this.register(s));
|
|
1775
|
+
},
|
|
1776
|
+
unregister(name) {
|
|
1777
|
+
return registry.unregister(name);
|
|
1778
|
+
},
|
|
1779
|
+
get(name) {
|
|
1780
|
+
return registry.get(name);
|
|
1781
|
+
},
|
|
1782
|
+
has(name) {
|
|
1783
|
+
return registry.has(name);
|
|
1784
|
+
},
|
|
1785
|
+
search(query) {
|
|
1786
|
+
return registry.search(query);
|
|
1787
|
+
},
|
|
1788
|
+
list() {
|
|
1789
|
+
return registry.list();
|
|
1790
|
+
},
|
|
1791
|
+
get size() {
|
|
1792
|
+
return registry.size;
|
|
1793
|
+
},
|
|
1794
|
+
snapshot() {
|
|
1795
|
+
return registry.snapshot();
|
|
1796
|
+
},
|
|
1797
|
+
clear() {
|
|
1798
|
+
return registry.clear();
|
|
1799
|
+
}
|
|
1800
|
+
};
|
|
1801
|
+
}
|
|
1716
1802
|
function parseNpmDescriptor(entry) {
|
|
1717
1803
|
if (typeof entry !== "string" || !entry.startsWith("npm:")) return null;
|
|
1718
1804
|
const rest = entry.slice(4).trim();
|
|
@@ -1732,7 +1818,8 @@ function loadBuiltinFromToolYamlCache(configFilePath, stepLog) {
|
|
|
1732
1818
|
const cacheOpts = cacheBase ? { cacheBase } : {};
|
|
1733
1819
|
if (stepLog) stepLog(`Loading builtin from tool.yaml cache (cacheBase: ${cacheBase ?? "~/.agent/cache"})`);
|
|
1734
1820
|
for (const entry of tools) {
|
|
1735
|
-
const
|
|
1821
|
+
const entryStr = String(entry).trim();
|
|
1822
|
+
const parsed = parseNpmDescriptor(entryStr);
|
|
1736
1823
|
if (!parsed || !BUILTIN_PKG_NAMES.includes(parsed.packageName)) continue;
|
|
1737
1824
|
for (const opts of [cacheOpts, {}]) {
|
|
1738
1825
|
try {
|
|
@@ -1742,7 +1829,10 @@ function loadBuiltinFromToolYamlCache(configFilePath, stepLog) {
|
|
|
1742
1829
|
const entryPath = getPackageEntryPath(cacheDir);
|
|
1743
1830
|
const req = createRequire(join(cacheDir, "package.json"));
|
|
1744
1831
|
const mod = req(entryPath);
|
|
1745
|
-
if (mod && typeof mod.registerCoreTools === "function")
|
|
1832
|
+
if (mod && typeof mod.registerCoreTools === "function") {
|
|
1833
|
+
const resolvedVersion = basename(cacheDir);
|
|
1834
|
+
return { registerCoreTools: mod.registerCoreTools, descriptor: entryStr, resolvedVersion };
|
|
1835
|
+
}
|
|
1746
1836
|
break;
|
|
1747
1837
|
} catch {
|
|
1748
1838
|
if (Object.keys(opts).length > 0) continue;
|
|
@@ -1762,7 +1852,8 @@ async function loadBuiltinFromToolYamlCacheAsync(configFilePath, stepLog) {
|
|
|
1762
1852
|
const cacheOpts = cacheBase ? { cacheBase } : {};
|
|
1763
1853
|
if (stepLog) stepLog("Loading builtin from tool.yaml cache (async)");
|
|
1764
1854
|
for (const entry of tools) {
|
|
1765
|
-
const
|
|
1855
|
+
const entryStr = String(entry).trim();
|
|
1856
|
+
const parsed = parseNpmDescriptor(entryStr);
|
|
1766
1857
|
if (!parsed || !BUILTIN_PKG_NAMES.includes(parsed.packageName)) continue;
|
|
1767
1858
|
for (const opts of [cacheOpts, {}]) {
|
|
1768
1859
|
try {
|
|
@@ -1770,7 +1861,10 @@ async function loadBuiltinFromToolYamlCacheAsync(configFilePath, stepLog) {
|
|
|
1770
1861
|
const cacheDir = ensurePackageInCache(parsed.packageName, parsed.version, opts);
|
|
1771
1862
|
if (stepLog) stepLog(`Using cache: ${cacheDir}`);
|
|
1772
1863
|
const mod = await importFromCache(cacheDir);
|
|
1773
|
-
if (mod && typeof mod.registerCoreTools === "function")
|
|
1864
|
+
if (mod && typeof mod.registerCoreTools === "function") {
|
|
1865
|
+
const resolvedVersion = basename(cacheDir);
|
|
1866
|
+
return { registerCoreTools: mod.registerCoreTools, descriptor: entryStr, resolvedVersion };
|
|
1867
|
+
}
|
|
1774
1868
|
break;
|
|
1775
1869
|
} catch {
|
|
1776
1870
|
if (Object.keys(opts).length > 0) continue;
|
|
@@ -1792,10 +1886,14 @@ function createRuntimeFromConfigSync(options = {}) {
|
|
|
1792
1886
|
const stepLog = options.stepLog;
|
|
1793
1887
|
if (options.coreTools !== void 0) {
|
|
1794
1888
|
if (stepLog) stepLog("Trying builtin from node_modules");
|
|
1795
|
-
let
|
|
1796
|
-
if (
|
|
1889
|
+
let builtinNode = loadBuiltinTools();
|
|
1890
|
+
if (builtinNode) {
|
|
1797
1891
|
if (stepLog) stepLog("Registered builtin from node_modules");
|
|
1798
|
-
const
|
|
1892
|
+
const descriptor = `npm:${builtinNode.packageName}`;
|
|
1893
|
+
const resolvedVersion = getInstalledPackageVersion(builtinNode.packageName);
|
|
1894
|
+
const prefix = npmDescriptorToRegistryPrefix(descriptor, resolvedVersion ?? void 0);
|
|
1895
|
+
const reg = prefix ? createPrefixingRegistry(registry, prefix) : registry;
|
|
1896
|
+
const coreAdapter = builtinNode.registerCoreTools(reg, options.coreTools);
|
|
1799
1897
|
const runtime3 = new PTCRuntime({ registry });
|
|
1800
1898
|
runtime3.registerAdapter(coreAdapter);
|
|
1801
1899
|
if (options.exampleTools !== void 0) {
|
|
@@ -1809,21 +1907,23 @@ function createRuntimeFromConfigSync(options = {}) {
|
|
|
1809
1907
|
}
|
|
1810
1908
|
if (options.configFilePath) {
|
|
1811
1909
|
if (stepLog) stepLog("No builtin in node_modules, loading from tool.yaml cache");
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1910
|
+
const builtinCache = loadBuiltinFromToolYamlCache(options.configFilePath, stepLog);
|
|
1911
|
+
if (builtinCache) {
|
|
1912
|
+
if (stepLog) stepLog("Registered builtin from cache");
|
|
1913
|
+
const prefix = npmDescriptorToRegistryPrefix(builtinCache.descriptor, builtinCache.resolvedVersion);
|
|
1914
|
+
const reg = prefix ? createPrefixingRegistry(registry, prefix) : registry;
|
|
1915
|
+
const coreAdapter = builtinCache.registerCoreTools(reg, options.coreTools);
|
|
1916
|
+
const runtime3 = new PTCRuntime({ registry });
|
|
1917
|
+
runtime3.registerAdapter(coreAdapter);
|
|
1918
|
+
if (options.exampleTools !== void 0) {
|
|
1919
|
+
const example = loadExampleTools();
|
|
1920
|
+
if (example) {
|
|
1921
|
+
const exampleAdapter = example.registerExampleTools(registry, options.exampleTools);
|
|
1922
|
+
runtime3.registerAdapter(exampleAdapter);
|
|
1923
|
+
}
|
|
1824
1924
|
}
|
|
1925
|
+
return { runtime: runtime3, registry };
|
|
1825
1926
|
}
|
|
1826
|
-
return { runtime: runtime3, registry };
|
|
1827
1927
|
}
|
|
1828
1928
|
const runtime2 = new PTCRuntime({ registry });
|
|
1829
1929
|
return { runtime: runtime2, registry };
|
|
@@ -1848,7 +1948,9 @@ async function createRuntimeFromConfig(options = {}) {
|
|
|
1848
1948
|
if (builtin) {
|
|
1849
1949
|
if (options.stepLog) options.stepLog("Registered builtin from async cache");
|
|
1850
1950
|
const registry = new ToolRegistry();
|
|
1851
|
-
const
|
|
1951
|
+
const prefix = npmDescriptorToRegistryPrefix(builtin.descriptor, builtin.resolvedVersion);
|
|
1952
|
+
const reg = prefix ? createPrefixingRegistry(registry, prefix) : registry;
|
|
1953
|
+
const coreAdapter = builtin.registerCoreTools(reg, options.coreTools);
|
|
1852
1954
|
const runtime = new PTCRuntime({ registry });
|
|
1853
1955
|
runtime.registerAdapter(coreAdapter);
|
|
1854
1956
|
return { runtime, registry };
|
|
@@ -1864,6 +1966,6 @@ var MCP_KIND = "mcp";
|
|
|
1864
1966
|
var LANGCHAIN_KIND = "langchain";
|
|
1865
1967
|
var LANGCHAIN_DIR_NAME = "langchain";
|
|
1866
1968
|
|
|
1867
|
-
export { BUILTIN_PKG_NAMES, BudgetManager, EventLog, LANGCHAIN_DIR_NAME, LANGCHAIN_KIND, MCP_KIND, Metrics, PTCRuntime, PolicyDeniedError, PolicyEngine, SchemaValidationError, SchemaValidator, Tracing, buildEvidence, createLogger, createRuntimeFromConfig, createRuntimeFromConfigSync, ensurePackageInCache, expandToolDescriptorsToRegistryNames, findAndLoadToolConfig, getDisplayScope, getPackageEntryPath, importFromCache, isBarePackageDescriptor, isNpmToolDescriptor, loadToolConfig, normalizeToolList, parseNpmDescriptor, parseNpmToolDescriptor, resolveNpmToolDescriptor, resolveSandboxedPath, resolveToolDescriptor, sanitizeForLog, summarizeForLog };
|
|
1868
|
-
//# sourceMappingURL=chunk-
|
|
1869
|
-
//# sourceMappingURL=chunk-
|
|
1969
|
+
export { BUILTIN_PKG_NAMES, BudgetManager, EventLog, LANGCHAIN_DIR_NAME, LANGCHAIN_KIND, MCP_KIND, Metrics, PTCRuntime, PolicyDeniedError, PolicyEngine, SchemaValidationError, SchemaValidator, Tracing, buildEvidence, createLogger, createRuntimeFromConfig, createRuntimeFromConfigSync, ensurePackageInCache, expandToolDescriptorsToRegistryNames, findAndLoadToolConfig, getDisplayScope, getPackageEntryPath, importFromCache, isBarePackageDescriptor, isNpmToolDescriptor, loadToolConfig, normalizeToolList, npmDescriptorToRegistryPrefix, parseNpmDescriptor, parseNpmToolDescriptor, resolveNpmToolDescriptor, resolveSandboxedPath, resolveToolDescriptor, sanitizeForLog, summarizeForLog };
|
|
1970
|
+
//# sourceMappingURL=chunk-IGMDLCV7.js.map
|
|
1971
|
+
//# sourceMappingURL=chunk-IGMDLCV7.js.map
|