@easynet/agent-tool 1.0.104 → 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.
@@ -2865,42 +2865,27 @@ async function invokeAndSend(runtime, ctx, res, tool, args) {
2865
2865
  details: result.error?.details
2866
2866
  });
2867
2867
  }
2868
- function createOpenAPIHttpServer(runtime, options = {}) {
2869
- const app = express();
2870
- const router = express.Router();
2871
- const basePath = (options.basePath ?? "").replace(/\/$/, "");
2872
- const ctxFactory = options.execContextFactory ?? (() => ({ ...DEFAULT_CTX2 }));
2873
- app.use(express.text({ type: "*/*" }));
2874
- router.get("/", (_req, res) => {
2875
- const specPath = basePath ? `${basePath}/openapi.json` : "/openapi.json";
2876
- 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
2877
2873
  });
2878
- 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) => {
2879
2880
  const specPath = basePath ? `${basePath}/openapi.json` : "/openapi.json";
2880
2881
  res.type("text/html; charset=utf-8").send(swaggerUiHtml(specPath));
2881
- });
2882
- router.get("/openapi.json", (_req, res) => {
2883
- sendJson(
2884
- res,
2885
- 200,
2886
- toolsToOpenAPISpec(runtime.getRegistry(), {
2887
- title: "Tool API",
2888
- version: "1.0.0",
2889
- basePath: basePath || void 0
2890
- })
2891
- );
2892
- });
2893
- router.get("/spec", (_req, res) => {
2894
- sendJson(
2895
- res,
2896
- 200,
2897
- toolsToOpenAPISpec(runtime.getRegistry(), {
2898
- title: "Tool API",
2899
- version: "1.0.0",
2900
- basePath: basePath || void 0
2901
- })
2902
- );
2903
- });
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) {
2904
2889
  router.get("/tools", async (_req, res, next) => {
2905
2890
  try {
2906
2891
  const { enrichSpecWithCanonicalSchema: enrichSpecWithCanonicalSchema2 } = await import('./canonicalCoreSchemas-PHGTNPN5.js');
@@ -2940,11 +2925,15 @@ function createOpenAPIHttpServer(runtime, options = {}) {
2940
2925
  }
2941
2926
  await invokeAndSend(runtime, ctxFactory(req), res, slugToToolName(req.params?.slug ?? ""), args);
2942
2927
  });
2928
+ }
2929
+ function mountRouter(app, router, basePath) {
2943
2930
  if (basePath) {
2944
2931
  app.use(basePath, router);
2945
- } else {
2946
- app.use(router);
2932
+ return;
2947
2933
  }
2934
+ app.use(router);
2935
+ }
2936
+ function registerErrorHandlers(app) {
2948
2937
  app.use((req, res) => {
2949
2938
  sendJson(res, 404, { error: "Not found", path: req.url ?? "/" });
2950
2939
  });
@@ -2952,6 +2941,8 @@ function createOpenAPIHttpServer(runtime, options = {}) {
2952
2941
  const message = err instanceof Error ? err.message : String(err);
2953
2942
  sendJson(res, 500, { error: message, kind: "INTERNAL_ERROR" });
2954
2943
  });
2944
+ }
2945
+ function patchListenDefaults(app, options) {
2955
2946
  const originalListen = app.listen.bind(app);
2956
2947
  const defaultPort = options.port;
2957
2948
  const defaultHost = options.host;
@@ -2964,6 +2955,18 @@ function createOpenAPIHttpServer(runtime, options = {}) {
2964
2955
  }
2965
2956
  return originalListen(...args);
2966
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);
2967
2970
  return app;
2968
2971
  }
2969
2972
  function listenOpenAPIHttpServer(app, options = {}) {
@@ -3006,5 +3009,5 @@ async function createHttpService(runtimeOrConfig, options = {}) {
3006
3009
  }
3007
3010
 
3008
3011
  export { createHttpService, createMCPServerStreamableHttp, createRuntimeFromConfig, ensurePackageInCache, expandToolDescriptorsToRegistryNames, fileDescriptorToPackagePrefix, findAndLoadToolConfig, getCacheBaseFromToolConfig, getDisplayScope, getPathSourceDescriptors, getToolSourceDescriptors, isBarePackageDescriptor, loadToolConfig, npmDescriptorToPackagePrefix, parseNpmDescriptor, parseToolPath, resolveLatestVersionFromRegistry, resolveSandboxedPath, resolveToolDescriptor, runMCPServerOverStdio, toToolObservationText };
3009
- //# sourceMappingURL=chunk-2MSEJB6X.js.map
3010
- //# sourceMappingURL=chunk-2MSEJB6X.js.map
3012
+ //# sourceMappingURL=chunk-OZUNZILF.js.map
3013
+ //# sourceMappingURL=chunk-OZUNZILF.js.map