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/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
2
|
-
import { I as InternalToolDefinition, T as ToolResponse } from './validate-
|
|
3
|
-
export { B as BuildConfig, m as BuildMetadata, C as CronSpec, q as GetHandler, H as HTTP_METHODS, f as HttpHandlerDefinition, e as HttpMethod, h as McpConfig, M as Metadata, N as NormalizedSchedule, P as PaymentConfig, r as PostHandler, S as ScheduleType, i as ServerConfig, j as Tool, n as ToolCategory, d as ToolContent, k as ToolMetadataOverrides, u as ToolModule, s as ToolModuleGET, t as ToolModulePOST, o as ToolProfileGET, p as ToolProfilePOST, b as generateMetadata, g as generateMetadataCommand, l as loadAndValidateTools, v as validateCommand } from './validate-
|
|
2
|
+
import { I as InternalToolDefinition, T as ToolResponse } from './validate-M_QdV0J3.js';
|
|
3
|
+
export { B as BuildConfig, m as BuildMetadata, C as CronSpec, q as GetHandler, H as HTTP_METHODS, f as HttpHandlerDefinition, e as HttpMethod, h as McpConfig, M as Metadata, N as NormalizedSchedule, P as PaymentConfig, r as PostHandler, S as ScheduleType, i as ServerConfig, j as Tool, n as ToolCategory, d as ToolContent, k as ToolMetadataOverrides, u as ToolModule, s as ToolModuleGET, t as ToolModulePOST, o as ToolProfileGET, p as ToolProfilePOST, b as generateMetadata, g as generateMetadataCommand, l as loadAndValidateTools, v as validateCommand } from './validate-M_QdV0J3.js';
|
|
4
4
|
export { CurrencySpec, DEFAULT_FACILITATOR, DefineX402PaymentConfig, EIP3009Authorization, PAYMENT_HEADERS, RequireX402PaymentOptions, RequireX402PaymentOutcome, RequireX402PaymentSuccess, SUPPORTED_CURRENCIES, X402BrowserClient, X402BrowserClientConfig, X402Client, X402ClientConfig, X402FacilitatorConfig, X402PayRequest, X402PayResult, X402Payment, X402PaymentContext, X402PaymentDefinition, X402PaymentRequiredError, X402VerificationResult, defineX402Payment, getX402PaymentContext, payX402, payX402WithWallet, requireX402Payment, withX402Payment } from './x402/index.js';
|
|
5
5
|
export { DEFAULT_CHAIN, DEFAULT_TOKENS, chains, getRpcUrl, registry, tokens, wallet, walletToolkit } from './wallet/index.js';
|
|
6
6
|
export { HyperliquidApiError, HyperliquidApproveBuilderFeeOptions, HyperliquidApproveBuilderFeeResponse, HyperliquidBuilderApprovalError, HyperliquidBuilderApprovalRecordInput, HyperliquidBuilderFee, HyperliquidClearinghouseState, HyperliquidDepositResult, HyperliquidEnvironment, HyperliquidExchangeClient, HyperliquidExchangeResponse, HyperliquidGrouping, HyperliquidGuardError, HyperliquidInfoClient, HyperliquidOrderIntent, HyperliquidOrderOptions, HyperliquidOrderResponse, HyperliquidOrderStatus, HyperliquidTermsError, HyperliquidTermsRecordInput, HyperliquidTriggerOptions, HyperliquidTriggerType, HyperliquidWithdrawResult, NonceSource, __hyperliquidInternals, approveHyperliquidBuilderFee, batchModifyHyperliquidOrders, cancelAllHyperliquidOrders, cancelHyperliquidOrders, cancelHyperliquidOrdersByCloid, cancelHyperliquidTwapOrder, createHyperliquidSubAccount, createMonotonicNonceFactory, depositToHyperliquidBridge, fetchHyperliquidAssetCtxs, fetchHyperliquidClearinghouseState, fetchHyperliquidFrontendOpenOrders, fetchHyperliquidHistoricalOrders, fetchHyperliquidMeta, fetchHyperliquidMetaAndAssetCtxs, fetchHyperliquidOpenOrders, fetchHyperliquidOrderStatus, fetchHyperliquidPreTransferCheck, fetchHyperliquidSpotAssetCtxs, fetchHyperliquidSpotClearinghouseState, fetchHyperliquidSpotMeta, fetchHyperliquidSpotMetaAndAssetCtxs, fetchHyperliquidUserFills, fetchHyperliquidUserFillsByTime, fetchHyperliquidUserRateLimit, getHyperliquidMaxBuilderFee, modifyHyperliquidOrder, placeHyperliquidOrder, placeHyperliquidTwapOrder, recordHyperliquidBuilderApproval, recordHyperliquidTermsAcceptance, reserveHyperliquidRequestWeight, scheduleHyperliquidCancel, sendHyperliquidSpot, setHyperliquidPortfolioMargin, transferHyperliquidSubAccount, updateHyperliquidIsolatedMargin, updateHyperliquidLeverage, withdrawFromHyperliquid } from './adapters/hyperliquid/index.js';
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
import * as path6 from 'path';
|
|
2
|
+
import { fileURLToPath, pathToFileURL } from 'url';
|
|
1
3
|
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
2
4
|
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
3
5
|
import { ListToolsRequestSchema, CallToolRequestSchema } from '@modelcontextprotocol/sdk/types.js';
|
|
4
6
|
import * as fs2 from 'fs';
|
|
5
|
-
import * as path5 from 'path';
|
|
6
|
-
import { fileURLToPath, pathToFileURL } from 'url';
|
|
7
7
|
import { zodToJsonSchema } from '@alcyone-labs/zod-to-json-schema';
|
|
8
8
|
import { z } from 'zod';
|
|
9
9
|
import { zeroAddress, createWalletClient, http, createPublicClient, parseUnits, encodeFunctionData, erc20Abi } from 'viem';
|
|
@@ -25,6 +25,8 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
|
|
|
25
25
|
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
26
26
|
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
27
27
|
});
|
|
28
|
+
var getFilename = () => fileURLToPath(import.meta.url);
|
|
29
|
+
var __filename = /* @__PURE__ */ getFilename();
|
|
28
30
|
var X402_VERSION = 1;
|
|
29
31
|
var HEADER_X402 = "X-PAYMENT";
|
|
30
32
|
var HEADER_PAYMENT_RESPONSE = "X-PAYMENT-RESPONSE";
|
|
@@ -988,7 +990,7 @@ function buildAdapters(tools) {
|
|
|
988
990
|
}
|
|
989
991
|
async function loadToolsFromDirectory(metadataMap) {
|
|
990
992
|
const tools = [];
|
|
991
|
-
const toolsDir =
|
|
993
|
+
const toolsDir = path6.join(process.cwd(), "tools");
|
|
992
994
|
if (!fs2.existsSync(toolsDir)) {
|
|
993
995
|
return tools;
|
|
994
996
|
}
|
|
@@ -997,7 +999,7 @@ async function loadToolsFromDirectory(metadataMap) {
|
|
|
997
999
|
if (!isSupportedToolFile(file)) {
|
|
998
1000
|
continue;
|
|
999
1001
|
}
|
|
1000
|
-
const toolPath =
|
|
1002
|
+
const toolPath = path6.join(toolsDir, file);
|
|
1001
1003
|
try {
|
|
1002
1004
|
const exportsObject = __require(toolPath);
|
|
1003
1005
|
const candidate = resolveModuleCandidate(exportsObject);
|
|
@@ -1061,7 +1063,7 @@ async function loadToolsFromDirectory(metadataMap) {
|
|
|
1061
1063
|
return tools;
|
|
1062
1064
|
}
|
|
1063
1065
|
function loadMetadata() {
|
|
1064
|
-
const metadataPath =
|
|
1066
|
+
const metadataPath = path6.join(process.cwd(), "metadata.json");
|
|
1065
1067
|
if (!fs2.existsSync(metadataPath)) {
|
|
1066
1068
|
return null;
|
|
1067
1069
|
}
|
|
@@ -1183,7 +1185,7 @@ function resolveRuntimePath(value) {
|
|
|
1183
1185
|
if (value.startsWith("file://")) {
|
|
1184
1186
|
return fileURLToPath(value);
|
|
1185
1187
|
}
|
|
1186
|
-
return
|
|
1188
|
+
return path6.resolve(value);
|
|
1187
1189
|
}
|
|
1188
1190
|
|
|
1189
1191
|
// src/types/index.ts
|
|
@@ -3358,9 +3360,9 @@ function parseOptionalDate(value) {
|
|
|
3358
3360
|
function buildHmacSignature(args) {
|
|
3359
3361
|
const timestamp2 = args.timestamp.toString();
|
|
3360
3362
|
const method = args.method.toUpperCase();
|
|
3361
|
-
const
|
|
3363
|
+
const path8 = args.path;
|
|
3362
3364
|
const body = args.body == null ? "" : typeof args.body === "string" ? args.body : JSON.stringify(args.body);
|
|
3363
|
-
const payload = `${timestamp2}${method}${
|
|
3365
|
+
const payload = `${timestamp2}${method}${path8}${body}`;
|
|
3364
3366
|
const key = Buffer.from(args.secret, "base64");
|
|
3365
3367
|
return createHmac("sha256", key).update(payload).digest("hex");
|
|
3366
3368
|
}
|
|
@@ -4725,9 +4727,9 @@ function assignIfDefined(target, key, value) {
|
|
|
4725
4727
|
target[key] = value;
|
|
4726
4728
|
}
|
|
4727
4729
|
}
|
|
4728
|
-
function buildUrl(baseUrl,
|
|
4730
|
+
function buildUrl(baseUrl, path8) {
|
|
4729
4731
|
const sanitizedBase = baseUrl.endsWith("/") ? baseUrl.slice(0, -1) : baseUrl;
|
|
4730
|
-
return `${sanitizedBase}${
|
|
4732
|
+
return `${sanitizedBase}${path8}`;
|
|
4731
4733
|
}
|
|
4732
4734
|
function createAbortBundle(upstreamSignal, timeoutMs) {
|
|
4733
4735
|
const controller = new AbortController();
|
|
@@ -4870,7 +4872,7 @@ var DiscoveryMetadataSchema = z.object({
|
|
|
4870
4872
|
compatibility: z.record(z.string(), z.any()).optional(),
|
|
4871
4873
|
documentation: z.union([z.string(), z.array(z.string())]).optional()
|
|
4872
4874
|
}).catchall(z.any());
|
|
4873
|
-
var ToolCategorySchema = z.enum(["strategy", "tracker"]);
|
|
4875
|
+
var ToolCategorySchema = z.enum(["strategy", "tracker", "orchestator"]);
|
|
4874
4876
|
var ToolMetadataOverridesSchema = z.object({
|
|
4875
4877
|
name: z.string().optional(),
|
|
4876
4878
|
description: z.string().optional(),
|
|
@@ -4940,7 +4942,7 @@ var BuildMetadataSchema = z.object({
|
|
|
4940
4942
|
chains: z.array(z.union([z.string(), z.number()])).optional()
|
|
4941
4943
|
}).strict();
|
|
4942
4944
|
function resolveTsconfig(projectRoot) {
|
|
4943
|
-
const candidate =
|
|
4945
|
+
const candidate = path6.join(projectRoot, "tsconfig.json");
|
|
4944
4946
|
if (fs2.existsSync(candidate)) {
|
|
4945
4947
|
return candidate;
|
|
4946
4948
|
}
|
|
@@ -4951,7 +4953,7 @@ async function transpileWithEsbuild(options) {
|
|
|
4951
4953
|
throw new Error("No entry points provided for esbuild transpilation");
|
|
4952
4954
|
}
|
|
4953
4955
|
const projectRoot = options.projectRoot;
|
|
4954
|
-
const tempBase = options.outDir ?? fs2.mkdtempSync(
|
|
4956
|
+
const tempBase = options.outDir ?? fs2.mkdtempSync(path6.join(tmpdir(), "opentool-"));
|
|
4955
4957
|
if (!fs2.existsSync(tempBase)) {
|
|
4956
4958
|
fs2.mkdirSync(tempBase, { recursive: true });
|
|
4957
4959
|
}
|
|
@@ -4995,7 +4997,7 @@ async function transpileWithEsbuild(options) {
|
|
|
4995
4997
|
}
|
|
4996
4998
|
await build(buildOptions);
|
|
4997
4999
|
if (options.format === "esm") {
|
|
4998
|
-
const packageJsonPath =
|
|
5000
|
+
const packageJsonPath = path6.join(tempBase, "package.json");
|
|
4999
5001
|
if (!fs2.existsSync(packageJsonPath)) {
|
|
5000
5002
|
fs2.writeFileSync(packageJsonPath, JSON.stringify({ type: "module" }), "utf8");
|
|
5001
5003
|
}
|
|
@@ -5008,10 +5010,12 @@ async function transpileWithEsbuild(options) {
|
|
|
5008
5010
|
};
|
|
5009
5011
|
return { outDir: tempBase, cleanup };
|
|
5010
5012
|
}
|
|
5011
|
-
createRequire(
|
|
5013
|
+
createRequire(
|
|
5014
|
+
typeof __filename !== "undefined" ? __filename : import.meta.url
|
|
5015
|
+
);
|
|
5012
5016
|
function resolveCompiledPath(outDir, originalFile, extension = ".js") {
|
|
5013
|
-
const baseName =
|
|
5014
|
-
return
|
|
5017
|
+
const baseName = path6.basename(originalFile).replace(/\.[^.]+$/, "");
|
|
5018
|
+
return path6.join(outDir, `${baseName}${extension}`);
|
|
5015
5019
|
}
|
|
5016
5020
|
async function importFresh(modulePath) {
|
|
5017
5021
|
const fileUrl = pathToFileURL(modulePath).href;
|
|
@@ -5023,13 +5027,13 @@ async function importFresh(modulePath) {
|
|
|
5023
5027
|
// src/cli/shared/metadata.ts
|
|
5024
5028
|
var METADATA_ENTRY = "metadata.ts";
|
|
5025
5029
|
async function loadMetadata2(projectRoot) {
|
|
5026
|
-
const absPath =
|
|
5030
|
+
const absPath = path6.join(projectRoot, METADATA_ENTRY);
|
|
5027
5031
|
if (!fs2.existsSync(absPath)) {
|
|
5028
5032
|
throw new Error(
|
|
5029
5033
|
`metadata.ts not found in ${projectRoot}. Create metadata.ts to describe your agent.`
|
|
5030
5034
|
);
|
|
5031
5035
|
}
|
|
5032
|
-
const tempDir =
|
|
5036
|
+
const tempDir = path6.join(projectRoot, ".opentool-temp");
|
|
5033
5037
|
if (fs2.existsSync(tempDir)) {
|
|
5034
5038
|
fs2.rmSync(tempDir, { recursive: true, force: true });
|
|
5035
5039
|
}
|
|
@@ -5070,7 +5074,7 @@ function extractMetadataExport(moduleExports) {
|
|
|
5070
5074
|
return moduleExports;
|
|
5071
5075
|
}
|
|
5072
5076
|
function readPackageJson(projectRoot) {
|
|
5073
|
-
const packagePath =
|
|
5077
|
+
const packagePath = path6.join(projectRoot, "package.json");
|
|
5074
5078
|
if (!fs2.existsSync(packagePath)) {
|
|
5075
5079
|
return {};
|
|
5076
5080
|
}
|
|
@@ -5086,7 +5090,7 @@ async function buildMetadataArtifact(options) {
|
|
|
5086
5090
|
const packageInfo = readPackageJson(projectRoot);
|
|
5087
5091
|
const { metadata: authored, sourcePath } = await loadMetadata2(projectRoot);
|
|
5088
5092
|
const defaultsApplied = [];
|
|
5089
|
-
const folderName =
|
|
5093
|
+
const folderName = path6.basename(projectRoot);
|
|
5090
5094
|
const name = resolveField(
|
|
5091
5095
|
"name",
|
|
5092
5096
|
authored.name,
|
|
@@ -5306,11 +5310,11 @@ var SUPPORTED_EXTENSIONS = [
|
|
|
5306
5310
|
async function validateCommand(options) {
|
|
5307
5311
|
console.log("\u{1F50D} Validating OpenTool metadata...");
|
|
5308
5312
|
try {
|
|
5309
|
-
const toolsDir =
|
|
5313
|
+
const toolsDir = path6.resolve(options.input);
|
|
5310
5314
|
if (!fs2.existsSync(toolsDir)) {
|
|
5311
5315
|
throw new Error(`Tools directory not found: ${toolsDir}`);
|
|
5312
5316
|
}
|
|
5313
|
-
const projectRoot =
|
|
5317
|
+
const projectRoot = path6.dirname(toolsDir);
|
|
5314
5318
|
const tools = await loadAndValidateTools(toolsDir, { projectRoot });
|
|
5315
5319
|
if (tools.length === 0) {
|
|
5316
5320
|
throw new Error("No valid tools found - metadata validation aborted");
|
|
@@ -5327,12 +5331,12 @@ async function validateCommand(options) {
|
|
|
5327
5331
|
}
|
|
5328
5332
|
}
|
|
5329
5333
|
async function loadAndValidateTools(toolsDir, options = {}) {
|
|
5330
|
-
const files = fs2.readdirSync(toolsDir).filter((file) => SUPPORTED_EXTENSIONS.includes(
|
|
5334
|
+
const files = fs2.readdirSync(toolsDir).filter((file) => SUPPORTED_EXTENSIONS.includes(path6.extname(file)));
|
|
5331
5335
|
if (files.length === 0) {
|
|
5332
5336
|
return [];
|
|
5333
5337
|
}
|
|
5334
|
-
const projectRoot = options.projectRoot ??
|
|
5335
|
-
const tempDir =
|
|
5338
|
+
const projectRoot = options.projectRoot ?? path6.dirname(toolsDir);
|
|
5339
|
+
const tempDir = path6.join(toolsDir, ".opentool-temp");
|
|
5336
5340
|
if (fs2.existsSync(tempDir)) {
|
|
5337
5341
|
fs2.rmSync(tempDir, { recursive: true, force: true });
|
|
5338
5342
|
}
|
|
@@ -5342,7 +5346,7 @@ async function loadAndValidateTools(toolsDir, options = {}) {
|
|
|
5342
5346
|
throw new Error(`Tool filename must be kebab-case: ${f}`);
|
|
5343
5347
|
}
|
|
5344
5348
|
}
|
|
5345
|
-
const entryPoints = files.map((file) =>
|
|
5349
|
+
const entryPoints = files.map((file) => path6.join(toolsDir, file));
|
|
5346
5350
|
const { outDir, cleanup } = await transpileWithEsbuild({
|
|
5347
5351
|
entryPoints,
|
|
5348
5352
|
projectRoot,
|
|
@@ -5383,7 +5387,7 @@ async function loadAndValidateTools(toolsDir, options = {}) {
|
|
|
5383
5387
|
const schedule = toolModule?.profile?.schedule;
|
|
5384
5388
|
const profileNotifyEmail = typeof toolModule?.profile?.notifyEmail === "boolean" ? toolModule.profile.notifyEmail : void 0;
|
|
5385
5389
|
const profileCategoryRaw = typeof toolModule?.profile?.category === "string" ? toolModule.profile.category : void 0;
|
|
5386
|
-
const allowedProfileCategories = /* @__PURE__ */ new Set(["strategy", "tracker"]);
|
|
5390
|
+
const allowedProfileCategories = /* @__PURE__ */ new Set(["strategy", "tracker", "orchestator"]);
|
|
5387
5391
|
if (profileCategoryRaw && !allowedProfileCategories.has(profileCategoryRaw)) {
|
|
5388
5392
|
throw new Error(
|
|
5389
5393
|
`${file}: profile.category must be one of ${Array.from(allowedProfileCategories).join(", ")}`
|
|
@@ -5454,7 +5458,7 @@ async function loadAndValidateTools(toolsDir, options = {}) {
|
|
|
5454
5458
|
httpHandlers,
|
|
5455
5459
|
mcpConfig: normalizeMcpConfig(toolModule.mcp, file),
|
|
5456
5460
|
filename: toBaseName(file),
|
|
5457
|
-
sourcePath:
|
|
5461
|
+
sourcePath: path6.join(toolsDir, file),
|
|
5458
5462
|
handler: async (params) => adapter(params),
|
|
5459
5463
|
payment: paymentExport ?? null,
|
|
5460
5464
|
schedule: normalizedSchedule,
|
|
@@ -5669,17 +5673,17 @@ async function generateMetadataCommand(options) {
|
|
|
5669
5673
|
}
|
|
5670
5674
|
}
|
|
5671
5675
|
async function generateMetadata(options) {
|
|
5672
|
-
const toolsDir =
|
|
5676
|
+
const toolsDir = path6.resolve(options.input);
|
|
5673
5677
|
if (!fs2.existsSync(toolsDir)) {
|
|
5674
5678
|
throw new Error(`Tools directory not found: ${toolsDir}`);
|
|
5675
5679
|
}
|
|
5676
|
-
const projectRoot =
|
|
5680
|
+
const projectRoot = path6.dirname(toolsDir);
|
|
5677
5681
|
const tools = await loadAndValidateTools(toolsDir, { projectRoot });
|
|
5678
5682
|
const { metadata, defaultsApplied } = await buildMetadataArtifact({
|
|
5679
5683
|
projectRoot,
|
|
5680
5684
|
tools
|
|
5681
5685
|
});
|
|
5682
|
-
const outputPath = options.output ?
|
|
5686
|
+
const outputPath = options.output ? path6.resolve(options.output) : path6.join(projectRoot, "metadata.json");
|
|
5683
5687
|
fs2.writeFileSync(outputPath, JSON.stringify(metadata, null, 2));
|
|
5684
5688
|
return {
|
|
5685
5689
|
metadata,
|