@wowok/agent-mcp 2.3.6 → 2.3.8

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.
Files changed (38) hide show
  1. package/dist/index.d.ts +1 -15838
  2. package/dist/index.js +40 -394
  3. package/dist/schema/call/bridge-handler.d.ts +5 -0
  4. package/dist/schema/call/bridge-handler.js +234 -0
  5. package/dist/schema/call/bridge.d.ts +2212 -0
  6. package/dist/schema/call/bridge.js +408 -0
  7. package/dist/schema/call/handler.js +29 -15
  8. package/dist/schema/call/index.d.ts +1 -0
  9. package/dist/schema/call/index.js +1 -0
  10. package/dist/schema/index.d.ts +1 -0
  11. package/dist/schema/index.js +1 -0
  12. package/dist/schema/messenger/index.d.ts +74 -74
  13. package/dist/schema/operations.d.ts +24302 -0
  14. package/dist/schema/operations.js +393 -0
  15. package/dist/schema-query/index.d.ts +3 -1
  16. package/dist/schema-query/index.js +63 -3
  17. package/dist/schemas/account_operation.output.json +1395 -0
  18. package/dist/schemas/bridge_operation.output.json +64 -0
  19. package/dist/schemas/bridge_operation.schema.json +547 -0
  20. package/dist/schemas/guard2file.output.json +84 -0
  21. package/dist/schemas/index.json +33 -14
  22. package/dist/schemas/local_info_operation.output.json +70 -0
  23. package/dist/schemas/local_mark_operation.output.json +114 -0
  24. package/dist/schemas/machineNode2file.output.json +89 -0
  25. package/dist/schemas/messenger_operation.output.json +1068 -0
  26. package/dist/schemas/onchain_events.output.json +513 -0
  27. package/dist/schemas/onchain_operations.output.json +1764 -0
  28. package/dist/schemas/onchain_operations.schema.json +8324 -49
  29. package/dist/schemas/onchain_table_data.output.json +1938 -0
  30. package/dist/schemas/onchain_table_data.schema.json +483 -22
  31. package/dist/schemas/query_toolkit.output.json +18 -0
  32. package/dist/schemas/query_toolkit.schema.json +454 -19
  33. package/dist/schemas/schema_query.output.json +42 -0
  34. package/dist/schemas/schema_query.schema.json +1 -0
  35. package/dist/schemas/wip_file.output.json +116 -0
  36. package/dist/schemas/wip_file.schema.json +163 -15
  37. package/dist/schemas/wowok_buildin_info.output.json +577 -0
  38. package/package.json +2 -3
@@ -0,0 +1,234 @@
1
+ import { BridgeClient, LocalMark, } from "@wowok/wowok";
2
+ let _bridgeClient = null;
3
+ let _bridgeClientEnv = null;
4
+ function getBridgeClient(env) {
5
+ const envObj = env || {};
6
+ const curAccount = envObj?.account;
7
+ if (_bridgeClient === null || _bridgeClientEnv === null || curAccount !== _bridgeClientEnv?.account) {
8
+ _bridgeClient = new BridgeClient({ wowEnv: envObj });
9
+ _bridgeClientEnv = envObj;
10
+ }
11
+ return _bridgeClient;
12
+ }
13
+ function getBridgeClientForQuery() {
14
+ if (_bridgeClient !== null)
15
+ return _bridgeClient;
16
+ _bridgeClient = new BridgeClient({});
17
+ _bridgeClientEnv = {};
18
+ return _bridgeClient;
19
+ }
20
+ function validateMainnet(env) {
21
+ const network = env?.network;
22
+ if (network && network !== "mainnet") {
23
+ throw new Error(`Bridge only supports WOW mainnet (current network: '${network}'). Only mainnet provides cross-chain functionality.`);
24
+ }
25
+ }
26
+ async function resolveWowAddress(addrOrName, env) {
27
+ if (!addrOrName) {
28
+ const acc = env?.account;
29
+ return acc;
30
+ }
31
+ if (/^0x[0-9a-fA-F]{64}$/.test(addrOrName))
32
+ return addrOrName;
33
+ try {
34
+ const addr = await LocalMark.Instance().get_address(addrOrName);
35
+ if (addr)
36
+ return addr;
37
+ return addrOrName;
38
+ }
39
+ catch {
40
+ return addrOrName;
41
+ }
42
+ }
43
+ function safeJson(obj) {
44
+ return JSON.stringify(obj, (_k, v) => typeof v === "bigint" ? v.toString() : v, 2);
45
+ }
46
+ function convertBigInts(obj) {
47
+ if (typeof obj === "bigint")
48
+ return obj.toString();
49
+ if (Array.isArray(obj))
50
+ return obj.map(convertBigInts);
51
+ if (obj && typeof obj === "object") {
52
+ const out = {};
53
+ for (const k of Object.keys(obj))
54
+ out[k] = convertBigInts(obj[k]);
55
+ return out;
56
+ }
57
+ return obj;
58
+ }
59
+ function ok(message, result) {
60
+ const safeResult = convertBigInts(result);
61
+ const output = { message, result: { type: "data", data: safeResult } };
62
+ return {
63
+ content: [
64
+ { type: "text", text: message },
65
+ { type: "text", text: safeJson(safeResult) },
66
+ ],
67
+ structuredContent: output,
68
+ };
69
+ }
70
+ function err(message) {
71
+ const output = { message, result: { type: "error", error: message } };
72
+ return {
73
+ content: [{ type: "text", text: message }],
74
+ structuredContent: output,
75
+ };
76
+ }
77
+ export async function handleBridgeOperations(args) {
78
+ if (!args || typeof args !== "object") {
79
+ return err("Invalid args: expected an object with operation_type");
80
+ }
81
+ let validated;
82
+ try {
83
+ const { strictParse } = await import("./base.js");
84
+ validated = strictParse((await import("./bridge.js")).BridgeOperationsSchema, args, "bridge_operations input");
85
+ }
86
+ catch (e) {
87
+ return err(`Parameter validation failed: ${e?.message ?? String(e)}`);
88
+ }
89
+ const env = validated.env;
90
+ try {
91
+ switch (validated.operation_type) {
92
+ case "cross_chain_wow_to_evm": {
93
+ validateMainnet(env);
94
+ const data = validated.data;
95
+ const client = getBridgeClient(env);
96
+ const result = await client.bridgeWowToEvmSimple({
97
+ token: data.token,
98
+ amount: BigInt(data.amount),
99
+ withdrawTo: data.withdrawTo,
100
+ waitForFinalization: false,
101
+ });
102
+ return ok(`WOW→EVM cross-chain step 1 (deposit) submitted. transferId=${result.transferId}, activeEvmAccount=${result.activeEvmAccount}. ` +
103
+ `Next: poll query_transfer_status until bridge signs (~1-5 min), then call claim_wow_to_evm to complete.`, result);
104
+ }
105
+ case "cross_chain_evm_to_wow": {
106
+ validateMainnet(env);
107
+ const data = validated.data;
108
+ const recipientWowAddress = await resolveWowAddress(data.recipientWowAddress, env);
109
+ const client = getBridgeClient(env);
110
+ const result = await client.bridgeEvmToWowSimple({
111
+ token: data.token,
112
+ amount: BigInt(data.amount),
113
+ recipientWowAddress,
114
+ waitForFinalization: false,
115
+ });
116
+ return ok(`EVM→WOW cross-chain submitted. transferId=${result.transferId}, activeEvmAccount=${result.activeEvmAccount}. ` +
117
+ `Bridge will auto-claim on WOW (~10-20 min). Poll query_transfer_status to monitor progress.`, result);
118
+ }
119
+ case "claim_wow_to_evm": {
120
+ validateMainnet(env);
121
+ const data = validated.data;
122
+ const client = getBridgeClient(env);
123
+ const result = await client.claimWowToEvm(data.transferId);
124
+ return ok(`WOW→EVM claim (step 2) completed. transferId=${result.transferId}, claimTxHash=${result.claimTxHash}`, result);
125
+ }
126
+ case "withdraw": {
127
+ const data = validated.data;
128
+ const client = getBridgeClientForQuery();
129
+ let tokenAddress = data.tokenAddress;
130
+ if (!tokenAddress && data.token && data.token !== "ETH") {
131
+ const cfg = client.config;
132
+ const chain = cfg?.evmChains?.find((c) => c.name === (data.network ?? "mainnet"));
133
+ const tokenMeta = chain?.tokens?.find((t) => t.symbol === data.token);
134
+ tokenAddress = tokenMeta?.evmAddress;
135
+ if (!tokenAddress) {
136
+ return err(`Cannot resolve ERC20 token address for symbol '${data.token}' on chain '${data.network ?? "mainnet"}'. Please pass tokenAddress explicitly.`);
137
+ }
138
+ }
139
+ const result = await client.withdrawFromActiveEvmAccount({
140
+ to: data.to,
141
+ amount: BigInt(data.amount),
142
+ tokenAddress,
143
+ token: data.token ? data.token : undefined,
144
+ network: data.network,
145
+ });
146
+ return ok(`Withdrawal submitted. transferId=${result.transferId}, txHash=${result.txHash}`, result);
147
+ }
148
+ case "query_active_evm_account": {
149
+ const data = validated.data ?? {};
150
+ const client = getBridgeClientForQuery();
151
+ const result = await client.queryActiveEvmAccount({
152
+ network: data.network,
153
+ tokens: data.tokens,
154
+ });
155
+ return ok(`activeEvmAccount: ${result.address} (${result.chains.length} chain(s))`, result);
156
+ }
157
+ case "query_supported_evm_chains": {
158
+ const client = getBridgeClientForQuery();
159
+ const result = await client.querySupportedEvmChains();
160
+ return ok(`${result.length} EVM chain(s) supported: ${result.map(c => `${c.name}(chainId=${c.chainId})`).join(", ")}`, result);
161
+ }
162
+ case "query_supported_tokens": {
163
+ const data = validated.data ?? {};
164
+ const client = getBridgeClientForQuery();
165
+ const result = await client.querySupportedTokens({
166
+ network: data.network,
167
+ });
168
+ const totalTokens = result.reduce((sum, c) => sum + c.tokens.length, 0);
169
+ return ok(`${result.length} chain(s), ${totalTokens} token entries: ${result.map((c) => `${c.chainName}(${c.tokens.length} tokens)`).join(", ")}`, result);
170
+ }
171
+ case "query_transfer_list": {
172
+ const data = validated.data ?? {};
173
+ const client = getBridgeClientForQuery();
174
+ let result = await client.queryTransferList({
175
+ onlyActive: data.onlyActive,
176
+ });
177
+ if (data.status) {
178
+ result = result.filter((r) => r.status === data.status);
179
+ }
180
+ if (data.direction) {
181
+ result = result.filter((r) => r.direction === data.direction);
182
+ }
183
+ if (data.token) {
184
+ result = result.filter((r) => r.token === data.token);
185
+ }
186
+ if (data.limit && data.limit > 0) {
187
+ result = result.slice(0, data.limit);
188
+ }
189
+ const active = result.filter(r => r.status !== "success" && r.status !== "failed").length;
190
+ return ok(`${result.length} transfer record(s) (${active} in progress)${data.status || data.direction || data.token ? " (filtered)" : ""}`, result);
191
+ }
192
+ case "query_transfer_status": {
193
+ const data = validated.data;
194
+ const client = getBridgeClientForQuery();
195
+ const refresh = data.refresh !== false;
196
+ if (refresh) {
197
+ try {
198
+ await Promise.race([
199
+ client.refreshTransferStatus(data.transferId),
200
+ new Promise((_, reject) => setTimeout(() => reject(new Error("refresh timeout")), 15_000)),
201
+ ]);
202
+ }
203
+ catch {
204
+ }
205
+ }
206
+ const result = await client.queryTransferStatus(data.transferId);
207
+ if (!result) {
208
+ return err(`transferId '${data.transferId}' not found. ` +
209
+ `Use query_transfer_list to see all valid transferIds. ` +
210
+ `Note: transfer history is persisted in cache.db and restored on MCP restart, ` +
211
+ `so this transferId may never have been created in this environment.`);
212
+ }
213
+ return ok(`Transfer ${data.transferId}: ${result.direction} / ${result.step} / ${result.status}`, result);
214
+ }
215
+ case "manage_evm_rpc": {
216
+ const data = validated.data;
217
+ const client = getBridgeClientForQuery();
218
+ const result = await client.manageEvmRpc({
219
+ op: data.op,
220
+ network: data.network,
221
+ rpcUrls: data.rpcUrls,
222
+ });
223
+ return ok(`RPC '${data.op}' operation ${result.success ? "succeeded" : "failed"}`, result);
224
+ }
225
+ default: {
226
+ return err(`Unsupported operation_type: ${validated.operation_type}`);
227
+ }
228
+ }
229
+ }
230
+ catch (e) {
231
+ const msg = e?.message ?? String(e);
232
+ return err(`Bridge operation failed: ${msg}`);
233
+ }
234
+ }