@easynet/agent-tool 1.0.24 → 1.0.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/api/extension/createExtension.d.ts +38 -0
- package/dist/api/extension/createExtension.d.ts.map +1 -0
- package/dist/api/extension/dynamicImportAdapter.d.ts +3 -2
- package/dist/api/extension/dynamicImportAdapter.d.ts.map +1 -1
- package/dist/api/extension/generateExtensionManifest.d.ts +29 -0
- package/dist/api/extension/generateExtensionManifest.d.ts.map +1 -0
- package/dist/api/extension/index.d.ts +4 -0
- package/dist/api/extension/index.d.ts.map +1 -1
- package/dist/api/extension/registerExtension.d.ts +6 -5
- package/dist/api/extension/registerExtension.d.ts.map +1 -1
- package/dist/api/extension/registerFromManifest.d.ts +2 -2
- package/dist/api/extension/registerFromManifest.d.ts.map +1 -1
- package/dist/api/main.cjs +14 -14
- package/dist/api/main.js +3 -3
- package/dist/api/runtimeFromConfig.d.ts +12 -10
- package/dist/api/runtimeFromConfig.d.ts.map +1 -1
- package/dist/{chunk-ZRDI2RKU.js → chunk-7J2DRVCV.js} +3 -3
- package/dist/{chunk-ZRDI2RKU.js.map → chunk-7J2DRVCV.js.map} +1 -1
- package/dist/{chunk-FWIMPZC2.cjs → chunk-EJSCDVKD.cjs} +14 -14
- package/dist/{chunk-FWIMPZC2.cjs.map → chunk-EJSCDVKD.cjs.map} +1 -1
- package/dist/{chunk-P2LVZGZ4.cjs → chunk-ETZKGTTF.cjs} +7 -7
- package/dist/{chunk-P2LVZGZ4.cjs.map → chunk-ETZKGTTF.cjs.map} +1 -1
- package/dist/{chunk-QP5FIRC2.js → chunk-GYUELFVR.js} +3 -3
- package/dist/{chunk-QP5FIRC2.js.map → chunk-GYUELFVR.js.map} +1 -1
- package/dist/{chunk-AH4NI4GN.cjs → chunk-PKUSCCS6.cjs} +84 -54
- package/dist/chunk-PKUSCCS6.cjs.map +1 -0
- package/dist/{chunk-BPHY6UVK.js → chunk-UUQGKFSG.js} +83 -53
- package/dist/chunk-UUQGKFSG.js.map +1 -0
- package/dist/{chunk-BOMOGAFZ.js → chunk-XRCHMWOC.js} +5 -4
- package/dist/chunk-XRCHMWOC.js.map +1 -0
- package/dist/{chunk-AT3N7SQK.cjs → chunk-ZOQWKN2O.cjs} +11 -10
- package/dist/chunk-ZOQWKN2O.cjs.map +1 -0
- package/dist/index.cjs +175 -73
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +120 -21
- package/dist/index.js.map +1 -1
- package/dist/tools/function/scanner.d.ts.map +1 -1
- package/dist/utils/cli/index.cjs +20 -18
- package/dist/utils/cli/index.cjs.map +1 -1
- package/dist/utils/cli/index.d.ts.map +1 -1
- package/dist/utils/cli/index.js +6 -4
- package/dist/utils/cli/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-AH4NI4GN.cjs.map +0 -1
- package/dist/chunk-AT3N7SQK.cjs.map +0 -1
- package/dist/chunk-BOMOGAFZ.js.map +0 -1
- package/dist/chunk-BPHY6UVK.js.map +0 -1
|
@@ -1731,18 +1731,14 @@ async function importFromCache(packageRoot) {
|
|
|
1731
1731
|
fileUrl
|
|
1732
1732
|
);
|
|
1733
1733
|
}
|
|
1734
|
-
var requireFromPackage = module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('chunk-
|
|
1734
|
+
var requireFromPackage = module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('chunk-PKUSCCS6.cjs', document.baseURI).href)));
|
|
1735
1735
|
function getProjectRequire() {
|
|
1736
1736
|
const cwd = process.cwd();
|
|
1737
1737
|
if (fs.existsSync(path.join(cwd, "package.json"))) return module$1.createRequire(path.join(cwd, "package.json"));
|
|
1738
1738
|
if (fs.existsSync(path.join(cwd, "tool.yaml"))) return module$1.createRequire(path.join(cwd, "tool.yaml"));
|
|
1739
1739
|
return null;
|
|
1740
1740
|
}
|
|
1741
|
-
var DEFAULT_EXTENSION_PACKAGES = [
|
|
1742
|
-
"@easynet/agent-tool-builtin-tools",
|
|
1743
|
-
"@easynet/agent-tool-builtin",
|
|
1744
|
-
"@easynet/agent-tool-buildin"
|
|
1745
|
-
];
|
|
1741
|
+
var DEFAULT_EXTENSION_PACKAGES = [];
|
|
1746
1742
|
function getInstalledPackageVersion(packageName) {
|
|
1747
1743
|
const projectRequire = getProjectRequire();
|
|
1748
1744
|
const requirers = [requireFromPackage];
|
|
@@ -1759,6 +1755,9 @@ function getInstalledPackageVersion(packageName) {
|
|
|
1759
1755
|
}
|
|
1760
1756
|
return null;
|
|
1761
1757
|
}
|
|
1758
|
+
function getRegisterFn(mod) {
|
|
1759
|
+
return mod?.register ?? mod?.registerCoreTools;
|
|
1760
|
+
}
|
|
1762
1761
|
function loadExtensionFromNodeModules() {
|
|
1763
1762
|
const projectRequire = getProjectRequire();
|
|
1764
1763
|
const requirers = [requireFromPackage];
|
|
@@ -1767,7 +1766,8 @@ function loadExtensionFromNodeModules() {
|
|
|
1767
1766
|
for (const pkg of DEFAULT_EXTENSION_PACKAGES) {
|
|
1768
1767
|
try {
|
|
1769
1768
|
const mod = req(pkg);
|
|
1770
|
-
|
|
1769
|
+
const fn = getRegisterFn(mod);
|
|
1770
|
+
if (typeof fn === "function") return { register: fn, packageName: pkg };
|
|
1771
1771
|
} catch {
|
|
1772
1772
|
continue;
|
|
1773
1773
|
}
|
|
@@ -1818,6 +1818,44 @@ function parseNpmDescriptor(entry) {
|
|
|
1818
1818
|
const version = rest.slice(at + 1).split("#")[0]?.trim() || "latest";
|
|
1819
1819
|
return { packageName, version };
|
|
1820
1820
|
}
|
|
1821
|
+
function loadExtensionFromToolYamlNodeModules(configFilePath, stepLog) {
|
|
1822
|
+
const localPath = path.isAbsolute(configFilePath) ? configFilePath : path.resolve(process.cwd(), configFilePath);
|
|
1823
|
+
if (!fs.existsSync(localPath)) return null;
|
|
1824
|
+
const config = loadToolConfig(localPath);
|
|
1825
|
+
const tools = config.tools;
|
|
1826
|
+
if (!Array.isArray(tools) || tools.length === 0) return null;
|
|
1827
|
+
const configDir = path.dirname(localPath);
|
|
1828
|
+
const packageJsonPath = path.join(configDir, "package.json");
|
|
1829
|
+
if (!fs.existsSync(packageJsonPath)) return null;
|
|
1830
|
+
const configRequire = module$1.createRequire(packageJsonPath);
|
|
1831
|
+
if (stepLog) stepLog("Trying tool.yaml npm entries from node_modules");
|
|
1832
|
+
for (const entry of tools) {
|
|
1833
|
+
const entryStr = String(entry).trim();
|
|
1834
|
+
const parsed = parseNpmDescriptor(entryStr);
|
|
1835
|
+
if (!parsed) continue;
|
|
1836
|
+
try {
|
|
1837
|
+
const mod = configRequire(parsed.packageName);
|
|
1838
|
+
const fn = getRegisterFn(mod);
|
|
1839
|
+
if (typeof fn === "function") {
|
|
1840
|
+
const resolvedVersion = getInstalledPackageVersionFromRequire(parsed.packageName, configRequire) ?? "latest";
|
|
1841
|
+
return { register: fn, descriptor: entryStr, resolvedVersion };
|
|
1842
|
+
}
|
|
1843
|
+
} catch {
|
|
1844
|
+
continue;
|
|
1845
|
+
}
|
|
1846
|
+
}
|
|
1847
|
+
return null;
|
|
1848
|
+
}
|
|
1849
|
+
function getInstalledPackageVersionFromRequire(packageName, req) {
|
|
1850
|
+
try {
|
|
1851
|
+
const pkgJsonPath = req.resolve(`${packageName}/package.json`);
|
|
1852
|
+
const json = fs.readFileSync(pkgJsonPath, "utf-8");
|
|
1853
|
+
const pkg = JSON.parse(json);
|
|
1854
|
+
return pkg.version ?? null;
|
|
1855
|
+
} catch {
|
|
1856
|
+
return null;
|
|
1857
|
+
}
|
|
1858
|
+
}
|
|
1821
1859
|
function loadExtensionFromToolYamlCache(configFilePath, stepLog) {
|
|
1822
1860
|
const localPath = path.isAbsolute(configFilePath) ? configFilePath : path.resolve(process.cwd(), configFilePath);
|
|
1823
1861
|
if (!fs.existsSync(localPath)) return null;
|
|
@@ -1839,9 +1877,10 @@ function loadExtensionFromToolYamlCache(configFilePath, stepLog) {
|
|
|
1839
1877
|
const entryPath = getPackageEntryPath(cacheDir);
|
|
1840
1878
|
const req = module$1.createRequire(path.join(cacheDir, "package.json"));
|
|
1841
1879
|
const mod = req(entryPath);
|
|
1842
|
-
|
|
1880
|
+
const fn = getRegisterFn(mod);
|
|
1881
|
+
if (typeof fn === "function") {
|
|
1843
1882
|
const resolvedVersion = path.basename(cacheDir);
|
|
1844
|
-
return {
|
|
1883
|
+
return { register: fn, descriptor: entryStr, resolvedVersion };
|
|
1845
1884
|
}
|
|
1846
1885
|
break;
|
|
1847
1886
|
} catch {
|
|
@@ -1871,9 +1910,10 @@ async function loadExtensionFromToolYamlCacheAsync(configFilePath, stepLog) {
|
|
|
1871
1910
|
const cacheDir = ensurePackageInCache(parsed.packageName, parsed.version, opts);
|
|
1872
1911
|
if (stepLog) stepLog(`Using cache: ${cacheDir}`);
|
|
1873
1912
|
const mod = await importFromCache(cacheDir);
|
|
1874
|
-
|
|
1913
|
+
const fn = getRegisterFn(mod);
|
|
1914
|
+
if (typeof fn === "function") {
|
|
1875
1915
|
const resolvedVersion = path.basename(cacheDir);
|
|
1876
|
-
return {
|
|
1916
|
+
return { register: fn, descriptor: entryStr, resolvedVersion };
|
|
1877
1917
|
}
|
|
1878
1918
|
break;
|
|
1879
1919
|
} catch {
|
|
@@ -1884,13 +1924,6 @@ async function loadExtensionFromToolYamlCacheAsync(configFilePath, stepLog) {
|
|
|
1884
1924
|
}
|
|
1885
1925
|
return null;
|
|
1886
1926
|
}
|
|
1887
|
-
function loadExampleTools() {
|
|
1888
|
-
try {
|
|
1889
|
-
return requireFromPackage("@easynet/agent-tool-example-tools");
|
|
1890
|
-
} catch {
|
|
1891
|
-
return null;
|
|
1892
|
-
}
|
|
1893
|
-
}
|
|
1894
1927
|
function createRuntimeFromConfigSync(options = {}) {
|
|
1895
1928
|
const registry = new chunkTOSPHMYU_cjs.ToolRegistry();
|
|
1896
1929
|
const stepLog = options.stepLog;
|
|
@@ -1903,70 +1936,67 @@ function createRuntimeFromConfigSync(options = {}) {
|
|
|
1903
1936
|
const resolvedVersion = getInstalledPackageVersion(extensionNode.packageName);
|
|
1904
1937
|
const prefix = npmDescriptorToRegistryPrefix(descriptor, resolvedVersion ?? void 0);
|
|
1905
1938
|
const reg = prefix ? createPrefixingRegistry(registry, prefix) : registry;
|
|
1906
|
-
const coreAdapter = extensionNode.
|
|
1939
|
+
const coreAdapter = extensionNode.register(reg, options.coreTools);
|
|
1907
1940
|
const runtime3 = new PTCRuntime({ registry });
|
|
1908
1941
|
runtime3.registerAdapter(coreAdapter);
|
|
1909
|
-
if (options.exampleTools !== void 0) {
|
|
1910
|
-
const example = loadExampleTools();
|
|
1911
|
-
if (example) {
|
|
1912
|
-
const exampleAdapter = example.registerExampleTools(registry, options.exampleTools);
|
|
1913
|
-
runtime3.registerAdapter(exampleAdapter);
|
|
1914
|
-
}
|
|
1915
|
-
}
|
|
1916
1942
|
return { runtime: runtime3, registry };
|
|
1917
1943
|
}
|
|
1918
1944
|
if (options.configFilePath) {
|
|
1945
|
+
const extensionFromNodeModules = loadExtensionFromToolYamlNodeModules(options.configFilePath, stepLog);
|
|
1946
|
+
if (extensionFromNodeModules) {
|
|
1947
|
+
if (stepLog) stepLog("Registered extension from tool.yaml list (node_modules)");
|
|
1948
|
+
const prefix = npmDescriptorToRegistryPrefix(extensionFromNodeModules.descriptor, extensionFromNodeModules.resolvedVersion);
|
|
1949
|
+
const reg = prefix ? createPrefixingRegistry(registry, prefix) : registry;
|
|
1950
|
+
const coreAdapter = extensionFromNodeModules.register(reg, options.coreTools);
|
|
1951
|
+
const runtime3 = new PTCRuntime({ registry });
|
|
1952
|
+
runtime3.registerAdapter(coreAdapter);
|
|
1953
|
+
return { runtime: runtime3, registry };
|
|
1954
|
+
}
|
|
1919
1955
|
if (stepLog) stepLog("No extension in node_modules, loading from tool.yaml cache");
|
|
1920
1956
|
const extensionCache = loadExtensionFromToolYamlCache(options.configFilePath, stepLog);
|
|
1921
1957
|
if (extensionCache) {
|
|
1922
1958
|
if (stepLog) stepLog("Registered extension from cache");
|
|
1923
1959
|
const prefix = npmDescriptorToRegistryPrefix(extensionCache.descriptor, extensionCache.resolvedVersion);
|
|
1924
1960
|
const reg = prefix ? createPrefixingRegistry(registry, prefix) : registry;
|
|
1925
|
-
const coreAdapter = extensionCache.
|
|
1961
|
+
const coreAdapter = extensionCache.register(reg, options.coreTools);
|
|
1926
1962
|
const runtime3 = new PTCRuntime({ registry });
|
|
1927
1963
|
runtime3.registerAdapter(coreAdapter);
|
|
1928
|
-
if (options.exampleTools !== void 0) {
|
|
1929
|
-
const example = loadExampleTools();
|
|
1930
|
-
if (example) {
|
|
1931
|
-
const exampleAdapter = example.registerExampleTools(registry, options.exampleTools);
|
|
1932
|
-
runtime3.registerAdapter(exampleAdapter);
|
|
1933
|
-
}
|
|
1934
|
-
}
|
|
1935
1964
|
return { runtime: runtime3, registry };
|
|
1936
1965
|
}
|
|
1937
1966
|
}
|
|
1938
1967
|
const runtime2 = new PTCRuntime({ registry });
|
|
1939
1968
|
return { runtime: runtime2, registry };
|
|
1940
1969
|
}
|
|
1941
|
-
if (options.exampleTools !== void 0) {
|
|
1942
|
-
const example = loadExampleTools();
|
|
1943
|
-
if (example) {
|
|
1944
|
-
const exampleAdapter = example.registerExampleTools(registry, options.exampleTools);
|
|
1945
|
-
const runtime2 = new PTCRuntime({ registry });
|
|
1946
|
-
runtime2.registerAdapter(exampleAdapter);
|
|
1947
|
-
return { runtime: runtime2, registry };
|
|
1948
|
-
}
|
|
1949
|
-
}
|
|
1950
1970
|
const runtime = new PTCRuntime({ registry });
|
|
1951
1971
|
return { runtime, registry };
|
|
1952
1972
|
}
|
|
1953
1973
|
async function createRuntimeFromConfig(options = {}) {
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
if (
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1974
|
+
if (options.coreTools !== void 0 && options.configFilePath) {
|
|
1975
|
+
const fromNodeModules = loadExtensionFromToolYamlNodeModules(options.configFilePath, options.stepLog);
|
|
1976
|
+
if (fromNodeModules) {
|
|
1977
|
+
if (options.stepLog) options.stepLog("Registered extension from tool.yaml list (node_modules)");
|
|
1978
|
+
const registry = new chunkTOSPHMYU_cjs.ToolRegistry();
|
|
1979
|
+
const prefix = npmDescriptorToRegistryPrefix(fromNodeModules.descriptor, fromNodeModules.resolvedVersion);
|
|
1980
|
+
const reg = prefix ? createPrefixingRegistry(registry, prefix) : registry;
|
|
1981
|
+
const coreAdapter = fromNodeModules.register(reg, options.coreTools);
|
|
1982
|
+
const runtime = new PTCRuntime({ registry });
|
|
1983
|
+
runtime.registerAdapter(coreAdapter);
|
|
1984
|
+
return { runtime, registry };
|
|
1985
|
+
}
|
|
1986
|
+
if (options.stepLog) options.stepLog("Loading extension from tool.yaml cache (dynamic: npm pack + import)");
|
|
1987
|
+
const fromCache = await loadExtensionFromToolYamlCacheAsync(options.configFilePath, options.stepLog);
|
|
1988
|
+
if (fromCache) {
|
|
1989
|
+
if (options.stepLog) options.stepLog("Registered extension from cache");
|
|
1960
1990
|
const registry = new chunkTOSPHMYU_cjs.ToolRegistry();
|
|
1961
|
-
const prefix = npmDescriptorToRegistryPrefix(
|
|
1991
|
+
const prefix = npmDescriptorToRegistryPrefix(fromCache.descriptor, fromCache.resolvedVersion);
|
|
1962
1992
|
const reg = prefix ? createPrefixingRegistry(registry, prefix) : registry;
|
|
1963
|
-
const coreAdapter =
|
|
1993
|
+
const coreAdapter = fromCache.register(reg, options.coreTools);
|
|
1964
1994
|
const runtime = new PTCRuntime({ registry });
|
|
1965
1995
|
runtime.registerAdapter(coreAdapter);
|
|
1966
1996
|
return { runtime, registry };
|
|
1967
1997
|
}
|
|
1968
1998
|
}
|
|
1969
|
-
return
|
|
1999
|
+
return createRuntimeFromConfigSync(options);
|
|
1970
2000
|
}
|
|
1971
2001
|
|
|
1972
2002
|
// src/tools/mcp/types.ts
|
|
@@ -2009,5 +2039,5 @@ exports.resolveSandboxedPath = resolveSandboxedPath;
|
|
|
2009
2039
|
exports.resolveToolDescriptor = resolveToolDescriptor;
|
|
2010
2040
|
exports.sanitizeForLog = sanitizeForLog;
|
|
2011
2041
|
exports.summarizeForLog = summarizeForLog;
|
|
2012
|
-
//# sourceMappingURL=chunk-
|
|
2013
|
-
//# sourceMappingURL=chunk-
|
|
2042
|
+
//# sourceMappingURL=chunk-PKUSCCS6.cjs.map
|
|
2043
|
+
//# sourceMappingURL=chunk-PKUSCCS6.cjs.map
|