@easynet/agent-tool 1.0.19 → 1.0.21

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.
Files changed (49) hide show
  1. package/dist/api/createAgentTools.d.ts.map +1 -1
  2. package/dist/api/main.cjs +15 -15
  3. package/dist/api/main.js +4 -4
  4. package/dist/api/runtimeFromConfig.d.ts +15 -11
  5. package/dist/api/runtimeFromConfig.d.ts.map +1 -1
  6. package/dist/canonicalCoreSchemas-JPTOIQKR.js +4 -0
  7. package/dist/{canonicalCoreSchemas-DNBAHSUC.js.map → canonicalCoreSchemas-JPTOIQKR.js.map} +1 -1
  8. package/dist/canonicalCoreSchemas-K57HKGZJ.cjs +21 -0
  9. package/dist/{canonicalCoreSchemas-IBTSIPJV.cjs.map → canonicalCoreSchemas-K57HKGZJ.cjs.map} +1 -1
  10. package/dist/{chunk-EAI37B5W.cjs → chunk-6JWQVVL2.cjs} +4 -3
  11. package/dist/chunk-6JWQVVL2.cjs.map +1 -0
  12. package/dist/{chunk-H2UMNHDE.cjs → chunk-DB7WQWTF.cjs} +10 -10
  13. package/dist/{chunk-H2UMNHDE.cjs.map → chunk-DB7WQWTF.cjs.map} +1 -1
  14. package/dist/{chunk-HISF2FEL.cjs → chunk-DF5ETXKZ.cjs} +16 -22
  15. package/dist/chunk-DF5ETXKZ.cjs.map +1 -0
  16. package/dist/{chunk-QB5ALDM3.js → chunk-DUWEP2CH.js} +3 -3
  17. package/dist/{chunk-QB5ALDM3.js.map → chunk-DUWEP2CH.js.map} +1 -1
  18. package/dist/{chunk-Y33OLGAJ.js → chunk-K6AMVYFV.js} +7 -13
  19. package/dist/chunk-K6AMVYFV.js.map +1 -0
  20. package/dist/{chunk-NNOTTUB2.cjs → chunk-NJNQCEHG.cjs} +151 -47
  21. package/dist/chunk-NJNQCEHG.cjs.map +1 -0
  22. package/dist/{chunk-46XYOB3H.js → chunk-P5UPHQ7N.js} +4 -3
  23. package/dist/chunk-P5UPHQ7N.js.map +1 -0
  24. package/dist/{chunk-GGKQQR54.js → chunk-SAYJJNA7.js} +5 -5
  25. package/dist/{chunk-GGKQQR54.js.map → chunk-SAYJJNA7.js.map} +1 -1
  26. package/dist/{chunk-TPWEGGKQ.cjs → chunk-XDAMV3HZ.cjs} +9 -9
  27. package/dist/{chunk-TPWEGGKQ.cjs.map → chunk-XDAMV3HZ.cjs.map} +1 -1
  28. package/dist/{chunk-TTYAOTOR.js → chunk-XYJRKFWR.js} +151 -46
  29. package/dist/chunk-XYJRKFWR.js.map +1 -0
  30. package/dist/index.cjs +52 -48
  31. package/dist/index.d.ts +1 -1
  32. package/dist/index.d.ts.map +1 -1
  33. package/dist/index.js +6 -6
  34. package/dist/tools/util/canonicalCoreSchemas.d.ts.map +1 -1
  35. package/dist/tools/util/index.d.ts +1 -1
  36. package/dist/tools/util/index.d.ts.map +1 -1
  37. package/dist/tools/util/toolDescriptor.d.ts +9 -0
  38. package/dist/tools/util/toolDescriptor.d.ts.map +1 -1
  39. package/dist/utils/cli/index.cjs +19 -19
  40. package/dist/utils/cli/index.js +4 -4
  41. package/package.json +1 -1
  42. package/dist/canonicalCoreSchemas-DNBAHSUC.js +0 -4
  43. package/dist/canonicalCoreSchemas-IBTSIPJV.cjs +0 -21
  44. package/dist/chunk-46XYOB3H.js.map +0 -1
  45. package/dist/chunk-EAI37B5W.cjs.map +0 -1
  46. package/dist/chunk-HISF2FEL.cjs.map +0 -1
  47. package/dist/chunk-NNOTTUB2.cjs.map +0 -1
  48. package/dist/chunk-TTYAOTOR.js.map +0 -1
  49. package/dist/chunk-Y33OLGAJ.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
- if (registryNames.includes(name) && !seen.has(name)) {
1526
- seen.add(name);
1527
- out.push(name);
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
- const name = isToolPath(s) ? s : normalizeToolName(s);
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;
@@ -1692,20 +1728,36 @@ function getProjectRequire() {
1692
1728
  if (existsSync(join(cwd, "tool.yaml"))) return createRequire(join(cwd, "tool.yaml"));
1693
1729
  return null;
1694
1730
  }
1695
- var BUILTIN_PKG_NAMES = [
1731
+ var DEFAULT_EXTENSION_PACKAGES = [
1696
1732
  "@easynet/agent-tool-builtin-tools",
1697
1733
  "@easynet/agent-tool-builtin",
1698
1734
  "@easynet/agent-tool-buildin"
1699
1735
  ];
1700
- function loadBuiltinTools() {
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
+ }
1752
+ function loadExtensionFromNodeModules() {
1701
1753
  const projectRequire = getProjectRequire();
1702
1754
  const requirers = [requireFromPackage];
1703
1755
  if (projectRequire) requirers.push(projectRequire);
1704
1756
  for (const req of requirers) {
1705
- for (const pkg of BUILTIN_PKG_NAMES) {
1757
+ for (const pkg of DEFAULT_EXTENSION_PACKAGES) {
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();
@@ -1722,7 +1808,7 @@ function parseNpmDescriptor(entry) {
1722
1808
  const version = rest.slice(at + 1).split("#")[0]?.trim() || "latest";
1723
1809
  return { packageName, version };
1724
1810
  }
1725
- function loadBuiltinFromToolYamlCache(configFilePath, stepLog) {
1811
+ function loadExtensionFromToolYamlCache(configFilePath, stepLog) {
1726
1812
  const localPath = isAbsolute(configFilePath) ? configFilePath : resolve(process.cwd(), configFilePath);
1727
1813
  if (!existsSync(localPath)) return null;
1728
1814
  const config = loadToolConfig(localPath);
@@ -1730,10 +1816,11 @@ function loadBuiltinFromToolYamlCache(configFilePath, stepLog) {
1730
1816
  if (!Array.isArray(tools)) return null;
1731
1817
  const cacheBase = getCacheBaseFromToolConfig(localPath);
1732
1818
  const cacheOpts = cacheBase ? { cacheBase } : {};
1733
- if (stepLog) stepLog(`Loading builtin from tool.yaml cache (cacheBase: ${cacheBase ?? "~/.agent/cache"})`);
1819
+ if (stepLog) stepLog(`Loading extension from tool.yaml cache (cacheBase: ${cacheBase ?? "~/.agent/cache"})`);
1734
1820
  for (const entry of tools) {
1735
- const parsed = parseNpmDescriptor(String(entry));
1736
- if (!parsed || !BUILTIN_PKG_NAMES.includes(parsed.packageName)) continue;
1821
+ const entryStr = String(entry).trim();
1822
+ const parsed = parseNpmDescriptor(entryStr);
1823
+ if (!parsed) continue;
1737
1824
  for (const opts of [cacheOpts, {}]) {
1738
1825
  try {
1739
1826
  if (stepLog && Object.keys(opts).length === 0 && cacheBase) stepLog("Falling back to default cache ~/.agent/cache");
@@ -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") return mod;
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;
@@ -1752,7 +1842,7 @@ function loadBuiltinFromToolYamlCache(configFilePath, stepLog) {
1752
1842
  }
1753
1843
  return null;
1754
1844
  }
1755
- async function loadBuiltinFromToolYamlCacheAsync(configFilePath, stepLog) {
1845
+ async function loadExtensionFromToolYamlCacheAsync(configFilePath, stepLog) {
1756
1846
  const localPath = isAbsolute(configFilePath) ? configFilePath : resolve(process.cwd(), configFilePath);
1757
1847
  if (!existsSync(localPath)) return null;
1758
1848
  const config = loadToolConfig(localPath);
@@ -1760,17 +1850,21 @@ async function loadBuiltinFromToolYamlCacheAsync(configFilePath, stepLog) {
1760
1850
  if (!Array.isArray(tools)) return null;
1761
1851
  const cacheBase = getCacheBaseFromToolConfig(localPath);
1762
1852
  const cacheOpts = cacheBase ? { cacheBase } : {};
1763
- if (stepLog) stepLog("Loading builtin from tool.yaml cache (async)");
1853
+ if (stepLog) stepLog("Loading extension from tool.yaml cache (async)");
1764
1854
  for (const entry of tools) {
1765
- const parsed = parseNpmDescriptor(String(entry));
1766
- if (!parsed || !BUILTIN_PKG_NAMES.includes(parsed.packageName)) continue;
1855
+ const entryStr = String(entry).trim();
1856
+ const parsed = parseNpmDescriptor(entryStr);
1857
+ if (!parsed) continue;
1767
1858
  for (const opts of [cacheOpts, {}]) {
1768
1859
  try {
1769
1860
  if (stepLog && Object.keys(opts).length === 0 && cacheBase) stepLog("Falling back to default cache ~/.agent/cache");
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") return mod;
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;
@@ -1791,11 +1885,16 @@ function createRuntimeFromConfigSync(options = {}) {
1791
1885
  const registry = new ToolRegistry();
1792
1886
  const stepLog = options.stepLog;
1793
1887
  if (options.coreTools !== void 0) {
1794
- if (stepLog) stepLog("Trying builtin from node_modules");
1795
- let builtin = loadBuiltinTools();
1796
- if (builtin) {
1797
- if (stepLog) stepLog("Registered builtin from node_modules");
1798
- const coreAdapter = builtin.registerCoreTools(registry, options.coreTools);
1888
+ if (stepLog) stepLog("Trying extension from node_modules");
1889
+ let extensionNode = loadExtensionFromNodeModules();
1890
+ if (extensionNode) {
1891
+ if (stepLog) stepLog("Registered extension from node_modules");
1892
+ const descriptor = `npm:${extensionNode.packageName}`;
1893
+ const resolvedVersion = getInstalledPackageVersion(extensionNode.packageName);
1894
+ const prefix = npmDescriptorToRegistryPrefix(descriptor, resolvedVersion ?? void 0);
1895
+ const reg = prefix ? createPrefixingRegistry(registry, prefix) : registry;
1896
+ const coreOptions = prefix ? { registryPrefix: prefix } : void 0;
1897
+ const coreAdapter = extensionNode.registerCoreTools(reg, options.coreTools, coreOptions);
1799
1898
  const runtime3 = new PTCRuntime({ registry });
1800
1899
  runtime3.registerAdapter(coreAdapter);
1801
1900
  if (options.exampleTools !== void 0) {
@@ -1808,22 +1907,25 @@ function createRuntimeFromConfigSync(options = {}) {
1808
1907
  return { runtime: runtime3, registry };
1809
1908
  }
1810
1909
  if (options.configFilePath) {
1811
- if (stepLog) stepLog("No builtin in node_modules, loading from tool.yaml cache");
1812
- builtin = loadBuiltinFromToolYamlCache(options.configFilePath, stepLog);
1813
- }
1814
- if (builtin) {
1815
- if (stepLog) stepLog("Registered builtin from cache");
1816
- const coreAdapter = builtin.registerCoreTools(registry, options.coreTools);
1817
- const runtime3 = new PTCRuntime({ registry });
1818
- runtime3.registerAdapter(coreAdapter);
1819
- if (options.exampleTools !== void 0) {
1820
- const example = loadExampleTools();
1821
- if (example) {
1822
- const exampleAdapter = example.registerExampleTools(registry, options.exampleTools);
1823
- runtime3.registerAdapter(exampleAdapter);
1910
+ if (stepLog) stepLog("No extension in node_modules, loading from tool.yaml cache");
1911
+ const extensionCache = loadExtensionFromToolYamlCache(options.configFilePath, stepLog);
1912
+ if (extensionCache) {
1913
+ if (stepLog) stepLog("Registered extension from cache");
1914
+ const prefix = npmDescriptorToRegistryPrefix(extensionCache.descriptor, extensionCache.resolvedVersion);
1915
+ const reg = prefix ? createPrefixingRegistry(registry, prefix) : registry;
1916
+ const coreOptions = prefix ? { registryPrefix: prefix } : void 0;
1917
+ const coreAdapter = extensionCache.registerCoreTools(reg, options.coreTools, coreOptions);
1918
+ const runtime3 = new PTCRuntime({ registry });
1919
+ runtime3.registerAdapter(coreAdapter);
1920
+ if (options.exampleTools !== void 0) {
1921
+ const example = loadExampleTools();
1922
+ if (example) {
1923
+ const exampleAdapter = example.registerExampleTools(registry, options.exampleTools);
1924
+ runtime3.registerAdapter(exampleAdapter);
1925
+ }
1824
1926
  }
1927
+ return { runtime: runtime3, registry };
1825
1928
  }
1826
- return { runtime: runtime3, registry };
1827
1929
  }
1828
1930
  const runtime2 = new PTCRuntime({ registry });
1829
1931
  return { runtime: runtime2, registry };
@@ -1843,12 +1945,15 @@ function createRuntimeFromConfigSync(options = {}) {
1843
1945
  async function createRuntimeFromConfig(options = {}) {
1844
1946
  const syncResult = createRuntimeFromConfigSync(options);
1845
1947
  if (options.coreTools !== void 0 && options.configFilePath && syncResult.registry.snapshot().length === 0) {
1846
- if (options.stepLog) options.stepLog("No builtin from sync, trying async cache load");
1847
- const builtin = await loadBuiltinFromToolYamlCacheAsync(options.configFilePath, options.stepLog);
1848
- if (builtin) {
1849
- if (options.stepLog) options.stepLog("Registered builtin from async cache");
1948
+ if (options.stepLog) options.stepLog("No extension from sync, trying async cache load");
1949
+ const extension = await loadExtensionFromToolYamlCacheAsync(options.configFilePath, options.stepLog);
1950
+ if (extension) {
1951
+ if (options.stepLog) options.stepLog("Registered extension from async cache");
1850
1952
  const registry = new ToolRegistry();
1851
- const coreAdapter = builtin.registerCoreTools(registry, options.coreTools);
1953
+ const prefix = npmDescriptorToRegistryPrefix(extension.descriptor, extension.resolvedVersion);
1954
+ const reg = prefix ? createPrefixingRegistry(registry, prefix) : registry;
1955
+ const coreOptions = prefix ? { registryPrefix: prefix } : void 0;
1956
+ const coreAdapter = extension.registerCoreTools(reg, options.coreTools, coreOptions);
1852
1957
  const runtime = new PTCRuntime({ registry });
1853
1958
  runtime.registerAdapter(coreAdapter);
1854
1959
  return { runtime, registry };
@@ -1864,6 +1969,6 @@ var MCP_KIND = "mcp";
1864
1969
  var LANGCHAIN_KIND = "langchain";
1865
1970
  var LANGCHAIN_DIR_NAME = "langchain";
1866
1971
 
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-TTYAOTOR.js.map
1869
- //# sourceMappingURL=chunk-TTYAOTOR.js.map
1972
+ export { 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, parseNpmToolDescriptor, resolveNpmToolDescriptor, resolveSandboxedPath, resolveToolDescriptor, sanitizeForLog, summarizeForLog };
1973
+ //# sourceMappingURL=chunk-XYJRKFWR.js.map
1974
+ //# sourceMappingURL=chunk-XYJRKFWR.js.map