agent-tool-hub 1.0.1 → 1.0.2
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/README.md +14 -0
- package/dist/chunk-57LVNNHL.js +19 -0
- package/dist/chunk-57LVNNHL.js.map +1 -0
- package/dist/chunk-6QTWECRD.cjs +23 -0
- package/dist/chunk-6QTWECRD.cjs.map +1 -0
- package/dist/{chunk-2CEY2WAM.js → chunk-HPDQEW2P.js} +214 -233
- package/dist/chunk-HPDQEW2P.js.map +1 -0
- package/dist/{chunk-GD4JXJHB.cjs → chunk-TIKHPRMB.cjs} +216 -238
- package/dist/chunk-TIKHPRMB.cjs.map +1 -0
- package/dist/cli.cjs +194 -0
- package/dist/cli.cjs.map +1 -0
- package/dist/cli.d.cts +10 -0
- package/dist/cli.d.ts +10 -0
- package/dist/cli.js +186 -0
- package/dist/cli.js.map +1 -0
- package/dist/index.cjs +62 -61
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +3 -2
- package/dist/index.js.map +1 -1
- package/dist/toolhub-runtime.cjs +12 -11
- package/dist/toolhub-runtime.js +2 -1
- package/package.json +4 -1
- package/dist/chunk-2CEY2WAM.js.map +0 -1
- package/dist/chunk-GD4JXJHB.cjs.map +0 -1
package/README.md
CHANGED
|
@@ -34,6 +34,20 @@ npm i agent-tool-hub
|
|
|
34
34
|
- Node >= 18
|
|
35
35
|
- Optional peers: `@langchain/core`, `@modelcontextprotocol/sdk`
|
|
36
36
|
|
|
37
|
+
After install, the `agent-tool-hub` CLI is available (or run via `npx agent-tool-hub`):
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
agent-tool-hub <command> [options]
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
| Command | Description |
|
|
44
|
+
| --- | --- |
|
|
45
|
+
| `scan` | Scan configured tool roots and load tools into the hub. |
|
|
46
|
+
| `verify` | Scan and verify tools; exit code 1 if any discovery errors. |
|
|
47
|
+
| `list` | List discovered tools. Use `--detail short \| normal \| full` for output level. |
|
|
48
|
+
|
|
49
|
+
Options: `--config, -c <path>` (default: `./toolhub.yaml`), `--detail, -d <level>` (for `list`), `--help, -h`.
|
|
50
|
+
|
|
37
51
|
### Configure via `toolhub.yaml`
|
|
38
52
|
|
|
39
53
|
Agent Tool Hub is configured by a YAML file. Keep it simple:
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { createToolHub, loadToolHubConfig } from './chunk-HPDQEW2P.js';
|
|
2
|
+
|
|
3
|
+
// src/toolhub-runtime.ts
|
|
4
|
+
async function createToolHubAndInit(options) {
|
|
5
|
+
const hub = createToolHub(options);
|
|
6
|
+
await hub.initAllTools();
|
|
7
|
+
return hub;
|
|
8
|
+
}
|
|
9
|
+
async function createToolHubAndInitFromConfig(configPath) {
|
|
10
|
+
const { options } = await loadToolHubConfig(configPath);
|
|
11
|
+
return createToolHubAndInit(options);
|
|
12
|
+
}
|
|
13
|
+
async function createAgentToolHub(configPath) {
|
|
14
|
+
return createToolHubAndInitFromConfig(configPath);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export { createAgentToolHub, createToolHubAndInit, createToolHubAndInitFromConfig };
|
|
18
|
+
//# sourceMappingURL=chunk-57LVNNHL.js.map
|
|
19
|
+
//# sourceMappingURL=chunk-57LVNNHL.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/toolhub-runtime.ts"],"names":[],"mappings":";;;AAKA,eAAsB,qBACpB,OAAA,EACA;AACA,EAAA,MAAM,GAAA,GAAM,cAAc,OAAO,CAAA;AACjC,EAAA,MAAM,IAAI,YAAA,EAAa;AACvB,EAAA,OAAO,GAAA;AACT;AAEA,eAAsB,+BAA+B,UAAA,EAAoB;AACvE,EAAA,MAAM,EAAE,OAAA,EAAQ,GAAI,MAAM,kBAAkB,UAAU,CAAA;AACtD,EAAA,OAAO,qBAAqB,OAAO,CAAA;AACrC;AAEA,eAAsB,mBAAmB,UAAA,EAAoB;AAC3D,EAAA,OAAO,+BAA+B,UAAU,CAAA;AAClD","file":"chunk-57LVNNHL.js","sourcesContent":["import { ToolHub, createToolHub } from \"./tool-hub/ToolHub.js\";\nimport { loadToolHubConfig } from \"./config/ToolHubConfig.js\";\nexport { ToolHub, createToolHub };\nexport type { ToolHubInitOptions, InvokeOptions } from \"./tool-hub/ToolHub.js\";\n\nexport async function createToolHubAndInit(\n options: import(\"./tool-hub/ToolHub.js\").ToolHubInitOptions,\n) {\n const hub = createToolHub(options);\n await hub.initAllTools();\n return hub;\n}\n\nexport async function createToolHubAndInitFromConfig(configPath: string) {\n const { options } = await loadToolHubConfig(configPath);\n return createToolHubAndInit(options);\n}\n\nexport async function createAgentToolHub(configPath: string) {\n return createToolHubAndInitFromConfig(configPath);\n}\n"]}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkTIKHPRMB_cjs = require('./chunk-TIKHPRMB.cjs');
|
|
4
|
+
|
|
5
|
+
// src/toolhub-runtime.ts
|
|
6
|
+
async function createToolHubAndInit(options) {
|
|
7
|
+
const hub = chunkTIKHPRMB_cjs.createToolHub(options);
|
|
8
|
+
await hub.initAllTools();
|
|
9
|
+
return hub;
|
|
10
|
+
}
|
|
11
|
+
async function createToolHubAndInitFromConfig(configPath) {
|
|
12
|
+
const { options } = await chunkTIKHPRMB_cjs.loadToolHubConfig(configPath);
|
|
13
|
+
return createToolHubAndInit(options);
|
|
14
|
+
}
|
|
15
|
+
async function createAgentToolHub(configPath) {
|
|
16
|
+
return createToolHubAndInitFromConfig(configPath);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
exports.createAgentToolHub = createAgentToolHub;
|
|
20
|
+
exports.createToolHubAndInit = createToolHubAndInit;
|
|
21
|
+
exports.createToolHubAndInitFromConfig = createToolHubAndInitFromConfig;
|
|
22
|
+
//# sourceMappingURL=chunk-6QTWECRD.cjs.map
|
|
23
|
+
//# sourceMappingURL=chunk-6QTWECRD.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/toolhub-runtime.ts"],"names":["createToolHub","loadToolHubConfig"],"mappings":";;;;;AAKA,eAAsB,qBACpB,OAAA,EACA;AACA,EAAA,MAAM,GAAA,GAAMA,gCAAc,OAAO,CAAA;AACjC,EAAA,MAAM,IAAI,YAAA,EAAa;AACvB,EAAA,OAAO,GAAA;AACT;AAEA,eAAsB,+BAA+B,UAAA,EAAoB;AACvE,EAAA,MAAM,EAAE,OAAA,EAAQ,GAAI,MAAMC,oCAAkB,UAAU,CAAA;AACtD,EAAA,OAAO,qBAAqB,OAAO,CAAA;AACrC;AAEA,eAAsB,mBAAmB,UAAA,EAAoB;AAC3D,EAAA,OAAO,+BAA+B,UAAU,CAAA;AAClD","file":"chunk-6QTWECRD.cjs","sourcesContent":["import { ToolHub, createToolHub } from \"./tool-hub/ToolHub.js\";\nimport { loadToolHubConfig } from \"./config/ToolHubConfig.js\";\nexport { ToolHub, createToolHub };\nexport type { ToolHubInitOptions, InvokeOptions } from \"./tool-hub/ToolHub.js\";\n\nexport async function createToolHubAndInit(\n options: import(\"./tool-hub/ToolHub.js\").ToolHubInitOptions,\n) {\n const hub = createToolHub(options);\n await hub.initAllTools();\n return hub;\n}\n\nexport async function createToolHubAndInitFromConfig(configPath: string) {\n const { options } = await loadToolHubConfig(configPath);\n return createToolHubAndInit(options);\n}\n\nexport async function createAgentToolHub(configPath: string) {\n return createToolHubAndInitFromConfig(configPath);\n}\n"]}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { createLogger, sanitizeForLog, summarizeForLog } from './chunk-YSYEED4K.js';
|
|
2
|
-
import {
|
|
2
|
+
import fs, { readdir, readFile, access, realpath, stat, mkdir, writeFile, rm, rmdir, unlink } from 'fs/promises';
|
|
3
|
+
import path, { join, extname, relative, basename, resolve, normalize, dirname } from 'path';
|
|
4
|
+
import yaml from 'js-yaml';
|
|
3
5
|
import Ajv from 'ajv';
|
|
4
6
|
import addFormats from 'ajv-formats';
|
|
5
7
|
import { bulkhead, circuitBreaker, handleAll, ConsecutiveBreaker } from 'cockatiel';
|
|
@@ -7,13 +9,111 @@ import { EventEmitter } from 'eventemitter3';
|
|
|
7
9
|
import { v4 } from 'uuid';
|
|
8
10
|
import pRetry from 'p-retry';
|
|
9
11
|
import pTimeout from 'p-timeout';
|
|
10
|
-
import fs, { readdir, readFile, access, realpath, stat, mkdir, writeFile, rm, rmdir, unlink } from 'fs/promises';
|
|
11
|
-
import path, { join, extname, relative, basename, resolve, normalize, dirname } from 'path';
|
|
12
12
|
import { pathToFileURL } from 'url';
|
|
13
|
+
import { randomUUID, createHash } from 'crypto';
|
|
13
14
|
import { createReadStream, watch } from 'fs';
|
|
14
15
|
import { createInterface } from 'readline';
|
|
15
16
|
import { lookup } from 'dns/promises';
|
|
16
|
-
|
|
17
|
+
|
|
18
|
+
function resolveRoots(rootsRaw, configDir) {
|
|
19
|
+
let coreToolsInlineConfig;
|
|
20
|
+
const roots = rootsRaw.map((root) => {
|
|
21
|
+
if (typeof root === "string") {
|
|
22
|
+
if (root === "coreTools") return root;
|
|
23
|
+
return path.isAbsolute(root) ? root : path.resolve(configDir, root);
|
|
24
|
+
}
|
|
25
|
+
if (root.path === "coreTools") {
|
|
26
|
+
coreToolsInlineConfig = root.config;
|
|
27
|
+
return root;
|
|
28
|
+
}
|
|
29
|
+
const resolvedPath = path.isAbsolute(root.path) ? root.path : path.resolve(configDir, root.path);
|
|
30
|
+
return { path: resolvedPath, namespace: root.namespace };
|
|
31
|
+
});
|
|
32
|
+
return { roots, coreToolsInlineConfig };
|
|
33
|
+
}
|
|
34
|
+
function extractCoreToolsConfig(coreTools, security, system, configDir) {
|
|
35
|
+
const sandboxRoot = coreTools.sandboxRoot ?? coreTools.sandbox?.root ?? security.sandbox?.root ?? system.sandbox?.root;
|
|
36
|
+
const allowedHosts = coreTools.allowedHosts ?? coreTools.network?.allowedHosts ?? security.network?.allowedHosts ?? system.network?.allowedHosts;
|
|
37
|
+
const blockedCidrs = coreTools.blockedCidrs ?? coreTools.network?.blockedCidrs ?? security.network?.blockedCidrs ?? system.network?.blockedCidrs;
|
|
38
|
+
const maxReadBytes = coreTools.maxReadBytes ?? coreTools.limits?.maxReadBytes;
|
|
39
|
+
const maxHttpBytes = coreTools.maxHttpBytes ?? coreTools.limits?.maxHttpBytes;
|
|
40
|
+
const maxDownloadBytes = coreTools.maxDownloadBytes ?? coreTools.limits?.maxDownloadBytes;
|
|
41
|
+
const defaultTimeoutMs = coreTools.defaultTimeoutMs ?? coreTools.limits?.defaultTimeoutMs;
|
|
42
|
+
const httpUserAgent = coreTools.httpUserAgent ?? coreTools.http?.userAgent;
|
|
43
|
+
const enableAutoWriteLargeResponses = coreTools.enableAutoWriteLargeResponses ?? coreTools.http?.enableAutoWriteLargeResponses;
|
|
44
|
+
return {
|
|
45
|
+
sandboxRoot: sandboxRoot ? path.isAbsolute(String(sandboxRoot)) ? String(sandboxRoot) : path.resolve(configDir, String(sandboxRoot)) : sandboxRoot,
|
|
46
|
+
allowedHosts: allowedHosts ?? [],
|
|
47
|
+
maxReadBytes,
|
|
48
|
+
maxHttpBytes,
|
|
49
|
+
maxDownloadBytes,
|
|
50
|
+
blockedCidrs,
|
|
51
|
+
defaultTimeoutMs,
|
|
52
|
+
httpUserAgent,
|
|
53
|
+
enableAutoWriteLargeResponses
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
function extractAdapterConfigs(adapters) {
|
|
57
|
+
const comfyuiRaw = adapters.comfyui ?? {};
|
|
58
|
+
const comfyuiConfig = Object.keys(comfyuiRaw).length > 0 ? {
|
|
59
|
+
...comfyuiRaw,
|
|
60
|
+
baseUrl: comfyuiRaw.baseUrl ?? comfyuiRaw.apiBaseUrl
|
|
61
|
+
} : void 0;
|
|
62
|
+
const n8nRaw = adapters.n8n ?? {};
|
|
63
|
+
const n8nMode = n8nRaw.mode ?? (n8nRaw.local ? "local" : void 0) ?? (n8nRaw.api ? "api" : void 0);
|
|
64
|
+
const n8nLocal = n8nRaw.local ?? void 0;
|
|
65
|
+
const n8nApi = n8nRaw.api ?? void 0;
|
|
66
|
+
return {
|
|
67
|
+
langchain: adapters.langchain,
|
|
68
|
+
mcp: adapters.mcp,
|
|
69
|
+
n8nMode,
|
|
70
|
+
n8nLocal: n8nMode === "local" ? n8nLocal : void 0,
|
|
71
|
+
n8n: n8nMode === "api" ? n8nApi : void 0,
|
|
72
|
+
comfyui: comfyuiConfig,
|
|
73
|
+
skill: adapters.skill
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
function mapToolHubConfig(raw, configDir) {
|
|
77
|
+
const config = raw ?? {};
|
|
78
|
+
const toolHub = config.toolHub ?? {};
|
|
79
|
+
const discovery = config.discovery ?? toolHub.discovery ?? {};
|
|
80
|
+
const system = config.system ?? {};
|
|
81
|
+
const security = config.security ?? {};
|
|
82
|
+
const runtime = system.runtime ?? config.runtime ?? {};
|
|
83
|
+
const coreToolsRaw = system.coreTools ?? config.coreTools ?? {};
|
|
84
|
+
const adapters = config.adapters ?? {};
|
|
85
|
+
const rootsRaw = discovery.roots ?? toolHub.roots ?? [];
|
|
86
|
+
const { roots, coreToolsInlineConfig } = resolveRoots(rootsRaw, configDir);
|
|
87
|
+
const coreTools = coreToolsInlineConfig ?? coreToolsRaw ?? {};
|
|
88
|
+
const includeCoreTools = roots.some((root) => {
|
|
89
|
+
if (typeof root === "string") return root === "coreTools";
|
|
90
|
+
return root.path === "coreTools";
|
|
91
|
+
});
|
|
92
|
+
const coreToolsConfig = includeCoreTools ? extractCoreToolsConfig(coreTools, security, system, configDir) : void 0;
|
|
93
|
+
const adapterConfigs = extractAdapterConfigs(adapters);
|
|
94
|
+
return {
|
|
95
|
+
roots,
|
|
96
|
+
namespace: config.namespace ?? toolHub.namespace,
|
|
97
|
+
extensions: discovery.extensions ?? config.extensions ?? toolHub.extensions,
|
|
98
|
+
debug: config.debug ?? toolHub.debug,
|
|
99
|
+
includeCoreTools,
|
|
100
|
+
coreTools: coreToolsConfig,
|
|
101
|
+
runtimeConfig: runtime,
|
|
102
|
+
watch: discovery.hotReload ?? discovery.watch ?? config.watch ?? toolHub.watch,
|
|
103
|
+
...adapterConfigs
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
async function loadToolHubConfig(configPath) {
|
|
107
|
+
const resolvedPath = path.resolve(process.cwd(), configPath);
|
|
108
|
+
const rawConfigText = await fs.readFile(resolvedPath, "utf-8");
|
|
109
|
+
const rawConfig = yaml.load(rawConfigText) ?? {};
|
|
110
|
+
const options = mapToolHubConfig(rawConfig, path.dirname(resolvedPath));
|
|
111
|
+
return {
|
|
112
|
+
configPath: resolvedPath,
|
|
113
|
+
rawConfig,
|
|
114
|
+
options
|
|
115
|
+
};
|
|
116
|
+
}
|
|
17
117
|
|
|
18
118
|
// src/registry/ToolRegistry.ts
|
|
19
119
|
var ToolRegistry = class {
|
|
@@ -1396,114 +1496,6 @@ var DiscoveryError = class extends Error {
|
|
|
1396
1496
|
this.cause = cause;
|
|
1397
1497
|
}
|
|
1398
1498
|
};
|
|
1399
|
-
function isCursorFormat(obj) {
|
|
1400
|
-
return typeof obj === "object" && obj !== null && "mcpServers" in obj && typeof obj.mcpServers === "object" && obj.mcpServers !== null;
|
|
1401
|
-
}
|
|
1402
|
-
function extractMCPConfig(parsed, toolName) {
|
|
1403
|
-
if (isCursorFormat(parsed)) {
|
|
1404
|
-
const servers = parsed.mcpServers;
|
|
1405
|
-
const keys = Object.keys(servers);
|
|
1406
|
-
if (keys.length === 0) {
|
|
1407
|
-
return {};
|
|
1408
|
-
}
|
|
1409
|
-
const name = toolName && keys.includes(toolName) ? toolName : keys[0];
|
|
1410
|
-
return servers[name];
|
|
1411
|
-
}
|
|
1412
|
-
return parsed;
|
|
1413
|
-
}
|
|
1414
|
-
async function loadMCPTool(dirPath, manifest) {
|
|
1415
|
-
const mcpPath = join(dirPath, manifest.entryPoint ?? "mcp.json");
|
|
1416
|
-
let raw;
|
|
1417
|
-
try {
|
|
1418
|
-
raw = await readFile(mcpPath, "utf-8");
|
|
1419
|
-
} catch (err) {
|
|
1420
|
-
throw new DiscoveryError(
|
|
1421
|
-
dirPath,
|
|
1422
|
-
"load",
|
|
1423
|
-
`Failed to read MCP config: ${mcpPath}`,
|
|
1424
|
-
err
|
|
1425
|
-
);
|
|
1426
|
-
}
|
|
1427
|
-
let parsed;
|
|
1428
|
-
try {
|
|
1429
|
-
parsed = JSON.parse(raw);
|
|
1430
|
-
} catch (err) {
|
|
1431
|
-
throw new DiscoveryError(
|
|
1432
|
-
dirPath,
|
|
1433
|
-
"load",
|
|
1434
|
-
`Invalid JSON in ${mcpPath}`,
|
|
1435
|
-
err
|
|
1436
|
-
);
|
|
1437
|
-
}
|
|
1438
|
-
const baseName = manifest.name?.split("/").pop();
|
|
1439
|
-
const config = extractMCPConfig(parsed, baseName);
|
|
1440
|
-
if (!config.command && !config.url) {
|
|
1441
|
-
throw new DiscoveryError(
|
|
1442
|
-
dirPath,
|
|
1443
|
-
"validate",
|
|
1444
|
-
`mcp.json must have either "command" or "url" field`
|
|
1445
|
-
);
|
|
1446
|
-
}
|
|
1447
|
-
return { manifest, dirPath, mcpConfig: config };
|
|
1448
|
-
}
|
|
1449
|
-
var DEFAULT_EXTENSIONS = [".js", ".mjs"];
|
|
1450
|
-
async function resolveEntryPoint(dirPath, baseName, extensions = DEFAULT_EXTENSIONS) {
|
|
1451
|
-
if (extensions.some((ext) => baseName.endsWith(ext))) {
|
|
1452
|
-
const fullPath = join(dirPath, baseName);
|
|
1453
|
-
await stat(fullPath);
|
|
1454
|
-
return fullPath;
|
|
1455
|
-
}
|
|
1456
|
-
for (const ext of extensions) {
|
|
1457
|
-
const fullPath = join(dirPath, `${baseName}${ext}`);
|
|
1458
|
-
try {
|
|
1459
|
-
await stat(fullPath);
|
|
1460
|
-
return fullPath;
|
|
1461
|
-
} catch {
|
|
1462
|
-
}
|
|
1463
|
-
}
|
|
1464
|
-
throw new Error(
|
|
1465
|
-
`Could not find entry point in ${dirPath}. Tried: ${extensions.map((e) => baseName + e).join(", ")}`
|
|
1466
|
-
);
|
|
1467
|
-
}
|
|
1468
|
-
|
|
1469
|
-
// src/discovery/loaders/LangChainLoader.ts
|
|
1470
|
-
async function loadLangChainTool(dirPath, manifest, extensions) {
|
|
1471
|
-
let entryFile;
|
|
1472
|
-
try {
|
|
1473
|
-
entryFile = await resolveEntryPoint(
|
|
1474
|
-
dirPath,
|
|
1475
|
-
manifest.entryPoint ?? "index",
|
|
1476
|
-
extensions
|
|
1477
|
-
);
|
|
1478
|
-
} catch (err) {
|
|
1479
|
-
throw new DiscoveryError(
|
|
1480
|
-
dirPath,
|
|
1481
|
-
"load",
|
|
1482
|
-
`Cannot find LangChain entry point`,
|
|
1483
|
-
err
|
|
1484
|
-
);
|
|
1485
|
-
}
|
|
1486
|
-
let mod;
|
|
1487
|
-
try {
|
|
1488
|
-
mod = await import(pathToFileURL(entryFile).href);
|
|
1489
|
-
} catch (err) {
|
|
1490
|
-
throw new DiscoveryError(
|
|
1491
|
-
dirPath,
|
|
1492
|
-
"load",
|
|
1493
|
-
`Failed to import ${entryFile}`,
|
|
1494
|
-
err
|
|
1495
|
-
);
|
|
1496
|
-
}
|
|
1497
|
-
const tool = mod.default ?? mod.tool ?? mod;
|
|
1498
|
-
if (!tool || typeof tool.invoke !== "function") {
|
|
1499
|
-
throw new DiscoveryError(
|
|
1500
|
-
dirPath,
|
|
1501
|
-
"validate",
|
|
1502
|
-
`Entry point must export an object with invoke() method (LangChainToolLike)`
|
|
1503
|
-
);
|
|
1504
|
-
}
|
|
1505
|
-
return { manifest, dirPath, impl: tool };
|
|
1506
|
-
}
|
|
1507
1499
|
|
|
1508
1500
|
// src/discovery/loaders/SkillManifest.ts
|
|
1509
1501
|
var SkillManifestError = class extends Error {
|
|
@@ -1571,8 +1563,6 @@ function validateFrontmatter(fm, filePath) {
|
|
|
1571
1563
|
);
|
|
1572
1564
|
}
|
|
1573
1565
|
}
|
|
1574
|
-
|
|
1575
|
-
// src/discovery/loaders/SkillMdParser.ts
|
|
1576
1566
|
var CODE_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
1577
1567
|
".py",
|
|
1578
1568
|
".js",
|
|
@@ -1736,8 +1726,114 @@ async function loadSkillDefinition(dirPath) {
|
|
|
1736
1726
|
skillMdPath
|
|
1737
1727
|
};
|
|
1738
1728
|
}
|
|
1729
|
+
function isCursorFormat(obj) {
|
|
1730
|
+
return typeof obj === "object" && obj !== null && "mcpServers" in obj && typeof obj.mcpServers === "object" && obj.mcpServers !== null;
|
|
1731
|
+
}
|
|
1732
|
+
function extractMCPConfig(parsed, toolName) {
|
|
1733
|
+
if (isCursorFormat(parsed)) {
|
|
1734
|
+
const servers = parsed.mcpServers;
|
|
1735
|
+
const keys = Object.keys(servers);
|
|
1736
|
+
if (keys.length === 0) {
|
|
1737
|
+
return {};
|
|
1738
|
+
}
|
|
1739
|
+
const name = toolName && keys.includes(toolName) ? toolName : keys[0];
|
|
1740
|
+
return servers[name];
|
|
1741
|
+
}
|
|
1742
|
+
return parsed;
|
|
1743
|
+
}
|
|
1744
|
+
async function loadMCPTool(dirPath, manifest) {
|
|
1745
|
+
const mcpPath = join(dirPath, manifest.entryPoint ?? "mcp.json");
|
|
1746
|
+
let raw;
|
|
1747
|
+
try {
|
|
1748
|
+
raw = await readFile(mcpPath, "utf-8");
|
|
1749
|
+
} catch (err) {
|
|
1750
|
+
throw new DiscoveryError(
|
|
1751
|
+
dirPath,
|
|
1752
|
+
"load",
|
|
1753
|
+
`Failed to read MCP config: ${mcpPath}`,
|
|
1754
|
+
err
|
|
1755
|
+
);
|
|
1756
|
+
}
|
|
1757
|
+
let parsed;
|
|
1758
|
+
try {
|
|
1759
|
+
parsed = JSON.parse(raw);
|
|
1760
|
+
} catch (err) {
|
|
1761
|
+
throw new DiscoveryError(
|
|
1762
|
+
dirPath,
|
|
1763
|
+
"load",
|
|
1764
|
+
`Invalid JSON in ${mcpPath}`,
|
|
1765
|
+
err
|
|
1766
|
+
);
|
|
1767
|
+
}
|
|
1768
|
+
const baseName = manifest.name?.split("/").pop();
|
|
1769
|
+
const config = extractMCPConfig(parsed, baseName);
|
|
1770
|
+
if (!config.command && !config.url) {
|
|
1771
|
+
throw new DiscoveryError(
|
|
1772
|
+
dirPath,
|
|
1773
|
+
"validate",
|
|
1774
|
+
`mcp.json must have either "command" or "url" field`
|
|
1775
|
+
);
|
|
1776
|
+
}
|
|
1777
|
+
return { manifest, dirPath, mcpConfig: config };
|
|
1778
|
+
}
|
|
1779
|
+
var DEFAULT_EXTENSIONS = [".js", ".mjs"];
|
|
1780
|
+
async function resolveEntryPoint(dirPath, baseName, extensions = DEFAULT_EXTENSIONS) {
|
|
1781
|
+
if (extensions.some((ext) => baseName.endsWith(ext))) {
|
|
1782
|
+
const fullPath = join(dirPath, baseName);
|
|
1783
|
+
await stat(fullPath);
|
|
1784
|
+
return fullPath;
|
|
1785
|
+
}
|
|
1786
|
+
for (const ext of extensions) {
|
|
1787
|
+
const fullPath = join(dirPath, `${baseName}${ext}`);
|
|
1788
|
+
try {
|
|
1789
|
+
await stat(fullPath);
|
|
1790
|
+
return fullPath;
|
|
1791
|
+
} catch {
|
|
1792
|
+
}
|
|
1793
|
+
}
|
|
1794
|
+
throw new Error(
|
|
1795
|
+
`Could not find entry point in ${dirPath}. Tried: ${extensions.map((e) => baseName + e).join(", ")}`
|
|
1796
|
+
);
|
|
1797
|
+
}
|
|
1739
1798
|
|
|
1740
|
-
// src/discovery/loaders/
|
|
1799
|
+
// src/discovery/loaders/LangChainLoader.ts
|
|
1800
|
+
async function loadLangChainTool(dirPath, manifest, extensions) {
|
|
1801
|
+
let entryFile;
|
|
1802
|
+
try {
|
|
1803
|
+
entryFile = await resolveEntryPoint(
|
|
1804
|
+
dirPath,
|
|
1805
|
+
manifest.entryPoint ?? "index",
|
|
1806
|
+
extensions
|
|
1807
|
+
);
|
|
1808
|
+
} catch (err) {
|
|
1809
|
+
throw new DiscoveryError(
|
|
1810
|
+
dirPath,
|
|
1811
|
+
"load",
|
|
1812
|
+
`Cannot find LangChain entry point`,
|
|
1813
|
+
err
|
|
1814
|
+
);
|
|
1815
|
+
}
|
|
1816
|
+
let mod;
|
|
1817
|
+
try {
|
|
1818
|
+
mod = await import(pathToFileURL(entryFile).href);
|
|
1819
|
+
} catch (err) {
|
|
1820
|
+
throw new DiscoveryError(
|
|
1821
|
+
dirPath,
|
|
1822
|
+
"load",
|
|
1823
|
+
`Failed to import ${entryFile}`,
|
|
1824
|
+
err
|
|
1825
|
+
);
|
|
1826
|
+
}
|
|
1827
|
+
const tool = mod.default ?? mod.tool ?? mod;
|
|
1828
|
+
if (!tool || typeof tool.invoke !== "function") {
|
|
1829
|
+
throw new DiscoveryError(
|
|
1830
|
+
dirPath,
|
|
1831
|
+
"validate",
|
|
1832
|
+
`Entry point must export an object with invoke() method (LangChainToolLike)`
|
|
1833
|
+
);
|
|
1834
|
+
}
|
|
1835
|
+
return { manifest, dirPath, impl: tool };
|
|
1836
|
+
}
|
|
1741
1837
|
async function loadSkillTool(dirPath, manifest, extensions) {
|
|
1742
1838
|
let skillDef;
|
|
1743
1839
|
try {
|
|
@@ -3069,8 +3165,6 @@ function isWithinRoot(path2, root) {
|
|
|
3069
3165
|
const normalizedRoot = normalize(root);
|
|
3070
3166
|
return normalizedPath === normalizedRoot || normalizedPath.startsWith(normalizedRoot + "/");
|
|
3071
3167
|
}
|
|
3072
|
-
|
|
3073
|
-
// src/core-tools/fs/readText.ts
|
|
3074
3168
|
var readTextInputSchema = {
|
|
3075
3169
|
type: "object",
|
|
3076
3170
|
properties: {
|
|
@@ -5151,120 +5245,7 @@ var ToolHub = class {
|
|
|
5151
5245
|
function createToolHub(options) {
|
|
5152
5246
|
return new ToolHub(options);
|
|
5153
5247
|
}
|
|
5154
|
-
function resolveRoots(rootsRaw, configDir) {
|
|
5155
|
-
let coreToolsInlineConfig;
|
|
5156
|
-
const roots = rootsRaw.map((root) => {
|
|
5157
|
-
if (typeof root === "string") {
|
|
5158
|
-
if (root === "coreTools") return root;
|
|
5159
|
-
return path.isAbsolute(root) ? root : path.resolve(configDir, root);
|
|
5160
|
-
}
|
|
5161
|
-
if (root.path === "coreTools") {
|
|
5162
|
-
coreToolsInlineConfig = root.config;
|
|
5163
|
-
return root;
|
|
5164
|
-
}
|
|
5165
|
-
const resolvedPath = path.isAbsolute(root.path) ? root.path : path.resolve(configDir, root.path);
|
|
5166
|
-
return { path: resolvedPath, namespace: root.namespace };
|
|
5167
|
-
});
|
|
5168
|
-
return { roots, coreToolsInlineConfig };
|
|
5169
|
-
}
|
|
5170
|
-
function extractCoreToolsConfig(coreTools, security, system, configDir) {
|
|
5171
|
-
const sandboxRoot = coreTools.sandboxRoot ?? coreTools.sandbox?.root ?? security.sandbox?.root ?? system.sandbox?.root;
|
|
5172
|
-
const allowedHosts = coreTools.allowedHosts ?? coreTools.network?.allowedHosts ?? security.network?.allowedHosts ?? system.network?.allowedHosts;
|
|
5173
|
-
const blockedCidrs = coreTools.blockedCidrs ?? coreTools.network?.blockedCidrs ?? security.network?.blockedCidrs ?? system.network?.blockedCidrs;
|
|
5174
|
-
const maxReadBytes = coreTools.maxReadBytes ?? coreTools.limits?.maxReadBytes;
|
|
5175
|
-
const maxHttpBytes = coreTools.maxHttpBytes ?? coreTools.limits?.maxHttpBytes;
|
|
5176
|
-
const maxDownloadBytes = coreTools.maxDownloadBytes ?? coreTools.limits?.maxDownloadBytes;
|
|
5177
|
-
const defaultTimeoutMs = coreTools.defaultTimeoutMs ?? coreTools.limits?.defaultTimeoutMs;
|
|
5178
|
-
const httpUserAgent = coreTools.httpUserAgent ?? coreTools.http?.userAgent;
|
|
5179
|
-
const enableAutoWriteLargeResponses = coreTools.enableAutoWriteLargeResponses ?? coreTools.http?.enableAutoWriteLargeResponses;
|
|
5180
|
-
return {
|
|
5181
|
-
sandboxRoot: sandboxRoot ? path.isAbsolute(String(sandboxRoot)) ? String(sandboxRoot) : path.resolve(configDir, String(sandboxRoot)) : sandboxRoot,
|
|
5182
|
-
allowedHosts: allowedHosts ?? [],
|
|
5183
|
-
maxReadBytes,
|
|
5184
|
-
maxHttpBytes,
|
|
5185
|
-
maxDownloadBytes,
|
|
5186
|
-
blockedCidrs,
|
|
5187
|
-
defaultTimeoutMs,
|
|
5188
|
-
httpUserAgent,
|
|
5189
|
-
enableAutoWriteLargeResponses
|
|
5190
|
-
};
|
|
5191
|
-
}
|
|
5192
|
-
function extractAdapterConfigs(adapters) {
|
|
5193
|
-
const comfyuiRaw = adapters.comfyui ?? {};
|
|
5194
|
-
const comfyuiConfig = Object.keys(comfyuiRaw).length > 0 ? {
|
|
5195
|
-
...comfyuiRaw,
|
|
5196
|
-
baseUrl: comfyuiRaw.baseUrl ?? comfyuiRaw.apiBaseUrl
|
|
5197
|
-
} : void 0;
|
|
5198
|
-
const n8nRaw = adapters.n8n ?? {};
|
|
5199
|
-
const n8nMode = n8nRaw.mode ?? (n8nRaw.local ? "local" : void 0) ?? (n8nRaw.api ? "api" : void 0);
|
|
5200
|
-
const n8nLocal = n8nRaw.local ?? void 0;
|
|
5201
|
-
const n8nApi = n8nRaw.api ?? void 0;
|
|
5202
|
-
return {
|
|
5203
|
-
langchain: adapters.langchain,
|
|
5204
|
-
mcp: adapters.mcp,
|
|
5205
|
-
n8nMode,
|
|
5206
|
-
n8nLocal: n8nMode === "local" ? n8nLocal : void 0,
|
|
5207
|
-
n8n: n8nMode === "api" ? n8nApi : void 0,
|
|
5208
|
-
comfyui: comfyuiConfig,
|
|
5209
|
-
skill: adapters.skill
|
|
5210
|
-
};
|
|
5211
|
-
}
|
|
5212
|
-
function mapToolHubConfig(raw, configDir) {
|
|
5213
|
-
const config = raw ?? {};
|
|
5214
|
-
const toolHub = config.toolHub ?? {};
|
|
5215
|
-
const discovery = config.discovery ?? toolHub.discovery ?? {};
|
|
5216
|
-
const system = config.system ?? {};
|
|
5217
|
-
const security = config.security ?? {};
|
|
5218
|
-
const runtime = system.runtime ?? config.runtime ?? {};
|
|
5219
|
-
const coreToolsRaw = system.coreTools ?? config.coreTools ?? {};
|
|
5220
|
-
const adapters = config.adapters ?? {};
|
|
5221
|
-
const rootsRaw = discovery.roots ?? toolHub.roots ?? [];
|
|
5222
|
-
const { roots, coreToolsInlineConfig } = resolveRoots(rootsRaw, configDir);
|
|
5223
|
-
const coreTools = coreToolsInlineConfig ?? coreToolsRaw ?? {};
|
|
5224
|
-
const includeCoreTools = roots.some((root) => {
|
|
5225
|
-
if (typeof root === "string") return root === "coreTools";
|
|
5226
|
-
return root.path === "coreTools";
|
|
5227
|
-
});
|
|
5228
|
-
const coreToolsConfig = includeCoreTools ? extractCoreToolsConfig(coreTools, security, system, configDir) : void 0;
|
|
5229
|
-
const adapterConfigs = extractAdapterConfigs(adapters);
|
|
5230
|
-
return {
|
|
5231
|
-
roots,
|
|
5232
|
-
namespace: config.namespace ?? toolHub.namespace,
|
|
5233
|
-
extensions: discovery.extensions ?? config.extensions ?? toolHub.extensions,
|
|
5234
|
-
debug: config.debug ?? toolHub.debug,
|
|
5235
|
-
includeCoreTools,
|
|
5236
|
-
coreTools: coreToolsConfig,
|
|
5237
|
-
runtimeConfig: runtime,
|
|
5238
|
-
watch: discovery.hotReload ?? discovery.watch ?? config.watch ?? toolHub.watch,
|
|
5239
|
-
...adapterConfigs
|
|
5240
|
-
};
|
|
5241
|
-
}
|
|
5242
|
-
async function loadToolHubConfig(configPath) {
|
|
5243
|
-
const resolvedPath = path.resolve(process.cwd(), configPath);
|
|
5244
|
-
const rawConfigText = await fs.readFile(resolvedPath, "utf-8");
|
|
5245
|
-
const rawConfig = yaml.load(rawConfigText) ?? {};
|
|
5246
|
-
const options = mapToolHubConfig(rawConfig, path.dirname(resolvedPath));
|
|
5247
|
-
return {
|
|
5248
|
-
configPath: resolvedPath,
|
|
5249
|
-
rawConfig,
|
|
5250
|
-
options
|
|
5251
|
-
};
|
|
5252
|
-
}
|
|
5253
|
-
|
|
5254
|
-
// src/toolhub-runtime.ts
|
|
5255
|
-
async function createToolHubAndInit(options) {
|
|
5256
|
-
const hub = createToolHub(options);
|
|
5257
|
-
await hub.initAllTools();
|
|
5258
|
-
return hub;
|
|
5259
|
-
}
|
|
5260
|
-
async function createToolHubAndInitFromConfig(configPath) {
|
|
5261
|
-
const { options } = await loadToolHubConfig(configPath);
|
|
5262
|
-
return createToolHubAndInit(options);
|
|
5263
|
-
}
|
|
5264
|
-
async function createAgentToolHub(configPath) {
|
|
5265
|
-
return createToolHubAndInitFromConfig(configPath);
|
|
5266
|
-
}
|
|
5267
5248
|
|
|
5268
|
-
export { BudgetManager, ComfyUIAdapter, CoreAdapter, DEFAULT_CORE_TOOLS_CONFIG, DirectoryScanner, DiscoveryError, EventLog, LangChainAdapter, MCPAdapter, Metrics, N8nAdapter, PTCRuntime, PolicyDeniedError, PolicyEngine, SchemaValidationError, SchemaValidator, SkillAdapter, SkillManifestError, ToolHub, ToolRegistry, Tracing, buildEvidence,
|
|
5269
|
-
//# sourceMappingURL=chunk-
|
|
5270
|
-
//# sourceMappingURL=chunk-
|
|
5249
|
+
export { BudgetManager, ComfyUIAdapter, CoreAdapter, DEFAULT_CORE_TOOLS_CONFIG, DirectoryScanner, DiscoveryError, EventLog, LangChainAdapter, MCPAdapter, Metrics, N8nAdapter, PTCRuntime, PolicyDeniedError, PolicyEngine, SchemaValidationError, SchemaValidator, SkillAdapter, SkillManifestError, ToolHub, ToolRegistry, Tracing, buildEvidence, createTaggedError, createToolHub, deletePathSpec, downloadFileSpec, fetchJsonSpec, fetchTextSpec, hashTextSpec, headSpec, isIpInBlockedCidrs, isRetryable, jsonSelectSpec, listDirSpec, loadSkillDefinition, loadToolHubConfig, mapToolHubConfig, nowSpec, parseSkillMd, readTextSpec, registerCoreTools, resolveSandboxedPath, scanSkillResources, searchTextSpec, sha256Spec, templateRenderSpec, truncateSpec, validateFrontmatter, validateUrl, withRetry, writeTextSpec };
|
|
5250
|
+
//# sourceMappingURL=chunk-HPDQEW2P.js.map
|
|
5251
|
+
//# sourceMappingURL=chunk-HPDQEW2P.js.map
|