@easynet/agent-tool 1.0.97 → 1.0.99
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 +16 -13
- package/config/tool.yaml +4 -5
- package/dist/agent-context.d.ts +1 -1
- package/dist/agent-context.d.ts.map +1 -1
- package/dist/api/createAgentTools.d.ts +1 -0
- package/dist/api/createAgentTools.d.ts.map +1 -1
- package/dist/api/expose/extension-init/initExtension.d.ts.map +1 -1
- package/dist/api/extension/registerExtension.d.ts +1 -0
- package/dist/api/extension/registerExtension.d.ts.map +1 -1
- package/dist/api/register-tools.d.ts +1 -0
- package/dist/api/register-tools.d.ts.map +1 -1
- package/dist/api/runtimeFromConfig.d.ts.map +1 -1
- package/dist/{chunk-WCMZLN3F.js → chunk-3TT5M7A3.js} +56 -52
- package/dist/chunk-3TT5M7A3.js.map +1 -0
- package/dist/{chunk-2TFGOUXN.cjs → chunk-TJUWCIYZ.cjs} +59 -54
- package/dist/chunk-TJUWCIYZ.cjs.map +1 -0
- package/dist/index.cjs +137 -50
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +128 -42
- package/dist/index.js.map +1 -1
- package/dist/sdk.cjs +15 -5
- package/dist/sdk.cjs.map +1 -1
- package/dist/sdk.js +15 -5
- package/dist/sdk.js.map +1 -1
- package/dist/tools/util/toolConfig.d.ts +5 -41
- package/dist/tools/util/toolConfig.d.ts.map +1 -1
- package/dist/tools/util/toolDescriptor.d.ts +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 +5 -6
- package/dist/utils/cli/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-2TFGOUXN.cjs.map +0 -1
- package/dist/chunk-WCMZLN3F.js.map +0 -1
|
@@ -46,6 +46,20 @@ function normalizeOpenApiConfig(raw) {
|
|
|
46
46
|
if (typeof source.port === "number" && Number.isFinite(source.port)) out.port = source.port;
|
|
47
47
|
return Object.keys(out).length > 0 ? out : void 0;
|
|
48
48
|
}
|
|
49
|
+
function normalizeToolSources(raw) {
|
|
50
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw)) return void 0;
|
|
51
|
+
const out = {};
|
|
52
|
+
for (const [sourceKey, sourceValue] of Object.entries(raw)) {
|
|
53
|
+
if (!sourceValue || typeof sourceValue !== "object" || Array.isArray(sourceValue)) continue;
|
|
54
|
+
const toolMap = {};
|
|
55
|
+
for (const [toolName, toolValue] of Object.entries(sourceValue)) {
|
|
56
|
+
if (!toolValue || typeof toolValue !== "object" || Array.isArray(toolValue)) continue;
|
|
57
|
+
toolMap[toolName] = toolValue;
|
|
58
|
+
}
|
|
59
|
+
out[sourceKey] = toolMap;
|
|
60
|
+
}
|
|
61
|
+
return Object.keys(out).length > 0 ? out : void 0;
|
|
62
|
+
}
|
|
49
63
|
function loadToolConfig(toolYamlPath) {
|
|
50
64
|
const abs = path.resolve(toolYamlPath);
|
|
51
65
|
const raw = fs.readFileSync(abs, "utf8");
|
|
@@ -54,41 +68,21 @@ function loadToolConfig(toolYamlPath) {
|
|
|
54
68
|
});
|
|
55
69
|
if (!parsed || typeof parsed !== "object") return {};
|
|
56
70
|
const source = parsed.spec && typeof parsed.spec === "object" && !Array.isArray(parsed.spec) ? parsed.spec : parsed;
|
|
57
|
-
const mcpConfig = normalizeMcpConfig(source.expose?.mcp ?? source.mcp);
|
|
58
|
-
const openApiConfig = normalizeOpenApiConfig(source.expose?.openapi ?? source.openapi);
|
|
59
|
-
const toolsBlock = source.tools;
|
|
60
|
-
if (toolsBlock != null && typeof toolsBlock === "object" && !Array.isArray(toolsBlock)) {
|
|
61
|
-
const toolDefaults = toolsBlock.defaults != null && typeof toolsBlock.defaults === "object" && !Array.isArray(toolsBlock.defaults) ? toolsBlock.defaults : void 0;
|
|
62
|
-
const packageToolDefaults2 = toolsBlock.packages != null && typeof toolsBlock.packages === "object" && !Array.isArray(toolsBlock.packages) ? toolsBlock.packages : void 0;
|
|
63
|
-
const list2 = Array.isArray(toolsBlock.list) && toolsBlock.list.length > 0 ? toolsBlock.list : void 0;
|
|
64
|
-
return {
|
|
65
|
-
tools: list2 ?? (packageToolDefaults2 ? Object.keys(packageToolDefaults2) : void 0),
|
|
66
|
-
sandboxedPath: typeof toolsBlock.sandboxedPath === "string" ? toolsBlock.sandboxedPath : source.sandboxedPath,
|
|
67
|
-
enableSandboxValidation: typeof toolsBlock.enableSandboxValidation === "boolean" ? toolsBlock.enableSandboxValidation : source.enableSandboxValidation,
|
|
68
|
-
allowedHosts: Array.isArray(toolsBlock.allowedHosts) ? toolsBlock.allowedHosts : source.allowedHosts,
|
|
69
|
-
blockedHosts: Array.isArray(toolsBlock.blockedHosts) ? toolsBlock.blockedHosts : source.blockedHosts,
|
|
70
|
-
blockedCidrs: Array.isArray(toolsBlock.blockedCidrs) ? toolsBlock.blockedCidrs : source.blockedCidrs,
|
|
71
|
-
toolDefaults,
|
|
72
|
-
packageToolDefaults: packageToolDefaults2,
|
|
73
|
-
mcp: mcpConfig,
|
|
74
|
-
openapi: openApiConfig
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
const packageToolDefaults = typeof source.packageToolDefaults === "object" && !Array.isArray(source.packageToolDefaults) ? source.packageToolDefaults : void 0;
|
|
78
|
-
const list = Array.isArray(source.tools) && source.tools.length > 0 ? source.tools : void 0;
|
|
79
71
|
return {
|
|
80
|
-
|
|
81
|
-
sandboxedPath: source.sandboxedPath,
|
|
72
|
+
sandboxedPath: typeof source.sandboxedPath === "string" ? source.sandboxedPath : void 0,
|
|
82
73
|
enableSandboxValidation: typeof source.enableSandboxValidation === "boolean" ? source.enableSandboxValidation : void 0,
|
|
83
74
|
allowedHosts: Array.isArray(source.allowedHosts) ? source.allowedHosts : void 0,
|
|
84
75
|
blockedHosts: Array.isArray(source.blockedHosts) ? source.blockedHosts : void 0,
|
|
85
76
|
blockedCidrs: Array.isArray(source.blockedCidrs) ? source.blockedCidrs : void 0,
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
openapi: openApiConfig
|
|
77
|
+
tools: normalizeToolSources(source.tools),
|
|
78
|
+
mcp: normalizeMcpConfig(source.expose?.mcp ?? source.mcp),
|
|
79
|
+
openapi: normalizeOpenApiConfig(source.expose?.openapi ?? source.openapi)
|
|
90
80
|
};
|
|
91
81
|
}
|
|
82
|
+
function getToolSourceDescriptors(config, options) {
|
|
83
|
+
const includeSelf = options?.includeSelf ?? false;
|
|
84
|
+
return Object.keys(config.tools ?? {}).filter((key) => includeSelf || key !== "self");
|
|
85
|
+
}
|
|
92
86
|
function resolveSandboxedPath(toolYamlPath, sandboxedPath) {
|
|
93
87
|
const configDir = path.dirname(path.resolve(toolYamlPath));
|
|
94
88
|
return config.resolveConfigPath(sandboxedPath, configDir, {
|
|
@@ -182,23 +176,6 @@ function npmDescriptorToPackagePrefix(descriptor) {
|
|
|
182
176
|
if (!normalized) return "";
|
|
183
177
|
return "npm." + normalized;
|
|
184
178
|
}
|
|
185
|
-
function npmDescriptorToPackagePrefixWithVersion(descriptor) {
|
|
186
|
-
const s = descriptor.trim();
|
|
187
|
-
if (typeof s !== "string" || !s.startsWith("npm:")) return "";
|
|
188
|
-
const rest = s.slice(4).trim();
|
|
189
|
-
const hashIdx = rest.indexOf("#");
|
|
190
|
-
const beforeHash = hashIdx < 0 ? rest : rest.slice(0, hashIdx);
|
|
191
|
-
const lastAt = beforeHash.lastIndexOf("@");
|
|
192
|
-
const scopeAndPackage = lastAt <= 0 ? beforeHash : beforeHash.slice(0, lastAt);
|
|
193
|
-
const version = lastAt <= 0 ? "" : beforeHash.slice(lastAt + 1).trim();
|
|
194
|
-
const slashIdx = scopeAndPackage.indexOf("/");
|
|
195
|
-
const scope = slashIdx < 0 ? scopeAndPackage : scopeAndPackage.slice(0, slashIdx).replace(/^@/, "");
|
|
196
|
-
const pkg = slashIdx < 0 ? "" : scopeAndPackage.slice(slashIdx + 1);
|
|
197
|
-
const segment = [scope, pkg, version].filter(Boolean).join(".");
|
|
198
|
-
const normalized = chunkJW4EMVTE_cjs.normalizeToolName(segment);
|
|
199
|
-
if (!normalized) return "";
|
|
200
|
-
return "npm." + normalized;
|
|
201
|
-
}
|
|
202
179
|
function getDisplayScope(registryName, _kind, _toolVersion) {
|
|
203
180
|
const i = registryName.indexOf(".");
|
|
204
181
|
return i < 0 ? registryName : registryName.slice(0, i);
|
|
@@ -1909,7 +1886,7 @@ async function importFromCache(packageRoot) {
|
|
|
1909
1886
|
fileUrl
|
|
1910
1887
|
);
|
|
1911
1888
|
}
|
|
1912
|
-
var requireFromPackage = module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('chunk-
|
|
1889
|
+
var requireFromPackage = module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('chunk-TJUWCIYZ.cjs', document.baseURI).href)));
|
|
1913
1890
|
function getProjectRequire() {
|
|
1914
1891
|
const cwd = process.cwd();
|
|
1915
1892
|
if (fs.existsSync(path.join(cwd, "package.json"))) return module$1.createRequire(path.join(cwd, "package.json"));
|
|
@@ -2075,7 +2052,7 @@ function parseNpmDescriptor(entry) {
|
|
|
2075
2052
|
}
|
|
2076
2053
|
|
|
2077
2054
|
// src/api/runtimeFromConfig.ts
|
|
2078
|
-
var requireFromPackage2 = module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('chunk-
|
|
2055
|
+
var requireFromPackage2 = module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('chunk-TJUWCIYZ.cjs', document.baseURI).href)));
|
|
2079
2056
|
var DEFAULT_EXTENSION_PACKAGES = [];
|
|
2080
2057
|
function resolveFileDescriptorPath(descriptor, configFilePath) {
|
|
2081
2058
|
const parsed = parseToolPath(descriptor.trim());
|
|
@@ -2122,7 +2099,34 @@ function loadExtensionFromFileDescriptorSync(descriptor, configFilePath, stepLog
|
|
|
2122
2099
|
if (stepLog) stepLog(`Loaded local extension from ${resolvedPath}`);
|
|
2123
2100
|
return { register: fn, descriptor: entryStr, resolvedVersion: "local", packageRoot: resolvedPath };
|
|
2124
2101
|
}
|
|
2125
|
-
} catch {
|
|
2102
|
+
} catch (error) {
|
|
2103
|
+
if (stepLog) {
|
|
2104
|
+
stepLog(`Failed to load local extension from ${resolvedPath}: ${error instanceof Error ? error.message : String(error)}`);
|
|
2105
|
+
}
|
|
2106
|
+
}
|
|
2107
|
+
return null;
|
|
2108
|
+
}
|
|
2109
|
+
async function loadExtensionFromFileDescriptorAsync(descriptor, configFilePath, stepLog) {
|
|
2110
|
+
const entryStr = descriptor.trim();
|
|
2111
|
+
const path2 = parseToolPath(entryStr);
|
|
2112
|
+
if (!path2 || path2.protocol !== "file") return null;
|
|
2113
|
+
const localPath = path.isAbsolute(configFilePath) ? configFilePath : path.resolve(process.cwd(), configFilePath);
|
|
2114
|
+
const configDir = path.dirname(localPath);
|
|
2115
|
+
const pathPart = `${path2.scope}/${path2.packageWithVersion}`;
|
|
2116
|
+
const resolvedPath = path.resolve(configDir, pathPart);
|
|
2117
|
+
if (!fs.existsSync(resolvedPath) || !fs.statSync(resolvedPath).isDirectory()) return null;
|
|
2118
|
+
try {
|
|
2119
|
+
const entryPath = getPackageEntryPath(resolvedPath);
|
|
2120
|
+
const mod = await import(url.pathToFileURL(entryPath).href);
|
|
2121
|
+
const fn = getRegisterFn(mod);
|
|
2122
|
+
if (typeof fn === "function") {
|
|
2123
|
+
if (stepLog) stepLog(`Loaded local extension from ${resolvedPath} (async import)`);
|
|
2124
|
+
return { register: fn, descriptor: entryStr, resolvedVersion: "local", packageRoot: resolvedPath };
|
|
2125
|
+
}
|
|
2126
|
+
} catch (error) {
|
|
2127
|
+
if (stepLog) {
|
|
2128
|
+
stepLog(`Failed to load local extension from ${resolvedPath}: ${error instanceof Error ? error.message : String(error)}`);
|
|
2129
|
+
}
|
|
2126
2130
|
}
|
|
2127
2131
|
return null;
|
|
2128
2132
|
}
|
|
@@ -2178,7 +2182,7 @@ function loadAllExtensionsFromToolYamlSync(configFilePath, stepLog) {
|
|
|
2178
2182
|
const localPath = path.isAbsolute(configFilePath) ? configFilePath : path.resolve(process.cwd(), configFilePath);
|
|
2179
2183
|
if (!fs.existsSync(localPath)) return [];
|
|
2180
2184
|
const config = loadToolConfig(localPath);
|
|
2181
|
-
const tools = config
|
|
2185
|
+
const tools = getToolSourceDescriptors(config);
|
|
2182
2186
|
if (!Array.isArray(tools) || tools.length === 0) return [];
|
|
2183
2187
|
if (stepLog) stepLog("Loading extensions from tool.yaml (npm + file)");
|
|
2184
2188
|
const loaded = [];
|
|
@@ -2281,7 +2285,7 @@ async function loadAllExtensionsFromToolYamlAsync(configFilePath, stepLog) {
|
|
|
2281
2285
|
const localPath = path.isAbsolute(configFilePath) ? configFilePath : path.resolve(process.cwd(), configFilePath);
|
|
2282
2286
|
if (!fs.existsSync(localPath)) return [];
|
|
2283
2287
|
const config = loadToolConfig(localPath);
|
|
2284
|
-
const tools = config
|
|
2288
|
+
const tools = getToolSourceDescriptors(config);
|
|
2285
2289
|
if (!Array.isArray(tools) || tools.length === 0) return [];
|
|
2286
2290
|
if (stepLog) stepLog("Loading extensions from tool.yaml (async)");
|
|
2287
2291
|
const loaded = [];
|
|
@@ -2291,7 +2295,7 @@ async function loadAllExtensionsFromToolYamlAsync(configFilePath, stepLog) {
|
|
|
2291
2295
|
const result = await loadExtensionForDescriptorAsync(entryStr, configFilePath, stepLog);
|
|
2292
2296
|
if (result) loaded.push(result);
|
|
2293
2297
|
} else if (entryStr.startsWith("file:")) {
|
|
2294
|
-
const result =
|
|
2298
|
+
const result = await loadExtensionFromFileDescriptorAsync(entryStr, configFilePath, stepLog);
|
|
2295
2299
|
if (result) {
|
|
2296
2300
|
loaded.push(result);
|
|
2297
2301
|
} else {
|
|
@@ -2949,13 +2953,14 @@ exports.expandToolDescriptorsToRegistryNames = expandToolDescriptorsToRegistryNa
|
|
|
2949
2953
|
exports.fileDescriptorToPackagePrefix = fileDescriptorToPackagePrefix;
|
|
2950
2954
|
exports.findAndLoadToolConfig = findAndLoadToolConfig;
|
|
2951
2955
|
exports.getDisplayScope = getDisplayScope;
|
|
2956
|
+
exports.getToolSourceDescriptors = getToolSourceDescriptors;
|
|
2952
2957
|
exports.isBarePackageDescriptor = isBarePackageDescriptor;
|
|
2953
2958
|
exports.loadAllExtensionsFromToolYamlSync = loadAllExtensionsFromToolYamlSync;
|
|
2954
2959
|
exports.loadToolConfig = loadToolConfig;
|
|
2955
|
-
exports.
|
|
2960
|
+
exports.npmDescriptorToPackagePrefix = npmDescriptorToPackagePrefix;
|
|
2956
2961
|
exports.resolveSandboxedPath = resolveSandboxedPath;
|
|
2957
2962
|
exports.resolveToolDescriptor = resolveToolDescriptor;
|
|
2958
2963
|
exports.runMCPServerOverStdio = runMCPServerOverStdio;
|
|
2959
2964
|
exports.toToolObservationText = toToolObservationText;
|
|
2960
|
-
//# sourceMappingURL=chunk-
|
|
2961
|
-
//# sourceMappingURL=chunk-
|
|
2965
|
+
//# sourceMappingURL=chunk-TJUWCIYZ.cjs.map
|
|
2966
|
+
//# sourceMappingURL=chunk-TJUWCIYZ.cjs.map
|