opentool 0.7.9 → 0.7.11
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 +6 -1
- package/dist/cli/index.d.ts +3 -2
- package/dist/cli/index.js +101 -2
- package/dist/cli/index.js.map +1 -1
- package/dist/index.d.ts +6 -2
- package/dist/index.js +112 -2
- package/dist/index.js.map +1 -1
- package/dist/store/index.d.ts +41 -0
- package/dist/store/index.js +70 -0
- package/dist/store/index.js.map +1 -0
- package/dist/{validate-BBjyq5nS.d.ts → validate-uetwG5jo.d.ts} +9 -1
- package/package.json +5 -1
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
type StoreStatus = "submitted" | "pending" | "confirmed" | "failed" | "cancelled" | "filled" | "partial_fill" | "settled" | "info";
|
|
2
|
+
type StoreAction = "stake" | "swap" | "bridge" | "order" | "lend" | "repay" | "withdraw" | "custom" | string;
|
|
3
|
+
type ChainScope = {
|
|
4
|
+
chainId: number;
|
|
5
|
+
network?: never;
|
|
6
|
+
} | {
|
|
7
|
+
network: string;
|
|
8
|
+
chainId?: never;
|
|
9
|
+
} | {
|
|
10
|
+
chainId?: never;
|
|
11
|
+
network?: never;
|
|
12
|
+
};
|
|
13
|
+
type StoreEventInput = ChainScope & {
|
|
14
|
+
source: string;
|
|
15
|
+
ref: string;
|
|
16
|
+
status: StoreStatus;
|
|
17
|
+
walletAddress?: `0x${string}`;
|
|
18
|
+
action?: StoreAction;
|
|
19
|
+
notional?: string;
|
|
20
|
+
metadata?: Record<string, unknown>;
|
|
21
|
+
};
|
|
22
|
+
interface StoreOptions {
|
|
23
|
+
baseUrl?: string;
|
|
24
|
+
apiKey?: string;
|
|
25
|
+
fetchFn?: typeof fetch;
|
|
26
|
+
}
|
|
27
|
+
interface StoreResponse {
|
|
28
|
+
id: string;
|
|
29
|
+
status?: StoreStatus | null;
|
|
30
|
+
}
|
|
31
|
+
declare class StoreError extends Error {
|
|
32
|
+
readonly status?: number | undefined;
|
|
33
|
+
readonly causeData?: unknown | undefined;
|
|
34
|
+
constructor(message: string, status?: number | undefined, causeData?: unknown | undefined);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Store a generic activity event (onchain tx, Hyperliquid order, etc.) in OpenPond.
|
|
38
|
+
*/
|
|
39
|
+
declare function store(input: StoreEventInput, options?: StoreOptions): Promise<StoreResponse>;
|
|
40
|
+
|
|
41
|
+
export { type StoreAction, StoreError, type StoreEventInput, type StoreOptions, type StoreResponse, store };
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
// src/store/index.ts
|
|
2
|
+
var StoreError = class extends Error {
|
|
3
|
+
constructor(message, status, causeData) {
|
|
4
|
+
super(message);
|
|
5
|
+
this.status = status;
|
|
6
|
+
this.causeData = causeData;
|
|
7
|
+
this.name = "StoreError";
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
function resolveConfig(options) {
|
|
11
|
+
const baseUrl = options?.baseUrl ?? process.env.BASE_URL;
|
|
12
|
+
const apiKey = options?.apiKey ?? process.env.OPENPOND_API_KEY;
|
|
13
|
+
if (!baseUrl) {
|
|
14
|
+
throw new StoreError("BASE_URL is required to store activity events");
|
|
15
|
+
}
|
|
16
|
+
if (!apiKey) {
|
|
17
|
+
throw new StoreError(
|
|
18
|
+
"OPENPOND_API_KEY is required to store activity events"
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
const normalizedBaseUrl = baseUrl.replace(/\/$/, "");
|
|
22
|
+
const fetchFn = options?.fetchFn ?? globalThis.fetch;
|
|
23
|
+
if (!fetchFn) {
|
|
24
|
+
throw new StoreError("Fetch is not available in this environment");
|
|
25
|
+
}
|
|
26
|
+
return { baseUrl: normalizedBaseUrl, apiKey, fetchFn };
|
|
27
|
+
}
|
|
28
|
+
async function store(input, options) {
|
|
29
|
+
const { baseUrl, apiKey, fetchFn } = resolveConfig(options);
|
|
30
|
+
const url = `${baseUrl}/apps/positions/tx`;
|
|
31
|
+
let response;
|
|
32
|
+
try {
|
|
33
|
+
response = await fetchFn(url, {
|
|
34
|
+
method: "POST",
|
|
35
|
+
headers: {
|
|
36
|
+
"content-type": "application/json",
|
|
37
|
+
"openpond-api-key": apiKey
|
|
38
|
+
},
|
|
39
|
+
body: JSON.stringify(input)
|
|
40
|
+
});
|
|
41
|
+
} catch (error) {
|
|
42
|
+
throw new StoreError("Failed to reach store endpoint", void 0, error);
|
|
43
|
+
}
|
|
44
|
+
if (!response.ok) {
|
|
45
|
+
let body;
|
|
46
|
+
try {
|
|
47
|
+
body = await response.json();
|
|
48
|
+
} catch {
|
|
49
|
+
body = await response.text().catch(() => void 0);
|
|
50
|
+
}
|
|
51
|
+
throw new StoreError(
|
|
52
|
+
`Store request failed with status ${response.status}`,
|
|
53
|
+
response.status,
|
|
54
|
+
body
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
try {
|
|
58
|
+
const data = await response.json();
|
|
59
|
+
return {
|
|
60
|
+
id: data.id ?? "",
|
|
61
|
+
status: data.status ?? null
|
|
62
|
+
};
|
|
63
|
+
} catch {
|
|
64
|
+
return { id: "", status: null };
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export { StoreError, store };
|
|
69
|
+
//# sourceMappingURL=index.js.map
|
|
70
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/store/index.ts"],"names":[],"mappings":";AA+CO,IAAM,UAAA,GAAN,cAAyB,KAAA,CAAM;AAAA,EACpC,WAAA,CACE,OAAA,EACgB,MAAA,EACA,SAAA,EAChB;AACA,IAAA,KAAA,CAAM,OAAO,CAAA;AAHG,IAAA,IAAA,CAAA,MAAA,GAAA,MAAA;AACA,IAAA,IAAA,CAAA,SAAA,GAAA,SAAA;AAGhB,IAAA,IAAA,CAAK,IAAA,GAAO,YAAA;AAAA,EACd;AACF;AAEA,SAAS,cAAc,OAAA,EAAwB;AAC7C,EAAA,MAAM,OAAA,G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A,EAAW,KAAK,CAAA;AAAA,EACzE;AAEA,EAAA,IAAI,CAAC,SAAS,EAAA,EAAI;AAChB,IAAA,IAAI,IAAA;AACJ,IAAA,IAAI;AACF,MAAA,IAAA,GAAO,MAAM,SAAS,IAAA,EAAK;AAAA,IAC7B,CAAA,CAAA,MAAQ;AACN,MAAA,IAAA,GAAO,MAAM,QAAA,CAAS,IAAA,EAAK,CAAE,KAAA,CAAM,MAAM,MAAS,CAAA;AAAA,IACpD;AACA,IAAA,MAAM,IAAI,UAAA;AAAA,MACR,CAAA,iCAAA,EAAoC,SAAS,MAAM,CAAA,CAAA;AAAA,MACnD,QAAA,CAAS,MAAA;AAAA,MACT;AAAA,KACF;AAAA,EACF;AAEA,EAAA,IAAI;AACF,IAAA,MAAM,IAAA,GAAQ,MAAM,QAAA,CAAS,IAAA,EAAK;AAClC,IAAA,OAAO;AAAA,MACL,EAAA,EAAI,KAAK,EAAA,IAAM,EAAA;AAAA,MACf,MAAA,EAAQ,KAAK,MAAA,IAAU;AAAA,KACzB;AAAA,EACF,CAAA,CAAA,MAAQ;AAEN,IAAA,OAAO,EAAE,EAAA,EAAI,EAAA,EAAI,MAAA,EAAQ,IAAA,EAAK;AAAA,EAChC;AACF","file":"index.js","sourcesContent":["type StoreStatus =\n | \"submitted\"\n | \"pending\"\n | \"confirmed\"\n | \"failed\"\n | \"cancelled\"\n | \"filled\"\n | \"partial_fill\"\n | \"settled\"\n | \"info\";\n\nexport type StoreAction =\n | \"stake\"\n | \"swap\"\n | \"bridge\"\n | \"order\"\n | \"lend\"\n | \"repay\"\n | \"withdraw\"\n | \"custom\"\n | string;\n\ntype ChainScope =\n | { chainId: number; network?: never }\n | { network: string; chainId?: never }\n | { chainId?: never; network?: never };\n\nexport type StoreEventInput = ChainScope & {\n source: string;\n ref: string;\n status: StoreStatus;\n walletAddress?: `0x${string}`;\n action?: StoreAction;\n notional?: string; // decimal string recommended to avoid float precision issues\n metadata?: Record<string, unknown>;\n};\n\nexport interface StoreOptions {\n baseUrl?: string;\n apiKey?: string;\n fetchFn?: typeof fetch;\n}\n\nexport interface StoreResponse {\n id: string;\n status?: StoreStatus | null;\n}\nexport class StoreError extends Error {\n constructor(\n message: string,\n public readonly status?: number,\n public readonly causeData?: unknown\n ) {\n super(message);\n this.name = \"StoreError\";\n }\n}\n\nfunction resolveConfig(options?: StoreOptions) {\n const baseUrl = options?.baseUrl ?? process.env.BASE_URL;\n const apiKey = options?.apiKey ?? process.env.OPENPOND_API_KEY;\n\n if (!baseUrl) {\n throw new StoreError(\"BASE_URL is required to store activity events\");\n }\n if (!apiKey) {\n throw new StoreError(\n \"OPENPOND_API_KEY is required to store activity events\"\n );\n }\n\n const normalizedBaseUrl = baseUrl.replace(/\\/$/, \"\");\n const fetchFn = options?.fetchFn ?? globalThis.fetch;\n if (!fetchFn) {\n throw new StoreError(\"Fetch is not available in this environment\");\n }\n\n return { baseUrl: normalizedBaseUrl, apiKey, fetchFn };\n}\n\n/**\n * Store a generic activity event (onchain tx, Hyperliquid order, etc.) in OpenPond.\n */\nexport async function store(\n input: StoreEventInput,\n options?: StoreOptions\n): Promise<StoreResponse> {\n const { baseUrl, apiKey, fetchFn } = resolveConfig(options);\n\n const url = `${baseUrl}/apps/positions/tx`;\n\n let response: Response;\n try {\n response = await fetchFn(url, {\n method: \"POST\",\n headers: {\n \"content-type\": \"application/json\",\n \"openpond-api-key\": apiKey,\n },\n body: JSON.stringify(input),\n });\n } catch (error) {\n throw new StoreError(\"Failed to reach store endpoint\", undefined, error);\n }\n\n if (!response.ok) {\n let body: unknown;\n try {\n body = await response.json();\n } catch {\n body = await response.text().catch(() => undefined);\n }\n throw new StoreError(\n `Store request failed with status ${response.status}`,\n response.status,\n body\n );\n }\n\n try {\n const data = (await response.json()) as Partial<StoreResponse>;\n return {\n id: data.id ?? \"\",\n status: data.status ?? null,\n };\n } catch {\n // Response is optional; return empty success\n return { id: \"\", status: null };\n }\n}\n"]}
|
|
@@ -327,6 +327,12 @@ interface HttpHandlerDefinition {
|
|
|
327
327
|
method: HttpMethod;
|
|
328
328
|
handler: (request: Request) => Promise<Response> | Response;
|
|
329
329
|
}
|
|
330
|
+
type ScheduleType = "cron" | "rate";
|
|
331
|
+
interface NormalizedSchedule {
|
|
332
|
+
type: ScheduleType;
|
|
333
|
+
expression: string;
|
|
334
|
+
authoredEnabled?: boolean;
|
|
335
|
+
}
|
|
330
336
|
interface McpConfig {
|
|
331
337
|
enabled: boolean;
|
|
332
338
|
mode?: "stdio" | "lambda" | "dual";
|
|
@@ -343,6 +349,8 @@ interface InternalToolDefinition<TSchema extends z.ZodSchema | undefined = z.Zod
|
|
|
343
349
|
sourcePath?: string;
|
|
344
350
|
handler?: (params: any) => Promise<ToolResponse>;
|
|
345
351
|
payment?: X402Payment | null;
|
|
352
|
+
schedule?: NormalizedSchedule | null;
|
|
353
|
+
profileDescription?: string | null;
|
|
346
354
|
}
|
|
347
355
|
interface ServerConfig {
|
|
348
356
|
name: string;
|
|
@@ -379,4 +387,4 @@ declare function validateCommand(options: ValidateOptions): Promise<void>;
|
|
|
379
387
|
declare function validateFullCommand(options: ValidateOptions): Promise<void>;
|
|
380
388
|
declare function loadAndValidateTools(toolsDir: string, options?: LoadToolsOptions): Promise<InternalToolDefinition[]>;
|
|
381
389
|
|
|
382
|
-
export { type BuildConfig as B, type GenerateMetadataOptions as G, HTTP_METHODS as H, type InternalToolDefinition as I, type Metadata as M, type PaymentConfig as P, type
|
|
390
|
+
export { type BuildConfig as B, type GenerateMetadataOptions as G, HTTP_METHODS as H, type InternalToolDefinition as I, type Metadata as M, type NormalizedSchedule as N, type PaymentConfig as P, type ScheduleType as S, type ToolResponse as T, type ValidateOptions as V, type GenerateMetadataResult as a, generateMetadata as b, validateFullCommand as c, type ToolContent as d, type HttpMethod as e, type HttpHandlerDefinition as f, generateMetadataCommand as g, type McpConfig as h, type ServerConfig as i, type Tool as j, type ToolMetadataOverrides as k, loadAndValidateTools as l, type BuildMetadata as m, validateCommand as v };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "opentool",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.11",
|
|
4
4
|
"description": "OpenTool framework for building serverless MCP tools",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -106,6 +106,10 @@
|
|
|
106
106
|
"import": "./dist/wallets/index.js",
|
|
107
107
|
"types": "./dist/wallets/index.d.ts"
|
|
108
108
|
},
|
|
109
|
+
"./store": {
|
|
110
|
+
"import": "./dist/store/index.js",
|
|
111
|
+
"types": "./dist/store/index.d.ts"
|
|
112
|
+
},
|
|
109
113
|
"./cli": {
|
|
110
114
|
"import": "./dist/cli/index.js",
|
|
111
115
|
"types": "./dist/cli/index.d.ts"
|