@easynet/agent-tool 1.0.18 → 1.0.20

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 (74) hide show
  1. package/dist/api/expose/mcpServer.d.ts.map +1 -1
  2. package/dist/api/expose/openapi.d.ts +2 -2
  3. package/dist/api/expose/openapi.d.ts.map +1 -1
  4. package/dist/api/main.cjs +17 -16
  5. package/dist/api/main.js +6 -5
  6. package/dist/api/runtimeFromConfig.d.ts.map +1 -1
  7. package/dist/canonicalCoreSchemas-JPTOIQKR.js +4 -0
  8. package/dist/{canonicalCoreSchemas-YLHVHYJZ.js.map → canonicalCoreSchemas-JPTOIQKR.js.map} +1 -1
  9. package/dist/canonicalCoreSchemas-K57HKGZJ.cjs +21 -0
  10. package/dist/{canonicalCoreSchemas-CTW6CCFY.cjs.map → canonicalCoreSchemas-K57HKGZJ.cjs.map} +1 -1
  11. package/dist/{chunk-6F5JHLZ7.cjs → chunk-6JWQVVL2.cjs} +24 -20
  12. package/dist/chunk-6JWQVVL2.cjs.map +1 -0
  13. package/dist/{chunk-EMI67SPN.cjs → chunk-6WQYJLVU.cjs} +151 -45
  14. package/dist/chunk-6WQYJLVU.cjs.map +1 -0
  15. package/dist/{chunk-SOFUWEZ6.cjs → chunk-FGGTT32N.cjs} +9 -3
  16. package/dist/chunk-FGGTT32N.cjs.map +1 -0
  17. package/dist/{chunk-5SWSNVMI.js → chunk-GWBJEGS7.js} +9 -4
  18. package/dist/chunk-GWBJEGS7.js.map +1 -0
  19. package/dist/{chunk-RKN4PT7P.js → chunk-IGMDLCV7.js} +138 -33
  20. package/dist/chunk-IGMDLCV7.js.map +1 -0
  21. package/dist/{chunk-OXTQULXH.cjs → chunk-INYWD3OJ.cjs} +14 -13
  22. package/dist/chunk-INYWD3OJ.cjs.map +1 -0
  23. package/dist/{chunk-AE6FSNGY.js → chunk-IU35EFPK.js} +14 -10
  24. package/dist/chunk-IU35EFPK.js.map +1 -0
  25. package/dist/{chunk-7WI5VK5G.js → chunk-NNMMUG2X.js} +3 -3
  26. package/dist/{chunk-7WI5VK5G.js.map → chunk-NNMMUG2X.js.map} +1 -1
  27. package/dist/{chunk-7MRBWT2T.js → chunk-OHDIMQ22.js} +4 -4
  28. package/dist/{chunk-7MRBWT2T.js.map → chunk-OHDIMQ22.js.map} +1 -1
  29. package/dist/{chunk-ZNJBRLKN.cjs → chunk-ONIBCU2Y.cjs} +14 -10
  30. package/dist/chunk-ONIBCU2Y.cjs.map +1 -0
  31. package/dist/{chunk-FR2CXERF.js → chunk-P5UPHQ7N.js} +24 -20
  32. package/dist/chunk-P5UPHQ7N.js.map +1 -0
  33. package/dist/{chunk-YK2MQDNJ.cjs → chunk-QP6JJF76.cjs} +11 -11
  34. package/dist/{chunk-YK2MQDNJ.cjs.map → chunk-QP6JJF76.cjs.map} +1 -1
  35. package/dist/{chunk-ZIFQWIN3.cjs → chunk-TAW4FP3A.cjs} +18 -18
  36. package/dist/{chunk-ZIFQWIN3.cjs.map → chunk-TAW4FP3A.cjs.map} +1 -1
  37. package/dist/{chunk-ETWGKCOP.js → chunk-WKWSXCS4.js} +9 -8
  38. package/dist/chunk-WKWSXCS4.js.map +1 -0
  39. package/dist/core/index.cjs +4 -4
  40. package/dist/core/index.js +1 -1
  41. package/dist/core/registry/ToolRegistry.d.ts +2 -2
  42. package/dist/core/registry/ToolRegistry.d.ts.map +1 -1
  43. package/dist/core/runtime/PTCRuntimePipeline.d.ts +1 -1
  44. package/dist/core/runtime/PTCRuntimePipeline.d.ts.map +1 -1
  45. package/dist/core/runtime.cjs +6 -5
  46. package/dist/core/runtime.js +2 -1
  47. package/dist/core/types/ToolSpec.d.ts +5 -0
  48. package/dist/core/types/ToolSpec.d.ts.map +1 -1
  49. package/dist/index.cjs +81 -73
  50. package/dist/index.d.ts +2 -2
  51. package/dist/index.d.ts.map +1 -1
  52. package/dist/index.js +10 -10
  53. package/dist/tools/util/canonicalCoreSchemas.d.ts.map +1 -1
  54. package/dist/tools/util/index.d.ts +1 -1
  55. package/dist/tools/util/index.d.ts.map +1 -1
  56. package/dist/tools/util/toolDescriptor.d.ts +11 -13
  57. package/dist/tools/util/toolDescriptor.d.ts.map +1 -1
  58. package/dist/utils/cli/index.cjs +23 -23
  59. package/dist/utils/cli/index.cjs.map +1 -1
  60. package/dist/utils/cli/index.js +8 -8
  61. package/dist/utils/cli/index.js.map +1 -1
  62. package/package.json +1 -1
  63. package/dist/canonicalCoreSchemas-CTW6CCFY.cjs +0 -20
  64. package/dist/canonicalCoreSchemas-YLHVHYJZ.js +0 -3
  65. package/dist/chunk-5SWSNVMI.js.map +0 -1
  66. package/dist/chunk-6F5JHLZ7.cjs.map +0 -1
  67. package/dist/chunk-AE6FSNGY.js.map +0 -1
  68. package/dist/chunk-EMI67SPN.cjs.map +0 -1
  69. package/dist/chunk-ETWGKCOP.js.map +0 -1
  70. package/dist/chunk-FR2CXERF.js.map +0 -1
  71. package/dist/chunk-OXTQULXH.cjs.map +0 -1
  72. package/dist/chunk-RKN4PT7P.js.map +0 -1
  73. package/dist/chunk-SOFUWEZ6.cjs.map +0 -1
  74. package/dist/chunk-ZNJBRLKN.cjs.map +0 -1
@@ -1,4 +1,5 @@
1
- import { ToolRegistry, createTaggedError, withRetry } from './chunk-AE6FSNGY.js';
1
+ import { ToolRegistry, createTaggedError, withRetry } from './chunk-IU35EFPK.js';
2
+ import { normalizeToolName } from './chunk-GWBJEGS7.js';
2
3
  import Ajv from 'ajv';
3
4
  import addFormats from 'ajv-formats';
4
5
  import { bulkhead, circuitBreaker, handleAll, ConsecutiveBreaker } from 'cockatiel';
@@ -6,7 +7,7 @@ import { EventEmitter } from 'eventemitter3';
6
7
  import { v4 } from 'uuid';
7
8
  import pTimeout from 'p-timeout';
8
9
  import { readFileSync, existsSync, mkdirSync, readdirSync, rmSync, renameSync } from 'fs';
9
- import { join, resolve, dirname, isAbsolute } from 'path';
10
+ import { join, resolve, dirname, isAbsolute, basename } from 'path';
10
11
  import { homedir } from 'os';
11
12
  import yaml from 'js-yaml';
12
13
  import { execSync } from 'child_process';
@@ -929,7 +930,8 @@ var Tracing = class {
929
930
  }
930
931
  };
931
932
  function resolveTool(toolName, registry) {
932
- const spec = registry.get(toolName);
933
+ const key = normalizeToolName(toolName);
934
+ const spec = registry.get(key);
933
935
  if (!spec) {
934
936
  throw createTaggedError(
935
937
  "TOOL_NOT_FOUND",
@@ -1498,6 +1500,26 @@ function parseToolPath(descriptor) {
1498
1500
  toolName: m[5] ?? ""
1499
1501
  };
1500
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
+ }
1501
1523
  function isNpmToolDescriptor(descriptor) {
1502
1524
  return isToolPath(descriptor) && parseToolPath(descriptor)?.protocol === "npm";
1503
1525
  }
@@ -1510,7 +1532,7 @@ function parseNpmToolDescriptor(descriptor) {
1510
1532
  };
1511
1533
  }
1512
1534
  function getDisplayScope(registryName, _kind, _toolVersion) {
1513
- const i = registryName.indexOf("/");
1535
+ const i = registryName.indexOf(".");
1514
1536
  return i < 0 ? registryName : registryName.slice(0, i);
1515
1537
  }
1516
1538
  function resolveNpmToolDescriptor(descriptor) {
@@ -1520,15 +1542,32 @@ function expandToolDescriptorsToRegistryNames(descriptors, registryNames) {
1520
1542
  const out = [];
1521
1543
  const seen = /* @__PURE__ */ new Set();
1522
1544
  function add(name) {
1523
- if (registryNames.includes(name) && !seen.has(name)) {
1524
- seen.add(name);
1525
- 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
+ }
1526
1557
  }
1527
1558
  }
1528
1559
  for (const d of descriptors) {
1529
1560
  const s = d.trim();
1530
1561
  if (!s) continue;
1531
- add(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);
1570
+ add(name);
1532
1571
  }
1533
1572
  return out;
1534
1573
  }
@@ -1694,6 +1733,22 @@ var BUILTIN_PKG_NAMES = [
1694
1733
  "@easynet/agent-tool-builtin",
1695
1734
  "@easynet/agent-tool-buildin"
1696
1735
  ];
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
+ }
1697
1752
  function loadBuiltinTools() {
1698
1753
  const projectRequire = getProjectRequire();
1699
1754
  const requirers = [requireFromPackage];
@@ -1702,7 +1757,7 @@ function loadBuiltinTools() {
1702
1757
  for (const pkg of BUILTIN_PKG_NAMES) {
1703
1758
  try {
1704
1759
  const mod = req(pkg);
1705
- if (mod && typeof mod.registerCoreTools === "function") return mod;
1760
+ if (mod && typeof mod.registerCoreTools === "function") return { registerCoreTools: mod.registerCoreTools, packageName: pkg };
1706
1761
  } catch {
1707
1762
  continue;
1708
1763
  }
@@ -1710,6 +1765,40 @@ function loadBuiltinTools() {
1710
1765
  }
1711
1766
  return null;
1712
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
+ }
1713
1802
  function parseNpmDescriptor(entry) {
1714
1803
  if (typeof entry !== "string" || !entry.startsWith("npm:")) return null;
1715
1804
  const rest = entry.slice(4).trim();
@@ -1729,7 +1818,8 @@ function loadBuiltinFromToolYamlCache(configFilePath, stepLog) {
1729
1818
  const cacheOpts = cacheBase ? { cacheBase } : {};
1730
1819
  if (stepLog) stepLog(`Loading builtin from tool.yaml cache (cacheBase: ${cacheBase ?? "~/.agent/cache"})`);
1731
1820
  for (const entry of tools) {
1732
- const parsed = parseNpmDescriptor(String(entry));
1821
+ const entryStr = String(entry).trim();
1822
+ const parsed = parseNpmDescriptor(entryStr);
1733
1823
  if (!parsed || !BUILTIN_PKG_NAMES.includes(parsed.packageName)) continue;
1734
1824
  for (const opts of [cacheOpts, {}]) {
1735
1825
  try {
@@ -1739,7 +1829,10 @@ function loadBuiltinFromToolYamlCache(configFilePath, stepLog) {
1739
1829
  const entryPath = getPackageEntryPath(cacheDir);
1740
1830
  const req = createRequire(join(cacheDir, "package.json"));
1741
1831
  const mod = req(entryPath);
1742
- 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
+ }
1743
1836
  break;
1744
1837
  } catch {
1745
1838
  if (Object.keys(opts).length > 0) continue;
@@ -1759,7 +1852,8 @@ async function loadBuiltinFromToolYamlCacheAsync(configFilePath, stepLog) {
1759
1852
  const cacheOpts = cacheBase ? { cacheBase } : {};
1760
1853
  if (stepLog) stepLog("Loading builtin from tool.yaml cache (async)");
1761
1854
  for (const entry of tools) {
1762
- const parsed = parseNpmDescriptor(String(entry));
1855
+ const entryStr = String(entry).trim();
1856
+ const parsed = parseNpmDescriptor(entryStr);
1763
1857
  if (!parsed || !BUILTIN_PKG_NAMES.includes(parsed.packageName)) continue;
1764
1858
  for (const opts of [cacheOpts, {}]) {
1765
1859
  try {
@@ -1767,7 +1861,10 @@ async function loadBuiltinFromToolYamlCacheAsync(configFilePath, stepLog) {
1767
1861
  const cacheDir = ensurePackageInCache(parsed.packageName, parsed.version, opts);
1768
1862
  if (stepLog) stepLog(`Using cache: ${cacheDir}`);
1769
1863
  const mod = await importFromCache(cacheDir);
1770
- 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
+ }
1771
1868
  break;
1772
1869
  } catch {
1773
1870
  if (Object.keys(opts).length > 0) continue;
@@ -1789,10 +1886,14 @@ function createRuntimeFromConfigSync(options = {}) {
1789
1886
  const stepLog = options.stepLog;
1790
1887
  if (options.coreTools !== void 0) {
1791
1888
  if (stepLog) stepLog("Trying builtin from node_modules");
1792
- let builtin = loadBuiltinTools();
1793
- if (builtin) {
1889
+ let builtinNode = loadBuiltinTools();
1890
+ if (builtinNode) {
1794
1891
  if (stepLog) stepLog("Registered builtin from node_modules");
1795
- const coreAdapter = builtin.registerCoreTools(registry, options.coreTools);
1892
+ const descriptor = `npm:${builtinNode.packageName}`;
1893
+ const resolvedVersion = getInstalledPackageVersion(builtinNode.packageName);
1894
+ const prefix = npmDescriptorToRegistryPrefix(descriptor, resolvedVersion ?? void 0);
1895
+ const reg = prefix ? createPrefixingRegistry(registry, prefix) : registry;
1896
+ const coreAdapter = builtinNode.registerCoreTools(reg, options.coreTools);
1796
1897
  const runtime3 = new PTCRuntime({ registry });
1797
1898
  runtime3.registerAdapter(coreAdapter);
1798
1899
  if (options.exampleTools !== void 0) {
@@ -1806,21 +1907,23 @@ function createRuntimeFromConfigSync(options = {}) {
1806
1907
  }
1807
1908
  if (options.configFilePath) {
1808
1909
  if (stepLog) stepLog("No builtin in node_modules, loading from tool.yaml cache");
1809
- builtin = loadBuiltinFromToolYamlCache(options.configFilePath, stepLog);
1810
- }
1811
- if (builtin) {
1812
- if (stepLog) stepLog("Registered builtin from cache");
1813
- const coreAdapter = builtin.registerCoreTools(registry, options.coreTools);
1814
- const runtime3 = new PTCRuntime({ registry });
1815
- runtime3.registerAdapter(coreAdapter);
1816
- if (options.exampleTools !== void 0) {
1817
- const example = loadExampleTools();
1818
- if (example) {
1819
- const exampleAdapter = example.registerExampleTools(registry, options.exampleTools);
1820
- runtime3.registerAdapter(exampleAdapter);
1910
+ const builtinCache = loadBuiltinFromToolYamlCache(options.configFilePath, stepLog);
1911
+ if (builtinCache) {
1912
+ if (stepLog) stepLog("Registered builtin from cache");
1913
+ const prefix = npmDescriptorToRegistryPrefix(builtinCache.descriptor, builtinCache.resolvedVersion);
1914
+ const reg = prefix ? createPrefixingRegistry(registry, prefix) : registry;
1915
+ const coreAdapter = builtinCache.registerCoreTools(reg, options.coreTools);
1916
+ const runtime3 = new PTCRuntime({ registry });
1917
+ runtime3.registerAdapter(coreAdapter);
1918
+ if (options.exampleTools !== void 0) {
1919
+ const example = loadExampleTools();
1920
+ if (example) {
1921
+ const exampleAdapter = example.registerExampleTools(registry, options.exampleTools);
1922
+ runtime3.registerAdapter(exampleAdapter);
1923
+ }
1821
1924
  }
1925
+ return { runtime: runtime3, registry };
1822
1926
  }
1823
- return { runtime: runtime3, registry };
1824
1927
  }
1825
1928
  const runtime2 = new PTCRuntime({ registry });
1826
1929
  return { runtime: runtime2, registry };
@@ -1845,7 +1948,9 @@ async function createRuntimeFromConfig(options = {}) {
1845
1948
  if (builtin) {
1846
1949
  if (options.stepLog) options.stepLog("Registered builtin from async cache");
1847
1950
  const registry = new ToolRegistry();
1848
- const coreAdapter = builtin.registerCoreTools(registry, options.coreTools);
1951
+ const prefix = npmDescriptorToRegistryPrefix(builtin.descriptor, builtin.resolvedVersion);
1952
+ const reg = prefix ? createPrefixingRegistry(registry, prefix) : registry;
1953
+ const coreAdapter = builtin.registerCoreTools(reg, options.coreTools);
1849
1954
  const runtime = new PTCRuntime({ registry });
1850
1955
  runtime.registerAdapter(coreAdapter);
1851
1956
  return { runtime, registry };
@@ -1861,6 +1966,6 @@ var MCP_KIND = "mcp";
1861
1966
  var LANGCHAIN_KIND = "langchain";
1862
1967
  var LANGCHAIN_DIR_NAME = "langchain";
1863
1968
 
1864
- 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 };
1865
- //# sourceMappingURL=chunk-RKN4PT7P.js.map
1866
- //# sourceMappingURL=chunk-RKN4PT7P.js.map
1969
+ 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, npmDescriptorToRegistryPrefix, parseNpmDescriptor, parseNpmToolDescriptor, resolveNpmToolDescriptor, resolveSandboxedPath, resolveToolDescriptor, sanitizeForLog, summarizeForLog };
1970
+ //# sourceMappingURL=chunk-IGMDLCV7.js.map
1971
+ //# sourceMappingURL=chunk-IGMDLCV7.js.map