@easynet/agent-tool 1.0.46 → 1.0.48
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 +31 -105
- package/dist/api/extension/groupPrefix.d.ts.map +1 -1
- package/dist/api/main.cjs +19 -20
- package/dist/api/main.js +2 -3
- package/dist/api/runtimeFromConfig.d.ts.map +1 -1
- package/dist/{chunk-5GFSI7ZJ.js → chunk-2ZPDD7ZO.js} +722 -280
- package/dist/chunk-2ZPDD7ZO.js.map +1 -0
- package/dist/{chunk-SRTE2OUH.js → chunk-64ZQQV5C.js} +79 -75
- package/dist/chunk-64ZQQV5C.js.map +1 -0
- package/dist/{chunk-XC7KPJLZ.cjs → chunk-A5B6Q6EG.cjs} +710 -295
- package/dist/chunk-A5B6Q6EG.cjs.map +1 -0
- package/dist/{chunk-QW27JAFS.cjs → chunk-IAEVDXWS.cjs} +15 -16
- package/dist/chunk-IAEVDXWS.cjs.map +1 -0
- package/dist/{chunk-H66TKSG4.js → chunk-KYBIKD5R.js} +5 -5
- package/dist/chunk-KYBIKD5R.js.map +1 -0
- package/dist/{chunk-LG5K7WOK.cjs → chunk-MDPU7EIO.cjs} +83 -87
- package/dist/chunk-MDPU7EIO.cjs.map +1 -0
- package/dist/index.cjs +195 -413
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +16 -63
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +171 -281
- package/dist/index.js.map +1 -1
- package/dist/utils/cli/index.cjs +16 -17
- package/dist/utils/cli/index.cjs.map +1 -1
- package/dist/utils/cli/index.js +3 -4
- package/dist/utils/cli/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-5GFSI7ZJ.js.map +0 -1
- package/dist/chunk-H66TKSG4.js.map +0 -1
- package/dist/chunk-LG5K7WOK.cjs.map +0 -1
- package/dist/chunk-O4XXNLNE.cjs +0 -480
- package/dist/chunk-O4XXNLNE.cjs.map +0 -1
- package/dist/chunk-QW27JAFS.cjs.map +0 -1
- package/dist/chunk-SRTE2OUH.js.map +0 -1
- package/dist/chunk-XC7KPJLZ.cjs.map +0 -1
- package/dist/chunk-YDYG4HF5.js +0 -474
- package/dist/chunk-YDYG4HF5.js.map +0 -1
|
@@ -2,18 +2,20 @@
|
|
|
2
2
|
|
|
3
3
|
var chunkTOSPHMYU_cjs = require('./chunk-TOSPHMYU.cjs');
|
|
4
4
|
var chunkDYDNPIV2_cjs = require('./chunk-DYDNPIV2.cjs');
|
|
5
|
+
var chunkUUNG3GL3_cjs = require('./chunk-UUNG3GL3.cjs');
|
|
6
|
+
var fs = require('fs');
|
|
7
|
+
var path = require('path');
|
|
8
|
+
var agentCommon = require('@easynet/agent-common');
|
|
5
9
|
var Ajv = require('ajv');
|
|
6
10
|
var addFormats = require('ajv-formats');
|
|
7
11
|
var cockatiel = require('cockatiel');
|
|
8
12
|
var eventemitter3 = require('eventemitter3');
|
|
9
13
|
var uuid = require('uuid');
|
|
10
14
|
var pTimeout = require('p-timeout');
|
|
11
|
-
var path = require('path');
|
|
12
15
|
var promises = require('fs/promises');
|
|
13
|
-
var fs = require('fs');
|
|
14
|
-
var agentCommon = require('@easynet/agent-common');
|
|
15
|
-
var npm = require('@easynet/agent-common/npm');
|
|
16
16
|
var module$1 = require('module');
|
|
17
|
+
var npm = require('@easynet/agent-common/npm');
|
|
18
|
+
var http = require('http');
|
|
17
19
|
|
|
18
20
|
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
19
21
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
@@ -22,6 +24,229 @@ var Ajv__default = /*#__PURE__*/_interopDefault(Ajv);
|
|
|
22
24
|
var addFormats__default = /*#__PURE__*/_interopDefault(addFormats);
|
|
23
25
|
var pTimeout__default = /*#__PURE__*/_interopDefault(pTimeout);
|
|
24
26
|
|
|
27
|
+
function loadToolConfig(toolYamlPath) {
|
|
28
|
+
const abs = path.resolve(toolYamlPath);
|
|
29
|
+
const raw = fs.readFileSync(abs, "utf8");
|
|
30
|
+
const parsed = agentCommon.parseYamlContent(raw, {
|
|
31
|
+
substituteEnv: false
|
|
32
|
+
});
|
|
33
|
+
if (!parsed || typeof parsed !== "object") return {};
|
|
34
|
+
const toolsBlock = parsed.tools;
|
|
35
|
+
if (toolsBlock != null && typeof toolsBlock === "object" && !Array.isArray(toolsBlock)) {
|
|
36
|
+
const toolDefaults = toolsBlock.defaults != null && typeof toolsBlock.defaults === "object" && !Array.isArray(toolsBlock.defaults) ? toolsBlock.defaults : void 0;
|
|
37
|
+
const packageToolDefaults2 = toolsBlock.packages != null && typeof toolsBlock.packages === "object" && !Array.isArray(toolsBlock.packages) ? toolsBlock.packages : void 0;
|
|
38
|
+
const list2 = Array.isArray(toolsBlock.list) && toolsBlock.list.length > 0 ? toolsBlock.list : void 0;
|
|
39
|
+
return {
|
|
40
|
+
tools: list2 ?? (packageToolDefaults2 ? Object.keys(packageToolDefaults2) : void 0),
|
|
41
|
+
sandboxedPath: typeof toolsBlock.sandboxedPath === "string" ? toolsBlock.sandboxedPath : parsed.sandboxedPath,
|
|
42
|
+
enableSandboxValidation: typeof toolsBlock.enableSandboxValidation === "boolean" ? toolsBlock.enableSandboxValidation : parsed.enableSandboxValidation,
|
|
43
|
+
allowedHosts: Array.isArray(toolsBlock.allowedHosts) ? toolsBlock.allowedHosts : parsed.allowedHosts,
|
|
44
|
+
blockedHosts: Array.isArray(toolsBlock.blockedHosts) ? toolsBlock.blockedHosts : parsed.blockedHosts,
|
|
45
|
+
blockedCidrs: Array.isArray(toolsBlock.blockedCidrs) ? toolsBlock.blockedCidrs : parsed.blockedCidrs,
|
|
46
|
+
toolDefaults,
|
|
47
|
+
packageToolDefaults: packageToolDefaults2
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
const packageToolDefaults = typeof parsed.packageToolDefaults === "object" && !Array.isArray(parsed.packageToolDefaults) ? parsed.packageToolDefaults : void 0;
|
|
51
|
+
const list = Array.isArray(parsed.tools) && parsed.tools.length > 0 ? parsed.tools : void 0;
|
|
52
|
+
return {
|
|
53
|
+
tools: list ?? (packageToolDefaults ? Object.keys(packageToolDefaults) : void 0),
|
|
54
|
+
sandboxedPath: parsed.sandboxedPath,
|
|
55
|
+
enableSandboxValidation: typeof parsed.enableSandboxValidation === "boolean" ? parsed.enableSandboxValidation : void 0,
|
|
56
|
+
allowedHosts: Array.isArray(parsed.allowedHosts) ? parsed.allowedHosts : void 0,
|
|
57
|
+
blockedHosts: Array.isArray(parsed.blockedHosts) ? parsed.blockedHosts : void 0,
|
|
58
|
+
blockedCidrs: Array.isArray(parsed.blockedCidrs) ? parsed.blockedCidrs : void 0,
|
|
59
|
+
toolDefaults: typeof parsed.toolDefaults === "object" && !Array.isArray(parsed.toolDefaults) ? parsed.toolDefaults : void 0,
|
|
60
|
+
packageToolDefaults
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
function resolveSandboxedPath(toolYamlPath, sandboxedPath) {
|
|
64
|
+
const configDir = path.dirname(path.resolve(toolYamlPath));
|
|
65
|
+
return agentCommon.resolveConfigPath(sandboxedPath, configDir, {
|
|
66
|
+
expandHome: true
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
var CACHE_SUBDIR = ".agent/cache";
|
|
70
|
+
function getCacheBaseFromToolConfig(toolYamlPath) {
|
|
71
|
+
const config = loadToolConfig(toolYamlPath);
|
|
72
|
+
if (!config.sandboxedPath || typeof config.sandboxedPath !== "string") return void 0;
|
|
73
|
+
const sandboxRoot = resolveSandboxedPath(toolYamlPath, config.sandboxedPath);
|
|
74
|
+
return path.join(sandboxRoot, CACHE_SUBDIR);
|
|
75
|
+
}
|
|
76
|
+
function findAndLoadToolConfig(dir) {
|
|
77
|
+
const resolvedDir = path.resolve(dir);
|
|
78
|
+
const candidates = [path.join(resolvedDir, "tool.yaml"), path.join(resolvedDir, ".tool.yaml")];
|
|
79
|
+
for (const p of candidates) {
|
|
80
|
+
if (fs.existsSync(p)) {
|
|
81
|
+
const config = loadToolConfig(p);
|
|
82
|
+
return { ...config, configPath: p };
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return {};
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// src/tools/util/toolDescriptor.ts
|
|
89
|
+
var TOOL_PATH_REGEX = /^([a-z][a-z0-9-]*):([^/]+)\/([^#]+)(#(.+))?$/;
|
|
90
|
+
function isToolPath(descriptor) {
|
|
91
|
+
return TOOL_PATH_REGEX.test(descriptor.trim());
|
|
92
|
+
}
|
|
93
|
+
function isBarePackageDescriptor(descriptor) {
|
|
94
|
+
const parsed = parseToolPath(descriptor.trim());
|
|
95
|
+
return parsed !== null && parsed.toolName === "";
|
|
96
|
+
}
|
|
97
|
+
function parseToolPath(descriptor) {
|
|
98
|
+
const s = descriptor.trim();
|
|
99
|
+
const m = s.match(TOOL_PATH_REGEX);
|
|
100
|
+
if (!m || m[1] === void 0 || m[2] === void 0 || m[3] === void 0) return null;
|
|
101
|
+
return {
|
|
102
|
+
protocol: m[1],
|
|
103
|
+
scope: m[2],
|
|
104
|
+
packageWithVersion: m[3],
|
|
105
|
+
toolName: m[5] ?? ""
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
function npmDescriptorToRegistryPrefix(descriptor, resolvedVersion) {
|
|
109
|
+
const s = descriptor.trim();
|
|
110
|
+
if (typeof s !== "string" || !s.startsWith("npm:")) return "";
|
|
111
|
+
const rest = s.slice(4).trim();
|
|
112
|
+
const hashIdx = rest.indexOf("#");
|
|
113
|
+
const beforeHash = hashIdx < 0 ? rest : rest.slice(0, hashIdx);
|
|
114
|
+
const lastAt = beforeHash.lastIndexOf("@");
|
|
115
|
+
const scopeAndPackage = lastAt <= 0 ? beforeHash : beforeHash.slice(0, lastAt);
|
|
116
|
+
let version = lastAt <= 0 ? "latest" : beforeHash.slice(lastAt + 1).trim() || "latest";
|
|
117
|
+
if (version === "latest" || !version) {
|
|
118
|
+
const resolved = (resolvedVersion ?? "").trim();
|
|
119
|
+
if (resolved !== "" && resolved.toLowerCase() !== "latest") {
|
|
120
|
+
version = resolved;
|
|
121
|
+
} else {
|
|
122
|
+
throw new Error(
|
|
123
|
+
`Registry prefix requires a concrete version when descriptor uses latest (${descriptor}). Resolve version from registry (e.g. resolveLatestVersionFromRegistry) and pass as resolvedVersion.`
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
if (!version || version.toLowerCase() === "latest") {
|
|
128
|
+
throw new Error(
|
|
129
|
+
`Registry never uses "latest"; pass resolved concrete version for npm descriptor: ${descriptor}`
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
const slashIdx = scopeAndPackage.indexOf("/");
|
|
133
|
+
const scope = slashIdx < 0 ? scopeAndPackage : scopeAndPackage.slice(0, slashIdx).replace(/^@/, "");
|
|
134
|
+
const pkg = slashIdx < 0 ? "" : scopeAndPackage.slice(slashIdx + 1);
|
|
135
|
+
const segment = [scope, pkg, version].filter(Boolean).join(".");
|
|
136
|
+
const normalized = chunkDYDNPIV2_cjs.normalizeToolName(segment);
|
|
137
|
+
if (!normalized) return "";
|
|
138
|
+
return "npm." + normalized + ".";
|
|
139
|
+
}
|
|
140
|
+
function npmDescriptorToPackagePrefix(descriptor) {
|
|
141
|
+
const s = descriptor.trim();
|
|
142
|
+
if (typeof s !== "string" || !s.startsWith("npm:")) return "";
|
|
143
|
+
const rest = s.slice(4).trim();
|
|
144
|
+
const hashIdx = rest.indexOf("#");
|
|
145
|
+
const beforeHash = hashIdx < 0 ? rest : rest.slice(0, hashIdx);
|
|
146
|
+
const lastAt = beforeHash.lastIndexOf("@");
|
|
147
|
+
const scopeAndPackage = lastAt <= 0 ? beforeHash : beforeHash.slice(0, lastAt);
|
|
148
|
+
const slashIdx = scopeAndPackage.indexOf("/");
|
|
149
|
+
const scope = slashIdx < 0 ? scopeAndPackage : scopeAndPackage.slice(0, slashIdx).replace(/^@/, "");
|
|
150
|
+
const pkg = slashIdx < 0 ? "" : scopeAndPackage.slice(slashIdx + 1);
|
|
151
|
+
const segment = [scope, pkg].filter(Boolean).join(".");
|
|
152
|
+
const normalized = chunkDYDNPIV2_cjs.normalizeToolName(segment);
|
|
153
|
+
if (!normalized) return "";
|
|
154
|
+
return "npm." + normalized;
|
|
155
|
+
}
|
|
156
|
+
function npmDescriptorToPackagePrefixWithVersion(descriptor) {
|
|
157
|
+
const s = descriptor.trim();
|
|
158
|
+
if (typeof s !== "string" || !s.startsWith("npm:")) return "";
|
|
159
|
+
const rest = s.slice(4).trim();
|
|
160
|
+
const hashIdx = rest.indexOf("#");
|
|
161
|
+
const beforeHash = hashIdx < 0 ? rest : rest.slice(0, hashIdx);
|
|
162
|
+
const lastAt = beforeHash.lastIndexOf("@");
|
|
163
|
+
const scopeAndPackage = lastAt <= 0 ? beforeHash : beforeHash.slice(0, lastAt);
|
|
164
|
+
const version = lastAt <= 0 ? "" : beforeHash.slice(lastAt + 1).trim();
|
|
165
|
+
const slashIdx = scopeAndPackage.indexOf("/");
|
|
166
|
+
const scope = slashIdx < 0 ? scopeAndPackage : scopeAndPackage.slice(0, slashIdx).replace(/^@/, "");
|
|
167
|
+
const pkg = slashIdx < 0 ? "" : scopeAndPackage.slice(slashIdx + 1);
|
|
168
|
+
const segment = [scope, pkg, version].filter(Boolean).join(".");
|
|
169
|
+
const normalized = chunkDYDNPIV2_cjs.normalizeToolName(segment);
|
|
170
|
+
if (!normalized) return "";
|
|
171
|
+
return "npm." + normalized;
|
|
172
|
+
}
|
|
173
|
+
function getDisplayScope(registryName, _kind, _toolVersion) {
|
|
174
|
+
const i = registryName.indexOf(".");
|
|
175
|
+
return i < 0 ? registryName : registryName.slice(0, i);
|
|
176
|
+
}
|
|
177
|
+
function expandToolDescriptorsToRegistryNames(descriptors, registryNames) {
|
|
178
|
+
const out = [];
|
|
179
|
+
const seen = /* @__PURE__ */ new Set();
|
|
180
|
+
function add(name) {
|
|
181
|
+
const key = chunkDYDNPIV2_cjs.normalizeToolName(name);
|
|
182
|
+
if (registryNames.includes(key) && !seen.has(key)) {
|
|
183
|
+
seen.add(key);
|
|
184
|
+
out.push(key);
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
const matched = registryNames.filter((r) => r === key || r.endsWith("." + key));
|
|
188
|
+
for (const m of matched) {
|
|
189
|
+
if (!seen.has(m)) {
|
|
190
|
+
seen.add(m);
|
|
191
|
+
out.push(m);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
for (const d of descriptors) {
|
|
196
|
+
const s = d.trim();
|
|
197
|
+
if (!s) continue;
|
|
198
|
+
if (isToolPath(s)) {
|
|
199
|
+
if (registryNames.includes(s) && !seen.has(s)) {
|
|
200
|
+
seen.add(s);
|
|
201
|
+
out.push(s);
|
|
202
|
+
continue;
|
|
203
|
+
}
|
|
204
|
+
const path = parseToolPath(s);
|
|
205
|
+
if (path) {
|
|
206
|
+
const packagePrefix = path.protocol === "npm" ? npmDescriptorToPackagePrefix(s) : path.protocol === "file" ? fileDescriptorToPackagePrefix(s) : "";
|
|
207
|
+
const prefixWithDot = packagePrefix ? packagePrefix + "." : "";
|
|
208
|
+
if (prefixWithDot) {
|
|
209
|
+
if (path.toolName) {
|
|
210
|
+
const suffix = "." + path.toolName;
|
|
211
|
+
for (const r of registryNames) {
|
|
212
|
+
if (r.startsWith(prefixWithDot) && r.endsWith(suffix) && !seen.has(r)) {
|
|
213
|
+
seen.add(r);
|
|
214
|
+
out.push(r);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
} else {
|
|
218
|
+
for (const r of registryNames) {
|
|
219
|
+
if (r.startsWith(prefixWithDot) && !seen.has(r)) {
|
|
220
|
+
seen.add(r);
|
|
221
|
+
out.push(r);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
continue;
|
|
228
|
+
}
|
|
229
|
+
const name = chunkDYDNPIV2_cjs.normalizeToolName(s);
|
|
230
|
+
add(name);
|
|
231
|
+
}
|
|
232
|
+
return out;
|
|
233
|
+
}
|
|
234
|
+
function resolveToolDescriptor(descriptor) {
|
|
235
|
+
const s = descriptor.trim();
|
|
236
|
+
return s;
|
|
237
|
+
}
|
|
238
|
+
function fileDescriptorToPackagePrefix(descriptor) {
|
|
239
|
+
const path = parseToolPath(descriptor.trim());
|
|
240
|
+
if (!path || path.protocol !== "file") return "";
|
|
241
|
+
const pathPart = `${path.scope}/${path.packageWithVersion}`;
|
|
242
|
+
const normalized = chunkDYDNPIV2_cjs.normalizeToolName(pathPart);
|
|
243
|
+
if (!normalized) return "";
|
|
244
|
+
return "file." + normalized;
|
|
245
|
+
}
|
|
246
|
+
function fileDescriptorToRegistryPrefix(descriptor) {
|
|
247
|
+
const prefix = fileDescriptorToPackagePrefix(descriptor);
|
|
248
|
+
return prefix ? prefix + "." : "";
|
|
249
|
+
}
|
|
25
250
|
var SchemaValidator = class {
|
|
26
251
|
ajv;
|
|
27
252
|
cache = /* @__PURE__ */ new Map();
|
|
@@ -1491,7 +1716,7 @@ var sandboxValidationEnabled = false;
|
|
|
1491
1716
|
function setSandboxValidationEnabled(enabled) {
|
|
1492
1717
|
sandboxValidationEnabled = enabled;
|
|
1493
1718
|
}
|
|
1494
|
-
async function
|
|
1719
|
+
async function resolveSandboxedPath2(inputPath, sandboxRoot) {
|
|
1495
1720
|
let normalizedRoot;
|
|
1496
1721
|
try {
|
|
1497
1722
|
normalizedRoot = await promises.realpath(path.resolve(sandboxRoot));
|
|
@@ -1529,261 +1754,13 @@ function isWithinRoot(path$1, root) {
|
|
|
1529
1754
|
return normalizedPath === normalizedRoot || normalizedPath.startsWith(normalizedRoot + "/");
|
|
1530
1755
|
}
|
|
1531
1756
|
|
|
1532
|
-
// src/
|
|
1533
|
-
var
|
|
1534
|
-
function
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
return parsed !== null && parsed.toolName === "";
|
|
1540
|
-
}
|
|
1541
|
-
function parseToolPath(descriptor) {
|
|
1542
|
-
const s = descriptor.trim();
|
|
1543
|
-
const m = s.match(TOOL_PATH_REGEX);
|
|
1544
|
-
if (!m || m[1] === void 0 || m[2] === void 0 || m[3] === void 0) return null;
|
|
1545
|
-
return {
|
|
1546
|
-
protocol: m[1],
|
|
1547
|
-
scope: m[2],
|
|
1548
|
-
packageWithVersion: m[3],
|
|
1549
|
-
toolName: m[5] ?? ""
|
|
1550
|
-
};
|
|
1551
|
-
}
|
|
1552
|
-
function npmDescriptorToRegistryPrefix(descriptor, resolvedVersion) {
|
|
1553
|
-
const s = descriptor.trim();
|
|
1554
|
-
if (typeof s !== "string" || !s.startsWith("npm:")) return "";
|
|
1555
|
-
const rest = s.slice(4).trim();
|
|
1556
|
-
const hashIdx = rest.indexOf("#");
|
|
1557
|
-
const beforeHash = hashIdx < 0 ? rest : rest.slice(0, hashIdx);
|
|
1558
|
-
const lastAt = beforeHash.lastIndexOf("@");
|
|
1559
|
-
const scopeAndPackage = lastAt <= 0 ? beforeHash : beforeHash.slice(0, lastAt);
|
|
1560
|
-
let version = lastAt <= 0 ? "latest" : beforeHash.slice(lastAt + 1).trim() || "latest";
|
|
1561
|
-
if (version === "latest" || !version) {
|
|
1562
|
-
const resolved = (resolvedVersion ?? "").trim();
|
|
1563
|
-
if (resolved !== "" && resolved.toLowerCase() !== "latest") {
|
|
1564
|
-
version = resolved;
|
|
1565
|
-
} else {
|
|
1566
|
-
throw new Error(
|
|
1567
|
-
`Registry prefix requires a concrete version when descriptor uses latest (${descriptor}). Resolve version from registry (e.g. resolveLatestVersionFromRegistry) and pass as resolvedVersion.`
|
|
1568
|
-
);
|
|
1569
|
-
}
|
|
1570
|
-
}
|
|
1571
|
-
if (!version || version.toLowerCase() === "latest") {
|
|
1572
|
-
throw new Error(
|
|
1573
|
-
`Registry never uses "latest"; pass resolved concrete version for npm descriptor: ${descriptor}`
|
|
1574
|
-
);
|
|
1575
|
-
}
|
|
1576
|
-
const slashIdx = scopeAndPackage.indexOf("/");
|
|
1577
|
-
const scope = slashIdx < 0 ? scopeAndPackage : scopeAndPackage.slice(0, slashIdx).replace(/^@/, "");
|
|
1578
|
-
const pkg = slashIdx < 0 ? "" : scopeAndPackage.slice(slashIdx + 1);
|
|
1579
|
-
const segment = [scope, pkg, version].filter(Boolean).join(".");
|
|
1580
|
-
const normalized = chunkDYDNPIV2_cjs.normalizeToolName(segment);
|
|
1581
|
-
if (!normalized) return "";
|
|
1582
|
-
return "npm." + normalized + ".";
|
|
1583
|
-
}
|
|
1584
|
-
function npmDescriptorToPackagePrefix(descriptor) {
|
|
1585
|
-
const s = descriptor.trim();
|
|
1586
|
-
if (typeof s !== "string" || !s.startsWith("npm:")) return "";
|
|
1587
|
-
const rest = s.slice(4).trim();
|
|
1588
|
-
const hashIdx = rest.indexOf("#");
|
|
1589
|
-
const beforeHash = hashIdx < 0 ? rest : rest.slice(0, hashIdx);
|
|
1590
|
-
const lastAt = beforeHash.lastIndexOf("@");
|
|
1591
|
-
const scopeAndPackage = lastAt <= 0 ? beforeHash : beforeHash.slice(0, lastAt);
|
|
1592
|
-
const slashIdx = scopeAndPackage.indexOf("/");
|
|
1593
|
-
const scope = slashIdx < 0 ? scopeAndPackage : scopeAndPackage.slice(0, slashIdx).replace(/^@/, "");
|
|
1594
|
-
const pkg = slashIdx < 0 ? "" : scopeAndPackage.slice(slashIdx + 1);
|
|
1595
|
-
const segment = [scope, pkg].filter(Boolean).join(".");
|
|
1596
|
-
const normalized = chunkDYDNPIV2_cjs.normalizeToolName(segment);
|
|
1597
|
-
if (!normalized) return "";
|
|
1598
|
-
return "npm." + normalized;
|
|
1599
|
-
}
|
|
1600
|
-
function npmDescriptorToPackagePrefixWithVersion(descriptor) {
|
|
1601
|
-
const s = descriptor.trim();
|
|
1602
|
-
if (typeof s !== "string" || !s.startsWith("npm:")) return "";
|
|
1603
|
-
const rest = s.slice(4).trim();
|
|
1604
|
-
const hashIdx = rest.indexOf("#");
|
|
1605
|
-
const beforeHash = hashIdx < 0 ? rest : rest.slice(0, hashIdx);
|
|
1606
|
-
const lastAt = beforeHash.lastIndexOf("@");
|
|
1607
|
-
const scopeAndPackage = lastAt <= 0 ? beforeHash : beforeHash.slice(0, lastAt);
|
|
1608
|
-
const version = lastAt <= 0 ? "" : beforeHash.slice(lastAt + 1).trim();
|
|
1609
|
-
const slashIdx = scopeAndPackage.indexOf("/");
|
|
1610
|
-
const scope = slashIdx < 0 ? scopeAndPackage : scopeAndPackage.slice(0, slashIdx).replace(/^@/, "");
|
|
1611
|
-
const pkg = slashIdx < 0 ? "" : scopeAndPackage.slice(slashIdx + 1);
|
|
1612
|
-
const segment = [scope, pkg, version].filter(Boolean).join(".");
|
|
1613
|
-
const normalized = chunkDYDNPIV2_cjs.normalizeToolName(segment);
|
|
1614
|
-
if (!normalized) return "";
|
|
1615
|
-
return "npm." + normalized;
|
|
1616
|
-
}
|
|
1617
|
-
function isNpmToolDescriptor(descriptor) {
|
|
1618
|
-
return isToolPath(descriptor) && parseToolPath(descriptor)?.protocol === "npm";
|
|
1619
|
-
}
|
|
1620
|
-
function parseNpmToolDescriptor(descriptor) {
|
|
1621
|
-
const parsed = parseToolPath(descriptor);
|
|
1622
|
-
if (!parsed || parsed.protocol !== "npm") return null;
|
|
1623
|
-
return {
|
|
1624
|
-
fullPackage: `${parsed.scope}/${parsed.packageWithVersion}`,
|
|
1625
|
-
toolPath: parsed.toolName
|
|
1626
|
-
};
|
|
1627
|
-
}
|
|
1628
|
-
function getDisplayScope(registryName, _kind, _toolVersion) {
|
|
1629
|
-
const i = registryName.indexOf(".");
|
|
1630
|
-
return i < 0 ? registryName : registryName.slice(0, i);
|
|
1631
|
-
}
|
|
1632
|
-
function resolveNpmToolDescriptor(descriptor) {
|
|
1633
|
-
return null;
|
|
1634
|
-
}
|
|
1635
|
-
function expandToolDescriptorsToRegistryNames(descriptors, registryNames) {
|
|
1636
|
-
const out = [];
|
|
1637
|
-
const seen = /* @__PURE__ */ new Set();
|
|
1638
|
-
function add(name) {
|
|
1639
|
-
const key = chunkDYDNPIV2_cjs.normalizeToolName(name);
|
|
1640
|
-
if (registryNames.includes(key) && !seen.has(key)) {
|
|
1641
|
-
seen.add(key);
|
|
1642
|
-
out.push(key);
|
|
1643
|
-
return;
|
|
1644
|
-
}
|
|
1645
|
-
const matched = registryNames.filter((r) => r === key || r.endsWith("." + key));
|
|
1646
|
-
for (const m of matched) {
|
|
1647
|
-
if (!seen.has(m)) {
|
|
1648
|
-
seen.add(m);
|
|
1649
|
-
out.push(m);
|
|
1650
|
-
}
|
|
1651
|
-
}
|
|
1652
|
-
}
|
|
1653
|
-
for (const d of descriptors) {
|
|
1654
|
-
const s = d.trim();
|
|
1655
|
-
if (!s) continue;
|
|
1656
|
-
if (isToolPath(s)) {
|
|
1657
|
-
if (registryNames.includes(s) && !seen.has(s)) {
|
|
1658
|
-
seen.add(s);
|
|
1659
|
-
out.push(s);
|
|
1660
|
-
continue;
|
|
1661
|
-
}
|
|
1662
|
-
const path = parseToolPath(s);
|
|
1663
|
-
if (path) {
|
|
1664
|
-
const packagePrefix = path.protocol === "npm" ? npmDescriptorToPackagePrefix(s) : path.protocol === "file" ? fileDescriptorToPackagePrefix(s) : "";
|
|
1665
|
-
const prefixWithDot = packagePrefix ? packagePrefix + "." : "";
|
|
1666
|
-
if (prefixWithDot) {
|
|
1667
|
-
if (path.toolName) {
|
|
1668
|
-
const suffix = "." + path.toolName;
|
|
1669
|
-
for (const r of registryNames) {
|
|
1670
|
-
if (r.startsWith(prefixWithDot) && r.endsWith(suffix) && !seen.has(r)) {
|
|
1671
|
-
seen.add(r);
|
|
1672
|
-
out.push(r);
|
|
1673
|
-
}
|
|
1674
|
-
}
|
|
1675
|
-
} else {
|
|
1676
|
-
for (const r of registryNames) {
|
|
1677
|
-
if (r.startsWith(prefixWithDot) && !seen.has(r)) {
|
|
1678
|
-
seen.add(r);
|
|
1679
|
-
out.push(r);
|
|
1680
|
-
}
|
|
1681
|
-
}
|
|
1682
|
-
}
|
|
1683
|
-
}
|
|
1684
|
-
}
|
|
1685
|
-
continue;
|
|
1686
|
-
}
|
|
1687
|
-
const name = chunkDYDNPIV2_cjs.normalizeToolName(s);
|
|
1688
|
-
add(name);
|
|
1689
|
-
}
|
|
1690
|
-
return out;
|
|
1691
|
-
}
|
|
1692
|
-
function resolveToolDescriptor(descriptor) {
|
|
1693
|
-
const s = descriptor.trim();
|
|
1694
|
-
return s;
|
|
1695
|
-
}
|
|
1696
|
-
function normalizeToolList(descriptors) {
|
|
1697
|
-
const seen = /* @__PURE__ */ new Set();
|
|
1698
|
-
const out = [];
|
|
1699
|
-
for (const d of descriptors) {
|
|
1700
|
-
if (typeof d !== "string" || !d.trim()) continue;
|
|
1701
|
-
const name = resolveToolDescriptor(d);
|
|
1702
|
-
if (!seen.has(name)) {
|
|
1703
|
-
seen.add(name);
|
|
1704
|
-
out.push(name);
|
|
1705
|
-
}
|
|
1706
|
-
}
|
|
1707
|
-
return out;
|
|
1708
|
-
}
|
|
1709
|
-
function fileDescriptorToPackagePrefix(descriptor) {
|
|
1710
|
-
const path = parseToolPath(descriptor.trim());
|
|
1711
|
-
if (!path || path.protocol !== "file") return "";
|
|
1712
|
-
const pathPart = `${path.scope}/${path.packageWithVersion}`;
|
|
1713
|
-
const normalized = chunkDYDNPIV2_cjs.normalizeToolName(pathPart);
|
|
1714
|
-
if (!normalized) return "";
|
|
1715
|
-
return "file." + normalized;
|
|
1716
|
-
}
|
|
1717
|
-
function fileDescriptorToRegistryPrefix(descriptor) {
|
|
1718
|
-
const prefix = fileDescriptorToPackagePrefix(descriptor);
|
|
1719
|
-
return prefix ? prefix + "." : "";
|
|
1720
|
-
}
|
|
1721
|
-
function loadToolConfig(toolYamlPath) {
|
|
1722
|
-
const abs = path.resolve(toolYamlPath);
|
|
1723
|
-
const raw = fs.readFileSync(abs, "utf8");
|
|
1724
|
-
const parsed = agentCommon.parseYamlContent(raw, {
|
|
1725
|
-
substituteEnv: false
|
|
1726
|
-
});
|
|
1727
|
-
if (!parsed || typeof parsed !== "object") return {};
|
|
1728
|
-
const toolsBlock = parsed.tools;
|
|
1729
|
-
if (toolsBlock != null && typeof toolsBlock === "object" && !Array.isArray(toolsBlock)) {
|
|
1730
|
-
const toolDefaults = toolsBlock.defaults != null && typeof toolsBlock.defaults === "object" && !Array.isArray(toolsBlock.defaults) ? toolsBlock.defaults : void 0;
|
|
1731
|
-
const packageToolDefaults2 = toolsBlock.packages != null && typeof toolsBlock.packages === "object" && !Array.isArray(toolsBlock.packages) ? toolsBlock.packages : void 0;
|
|
1732
|
-
const list2 = Array.isArray(toolsBlock.list) && toolsBlock.list.length > 0 ? toolsBlock.list : void 0;
|
|
1733
|
-
return {
|
|
1734
|
-
tools: list2 ?? (packageToolDefaults2 ? Object.keys(packageToolDefaults2) : void 0),
|
|
1735
|
-
sandboxedPath: typeof toolsBlock.sandboxedPath === "string" ? toolsBlock.sandboxedPath : parsed.sandboxedPath,
|
|
1736
|
-
enableSandboxValidation: typeof toolsBlock.enableSandboxValidation === "boolean" ? toolsBlock.enableSandboxValidation : parsed.enableSandboxValidation,
|
|
1737
|
-
allowedHosts: Array.isArray(toolsBlock.allowedHosts) ? toolsBlock.allowedHosts : parsed.allowedHosts,
|
|
1738
|
-
blockedHosts: Array.isArray(toolsBlock.blockedHosts) ? toolsBlock.blockedHosts : parsed.blockedHosts,
|
|
1739
|
-
blockedCidrs: Array.isArray(toolsBlock.blockedCidrs) ? toolsBlock.blockedCidrs : parsed.blockedCidrs,
|
|
1740
|
-
toolDefaults,
|
|
1741
|
-
packageToolDefaults: packageToolDefaults2
|
|
1742
|
-
};
|
|
1743
|
-
}
|
|
1744
|
-
const packageToolDefaults = typeof parsed.packageToolDefaults === "object" && !Array.isArray(parsed.packageToolDefaults) ? parsed.packageToolDefaults : void 0;
|
|
1745
|
-
const list = Array.isArray(parsed.tools) && parsed.tools.length > 0 ? parsed.tools : void 0;
|
|
1746
|
-
return {
|
|
1747
|
-
tools: list ?? (packageToolDefaults ? Object.keys(packageToolDefaults) : void 0),
|
|
1748
|
-
sandboxedPath: parsed.sandboxedPath,
|
|
1749
|
-
enableSandboxValidation: typeof parsed.enableSandboxValidation === "boolean" ? parsed.enableSandboxValidation : void 0,
|
|
1750
|
-
allowedHosts: Array.isArray(parsed.allowedHosts) ? parsed.allowedHosts : void 0,
|
|
1751
|
-
blockedHosts: Array.isArray(parsed.blockedHosts) ? parsed.blockedHosts : void 0,
|
|
1752
|
-
blockedCidrs: Array.isArray(parsed.blockedCidrs) ? parsed.blockedCidrs : void 0,
|
|
1753
|
-
toolDefaults: typeof parsed.toolDefaults === "object" && !Array.isArray(parsed.toolDefaults) ? parsed.toolDefaults : void 0,
|
|
1754
|
-
packageToolDefaults
|
|
1755
|
-
};
|
|
1756
|
-
}
|
|
1757
|
-
function resolveSandboxedPath2(toolYamlPath, sandboxedPath) {
|
|
1758
|
-
const configDir = path.dirname(path.resolve(toolYamlPath));
|
|
1759
|
-
return agentCommon.resolveConfigPath(sandboxedPath, configDir, {
|
|
1760
|
-
expandHome: true
|
|
1761
|
-
});
|
|
1762
|
-
}
|
|
1763
|
-
var CACHE_SUBDIR = ".agent/cache";
|
|
1764
|
-
function getCacheBaseFromToolConfig(toolYamlPath) {
|
|
1765
|
-
const config = loadToolConfig(toolYamlPath);
|
|
1766
|
-
if (!config.sandboxedPath || typeof config.sandboxedPath !== "string") return void 0;
|
|
1767
|
-
const sandboxRoot = resolveSandboxedPath2(toolYamlPath, config.sandboxedPath);
|
|
1768
|
-
return path.join(sandboxRoot, CACHE_SUBDIR);
|
|
1769
|
-
}
|
|
1770
|
-
function findAndLoadToolConfig(dir) {
|
|
1771
|
-
const resolvedDir = path.resolve(dir);
|
|
1772
|
-
const candidates = [path.join(resolvedDir, "tool.yaml"), path.join(resolvedDir, ".tool.yaml")];
|
|
1773
|
-
for (const p of candidates) {
|
|
1774
|
-
if (fs.existsSync(p)) {
|
|
1775
|
-
const config = loadToolConfig(p);
|
|
1776
|
-
return { ...config, configPath: p };
|
|
1777
|
-
}
|
|
1778
|
-
}
|
|
1779
|
-
return {};
|
|
1780
|
-
}
|
|
1781
|
-
var requireFromPackage = module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('chunk-XC7KPJLZ.cjs', document.baseURI).href)));
|
|
1782
|
-
function getProjectRequire() {
|
|
1783
|
-
const cwd = process.cwd();
|
|
1784
|
-
if (fs.existsSync(path.join(cwd, "package.json"))) return module$1.createRequire(path.join(cwd, "package.json"));
|
|
1785
|
-
if (fs.existsSync(path.join(cwd, "tool.yaml"))) return module$1.createRequire(path.join(cwd, "tool.yaml"));
|
|
1786
|
-
return null;
|
|
1757
|
+
// src/api/runtimeFromConfig.ts
|
|
1758
|
+
var requireFromPackage = module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('chunk-A5B6Q6EG.cjs', document.baseURI).href)));
|
|
1759
|
+
function getProjectRequire() {
|
|
1760
|
+
const cwd = process.cwd();
|
|
1761
|
+
if (fs.existsSync(path.join(cwd, "package.json"))) return module$1.createRequire(path.join(cwd, "package.json"));
|
|
1762
|
+
if (fs.existsSync(path.join(cwd, "tool.yaml"))) return module$1.createRequire(path.join(cwd, "tool.yaml"));
|
|
1763
|
+
return null;
|
|
1787
1764
|
}
|
|
1788
1765
|
var DEFAULT_EXTENSION_PACKAGES = [];
|
|
1789
1766
|
function getInstalledPackageVersion(packageName) {
|
|
@@ -2069,43 +2046,487 @@ async function createRuntimeFromConfig(options = {}) {
|
|
|
2069
2046
|
return createRuntimeFromConfigSync(options);
|
|
2070
2047
|
}
|
|
2071
2048
|
|
|
2049
|
+
// src/api/expose/openapi.ts
|
|
2050
|
+
function toolNameToSlug(name) {
|
|
2051
|
+
return name.replace(/\./g, "~");
|
|
2052
|
+
}
|
|
2053
|
+
function slugToToolName(slug) {
|
|
2054
|
+
return slug.replace(/~/g, ".");
|
|
2055
|
+
}
|
|
2056
|
+
function toolSchemaKey(name) {
|
|
2057
|
+
return `Tool_${name.replace(/[^a-zA-Z0-9_]/g, "_")}`;
|
|
2058
|
+
}
|
|
2059
|
+
var resultSchema = {
|
|
2060
|
+
type: "object",
|
|
2061
|
+
properties: {
|
|
2062
|
+
result: { description: "Tool return value", additionalProperties: true }
|
|
2063
|
+
}
|
|
2064
|
+
};
|
|
2065
|
+
var errorSchema = {
|
|
2066
|
+
type: "object",
|
|
2067
|
+
properties: {
|
|
2068
|
+
error: { type: "string" },
|
|
2069
|
+
kind: { type: "string" },
|
|
2070
|
+
details: { type: "object", additionalProperties: true }
|
|
2071
|
+
}
|
|
2072
|
+
};
|
|
2073
|
+
function toolsToOpenAPISpec(registry, options = {}) {
|
|
2074
|
+
const title = options.title ?? "Tool API";
|
|
2075
|
+
const version = options.version ?? "1.0.0";
|
|
2076
|
+
const basePath = (options.basePath ?? "").replace(/\/$/, "");
|
|
2077
|
+
const specs = registry.snapshot().map(chunkUUNG3GL3_cjs.enrichSpecWithCanonicalSchema);
|
|
2078
|
+
const toolNamesSchema = {
|
|
2079
|
+
type: "object",
|
|
2080
|
+
required: ["tools"],
|
|
2081
|
+
properties: {
|
|
2082
|
+
tools: {
|
|
2083
|
+
type: "array",
|
|
2084
|
+
items: {
|
|
2085
|
+
type: "object",
|
|
2086
|
+
properties: {
|
|
2087
|
+
name: { type: "string" },
|
|
2088
|
+
description: { type: "string" },
|
|
2089
|
+
kind: { type: "string" }
|
|
2090
|
+
}
|
|
2091
|
+
}
|
|
2092
|
+
}
|
|
2093
|
+
}
|
|
2094
|
+
};
|
|
2095
|
+
const invokeRequestBody = {
|
|
2096
|
+
type: "object",
|
|
2097
|
+
required: ["tool", "args"],
|
|
2098
|
+
properties: {
|
|
2099
|
+
tool: { type: "string", description: "Tool name (e.g. from GET /tools)" },
|
|
2100
|
+
args: {
|
|
2101
|
+
type: "object",
|
|
2102
|
+
description: "Tool arguments (schema per tool; use per-tool paths for typed schema)",
|
|
2103
|
+
additionalProperties: true
|
|
2104
|
+
}
|
|
2105
|
+
}
|
|
2106
|
+
};
|
|
2107
|
+
const prefix = basePath ? `${basePath}/` : "/";
|
|
2108
|
+
const paths = {
|
|
2109
|
+
[`${prefix}tools`]: {
|
|
2110
|
+
get: {
|
|
2111
|
+
summary: "List tools",
|
|
2112
|
+
description: "Returns all registered tool names and descriptions.",
|
|
2113
|
+
operationId: "listTools",
|
|
2114
|
+
responses: {
|
|
2115
|
+
"200": {
|
|
2116
|
+
description: "List of tools",
|
|
2117
|
+
content: {
|
|
2118
|
+
"application/json": {
|
|
2119
|
+
schema: toolNamesSchema
|
|
2120
|
+
}
|
|
2121
|
+
}
|
|
2122
|
+
}
|
|
2123
|
+
}
|
|
2124
|
+
}
|
|
2125
|
+
},
|
|
2126
|
+
[`${prefix}invoke`]: {
|
|
2127
|
+
post: {
|
|
2128
|
+
summary: "Invoke a tool (generic)",
|
|
2129
|
+
description: "Call any tool by name with body { tool, args }. For typed schemas use POST /invoke/{toolSlug}.",
|
|
2130
|
+
operationId: "invokeTool",
|
|
2131
|
+
requestBody: {
|
|
2132
|
+
required: true,
|
|
2133
|
+
content: {
|
|
2134
|
+
"application/json": {
|
|
2135
|
+
schema: invokeRequestBody
|
|
2136
|
+
}
|
|
2137
|
+
}
|
|
2138
|
+
},
|
|
2139
|
+
responses: {
|
|
2140
|
+
"200": {
|
|
2141
|
+
description: "Tool result",
|
|
2142
|
+
content: { "application/json": { schema: resultSchema } }
|
|
2143
|
+
},
|
|
2144
|
+
"400": {
|
|
2145
|
+
description: "Bad request",
|
|
2146
|
+
content: { "application/json": { schema: errorSchema } }
|
|
2147
|
+
}
|
|
2148
|
+
}
|
|
2149
|
+
}
|
|
2150
|
+
}
|
|
2151
|
+
};
|
|
2152
|
+
const schemaEntries = [];
|
|
2153
|
+
for (const s of specs) {
|
|
2154
|
+
const key = toolSchemaKey(s.name);
|
|
2155
|
+
schemaEntries.push([key, s.inputSchema]);
|
|
2156
|
+
const slug = toolNameToSlug(s.name);
|
|
2157
|
+
paths[`${prefix}invoke/${slug}`] = {
|
|
2158
|
+
post: {
|
|
2159
|
+
summary: s.description ?? s.name,
|
|
2160
|
+
description: `Invoke tool \`${s.name}\`. Request body is the tool's arguments (JSON Schema below).`,
|
|
2161
|
+
operationId: `invoke_${key}`,
|
|
2162
|
+
requestBody: {
|
|
2163
|
+
required: true,
|
|
2164
|
+
content: {
|
|
2165
|
+
"application/json": {
|
|
2166
|
+
schema: { $ref: `#/components/schemas/${key}` }
|
|
2167
|
+
}
|
|
2168
|
+
}
|
|
2169
|
+
},
|
|
2170
|
+
responses: {
|
|
2171
|
+
"200": {
|
|
2172
|
+
description: "Tool result",
|
|
2173
|
+
content: { "application/json": { schema: resultSchema } }
|
|
2174
|
+
},
|
|
2175
|
+
"400": {
|
|
2176
|
+
description: "Bad request (invalid args or tool error)",
|
|
2177
|
+
content: { "application/json": { schema: errorSchema } }
|
|
2178
|
+
}
|
|
2179
|
+
}
|
|
2180
|
+
}
|
|
2181
|
+
};
|
|
2182
|
+
}
|
|
2183
|
+
return {
|
|
2184
|
+
openapi: "3.0.3",
|
|
2185
|
+
info: { title, version },
|
|
2186
|
+
paths,
|
|
2187
|
+
components: {
|
|
2188
|
+
schemas: Object.fromEntries(schemaEntries)
|
|
2189
|
+
}
|
|
2190
|
+
};
|
|
2191
|
+
}
|
|
2192
|
+
|
|
2193
|
+
// src/api/expose/openapiHttp.ts
|
|
2194
|
+
var DEFAULT_CTX = {
|
|
2195
|
+
requestId: `http-${Date.now()}-${Math.random().toString(36).slice(2, 9)}`,
|
|
2196
|
+
taskId: `task-${Date.now()}`,
|
|
2197
|
+
permissions: [
|
|
2198
|
+
"read:web",
|
|
2199
|
+
"read:fs",
|
|
2200
|
+
"write:fs",
|
|
2201
|
+
"read:db",
|
|
2202
|
+
"write:db",
|
|
2203
|
+
"network",
|
|
2204
|
+
"workflow",
|
|
2205
|
+
"danger:destructive"
|
|
2206
|
+
]
|
|
2207
|
+
};
|
|
2208
|
+
function parseBody(req) {
|
|
2209
|
+
return new Promise((resolve4, reject) => {
|
|
2210
|
+
const chunks = [];
|
|
2211
|
+
req.on("data", (chunk) => chunks.push(chunk));
|
|
2212
|
+
req.on("end", () => {
|
|
2213
|
+
const raw = Buffer.concat(chunks).toString("utf-8");
|
|
2214
|
+
if (!raw.trim()) {
|
|
2215
|
+
resolve4({});
|
|
2216
|
+
return;
|
|
2217
|
+
}
|
|
2218
|
+
try {
|
|
2219
|
+
resolve4(JSON.parse(raw));
|
|
2220
|
+
} catch {
|
|
2221
|
+
reject(new Error("Invalid JSON body"));
|
|
2222
|
+
}
|
|
2223
|
+
});
|
|
2224
|
+
req.on("error", reject);
|
|
2225
|
+
});
|
|
2226
|
+
}
|
|
2227
|
+
function sendJson(res, status, data) {
|
|
2228
|
+
res.writeHead(status, { "Content-Type": "application/json" });
|
|
2229
|
+
res.end(JSON.stringify(data));
|
|
2230
|
+
}
|
|
2231
|
+
function swaggerUiHtml(specUrl) {
|
|
2232
|
+
const specUrlEscaped = specUrl.replace(/"/g, """);
|
|
2233
|
+
return `<!DOCTYPE html>
|
|
2234
|
+
<html lang="en">
|
|
2235
|
+
<head>
|
|
2236
|
+
<meta charset="UTF-8">
|
|
2237
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
2238
|
+
<title>Tool API \u2013 Swagger UI</title>
|
|
2239
|
+
<link rel="stylesheet" href="https://unpkg.com/swagger-ui-dist@5/swagger-ui.css">
|
|
2240
|
+
</head>
|
|
2241
|
+
<body>
|
|
2242
|
+
<div id="swagger-ui"></div>
|
|
2243
|
+
<script src="https://unpkg.com/swagger-ui-dist@5/swagger-ui-bundle.js" crossorigin></script>
|
|
2244
|
+
<script src="https://unpkg.com/swagger-ui-dist@5/swagger-ui-standalone-preset.js" crossorigin></script>
|
|
2245
|
+
<script>
|
|
2246
|
+
window.onload = function() {
|
|
2247
|
+
window.ui = SwaggerUIBundle({
|
|
2248
|
+
url: "${specUrlEscaped}",
|
|
2249
|
+
dom_id: "#swagger-ui",
|
|
2250
|
+
deepLinking: true,
|
|
2251
|
+
presets: [
|
|
2252
|
+
SwaggerUIBundle.presets.apis,
|
|
2253
|
+
SwaggerUIStandalonePreset
|
|
2254
|
+
],
|
|
2255
|
+
layout: "StandaloneLayout"
|
|
2256
|
+
});
|
|
2257
|
+
};
|
|
2258
|
+
</script>
|
|
2259
|
+
</body>
|
|
2260
|
+
</html>`;
|
|
2261
|
+
}
|
|
2262
|
+
function createOpenAPIHttpServer(runtime, options = {}) {
|
|
2263
|
+
const basePath = (options.basePath ?? "").replace(/\/$/, "");
|
|
2264
|
+
const ctxFactory = options.execContextFactory ?? (() => ({ ...DEFAULT_CTX }));
|
|
2265
|
+
const server = http.createServer(async (req, res) => {
|
|
2266
|
+
const url = req.url ?? "/";
|
|
2267
|
+
const path = url.split("?")[0] ?? "/";
|
|
2268
|
+
const norm = basePath ? path === basePath ? "" : path.replace(basePath, "") || "/" : path;
|
|
2269
|
+
try {
|
|
2270
|
+
if (req.method === "GET" && (norm === "/" || norm === "/swagger")) {
|
|
2271
|
+
const specPath = basePath ? `${basePath}/openapi.json` : "/openapi.json";
|
|
2272
|
+
const html = swaggerUiHtml(specPath);
|
|
2273
|
+
res.writeHead(200, { "Content-Type": "text/html; charset=utf-8" });
|
|
2274
|
+
res.end(html);
|
|
2275
|
+
return;
|
|
2276
|
+
}
|
|
2277
|
+
if (req.method === "GET" && (norm === "/openapi.json" || norm === "/spec")) {
|
|
2278
|
+
const spec = toolsToOpenAPISpec(runtime.getRegistry(), {
|
|
2279
|
+
title: "Tool API",
|
|
2280
|
+
version: "1.0.0",
|
|
2281
|
+
basePath: basePath || void 0
|
|
2282
|
+
});
|
|
2283
|
+
sendJson(res, 200, spec);
|
|
2284
|
+
return;
|
|
2285
|
+
}
|
|
2286
|
+
if (req.method === "GET" && norm === "/tools") {
|
|
2287
|
+
const { enrichSpecWithCanonicalSchema: enrichSpecWithCanonicalSchema2 } = await import('./canonicalCoreSchemas-TY7NCWCC.cjs');
|
|
2288
|
+
const specs = runtime.getRegistry().snapshot().map(enrichSpecWithCanonicalSchema2);
|
|
2289
|
+
const tools = specs.map((s) => ({
|
|
2290
|
+
name: s.name,
|
|
2291
|
+
description: s.description,
|
|
2292
|
+
kind: s.kind,
|
|
2293
|
+
inputSchema: s.inputSchema
|
|
2294
|
+
}));
|
|
2295
|
+
sendJson(res, 200, { tools });
|
|
2296
|
+
return;
|
|
2297
|
+
}
|
|
2298
|
+
if (req.method === "POST" && norm === "/invoke") {
|
|
2299
|
+
const body = await parseBody(req);
|
|
2300
|
+
const tool = body?.tool;
|
|
2301
|
+
const args = body?.args ?? {};
|
|
2302
|
+
if (typeof tool !== "string" || !tool.trim()) {
|
|
2303
|
+
sendJson(res, 400, { error: "Missing or invalid 'tool' in body", kind: "BAD_REQUEST" });
|
|
2304
|
+
return;
|
|
2305
|
+
}
|
|
2306
|
+
const ctx = ctxFactory(req);
|
|
2307
|
+
const result = await runtime.invoke(
|
|
2308
|
+
{ tool: tool.trim(), args, purpose: "openapi" },
|
|
2309
|
+
ctx
|
|
2310
|
+
);
|
|
2311
|
+
if (result.ok) {
|
|
2312
|
+
sendJson(res, 200, { result: result.result });
|
|
2313
|
+
return;
|
|
2314
|
+
}
|
|
2315
|
+
sendJson(res, 400, {
|
|
2316
|
+
error: result.error?.message ?? "Tool failed",
|
|
2317
|
+
kind: result.error?.kind,
|
|
2318
|
+
details: result.error?.details
|
|
2319
|
+
});
|
|
2320
|
+
return;
|
|
2321
|
+
}
|
|
2322
|
+
if (req.method === "POST" && norm.startsWith("/invoke/") && norm.length > "/invoke/".length) {
|
|
2323
|
+
const slug = norm.slice("/invoke/".length);
|
|
2324
|
+
const toolName = slugToToolName(slug);
|
|
2325
|
+
let args;
|
|
2326
|
+
try {
|
|
2327
|
+
args = await parseBody(req);
|
|
2328
|
+
} catch {
|
|
2329
|
+
sendJson(res, 400, { error: "Invalid JSON body", kind: "BAD_REQUEST" });
|
|
2330
|
+
return;
|
|
2331
|
+
}
|
|
2332
|
+
const ctx = ctxFactory(req);
|
|
2333
|
+
const result = await runtime.invoke(
|
|
2334
|
+
{ tool: toolName, args: args ?? {}, purpose: "openapi" },
|
|
2335
|
+
ctx
|
|
2336
|
+
);
|
|
2337
|
+
if (result.ok) {
|
|
2338
|
+
sendJson(res, 200, { result: result.result });
|
|
2339
|
+
return;
|
|
2340
|
+
}
|
|
2341
|
+
sendJson(res, 400, {
|
|
2342
|
+
error: result.error?.message ?? "Tool failed",
|
|
2343
|
+
kind: result.error?.kind,
|
|
2344
|
+
details: result.error?.details
|
|
2345
|
+
});
|
|
2346
|
+
return;
|
|
2347
|
+
}
|
|
2348
|
+
res.writeHead(404, { "Content-Type": "application/json" });
|
|
2349
|
+
res.end(JSON.stringify({ error: "Not found", path: norm }));
|
|
2350
|
+
} catch (err) {
|
|
2351
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
2352
|
+
sendJson(res, 500, { error: message, kind: "INTERNAL_ERROR" });
|
|
2353
|
+
}
|
|
2354
|
+
});
|
|
2355
|
+
return server;
|
|
2356
|
+
}
|
|
2357
|
+
function listenOpenAPIHttpServer(server, options = {}) {
|
|
2358
|
+
return new Promise((resolve4, reject) => {
|
|
2359
|
+
const port = options.port ?? 0;
|
|
2360
|
+
const host = options.host ?? "localhost";
|
|
2361
|
+
server.listen(port, host, () => {
|
|
2362
|
+
const addr = server.address();
|
|
2363
|
+
const actualPort = typeof addr === "object" && addr?.port != null ? addr.port : port;
|
|
2364
|
+
resolve4({ port: actualPort, host });
|
|
2365
|
+
});
|
|
2366
|
+
server.on("error", reject);
|
|
2367
|
+
});
|
|
2368
|
+
}
|
|
2369
|
+
async function createHttpService(runtimeOrConfig, options = {}) {
|
|
2370
|
+
const runtime = "invoke" in runtimeOrConfig && typeof runtimeOrConfig.invoke === "function" ? runtimeOrConfig : (await createRuntimeFromConfig(runtimeOrConfig)).runtime;
|
|
2371
|
+
const server = createOpenAPIHttpServer(runtime, options);
|
|
2372
|
+
const openApiSpec = toolsToOpenAPISpec(runtime.getRegistry(), {
|
|
2373
|
+
title: options.title ?? "Tool API",
|
|
2374
|
+
version: options.version ?? "1.0.0",
|
|
2375
|
+
basePath: options.basePath
|
|
2376
|
+
});
|
|
2377
|
+
return {
|
|
2378
|
+
server,
|
|
2379
|
+
openApiSpec,
|
|
2380
|
+
listen: (listenOpts) => listenOpenAPIHttpServer(server, listenOpts)
|
|
2381
|
+
};
|
|
2382
|
+
}
|
|
2383
|
+
|
|
2072
2384
|
// src/tools/mcp/types.ts
|
|
2073
2385
|
var MCP_KIND = "mcp";
|
|
2074
2386
|
|
|
2387
|
+
// src/api/expose/mcpServer.ts
|
|
2388
|
+
var DEFAULT_CTX2 = {
|
|
2389
|
+
requestId: `mcp-${Date.now()}-${Math.random().toString(36).slice(2, 9)}`,
|
|
2390
|
+
taskId: `task-${Date.now()}`,
|
|
2391
|
+
permissions: [
|
|
2392
|
+
"read:web",
|
|
2393
|
+
"read:fs",
|
|
2394
|
+
"write:fs",
|
|
2395
|
+
"read:db",
|
|
2396
|
+
"write:db",
|
|
2397
|
+
"network",
|
|
2398
|
+
"workflow",
|
|
2399
|
+
"danger:destructive"
|
|
2400
|
+
]
|
|
2401
|
+
};
|
|
2402
|
+
function toMcpToolName(registryName) {
|
|
2403
|
+
return chunkDYDNPIV2_cjs.normalizeToolName(registryName);
|
|
2404
|
+
}
|
|
2405
|
+
async function createMcpServerWithTools(runtime, options) {
|
|
2406
|
+
const { McpServer } = await import('@modelcontextprotocol/sdk/server/mcp.js');
|
|
2407
|
+
const name = options.name ?? "agent-tool";
|
|
2408
|
+
const version = options.version ?? "1.0.0";
|
|
2409
|
+
const ctxFactory = options.execContextFactory ?? (() => ({ ...DEFAULT_CTX2 }));
|
|
2410
|
+
const server = new McpServer({ name, version });
|
|
2411
|
+
const registry = runtime.getRegistry();
|
|
2412
|
+
const specs = registry.snapshot();
|
|
2413
|
+
for (const spec of specs) {
|
|
2414
|
+
const mcpName = toMcpToolName(spec.name);
|
|
2415
|
+
server.registerTool(
|
|
2416
|
+
mcpName,
|
|
2417
|
+
{
|
|
2418
|
+
description: spec.description ?? `Tool: ${spec.name}`,
|
|
2419
|
+
inputSchema: spec.inputSchema,
|
|
2420
|
+
_meta: spec._meta
|
|
2421
|
+
},
|
|
2422
|
+
async (args) => {
|
|
2423
|
+
const ctx = ctxFactory();
|
|
2424
|
+
const result = await runtime.invoke(
|
|
2425
|
+
{ tool: spec.name, args: args ?? {}, purpose: MCP_KIND },
|
|
2426
|
+
ctx
|
|
2427
|
+
);
|
|
2428
|
+
if (result.ok) {
|
|
2429
|
+
return { content: [{ type: "text", text: JSON.stringify(result.result) }] };
|
|
2430
|
+
}
|
|
2431
|
+
const err = result.error;
|
|
2432
|
+
return {
|
|
2433
|
+
content: [
|
|
2434
|
+
{
|
|
2435
|
+
type: "text",
|
|
2436
|
+
text: JSON.stringify({ error: err?.message ?? "Tool failed", kind: err?.kind })
|
|
2437
|
+
}
|
|
2438
|
+
],
|
|
2439
|
+
isError: true
|
|
2440
|
+
};
|
|
2441
|
+
}
|
|
2442
|
+
);
|
|
2443
|
+
}
|
|
2444
|
+
return { server };
|
|
2445
|
+
}
|
|
2446
|
+
async function createMCPServer(runtimeOrConfig, options = {}) {
|
|
2447
|
+
const runtime = "invoke" in runtimeOrConfig && typeof runtimeOrConfig.invoke === "function" ? runtimeOrConfig : (await createRuntimeFromConfig(runtimeOrConfig)).runtime;
|
|
2448
|
+
const { StdioServerTransport } = await import('@modelcontextprotocol/sdk/server/stdio.js');
|
|
2449
|
+
const { server } = await createMcpServerWithTools(runtime, options);
|
|
2450
|
+
return {
|
|
2451
|
+
server,
|
|
2452
|
+
async connectStdio() {
|
|
2453
|
+
const transport = new StdioServerTransport();
|
|
2454
|
+
await server.connect(transport);
|
|
2455
|
+
}
|
|
2456
|
+
};
|
|
2457
|
+
}
|
|
2458
|
+
function createMCPStreamableHttpHandler(runtimeOrConfig, options = {}) {
|
|
2459
|
+
if ("invoke" in runtimeOrConfig && typeof runtimeOrConfig.invoke === "function") {
|
|
2460
|
+
const runtime = runtimeOrConfig;
|
|
2461
|
+
return async function streamableHttpHandler(req, res, parsedBody) {
|
|
2462
|
+
const { StreamableHTTPServerTransport } = await import('@modelcontextprotocol/sdk/server/streamableHttp.js');
|
|
2463
|
+
const { server } = await createMcpServerWithTools(runtime, options);
|
|
2464
|
+
const transport = new StreamableHTTPServerTransport({ sessionIdGenerator: void 0 });
|
|
2465
|
+
await server.connect(transport);
|
|
2466
|
+
const onClose = () => {
|
|
2467
|
+
transport.close().catch(() => {
|
|
2468
|
+
});
|
|
2469
|
+
server.close().catch(() => {
|
|
2470
|
+
});
|
|
2471
|
+
res.removeListener("close", onClose);
|
|
2472
|
+
res.removeListener("finish", onClose);
|
|
2473
|
+
};
|
|
2474
|
+
res.once("close", onClose);
|
|
2475
|
+
res.once("finish", onClose);
|
|
2476
|
+
await transport.handleRequest(
|
|
2477
|
+
req,
|
|
2478
|
+
res,
|
|
2479
|
+
parsedBody
|
|
2480
|
+
);
|
|
2481
|
+
};
|
|
2482
|
+
}
|
|
2483
|
+
return (async () => {
|
|
2484
|
+
const { runtime } = await createRuntimeFromConfig(runtimeOrConfig);
|
|
2485
|
+
return createMCPStreamableHttpHandler(runtime, options);
|
|
2486
|
+
})();
|
|
2487
|
+
}
|
|
2488
|
+
async function createMCPServerStreamableHttp(runtimeOrConfig, options = {}) {
|
|
2489
|
+
const path = options.path ?? "/mcp";
|
|
2490
|
+
const host = options.host ?? "127.0.0.1";
|
|
2491
|
+
const port = options.port ?? 3e3;
|
|
2492
|
+
const { createMcpExpressApp } = await import('@modelcontextprotocol/sdk/server/express.js');
|
|
2493
|
+
const handler = "invoke" in runtimeOrConfig && typeof runtimeOrConfig.invoke === "function" ? createMCPStreamableHttpHandler(runtimeOrConfig, options) : await createMCPStreamableHttpHandler(runtimeOrConfig, options);
|
|
2494
|
+
const app = createMcpExpressApp({ host });
|
|
2495
|
+
app.post(path, handler);
|
|
2496
|
+
return {
|
|
2497
|
+
app,
|
|
2498
|
+
path,
|
|
2499
|
+
async listen(listenPort, listenHost) {
|
|
2500
|
+
const p = listenPort ?? port;
|
|
2501
|
+
const h = listenHost ?? host;
|
|
2502
|
+
return new Promise((resolve4, reject) => {
|
|
2503
|
+
const server = app.listen(p, h, () => {
|
|
2504
|
+
const addr = server.address();
|
|
2505
|
+
const actualPort = typeof addr === "object" && addr !== null && "port" in addr ? addr.port : p;
|
|
2506
|
+
resolve4({ url: `http://${h}:${actualPort}${path}`, port: actualPort });
|
|
2507
|
+
});
|
|
2508
|
+
});
|
|
2509
|
+
}
|
|
2510
|
+
};
|
|
2511
|
+
}
|
|
2512
|
+
async function runMCPServerOverStdio(runtime, options = {}) {
|
|
2513
|
+
const result = await createMCPServer(runtime, options);
|
|
2514
|
+
await result.connectStdio();
|
|
2515
|
+
return result;
|
|
2516
|
+
}
|
|
2517
|
+
|
|
2075
2518
|
// src/tools/langchain/types.ts
|
|
2076
2519
|
var LANGCHAIN_KIND = "langchain";
|
|
2077
2520
|
var LANGCHAIN_DIR_NAME = "langchain";
|
|
2078
2521
|
|
|
2079
|
-
Object.defineProperty(exports, "ensurePackageInCache", {
|
|
2080
|
-
enumerable: true,
|
|
2081
|
-
get: function () { return npm.ensurePackageInCache; }
|
|
2082
|
-
});
|
|
2083
|
-
Object.defineProperty(exports, "getPackageEntryPath", {
|
|
2084
|
-
enumerable: true,
|
|
2085
|
-
get: function () { return npm.getPackageEntryPath; }
|
|
2086
|
-
});
|
|
2087
|
-
Object.defineProperty(exports, "importFromCache", {
|
|
2088
|
-
enumerable: true,
|
|
2089
|
-
get: function () { return npm.importFromCache; }
|
|
2090
|
-
});
|
|
2091
|
-
Object.defineProperty(exports, "resolveLatestVersionFromRegistry", {
|
|
2092
|
-
enumerable: true,
|
|
2093
|
-
get: function () { return npm.resolveLatestVersionFromRegistry; }
|
|
2094
|
-
});
|
|
2095
|
-
exports.BudgetManager = BudgetManager;
|
|
2096
|
-
exports.EventLog = EventLog;
|
|
2097
2522
|
exports.LANGCHAIN_DIR_NAME = LANGCHAIN_DIR_NAME;
|
|
2098
2523
|
exports.LANGCHAIN_KIND = LANGCHAIN_KIND;
|
|
2099
2524
|
exports.MCP_KIND = MCP_KIND;
|
|
2100
|
-
exports.Metrics = Metrics;
|
|
2101
2525
|
exports.PTCRuntime = PTCRuntime;
|
|
2102
|
-
exports.
|
|
2103
|
-
exports.
|
|
2104
|
-
exports.
|
|
2105
|
-
exports.
|
|
2106
|
-
exports.Tracing = Tracing;
|
|
2107
|
-
exports.buildEvidence = buildEvidence;
|
|
2108
|
-
exports.createLogger = createLogger;
|
|
2526
|
+
exports.createHttpService = createHttpService;
|
|
2527
|
+
exports.createMCPServer = createMCPServer;
|
|
2528
|
+
exports.createMCPServerStreamableHttp = createMCPServerStreamableHttp;
|
|
2529
|
+
exports.createMCPStreamableHttpHandler = createMCPStreamableHttpHandler;
|
|
2109
2530
|
exports.createRuntimeFromConfig = createRuntimeFromConfig;
|
|
2110
2531
|
exports.createRuntimeFromConfigSync = createRuntimeFromConfigSync;
|
|
2111
2532
|
exports.expandToolDescriptorsToRegistryNames = expandToolDescriptorsToRegistryNames;
|
|
@@ -2113,18 +2534,12 @@ exports.fileDescriptorToPackagePrefix = fileDescriptorToPackagePrefix;
|
|
|
2113
2534
|
exports.findAndLoadToolConfig = findAndLoadToolConfig;
|
|
2114
2535
|
exports.getDisplayScope = getDisplayScope;
|
|
2115
2536
|
exports.isBarePackageDescriptor = isBarePackageDescriptor;
|
|
2116
|
-
exports.isNpmToolDescriptor = isNpmToolDescriptor;
|
|
2117
2537
|
exports.loadToolConfig = loadToolConfig;
|
|
2118
|
-
exports.normalizeToolList = normalizeToolList;
|
|
2119
2538
|
exports.npmDescriptorToPackagePrefixWithVersion = npmDescriptorToPackagePrefixWithVersion;
|
|
2120
|
-
exports.npmDescriptorToRegistryPrefix = npmDescriptorToRegistryPrefix;
|
|
2121
|
-
exports.parseNpmToolDescriptor = parseNpmToolDescriptor;
|
|
2122
|
-
exports.resolveNpmToolDescriptor = resolveNpmToolDescriptor;
|
|
2123
2539
|
exports.resolveSandboxedPath = resolveSandboxedPath;
|
|
2124
2540
|
exports.resolveSandboxedPath2 = resolveSandboxedPath2;
|
|
2125
2541
|
exports.resolveToolDescriptor = resolveToolDescriptor;
|
|
2126
|
-
exports.
|
|
2542
|
+
exports.runMCPServerOverStdio = runMCPServerOverStdio;
|
|
2127
2543
|
exports.setSandboxValidationEnabled = setSandboxValidationEnabled;
|
|
2128
|
-
|
|
2129
|
-
//# sourceMappingURL=chunk-
|
|
2130
|
-
//# sourceMappingURL=chunk-XC7KPJLZ.cjs.map
|
|
2544
|
+
//# sourceMappingURL=chunk-A5B6Q6EG.cjs.map
|
|
2545
|
+
//# sourceMappingURL=chunk-A5B6Q6EG.cjs.map
|