@easynet/agent-tool 1.0.103 → 1.0.105

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 (64) hide show
  1. package/README.md +33 -35
  2. package/config/build/build.sh +182 -0
  3. package/config/build/tsconfig.dts.json +34 -0
  4. package/config/build/tsup.config.ts +19 -0
  5. package/config/build/vitest.config.ts +29 -0
  6. package/config/tool.yaml +1 -0
  7. package/dist/api/adapters/LangChainToolsHub.d.ts +1 -0
  8. package/dist/api/adapters/LangChainToolsHub.d.ts.map +1 -1
  9. package/dist/api/expose/openapiHttp.d.ts.map +1 -1
  10. package/dist/api/extension/createExtension.d.ts +1 -1
  11. package/dist/api/extension/createExtension.d.ts.map +1 -1
  12. package/dist/api/extension/index.d.ts +3 -3
  13. package/dist/api/extension/index.d.ts.map +1 -1
  14. package/dist/api/extension/support/groupPrefix.d.ts.map +1 -0
  15. package/dist/api/extension/{types.d.ts → support/types.d.ts} +3 -3
  16. package/dist/api/extension/support/types.d.ts.map +1 -0
  17. package/dist/api/resolveAgentSkillRoots.d.ts +7 -0
  18. package/dist/api/resolveAgentSkillRoots.d.ts.map +1 -0
  19. package/dist/api/runtimeFromConfig.d.ts +2 -65
  20. package/dist/api/runtimeFromConfig.d.ts.map +1 -1
  21. package/dist/api/runtimeFromConfig.types.d.ts +37 -0
  22. package/dist/api/runtimeFromConfig.types.d.ts.map +1 -0
  23. package/dist/build.cjs +5 -5
  24. package/dist/build.js +2 -2
  25. package/dist/{chunk-POUTZDWB.js → chunk-2Y6T67HJ.js} +3 -3
  26. package/dist/chunk-2Y6T67HJ.js.map +1 -0
  27. package/dist/{chunk-VLV5F6HX.cjs → chunk-45MCEW2Y.cjs} +3 -3
  28. package/dist/chunk-45MCEW2Y.cjs.map +1 -0
  29. package/dist/{chunk-KTPQDVP6.cjs → chunk-MQXOFUSU.cjs} +117 -59
  30. package/dist/chunk-MQXOFUSU.cjs.map +1 -0
  31. package/dist/{chunk-3C4VJ4DI.js → chunk-OZUNZILF.js} +109 -57
  32. package/dist/chunk-OZUNZILF.js.map +1 -0
  33. package/dist/{chunk-34SG3EMW.js → chunk-WNWMAS7C.js} +3 -3
  34. package/dist/{chunk-34SG3EMW.js.map → chunk-WNWMAS7C.js.map} +1 -1
  35. package/dist/{chunk-XUIGSBWG.cjs → chunk-YAIP4AYQ.cjs} +7 -7
  36. package/dist/{chunk-XUIGSBWG.cjs.map → chunk-YAIP4AYQ.cjs.map} +1 -1
  37. package/dist/core/runtime/PTCRuntimePipeline.d.ts.map +1 -1
  38. package/dist/index.cjs +120 -17
  39. package/dist/index.cjs.map +1 -1
  40. package/dist/index.d.ts +2 -0
  41. package/dist/index.d.ts.map +1 -1
  42. package/dist/index.js +112 -11
  43. package/dist/index.js.map +1 -1
  44. package/dist/sdk.cjs +1 -1
  45. package/dist/sdk.cjs.map +1 -1
  46. package/dist/sdk.js +1 -1
  47. package/dist/sdk.js.map +1 -1
  48. package/dist/tools/mcp/index.d.ts +1 -0
  49. package/dist/tools/mcp/index.d.ts.map +1 -1
  50. package/dist/tools/mcp/support/types.d.ts.map +1 -0
  51. package/dist/tools/util/toolConfig.d.ts +7 -0
  52. package/dist/tools/util/toolConfig.d.ts.map +1 -1
  53. package/dist/utils/cli/index.cjs +19 -19
  54. package/dist/utils/cli/index.js +3 -3
  55. package/package.json +17 -17
  56. package/dist/api/extension/groupPrefix.d.ts.map +0 -1
  57. package/dist/api/extension/types.d.ts.map +0 -1
  58. package/dist/chunk-3C4VJ4DI.js.map +0 -1
  59. package/dist/chunk-KTPQDVP6.cjs.map +0 -1
  60. package/dist/chunk-POUTZDWB.js.map +0 -1
  61. package/dist/chunk-VLV5F6HX.cjs.map +0 -1
  62. package/dist/tools/mcp/types.d.ts.map +0 -1
  63. /package/dist/api/extension/{groupPrefix.d.ts → support/groupPrefix.d.ts} +0 -0
  64. /package/dist/tools/mcp/{types.d.ts → support/types.d.ts} +0 -0
@@ -1,8 +1,8 @@
1
- import { DirectoryScanner, MCP_KIND } from './chunk-POUTZDWB.js';
1
+ import { DirectoryScanner, MCP_KIND } from './chunk-2Y6T67HJ.js';
2
2
  import { setSandboxValidationEnabled, ToolRegistry, createTaggedError, withRetry } from './chunk-IVL4TBFB.js';
3
3
  import { normalizeToolName } from './chunk-BDUSB6GT.js';
4
4
  import { enrichSpecWithCanonicalSchema } from './chunk-NTWOVFEY.js';
5
- import { readFileSync, existsSync, statSync, rmSync, mkdirSync, readdirSync, renameSync } from 'fs';
5
+ import { readFileSync, existsSync, rmSync, mkdirSync, readdirSync, renameSync, statSync } from 'fs';
6
6
  import { join, resolve, dirname, isAbsolute, basename } from 'path';
7
7
  import { parseYamlContent, resolveConfigPath } from '@easynet/agent-common/config';
8
8
  import { createRequire } from 'module';
@@ -42,14 +42,25 @@ function normalizeToolSources(raw) {
42
42
  const out = {};
43
43
  const customized = source.customized;
44
44
  if (customized && typeof customized === "object" && !Array.isArray(customized)) {
45
- for (const [sourceKey, sourceValue] of Object.entries(customized)) {
46
- if (!sourceValue || typeof sourceValue !== "object" || Array.isArray(sourceValue)) continue;
45
+ const customizedSource = customized;
46
+ const descriptorGrouped = Object.keys(customizedSource).some((key) => /^(npm|file):/.test(key));
47
+ if (descriptorGrouped) {
48
+ for (const [sourceKey, sourceValue] of Object.entries(customizedSource)) {
49
+ if (!sourceValue || typeof sourceValue !== "object" || Array.isArray(sourceValue)) continue;
50
+ const toolMap = {};
51
+ for (const [toolName, toolValue] of Object.entries(sourceValue)) {
52
+ if (!toolValue || typeof toolValue !== "object" || Array.isArray(toolValue)) continue;
53
+ toolMap[toolName] = toolValue;
54
+ }
55
+ out[sourceKey] = toolMap;
56
+ }
57
+ } else {
47
58
  const toolMap = {};
48
- for (const [toolName, toolValue] of Object.entries(sourceValue)) {
59
+ for (const [toolName, toolValue] of Object.entries(customizedSource)) {
49
60
  if (!toolValue || typeof toolValue !== "object" || Array.isArray(toolValue)) continue;
50
61
  toolMap[toolName] = toolValue;
51
62
  }
52
- out[sourceKey] = toolMap;
63
+ if (Object.keys(toolMap).length > 0) out.self = toolMap;
53
64
  }
54
65
  }
55
66
  for (const [sourceKey, sourceValue] of Object.entries(source)) {
@@ -64,6 +75,19 @@ function normalizeToolSources(raw) {
64
75
  }
65
76
  return Object.keys(out).length > 0 ? out : void 0;
66
77
  }
78
+ function normalizePathSources(raw) {
79
+ if (!raw || typeof raw !== "object" || Array.isArray(raw)) return void 0;
80
+ const source = raw;
81
+ const out = {};
82
+ for (const [descriptor, value] of Object.entries(source)) {
83
+ if (!value || typeof value !== "object" || Array.isArray(value)) {
84
+ out[descriptor] = {};
85
+ continue;
86
+ }
87
+ out[descriptor] = value;
88
+ }
89
+ return Object.keys(out).length > 0 ? out : void 0;
90
+ }
67
91
  function loadToolConfig(toolYamlPath) {
68
92
  const abs = resolve(toolYamlPath);
69
93
  const raw = readFileSync(abs, "utf8");
@@ -74,6 +98,10 @@ function loadToolConfig(toolYamlPath) {
74
98
  const source = parsed.spec && typeof parsed.spec === "object" && !Array.isArray(parsed.spec) ? parsed.spec : parsed;
75
99
  return {
76
100
  sandboxedPath: typeof source.sandboxedPath === "string" ? source.sandboxedPath : void 0,
101
+ cacheDir: typeof source.cacheDir === "string" ? source.cacheDir : void 0,
102
+ toolPath: typeof source.toolPath === "string" ? source.toolPath : void 0,
103
+ skillPath: typeof source.skillPath === "string" ? source.skillPath : void 0,
104
+ paths: normalizePathSources(source.paths),
77
105
  enableSandboxValidation: typeof source.enableSandboxValidation === "boolean" ? source.enableSandboxValidation : void 0,
78
106
  allowedHosts: Array.isArray(source.allowedHosts) ? source.allowedHosts : void 0,
79
107
  blockedHosts: Array.isArray(source.blockedHosts) ? source.blockedHosts : void 0,
@@ -87,15 +115,29 @@ function getToolSourceDescriptors(config, options) {
87
115
  const includeSelf = options?.includeSelf ?? false;
88
116
  return Object.keys(config.tools ?? {}).filter((key) => includeSelf || key !== "self");
89
117
  }
118
+ function getPathSourceDescriptors(config) {
119
+ const fromPaths = Object.keys(config.paths ?? {});
120
+ if (fromPaths.length > 0) return fromPaths;
121
+ return getToolSourceDescriptors(config);
122
+ }
90
123
  function resolveSandboxedPath(toolYamlPath, sandboxedPath) {
91
124
  const configDir = dirname(resolve(toolYamlPath));
92
125
  return resolveConfigPath(sandboxedPath, configDir, {
93
126
  expandHome: true
94
127
  });
95
128
  }
129
+ function resolveCacheDir(toolYamlPath, cacheDir) {
130
+ const configDir = dirname(resolve(toolYamlPath));
131
+ return resolveConfigPath(cacheDir, configDir, {
132
+ expandHome: true
133
+ });
134
+ }
96
135
  var CACHE_SUBDIR = ".agent/cache";
97
136
  function getCacheBaseFromToolConfig(toolYamlPath) {
98
137
  const config = loadToolConfig(toolYamlPath);
138
+ if (config.cacheDir && typeof config.cacheDir === "string") {
139
+ return resolveCacheDir(toolYamlPath, config.cacheDir);
140
+ }
99
141
  if (!config.sandboxedPath || typeof config.sandboxedPath !== "string") return void 0;
100
142
  const sandboxRoot = resolveSandboxedPath(toolYamlPath, config.sandboxedPath);
101
143
  return join(sandboxRoot, CACHE_SUBDIR);
@@ -1170,14 +1212,19 @@ var Tracing = class {
1170
1212
  function resolveTool(toolName, registry) {
1171
1213
  const key = normalizeToolName(toolName);
1172
1214
  const spec = registry.get(key);
1173
- if (!spec) {
1174
- throw createTaggedError(
1175
- "TOOL_NOT_FOUND",
1176
- `Tool not found: ${toolName}`,
1177
- { availableTools: registry.snapshot().slice(0, 20).map((s) => s.name) }
1178
- );
1179
- }
1180
- return spec;
1215
+ if (spec) {
1216
+ return spec;
1217
+ }
1218
+ const suffixMatches = registry.snapshot().filter((candidate) => candidate.name.endsWith(`.${key}`));
1219
+ const uniqueSuffixMatch = suffixMatches[0];
1220
+ if (suffixMatches.length === 1 && uniqueSuffixMatch !== void 0) {
1221
+ return uniqueSuffixMatch;
1222
+ }
1223
+ throw createTaggedError(
1224
+ "TOOL_NOT_FOUND",
1225
+ `Tool not found: ${toolName}`,
1226
+ { availableTools: registry.snapshot().slice(0, 20).map((s) => s.name) }
1227
+ );
1181
1228
  }
1182
1229
  var INPUT_ALIASES = {
1183
1230
  q: "query"
@@ -1802,7 +1849,7 @@ function packagePathSegments(name) {
1802
1849
  const withoutScope = name.replace(/^@/, "");
1803
1850
  return withoutScope.split("/").filter(Boolean);
1804
1851
  }
1805
- function resolveCacheDir(cacheBase, packageName, version) {
1852
+ function resolveCacheDir2(cacheBase, packageName, version) {
1806
1853
  const segments = packagePathSegments(packageName);
1807
1854
  return join(cacheBase, ...segments, version);
1808
1855
  }
@@ -1810,7 +1857,7 @@ function ensurePackageInCache(packageName, version = "latest", options = {}) {
1810
1857
  const cacheBase = options.cacheBase ?? DEFAULT_CACHE_BASE;
1811
1858
  const cwd = options.cwd ?? process.cwd();
1812
1859
  const resolvedVersion = isLatestRequest(version) ? resolveLatestVersionFromRegistry(packageName, { cwd }) : version;
1813
- const cacheDir = resolveCacheDir(cacheBase, packageName, resolvedVersion);
1860
+ const cacheDir = resolveCacheDir2(cacheBase, packageName, resolvedVersion);
1814
1861
  const packageJsonPath = join(cacheDir, "package.json");
1815
1862
  const nodeModulesPath = join(cacheDir, "node_modules");
1816
1863
  if (existsSync(packageJsonPath) && existsSync(nodeModulesPath)) {
@@ -2055,9 +2102,11 @@ function parseNpmDescriptor(entry) {
2055
2102
  return { packageName, version };
2056
2103
  }
2057
2104
 
2105
+ // src/api/runtimeFromConfig.types.ts
2106
+ var DEFAULT_EXTENSION_PACKAGES = [];
2107
+
2058
2108
  // src/api/runtimeFromConfig.ts
2059
2109
  var requireFromPackage2 = createRequire(import.meta.url);
2060
- var DEFAULT_EXTENSION_PACKAGES = [];
2061
2110
  function resolveEffectiveCoreTools(options) {
2062
2111
  if (options.coreTools) return options.coreTools;
2063
2112
  if (options.configFilePath) return {};
@@ -2191,7 +2240,7 @@ function loadAllExtensionsFromToolYamlSync(configFilePath, stepLog) {
2191
2240
  const localPath = isAbsolute(configFilePath) ? configFilePath : resolve(process.cwd(), configFilePath);
2192
2241
  if (!existsSync(localPath)) return [];
2193
2242
  const config = loadToolConfig(localPath);
2194
- const tools = getToolSourceDescriptors(config);
2243
+ const tools = getPathSourceDescriptors(config);
2195
2244
  if (!Array.isArray(tools) || tools.length === 0) return [];
2196
2245
  if (stepLog) stepLog("Loading extensions from tool.yaml (npm + file)");
2197
2246
  const loaded = [];
@@ -2294,7 +2343,7 @@ async function loadAllExtensionsFromToolYamlAsync(configFilePath, stepLog) {
2294
2343
  const localPath = isAbsolute(configFilePath) ? configFilePath : resolve(process.cwd(), configFilePath);
2295
2344
  if (!existsSync(localPath)) return [];
2296
2345
  const config = loadToolConfig(localPath);
2297
- const tools = getToolSourceDescriptors(config);
2346
+ const tools = getPathSourceDescriptors(config);
2298
2347
  if (!Array.isArray(tools) || tools.length === 0) return [];
2299
2348
  if (stepLog) stepLog("Loading extensions from tool.yaml (async)");
2300
2349
  const loaded = [];
@@ -2816,42 +2865,27 @@ async function invokeAndSend(runtime, ctx, res, tool, args) {
2816
2865
  details: result.error?.details
2817
2866
  });
2818
2867
  }
2819
- function createOpenAPIHttpServer(runtime, options = {}) {
2820
- const app = express();
2821
- const router = express.Router();
2822
- const basePath = (options.basePath ?? "").replace(/\/$/, "");
2823
- const ctxFactory = options.execContextFactory ?? (() => ({ ...DEFAULT_CTX2 }));
2824
- app.use(express.text({ type: "*/*" }));
2825
- router.get("/", (_req, res) => {
2826
- const specPath = basePath ? `${basePath}/openapi.json` : "/openapi.json";
2827
- res.type("text/html; charset=utf-8").send(swaggerUiHtml(specPath));
2868
+ function buildSpec(runtime, basePath) {
2869
+ return toolsToOpenAPISpec(runtime.getRegistry(), {
2870
+ title: "Tool API",
2871
+ version: "1.0.0",
2872
+ basePath: basePath || void 0
2828
2873
  });
2829
- router.get("/swagger", (_req, res) => {
2874
+ }
2875
+ function registerSpecRoutes(router, runtime, basePath) {
2876
+ const sendSpec = (_req, res) => {
2877
+ sendJson(res, 200, buildSpec(runtime, basePath));
2878
+ };
2879
+ const sendSwagger = (_req, res) => {
2830
2880
  const specPath = basePath ? `${basePath}/openapi.json` : "/openapi.json";
2831
2881
  res.type("text/html; charset=utf-8").send(swaggerUiHtml(specPath));
2832
- });
2833
- router.get("/openapi.json", (_req, res) => {
2834
- sendJson(
2835
- res,
2836
- 200,
2837
- toolsToOpenAPISpec(runtime.getRegistry(), {
2838
- title: "Tool API",
2839
- version: "1.0.0",
2840
- basePath: basePath || void 0
2841
- })
2842
- );
2843
- });
2844
- router.get("/spec", (_req, res) => {
2845
- sendJson(
2846
- res,
2847
- 200,
2848
- toolsToOpenAPISpec(runtime.getRegistry(), {
2849
- title: "Tool API",
2850
- version: "1.0.0",
2851
- basePath: basePath || void 0
2852
- })
2853
- );
2854
- });
2882
+ };
2883
+ router.get("/", sendSwagger);
2884
+ router.get("/swagger", sendSwagger);
2885
+ router.get("/openapi.json", sendSpec);
2886
+ router.get("/spec", sendSpec);
2887
+ }
2888
+ function registerToolRoutes(router, runtime, ctxFactory) {
2855
2889
  router.get("/tools", async (_req, res, next) => {
2856
2890
  try {
2857
2891
  const { enrichSpecWithCanonicalSchema: enrichSpecWithCanonicalSchema2 } = await import('./canonicalCoreSchemas-PHGTNPN5.js');
@@ -2891,11 +2925,15 @@ function createOpenAPIHttpServer(runtime, options = {}) {
2891
2925
  }
2892
2926
  await invokeAndSend(runtime, ctxFactory(req), res, slugToToolName(req.params?.slug ?? ""), args);
2893
2927
  });
2928
+ }
2929
+ function mountRouter(app, router, basePath) {
2894
2930
  if (basePath) {
2895
2931
  app.use(basePath, router);
2896
- } else {
2897
- app.use(router);
2932
+ return;
2898
2933
  }
2934
+ app.use(router);
2935
+ }
2936
+ function registerErrorHandlers(app) {
2899
2937
  app.use((req, res) => {
2900
2938
  sendJson(res, 404, { error: "Not found", path: req.url ?? "/" });
2901
2939
  });
@@ -2903,6 +2941,8 @@ function createOpenAPIHttpServer(runtime, options = {}) {
2903
2941
  const message = err instanceof Error ? err.message : String(err);
2904
2942
  sendJson(res, 500, { error: message, kind: "INTERNAL_ERROR" });
2905
2943
  });
2944
+ }
2945
+ function patchListenDefaults(app, options) {
2906
2946
  const originalListen = app.listen.bind(app);
2907
2947
  const defaultPort = options.port;
2908
2948
  const defaultHost = options.host;
@@ -2915,6 +2955,18 @@ function createOpenAPIHttpServer(runtime, options = {}) {
2915
2955
  }
2916
2956
  return originalListen(...args);
2917
2957
  });
2958
+ }
2959
+ function createOpenAPIHttpServer(runtime, options = {}) {
2960
+ const app = express();
2961
+ const router = express.Router();
2962
+ const basePath = (options.basePath ?? "").replace(/\/$/, "");
2963
+ const ctxFactory = options.execContextFactory ?? (() => ({ ...DEFAULT_CTX2 }));
2964
+ app.use(express.text({ type: "*/*" }));
2965
+ registerSpecRoutes(router, runtime, basePath);
2966
+ registerToolRoutes(router, runtime, ctxFactory);
2967
+ mountRouter(app, router, basePath);
2968
+ registerErrorHandlers(app);
2969
+ patchListenDefaults(app, options);
2918
2970
  return app;
2919
2971
  }
2920
2972
  function listenOpenAPIHttpServer(app, options = {}) {
@@ -2956,6 +3008,6 @@ async function createHttpService(runtimeOrConfig, options = {}) {
2956
3008
  };
2957
3009
  }
2958
3010
 
2959
- export { createHttpService, createMCPServerStreamableHttp, createRuntimeFromConfig, expandToolDescriptorsToRegistryNames, fileDescriptorToPackagePrefix, findAndLoadToolConfig, getDisplayScope, getToolSourceDescriptors, isBarePackageDescriptor, loadToolConfig, npmDescriptorToPackagePrefix, resolveSandboxedPath, resolveToolDescriptor, runMCPServerOverStdio, toToolObservationText };
2960
- //# sourceMappingURL=chunk-3C4VJ4DI.js.map
2961
- //# sourceMappingURL=chunk-3C4VJ4DI.js.map
3011
+ export { createHttpService, createMCPServerStreamableHttp, createRuntimeFromConfig, ensurePackageInCache, expandToolDescriptorsToRegistryNames, fileDescriptorToPackagePrefix, findAndLoadToolConfig, getCacheBaseFromToolConfig, getDisplayScope, getPathSourceDescriptors, getToolSourceDescriptors, isBarePackageDescriptor, loadToolConfig, npmDescriptorToPackagePrefix, parseNpmDescriptor, parseToolPath, resolveLatestVersionFromRegistry, resolveSandboxedPath, resolveToolDescriptor, runMCPServerOverStdio, toToolObservationText };
3012
+ //# sourceMappingURL=chunk-OZUNZILF.js.map
3013
+ //# sourceMappingURL=chunk-OZUNZILF.js.map