@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
|
@@ -0,0 +1,463 @@
|
|
|
1
|
+
import { DEFAULT_OUTPUT_SCHEMA } from './chunk-ODEHUAR4.js';
|
|
2
|
+
import * as path from 'path';
|
|
3
|
+
import { join } from 'path';
|
|
4
|
+
import * as fs from 'fs';
|
|
5
|
+
import * as ts2 from 'typescript';
|
|
6
|
+
import { readdir } from 'fs/promises';
|
|
7
|
+
|
|
8
|
+
async function findDirsContainingFile(rootPath, fileName) {
|
|
9
|
+
const found = [];
|
|
10
|
+
await collectDirsWithFile(rootPath, fileName, found);
|
|
11
|
+
return found;
|
|
12
|
+
}
|
|
13
|
+
async function collectDirsWithFile(dir, fileName, acc) {
|
|
14
|
+
let entries;
|
|
15
|
+
try {
|
|
16
|
+
const e = await readdir(dir, { withFileTypes: true });
|
|
17
|
+
entries = e.map((x) => ({
|
|
18
|
+
name: x.name,
|
|
19
|
+
isDirectory: x.isDirectory(),
|
|
20
|
+
isFile: x.isFile()
|
|
21
|
+
}));
|
|
22
|
+
} catch {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
if (entries.some((x) => x.isFile && x.name === fileName)) acc.push(dir);
|
|
26
|
+
for (const entry of entries) {
|
|
27
|
+
if (!entry.isDirectory || entry.name === "node_modules" || entry.name.startsWith(".")) continue;
|
|
28
|
+
await collectDirsWithFile(join(dir, entry.name), fileName, acc);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
function pathToToolName(sourcePath, programName) {
|
|
32
|
+
const normalized = sourcePath.replace(/\\/g, "/").replace(/\.(ts|tsx|js|mjs|json)$/i, "");
|
|
33
|
+
const segments = normalized.split("/").filter(Boolean);
|
|
34
|
+
return segments.length === 0 ? programName : `${segments.join(".")}.${programName}`;
|
|
35
|
+
}
|
|
36
|
+
function buildOutputSchemaFromReturnType(node, typeChecker, onWarn) {
|
|
37
|
+
const sig = typeChecker.getSignatureFromDeclaration(node);
|
|
38
|
+
if (!sig) {
|
|
39
|
+
onWarn?.("Could not get signature for return type, using object");
|
|
40
|
+
return { type: "object", additionalProperties: true };
|
|
41
|
+
}
|
|
42
|
+
let returnType = typeChecker.getReturnTypeOfSignature(sig);
|
|
43
|
+
if (returnType.getSymbol?.()?.getName() === "Promise") {
|
|
44
|
+
const typeArgs = returnType.typeArguments;
|
|
45
|
+
if (typeArgs?.[0]) returnType = typeArgs[0];
|
|
46
|
+
}
|
|
47
|
+
const schema = typeToJsonSchema(returnType, typeChecker, onWarn);
|
|
48
|
+
const hasProps = typeof schema === "object" && schema.type === "object" && Object.keys(schema.properties ?? {}).length > 0;
|
|
49
|
+
return hasProps ? schema : { type: "object", additionalProperties: true };
|
|
50
|
+
}
|
|
51
|
+
function buildInputSchemaFromParams(node, typeChecker, onWarn) {
|
|
52
|
+
const properties = {};
|
|
53
|
+
const required = [];
|
|
54
|
+
if (!node.parameters.length) {
|
|
55
|
+
return { schema: { type: "object", properties: {} }, required: [] };
|
|
56
|
+
}
|
|
57
|
+
for (const param of node.parameters) {
|
|
58
|
+
const name = param.name.getText();
|
|
59
|
+
if (name.startsWith("_") && name.length <= 2) continue;
|
|
60
|
+
const sym = param.symbol;
|
|
61
|
+
const paramType = sym ? typeChecker.getTypeOfSymbolAtLocation(sym, param) : typeChecker.getTypeAtLocation(param);
|
|
62
|
+
const isOptional = !!param.questionToken || param.initializer !== void 0;
|
|
63
|
+
const propSchema = typeToJsonSchema(paramType, typeChecker, onWarn);
|
|
64
|
+
properties[name] = propSchema;
|
|
65
|
+
if (!isOptional) required.push(name);
|
|
66
|
+
}
|
|
67
|
+
const paramNames = Object.keys(properties);
|
|
68
|
+
if (paramNames.length === 1) {
|
|
69
|
+
const soleName = paramNames[0];
|
|
70
|
+
const inner = properties[soleName];
|
|
71
|
+
if (inner && typeof inner === "object" && inner.type === "object" && inner.properties && typeof inner.properties === "object") {
|
|
72
|
+
return {
|
|
73
|
+
schema: {
|
|
74
|
+
type: "object",
|
|
75
|
+
properties: inner.properties,
|
|
76
|
+
...Array.isArray(inner.required) && inner.required.length > 0 ? { required: inner.required } : {},
|
|
77
|
+
...inner.additionalProperties !== void 0 ? { additionalProperties: inner.additionalProperties } : {}
|
|
78
|
+
},
|
|
79
|
+
required: inner.required ?? []
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return {
|
|
84
|
+
schema: {
|
|
85
|
+
type: "object",
|
|
86
|
+
properties,
|
|
87
|
+
...required.length > 0 ? { required } : {}
|
|
88
|
+
},
|
|
89
|
+
required
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
function typeToJsonSchema(type, typeChecker, onWarn) {
|
|
93
|
+
const flags = type.flags;
|
|
94
|
+
if (flags & ts2.TypeFlags.String) return { type: "string" };
|
|
95
|
+
if (flags & ts2.TypeFlags.Number) return { type: "number" };
|
|
96
|
+
if (flags & ts2.TypeFlags.Boolean) return { type: "boolean" };
|
|
97
|
+
if (flags & ts2.TypeFlags.BooleanLiteral) return { type: "boolean" };
|
|
98
|
+
if (flags & ts2.TypeFlags.Null) return { type: "null" };
|
|
99
|
+
if (flags & ts2.TypeFlags.Undefined || flags & ts2.TypeFlags.Void) return {};
|
|
100
|
+
if (flags & ts2.TypeFlags.Any || flags & ts2.TypeFlags.Unknown) {
|
|
101
|
+
onWarn?.(`Unsupported type: any/unknown, using empty schema`);
|
|
102
|
+
return {};
|
|
103
|
+
}
|
|
104
|
+
if (type.isUnion?.()) {
|
|
105
|
+
const union = type;
|
|
106
|
+
const types = union.types;
|
|
107
|
+
const withoutUndef = types.filter(
|
|
108
|
+
(t) => !(t.flags & ts2.TypeFlags.Undefined) && !(t.flags & ts2.TypeFlags.Void)
|
|
109
|
+
);
|
|
110
|
+
if (withoutUndef.length === 1) return typeToJsonSchema(withoutUndef[0], typeChecker, onWarn);
|
|
111
|
+
if (withoutUndef.length === 0) return {};
|
|
112
|
+
const stringEnumValues = [];
|
|
113
|
+
let allStringLiterals = true;
|
|
114
|
+
for (const t of withoutUndef) {
|
|
115
|
+
if (t.flags & ts2.TypeFlags.StringLiteral) {
|
|
116
|
+
const lit = t;
|
|
117
|
+
if (typeof lit.value === "string") stringEnumValues.push(lit.value);
|
|
118
|
+
} else {
|
|
119
|
+
allStringLiterals = false;
|
|
120
|
+
break;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
if (allStringLiterals && stringEnumValues.length > 0) {
|
|
124
|
+
return { type: "string", enum: [...new Set(stringEnumValues)] };
|
|
125
|
+
}
|
|
126
|
+
let allBooleanLiterals = true;
|
|
127
|
+
for (const t of withoutUndef) {
|
|
128
|
+
if (!(t.flags & ts2.TypeFlags.BooleanLiteral)) {
|
|
129
|
+
allBooleanLiterals = false;
|
|
130
|
+
break;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
if (allBooleanLiterals) return { type: "boolean" };
|
|
134
|
+
}
|
|
135
|
+
if (flags & ts2.TypeFlags.StringLiteral) {
|
|
136
|
+
const lit = type;
|
|
137
|
+
if (typeof lit.value === "string") {
|
|
138
|
+
return { type: "string", enum: [lit.value] };
|
|
139
|
+
}
|
|
140
|
+
return { type: "string" };
|
|
141
|
+
}
|
|
142
|
+
if (typeChecker.isArrayType(type)) {
|
|
143
|
+
const typeRef = type;
|
|
144
|
+
const typeArgs = typeRef.typeArguments;
|
|
145
|
+
const itemType = typeArgs?.[0];
|
|
146
|
+
const items = itemType ? typeToJsonSchema(itemType, typeChecker, onWarn) : {};
|
|
147
|
+
return { type: "array", items: Object.keys(items).length ? items : {} };
|
|
148
|
+
}
|
|
149
|
+
const str = typeChecker.typeToString(type);
|
|
150
|
+
if (str === "string") return { type: "string" };
|
|
151
|
+
if (str === "number") return { type: "number" };
|
|
152
|
+
if (str === "boolean") return { type: "boolean" };
|
|
153
|
+
if (str.endsWith("[]")) {
|
|
154
|
+
const inner = str.slice(0, -2).trim();
|
|
155
|
+
const itemType = inner === "string" ? { type: "string" } : inner === "number" ? { type: "number" } : {};
|
|
156
|
+
return { type: "array", items: itemType };
|
|
157
|
+
}
|
|
158
|
+
if (type.getProperties && type.getProperties().length >= 0) {
|
|
159
|
+
const props = type.getProperties();
|
|
160
|
+
const properties = {};
|
|
161
|
+
const required = [];
|
|
162
|
+
for (const p of props) {
|
|
163
|
+
const decl = p.valueDeclaration;
|
|
164
|
+
const propType = decl ? typeChecker.getTypeAtLocation(decl) : typeChecker.getTypeOfSymbolAtLocation(p, p.valueDeclaration);
|
|
165
|
+
const optional = decl && ts2.isPropertySignature(decl) ? !!decl.questionToken : false;
|
|
166
|
+
properties[p.name] = typeToJsonSchema(propType, typeChecker, onWarn);
|
|
167
|
+
if (!optional) required.push(p.name);
|
|
168
|
+
}
|
|
169
|
+
return { type: "object", properties, ...required.length ? { required } : {} };
|
|
170
|
+
}
|
|
171
|
+
onWarn?.(`Unsupported type: ${str}, using object`);
|
|
172
|
+
return { type: "object" };
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// src/tools/function/types.ts
|
|
176
|
+
var FUNCTION_KIND = "function";
|
|
177
|
+
|
|
178
|
+
// src/tools/skill/types.ts
|
|
179
|
+
var SKILL_KIND = "skill";
|
|
180
|
+
var SKILL_DIR_NAME = "skill";
|
|
181
|
+
|
|
182
|
+
// src/tools/n8n/types.ts
|
|
183
|
+
var N8N_KIND = "n8n";
|
|
184
|
+
|
|
185
|
+
// src/tools/mcp/mcpSpecToToolSpec.ts
|
|
186
|
+
var DEFAULT_OUTPUT = { type: "object", additionalProperties: true };
|
|
187
|
+
function mcpSpecToToolSpec(spec, projectPath) {
|
|
188
|
+
const base = {
|
|
189
|
+
name: spec.name,
|
|
190
|
+
version: "1.0.0",
|
|
191
|
+
kind: spec.kind,
|
|
192
|
+
description: spec.description,
|
|
193
|
+
inputSchema: spec.inputSchema ?? DEFAULT_OUTPUT,
|
|
194
|
+
outputSchema: "outputSchema" in spec && spec.outputSchema ? spec.outputSchema : DEFAULT_OUTPUT_SCHEMA,
|
|
195
|
+
capabilities: [],
|
|
196
|
+
_meta: spec._meta,
|
|
197
|
+
...spec.kind === N8N_KIND && "webhookUrl" in spec && spec.webhookUrl ? { endpoint: spec.webhookUrl } : {}
|
|
198
|
+
};
|
|
199
|
+
if (spec.kind === FUNCTION_KIND && "sourcePath" in spec && "exportName" in spec) {
|
|
200
|
+
base._meta = {
|
|
201
|
+
...base._meta,
|
|
202
|
+
sourcePath: spec.sourcePath,
|
|
203
|
+
exportName: spec.exportName,
|
|
204
|
+
...projectPath && { projectPath }
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
if (spec.kind === SKILL_KIND && "sourcePath" in spec && projectPath) {
|
|
208
|
+
base._meta = { ...base._meta, sourcePath: spec.sourcePath, projectPath };
|
|
209
|
+
}
|
|
210
|
+
if (spec.kind === N8N_KIND && "sourcePath" in spec && projectPath) {
|
|
211
|
+
base._meta = { ...base._meta, sourcePath: spec.sourcePath, projectPath };
|
|
212
|
+
}
|
|
213
|
+
return base;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
// src/tools/function/scanner.ts
|
|
217
|
+
var TOOL_TAG = "@tool";
|
|
218
|
+
var EFFECT_VALUES = ["none", "local_write", "external_write", "destructive"];
|
|
219
|
+
function scanForTools(options) {
|
|
220
|
+
const projectPath = path.resolve(options.projectPath);
|
|
221
|
+
const tsconfigPath = options.tsconfigPath ?? path.join(projectPath, "tsconfig.json");
|
|
222
|
+
const include = options.include ?? ["**/*.ts"];
|
|
223
|
+
const errors = [];
|
|
224
|
+
const warnings = [];
|
|
225
|
+
let config;
|
|
226
|
+
let configPathResolved = path.resolve(projectPath, tsconfigPath);
|
|
227
|
+
if (!fs.existsSync(configPathResolved)) {
|
|
228
|
+
configPathResolved = path.join(projectPath, "tsconfig.json");
|
|
229
|
+
}
|
|
230
|
+
if (fs.existsSync(configPathResolved)) {
|
|
231
|
+
const configFile = ts2.readConfigFile(configPathResolved, ts2.sys.readFile);
|
|
232
|
+
if (configFile.error) {
|
|
233
|
+
errors.push({ file: configPathResolved, message: String(configFile.error.messageText) });
|
|
234
|
+
return { specs: [], errors, warnings };
|
|
235
|
+
}
|
|
236
|
+
const parsed = ts2.parseJsonConfigFileContent(
|
|
237
|
+
configFile.config,
|
|
238
|
+
ts2.sys,
|
|
239
|
+
path.dirname(configPathResolved)
|
|
240
|
+
);
|
|
241
|
+
if (parsed.errors.length) {
|
|
242
|
+
for (const e of parsed.errors) {
|
|
243
|
+
errors.push({ file: e.file?.fileName ?? "tsconfig", message: String(e.messageText) });
|
|
244
|
+
}
|
|
245
|
+
return { specs: [], errors, warnings };
|
|
246
|
+
}
|
|
247
|
+
config = parsed;
|
|
248
|
+
} else {
|
|
249
|
+
config = {
|
|
250
|
+
options: {
|
|
251
|
+
target: ts2.ScriptTarget.ES2022,
|
|
252
|
+
module: ts2.ModuleKind.ESNext,
|
|
253
|
+
moduleResolution: ts2.ModuleResolutionKind.NodeNext,
|
|
254
|
+
strict: true,
|
|
255
|
+
skipLibCheck: true,
|
|
256
|
+
noEmit: true
|
|
257
|
+
},
|
|
258
|
+
fileNames: resolveGlob(projectPath, include),
|
|
259
|
+
errors: []
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
const program = ts2.createProgram(config.fileNames, config.options);
|
|
263
|
+
const typeChecker = program.getTypeChecker();
|
|
264
|
+
const specs = [];
|
|
265
|
+
for (const sourceFile of program.getSourceFiles()) {
|
|
266
|
+
const fileName = sourceFile.fileName;
|
|
267
|
+
if (fileName.includes("node_modules") || fileName.endsWith(".d.ts")) continue;
|
|
268
|
+
if (!config.fileNames.some((f) => path.resolve(f) === path.resolve(fileName))) continue;
|
|
269
|
+
ts2.forEachChild(sourceFile, (node) => {
|
|
270
|
+
const decl = getExportedFunctionDeclaration(node);
|
|
271
|
+
if (!decl) return;
|
|
272
|
+
const func = decl.func;
|
|
273
|
+
const name = decl.name;
|
|
274
|
+
if (!name) return;
|
|
275
|
+
const host = getJSDocHost(func);
|
|
276
|
+
if (!hasToolTag(host)) return;
|
|
277
|
+
const jsDoc = getJSDocComments(host);
|
|
278
|
+
const description = getDescription(jsDoc);
|
|
279
|
+
if (!description) {
|
|
280
|
+
warnings.push({ file: fileName, message: `Tool ${name}: missing description, using humanized name` });
|
|
281
|
+
}
|
|
282
|
+
const sideEffect = getEffect(host);
|
|
283
|
+
const onWarn = (msg) => warnings.push({ file: fileName, message: `${name}: ${msg}` });
|
|
284
|
+
const { schema } = buildInputSchemaFromParams(func, typeChecker, onWarn);
|
|
285
|
+
const inputSchema = Object.keys(schema.properties ?? {}).length > 0 ? schema : { type: "object", properties: {} };
|
|
286
|
+
const outputSchema = buildOutputSchemaFromReturnType(func, typeChecker, onWarn);
|
|
287
|
+
const sourcePath = path.relative(projectPath, fileName) || path.basename(fileName);
|
|
288
|
+
const toolName = pathToToolName(sourcePath, name);
|
|
289
|
+
specs.push({
|
|
290
|
+
kind: FUNCTION_KIND,
|
|
291
|
+
name: toolName,
|
|
292
|
+
description: description || humanize(name),
|
|
293
|
+
inputSchema,
|
|
294
|
+
outputSchema,
|
|
295
|
+
_meta: { hitl: { sideEffect } },
|
|
296
|
+
sourcePath,
|
|
297
|
+
exportName: name
|
|
298
|
+
});
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
return { specs, errors, warnings };
|
|
302
|
+
}
|
|
303
|
+
function resolveGlob(projectPath, patterns) {
|
|
304
|
+
const result = [];
|
|
305
|
+
const seen = /* @__PURE__ */ new Set();
|
|
306
|
+
const add = (f) => {
|
|
307
|
+
const abs = path.resolve(f);
|
|
308
|
+
if (f.endsWith(".ts") && !f.endsWith(".d.ts") && !seen.has(abs)) {
|
|
309
|
+
seen.add(abs);
|
|
310
|
+
result.push(abs);
|
|
311
|
+
}
|
|
312
|
+
};
|
|
313
|
+
for (const p of patterns) {
|
|
314
|
+
const full = path.join(projectPath, p);
|
|
315
|
+
if (full.includes("*")) {
|
|
316
|
+
const baseDir = full.replace(/\*\*\/.*$/, "").replace(/\*.*$/, "").replace(/\/?$/, "") || ".";
|
|
317
|
+
const dir = path.resolve(projectPath, baseDir);
|
|
318
|
+
if (fs.existsSync(dir)) walk(dir, add);
|
|
319
|
+
} else {
|
|
320
|
+
const resolved = path.resolve(projectPath, full);
|
|
321
|
+
if (fs.existsSync(resolved)) {
|
|
322
|
+
if (fs.statSync(resolved).isFile()) add(resolved);
|
|
323
|
+
else walk(resolved, add);
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
if (result.length > 0) return result;
|
|
328
|
+
const srcDir = path.join(projectPath, "src");
|
|
329
|
+
if (fs.existsSync(srcDir)) return walkCollect(srcDir);
|
|
330
|
+
return [];
|
|
331
|
+
}
|
|
332
|
+
function walkCollect(dir) {
|
|
333
|
+
const out = [];
|
|
334
|
+
walk(dir, (fullPath) => {
|
|
335
|
+
if (fullPath.endsWith(".ts") && !fullPath.endsWith(".d.ts")) out.push(path.resolve(fullPath));
|
|
336
|
+
});
|
|
337
|
+
return out;
|
|
338
|
+
}
|
|
339
|
+
var SKIP_DIRS = /* @__PURE__ */ new Set(["node_modules", "generated", "dist"]);
|
|
340
|
+
function walk(dir, visit) {
|
|
341
|
+
try {
|
|
342
|
+
const entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
343
|
+
for (const e of entries) {
|
|
344
|
+
const full = path.join(dir, e.name);
|
|
345
|
+
if (e.isDirectory() && !SKIP_DIRS.has(e.name)) walk(full, visit);
|
|
346
|
+
else if (e.isFile()) visit(full);
|
|
347
|
+
}
|
|
348
|
+
} catch {
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
function getExportedFunctionDeclaration(node, _sourceFile) {
|
|
352
|
+
if (ts2.isFunctionDeclaration(node) && node.name) {
|
|
353
|
+
const exported = (ts2.getModifiers(node) ?? []).some((m) => m.kind === ts2.SyntaxKind.ExportKeyword);
|
|
354
|
+
if (exported) return { func: node, name: node.name.getText() };
|
|
355
|
+
return null;
|
|
356
|
+
}
|
|
357
|
+
if (ts2.isVariableStatement(node)) {
|
|
358
|
+
const exported = (ts2.getModifiers(node) ?? []).some((m) => m.kind === ts2.SyntaxKind.ExportKeyword);
|
|
359
|
+
if (!exported) return null;
|
|
360
|
+
for (const decl of node.declarationList.declarations) {
|
|
361
|
+
let init = decl.initializer;
|
|
362
|
+
while (init && (ts2.isParenthesizedExpression(init) || ts2.isAsExpression(init)))
|
|
363
|
+
init = init.expression;
|
|
364
|
+
if (init && ts2.isArrowFunction(init)) {
|
|
365
|
+
const name = decl.name.getText();
|
|
366
|
+
return { func: init, name };
|
|
367
|
+
}
|
|
368
|
+
if (init && ts2.isFunctionExpression(init)) {
|
|
369
|
+
const name = decl.name.getText();
|
|
370
|
+
return { func: init, name };
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
return null;
|
|
375
|
+
}
|
|
376
|
+
function getJSDocHost(node) {
|
|
377
|
+
const parent = node.parent;
|
|
378
|
+
if (ts2.isVariableDeclaration(parent)) {
|
|
379
|
+
const gp = parent.parent;
|
|
380
|
+
if (ts2.isVariableDeclarationList(gp) && gp.parent && ts2.isVariableStatement(gp.parent)) return gp.parent;
|
|
381
|
+
}
|
|
382
|
+
return node;
|
|
383
|
+
}
|
|
384
|
+
function getJSDocComments(host) {
|
|
385
|
+
const all = ts2.getJSDocCommentsAndTags(host);
|
|
386
|
+
return all.filter((t) => ts2.isJSDoc(t));
|
|
387
|
+
}
|
|
388
|
+
function hasToolTag(host) {
|
|
389
|
+
const tags = ts2.getJSDocTags(host);
|
|
390
|
+
for (const tag of tags) {
|
|
391
|
+
const name = tag.tagName?.getText() ?? "";
|
|
392
|
+
if (name === "tool") return true;
|
|
393
|
+
}
|
|
394
|
+
const all = ts2.getJSDocCommentsAndTags(host);
|
|
395
|
+
for (const t of all) {
|
|
396
|
+
if (ts2.isJSDoc(t)) {
|
|
397
|
+
const full = t.getFullText();
|
|
398
|
+
if (full.includes(TOOL_TAG)) return true;
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
return false;
|
|
402
|
+
}
|
|
403
|
+
function getDescription(jsDocs, fallbackName) {
|
|
404
|
+
for (const doc of jsDocs) {
|
|
405
|
+
const comment = doc.comment;
|
|
406
|
+
if (typeof comment === "string") {
|
|
407
|
+
const first = comment.split(/\n/)[0]?.trim() ?? "";
|
|
408
|
+
if (first && !first.startsWith("@")) return first;
|
|
409
|
+
}
|
|
410
|
+
if (Array.isArray(comment)) {
|
|
411
|
+
const first = comment[0];
|
|
412
|
+
if (first && typeof first === "object" && "text" in first) {
|
|
413
|
+
const t = first.text.trim();
|
|
414
|
+
if (t && !t.startsWith("@")) return t;
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
const full = doc.getFullText();
|
|
418
|
+
const match = full.match(/\*\s*@tool\s+(.+?)(?=\n|$|\*\/)/s);
|
|
419
|
+
if (match?.[1]) return match[1].trim();
|
|
420
|
+
}
|
|
421
|
+
return "";
|
|
422
|
+
}
|
|
423
|
+
function getEffect(host) {
|
|
424
|
+
const tags = ts2.getJSDocTags(host);
|
|
425
|
+
for (const tag of tags) {
|
|
426
|
+
const name = tag.tagName?.getText() ?? "";
|
|
427
|
+
if (name === "effect") {
|
|
428
|
+
const comment = tag.comment;
|
|
429
|
+
const v = (typeof comment === "string" ? comment : "").trim().toLowerCase();
|
|
430
|
+
if (EFFECT_VALUES.includes(v)) return v;
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
const all = ts2.getJSDocCommentsAndTags(host);
|
|
434
|
+
for (const t of all) {
|
|
435
|
+
if (ts2.isJSDoc(t)) {
|
|
436
|
+
const full = t.getFullText();
|
|
437
|
+
const match = full.match(/\*\s*@effect\s+(\w+)/);
|
|
438
|
+
if (match && EFFECT_VALUES.includes(match[1])) return match[1];
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
return "none";
|
|
442
|
+
}
|
|
443
|
+
function humanize(name) {
|
|
444
|
+
return name.replace(/([A-Z])/g, " $1").replace(/^./, (s) => s.toUpperCase()).trim();
|
|
445
|
+
}
|
|
446
|
+
function scan(projectPath, options = {}) {
|
|
447
|
+
const root = path.resolve(projectPath);
|
|
448
|
+
const result = scanForTools({
|
|
449
|
+
projectPath: root,
|
|
450
|
+
include: options.include ?? ["**/*.ts"],
|
|
451
|
+
tsconfigPath: options.tsconfigPath
|
|
452
|
+
});
|
|
453
|
+
const specs = result.specs.map((s) => mcpSpecToToolSpec(s, root));
|
|
454
|
+
return Promise.resolve({
|
|
455
|
+
specs,
|
|
456
|
+
errors: result.errors,
|
|
457
|
+
warnings: result.warnings
|
|
458
|
+
});
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
export { FUNCTION_KIND, N8N_KIND, SKILL_DIR_NAME, SKILL_KIND, findDirsContainingFile, mcpSpecToToolSpec, pathToToolName, scan, scanForTools };
|
|
462
|
+
//# sourceMappingURL=chunk-45S2HPVU.js.map
|
|
463
|
+
//# sourceMappingURL=chunk-45S2HPVU.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/tools/util/scanUtil.ts","../src/tools/function/schemaFromTs.ts","../src/tools/function/types.ts","../src/tools/skill/types.ts","../src/tools/n8n/types.ts","../src/tools/mcp/mcpSpecToToolSpec.ts","../src/tools/function/scanner.ts"],"names":["ts"],"mappings":";;;;;;;AASA,eAAsB,sBAAA,CACpB,UACA,QAAA,EACmB;AACnB,EAAA,MAAM,QAAkB,EAAC;AACzB,EAAA,MAAM,mBAAA,CAAoB,QAAA,EAAU,QAAA,EAAU,KAAK,CAAA;AACnD,EAAA,OAAO,KAAA;AACT;AAEA,eAAe,mBAAA,CACb,GAAA,EACA,QAAA,EACA,GAAA,EACe;AACf,EAAA,IAAI,OAAA;AACJ,EAAA,IAAI;AACF,IAAA,MAAM,IAAI,MAAM,OAAA,C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AA,IAC1B,WAAA,EAAa,IAAA;AAAA,IACb,OAAA,EAAS,OAAA,CAAQ,OAAA,IAAW,CAAC,SAAS,CAAA;AAAA,IACtC,cAAc,OAAA,CAAQ;AAAA,GACvB,CAAA;AACD,EAAA,MAAM,KAAA,GAAQ,OAAO,KAAA,CAAM,GAAA,CAAI,CAAC,CAAA,KAAM,iBAAA,CAAkB,CAAA,EAAG,IAAI,CAAC,CAAA;AAChE,EAAA,OAAO,QAAQ,OAAA,CAAQ;AAAA,IACrB,KAAA;AAAA,IACA,QAAQ,MAAA,CAAO,MAAA;AAAA,IACf,UAAU,MAAA,CAAO;AAAA,GAClB,CAAA;AACH","file":"chunk-45S2HPVU.js","sourcesContent":["/**\n * Shared scan helpers for tool-type scanners (function, skill, n8n).\n * findDirsContainingFile: recursive dirs that contain a given file name.\n * pathToToolName: build dotted tool name from source path and program name.\n */\n\nimport { readdir } from \"node:fs/promises\";\nimport { join } from \"node:path\";\n\nexport async function findDirsContainingFile(\n rootPath: string,\n fileName: string,\n): Promise<string[]> {\n const found: string[] = [];\n await collectDirsWithFile(rootPath, fileName, found);\n return found;\n}\n\nasync function collectDirsWithFile(\n dir: string,\n fileName: string,\n acc: string[],\n): Promise<void> {\n let entries: Array<{ name: string; isDirectory: boolean; isFile: boolean }>;\n try {\n const e = await readdir(dir, { withFileTypes: true });\n entries = e.map((x) => ({\n name: x.name,\n isDirectory: x.isDirectory(),\n isFile: x.isFile(),\n }));\n } catch {\n return;\n }\n if (entries.some((x) => x.isFile && x.name === fileName)) acc.push(dir);\n for (const entry of entries) {\n if (!entry.isDirectory || entry.name === \"node_modules\" || entry.name.startsWith(\".\")) continue;\n await collectDirsWithFile(join(dir, entry.name), fileName, acc);\n }\n}\n\n/** Build dotted tool name from source path (extension stripped) and program name. */\nexport function pathToToolName(sourcePath: string, programName: string): string {\n const normalized = sourcePath\n .replace(/\\\\/g, \"/\")\n .replace(/\\.(ts|tsx|js|mjs|json)$/i, \"\");\n const segments = normalized.split(\"/\").filter(Boolean);\n return segments.length === 0 ? programName : `${segments.join(\".\")}.${programName}`;\n}\n","/**\n * Build JSON Schema from TypeScript parameter types using the compiler API.\n * MVP: primitives, optional, array, object. Complex types fallback to {} with warn.\n */\n\nimport * as ts from \"typescript\";\n\n/**\n * Build output JSON Schema from function return type (unwrap Promise if present).\n * Used by scan when auto-deriving schema.\n */\nexport function buildOutputSchemaFromReturnType(\n node: ts.FunctionDeclaration | ts.ArrowFunction | ts.FunctionExpression,\n typeChecker: ts.TypeChecker,\n onWarn?: (message: string) => void,\n): object {\n const sig = typeChecker.getSignatureFromDeclaration(node as ts.SignatureDeclaration);\n if (!sig) {\n onWarn?.(\"Could not get signature for return type, using object\");\n return { type: \"object\", additionalProperties: true };\n }\n let returnType = typeChecker.getReturnTypeOfSignature(sig);\n // Unwrap Promise<T> to T\n if (returnType.getSymbol?.()?.getName() === \"Promise\") {\n const typeArgs = (returnType as ts.TypeReference).typeArguments;\n if (typeArgs?.[0]) returnType = typeArgs[0];\n }\n const schema = typeToJsonSchema(returnType, typeChecker, onWarn);\n const hasProps =\n typeof schema === \"object\" &&\n (schema as { type?: string; properties?: object }).type === \"object\" &&\n Object.keys((schema as { properties?: object }).properties ?? {}).length > 0;\n return hasProps ? schema : { type: \"object\", additionalProperties: true };\n}\n\n/** Build { type: \"object\", properties, required } from function parameters. */\nexport function buildInputSchemaFromParams(\n node: ts.FunctionDeclaration | ts.ArrowFunction | ts.FunctionExpression,\n typeChecker: ts.TypeChecker,\n onWarn?: (message: string) => void,\n): { schema: object; required: string[] } {\n const properties: Record<string, object> = {};\n const required: string[] = [];\n\n if (!node.parameters.length) {\n return { schema: { type: \"object\", properties: {} }, required: [] };\n }\n\n for (const param of node.parameters) {\n const name = (param.name as ts.Identifier).getText();\n if (name.startsWith(\"_\") && name.length <= 2) continue;\n const sym = (param as ts.ParameterDeclaration & { symbol?: ts.Symbol }).symbol;\n const paramType = sym\n ? typeChecker.getTypeOfSymbolAtLocation(sym, param)\n : typeChecker.getTypeAtLocation(param);\n const isOptional = !!param.questionToken || param.initializer !== undefined;\n const propSchema = typeToJsonSchema(paramType, typeChecker, onWarn);\n properties[name] = propSchema;\n if (!isOptional) required.push(name);\n }\n\n // Flatten: when there is exactly one parameter and it's an object type, emit that object's\n // schema at top level so agents can pass flat params like { path: \".\" } instead of { args: { path: \".\" } }.\n const paramNames = Object.keys(properties);\n if (paramNames.length === 1) {\n const soleName = paramNames[0]!;\n const inner = properties[soleName] as\n | { type?: string; properties?: Record<string, object>; required?: string[]; additionalProperties?: boolean }\n | undefined;\n if (\n inner &&\n typeof inner === \"object\" &&\n inner.type === \"object\" &&\n inner.properties &&\n typeof inner.properties === \"object\"\n ) {\n return {\n schema: {\n type: \"object\",\n properties: inner.properties,\n ...(Array.isArray(inner.required) && inner.required.length > 0 ? { required: inner.required } : {}),\n ...(inner.additionalProperties !== undefined ? { additionalProperties: inner.additionalProperties } : {}),\n },\n required: inner.required ?? [],\n };\n }\n }\n\n return {\n schema: {\n type: \"object\",\n properties,\n ...(required.length > 0 ? { required } : {}),\n },\n required,\n };\n}\n\nfunction typeToJsonSchema(\n type: ts.Type,\n typeChecker: ts.TypeChecker,\n onWarn?: (message: string) => void,\n): object {\n const flags = type.flags;\n if (flags & ts.TypeFlags.String) return { type: \"string\" };\n if (flags & ts.TypeFlags.Number) return { type: \"number\" };\n if (flags & ts.TypeFlags.Boolean) return { type: \"boolean\" };\n if (flags & ts.TypeFlags.BooleanLiteral) return { type: \"boolean\" };\n if (flags & ts.TypeFlags.Null) return { type: \"null\" };\n if (flags & ts.TypeFlags.Undefined || flags & ts.TypeFlags.Void) return {};\n if (flags & ts.TypeFlags.Any || flags & ts.TypeFlags.Unknown) {\n onWarn?.(`Unsupported type: any/unknown, using empty schema`);\n return {};\n }\n\n if (type.isUnion?.()) {\n const union = type as ts.UnionType;\n const types = union.types;\n const withoutUndef = types.filter(\n (t) => !(t.flags & ts.TypeFlags.Undefined) && !(t.flags & ts.TypeFlags.Void),\n );\n if (withoutUndef.length === 1) return typeToJsonSchema(withoutUndef[0]!, typeChecker, onWarn);\n if (withoutUndef.length === 0) return {};\n // Union of string literals -> { type: \"string\", enum: [...] } so we don't fall through to getProperties() (String prototype).\n const stringEnumValues: string[] = [];\n let allStringLiterals = true;\n for (const t of withoutUndef) {\n if (t.flags & ts.TypeFlags.StringLiteral) {\n const lit = t as ts.StringLiteralType;\n if (typeof lit.value === \"string\") stringEnumValues.push(lit.value);\n } else {\n allStringLiterals = false;\n break;\n }\n }\n if (allStringLiterals && stringEnumValues.length > 0) {\n return { type: \"string\", enum: [...new Set(stringEnumValues)] };\n }\n\n // Union of boolean literals (true | false | undefined) should stay boolean.\n let allBooleanLiterals = true;\n for (const t of withoutUndef) {\n if (!(t.flags & ts.TypeFlags.BooleanLiteral)) {\n allBooleanLiterals = false;\n break;\n }\n }\n if (allBooleanLiterals) return { type: \"boolean\" };\n }\n\n // Single string literal (e.g. type: \"file\") -> { type: \"string\", enum: [\"file\"] }, not object with String methods.\n if (flags & ts.TypeFlags.StringLiteral) {\n const lit = type as ts.StringLiteralType;\n if (typeof lit.value === \"string\") {\n return { type: \"string\", enum: [lit.value] };\n }\n return { type: \"string\" };\n }\n\n if (typeChecker.isArrayType(type)) {\n const typeRef = type as ts.TypeReference;\n const typeArgs = typeRef.typeArguments;\n const itemType = typeArgs?.[0];\n const items = itemType ? typeToJsonSchema(itemType, typeChecker, onWarn) : {};\n return { type: \"array\", items: Object.keys(items).length ? items : {} };\n }\n\n const str = typeChecker.typeToString(type);\n if (str === \"string\") return { type: \"string\" };\n if (str === \"number\") return { type: \"number\" };\n if (str === \"boolean\") return { type: \"boolean\" };\n if (str.endsWith(\"[]\")) {\n const inner = str.slice(0, -2).trim();\n const itemType =\n inner === \"string\" ? { type: \"string\" as const } : inner === \"number\" ? { type: \"number\" as const } : {};\n return { type: \"array\", items: itemType };\n }\n\n if (type.getProperties && type.getProperties().length >= 0) {\n const props = type.getProperties();\n const properties: Record<string, object> = {};\n const required: string[] = [];\n for (const p of props) {\n const decl = p.valueDeclaration;\n const propType = decl\n ? typeChecker.getTypeAtLocation(decl)\n : typeChecker.getTypeOfSymbolAtLocation(p, (p as unknown as { valueDeclaration: ts.Node }).valueDeclaration);\n const optional = decl && ts.isPropertySignature(decl) ? !!decl.questionToken : false;\n properties[p.name] = typeToJsonSchema(propType, typeChecker, onWarn);\n if (!optional) required.push(p.name);\n }\n return { type: \"object\", properties, ...(required.length ? { required } : {}) };\n }\n\n onWarn?.(`Unsupported type: ${str}, using object`);\n return { type: \"object\" };\n}\n","/** HITL side-effect classification. */\nexport type SideEffect = \"none\" | \"local_write\" | \"external_write\" | \"destructive\";\n\n/** Kind for @tool function discovery. */\nexport const FUNCTION_KIND = \"function\" as const;\n\n/** Single tool spec from @tool function. */\nexport interface FunctionToolSpec {\n kind: typeof FUNCTION_KIND;\n name: string;\n description: string;\n inputSchema: object;\n outputSchema?: object;\n _meta?: { hitl?: { sideEffect?: SideEffect } };\n sourcePath: string;\n exportName: string;\n}\n","import type { SideEffect } from \"../function/types.js\";\n\n/** Kind for SKILL.md discovery. */\nexport const SKILL_KIND = \"skill\" as const;\n\n/** Conventional directory name for skill tools. */\nexport const SKILL_DIR_NAME = \"skill\" as const;\n\n/** Single tool spec from SKILL.md directory. */\nexport interface SkillToolSpec {\n kind: typeof SKILL_KIND;\n name: string;\n description: string;\n inputSchema: object;\n _meta?: { hitl?: { sideEffect?: SideEffect } };\n sourcePath: string;\n}\n","import type { SideEffect } from \"../function/types.js\";\n\n/** Kind for n8n workflow.json discovery. */\nexport const N8N_KIND = \"n8n\" as const;\n\n/** Single tool spec from n8n workflow.json directory. */\nexport interface N8nToolSpec {\n kind: typeof N8N_KIND;\n name: string;\n description: string;\n inputSchema: object;\n _meta?: { hitl?: { sideEffect?: SideEffect } };\n sourcePath: string;\n webhookUrl?: string;\n}\n","/**\n * Convert MCPToolSpec (function/skill/n8n scan result) to unified ToolSpec.\n * MCP layer: used by function/skill/n8n scanners when exposing unified ToolSpec.\n */\n\nimport type { ToolSpec } from \"../../core/types/ToolSpec.js\";\nimport { DEFAULT_OUTPUT_SCHEMA } from \"../../core/types/ToolSpec.js\";\nimport type { MCPToolSpec } from \"../discoveryFactory.js\";\nimport { FUNCTION_KIND } from \"../function/types.js\";\nimport { SKILL_KIND } from \"../skill/types.js\";\nimport { N8N_KIND } from \"../n8n/types.js\";\n\nconst DEFAULT_OUTPUT = { type: \"object\" as const, additionalProperties: true };\n\nexport function mcpSpecToToolSpec(spec: MCPToolSpec, projectPath?: string): ToolSpec {\n const base: ToolSpec = {\n name: spec.name,\n version: \"1.0.0\",\n kind: spec.kind,\n description: spec.description,\n inputSchema: spec.inputSchema ?? DEFAULT_OUTPUT,\n outputSchema:\n \"outputSchema\" in spec && spec.outputSchema\n ? spec.outputSchema\n : (DEFAULT_OUTPUT_SCHEMA as object),\n capabilities: [],\n _meta: spec._meta,\n ...(spec.kind === N8N_KIND && \"webhookUrl\" in spec && spec.webhookUrl\n ? { endpoint: spec.webhookUrl }\n : {}),\n };\n if (spec.kind === FUNCTION_KIND && \"sourcePath\" in spec && \"exportName\" in spec) {\n base._meta = {\n ...base._meta,\n sourcePath: spec.sourcePath,\n exportName: spec.exportName,\n ...(projectPath && { projectPath }),\n };\n }\n if (spec.kind === SKILL_KIND && \"sourcePath\" in spec && projectPath) {\n base._meta = { ...base._meta, sourcePath: spec.sourcePath, projectPath };\n }\n if (spec.kind === N8N_KIND && \"sourcePath\" in spec && projectPath) {\n base._meta = { ...base._meta, sourcePath: spec.sourcePath, projectPath };\n }\n return base;\n}\n","/**\n * Scan TypeScript source files for exported functions with @tool JSDoc.\n * Extracts description, @effect, and builds inputSchema from param types.\n * Exposes both scanForTools (raw) and scan (unified DiscoverToolsResult).\n */\n\nimport * as path from \"node:path\";\nimport * as fs from \"node:fs\";\nimport * as ts from \"typescript\";\nimport { pathToToolName } from \"../util/scanUtil.js\";\nimport { buildInputSchemaFromParams, buildOutputSchemaFromReturnType } from \"./schemaFromTs.js\";\nimport type { FunctionToolSpec, SideEffect } from \"./types.js\";\nimport { FUNCTION_KIND } from \"./types.js\";\nimport type { DiscoverToolsOptions, DiscoverToolsResult } from \"../discoveryFactory.js\";\nimport { mcpSpecToToolSpec } from \"../mcp/mcpSpecToToolSpec.js\";\n\nconst TOOL_TAG = \"@tool\";\nconst EFFECT_TAG = \"@effect\";\nconst EFFECT_VALUES: SideEffect[] = [\"none\", \"local_write\", \"external_write\", \"destructive\"];\n\nexport interface ScanResult {\n specs: FunctionToolSpec[];\n errors: Array<{ file: string; message: string }>;\n warnings: Array<{ file: string; message: string }>;\n}\n\n/**\n * Scan a project folder for exported functions annotated with @tool.\n */\nexport function scanForTools(options: {\n projectPath: string;\n include?: string[];\n tsconfigPath?: string;\n}): ScanResult {\n const projectPath = path.resolve(options.projectPath);\n const tsconfigPath =\n options.tsconfigPath ?? path.join(projectPath, \"tsconfig.json\");\n const include = options.include ?? [\"**/*.ts\"];\n const errors: Array<{ file: string; message: string }> = [];\n const warnings: Array<{ file: string; message: string }> = [];\n\n let config: ts.ParsedCommandLine;\n let configPathResolved = path.resolve(projectPath, tsconfigPath);\n if (!fs.existsSync(configPathResolved)) {\n configPathResolved = path.join(projectPath, \"tsconfig.json\");\n }\n if (fs.existsSync(configPathResolved)) {\n const configFile = ts.readConfigFile(configPathResolved, ts.sys.readFile);\n if (configFile.error) {\n errors.push({ file: configPathResolved, message: String(configFile.error.messageText) });\n return { specs: [], errors, warnings };\n }\n const parsed = ts.parseJsonConfigFileContent(\n configFile.config,\n ts.sys,\n path.dirname(configPathResolved),\n );\n if (parsed.errors.length) {\n for (const e of parsed.errors) {\n errors.push({ file: e.file?.fileName ?? \"tsconfig\", message: String(e.messageText) });\n }\n return { specs: [], errors, warnings };\n }\n config = parsed;\n } else {\n config = {\n options: {\n target: ts.ScriptTarget.ES2022,\n module: ts.ModuleKind.ESNext,\n moduleResolution: ts.ModuleResolutionKind.NodeNext,\n strict: true,\n skipLibCheck: true,\n noEmit: true,\n },\n fileNames: resolveGlob(projectPath, include),\n errors: [],\n } as ts.ParsedCommandLine;\n }\n\n const program = ts.createProgram(config.fileNames, config.options);\n const typeChecker = program.getTypeChecker();\n const specs: FunctionToolSpec[] = [];\n\n for (const sourceFile of program.getSourceFiles()) {\n const fileName = sourceFile.fileName;\n if (fileName.includes(\"node_modules\") || fileName.endsWith(\".d.ts\")) continue;\n if (!config.fileNames.some((f) => path.resolve(f) === path.resolve(fileName))) continue;\n\n ts.forEachChild(sourceFile, (node) => {\n const decl = getExportedFunctionDeclaration(node, sourceFile);\n if (!decl) return;\n const func = decl.func;\n const name = decl.name;\n if (!name) return;\n\n const host = getJSDocHost(func);\n if (!hasToolTag(host)) return;\n const jsDoc = getJSDocComments(host);\n\n const description = getDescription(jsDoc, name);\n if (!description) {\n warnings.push({ file: fileName, message: `Tool ${name}: missing description, using humanized name` });\n }\n const sideEffect = getEffect(host);\n\n const onWarn = (msg: string) => warnings.push({ file: fileName, message: `${name}: ${msg}` });\n const { schema } = buildInputSchemaFromParams(func, typeChecker, onWarn);\n\n const inputSchema =\n Object.keys((schema as { properties?: object }).properties ?? {}).length > 0\n ? schema\n : { type: \"object\" as const, properties: {} };\n\n const outputSchema = buildOutputSchemaFromReturnType(func, typeChecker, onWarn);\n\n const sourcePath = path.relative(projectPath, fileName) || path.basename(fileName);\n const toolName = pathToToolName(sourcePath, name);\n\n specs.push({\n kind: FUNCTION_KIND,\n name: toolName,\n description: description || humanize(name),\n inputSchema,\n outputSchema,\n _meta: { hitl: { sideEffect } },\n sourcePath,\n exportName: name,\n });\n });\n }\n\n return { specs, errors, warnings };\n}\n\nfunction resolveGlob(projectPath: string, patterns: string[]): string[] {\n const result: string[] = [];\n const seen = new Set<string>();\n const add = (f: string) => {\n const abs = path.resolve(f);\n if (f.endsWith(\".ts\") && !f.endsWith(\".d.ts\") && !seen.has(abs)) {\n seen.add(abs);\n result.push(abs);\n }\n };\n for (const p of patterns) {\n const full = path.join(projectPath, p);\n if (full.includes(\"*\")) {\n const baseDir = full.replace(/\\*\\*\\/.*$/, \"\").replace(/\\*.*$/, \"\").replace(/\\/?$/, \"\") || \".\";\n const dir = path.resolve(projectPath, baseDir);\n if (fs.existsSync(dir)) walk(dir, add);\n } else {\n const resolved = path.resolve(projectPath, full);\n if (fs.existsSync(resolved)) {\n if (fs.statSync(resolved).isFile()) add(resolved);\n else walk(resolved, add);\n }\n }\n }\n if (result.length > 0) return result;\n const srcDir = path.join(projectPath, \"src\");\n if (fs.existsSync(srcDir)) return walkCollect(srcDir);\n return [];\n}\n\nfunction walkCollect(dir: string): string[] {\n const out: string[] = [];\n walk(dir, (fullPath) => {\n if (fullPath.endsWith(\".ts\") && !fullPath.endsWith(\".d.ts\")) out.push(path.resolve(fullPath));\n });\n return out;\n}\n\nconst SKIP_DIRS = new Set([\"node_modules\", \"generated\", \"dist\"]);\n\nfunction walk(dir: string, visit: (fullPath: string) => void): void {\n try {\n const entries = fs.readdirSync(dir, { withFileTypes: true });\n for (const e of entries) {\n const full = path.join(dir, e.name);\n if (e.isDirectory() && !SKIP_DIRS.has(e.name)) walk(full, visit);\n else if (e.isFile()) visit(full);\n }\n } catch {\n // ignore\n }\n}\n\nfunction getExportedFunctionDeclaration(\n node: ts.Node,\n _sourceFile: ts.SourceFile,\n): { func: ts.FunctionDeclaration | ts.ArrowFunction | ts.FunctionExpression; name: string } | null {\n if (ts.isFunctionDeclaration(node) && node.name) {\n const exported = (ts.getModifiers(node) ?? []).some((m) => m.kind === ts.SyntaxKind.ExportKeyword);\n if (exported) return { func: node, name: node.name.getText() };\n return null;\n }\n if (ts.isVariableStatement(node)) {\n const exported = (ts.getModifiers(node) ?? []).some((m) => m.kind === ts.SyntaxKind.ExportKeyword);\n if (!exported) return null;\n for (const decl of node.declarationList.declarations) {\n let init = decl.initializer;\n while (init && (ts.isParenthesizedExpression(init) || ts.isAsExpression(init)))\n init = init.expression;\n if (init && ts.isArrowFunction(init)) {\n const name = (decl.name as ts.Identifier).getText();\n return { func: init, name };\n }\n if (init && ts.isFunctionExpression(init)) {\n const name = (decl.name as ts.Identifier).getText();\n return { func: init, name };\n }\n }\n }\n return null;\n}\n\nfunction getJSDocHost(node: ts.FunctionDeclaration | ts.ArrowFunction | ts.FunctionExpression): ts.Node {\n const parent = node.parent;\n if (ts.isVariableDeclaration(parent)) {\n const gp = parent.parent;\n if (ts.isVariableDeclarationList(gp) && gp.parent && ts.isVariableStatement(gp.parent)) return gp.parent;\n }\n return node as ts.Node;\n}\n\nfunction getJSDocComments(host: ts.Node): ts.JSDoc[] {\n const all = ts.getJSDocCommentsAndTags(host);\n return all.filter((t): t is ts.JSDoc => ts.isJSDoc(t));\n}\n\nfunction hasToolTag(host: ts.Node): boolean {\n const tags = ts.getJSDocTags(host);\n for (const tag of tags) {\n const name = (tag as { tagName?: ts.Identifier }).tagName?.getText() ?? \"\";\n if (name === \"tool\") return true;\n }\n const all = ts.getJSDocCommentsAndTags(host);\n for (const t of all) {\n if (ts.isJSDoc(t)) {\n const full = t.getFullText();\n if (full.includes(TOOL_TAG)) return true;\n }\n }\n return false;\n}\n\nfunction getDescription(jsDocs: ts.JSDoc[], fallbackName: string): string {\n for (const doc of jsDocs) {\n const comment = doc.comment;\n if (typeof comment === \"string\") {\n const first = comment.split(/\\n/)[0]?.trim() ?? \"\";\n if (first && !first.startsWith(\"@\")) return first;\n }\n if (Array.isArray(comment)) {\n const first = comment[0];\n if (first && typeof first === \"object\" && \"text\" in first) {\n const t = (first as { text: string }).text.trim();\n if (t && !t.startsWith(\"@\")) return t;\n }\n }\n const full = doc.getFullText();\n const match = full.match(/\\*\\s*@tool\\s+(.+?)(?=\\n|$|\\*\\/)/s);\n if (match?.[1]) return match[1].trim();\n }\n return \"\";\n}\n\nfunction getEffect(host: ts.Node): SideEffect {\n const tags = ts.getJSDocTags(host);\n for (const tag of tags) {\n const name = (tag as { tagName?: ts.Identifier }).tagName?.getText() ?? \"\";\n if (name === \"effect\") {\n const comment = (tag as ts.JSDocUnknownTag).comment;\n const v = (typeof comment === \"string\" ? comment : \"\").trim().toLowerCase();\n if (EFFECT_VALUES.includes(v as SideEffect)) return v as SideEffect;\n }\n }\n const all = ts.getJSDocCommentsAndTags(host);\n for (const t of all) {\n if (ts.isJSDoc(t)) {\n const full = t.getFullText();\n const match = full.match(/\\*\\s*@effect\\s+(\\w+)/);\n if (match && EFFECT_VALUES.includes(match[1] as SideEffect)) return match[1] as SideEffect;\n }\n }\n return \"none\";\n}\n\nfunction humanize(name: string): string {\n return name.replace(/([A-Z])/g, \" $1\").replace(/^./, (s) => s.toUpperCase()).trim();\n}\n\n/** Unified scan: (path, options) → DiscoverToolsResult. */\nexport function scan(\n projectPath: string,\n options: DiscoverToolsOptions = {},\n): Promise<DiscoverToolsResult> {\n const root = path.resolve(projectPath);\n const result = scanForTools({\n projectPath: root,\n include: options.include ?? [\"**/*.ts\"],\n tsconfigPath: options.tsconfigPath,\n });\n const specs = result.specs.map((s) => mcpSpecToToolSpec(s, root));\n return Promise.resolve({\n specs,\n errors: result.errors,\n warnings: result.warnings,\n });\n}\n"]}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { discoverTools
|
|
1
|
+
import { discoverTools } from './chunk-YRFUGA3C.js';
|
|
2
|
+
import { FUNCTION_KIND, SKILL_KIND, N8N_KIND } from './chunk-45S2HPVU.js';
|
|
2
3
|
import * as fs2 from 'fs/promises';
|
|
3
4
|
import * as path3 from 'path';
|
|
4
5
|
import { fileURLToPath } from 'url';
|
|
@@ -19,14 +20,14 @@ var TEMPLATES = {
|
|
|
19
20
|
}
|
|
20
21
|
}
|
|
21
22
|
`,
|
|
22
|
-
"build.mjs": `import {
|
|
23
|
+
"build.mjs": `import { buildMCPPackage } from "@easynet/agent-tool/build";
|
|
23
24
|
|
|
24
|
-
const result = await
|
|
25
|
+
const result = await buildMCPPackage({ outDir: "dist" });
|
|
25
26
|
console.log("Built", result.toolCount, "tool(s) ->", result.outDir);
|
|
26
27
|
`,
|
|
27
|
-
"start.mjs": `import {
|
|
28
|
+
"start.mjs": `import { runMCPServer } from "@easynet/agent-tool/build";
|
|
28
29
|
|
|
29
|
-
const { process: child } = await
|
|
30
|
+
const { process: child } = await runMCPServer({ path: "./dist" });
|
|
30
31
|
child.stdin?.pipe(process.stdin);
|
|
31
32
|
child.stdout?.pipe(process.stdout);
|
|
32
33
|
child.stderr?.pipe(process.stderr);
|
|
@@ -253,7 +254,7 @@ async function generate(options) {
|
|
|
253
254
|
}
|
|
254
255
|
|
|
255
256
|
// src/api/expose/mcp-build/build.ts
|
|
256
|
-
async function
|
|
257
|
+
async function buildMCPPackage(options = {}) {
|
|
257
258
|
const projectPath = path3.resolve(options.projectPath ?? process.cwd());
|
|
258
259
|
const outDir = path3.resolve(projectPath, options.outDir ?? "dist");
|
|
259
260
|
const include = options.include ?? ["**/*.ts"];
|
|
@@ -285,8 +286,7 @@ async function buildMcpPackage(options = {}) {
|
|
|
285
286
|
mcpJsonPath
|
|
286
287
|
};
|
|
287
288
|
}
|
|
288
|
-
|
|
289
|
-
async function runMcpServer(options = {}) {
|
|
289
|
+
async function runMCPServer(options = {}) {
|
|
290
290
|
const base = options.path ?? process.cwd();
|
|
291
291
|
const candidates = [
|
|
292
292
|
path3.join(base, "mcp-server.ts"),
|
|
@@ -318,8 +318,7 @@ async function runMcpServer(options = {}) {
|
|
|
318
318
|
});
|
|
319
319
|
return { process: child };
|
|
320
320
|
}
|
|
321
|
-
var runGeneratedMCP = runMcpServer;
|
|
322
321
|
|
|
323
|
-
export {
|
|
324
|
-
//# sourceMappingURL=chunk-
|
|
325
|
-
//# sourceMappingURL=chunk-
|
|
322
|
+
export { buildMCPPackage, initProject, runMCPServer };
|
|
323
|
+
//# sourceMappingURL=chunk-5J27MF7S.js.map
|
|
324
|
+
//# sourceMappingURL=chunk-5J27MF7S.js.map
|