@easynet/agent-tool 1.0.59 → 1.0.61
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/dist/api/expose/index.d.ts +1 -1
- package/dist/api/expose/index.d.ts.map +1 -1
- package/dist/api/expose/mcp-build/build.d.ts +1 -3
- package/dist/api/expose/mcp-build/build.d.ts.map +1 -1
- package/dist/api/expose/mcp-build/index.d.ts +2 -2
- package/dist/api/expose/mcp-build/index.d.ts.map +1 -1
- package/dist/api/expose/mcp-build/run.d.ts +1 -3
- package/dist/api/expose/mcp-build/run.d.ts.map +1 -1
- package/dist/api/main.cjs +19 -15
- package/dist/api/main.js +8 -4
- package/dist/build.cjs +31 -0
- package/dist/build.cjs.map +1 -0
- package/dist/build.d.ts +13 -0
- package/dist/build.d.ts.map +1 -0
- package/dist/build.js +6 -0
- package/dist/build.js.map +1 -0
- package/dist/chunk-45S2HPVU.js +463 -0
- package/dist/chunk-45S2HPVU.js.map +1 -0
- package/dist/{chunk-Y75CRPVF.js → chunk-5J27MF7S.js} +11 -12
- package/dist/chunk-5J27MF7S.js.map +1 -0
- package/dist/{chunk-JXYANBTH.cjs → chunk-HK4GTFTQ.cjs} +57 -1645
- package/dist/chunk-HK4GTFTQ.cjs.map +1 -0
- package/dist/chunk-JNIWNSCQ.cjs +494 -0
- package/dist/chunk-JNIWNSCQ.cjs.map +1 -0
- package/dist/{chunk-DPOLJN7F.cjs → chunk-NMZ4IMEW.cjs} +22 -25
- package/dist/chunk-NMZ4IMEW.cjs.map +1 -0
- package/dist/{chunk-A5C2MUNA.js → chunk-NVT4X4CB.js} +41 -1600
- package/dist/chunk-NVT4X4CB.js.map +1 -0
- package/dist/chunk-OG5ZSXQ5.cjs +1099 -0
- package/dist/chunk-OG5ZSXQ5.cjs.map +1 -0
- package/dist/{chunk-WQMHMPNC.cjs → chunk-PYCCJF7C.cjs} +2 -68
- package/dist/chunk-PYCCJF7C.cjs.map +1 -0
- package/dist/{chunk-IWM5B5DU.js → chunk-QPKBEU64.js} +4 -3
- package/dist/chunk-QPKBEU64.js.map +1 -0
- package/dist/chunk-QXQ4477T.js +49 -0
- package/dist/chunk-QXQ4477T.js.map +1 -0
- package/dist/chunk-RZTTO5MQ.js +65 -0
- package/dist/chunk-RZTTO5MQ.js.map +1 -0
- package/dist/{chunk-FCYBA7PR.js → chunk-WUMLZERG.js} +3 -62
- package/dist/chunk-WUMLZERG.js.map +1 -0
- package/dist/chunk-XPGHS4W7.cjs +73 -0
- package/dist/chunk-XPGHS4W7.cjs.map +1 -0
- package/dist/chunk-YRFUGA3C.js +1072 -0
- package/dist/chunk-YRFUGA3C.js.map +1 -0
- package/dist/chunk-ZDSZHEQU.cjs +52 -0
- package/dist/chunk-ZDSZHEQU.cjs.map +1 -0
- package/dist/{chunk-MUBZV65R.cjs → chunk-ZH5MH3AK.cjs} +16 -15
- package/dist/chunk-ZH5MH3AK.cjs.map +1 -0
- package/dist/core/runtime.cjs +6 -5
- package/dist/core/runtime.js +2 -1
- package/dist/extension.cjs +359 -0
- package/dist/extension.cjs.map +1 -0
- package/dist/extension.d.ts +6 -0
- package/dist/extension.d.ts.map +1 -0
- package/dist/extension.js +341 -0
- package/dist/extension.js.map +1 -0
- package/dist/index.cjs +17 -609
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -25
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -520
- package/dist/index.js.map +1 -1
- package/dist/security.cjs +193 -0
- package/dist/security.cjs.map +1 -0
- package/dist/security.d.ts +6 -0
- package/dist/security.d.ts.map +1 -0
- package/dist/security.js +182 -0
- package/dist/security.js.map +1 -0
- package/dist/utils/cli/index.cjs +25 -21
- package/dist/utils/cli/index.cjs.map +1 -1
- package/dist/utils/cli/index.js +13 -9
- package/dist/utils/cli/index.js.map +1 -1
- package/package.json +16 -2
- package/dist/chunk-A5C2MUNA.js.map +0 -1
- package/dist/chunk-DPOLJN7F.cjs.map +0 -1
- package/dist/chunk-FCYBA7PR.js.map +0 -1
- package/dist/chunk-IWM5B5DU.js.map +0 -1
- package/dist/chunk-JXYANBTH.cjs.map +0 -1
- package/dist/chunk-MUBZV65R.cjs.map +0 -1
- package/dist/chunk-WQMHMPNC.cjs.map +0 -1
- package/dist/chunk-Y75CRPVF.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,523 +1,11 @@
|
|
|
1
|
-
export { createAgentTools, createLangChainToolsAsync } from './chunk-
|
|
2
|
-
export {
|
|
3
|
-
import { scanForTools } from './chunk-A5C2MUNA.js';
|
|
4
|
-
export { PTCRuntime, createMCPServer, createMCPServerStreamableHttp, createMCPStreamableHttpHandler, createHttpService as createOpenAPIServer, createRuntimeFromConfig, createRuntimeFromConfigSync, loadToolConfig, resolveSandboxedPath2 as resolveSandboxedPath, runMCPServerOverStdio, scan, scanForTools, setSandboxValidationEnabled } from './chunk-A5C2MUNA.js';
|
|
5
|
-
import { createTaggedError } from './chunk-FCYBA7PR.js';
|
|
6
|
-
export { ToolRegistry, createTaggedError } from './chunk-FCYBA7PR.js';
|
|
7
|
-
import { createToolSpec } from './chunk-ODEHUAR4.js';
|
|
8
|
-
export { DEFAULT_INPUT_SCHEMA, DEFAULT_OUTPUT_SCHEMA, createToolSpec, normalizeToolName } from './chunk-ODEHUAR4.js';
|
|
1
|
+
export { createAgentTools, createLangChainToolsAsync } from './chunk-QPKBEU64.js';
|
|
2
|
+
export { createMCPServer, createMCPServerStreamableHttp, createMCPStreamableHttpHandler, createHttpService as createOpenAPIServer, createRuntimeFromConfig, createRuntimeFromConfigSync, runMCPServerOverStdio } from './chunk-NVT4X4CB.js';
|
|
9
3
|
import './chunk-NTWOVFEY.js';
|
|
10
|
-
import
|
|
11
|
-
import
|
|
12
|
-
import
|
|
13
|
-
import
|
|
14
|
-
import
|
|
15
|
-
import
|
|
16
|
-
|
|
17
|
-
function createContextRunner() {
|
|
18
|
-
const storage = new AsyncLocalStorage();
|
|
19
|
-
return {
|
|
20
|
-
runWith(ctx, fn) {
|
|
21
|
-
return storage.run(ctx, fn);
|
|
22
|
-
},
|
|
23
|
-
getContext() {
|
|
24
|
-
const ctx = storage.getStore();
|
|
25
|
-
if (ctx === void 0) {
|
|
26
|
-
throw new Error("Extension context not set; invoke only through the extension adapter.");
|
|
27
|
-
}
|
|
28
|
-
return ctx;
|
|
29
|
-
}
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
function unwrapArgsForHandler(spec, args) {
|
|
33
|
-
if (args == null || typeof args !== "object" || Array.isArray(args)) return args;
|
|
34
|
-
const s = spec.inputSchema;
|
|
35
|
-
if (s?.type !== "object" || !s.properties || typeof s.properties !== "object") return args;
|
|
36
|
-
const props = s.properties;
|
|
37
|
-
const argsProp = props.args;
|
|
38
|
-
if (argsProp != null && typeof argsProp === "object" && argsProp.type === "object" && argsProp.properties != null) {
|
|
39
|
-
const obj = args;
|
|
40
|
-
if (Object.keys(obj).length === 1 && "args" in obj && typeof obj.args === "object" && obj.args !== null) {
|
|
41
|
-
return obj.args;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
return args;
|
|
45
|
-
}
|
|
46
|
-
function createDynamicImportAdapter(options) {
|
|
47
|
-
const { kind, packageRoot, getExtensionContext, contextRunner } = options;
|
|
48
|
-
return {
|
|
49
|
-
kind,
|
|
50
|
-
async invoke(spec, args, execCtx) {
|
|
51
|
-
const meta = spec._meta;
|
|
52
|
-
const sourcePath = meta?.sourcePath;
|
|
53
|
-
const exportName = meta?.exportName;
|
|
54
|
-
if (!sourcePath || !exportName) {
|
|
55
|
-
throw new Error(`Extension tool ${spec.name} missing _meta.sourcePath or _meta.exportName`);
|
|
56
|
-
}
|
|
57
|
-
const defaultArgs = meta?.defaultArgs ?? {};
|
|
58
|
-
const mergedArgs = Object.keys(defaultArgs).length === 0 ? args : { ...defaultArgs, ...args };
|
|
59
|
-
const handlerArgs = unwrapArgsForHandler(spec, mergedArgs);
|
|
60
|
-
const resolvedPackageRoot = meta?.packageRoot ?? packageRoot;
|
|
61
|
-
const modulePath = path6.join(resolvedPackageRoot, `${sourcePath}.js`);
|
|
62
|
-
const mod = await import(pathToFileURL(modulePath).href);
|
|
63
|
-
const handler = mod[exportName];
|
|
64
|
-
if (typeof handler !== "function") {
|
|
65
|
-
throw new Error(
|
|
66
|
-
`Extension tool ${spec.name}: export "${exportName}" from ${sourcePath} is not a function`
|
|
67
|
-
);
|
|
68
|
-
}
|
|
69
|
-
const ctx = getExtensionContext(execCtx, spec, mergedArgs);
|
|
70
|
-
const output = await contextRunner.runWith(ctx, () => handler(handlerArgs));
|
|
71
|
-
return {
|
|
72
|
-
result: { result: output.result, evidence: output.evidence },
|
|
73
|
-
raw: { evidence: output.evidence }
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
|
-
function loadToolYaml(packageRoot, sourcePath) {
|
|
79
|
-
const dir = path6.dirname(sourcePath);
|
|
80
|
-
const base = path6.basename(sourcePath);
|
|
81
|
-
const dirPath = path6.join(packageRoot, dir);
|
|
82
|
-
const yamlPath = existsSync(path6.join(dirPath, `${base}.tool.yaml`)) ? path6.join(dirPath, `${base}.tool.yaml`) : path6.join(dirPath, `${base}.example.yaml`);
|
|
83
|
-
if (!existsSync(yamlPath)) return void 0;
|
|
84
|
-
try {
|
|
85
|
-
const raw = readFileSync(yamlPath, "utf-8");
|
|
86
|
-
const data = yaml.load(raw);
|
|
87
|
-
if (data == null || typeof data !== "object" || Array.isArray(data)) return void 0;
|
|
88
|
-
const obj = data;
|
|
89
|
-
const toolBlock = obj?.tool;
|
|
90
|
-
const arr = toolBlock?.list;
|
|
91
|
-
if (!Array.isArray(arr)) return void 0;
|
|
92
|
-
const defaults = toolBlock?.defaults != null && typeof toolBlock.defaults === "object" && !Array.isArray(toolBlock.defaults) ? toolBlock.defaults : {};
|
|
93
|
-
const item = arr.find(
|
|
94
|
-
(e) => e != null && typeof e === "object" && e.name === base
|
|
95
|
-
);
|
|
96
|
-
if (!item || typeof item !== "object") return void 0;
|
|
97
|
-
const { name: _n, ...rest } = item;
|
|
98
|
-
const merged = { ...defaults, ...rest };
|
|
99
|
-
if (Object.keys(merged).length === 0) return void 0;
|
|
100
|
-
return merged;
|
|
101
|
-
} catch {
|
|
102
|
-
return void 0;
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
// src/api/extension/registerFromManifest.ts
|
|
107
|
-
function loadExtensionManifest(manifestPathOrDir) {
|
|
108
|
-
const p = path6.resolve(manifestPathOrDir);
|
|
109
|
-
let manifestPath;
|
|
110
|
-
if (existsSync(p) && statSync(p).isFile()) {
|
|
111
|
-
manifestPath = p;
|
|
112
|
-
} else {
|
|
113
|
-
const inDir = path6.join(p, "core-tools-manifest.json");
|
|
114
|
-
const inDist = path6.join(p, "dist", "core-tools-manifest.json");
|
|
115
|
-
manifestPath = existsSync(inDir) ? inDir : inDist;
|
|
116
|
-
}
|
|
117
|
-
const raw = readFileSync(manifestPath, "utf-8");
|
|
118
|
-
const parsed = JSON.parse(raw);
|
|
119
|
-
if (Array.isArray(parsed)) {
|
|
120
|
-
return { entries: parsed };
|
|
121
|
-
}
|
|
122
|
-
return { kind: parsed.kind, entries: parsed.tools ?? [] };
|
|
123
|
-
}
|
|
124
|
-
function registerToolsFromManifest(registry, options) {
|
|
125
|
-
const { manifestPathOrDir, kind: kindOpt, only, namePrefixes, packageRoot } = options;
|
|
126
|
-
const loaded = loadExtensionManifest(manifestPathOrDir);
|
|
127
|
-
const kind = kindOpt ?? loaded.kind ?? "extension";
|
|
128
|
-
const entries = loaded.entries;
|
|
129
|
-
const onlySet = only?.length ? new Set(only) : null;
|
|
130
|
-
const registered = [];
|
|
131
|
-
for (const entry of entries) {
|
|
132
|
-
const toolName = entry.name ?? (entry.coreName != null ? entry.coreName.replace(/^[^/]+\//, "").replace(/^src\./, "") : entry.sourcePath.replace(/^src\//, "").replace(/\//g, "."));
|
|
133
|
-
let spec = createToolSpec({
|
|
134
|
-
name: toolName,
|
|
135
|
-
kind,
|
|
136
|
-
description: entry.description,
|
|
137
|
-
inputSchema: entry.inputSchema,
|
|
138
|
-
outputSchema: entry.outputSchema,
|
|
139
|
-
capabilities: [],
|
|
140
|
-
sideEffect: entry.sideEffect
|
|
141
|
-
});
|
|
142
|
-
if (onlySet && !onlySet.has(spec.name)) continue;
|
|
143
|
-
if (namePrefixes?.length && !namePrefixes.some((prefix) => spec.name.startsWith(prefix))) {
|
|
144
|
-
continue;
|
|
145
|
-
}
|
|
146
|
-
const defaultArgs = packageRoot != null ? loadToolYaml(packageRoot, entry.sourcePath) : void 0;
|
|
147
|
-
spec = {
|
|
148
|
-
...spec,
|
|
149
|
-
_meta: {
|
|
150
|
-
...spec._meta,
|
|
151
|
-
sourcePath: entry.sourcePath,
|
|
152
|
-
exportName: entry.exportName,
|
|
153
|
-
shortName: toolName,
|
|
154
|
-
...packageRoot != null && { packageRoot },
|
|
155
|
-
...defaultArgs != null && Object.keys(defaultArgs).length > 0 && { defaultArgs }
|
|
156
|
-
}
|
|
157
|
-
};
|
|
158
|
-
registry.register(spec);
|
|
159
|
-
registered.push(spec);
|
|
160
|
-
}
|
|
161
|
-
return registered;
|
|
162
|
-
}
|
|
163
|
-
function resolveExtensionPackageRoot(metaUrlOrPath) {
|
|
164
|
-
const dir = metaUrlOrPath.startsWith("file:") ? path6.dirname(fileURLToPath(metaUrlOrPath)) : path6.resolve(metaUrlOrPath);
|
|
165
|
-
const dist = path6.join(dir, "dist");
|
|
166
|
-
return existsSync(dist) ? dist : dir;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
// src/api/extension/registerExtension.ts
|
|
170
|
-
function registerExtension(registry, options) {
|
|
171
|
-
const { packagePath, kind: kindOpt, config, getContextRunner, only, namePrefixes } = options;
|
|
172
|
-
const packageRoot = resolveExtensionPackageRoot(packagePath);
|
|
173
|
-
const contextRunner = getContextRunner();
|
|
174
|
-
const loaded = loadExtensionManifest(packagePath);
|
|
175
|
-
const kind = kindOpt ?? loaded.kind ?? "extension";
|
|
176
|
-
registerToolsFromManifest(registry, {
|
|
177
|
-
manifestPathOrDir: packagePath,
|
|
178
|
-
kind,
|
|
179
|
-
only,
|
|
180
|
-
namePrefixes,
|
|
181
|
-
packageRoot
|
|
182
|
-
});
|
|
183
|
-
const adapter = createDynamicImportAdapter({
|
|
184
|
-
kind,
|
|
185
|
-
packageRoot,
|
|
186
|
-
getExtensionContext: (execCtx, spec, mergedArgs) => {
|
|
187
|
-
const defaultArgs = spec._meta?.defaultArgs ?? {};
|
|
188
|
-
const baseConfig = config !== void 0 ? config : {};
|
|
189
|
-
const toolOverrides = baseConfig?.toolOverrides;
|
|
190
|
-
const shortName = spec._meta?.shortName ?? spec.name;
|
|
191
|
-
const prefixWithVersion = shortName && spec.name.endsWith(shortName) && spec.name.length > shortName.length ? spec.name.slice(0, spec.name.length - shortName.length - 1) : "";
|
|
192
|
-
const parts = prefixWithVersion ? prefixWithVersion.split(".") : [];
|
|
193
|
-
const packageScopedKey = parts.length > 1 ? `${parts.slice(0, -1).join(".")}::${shortName}` : "";
|
|
194
|
-
const perTool = toolOverrides?.[spec.name] ?? (packageScopedKey ? toolOverrides?.[packageScopedKey] : void 0) ?? toolOverrides?.[shortName] ?? {};
|
|
195
|
-
const packagePrefix = parts.length > 1 ? parts.slice(0, -1).join(".") : "";
|
|
196
|
-
const packageDefaults = baseConfig?.packageDefaults;
|
|
197
|
-
const packageDefaultsForPkg = (packagePrefix && packageDefaults?.[packagePrefix]) ?? (prefixWithVersion && packageDefaults?.[prefixWithVersion]) ?? {};
|
|
198
|
-
const baseWithoutOverrides = { ...baseConfig };
|
|
199
|
-
delete baseWithoutOverrides.toolOverrides;
|
|
200
|
-
delete baseWithoutOverrides.packageDefaults;
|
|
201
|
-
const resolvedConfig = {
|
|
202
|
-
...defaultArgs,
|
|
203
|
-
...baseWithoutOverrides,
|
|
204
|
-
...packageDefaultsForPkg,
|
|
205
|
-
...perTool,
|
|
206
|
-
...mergedArgs ?? {}
|
|
207
|
-
};
|
|
208
|
-
return { execCtx, config: resolvedConfig };
|
|
209
|
-
},
|
|
210
|
-
contextRunner: {
|
|
211
|
-
runWith(ctx, fn) {
|
|
212
|
-
return contextRunner.runWith(ctx, fn);
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
});
|
|
216
|
-
return adapter;
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
// src/api/extension/createExtension.ts
|
|
220
|
-
function resolvePackagePath(options) {
|
|
221
|
-
if (options.packagePath != null && options.packagePath !== "") return options.packagePath;
|
|
222
|
-
if (options.importMeta?.url) return path6.dirname(fileURLToPath(options.importMeta.url));
|
|
223
|
-
throw new Error("createExtension: provide packagePath or importMeta");
|
|
224
|
-
}
|
|
225
|
-
function createExtension(options) {
|
|
226
|
-
const packagePath = resolvePackagePath(options);
|
|
227
|
-
const kind = options.kind;
|
|
228
|
-
const buildConfig = "buildConfig" in options ? options.buildConfig : void 0;
|
|
229
|
-
const contextRunner = createContextRunner();
|
|
230
|
-
return {
|
|
231
|
-
register(registry, userConfigOrOpts, opts) {
|
|
232
|
-
const config = buildConfig ? buildConfig(userConfigOrOpts) : userConfigOrOpts;
|
|
233
|
-
return registerExtension(registry, {
|
|
234
|
-
packagePath,
|
|
235
|
-
kind,
|
|
236
|
-
config,
|
|
237
|
-
getContextRunner: () => contextRunner,
|
|
238
|
-
only: opts?.only ?? userConfigOrOpts?.only,
|
|
239
|
-
namePrefixes: opts?.namePrefixes ?? userConfigOrOpts?.namePrefixes
|
|
240
|
-
});
|
|
241
|
-
},
|
|
242
|
-
getContext() {
|
|
243
|
-
return contextRunner.getContext();
|
|
244
|
-
},
|
|
245
|
-
runWith(ctx, fn) {
|
|
246
|
-
return contextRunner.runWith(ctx, fn);
|
|
247
|
-
}
|
|
248
|
-
};
|
|
249
|
-
}
|
|
250
|
-
function copyToolYamlRecursive(srcDir, destDir) {
|
|
251
|
-
if (!existsSync(srcDir)) return 0;
|
|
252
|
-
let copied = 0;
|
|
253
|
-
for (const e of readdirSync(srcDir, { withFileTypes: true })) {
|
|
254
|
-
const srcPath = path6.join(srcDir, e.name);
|
|
255
|
-
const destPath = path6.join(destDir, e.name);
|
|
256
|
-
if (e.isFile() && (e.name.endsWith(".tool.yaml") || e.name.endsWith(".example.yaml"))) {
|
|
257
|
-
if (!existsSync(destDir)) mkdirSync(destDir, { recursive: true });
|
|
258
|
-
copyFileSync(srcPath, destPath);
|
|
259
|
-
copied++;
|
|
260
|
-
} else if (e.isDirectory()) {
|
|
261
|
-
copied += copyToolYamlRecursive(srcPath, destPath);
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
return copied;
|
|
265
|
-
}
|
|
266
|
-
function generateExtensionManifest(projectRoot = process.cwd(), options = {}) {
|
|
267
|
-
const root = path6.resolve(projectRoot);
|
|
268
|
-
const outDir = path6.resolve(options.outDir ?? path6.join(root, "dist"));
|
|
269
|
-
const kind = options.kind ?? "core";
|
|
270
|
-
const { specs, errors } = scanForTools({
|
|
271
|
-
projectPath: root,
|
|
272
|
-
include: options.include ?? ["**/*.ts"],
|
|
273
|
-
tsconfigPath: options.tsconfigPath
|
|
274
|
-
});
|
|
275
|
-
if (errors.length > 0) {
|
|
276
|
-
console.warn("generateExtensionManifest: scan errors", errors);
|
|
277
|
-
}
|
|
278
|
-
const entries = specs.map((spec) => {
|
|
279
|
-
const sourcePathNoExt = (spec.sourcePath ?? "").replace(/\.(ts|tsx)$/i, "");
|
|
280
|
-
const pathBasedName = sourcePathNoExt.replace(/^src\//, "").replace(/\//g, ".");
|
|
281
|
-
const name = spec.exportName ?? pathBasedName;
|
|
282
|
-
const sideEffect = spec._meta?.hitl?.sideEffect ?? "none";
|
|
283
|
-
return {
|
|
284
|
-
name,
|
|
285
|
-
description: spec.description ?? sourcePathNoExt,
|
|
286
|
-
inputSchema: spec.inputSchema ?? { type: "object", additionalProperties: true },
|
|
287
|
-
outputSchema: spec.outputSchema ?? { type: "object", additionalProperties: true },
|
|
288
|
-
sourcePath: sourcePathNoExt,
|
|
289
|
-
exportName: spec.exportName ?? "",
|
|
290
|
-
sideEffect
|
|
291
|
-
};
|
|
292
|
-
});
|
|
293
|
-
if (!existsSync(outDir)) mkdirSync(outDir, { recursive: true });
|
|
294
|
-
const manifestPath = path6.join(outDir, "core-tools-manifest.json");
|
|
295
|
-
writeFileSync(
|
|
296
|
-
manifestPath,
|
|
297
|
-
JSON.stringify({ kind, tools: entries }, null, 2),
|
|
298
|
-
"utf-8"
|
|
299
|
-
);
|
|
300
|
-
let toolYamlCopied = 0;
|
|
301
|
-
const copyDirs = options.copyToolYamlDirs;
|
|
302
|
-
if (copyDirs?.length) {
|
|
303
|
-
for (const d of copyDirs) {
|
|
304
|
-
const srcDir = path6.join(root, d);
|
|
305
|
-
const destDir = path6.join(outDir, d);
|
|
306
|
-
try {
|
|
307
|
-
toolYamlCopied += copyToolYamlRecursive(srcDir, destDir);
|
|
308
|
-
} catch {
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
return { manifestPath, toolsCount: entries.length, toolYamlCopied };
|
|
313
|
-
}
|
|
314
|
-
function generateManifest(projectRoot = process.cwd(), options = {}) {
|
|
315
|
-
const { manifestPath, toolsCount, toolYamlCopied } = generateExtensionManifest(projectRoot, {
|
|
316
|
-
include: ["src/**/*.ts"],
|
|
317
|
-
copyToolYamlDirs: ["src"],
|
|
318
|
-
...options
|
|
319
|
-
});
|
|
320
|
-
console.log(`Wrote ${toolsCount} tools to ${path6.relative(projectRoot, manifestPath)}`);
|
|
321
|
-
if (toolYamlCopied > 0) console.log(`Copied ${toolYamlCopied} .tool.yaml/.example.yaml file(s) to dist`);
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
// src/api/extension/overrideWithConfig.ts
|
|
325
|
-
function overrideWithConfig(defaults, config) {
|
|
326
|
-
const c = config != null && typeof config === "object" && !Array.isArray(config) ? config : {};
|
|
327
|
-
const out = { ...defaults };
|
|
328
|
-
for (const key of Object.keys(defaults)) {
|
|
329
|
-
if (key in c && c[key] !== void 0) {
|
|
330
|
-
out[key] = c[key];
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
return out;
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
// src/api/extension/groupPrefix.ts
|
|
337
|
-
function getGroupNamePrefixes(options) {
|
|
338
|
-
const { groups, only, groupPrefixMap } = options;
|
|
339
|
-
const onlySet = only?.length ? new Set(only) : null;
|
|
340
|
-
const namePrefixes = !onlySet && groups?.length ? groups.map((g) => groupPrefixMap[g]).filter((x) => x != null) : void 0;
|
|
341
|
-
return {
|
|
342
|
-
...onlySet ? { only: Array.from(onlySet) } : {},
|
|
343
|
-
...namePrefixes?.length ? { namePrefixes } : {}
|
|
344
|
-
};
|
|
345
|
-
}
|
|
346
|
-
async function validateUrl(url, options) {
|
|
347
|
-
let parsed;
|
|
348
|
-
try {
|
|
349
|
-
parsed = new URL(url);
|
|
350
|
-
} catch {
|
|
351
|
-
throw createTaggedError(
|
|
352
|
-
"HTTP_DISALLOWED_HOST",
|
|
353
|
-
`Invalid URL: ${url}`,
|
|
354
|
-
{ url }
|
|
355
|
-
);
|
|
356
|
-
}
|
|
357
|
-
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") {
|
|
358
|
-
throw createTaggedError(
|
|
359
|
-
"HTTP_DISALLOWED_HOST",
|
|
360
|
-
`Protocol not allowed: ${parsed.protocol}. Only http: and https: are supported.`,
|
|
361
|
-
{ url, protocol: parsed.protocol }
|
|
362
|
-
);
|
|
363
|
-
}
|
|
364
|
-
const hostname = parsed.hostname;
|
|
365
|
-
if (!isHostAllowed(hostname, options.allowedHosts)) {
|
|
366
|
-
throw createTaggedError(
|
|
367
|
-
"HTTP_DISALLOWED_HOST",
|
|
368
|
-
`Host "${hostname}" is not in the allowed hosts list`,
|
|
369
|
-
{ url, hostname, allowedHosts: options.allowedHosts }
|
|
370
|
-
);
|
|
371
|
-
}
|
|
372
|
-
if (isHostBlocked(hostname, options.blockedHosts)) {
|
|
373
|
-
throw createTaggedError(
|
|
374
|
-
"HTTP_DISALLOWED_HOST",
|
|
375
|
-
`Host "${hostname}" is in the blocked hosts list`,
|
|
376
|
-
{ url, hostname, blockedHosts: options.blockedHosts }
|
|
377
|
-
);
|
|
378
|
-
}
|
|
379
|
-
try {
|
|
380
|
-
const { address } = await lookup(hostname);
|
|
381
|
-
if (isIpInBlockedCidrs(address, options.blockedCidrs)) {
|
|
382
|
-
throw createTaggedError(
|
|
383
|
-
"HTTP_DISALLOWED_HOST",
|
|
384
|
-
`Host "${hostname}" resolves to blocked IP: ${address}`,
|
|
385
|
-
{ url, hostname, resolvedIp: address }
|
|
386
|
-
);
|
|
387
|
-
}
|
|
388
|
-
} catch (err) {
|
|
389
|
-
if (err instanceof Error && err.kind === "HTTP_DISALLOWED_HOST") {
|
|
390
|
-
throw err;
|
|
391
|
-
}
|
|
392
|
-
throw createTaggedError(
|
|
393
|
-
"HTTP_DISALLOWED_HOST",
|
|
394
|
-
`DNS resolution failed for host "${hostname}": ${err instanceof Error ? err.message : String(err)}`,
|
|
395
|
-
{ url, hostname }
|
|
396
|
-
);
|
|
397
|
-
}
|
|
398
|
-
return parsed;
|
|
399
|
-
}
|
|
400
|
-
function isHostAllowed(hostname, allowedHosts) {
|
|
401
|
-
for (const pattern of allowedHosts) {
|
|
402
|
-
if (pattern === "*") {
|
|
403
|
-
return true;
|
|
404
|
-
}
|
|
405
|
-
if (pattern.startsWith("*.")) {
|
|
406
|
-
const suffix = pattern.slice(1);
|
|
407
|
-
if (hostname.endsWith(suffix) || hostname === pattern.slice(2)) {
|
|
408
|
-
return true;
|
|
409
|
-
}
|
|
410
|
-
} else if (hostname === pattern) {
|
|
411
|
-
return true;
|
|
412
|
-
}
|
|
413
|
-
}
|
|
414
|
-
return false;
|
|
415
|
-
}
|
|
416
|
-
function isHostBlocked(hostname, blockedHosts) {
|
|
417
|
-
for (const pattern of blockedHosts) {
|
|
418
|
-
if (pattern === "*") {
|
|
419
|
-
return true;
|
|
420
|
-
}
|
|
421
|
-
if (pattern.startsWith("*.")) {
|
|
422
|
-
const suffix = pattern.slice(1);
|
|
423
|
-
if (hostname.endsWith(suffix) || hostname === pattern.slice(2)) {
|
|
424
|
-
return true;
|
|
425
|
-
}
|
|
426
|
-
} else if (hostname === pattern) {
|
|
427
|
-
return true;
|
|
428
|
-
}
|
|
429
|
-
}
|
|
430
|
-
return false;
|
|
431
|
-
}
|
|
432
|
-
function isIpInBlockedCidrs(ip, cidrs) {
|
|
433
|
-
const normalizedIp = normalizeIp(ip);
|
|
434
|
-
if (!normalizedIp) return false;
|
|
435
|
-
for (const cidr of cidrs) {
|
|
436
|
-
if (cidr.includes(":")) {
|
|
437
|
-
if (!ip.includes(":")) continue;
|
|
438
|
-
if (isIpv6InCidr(ip, cidr)) return true;
|
|
439
|
-
} else {
|
|
440
|
-
if (isIpv4InCidr(normalizedIp, cidr)) return true;
|
|
441
|
-
}
|
|
442
|
-
}
|
|
443
|
-
return false;
|
|
444
|
-
}
|
|
445
|
-
function normalizeIp(ip) {
|
|
446
|
-
if (ip.startsWith("::ffff:")) {
|
|
447
|
-
return ip.slice(7);
|
|
448
|
-
}
|
|
449
|
-
if (/^\d+\.\d+\.\d+\.\d+$/.test(ip)) {
|
|
450
|
-
return ip;
|
|
451
|
-
}
|
|
452
|
-
return null;
|
|
453
|
-
}
|
|
454
|
-
function isIpv4InCidr(ip, cidr) {
|
|
455
|
-
const [cidrIp, prefixStr] = cidr.split("/");
|
|
456
|
-
if (!cidrIp || !prefixStr) return false;
|
|
457
|
-
const prefix = parseInt(prefixStr, 10);
|
|
458
|
-
if (isNaN(prefix) || prefix < 0 || prefix > 32) return false;
|
|
459
|
-
const ipNum = ipv4ToNum(ip);
|
|
460
|
-
const cidrNum = ipv4ToNum(cidrIp);
|
|
461
|
-
if (ipNum === null || cidrNum === null) return false;
|
|
462
|
-
const mask = prefix === 0 ? 0 : -1 << 32 - prefix >>> 0;
|
|
463
|
-
return (ipNum & mask) === (cidrNum & mask);
|
|
464
|
-
}
|
|
465
|
-
function ipv4ToNum(ip) {
|
|
466
|
-
const parts = ip.split(".");
|
|
467
|
-
if (parts.length !== 4) return null;
|
|
468
|
-
let num = 0;
|
|
469
|
-
for (const part of parts) {
|
|
470
|
-
const n = parseInt(part, 10);
|
|
471
|
-
if (isNaN(n) || n < 0 || n > 255) return null;
|
|
472
|
-
num = num << 8 | n;
|
|
473
|
-
}
|
|
474
|
-
return num >>> 0;
|
|
475
|
-
}
|
|
476
|
-
function isIpv6InCidr(ip, cidr) {
|
|
477
|
-
const [cidrIp, prefixStr] = cidr.split("/");
|
|
478
|
-
if (!cidrIp || !prefixStr) return false;
|
|
479
|
-
const prefix = parseInt(prefixStr, 10);
|
|
480
|
-
if (isNaN(prefix)) return false;
|
|
481
|
-
const ipBytes = expandIpv6(ip);
|
|
482
|
-
const cidrBytes = expandIpv6(cidrIp);
|
|
483
|
-
if (!ipBytes || !cidrBytes) return false;
|
|
484
|
-
const fullBytes = Math.floor(prefix / 8);
|
|
485
|
-
for (let i = 0; i < fullBytes && i < 16; i++) {
|
|
486
|
-
if (ipBytes[i] !== cidrBytes[i]) return false;
|
|
487
|
-
}
|
|
488
|
-
const remainingBits = prefix % 8;
|
|
489
|
-
if (remainingBits > 0 && fullBytes < 16) {
|
|
490
|
-
const mask = -1 << 8 - remainingBits & 255;
|
|
491
|
-
if ((ipBytes[fullBytes] & mask) !== (cidrBytes[fullBytes] & mask)) return false;
|
|
492
|
-
}
|
|
493
|
-
return true;
|
|
494
|
-
}
|
|
495
|
-
function expandIpv6(ip) {
|
|
496
|
-
const zoneIdx = ip.indexOf("%");
|
|
497
|
-
if (zoneIdx !== -1) ip = ip.slice(0, zoneIdx);
|
|
498
|
-
const parts = ip.split("::");
|
|
499
|
-
if (parts.length > 2) return null;
|
|
500
|
-
const bytes = new Array(16).fill(0);
|
|
501
|
-
const expandGroup = (group) => {
|
|
502
|
-
if (!group) return [];
|
|
503
|
-
return group.split(":").flatMap((hex) => {
|
|
504
|
-
const val = parseInt(hex || "0", 16);
|
|
505
|
-
return [val >> 8 & 255, val & 255];
|
|
506
|
-
});
|
|
507
|
-
};
|
|
508
|
-
if (parts.length === 1) {
|
|
509
|
-
const expanded = expandGroup(parts[0]);
|
|
510
|
-
if (expanded.length !== 16) return null;
|
|
511
|
-
return expanded;
|
|
512
|
-
}
|
|
513
|
-
const left = expandGroup(parts[0]);
|
|
514
|
-
const right = expandGroup(parts[1]);
|
|
515
|
-
if (left.length + right.length > 16) return null;
|
|
516
|
-
for (let i = 0; i < left.length; i++) bytes[i] = left[i];
|
|
517
|
-
for (let i = 0; i < right.length; i++) bytes[16 - right.length + i] = right[i];
|
|
518
|
-
return bytes;
|
|
519
|
-
}
|
|
520
|
-
|
|
521
|
-
export { createContextRunner, createDynamicImportAdapter, createExtension, generateExtensionManifest, generateManifest, getGroupNamePrefixes, isIpInBlockedCidrs, loadExtensionManifest, loadToolYaml, overrideWithConfig, registerExtension, registerToolsFromManifest, resolveExtensionPackageRoot, validateUrl };
|
|
4
|
+
import './chunk-YRFUGA3C.js';
|
|
5
|
+
import './chunk-45S2HPVU.js';
|
|
6
|
+
import './chunk-QXQ4477T.js';
|
|
7
|
+
import './chunk-WUMLZERG.js';
|
|
8
|
+
import './chunk-RZTTO5MQ.js';
|
|
9
|
+
import './chunk-ODEHUAR4.js';
|
|
522
10
|
//# sourceMappingURL=index.js.map
|
|
523
11
|
//# sourceMappingURL=index.js.map
|