@easynet/agent-tool 1.0.90 → 1.0.92
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/agent-context.d.ts +3 -0
- package/dist/agent-context.d.ts.map +1 -0
- package/dist/api/extension/overrideWithConfig.d.ts +1 -1
- package/dist/api/extension/overrideWithConfig.d.ts.map +1 -1
- package/dist/api/register-tools.d.ts.map +1 -1
- package/dist/{chunk-AK3C5LLW.cjs → chunk-BMU5SD2G.cjs} +190 -32
- package/dist/chunk-BMU5SD2G.cjs.map +1 -0
- package/dist/{chunk-GAC3N3KH.js → chunk-Z6FD2GKB.js} +179 -21
- package/dist/chunk-Z6FD2GKB.js.map +1 -0
- package/dist/index.cjs +24 -12
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +14 -2
- package/dist/index.js.map +1 -1
- package/dist/observability/Logger.d.ts +1 -1
- package/dist/observability/Logger.d.ts.map +1 -1
- package/dist/sdk.cjs +13 -5
- package/dist/sdk.cjs.map +1 -1
- package/dist/sdk.js +13 -2
- package/dist/sdk.js.map +1 -1
- package/dist/utils/cli/index.cjs +12 -12
- package/dist/utils/cli/index.js +1 -1
- package/dist/utils/log.d.ts +2 -0
- package/dist/utils/log.d.ts.map +1 -0
- package/dist/utils/npmCache.d.ts +10 -1
- package/dist/utils/npmCache.d.ts.map +1 -1
- package/dist/utils/npmVersion.d.ts +10 -0
- package/dist/utils/npmVersion.d.ts.map +1 -0
- package/dist/utils/overrideWithConfig.d.ts +2 -0
- package/dist/utils/overrideWithConfig.d.ts.map +1 -0
- package/package.json +1 -1
- package/dist/chunk-AK3C5LLW.cjs.map +0 -1
- package/dist/chunk-GAC3N3KH.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-context.d.ts","sourceRoot":"","sources":["../src/agent-context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsB,KAAK,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAc9E,wBAAgB,sBAAsB,IAAI,YAAY,CAQrD"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { overrideWithConfig } from "
|
|
1
|
+
export { overrideWithConfig } from "../../utils/overrideWithConfig.js";
|
|
2
2
|
//# sourceMappingURL=overrideWithConfig.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"overrideWithConfig.d.ts","sourceRoot":"","sources":["../../../src/api/extension/overrideWithConfig.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"overrideWithConfig.d.ts","sourceRoot":"","sources":["../../../src/api/extension/overrideWithConfig.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,mCAAmC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"register-tools.d.ts","sourceRoot":"","sources":["../../src/api/register-tools.ts"],"names":[],"mappings":"AACA,OAAO,EAA6B,KAAK,uBAAuB,EAAE,MAAM,uBAAuB,CAAC;AAChG,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"register-tools.d.ts","sourceRoot":"","sources":["../../src/api/register-tools.ts"],"names":[],"mappings":"AACA,OAAO,EAA6B,KAAK,uBAAuB,EAAE,MAAM,uBAAuB,CAAC;AAChG,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAC;AAGrE,MAAM,WAAW,6BAA8B,SAAQ,uBAAuB;CAAG;AAEjF;;;;;;;;;;GAUG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,CAAC,EAAE,6BAA6B,GAAG,uBAAuB,EAAE,CAInG"}
|
|
@@ -15,7 +15,8 @@ var cockatiel = require('cockatiel');
|
|
|
15
15
|
var eventemitter3 = require('eventemitter3');
|
|
16
16
|
var uuid = require('uuid');
|
|
17
17
|
var pTimeout = require('p-timeout');
|
|
18
|
-
var
|
|
18
|
+
var child_process = require('child_process');
|
|
19
|
+
var os = require('os');
|
|
19
20
|
var express = require('express');
|
|
20
21
|
|
|
21
22
|
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
@@ -229,13 +230,13 @@ function expandToolDescriptorsToRegistryNames(descriptors, registryNames) {
|
|
|
229
230
|
out.push(s);
|
|
230
231
|
continue;
|
|
231
232
|
}
|
|
232
|
-
const
|
|
233
|
-
if (
|
|
234
|
-
const packagePrefix =
|
|
233
|
+
const path2 = parseToolPath(s);
|
|
234
|
+
if (path2) {
|
|
235
|
+
const packagePrefix = path2.protocol === "npm" ? npmDescriptorToPackagePrefix(s) : path2.protocol === "file" ? fileDescriptorToPackagePrefix(s) : "";
|
|
235
236
|
const prefixWithDot = packagePrefix ? packagePrefix + "." : "";
|
|
236
237
|
if (prefixWithDot) {
|
|
237
|
-
if (
|
|
238
|
-
const suffix = "." +
|
|
238
|
+
if (path2.toolName) {
|
|
239
|
+
const suffix = "." + path2.toolName;
|
|
239
240
|
for (const r of registryNames) {
|
|
240
241
|
if (r.startsWith(prefixWithDot) && r.endsWith(suffix) && !seen.has(r)) {
|
|
241
242
|
seen.add(r);
|
|
@@ -264,9 +265,9 @@ function resolveToolDescriptor(descriptor) {
|
|
|
264
265
|
return s;
|
|
265
266
|
}
|
|
266
267
|
function fileDescriptorToPackagePrefix(descriptor) {
|
|
267
|
-
const
|
|
268
|
-
if (!
|
|
269
|
-
const pathPart = `${
|
|
268
|
+
const path2 = parseToolPath(descriptor.trim());
|
|
269
|
+
if (!path2 || path2.protocol !== "file") return "";
|
|
270
|
+
const pathPart = `${path2.scope}/${path2.packageWithVersion}`;
|
|
270
271
|
const normalized = chunkJW4EMVTE_cjs.normalizeToolName(pathPart);
|
|
271
272
|
if (!normalized) return "";
|
|
272
273
|
return chunkJW4EMVTE_cjs.normalizeToolName("file." + normalized);
|
|
@@ -864,6 +865,22 @@ var EventLog = class {
|
|
|
864
865
|
this.seq = 0;
|
|
865
866
|
}
|
|
866
867
|
};
|
|
868
|
+
|
|
869
|
+
// src/utils/log.ts
|
|
870
|
+
function summarizeForLog(value, maxLen = 220) {
|
|
871
|
+
const raw = typeof value === "string" ? value : value == null ? "" : (() => {
|
|
872
|
+
try {
|
|
873
|
+
return JSON.stringify(value);
|
|
874
|
+
} catch {
|
|
875
|
+
return String(value);
|
|
876
|
+
}
|
|
877
|
+
})();
|
|
878
|
+
const compact = raw.replace(/\s+/g, " ").trim();
|
|
879
|
+
if (!compact) return "(empty)";
|
|
880
|
+
return compact.length > maxLen ? `${compact.slice(0, maxLen)}...` : compact;
|
|
881
|
+
}
|
|
882
|
+
|
|
883
|
+
// src/observability/Logger.ts
|
|
867
884
|
var LEVEL_ORDER = {
|
|
868
885
|
silent: 0,
|
|
869
886
|
error: 1,
|
|
@@ -1445,7 +1462,7 @@ function handleError(error, intent, ctx, durationMs, spanId, deps) {
|
|
|
1445
1462
|
kind,
|
|
1446
1463
|
message,
|
|
1447
1464
|
durationMs,
|
|
1448
|
-
details: deps.logger.options.includeResults ?
|
|
1465
|
+
details: deps.logger.options.includeResults ? summarizeForLog(details) : void 0
|
|
1449
1466
|
});
|
|
1450
1467
|
return {
|
|
1451
1468
|
ok: false,
|
|
@@ -1672,8 +1689,8 @@ var PTCRuntime = class {
|
|
|
1672
1689
|
this.logger.debug("invoke.ok", {
|
|
1673
1690
|
tool: pipeline.spec.name,
|
|
1674
1691
|
durationMs,
|
|
1675
|
-
result: this.logger.options.includeResults ?
|
|
1676
|
-
raw: this.logger.options.includeRaw ?
|
|
1692
|
+
result: this.logger.options.includeResults ? summarizeForLog(validatedOutput) : void 0,
|
|
1693
|
+
raw: this.logger.options.includeRaw ? summarizeForLog(pipeline.raw) : void 0
|
|
1677
1694
|
});
|
|
1678
1695
|
}
|
|
1679
1696
|
return {
|
|
@@ -1751,7 +1768,148 @@ function buildInputSchemaHint(inputSchema) {
|
|
|
1751
1768
|
if (names.length === 0) return null;
|
|
1752
1769
|
return `This tool expects input property ${names.length === 1 ? `'${names[0]}'` : `one of [${names.map((n) => `'${n}'`).join(", ")}]`}. Use the exact property names from the tool schema.`;
|
|
1753
1770
|
}
|
|
1754
|
-
var
|
|
1771
|
+
var versionCache = /* @__PURE__ */ new Map();
|
|
1772
|
+
var CACHE_TTL = 5 * 60 * 1e3;
|
|
1773
|
+
function resolveNpmPackageVersion(packageName, tag, options = {}) {
|
|
1774
|
+
const cacheKey = packageName;
|
|
1775
|
+
const cached = versionCache.get(cacheKey);
|
|
1776
|
+
if (cached && Date.now() - cached.timestamp < CACHE_TTL) {
|
|
1777
|
+
return cached.version;
|
|
1778
|
+
}
|
|
1779
|
+
try {
|
|
1780
|
+
const spec = tag ? `${packageName}@${tag}` : packageName;
|
|
1781
|
+
const out = child_process.execFileSync("npm", ["view", spec, "version"], {
|
|
1782
|
+
cwd: options.cwd ?? process.cwd(),
|
|
1783
|
+
encoding: "utf-8",
|
|
1784
|
+
timeout: options.timeoutMs ?? 8e3,
|
|
1785
|
+
stdio: ["ignore", "pipe", "pipe"]
|
|
1786
|
+
});
|
|
1787
|
+
const version = out?.trim() ?? null;
|
|
1788
|
+
if (version) {
|
|
1789
|
+
versionCache.set(cacheKey, { version, timestamp: Date.now() });
|
|
1790
|
+
}
|
|
1791
|
+
return version;
|
|
1792
|
+
} catch {
|
|
1793
|
+
return null;
|
|
1794
|
+
}
|
|
1795
|
+
}
|
|
1796
|
+
function resolveLatestVersionFromRegistry(packageName, options = {}) {
|
|
1797
|
+
const version = resolveNpmPackageVersion(packageName, void 0, options);
|
|
1798
|
+
if (!version) {
|
|
1799
|
+
throw new Error(`Failed to resolve latest version for ${packageName}`);
|
|
1800
|
+
}
|
|
1801
|
+
return version;
|
|
1802
|
+
}
|
|
1803
|
+
|
|
1804
|
+
// src/utils/npmCache.ts
|
|
1805
|
+
var DEFAULT_CACHE_BASE = path.join(os.homedir(), ".agent", "cache");
|
|
1806
|
+
function isLatestRequest(version) {
|
|
1807
|
+
const normalized = (version ?? "").trim().toLowerCase();
|
|
1808
|
+
return normalized === "" || normalized === "latest";
|
|
1809
|
+
}
|
|
1810
|
+
function getCachedPackageVersion(cacheDir) {
|
|
1811
|
+
const pkgPath = path.join(cacheDir, "package.json");
|
|
1812
|
+
if (!fs.existsSync(pkgPath)) return void 0;
|
|
1813
|
+
try {
|
|
1814
|
+
const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf-8"));
|
|
1815
|
+
return typeof pkg.version === "string" ? pkg.version : void 0;
|
|
1816
|
+
} catch {
|
|
1817
|
+
return void 0;
|
|
1818
|
+
}
|
|
1819
|
+
}
|
|
1820
|
+
function packagePathSegments(name) {
|
|
1821
|
+
const withoutScope = name.replace(/^@/, "");
|
|
1822
|
+
return withoutScope.split("/").filter(Boolean);
|
|
1823
|
+
}
|
|
1824
|
+
function resolveCacheDir(cacheBase, packageName, version) {
|
|
1825
|
+
const segments = packagePathSegments(packageName);
|
|
1826
|
+
return path.join(cacheBase, ...segments, version);
|
|
1827
|
+
}
|
|
1828
|
+
function ensurePackageInCache(packageName, version = "latest", options = {}) {
|
|
1829
|
+
const cacheBase = options.cacheBase ?? DEFAULT_CACHE_BASE;
|
|
1830
|
+
const cwd = options.cwd ?? process.cwd();
|
|
1831
|
+
const resolvedVersion = isLatestRequest(version) ? resolveLatestVersionFromRegistry(packageName, { cwd }) : version;
|
|
1832
|
+
const cacheDir = resolveCacheDir(cacheBase, packageName, resolvedVersion);
|
|
1833
|
+
const packageJsonPath = path.join(cacheDir, "package.json");
|
|
1834
|
+
const nodeModulesPath = path.join(cacheDir, "node_modules");
|
|
1835
|
+
if (fs.existsSync(packageJsonPath) && fs.existsSync(nodeModulesPath)) {
|
|
1836
|
+
const cachedVersion = getCachedPackageVersion(cacheDir);
|
|
1837
|
+
if (cachedVersion === resolvedVersion) {
|
|
1838
|
+
options.afterInstall?.(cacheDir, packageName);
|
|
1839
|
+
return cacheDir;
|
|
1840
|
+
}
|
|
1841
|
+
fs.rmSync(cacheDir, { recursive: true, force: true });
|
|
1842
|
+
}
|
|
1843
|
+
const packDest = path.join(cacheBase, ".pack-tmp", packageName.replace(/@/g, "").replace(/\//g, "_"));
|
|
1844
|
+
fs.mkdirSync(packDest, { recursive: true });
|
|
1845
|
+
try {
|
|
1846
|
+
child_process.execSync(`npm pack ${packageName}@${resolvedVersion} --pack-destination "${packDest}"`, {
|
|
1847
|
+
cwd,
|
|
1848
|
+
stdio: "pipe",
|
|
1849
|
+
encoding: "utf-8"
|
|
1850
|
+
});
|
|
1851
|
+
const files = fs.readdirSync(packDest);
|
|
1852
|
+
const tgz = files.find((file) => file.endsWith(".tgz"));
|
|
1853
|
+
if (!tgz) throw new Error(`npm pack did not produce a .tgz in ${packDest}`);
|
|
1854
|
+
const extractDir = path.join(packDest, "extract");
|
|
1855
|
+
fs.mkdirSync(extractDir, { recursive: true });
|
|
1856
|
+
child_process.execSync(`tar -xzf "${path.join(packDest, tgz)}" -C "${extractDir}"`, {
|
|
1857
|
+
stdio: "pipe",
|
|
1858
|
+
encoding: "utf-8"
|
|
1859
|
+
});
|
|
1860
|
+
const extractedPackage = path.join(extractDir, "package");
|
|
1861
|
+
if (!fs.existsSync(extractedPackage)) {
|
|
1862
|
+
throw new Error(`Extracted tarball did not contain "package" dir in ${extractDir}`);
|
|
1863
|
+
}
|
|
1864
|
+
fs.mkdirSync(path.join(cacheDir, ".."), { recursive: true });
|
|
1865
|
+
if (fs.existsSync(cacheDir)) fs.rmSync(cacheDir, { recursive: true, force: true });
|
|
1866
|
+
fs.renameSync(extractedPackage, cacheDir);
|
|
1867
|
+
const npmInstallTimeout = 12e4;
|
|
1868
|
+
const maxAttempts = 3;
|
|
1869
|
+
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
|
|
1870
|
+
try {
|
|
1871
|
+
child_process.execSync("npm install --prefer-offline --no-audit --no-fund", {
|
|
1872
|
+
cwd: cacheDir,
|
|
1873
|
+
stdio: "pipe",
|
|
1874
|
+
encoding: "utf-8",
|
|
1875
|
+
timeout: npmInstallTimeout
|
|
1876
|
+
});
|
|
1877
|
+
break;
|
|
1878
|
+
} catch (error) {
|
|
1879
|
+
if (attempt >= maxAttempts) {
|
|
1880
|
+
const lastError = error instanceof Error ? error : new Error(String(error));
|
|
1881
|
+
throw new Error(`npm install in cache failed after ${maxAttempts} attempts: ${lastError.message}`);
|
|
1882
|
+
}
|
|
1883
|
+
const delayMs = 5e3 * attempt;
|
|
1884
|
+
const deadline = Date.now() + delayMs;
|
|
1885
|
+
while (Date.now() < deadline) {
|
|
1886
|
+
}
|
|
1887
|
+
}
|
|
1888
|
+
}
|
|
1889
|
+
options.afterInstall?.(cacheDir, packageName);
|
|
1890
|
+
return cacheDir;
|
|
1891
|
+
} finally {
|
|
1892
|
+
if (fs.existsSync(packDest)) fs.rmSync(packDest, { recursive: true, force: true });
|
|
1893
|
+
}
|
|
1894
|
+
}
|
|
1895
|
+
function getPackageEntryPath(packageRoot) {
|
|
1896
|
+
const pkgPath = path.join(packageRoot, "package.json");
|
|
1897
|
+
if (!fs.existsSync(pkgPath)) throw new Error(`No package.json in ${packageRoot}`);
|
|
1898
|
+
const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf-8"));
|
|
1899
|
+
const main = pkg.main ?? "dist/index.js";
|
|
1900
|
+
const entryPath = path.join(packageRoot, main);
|
|
1901
|
+
if (!fs.existsSync(entryPath)) throw new Error(`Entry not found: ${entryPath}`);
|
|
1902
|
+
return entryPath;
|
|
1903
|
+
}
|
|
1904
|
+
async function importFromCache(packageRoot) {
|
|
1905
|
+
const entryPath = getPackageEntryPath(packageRoot);
|
|
1906
|
+
const fileUrl = url.pathToFileURL(entryPath).href;
|
|
1907
|
+
return import(
|
|
1908
|
+
/* @vite-ignore */
|
|
1909
|
+
fileUrl
|
|
1910
|
+
);
|
|
1911
|
+
}
|
|
1912
|
+
var requireFromPackage = module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('chunk-BMU5SD2G.cjs', document.baseURI).href)));
|
|
1755
1913
|
function getProjectRequire() {
|
|
1756
1914
|
const cwd = process.cwd();
|
|
1757
1915
|
if (fs.existsSync(path.join(cwd, "package.json"))) return module$1.createRequire(path.join(cwd, "package.json"));
|
|
@@ -1917,7 +2075,7 @@ function parseNpmDescriptor(entry) {
|
|
|
1917
2075
|
}
|
|
1918
2076
|
|
|
1919
2077
|
// src/api/runtimeFromConfig.ts
|
|
1920
|
-
var requireFromPackage2 = module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('chunk-
|
|
2078
|
+
var requireFromPackage2 = module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('chunk-BMU5SD2G.cjs', document.baseURI).href)));
|
|
1921
2079
|
var DEFAULT_EXTENSION_PACKAGES = [];
|
|
1922
2080
|
function resolveFileDescriptorPath(descriptor, configFilePath) {
|
|
1923
2081
|
const parsed = parseToolPath(descriptor.trim());
|
|
@@ -1948,15 +2106,15 @@ function loadExtensionFromNodeModules() {
|
|
|
1948
2106
|
}
|
|
1949
2107
|
function loadExtensionFromFileDescriptorSync(descriptor, configFilePath, stepLog) {
|
|
1950
2108
|
const entryStr = descriptor.trim();
|
|
1951
|
-
const
|
|
1952
|
-
if (!
|
|
2109
|
+
const path2 = parseToolPath(entryStr);
|
|
2110
|
+
if (!path2 || path2.protocol !== "file") return null;
|
|
1953
2111
|
const localPath = path.isAbsolute(configFilePath) ? configFilePath : path.resolve(process.cwd(), configFilePath);
|
|
1954
2112
|
const configDir = path.dirname(localPath);
|
|
1955
|
-
const pathPart = `${
|
|
2113
|
+
const pathPart = `${path2.scope}/${path2.packageWithVersion}`;
|
|
1956
2114
|
const resolvedPath = path.resolve(configDir, pathPart);
|
|
1957
2115
|
if (!fs.existsSync(resolvedPath) || !fs.statSync(resolvedPath).isDirectory()) return null;
|
|
1958
2116
|
try {
|
|
1959
|
-
const entryPath =
|
|
2117
|
+
const entryPath = getPackageEntryPath(resolvedPath);
|
|
1960
2118
|
const req = module$1.createRequire(path.join(resolvedPath, "package.json"));
|
|
1961
2119
|
const mod = req(entryPath);
|
|
1962
2120
|
const fn = getRegisterFn(mod);
|
|
@@ -1984,7 +2142,7 @@ function loadExtensionForDescriptorSync(descriptor, configFilePath, stepLog) {
|
|
|
1984
2142
|
if (typeof fn === "function") {
|
|
1985
2143
|
const installed = getInstalledPackageVersionFromRequire(parsed.packageName, configRequire);
|
|
1986
2144
|
const requested = parsed.version === "latest" || !parsed.version?.trim() ? null : parsed.version;
|
|
1987
|
-
const resolvedVersion = requested ?? installed ??
|
|
2145
|
+
const resolvedVersion = requested ?? installed ?? resolveLatestVersionFromRegistry(parsed.packageName, { cwd: npmCwd });
|
|
1988
2146
|
if (installed === resolvedVersion) {
|
|
1989
2147
|
if (stepLog) stepLog(`Loaded ${parsed.packageName}@${resolvedVersion} from node_modules`);
|
|
1990
2148
|
const pkgRoot = path.dirname(configRequire.resolve(`${parsed.packageName}/package.json`));
|
|
@@ -1998,9 +2156,9 @@ function loadExtensionForDescriptorSync(descriptor, configFilePath, stepLog) {
|
|
|
1998
2156
|
const cacheOptions = cacheBase ? [{ cacheBase, cwd: npmCwd }, { cwd: npmCwd }] : [{ cwd: npmCwd }];
|
|
1999
2157
|
for (const opts of cacheOptions) {
|
|
2000
2158
|
try {
|
|
2001
|
-
const cacheDir =
|
|
2159
|
+
const cacheDir = ensurePackageInCache(parsed.packageName, parsed.version, opts);
|
|
2002
2160
|
if (stepLog) stepLog(`Loaded ${parsed.packageName} from cache: ${cacheDir}`);
|
|
2003
|
-
const entryPath =
|
|
2161
|
+
const entryPath = getPackageEntryPath(cacheDir);
|
|
2004
2162
|
const req = module$1.createRequire(path.join(cacheDir, "package.json"));
|
|
2005
2163
|
const mod = req(entryPath);
|
|
2006
2164
|
const fn = getRegisterFn(mod);
|
|
@@ -2061,11 +2219,11 @@ async function loadExtensionForDescriptorAsync(descriptor, configFilePath, stepL
|
|
|
2061
2219
|
try {
|
|
2062
2220
|
const installed = getInstalledPackageVersionFromRequire(parsed.packageName, configRequire);
|
|
2063
2221
|
const requested = parsed.version === "latest" || !parsed.version?.trim() ? null : parsed.version;
|
|
2064
|
-
const resolvedVersion = requested ?? installed ??
|
|
2222
|
+
const resolvedVersion = requested ?? installed ?? resolveLatestVersionFromRegistry(parsed.packageName, { cwd: npmCwd });
|
|
2065
2223
|
if (installed === resolvedVersion) {
|
|
2066
2224
|
const pkgJsonResolved = configRequire.resolve(`${parsed.packageName}/package.json`);
|
|
2067
2225
|
const packageRoot = path.dirname(pkgJsonResolved);
|
|
2068
|
-
const entryPath =
|
|
2226
|
+
const entryPath = getPackageEntryPath(packageRoot);
|
|
2069
2227
|
const mod = await import(url.pathToFileURL(entryPath).href);
|
|
2070
2228
|
const fn = getRegisterFn(mod);
|
|
2071
2229
|
if (typeof fn === "function") {
|
|
@@ -2080,9 +2238,9 @@ async function loadExtensionForDescriptorAsync(descriptor, configFilePath, stepL
|
|
|
2080
2238
|
const cacheOptions = cacheBase ? [{ cacheBase, cwd: npmCwd }, { cwd: npmCwd }] : [{ cwd: npmCwd }];
|
|
2081
2239
|
for (const opts of cacheOptions) {
|
|
2082
2240
|
try {
|
|
2083
|
-
const cacheDir =
|
|
2241
|
+
const cacheDir = ensurePackageInCache(parsed.packageName, parsed.version, opts);
|
|
2084
2242
|
if (stepLog) stepLog(`Loaded ${parsed.packageName} from cache (async): ${cacheDir}`);
|
|
2085
|
-
const mod = await
|
|
2243
|
+
const mod = await importFromCache(cacheDir);
|
|
2086
2244
|
const fn = getRegisterFn(mod);
|
|
2087
2245
|
if (typeof fn === "function") {
|
|
2088
2246
|
const resolvedVersion = path.basename(cacheDir);
|
|
@@ -2171,7 +2329,7 @@ function createRuntimeFromConfigSync(options = {}) {
|
|
|
2171
2329
|
if (extensionNode) {
|
|
2172
2330
|
if (stepLog) stepLog("Registered extension from node_modules");
|
|
2173
2331
|
const descriptor = `npm:${extensionNode.packageName}`;
|
|
2174
|
-
const resolvedVersion = getInstalledPackageVersion(extensionNode.packageName) ??
|
|
2332
|
+
const resolvedVersion = getInstalledPackageVersion(extensionNode.packageName) ?? resolveLatestVersionFromRegistry(extensionNode.packageName);
|
|
2175
2333
|
const before = new Set(registry.snapshot().map((s) => s.name));
|
|
2176
2334
|
const prefix = npmDescriptorToRegistryPrefix(descriptor, resolvedVersion);
|
|
2177
2335
|
const reg = createPrefixingRegistry(registry, prefix ?? "");
|
|
@@ -2370,16 +2528,16 @@ function createMCPStreamableHttpHandler(runtimeOrConfig, options = {}) {
|
|
|
2370
2528
|
})();
|
|
2371
2529
|
}
|
|
2372
2530
|
async function createMCPServerStreamableHttp(runtimeOrConfig, options = {}) {
|
|
2373
|
-
const
|
|
2531
|
+
const path2 = options.path ?? "/mcp";
|
|
2374
2532
|
const host = options.host ?? "127.0.0.1";
|
|
2375
2533
|
const port = options.port ?? 3e3;
|
|
2376
2534
|
const { createMcpExpressApp } = await import('@modelcontextprotocol/sdk/server/express.js');
|
|
2377
2535
|
const handler = "invoke" in runtimeOrConfig && typeof runtimeOrConfig.invoke === "function" ? createMCPStreamableHttpHandler(runtimeOrConfig, options) : await createMCPStreamableHttpHandler(runtimeOrConfig, options);
|
|
2378
2536
|
const app = createMcpExpressApp({ host });
|
|
2379
|
-
app.post(
|
|
2537
|
+
app.post(path2, handler);
|
|
2380
2538
|
return {
|
|
2381
2539
|
app,
|
|
2382
|
-
path,
|
|
2540
|
+
path: path2,
|
|
2383
2541
|
async listen(listenPort, listenHost) {
|
|
2384
2542
|
const p = listenPort ?? port;
|
|
2385
2543
|
const h = listenHost ?? host;
|
|
@@ -2387,7 +2545,7 @@ async function createMCPServerStreamableHttp(runtimeOrConfig, options = {}) {
|
|
|
2387
2545
|
const server = app.listen(p, h, () => {
|
|
2388
2546
|
const addr = server.address();
|
|
2389
2547
|
const actualPort = typeof addr === "object" && addr !== null && "port" in addr ? addr.port : p;
|
|
2390
|
-
resolve4({ url: `http://${h}:${actualPort}${
|
|
2548
|
+
resolve4({ url: `http://${h}:${actualPort}${path2}`, port: actualPort });
|
|
2391
2549
|
});
|
|
2392
2550
|
});
|
|
2393
2551
|
}
|
|
@@ -2799,5 +2957,5 @@ exports.resolveSandboxedPath = resolveSandboxedPath;
|
|
|
2799
2957
|
exports.resolveToolDescriptor = resolveToolDescriptor;
|
|
2800
2958
|
exports.runMCPServerOverStdio = runMCPServerOverStdio;
|
|
2801
2959
|
exports.toToolObservationText = toToolObservationText;
|
|
2802
|
-
//# sourceMappingURL=chunk-
|
|
2803
|
-
//# sourceMappingURL=chunk-
|
|
2960
|
+
//# sourceMappingURL=chunk-BMU5SD2G.cjs.map
|
|
2961
|
+
//# sourceMappingURL=chunk-BMU5SD2G.cjs.map
|