opentool 0.8.7 → 0.8.9
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 +1 -1
- package/dist/cli/index.d.ts +2 -2
- package/dist/cli/index.js +81 -77
- package/dist/cli/index.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +36 -32
- package/dist/index.js.map +1 -1
- package/dist/{validate-3e5UvzfQ.d.ts → validate-M_QdV0J3.d.ts} +3 -1
- package/package.json +1 -1
- package/templates/base/package.json +1 -1
package/README.md
CHANGED
|
@@ -73,7 +73,7 @@ For private tools, say for internal trading apps:
|
|
|
73
73
|
|
|
74
74
|
- GET-only (scheduled default profile)
|
|
75
75
|
- POST-only (one-off, parameterized with Zod)
|
|
76
|
-
|
|
76
|
+
- `profile.category` defaults to `tracker` if omitted; set to `strategy` or `orchestator` for PnL/automation tools.
|
|
77
77
|
|
|
78
78
|
GET-only (scheduled default)
|
|
79
79
|
|
package/dist/cli/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { M as Metadata, I as InternalToolDefinition } from '../validate-
|
|
3
|
-
export { G as GenerateMetadataOptions, a as GenerateMetadataResult, V as ValidateOptions, b as generateMetadata, g as generateMetadataCommand, l as loadAndValidateTools, v as validateCommand, c as validateFullCommand } from '../validate-
|
|
2
|
+
import { M as Metadata, I as InternalToolDefinition } from '../validate-M_QdV0J3.js';
|
|
3
|
+
export { G as GenerateMetadataOptions, a as GenerateMetadataResult, V as ValidateOptions, b as generateMetadata, g as generateMetadataCommand, l as loadAndValidateTools, v as validateCommand, c as validateFullCommand } from '../validate-M_QdV0J3.js';
|
|
4
4
|
import 'zod';
|
|
5
5
|
import '../x402/index.js';
|
|
6
6
|
import 'viem';
|
package/dist/cli/index.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import * as path6 from 'path';
|
|
3
|
+
import path6__default from 'path';
|
|
4
|
+
import { fileURLToPath, pathToFileURL } from 'url';
|
|
2
5
|
import { program } from 'commander';
|
|
3
6
|
import * as fs4 from 'fs';
|
|
4
7
|
import { promises } from 'fs';
|
|
5
|
-
import * as path5 from 'path';
|
|
6
|
-
import path5__default from 'path';
|
|
7
8
|
import { tmpdir } from 'os';
|
|
8
9
|
import { build } from 'esbuild';
|
|
9
10
|
import { z } from 'zod';
|
|
10
11
|
import { createRequire } from 'module';
|
|
11
|
-
import { fileURLToPath, pathToFileURL } from 'url';
|
|
12
12
|
import { zodToJsonSchema } from '@alcyone-labs/zod-to-json-schema';
|
|
13
13
|
import 'viem';
|
|
14
14
|
import 'viem/accounts';
|
|
@@ -19,8 +19,10 @@ import { ListToolsRequestSchema, CallToolRequestSchema } from '@modelcontextprot
|
|
|
19
19
|
import * as http2 from 'http';
|
|
20
20
|
import dotenv from 'dotenv';
|
|
21
21
|
|
|
22
|
+
var getFilename = () => fileURLToPath(import.meta.url);
|
|
23
|
+
var __filename = /* @__PURE__ */ getFilename();
|
|
22
24
|
function resolveTsconfig(projectRoot) {
|
|
23
|
-
const candidate =
|
|
25
|
+
const candidate = path6.join(projectRoot, "tsconfig.json");
|
|
24
26
|
if (fs4.existsSync(candidate)) {
|
|
25
27
|
return candidate;
|
|
26
28
|
}
|
|
@@ -31,7 +33,7 @@ async function transpileWithEsbuild(options) {
|
|
|
31
33
|
throw new Error("No entry points provided for esbuild transpilation");
|
|
32
34
|
}
|
|
33
35
|
const projectRoot = options.projectRoot;
|
|
34
|
-
const tempBase = options.outDir ?? fs4.mkdtempSync(
|
|
36
|
+
const tempBase = options.outDir ?? fs4.mkdtempSync(path6.join(tmpdir(), "opentool-"));
|
|
35
37
|
if (!fs4.existsSync(tempBase)) {
|
|
36
38
|
fs4.mkdirSync(tempBase, { recursive: true });
|
|
37
39
|
}
|
|
@@ -75,7 +77,7 @@ async function transpileWithEsbuild(options) {
|
|
|
75
77
|
}
|
|
76
78
|
await build(buildOptions);
|
|
77
79
|
if (options.format === "esm") {
|
|
78
|
-
const packageJsonPath =
|
|
80
|
+
const packageJsonPath = path6.join(tempBase, "package.json");
|
|
79
81
|
if (!fs4.existsSync(packageJsonPath)) {
|
|
80
82
|
fs4.writeFileSync(packageJsonPath, JSON.stringify({ type: "module" }), "utf8");
|
|
81
83
|
}
|
|
@@ -139,7 +141,7 @@ var DiscoveryMetadataSchema = z.object({
|
|
|
139
141
|
compatibility: z.record(z.string(), z.any()).optional(),
|
|
140
142
|
documentation: z.union([z.string(), z.array(z.string())]).optional()
|
|
141
143
|
}).catchall(z.any());
|
|
142
|
-
var ToolCategorySchema = z.enum(["strategy", "tracker"]);
|
|
144
|
+
var ToolCategorySchema = z.enum(["strategy", "tracker", "orchestator"]);
|
|
143
145
|
var ToolMetadataOverridesSchema = z.object({
|
|
144
146
|
name: z.string().optional(),
|
|
145
147
|
description: z.string().optional(),
|
|
@@ -208,10 +210,12 @@ var BuildMetadataSchema = z.object({
|
|
|
208
210
|
animation_url: z.string().optional(),
|
|
209
211
|
chains: z.array(z.union([z.string(), z.number()])).optional()
|
|
210
212
|
}).strict();
|
|
211
|
-
createRequire(
|
|
213
|
+
createRequire(
|
|
214
|
+
typeof __filename !== "undefined" ? __filename : import.meta.url
|
|
215
|
+
);
|
|
212
216
|
function resolveCompiledPath(outDir, originalFile, extension = ".js") {
|
|
213
|
-
const baseName =
|
|
214
|
-
return
|
|
217
|
+
const baseName = path6.basename(originalFile).replace(/\.[^.]+$/, "");
|
|
218
|
+
return path6.join(outDir, `${baseName}${extension}`);
|
|
215
219
|
}
|
|
216
220
|
async function importFresh(modulePath) {
|
|
217
221
|
const fileUrl = pathToFileURL(modulePath).href;
|
|
@@ -223,13 +227,13 @@ async function importFresh(modulePath) {
|
|
|
223
227
|
// src/cli/shared/metadata.ts
|
|
224
228
|
var METADATA_ENTRY = "metadata.ts";
|
|
225
229
|
async function loadMetadata(projectRoot) {
|
|
226
|
-
const absPath =
|
|
230
|
+
const absPath = path6.join(projectRoot, METADATA_ENTRY);
|
|
227
231
|
if (!fs4.existsSync(absPath)) {
|
|
228
232
|
throw new Error(
|
|
229
233
|
`metadata.ts not found in ${projectRoot}. Create metadata.ts to describe your agent.`
|
|
230
234
|
);
|
|
231
235
|
}
|
|
232
|
-
const tempDir =
|
|
236
|
+
const tempDir = path6.join(projectRoot, ".opentool-temp");
|
|
233
237
|
if (fs4.existsSync(tempDir)) {
|
|
234
238
|
fs4.rmSync(tempDir, { recursive: true, force: true });
|
|
235
239
|
}
|
|
@@ -270,7 +274,7 @@ function extractMetadataExport(moduleExports) {
|
|
|
270
274
|
return moduleExports;
|
|
271
275
|
}
|
|
272
276
|
function readPackageJson(projectRoot) {
|
|
273
|
-
const packagePath =
|
|
277
|
+
const packagePath = path6.join(projectRoot, "package.json");
|
|
274
278
|
if (!fs4.existsSync(packagePath)) {
|
|
275
279
|
return {};
|
|
276
280
|
}
|
|
@@ -286,7 +290,7 @@ async function buildMetadataArtifact(options) {
|
|
|
286
290
|
const packageInfo = readPackageJson(projectRoot);
|
|
287
291
|
const { metadata: authored, sourcePath } = await loadMetadata(projectRoot);
|
|
288
292
|
const defaultsApplied = [];
|
|
289
|
-
const folderName =
|
|
293
|
+
const folderName = path6.basename(projectRoot);
|
|
290
294
|
const name = resolveField(
|
|
291
295
|
"name",
|
|
292
296
|
authored.name,
|
|
@@ -999,11 +1003,11 @@ var SUPPORTED_EXTENSIONS = [
|
|
|
999
1003
|
async function validateCommand(options) {
|
|
1000
1004
|
console.log("\u{1F50D} Validating OpenTool metadata...");
|
|
1001
1005
|
try {
|
|
1002
|
-
const toolsDir =
|
|
1006
|
+
const toolsDir = path6.resolve(options.input);
|
|
1003
1007
|
if (!fs4.existsSync(toolsDir)) {
|
|
1004
1008
|
throw new Error(`Tools directory not found: ${toolsDir}`);
|
|
1005
1009
|
}
|
|
1006
|
-
const projectRoot =
|
|
1010
|
+
const projectRoot = path6.dirname(toolsDir);
|
|
1007
1011
|
const tools = await loadAndValidateTools(toolsDir, { projectRoot });
|
|
1008
1012
|
if (tools.length === 0) {
|
|
1009
1013
|
throw new Error("No valid tools found - metadata validation aborted");
|
|
@@ -1022,11 +1026,11 @@ async function validateCommand(options) {
|
|
|
1022
1026
|
async function validateFullCommand(options) {
|
|
1023
1027
|
console.log("\u{1F50D} Running full OpenTool validation...\n");
|
|
1024
1028
|
try {
|
|
1025
|
-
const toolsDir =
|
|
1029
|
+
const toolsDir = path6.resolve(options.input);
|
|
1026
1030
|
if (!fs4.existsSync(toolsDir)) {
|
|
1027
1031
|
throw new Error(`Tools directory not found: ${toolsDir}`);
|
|
1028
1032
|
}
|
|
1029
|
-
const projectRoot =
|
|
1033
|
+
const projectRoot = path6.dirname(toolsDir);
|
|
1030
1034
|
const tools = await loadAndValidateTools(toolsDir, { projectRoot });
|
|
1031
1035
|
if (tools.length === 0) {
|
|
1032
1036
|
throw new Error("No tools discovered in the target directory");
|
|
@@ -1054,12 +1058,12 @@ async function validateFullCommand(options) {
|
|
|
1054
1058
|
}
|
|
1055
1059
|
}
|
|
1056
1060
|
async function loadAndValidateTools(toolsDir, options = {}) {
|
|
1057
|
-
const files = fs4.readdirSync(toolsDir).filter((file) => SUPPORTED_EXTENSIONS.includes(
|
|
1061
|
+
const files = fs4.readdirSync(toolsDir).filter((file) => SUPPORTED_EXTENSIONS.includes(path6.extname(file)));
|
|
1058
1062
|
if (files.length === 0) {
|
|
1059
1063
|
return [];
|
|
1060
1064
|
}
|
|
1061
|
-
const projectRoot = options.projectRoot ??
|
|
1062
|
-
const tempDir =
|
|
1065
|
+
const projectRoot = options.projectRoot ?? path6.dirname(toolsDir);
|
|
1066
|
+
const tempDir = path6.join(toolsDir, ".opentool-temp");
|
|
1063
1067
|
if (fs4.existsSync(tempDir)) {
|
|
1064
1068
|
fs4.rmSync(tempDir, { recursive: true, force: true });
|
|
1065
1069
|
}
|
|
@@ -1069,7 +1073,7 @@ async function loadAndValidateTools(toolsDir, options = {}) {
|
|
|
1069
1073
|
throw new Error(`Tool filename must be kebab-case: ${f}`);
|
|
1070
1074
|
}
|
|
1071
1075
|
}
|
|
1072
|
-
const entryPoints = files.map((file) =>
|
|
1076
|
+
const entryPoints = files.map((file) => path6.join(toolsDir, file));
|
|
1073
1077
|
const { outDir, cleanup } = await transpileWithEsbuild({
|
|
1074
1078
|
entryPoints,
|
|
1075
1079
|
projectRoot,
|
|
@@ -1110,7 +1114,7 @@ async function loadAndValidateTools(toolsDir, options = {}) {
|
|
|
1110
1114
|
const schedule = toolModule?.profile?.schedule;
|
|
1111
1115
|
const profileNotifyEmail = typeof toolModule?.profile?.notifyEmail === "boolean" ? toolModule.profile.notifyEmail : void 0;
|
|
1112
1116
|
const profileCategoryRaw = typeof toolModule?.profile?.category === "string" ? toolModule.profile.category : void 0;
|
|
1113
|
-
const allowedProfileCategories = /* @__PURE__ */ new Set(["strategy", "tracker"]);
|
|
1117
|
+
const allowedProfileCategories = /* @__PURE__ */ new Set(["strategy", "tracker", "orchestator"]);
|
|
1114
1118
|
if (profileCategoryRaw && !allowedProfileCategories.has(profileCategoryRaw)) {
|
|
1115
1119
|
throw new Error(
|
|
1116
1120
|
`${file}: profile.category must be one of ${Array.from(allowedProfileCategories).join(", ")}`
|
|
@@ -1181,7 +1185,7 @@ async function loadAndValidateTools(toolsDir, options = {}) {
|
|
|
1181
1185
|
httpHandlers,
|
|
1182
1186
|
mcpConfig: normalizeMcpConfig(toolModule.mcp, file),
|
|
1183
1187
|
filename: toBaseName(file),
|
|
1184
|
-
sourcePath:
|
|
1188
|
+
sourcePath: path6.join(toolsDir, file),
|
|
1185
1189
|
handler: async (params) => adapter(params),
|
|
1186
1190
|
payment: paymentExport ?? null,
|
|
1187
1191
|
schedule: normalizedSchedule,
|
|
@@ -1386,12 +1390,12 @@ async function buildCommand(options) {
|
|
|
1386
1390
|
}
|
|
1387
1391
|
}
|
|
1388
1392
|
async function buildProject(options) {
|
|
1389
|
-
const toolsDir =
|
|
1393
|
+
const toolsDir = path6.resolve(options.input);
|
|
1390
1394
|
if (!fs4.existsSync(toolsDir)) {
|
|
1391
1395
|
throw new Error(`Tools directory not found: ${toolsDir}`);
|
|
1392
1396
|
}
|
|
1393
|
-
const projectRoot =
|
|
1394
|
-
const outputDir =
|
|
1397
|
+
const projectRoot = path6.dirname(toolsDir);
|
|
1398
|
+
const outputDir = path6.resolve(options.output);
|
|
1395
1399
|
fs4.mkdirSync(outputDir, { recursive: true });
|
|
1396
1400
|
const serverName = options.name ?? "opentool-server";
|
|
1397
1401
|
const serverVersion = options.version ?? "1.0.0";
|
|
@@ -1403,7 +1407,7 @@ async function buildProject(options) {
|
|
|
1403
1407
|
projectRoot,
|
|
1404
1408
|
tools
|
|
1405
1409
|
});
|
|
1406
|
-
const metadataPath =
|
|
1410
|
+
const metadataPath = path6.join(outputDir, "metadata.json");
|
|
1407
1411
|
fs4.writeFileSync(metadataPath, JSON.stringify(metadata, null, 2));
|
|
1408
1412
|
const compiledTools = await emitTools(tools, {
|
|
1409
1413
|
projectRoot,
|
|
@@ -1430,7 +1434,7 @@ async function buildProject(options) {
|
|
|
1430
1434
|
serverVersion,
|
|
1431
1435
|
compiledTools});
|
|
1432
1436
|
} else {
|
|
1433
|
-
const serverPath =
|
|
1437
|
+
const serverPath = path6.join(outputDir, "mcp-server.js");
|
|
1434
1438
|
if (fs4.existsSync(serverPath)) {
|
|
1435
1439
|
fs4.rmSync(serverPath);
|
|
1436
1440
|
}
|
|
@@ -1446,7 +1450,7 @@ async function buildProject(options) {
|
|
|
1446
1450
|
};
|
|
1447
1451
|
}
|
|
1448
1452
|
async function emitTools(tools, config) {
|
|
1449
|
-
const toolsOutDir =
|
|
1453
|
+
const toolsOutDir = path6.join(config.outputDir, "tools");
|
|
1450
1454
|
if (fs4.existsSync(toolsOutDir)) {
|
|
1451
1455
|
fs4.rmSync(toolsOutDir, { recursive: true, force: true });
|
|
1452
1456
|
}
|
|
@@ -1468,9 +1472,9 @@ async function emitTools(tools, config) {
|
|
|
1468
1472
|
if (!tool.sourcePath) {
|
|
1469
1473
|
throw new Error(`Missing sourcePath for tool ${tool.filename}`);
|
|
1470
1474
|
}
|
|
1471
|
-
const base =
|
|
1472
|
-
const modulePath =
|
|
1473
|
-
if (!fs4.existsSync(
|
|
1475
|
+
const base = path6.basename(tool.sourcePath).replace(/\.[^.]+$/, "");
|
|
1476
|
+
const modulePath = path6.join("tools", `${base}.js`);
|
|
1477
|
+
if (!fs4.existsSync(path6.join(config.outputDir, modulePath))) {
|
|
1474
1478
|
throw new Error(`Expected compiled output missing: ${modulePath}`);
|
|
1475
1479
|
}
|
|
1476
1480
|
const defaultMcpMethod = tool.mcpConfig?.defaultMethod;
|
|
@@ -1487,7 +1491,7 @@ async function emitTools(tools, config) {
|
|
|
1487
1491
|
return compiled;
|
|
1488
1492
|
}
|
|
1489
1493
|
async function emitSharedModules(config) {
|
|
1490
|
-
const srcDir =
|
|
1494
|
+
const srcDir = path6.join(config.projectRoot, "src");
|
|
1491
1495
|
if (!fs4.existsSync(srcDir)) {
|
|
1492
1496
|
return null;
|
|
1493
1497
|
}
|
|
@@ -1495,7 +1499,7 @@ async function emitSharedModules(config) {
|
|
|
1495
1499
|
if (sharedFiles.length === 0) {
|
|
1496
1500
|
return null;
|
|
1497
1501
|
}
|
|
1498
|
-
const sharedOutDir =
|
|
1502
|
+
const sharedOutDir = path6.join(config.outputDir, "src");
|
|
1499
1503
|
await transpileWithEsbuild({
|
|
1500
1504
|
entryPoints: sharedFiles,
|
|
1501
1505
|
projectRoot: config.projectRoot,
|
|
@@ -1513,7 +1517,7 @@ function collectSourceFiles(dir) {
|
|
|
1513
1517
|
const ignoreDirs = /* @__PURE__ */ new Set(["node_modules", ".git", "dist", ".opentool-temp"]);
|
|
1514
1518
|
const entries = fs4.readdirSync(dir, { withFileTypes: true });
|
|
1515
1519
|
for (const entry of entries) {
|
|
1516
|
-
const fullPath =
|
|
1520
|
+
const fullPath = path6.join(dir, entry.name);
|
|
1517
1521
|
if (entry.isDirectory()) {
|
|
1518
1522
|
if (ignoreDirs.has(entry.name)) {
|
|
1519
1523
|
continue;
|
|
@@ -1521,7 +1525,7 @@ function collectSourceFiles(dir) {
|
|
|
1521
1525
|
results.push(...collectSourceFiles(fullPath));
|
|
1522
1526
|
continue;
|
|
1523
1527
|
}
|
|
1524
|
-
const ext =
|
|
1528
|
+
const ext = path6.extname(entry.name);
|
|
1525
1529
|
if (supported.has(ext) && !entry.name.endsWith(".d.ts")) {
|
|
1526
1530
|
results.push(fullPath);
|
|
1527
1531
|
}
|
|
@@ -1623,14 +1627,14 @@ module.exports = { server };
|
|
|
1623
1627
|
}
|
|
1624
1628
|
async function writeMcpServer(options) {
|
|
1625
1629
|
const serverCode = renderMcpServer(options);
|
|
1626
|
-
const serverPath =
|
|
1630
|
+
const serverPath = path6.join(options.outputDir, "mcp-server.js");
|
|
1627
1631
|
fs4.writeFileSync(serverPath, serverCode);
|
|
1628
1632
|
fs4.chmodSync(serverPath, 493);
|
|
1629
1633
|
}
|
|
1630
1634
|
function writeCronManifest(options) {
|
|
1631
1635
|
const scheduledTools = options.tools.filter((tool) => tool.schedule?.expression);
|
|
1632
|
-
const manifestDir =
|
|
1633
|
-
const manifestPath =
|
|
1636
|
+
const manifestDir = path6.join(options.outputDir, ".well-known", "opentool");
|
|
1637
|
+
const manifestPath = path6.join(manifestDir, "cron.json");
|
|
1634
1638
|
if (scheduledTools.length === 0) {
|
|
1635
1639
|
if (fs4.existsSync(manifestPath)) {
|
|
1636
1640
|
fs4.rmSync(manifestPath);
|
|
@@ -1680,7 +1684,7 @@ function writeCronManifest(options) {
|
|
|
1680
1684
|
function logBuildSummary(artifacts, options) {
|
|
1681
1685
|
const end = timestamp();
|
|
1682
1686
|
console.log(`[${end}] Build completed successfully!`);
|
|
1683
|
-
console.log(`Output directory: ${
|
|
1687
|
+
console.log(`Output directory: ${path6.resolve(options.output)}`);
|
|
1684
1688
|
console.log("Generated files:");
|
|
1685
1689
|
const hasMcp = artifacts.compiledTools.some((tool) => tool.mcpEnabled);
|
|
1686
1690
|
if (hasMcp) {
|
|
@@ -1722,7 +1726,7 @@ function logBuildSummary(artifacts, options) {
|
|
|
1722
1726
|
}
|
|
1723
1727
|
}
|
|
1724
1728
|
async function buildWorkflowsIfPresent(options) {
|
|
1725
|
-
const workflowsDir = options.workflowsDir ??
|
|
1729
|
+
const workflowsDir = options.workflowsDir ?? path6.join(options.projectRoot, "workflows");
|
|
1726
1730
|
if (!fs4.existsSync(workflowsDir)) {
|
|
1727
1731
|
return null;
|
|
1728
1732
|
}
|
|
@@ -1769,11 +1773,11 @@ Reason: ${error.message}` : "";
|
|
|
1769
1773
|
"Creating OpenTool workflow steps bundle at",
|
|
1770
1774
|
this.config.stepsBundlePath
|
|
1771
1775
|
);
|
|
1772
|
-
const stepsBundlePath2 =
|
|
1776
|
+
const stepsBundlePath2 = path6.resolve(
|
|
1773
1777
|
this.config.workingDir,
|
|
1774
1778
|
this.config.stepsBundlePath
|
|
1775
1779
|
);
|
|
1776
|
-
await fs4.promises.mkdir(
|
|
1780
|
+
await fs4.promises.mkdir(path6.dirname(stepsBundlePath2), { recursive: true });
|
|
1777
1781
|
await this.createStepsBundle({
|
|
1778
1782
|
outfile: stepsBundlePath2,
|
|
1779
1783
|
...options2
|
|
@@ -1784,11 +1788,11 @@ Reason: ${error.message}` : "";
|
|
|
1784
1788
|
"Creating OpenTool workflow bundle at",
|
|
1785
1789
|
this.config.workflowsBundlePath
|
|
1786
1790
|
);
|
|
1787
|
-
const workflowBundlePath =
|
|
1791
|
+
const workflowBundlePath = path6.resolve(
|
|
1788
1792
|
this.config.workingDir,
|
|
1789
1793
|
this.config.workflowsBundlePath
|
|
1790
1794
|
);
|
|
1791
|
-
await fs4.promises.mkdir(
|
|
1795
|
+
await fs4.promises.mkdir(path6.dirname(workflowBundlePath), {
|
|
1792
1796
|
recursive: true
|
|
1793
1797
|
});
|
|
1794
1798
|
await this.createWorkflowsBundle({
|
|
@@ -1802,11 +1806,11 @@ Reason: ${error.message}` : "";
|
|
|
1802
1806
|
"Creating OpenTool workflow webhook bundle at",
|
|
1803
1807
|
this.config.webhookBundlePath
|
|
1804
1808
|
);
|
|
1805
|
-
const webhookBundlePath2 =
|
|
1809
|
+
const webhookBundlePath2 = path6.resolve(
|
|
1806
1810
|
this.config.workingDir,
|
|
1807
1811
|
this.config.webhookBundlePath
|
|
1808
1812
|
);
|
|
1809
|
-
await fs4.promises.mkdir(
|
|
1813
|
+
await fs4.promises.mkdir(path6.dirname(webhookBundlePath2), {
|
|
1810
1814
|
recursive: true
|
|
1811
1815
|
});
|
|
1812
1816
|
await this.createWebhookBundle({ outfile: webhookBundlePath2 });
|
|
@@ -1815,11 +1819,11 @@ Reason: ${error.message}` : "";
|
|
|
1815
1819
|
if (!this.config?.clientBundlePath) {
|
|
1816
1820
|
return;
|
|
1817
1821
|
}
|
|
1818
|
-
const clientBundlePath2 =
|
|
1822
|
+
const clientBundlePath2 = path6.resolve(
|
|
1819
1823
|
this.config.workingDir,
|
|
1820
1824
|
this.config.clientBundlePath
|
|
1821
1825
|
);
|
|
1822
|
-
await fs4.promises.mkdir(
|
|
1826
|
+
await fs4.promises.mkdir(path6.dirname(clientBundlePath2), {
|
|
1823
1827
|
recursive: true
|
|
1824
1828
|
});
|
|
1825
1829
|
await this.createWorkflowsBundle({
|
|
@@ -1828,17 +1832,17 @@ Reason: ${error.message}` : "";
|
|
|
1828
1832
|
});
|
|
1829
1833
|
}
|
|
1830
1834
|
}
|
|
1831
|
-
const relativeSourceDir =
|
|
1832
|
-
const outputBase =
|
|
1835
|
+
const relativeSourceDir = path6.relative(options.projectRoot, workflowsDir) || ".";
|
|
1836
|
+
const outputBase = path6.join(
|
|
1833
1837
|
options.outputDir,
|
|
1834
1838
|
".well-known",
|
|
1835
1839
|
"workflow",
|
|
1836
1840
|
"v1"
|
|
1837
1841
|
);
|
|
1838
|
-
const stepsBundlePath =
|
|
1839
|
-
const workflowsBundlePath =
|
|
1840
|
-
const webhookBundlePath =
|
|
1841
|
-
const manifestPath =
|
|
1842
|
+
const stepsBundlePath = path6.join(outputBase, "step.js");
|
|
1843
|
+
const workflowsBundlePath = path6.join(outputBase, "flow.js");
|
|
1844
|
+
const webhookBundlePath = path6.join(outputBase, "webhook.js");
|
|
1845
|
+
const manifestPath = path6.join(outputBase, "manifest.json");
|
|
1842
1846
|
const builder = new OpenToolWorkflowBuilder({
|
|
1843
1847
|
workingDir: options.projectRoot,
|
|
1844
1848
|
dirs: [relativeSourceDir],
|
|
@@ -1874,13 +1878,13 @@ function hasWorkflowSourceFiles(directory) {
|
|
|
1874
1878
|
const entries = fs4.readdirSync(directory, { withFileTypes: true });
|
|
1875
1879
|
for (const entry of entries) {
|
|
1876
1880
|
if (entry.isDirectory()) {
|
|
1877
|
-
if (hasWorkflowSourceFiles(
|
|
1881
|
+
if (hasWorkflowSourceFiles(path6.join(directory, entry.name))) {
|
|
1878
1882
|
return true;
|
|
1879
1883
|
}
|
|
1880
1884
|
continue;
|
|
1881
1885
|
}
|
|
1882
1886
|
if (entry.isFile()) {
|
|
1883
|
-
const extension =
|
|
1887
|
+
const extension = path6.extname(entry.name).toLowerCase();
|
|
1884
1888
|
if (WORKFLOW_SOURCE_EXTENSIONS.has(extension)) {
|
|
1885
1889
|
return true;
|
|
1886
1890
|
}
|
|
@@ -1904,9 +1908,9 @@ function timestamp() {
|
|
|
1904
1908
|
function escapeForJs(value) {
|
|
1905
1909
|
return value.replace(/'/g, "\\'");
|
|
1906
1910
|
}
|
|
1907
|
-
var __dirname2 =
|
|
1911
|
+
var __dirname2 = path6.dirname(fileURLToPath(import.meta.url));
|
|
1908
1912
|
var packageJson = JSON.parse(
|
|
1909
|
-
fs4.readFileSync(
|
|
1913
|
+
fs4.readFileSync(path6.resolve(__dirname2, "../../package.json"), "utf-8")
|
|
1910
1914
|
);
|
|
1911
1915
|
var cyan = "\x1B[36m";
|
|
1912
1916
|
var bold = "\x1B[1m";
|
|
@@ -1919,11 +1923,11 @@ async function devCommand(options) {
|
|
|
1919
1923
|
const log = enableStdio ? (_message) => {
|
|
1920
1924
|
} : (message) => console.log(message);
|
|
1921
1925
|
try {
|
|
1922
|
-
const toolsDir =
|
|
1926
|
+
const toolsDir = path6.resolve(options.input);
|
|
1923
1927
|
if (!fs4.existsSync(toolsDir)) {
|
|
1924
1928
|
throw new Error(`Tools directory not found: ${toolsDir}`);
|
|
1925
1929
|
}
|
|
1926
|
-
const projectRoot =
|
|
1930
|
+
const projectRoot = path6.dirname(toolsDir);
|
|
1927
1931
|
loadEnvFiles(projectRoot);
|
|
1928
1932
|
let toolDefinitions = await loadToolDefinitions(toolsDir, projectRoot);
|
|
1929
1933
|
if (toolDefinitions.length === 0) {
|
|
@@ -1933,7 +1937,7 @@ async function devCommand(options) {
|
|
|
1933
1937
|
const stdioController = enableStdio ? await startMcpServer(() => toolDefinitions) : null;
|
|
1934
1938
|
if (watch2) {
|
|
1935
1939
|
const reloadableExtensions = /\.(ts|js|mjs|cjs|tsx|jsx)$/i;
|
|
1936
|
-
const tempDir =
|
|
1940
|
+
const tempDir = path6.join(toolsDir, ".opentool-temp");
|
|
1937
1941
|
const watchTargets = /* @__PURE__ */ new Set([toolsDir]);
|
|
1938
1942
|
if (projectRoot !== toolsDir) {
|
|
1939
1943
|
watchTargets.add(projectRoot);
|
|
@@ -1964,11 +1968,11 @@ Detected change in ${changedPath ?? "tools directory"}, reloading...${reset}`
|
|
|
1964
1968
|
if (filename && !reloadableExtensions.test(filename)) {
|
|
1965
1969
|
return;
|
|
1966
1970
|
}
|
|
1967
|
-
const fullPath = filename ?
|
|
1971
|
+
const fullPath = filename ? path6.join(target, filename) : void 0;
|
|
1968
1972
|
if (fullPath && fullPath.startsWith(tempDir)) {
|
|
1969
1973
|
return;
|
|
1970
1974
|
}
|
|
1971
|
-
const displayPath = fullPath ?
|
|
1975
|
+
const displayPath = fullPath ? path6.relative(projectRoot, fullPath) || path6.basename(fullPath) : path6.relative(projectRoot, target) || path6.basename(target);
|
|
1972
1976
|
await scheduleReload(displayPath);
|
|
1973
1977
|
});
|
|
1974
1978
|
}
|
|
@@ -2201,7 +2205,7 @@ function routeName(tool) {
|
|
|
2201
2205
|
function loadEnvFiles(projectRoot) {
|
|
2202
2206
|
const envFiles = [".env.local", ".env"];
|
|
2203
2207
|
for (const file of envFiles) {
|
|
2204
|
-
const candidate =
|
|
2208
|
+
const candidate = path6.join(projectRoot, file);
|
|
2205
2209
|
if (fs4.existsSync(candidate)) {
|
|
2206
2210
|
dotenv.config({ path: candidate, override: false });
|
|
2207
2211
|
}
|
|
@@ -2272,17 +2276,17 @@ async function generateMetadataCommand(options) {
|
|
|
2272
2276
|
}
|
|
2273
2277
|
}
|
|
2274
2278
|
async function generateMetadata(options) {
|
|
2275
|
-
const toolsDir =
|
|
2279
|
+
const toolsDir = path6.resolve(options.input);
|
|
2276
2280
|
if (!fs4.existsSync(toolsDir)) {
|
|
2277
2281
|
throw new Error(`Tools directory not found: ${toolsDir}`);
|
|
2278
2282
|
}
|
|
2279
|
-
const projectRoot =
|
|
2283
|
+
const projectRoot = path6.dirname(toolsDir);
|
|
2280
2284
|
const tools = await loadAndValidateTools(toolsDir, { projectRoot });
|
|
2281
2285
|
const { metadata, defaultsApplied } = await buildMetadataArtifact({
|
|
2282
2286
|
projectRoot,
|
|
2283
2287
|
tools
|
|
2284
2288
|
});
|
|
2285
|
-
const outputPath = options.output ?
|
|
2289
|
+
const outputPath = options.output ? path6.resolve(options.output) : path6.join(projectRoot, "metadata.json");
|
|
2286
2290
|
fs4.writeFileSync(outputPath, JSON.stringify(metadata, null, 2));
|
|
2287
2291
|
return {
|
|
2288
2292
|
metadata,
|
|
@@ -2295,8 +2299,8 @@ function timestamp2() {
|
|
|
2295
2299
|
return (/* @__PURE__ */ new Date()).toISOString().replace("T", " ").slice(0, 19);
|
|
2296
2300
|
}
|
|
2297
2301
|
function resolveTemplateDir() {
|
|
2298
|
-
const here =
|
|
2299
|
-
return
|
|
2302
|
+
const here = path6__default.dirname(fileURLToPath(import.meta.url));
|
|
2303
|
+
return path6__default.resolve(here, "../../templates/base");
|
|
2300
2304
|
}
|
|
2301
2305
|
async function directoryIsEmpty(targetDir) {
|
|
2302
2306
|
try {
|
|
@@ -2313,8 +2317,8 @@ async function copyDir(src, dest) {
|
|
|
2313
2317
|
await promises.mkdir(dest, { recursive: true });
|
|
2314
2318
|
const entries = await promises.readdir(src, { withFileTypes: true });
|
|
2315
2319
|
for (const entry of entries) {
|
|
2316
|
-
const srcPath =
|
|
2317
|
-
const destPath =
|
|
2320
|
+
const srcPath = path6__default.join(src, entry.name);
|
|
2321
|
+
const destPath = path6__default.join(dest, entry.name);
|
|
2318
2322
|
if (entry.isDirectory()) {
|
|
2319
2323
|
await copyDir(srcPath, destPath);
|
|
2320
2324
|
} else if (entry.isFile()) {
|
|
@@ -2329,7 +2333,7 @@ function toDisplayName(value) {
|
|
|
2329
2333
|
return value.trim().replace(/[-_]+/g, " ").replace(/\b\w/g, (ch) => ch.toUpperCase()) || "OpenTool Project";
|
|
2330
2334
|
}
|
|
2331
2335
|
async function updatePackageJson(targetDir, name, description) {
|
|
2332
|
-
const filePath =
|
|
2336
|
+
const filePath = path6__default.join(targetDir, "package.json");
|
|
2333
2337
|
const raw = await promises.readFile(filePath, "utf-8");
|
|
2334
2338
|
const pkg = JSON.parse(raw);
|
|
2335
2339
|
pkg.name = toPackageName(name);
|
|
@@ -2340,7 +2344,7 @@ async function updatePackageJson(targetDir, name, description) {
|
|
|
2340
2344
|
`, "utf-8");
|
|
2341
2345
|
}
|
|
2342
2346
|
async function updateMetadata(targetDir, name, description) {
|
|
2343
|
-
const filePath =
|
|
2347
|
+
const filePath = path6__default.join(targetDir, "metadata.ts");
|
|
2344
2348
|
const raw = await promises.readFile(filePath, "utf-8");
|
|
2345
2349
|
const displayName = toDisplayName(name);
|
|
2346
2350
|
const resolvedDescription = description || "OpenTool project";
|
|
@@ -2348,7 +2352,7 @@ async function updateMetadata(targetDir, name, description) {
|
|
|
2348
2352
|
await promises.writeFile(filePath, updated, "utf-8");
|
|
2349
2353
|
}
|
|
2350
2354
|
async function initCommand(options) {
|
|
2351
|
-
const targetDir =
|
|
2355
|
+
const targetDir = path6__default.resolve(process.cwd(), options.dir || ".");
|
|
2352
2356
|
const templateDir = resolveTemplateDir();
|
|
2353
2357
|
const empty = await directoryIsEmpty(targetDir);
|
|
2354
2358
|
if (!empty && !options.force) {
|
|
@@ -2357,7 +2361,7 @@ async function initCommand(options) {
|
|
|
2357
2361
|
);
|
|
2358
2362
|
}
|
|
2359
2363
|
await copyDir(templateDir, targetDir);
|
|
2360
|
-
const projectName = options.name ||
|
|
2364
|
+
const projectName = options.name || path6__default.basename(targetDir);
|
|
2361
2365
|
const description = options.description;
|
|
2362
2366
|
await updatePackageJson(targetDir, projectName, description);
|
|
2363
2367
|
await updateMetadata(targetDir, projectName, description);
|