@easynet/agent-tool 1.0.40 → 1.0.41
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 +14 -14
- package/dist/api/main.js +3 -3
- package/dist/{chunk-QRI34I5Z.js → chunk-4MAR5XDN.js} +3 -3
- package/dist/{chunk-QRI34I5Z.js.map → chunk-4MAR5XDN.js.map} +1 -1
- package/dist/{chunk-ZPXO5IOW.cjs → chunk-CTB3RP4C.cjs} +15 -15
- package/dist/{chunk-ZPXO5IOW.cjs.map → chunk-CTB3RP4C.cjs.map} +1 -1
- package/dist/{chunk-TSJRMNOB.cjs → chunk-GVYVTQUB.cjs} +7 -7
- package/dist/{chunk-TSJRMNOB.cjs.map → chunk-GVYVTQUB.cjs.map} +1 -1
- package/dist/{chunk-4NNTCCJ6.cjs → chunk-LO5Y3D4O.cjs} +9 -9
- package/dist/{chunk-4NNTCCJ6.cjs.map → chunk-LO5Y3D4O.cjs.map} +1 -1
- package/dist/{chunk-GWUMQRCN.js → chunk-NE3PKHM7.js} +3 -3
- package/dist/{chunk-GWUMQRCN.js.map → chunk-NE3PKHM7.js.map} +1 -1
- package/dist/{chunk-J5VQMYUV.cjs → chunk-PAXUM4QS.cjs} +27 -159
- package/dist/chunk-PAXUM4QS.cjs.map +1 -0
- package/dist/{chunk-3AEYVD7K.js → chunk-TXZITBLR.js} +7 -150
- package/dist/chunk-TXZITBLR.js.map +1 -0
- package/dist/{chunk-OSENBU42.js → chunk-UFV5ZRAX.js} +3 -3
- package/dist/{chunk-OSENBU42.js.map → chunk-UFV5ZRAX.js.map} +1 -1
- package/dist/index.cjs +52 -52
- package/dist/index.js +5 -5
- package/dist/utils/cli/index.cjs +17 -17
- package/dist/utils/cli/index.js +3 -3
- package/dist/utils/npmCache.d.ts +1 -41
- package/dist/utils/npmCache.d.ts.map +1 -1
- package/package.json +3 -2
- package/dist/chunk-3AEYVD7K.js.map +0 -1
- package/dist/chunk-J5VQMYUV.cjs.map +0 -1
|
@@ -13,8 +13,7 @@ var promises = require('fs/promises');
|
|
|
13
13
|
var fs = require('fs');
|
|
14
14
|
var os = require('os');
|
|
15
15
|
var yaml = require('js-yaml');
|
|
16
|
-
var
|
|
17
|
-
var url = require('url');
|
|
16
|
+
var agentCommon = require('@easynet/agent-common');
|
|
18
17
|
var module$1 = require('module');
|
|
19
18
|
|
|
20
19
|
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
@@ -1778,150 +1777,7 @@ function findAndLoadToolConfig(dir) {
|
|
|
1778
1777
|
}
|
|
1779
1778
|
return {};
|
|
1780
1779
|
}
|
|
1781
|
-
var
|
|
1782
|
-
function isLatestRequest(version) {
|
|
1783
|
-
const v = (version ?? "").trim().toLowerCase();
|
|
1784
|
-
return v === "" || v === "latest";
|
|
1785
|
-
}
|
|
1786
|
-
function resolveLatestVersionFromRegistry(packageName) {
|
|
1787
|
-
const quoted = packageName.includes(" ") ? `"${packageName}"` : packageName;
|
|
1788
|
-
try {
|
|
1789
|
-
const out = child_process.execSync(`npm view ${quoted} version`, {
|
|
1790
|
-
encoding: "utf-8",
|
|
1791
|
-
stdio: ["pipe", "pipe", "pipe"]
|
|
1792
|
-
});
|
|
1793
|
-
const version = (out ?? "").trim();
|
|
1794
|
-
if (!version) {
|
|
1795
|
-
throw new Error(`npm view ${packageName} version returned empty`);
|
|
1796
|
-
}
|
|
1797
|
-
return version;
|
|
1798
|
-
} catch (err) {
|
|
1799
|
-
const msg = err instanceof Error ? err.message : String(err);
|
|
1800
|
-
throw new Error(`Failed to resolve latest version for ${packageName}: ${msg}`);
|
|
1801
|
-
}
|
|
1802
|
-
}
|
|
1803
|
-
function getCachedPackageVersion(cacheDir) {
|
|
1804
|
-
const pkgPath = path.join(cacheDir, "package.json");
|
|
1805
|
-
if (!fs.existsSync(pkgPath)) return void 0;
|
|
1806
|
-
try {
|
|
1807
|
-
const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf-8"));
|
|
1808
|
-
return typeof pkg.version === "string" ? pkg.version : void 0;
|
|
1809
|
-
} catch {
|
|
1810
|
-
return void 0;
|
|
1811
|
-
}
|
|
1812
|
-
}
|
|
1813
|
-
function packagePathSegments(name) {
|
|
1814
|
-
const withoutScope = name.replace(/^@/, "");
|
|
1815
|
-
return withoutScope.split("/").filter(Boolean);
|
|
1816
|
-
}
|
|
1817
|
-
function resolveCacheDir(cacheBase, packageName, version) {
|
|
1818
|
-
const segments = packagePathSegments(packageName);
|
|
1819
|
-
return path.join(cacheBase, ...segments, version);
|
|
1820
|
-
}
|
|
1821
|
-
function ensurePackageInCache(packageName, version = "latest", options = {}) {
|
|
1822
|
-
const cacheBase = options.cacheBase ?? DEFAULT_CACHE_BASE;
|
|
1823
|
-
let resolvedVersion;
|
|
1824
|
-
if (isLatestRequest(version)) {
|
|
1825
|
-
resolvedVersion = resolveLatestVersionFromRegistry(packageName);
|
|
1826
|
-
} else {
|
|
1827
|
-
resolvedVersion = version;
|
|
1828
|
-
}
|
|
1829
|
-
const cacheDir = resolveCacheDir(cacheBase, packageName, resolvedVersion);
|
|
1830
|
-
const packageJsonPath = path.join(cacheDir, "package.json");
|
|
1831
|
-
const nodeModulesPath = path.join(cacheDir, "node_modules");
|
|
1832
|
-
if (fs.existsSync(packageJsonPath) && fs.existsSync(nodeModulesPath)) {
|
|
1833
|
-
const cachedVersion = getCachedPackageVersion(cacheDir);
|
|
1834
|
-
if (cachedVersion === resolvedVersion) {
|
|
1835
|
-
options.afterInstall?.(cacheDir, packageName);
|
|
1836
|
-
return cacheDir;
|
|
1837
|
-
}
|
|
1838
|
-
fs.rmSync(cacheDir, { recursive: true, force: true });
|
|
1839
|
-
}
|
|
1840
|
-
const packDest = path.join(cacheBase, ".pack-tmp", packageName.replace(/@/g, "").replace(/\//g, "_"));
|
|
1841
|
-
fs.mkdirSync(packDest, { recursive: true });
|
|
1842
|
-
try {
|
|
1843
|
-
child_process.execSync(`npm pack ${packageName}@${resolvedVersion} --pack-destination "${packDest}"`, {
|
|
1844
|
-
cwd: process.cwd(),
|
|
1845
|
-
stdio: "pipe",
|
|
1846
|
-
encoding: "utf-8"
|
|
1847
|
-
});
|
|
1848
|
-
const files = fs.readdirSync(packDest);
|
|
1849
|
-
const tgz = files.find((f) => f.endsWith(".tgz"));
|
|
1850
|
-
if (!tgz) {
|
|
1851
|
-
throw new Error(`npm pack did not produce a .tgz in ${packDest}`);
|
|
1852
|
-
}
|
|
1853
|
-
const extractDir = path.join(packDest, "extract");
|
|
1854
|
-
fs.mkdirSync(extractDir, { recursive: true });
|
|
1855
|
-
child_process.execSync(`tar -xzf "${path.join(packDest, tgz)}" -C "${extractDir}"`, {
|
|
1856
|
-
stdio: "pipe",
|
|
1857
|
-
encoding: "utf-8"
|
|
1858
|
-
});
|
|
1859
|
-
const extractedPackage = path.join(extractDir, "package");
|
|
1860
|
-
if (!fs.existsSync(extractedPackage)) {
|
|
1861
|
-
throw new Error(`Extracted tarball did not contain "package" dir in ${extractDir}`);
|
|
1862
|
-
}
|
|
1863
|
-
fs.mkdirSync(path.join(cacheDir, ".."), { recursive: true });
|
|
1864
|
-
if (fs.existsSync(cacheDir)) {
|
|
1865
|
-
fs.rmSync(cacheDir, { recursive: true, force: true });
|
|
1866
|
-
}
|
|
1867
|
-
fs.renameSync(extractedPackage, cacheDir);
|
|
1868
|
-
const npmInstallTimeout = 12e4;
|
|
1869
|
-
const maxAttempts = 3;
|
|
1870
|
-
let lastErr;
|
|
1871
|
-
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
|
|
1872
|
-
try {
|
|
1873
|
-
child_process.execSync("npm install --prefer-offline --no-audit --no-fund", {
|
|
1874
|
-
cwd: cacheDir,
|
|
1875
|
-
stdio: "pipe",
|
|
1876
|
-
encoding: "utf-8",
|
|
1877
|
-
timeout: npmInstallTimeout
|
|
1878
|
-
});
|
|
1879
|
-
lastErr = void 0;
|
|
1880
|
-
break;
|
|
1881
|
-
} catch (err) {
|
|
1882
|
-
lastErr = err instanceof Error ? err : new Error(String(err));
|
|
1883
|
-
if (attempt < maxAttempts) {
|
|
1884
|
-
const delayMs = 5e3 * attempt;
|
|
1885
|
-
const deadline = Date.now() + delayMs;
|
|
1886
|
-
while (Date.now() < deadline) {
|
|
1887
|
-
}
|
|
1888
|
-
} else {
|
|
1889
|
-
throw new Error(
|
|
1890
|
-
`npm install in cache failed after ${maxAttempts} attempts: ${lastErr.message}`
|
|
1891
|
-
);
|
|
1892
|
-
}
|
|
1893
|
-
}
|
|
1894
|
-
}
|
|
1895
|
-
options.afterInstall?.(cacheDir, packageName);
|
|
1896
|
-
return cacheDir;
|
|
1897
|
-
} finally {
|
|
1898
|
-
if (fs.existsSync(packDest)) {
|
|
1899
|
-
fs.rmSync(packDest, { recursive: true, force: true });
|
|
1900
|
-
}
|
|
1901
|
-
}
|
|
1902
|
-
}
|
|
1903
|
-
function getPackageEntryPath(packageRoot) {
|
|
1904
|
-
const pkgPath = path.join(packageRoot, "package.json");
|
|
1905
|
-
if (!fs.existsSync(pkgPath)) {
|
|
1906
|
-
throw new Error(`No package.json in ${packageRoot}`);
|
|
1907
|
-
}
|
|
1908
|
-
const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf-8"));
|
|
1909
|
-
const main = pkg.main ?? "dist/index.js";
|
|
1910
|
-
const entry = path.join(packageRoot, main);
|
|
1911
|
-
if (!fs.existsSync(entry)) {
|
|
1912
|
-
throw new Error(`Entry not found: ${entry}`);
|
|
1913
|
-
}
|
|
1914
|
-
return entry;
|
|
1915
|
-
}
|
|
1916
|
-
async function importFromCache(packageRoot) {
|
|
1917
|
-
const entryPath = getPackageEntryPath(packageRoot);
|
|
1918
|
-
const fileUrl = url.pathToFileURL(entryPath).href;
|
|
1919
|
-
return import(
|
|
1920
|
-
/* @vite-ignore */
|
|
1921
|
-
fileUrl
|
|
1922
|
-
);
|
|
1923
|
-
}
|
|
1924
|
-
var requireFromPackage = module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('chunk-J5VQMYUV.cjs', document.baseURI).href)));
|
|
1780
|
+
var requireFromPackage = module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('chunk-PAXUM4QS.cjs', document.baseURI).href)));
|
|
1925
1781
|
function getProjectRequire() {
|
|
1926
1782
|
const cwd = process.cwd();
|
|
1927
1783
|
if (fs.existsSync(path.join(cwd, "package.json"))) return module$1.createRequire(path.join(cwd, "package.json"));
|
|
@@ -2018,7 +1874,7 @@ function loadExtensionFromFileDescriptorSync(descriptor, configFilePath, stepLog
|
|
|
2018
1874
|
const resolvedPath = path.resolve(configDir, pathPart);
|
|
2019
1875
|
if (!fs.existsSync(resolvedPath) || !fs.statSync(resolvedPath).isDirectory()) return null;
|
|
2020
1876
|
try {
|
|
2021
|
-
const entryPath = getPackageEntryPath(resolvedPath);
|
|
1877
|
+
const entryPath = agentCommon.getPackageEntryPath(resolvedPath);
|
|
2022
1878
|
const req = module$1.createRequire(path.join(resolvedPath, "package.json"));
|
|
2023
1879
|
const mod = req(entryPath);
|
|
2024
1880
|
const fn = getRegisterFn(mod);
|
|
@@ -2046,7 +1902,7 @@ function loadExtensionForDescriptorSync(descriptor, configFilePath, stepLog) {
|
|
|
2046
1902
|
if (typeof fn === "function") {
|
|
2047
1903
|
const installed = getInstalledPackageVersionFromRequire(parsed.packageName, configRequire);
|
|
2048
1904
|
const requested = parsed.version === "latest" || !parsed.version?.trim() ? null : parsed.version;
|
|
2049
|
-
const resolvedVersion = requested === null ? resolveLatestVersionFromRegistry(parsed.packageName) : requested;
|
|
1905
|
+
const resolvedVersion = requested === null ? agentCommon.resolveLatestVersionFromRegistry(parsed.packageName) : requested;
|
|
2050
1906
|
if (installed === resolvedVersion) {
|
|
2051
1907
|
if (stepLog) stepLog(`Loaded ${parsed.packageName}@${resolvedVersion} from node_modules`);
|
|
2052
1908
|
return { register: fn, descriptor: entryStr, resolvedVersion };
|
|
@@ -2059,9 +1915,9 @@ function loadExtensionForDescriptorSync(descriptor, configFilePath, stepLog) {
|
|
|
2059
1915
|
const cacheOpts = cacheBase ? { cacheBase } : {};
|
|
2060
1916
|
for (const opts of [cacheOpts, {}]) {
|
|
2061
1917
|
try {
|
|
2062
|
-
const cacheDir = ensurePackageInCache(parsed.packageName, parsed.version, opts);
|
|
1918
|
+
const cacheDir = agentCommon.ensurePackageInCache(parsed.packageName, parsed.version, opts);
|
|
2063
1919
|
if (stepLog) stepLog(`Loaded ${parsed.packageName} from cache: ${cacheDir}`);
|
|
2064
|
-
const entryPath = getPackageEntryPath(cacheDir);
|
|
1920
|
+
const entryPath = agentCommon.getPackageEntryPath(cacheDir);
|
|
2065
1921
|
const req = module$1.createRequire(path.join(cacheDir, "package.json"));
|
|
2066
1922
|
const mod = req(entryPath);
|
|
2067
1923
|
const fn = getRegisterFn(mod);
|
|
@@ -2118,9 +1974,9 @@ async function loadExtensionForDescriptorAsync(descriptor, configFilePath, stepL
|
|
|
2118
1974
|
const cacheOpts = cacheBase ? { cacheBase } : {};
|
|
2119
1975
|
for (const opts of [cacheOpts, {}]) {
|
|
2120
1976
|
try {
|
|
2121
|
-
const cacheDir = ensurePackageInCache(parsed.packageName, parsed.version, opts);
|
|
1977
|
+
const cacheDir = agentCommon.ensurePackageInCache(parsed.packageName, parsed.version, opts);
|
|
2122
1978
|
if (stepLog) stepLog(`Loaded ${parsed.packageName} from cache (async): ${cacheDir}`);
|
|
2123
|
-
const mod = await importFromCache(cacheDir);
|
|
1979
|
+
const mod = await agentCommon.importFromCache(cacheDir);
|
|
2124
1980
|
const fn = getRegisterFn(mod);
|
|
2125
1981
|
if (typeof fn === "function") {
|
|
2126
1982
|
const resolvedVersion = path.basename(cacheDir);
|
|
@@ -2178,7 +2034,7 @@ function createRuntimeFromConfigSync(options = {}) {
|
|
|
2178
2034
|
if (extensionNode) {
|
|
2179
2035
|
if (stepLog) stepLog("Registered extension from node_modules");
|
|
2180
2036
|
const descriptor = `npm:${extensionNode.packageName}`;
|
|
2181
|
-
const resolvedVersion = getInstalledPackageVersion(extensionNode.packageName) ?? resolveLatestVersionFromRegistry(extensionNode.packageName);
|
|
2037
|
+
const resolvedVersion = getInstalledPackageVersion(extensionNode.packageName) ?? agentCommon.resolveLatestVersionFromRegistry(extensionNode.packageName);
|
|
2182
2038
|
const prefix = npmDescriptorToRegistryPrefix(descriptor, resolvedVersion);
|
|
2183
2039
|
const reg = prefix ? createPrefixingRegistry(registry, prefix) : registry;
|
|
2184
2040
|
const coreAdapter = extensionNode.register(reg, options.coreTools);
|
|
@@ -2219,6 +2075,22 @@ var MCP_KIND = "mcp";
|
|
|
2219
2075
|
var LANGCHAIN_KIND = "langchain";
|
|
2220
2076
|
var LANGCHAIN_DIR_NAME = "langchain";
|
|
2221
2077
|
|
|
2078
|
+
Object.defineProperty(exports, "ensurePackageInCache", {
|
|
2079
|
+
enumerable: true,
|
|
2080
|
+
get: function () { return agentCommon.ensurePackageInCache; }
|
|
2081
|
+
});
|
|
2082
|
+
Object.defineProperty(exports, "getPackageEntryPath", {
|
|
2083
|
+
enumerable: true,
|
|
2084
|
+
get: function () { return agentCommon.getPackageEntryPath; }
|
|
2085
|
+
});
|
|
2086
|
+
Object.defineProperty(exports, "importFromCache", {
|
|
2087
|
+
enumerable: true,
|
|
2088
|
+
get: function () { return agentCommon.importFromCache; }
|
|
2089
|
+
});
|
|
2090
|
+
Object.defineProperty(exports, "resolveLatestVersionFromRegistry", {
|
|
2091
|
+
enumerable: true,
|
|
2092
|
+
get: function () { return agentCommon.resolveLatestVersionFromRegistry; }
|
|
2093
|
+
});
|
|
2222
2094
|
exports.BudgetManager = BudgetManager;
|
|
2223
2095
|
exports.EventLog = EventLog;
|
|
2224
2096
|
exports.LANGCHAIN_DIR_NAME = LANGCHAIN_DIR_NAME;
|
|
@@ -2235,13 +2107,10 @@ exports.buildEvidence = buildEvidence;
|
|
|
2235
2107
|
exports.createLogger = createLogger;
|
|
2236
2108
|
exports.createRuntimeFromConfig = createRuntimeFromConfig;
|
|
2237
2109
|
exports.createRuntimeFromConfigSync = createRuntimeFromConfigSync;
|
|
2238
|
-
exports.ensurePackageInCache = ensurePackageInCache;
|
|
2239
2110
|
exports.expandToolDescriptorsToRegistryNames = expandToolDescriptorsToRegistryNames;
|
|
2240
2111
|
exports.fileDescriptorToPackagePrefix = fileDescriptorToPackagePrefix;
|
|
2241
2112
|
exports.findAndLoadToolConfig = findAndLoadToolConfig;
|
|
2242
2113
|
exports.getDisplayScope = getDisplayScope;
|
|
2243
|
-
exports.getPackageEntryPath = getPackageEntryPath;
|
|
2244
|
-
exports.importFromCache = importFromCache;
|
|
2245
2114
|
exports.isBarePackageDescriptor = isBarePackageDescriptor;
|
|
2246
2115
|
exports.isNpmToolDescriptor = isNpmToolDescriptor;
|
|
2247
2116
|
exports.loadToolConfig = loadToolConfig;
|
|
@@ -2249,7 +2118,6 @@ exports.normalizeToolList = normalizeToolList;
|
|
|
2249
2118
|
exports.npmDescriptorToPackagePrefixWithVersion = npmDescriptorToPackagePrefixWithVersion;
|
|
2250
2119
|
exports.npmDescriptorToRegistryPrefix = npmDescriptorToRegistryPrefix;
|
|
2251
2120
|
exports.parseNpmToolDescriptor = parseNpmToolDescriptor;
|
|
2252
|
-
exports.resolveLatestVersionFromRegistry = resolveLatestVersionFromRegistry;
|
|
2253
2121
|
exports.resolveNpmToolDescriptor = resolveNpmToolDescriptor;
|
|
2254
2122
|
exports.resolveSandboxedPath = resolveSandboxedPath;
|
|
2255
2123
|
exports.resolveSandboxedPath2 = resolveSandboxedPath2;
|
|
@@ -2257,5 +2125,5 @@ exports.resolveToolDescriptor = resolveToolDescriptor;
|
|
|
2257
2125
|
exports.sanitizeForLog = sanitizeForLog;
|
|
2258
2126
|
exports.setSandboxValidationEnabled = setSandboxValidationEnabled;
|
|
2259
2127
|
exports.summarizeForLog = summarizeForLog;
|
|
2260
|
-
//# sourceMappingURL=chunk-
|
|
2261
|
-
//# sourceMappingURL=chunk-
|
|
2128
|
+
//# sourceMappingURL=chunk-PAXUM4QS.cjs.map
|
|
2129
|
+
//# sourceMappingURL=chunk-PAXUM4QS.cjs.map
|