@easynet/agent-tool 1.0.39 → 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-TRJL2ZIH.js → chunk-4MAR5XDN.js} +3 -3
- package/dist/{chunk-TRJL2ZIH.js.map → chunk-4MAR5XDN.js.map} +1 -1
- package/dist/{chunk-HUUG5MZ7.cjs → chunk-CTB3RP4C.cjs} +15 -15
- package/dist/{chunk-HUUG5MZ7.cjs.map → chunk-CTB3RP4C.cjs.map} +1 -1
- package/dist/{chunk-5BYLYZ22.cjs → chunk-GVYVTQUB.cjs} +7 -7
- package/dist/{chunk-5BYLYZ22.cjs.map → chunk-GVYVTQUB.cjs.map} +1 -1
- package/dist/{chunk-23KQ6MPJ.cjs → chunk-LO5Y3D4O.cjs} +18 -9
- package/dist/chunk-LO5Y3D4O.cjs.map +1 -0
- package/dist/{chunk-JRT4FEQB.js → chunk-NE3PKHM7.js} +12 -3
- package/dist/chunk-NE3PKHM7.js.map +1 -0
- package/dist/{chunk-JGQVKMRY.cjs → chunk-PAXUM4QS.cjs} +28 -160
- package/dist/chunk-PAXUM4QS.cjs.map +1 -0
- package/dist/{chunk-YZLDVSS4.js → chunk-TXZITBLR.js} +9 -152
- package/dist/chunk-TXZITBLR.js.map +1 -0
- package/dist/{chunk-OAZPWIHV.js → chunk-UFV5ZRAX.js} +3 -3
- package/dist/{chunk-OAZPWIHV.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-23KQ6MPJ.cjs.map +0 -1
- package/dist/chunk-JGQVKMRY.cjs.map +0 -1
- package/dist/chunk-JRT4FEQB.js.map +0 -1
- package/dist/chunk-YZLDVSS4.js.map +0 -1
|
@@ -6,13 +6,13 @@ import { bulkhead, circuitBreaker, handleAll, ConsecutiveBreaker } from 'cockati
|
|
|
6
6
|
import { EventEmitter } from 'eventemitter3';
|
|
7
7
|
import { v4 } from 'uuid';
|
|
8
8
|
import pTimeout from 'p-timeout';
|
|
9
|
-
import {
|
|
9
|
+
import { resolve, normalize, dirname, basename, join, isAbsolute } from 'path';
|
|
10
10
|
import { realpath, access } from 'fs/promises';
|
|
11
|
-
import { readFileSync, existsSync,
|
|
11
|
+
import { readFileSync, existsSync, statSync } from 'fs';
|
|
12
12
|
import { homedir } from 'os';
|
|
13
13
|
import yaml from 'js-yaml';
|
|
14
|
-
import {
|
|
15
|
-
|
|
14
|
+
import { resolveLatestVersionFromRegistry, ensurePackageInCache, getPackageEntryPath, importFromCache } from '@easynet/agent-common';
|
|
15
|
+
export { ensurePackageInCache, getPackageEntryPath, importFromCache, resolveLatestVersionFromRegistry } from '@easynet/agent-common';
|
|
16
16
|
import { createRequire } from 'module';
|
|
17
17
|
|
|
18
18
|
var SchemaValidator = class {
|
|
@@ -1768,149 +1768,6 @@ function findAndLoadToolConfig(dir) {
|
|
|
1768
1768
|
}
|
|
1769
1769
|
return {};
|
|
1770
1770
|
}
|
|
1771
|
-
var DEFAULT_CACHE_BASE = join(homedir(), ".agent", "cache");
|
|
1772
|
-
function isLatestRequest(version) {
|
|
1773
|
-
const v = (version ?? "").trim().toLowerCase();
|
|
1774
|
-
return v === "" || v === "latest";
|
|
1775
|
-
}
|
|
1776
|
-
function resolveLatestVersionFromRegistry(packageName) {
|
|
1777
|
-
const quoted = packageName.includes(" ") ? `"${packageName}"` : packageName;
|
|
1778
|
-
try {
|
|
1779
|
-
const out = execSync(`npm view ${quoted} version`, {
|
|
1780
|
-
encoding: "utf-8",
|
|
1781
|
-
stdio: ["pipe", "pipe", "pipe"]
|
|
1782
|
-
});
|
|
1783
|
-
const version = (out ?? "").trim();
|
|
1784
|
-
if (!version) {
|
|
1785
|
-
throw new Error(`npm view ${packageName} version returned empty`);
|
|
1786
|
-
}
|
|
1787
|
-
return version;
|
|
1788
|
-
} catch (err) {
|
|
1789
|
-
const msg = err instanceof Error ? err.message : String(err);
|
|
1790
|
-
throw new Error(`Failed to resolve latest version for ${packageName}: ${msg}`);
|
|
1791
|
-
}
|
|
1792
|
-
}
|
|
1793
|
-
function getCachedPackageVersion(cacheDir) {
|
|
1794
|
-
const pkgPath = join(cacheDir, "package.json");
|
|
1795
|
-
if (!existsSync(pkgPath)) return void 0;
|
|
1796
|
-
try {
|
|
1797
|
-
const pkg = JSON.parse(readFileSync(pkgPath, "utf-8"));
|
|
1798
|
-
return typeof pkg.version === "string" ? pkg.version : void 0;
|
|
1799
|
-
} catch {
|
|
1800
|
-
return void 0;
|
|
1801
|
-
}
|
|
1802
|
-
}
|
|
1803
|
-
function packagePathSegments(name) {
|
|
1804
|
-
const withoutScope = name.replace(/^@/, "");
|
|
1805
|
-
return withoutScope.split("/").filter(Boolean);
|
|
1806
|
-
}
|
|
1807
|
-
function resolveCacheDir(cacheBase, packageName, version) {
|
|
1808
|
-
const segments = packagePathSegments(packageName);
|
|
1809
|
-
return join(cacheBase, ...segments, version);
|
|
1810
|
-
}
|
|
1811
|
-
function ensurePackageInCache(packageName, version = "latest", options = {}) {
|
|
1812
|
-
const cacheBase = options.cacheBase ?? DEFAULT_CACHE_BASE;
|
|
1813
|
-
let resolvedVersion;
|
|
1814
|
-
if (isLatestRequest(version)) {
|
|
1815
|
-
resolvedVersion = resolveLatestVersionFromRegistry(packageName);
|
|
1816
|
-
} else {
|
|
1817
|
-
resolvedVersion = version;
|
|
1818
|
-
}
|
|
1819
|
-
const cacheDir = resolveCacheDir(cacheBase, packageName, resolvedVersion);
|
|
1820
|
-
const packageJsonPath = join(cacheDir, "package.json");
|
|
1821
|
-
const nodeModulesPath = join(cacheDir, "node_modules");
|
|
1822
|
-
if (existsSync(packageJsonPath) && existsSync(nodeModulesPath)) {
|
|
1823
|
-
const cachedVersion = getCachedPackageVersion(cacheDir);
|
|
1824
|
-
if (cachedVersion === resolvedVersion) {
|
|
1825
|
-
options.afterInstall?.(cacheDir, packageName);
|
|
1826
|
-
return cacheDir;
|
|
1827
|
-
}
|
|
1828
|
-
rmSync(cacheDir, { recursive: true, force: true });
|
|
1829
|
-
}
|
|
1830
|
-
const packDest = join(cacheBase, ".pack-tmp", packageName.replace(/@/g, "").replace(/\//g, "_"));
|
|
1831
|
-
mkdirSync(packDest, { recursive: true });
|
|
1832
|
-
try {
|
|
1833
|
-
execSync(`npm pack ${packageName}@${resolvedVersion} --pack-destination "${packDest}"`, {
|
|
1834
|
-
cwd: process.cwd(),
|
|
1835
|
-
stdio: "pipe",
|
|
1836
|
-
encoding: "utf-8"
|
|
1837
|
-
});
|
|
1838
|
-
const files = readdirSync(packDest);
|
|
1839
|
-
const tgz = files.find((f) => f.endsWith(".tgz"));
|
|
1840
|
-
if (!tgz) {
|
|
1841
|
-
throw new Error(`npm pack did not produce a .tgz in ${packDest}`);
|
|
1842
|
-
}
|
|
1843
|
-
const extractDir = join(packDest, "extract");
|
|
1844
|
-
mkdirSync(extractDir, { recursive: true });
|
|
1845
|
-
execSync(`tar -xzf "${join(packDest, tgz)}" -C "${extractDir}"`, {
|
|
1846
|
-
stdio: "pipe",
|
|
1847
|
-
encoding: "utf-8"
|
|
1848
|
-
});
|
|
1849
|
-
const extractedPackage = join(extractDir, "package");
|
|
1850
|
-
if (!existsSync(extractedPackage)) {
|
|
1851
|
-
throw new Error(`Extracted tarball did not contain "package" dir in ${extractDir}`);
|
|
1852
|
-
}
|
|
1853
|
-
mkdirSync(join(cacheDir, ".."), { recursive: true });
|
|
1854
|
-
if (existsSync(cacheDir)) {
|
|
1855
|
-
rmSync(cacheDir, { recursive: true, force: true });
|
|
1856
|
-
}
|
|
1857
|
-
renameSync(extractedPackage, cacheDir);
|
|
1858
|
-
const npmInstallTimeout = 12e4;
|
|
1859
|
-
const maxAttempts = 3;
|
|
1860
|
-
let lastErr;
|
|
1861
|
-
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
|
|
1862
|
-
try {
|
|
1863
|
-
execSync("npm install --prefer-offline --no-audit --no-fund", {
|
|
1864
|
-
cwd: cacheDir,
|
|
1865
|
-
stdio: "pipe",
|
|
1866
|
-
encoding: "utf-8",
|
|
1867
|
-
timeout: npmInstallTimeout
|
|
1868
|
-
});
|
|
1869
|
-
lastErr = void 0;
|
|
1870
|
-
break;
|
|
1871
|
-
} catch (err) {
|
|
1872
|
-
lastErr = err instanceof Error ? err : new Error(String(err));
|
|
1873
|
-
if (attempt < maxAttempts) {
|
|
1874
|
-
const delayMs = 5e3 * attempt;
|
|
1875
|
-
const deadline = Date.now() + delayMs;
|
|
1876
|
-
while (Date.now() < deadline) {
|
|
1877
|
-
}
|
|
1878
|
-
} else {
|
|
1879
|
-
throw new Error(
|
|
1880
|
-
`npm install in cache failed after ${maxAttempts} attempts: ${lastErr.message}`
|
|
1881
|
-
);
|
|
1882
|
-
}
|
|
1883
|
-
}
|
|
1884
|
-
}
|
|
1885
|
-
options.afterInstall?.(cacheDir, packageName);
|
|
1886
|
-
return cacheDir;
|
|
1887
|
-
} finally {
|
|
1888
|
-
if (existsSync(packDest)) {
|
|
1889
|
-
rmSync(packDest, { recursive: true, force: true });
|
|
1890
|
-
}
|
|
1891
|
-
}
|
|
1892
|
-
}
|
|
1893
|
-
function getPackageEntryPath(packageRoot) {
|
|
1894
|
-
const pkgPath = join(packageRoot, "package.json");
|
|
1895
|
-
if (!existsSync(pkgPath)) {
|
|
1896
|
-
throw new Error(`No package.json in ${packageRoot}`);
|
|
1897
|
-
}
|
|
1898
|
-
const pkg = JSON.parse(readFileSync(pkgPath, "utf-8"));
|
|
1899
|
-
const main = pkg.main ?? "dist/index.js";
|
|
1900
|
-
const entry = join(packageRoot, main);
|
|
1901
|
-
if (!existsSync(entry)) {
|
|
1902
|
-
throw new Error(`Entry not found: ${entry}`);
|
|
1903
|
-
}
|
|
1904
|
-
return entry;
|
|
1905
|
-
}
|
|
1906
|
-
async function importFromCache(packageRoot) {
|
|
1907
|
-
const entryPath = getPackageEntryPath(packageRoot);
|
|
1908
|
-
const fileUrl = pathToFileURL(entryPath).href;
|
|
1909
|
-
return import(
|
|
1910
|
-
/* @vite-ignore */
|
|
1911
|
-
fileUrl
|
|
1912
|
-
);
|
|
1913
|
-
}
|
|
1914
1771
|
var requireFromPackage = createRequire(import.meta.url);
|
|
1915
1772
|
function getProjectRequire() {
|
|
1916
1773
|
const cwd = process.cwd();
|
|
@@ -2036,8 +1893,8 @@ function loadExtensionForDescriptorSync(descriptor, configFilePath, stepLog) {
|
|
|
2036
1893
|
if (typeof fn === "function") {
|
|
2037
1894
|
const installed = getInstalledPackageVersionFromRequire(parsed.packageName, configRequire);
|
|
2038
1895
|
const requested = parsed.version === "latest" || !parsed.version?.trim() ? null : parsed.version;
|
|
2039
|
-
const resolvedVersion =
|
|
2040
|
-
if (
|
|
1896
|
+
const resolvedVersion = requested === null ? resolveLatestVersionFromRegistry(parsed.packageName) : requested;
|
|
1897
|
+
if (installed === resolvedVersion) {
|
|
2041
1898
|
if (stepLog) stepLog(`Loaded ${parsed.packageName}@${resolvedVersion} from node_modules`);
|
|
2042
1899
|
return { register: fn, descriptor: entryStr, resolvedVersion };
|
|
2043
1900
|
}
|
|
@@ -2209,6 +2066,6 @@ var MCP_KIND = "mcp";
|
|
|
2209
2066
|
var LANGCHAIN_KIND = "langchain";
|
|
2210
2067
|
var LANGCHAIN_DIR_NAME = "langchain";
|
|
2211
2068
|
|
|
2212
|
-
export { BudgetManager, EventLog, LANGCHAIN_DIR_NAME, LANGCHAIN_KIND, MCP_KIND, Metrics, PTCRuntime, PolicyDeniedError, PolicyEngine, SchemaValidationError, SchemaValidator, Tracing, buildEvidence, createLogger, createRuntimeFromConfig, createRuntimeFromConfigSync,
|
|
2213
|
-
//# sourceMappingURL=chunk-
|
|
2214
|
-
//# sourceMappingURL=chunk-
|
|
2069
|
+
export { BudgetManager, EventLog, LANGCHAIN_DIR_NAME, LANGCHAIN_KIND, MCP_KIND, Metrics, PTCRuntime, PolicyDeniedError, PolicyEngine, SchemaValidationError, SchemaValidator, Tracing, buildEvidence, createLogger, createRuntimeFromConfig, createRuntimeFromConfigSync, expandToolDescriptorsToRegistryNames, fileDescriptorToPackagePrefix, findAndLoadToolConfig, getDisplayScope, isBarePackageDescriptor, isNpmToolDescriptor, loadToolConfig, normalizeToolList, npmDescriptorToPackagePrefixWithVersion, npmDescriptorToRegistryPrefix, parseNpmToolDescriptor, resolveNpmToolDescriptor, resolveSandboxedPath, resolveSandboxedPath2, resolveToolDescriptor, sanitizeForLog, setSandboxValidationEnabled, summarizeForLog };
|
|
2070
|
+
//# sourceMappingURL=chunk-TXZITBLR.js.map
|
|
2071
|
+
//# sourceMappingURL=chunk-TXZITBLR.js.map
|