@zakyirsyaad/monagent-plugin 0.1.0 → 0.1.3

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 (40) hide show
  1. package/dist/commands/monad/identity/get.d.ts +19 -0
  2. package/dist/commands/monad/identity/get.js +113 -0
  3. package/dist/commands/monad/identity/register.d.ts +16 -0
  4. package/dist/commands/monad/identity/register.js +122 -0
  5. package/dist/commands/monad/jobs/complete.d.ts +15 -0
  6. package/dist/commands/monad/jobs/complete.js +63 -0
  7. package/dist/commands/{jobs → monad/jobs}/create.d.ts +5 -2
  8. package/dist/commands/monad/jobs/create.js +88 -0
  9. package/dist/commands/monad/jobs/refund.d.ts +14 -0
  10. package/dist/commands/monad/jobs/refund.js +56 -0
  11. package/dist/commands/{pay.d.ts → monad/pay.d.ts} +5 -2
  12. package/dist/commands/monad/pay.js +123 -0
  13. package/dist/commands/monad/reputation/check.d.ts +18 -0
  14. package/dist/commands/monad/reputation/check.js +103 -0
  15. package/dist/commands/monad/reputation/give.d.ts +15 -0
  16. package/dist/commands/monad/reputation/give.js +99 -0
  17. package/dist/commands/monad/x402/pay.d.ts +21 -0
  18. package/dist/commands/monad/x402/pay.js +224 -0
  19. package/dist/index.d.ts +10 -7
  20. package/dist/index.js +10 -7
  21. package/dist/monad.d.ts +424 -0
  22. package/dist/monad.js +186 -0
  23. package/dist/sdk.d.ts +62 -39
  24. package/dist/sdk.js +95 -8
  25. package/oclif.manifest.json +1304 -24
  26. package/package.json +47 -11
  27. package/dist/commands/identity/get.d.ts +0 -13
  28. package/dist/commands/identity/get.js +0 -59
  29. package/dist/commands/identity/register.d.ts +0 -12
  30. package/dist/commands/identity/register.js +0 -39
  31. package/dist/commands/jobs/create.js +0 -38
  32. package/dist/commands/pay.js +0 -33
  33. package/dist/commands/reputation/check.d.ts +0 -12
  34. package/dist/commands/reputation/check.js +0 -46
  35. package/dist/commands/reputation/give.d.ts +0 -12
  36. package/dist/commands/reputation/give.js +0 -45
  37. package/dist/commands/x402/pay.d.ts +0 -13
  38. package/dist/commands/x402/pay.js +0 -67
  39. package/dist/commands.test.d.ts +0 -1
  40. package/dist/commands.test.js +0 -141
package/dist/sdk.d.ts CHANGED
@@ -1,52 +1,75 @@
1
- import type { PublicClient } from "viem";
1
+ import { PluginCommand, type CommandIO, type PluginCommandContext, CommandError, InputFieldType, type InputSchema } from "@metamask/agent-wallet/plugin";
2
+ import { type PublicClient } from "viem";
3
+ export declare abstract class BaseMonadPluginCommand<TFinal = void> extends PluginCommand<TFinal> {
4
+ static description: string;
5
+ ctx: PluginCommandContext;
6
+ protected abstract readonly pluginCommandId: string;
7
+ setContext(ctx: PluginCommandContext): void;
8
+ /**
9
+ * Get an EVM PublicClient for reads, preferring the host's publicClient if available,
10
+ * with fallback to canonical Monad RPC specifically on transport errors (e.g. host Infura
11
+ * proxy returning 400 "Invalid chainId" when querying testnet 10143).
12
+ */
13
+ getPublicClient(chainId?: number): PublicClient;
14
+ }
15
+ export { type CommandIO, type PluginCommandContext, CommandError, InputFieldType, type InputSchema, type PublicClient, };
2
16
  /**
3
- * Standard CommandIO interface conforming to @metamask/agent-wallet/plugin
17
+ * EVM Transaction payload expected by MetaMask EvmWalletExecutor
4
18
  */
5
- export interface CommandIO {
6
- resolveInputs<T>(schema: unknown): Promise<T>;
7
- log(message: string): void;
8
- error(message: string): void;
9
- warn(message: string): void;
19
+ export interface EvmTxParams {
20
+ to: `0x${string}`;
21
+ value?: bigint;
22
+ data?: `0x${string}`;
10
23
  }
11
- export type WalletExecutorRequest = {
24
+ export interface EvmExecutorTransactionRequest {
12
25
  kind: "transaction";
13
26
  chainId: number;
14
- to: string;
15
- value?: bigint;
16
- data?: `0x${string}`;
17
- } | {
27
+ transaction: EvmTxParams;
28
+ }
29
+ export interface EvmExecutorTypedDataRequest {
30
+ kind: "typed-data";
31
+ chainId: number;
32
+ typedData: {
33
+ domain: Record<string, unknown>;
34
+ types: Record<string, unknown>;
35
+ primaryType: string;
36
+ message: Record<string, unknown>;
37
+ };
38
+ }
39
+ export interface EvmExecutorMessageRequest {
18
40
  kind: "message";
41
+ chainId: number;
19
42
  message: string;
20
- } | {
21
- kind: "typed-data";
22
- domain: Record<string, unknown>;
23
- types: Record<string, unknown>;
24
- primaryType: string;
25
- message: Record<string, unknown>;
26
- };
27
- export interface WalletExecutorResult {
43
+ }
44
+ export type EvmExecutorRequest = EvmExecutorTransactionRequest | EvmExecutorTypedDataRequest | EvmExecutorMessageRequest;
45
+ export interface EvmExecutorResult {
46
+ kind?: string;
28
47
  hash?: `0x${string}`;
29
48
  signature?: `0x${string}`;
30
- status: "success" | "pending" | "rejected";
31
- }
32
- export interface PluginCommandContext {
33
- publicClient(chainId: number): PublicClient;
34
- walletExecutor(io: CommandIO, commandId: string): (req: WalletExecutorRequest) => Promise<WalletExecutorResult>;
35
- logger: {
36
- info(msg: string): void;
37
- error(msg: string): void;
38
- warn(msg: string): void;
49
+ status: "CONFIRMED" | "SUBMITTED" | "FAILED" | "REJECTED" | string;
50
+ failureDescription?: string;
51
+ pendingJob?: {
52
+ pollingId?: string;
39
53
  };
40
54
  }
41
55
  /**
42
- * Base PluginCommand class simulating the sealed host lifecycle of MetaMask Agent Wallet
56
+ * Helper function to execute transactions through MetaMask EvmWalletExecutor
43
57
  */
44
- export declare abstract class PluginCommand<TResult = unknown> {
45
- static description: string;
46
- static requiresAuth: boolean;
47
- static requiresInit: boolean;
48
- protected abstract readonly pluginCommandId: string;
49
- protected ctx: PluginCommandContext;
50
- setContext(ctx: PluginCommandContext): void;
51
- abstract execute(io: CommandIO): Promise<TResult>;
52
- }
58
+ export declare function executeTransaction(ctx: PluginCommandContext, io: CommandIO, source: string, params: {
59
+ chainId: number;
60
+ to: `0x${string}`;
61
+ value?: bigint;
62
+ data?: `0x${string}`;
63
+ }): Promise<`0x${string}`>;
64
+ /**
65
+ * Helper function to sign typed data (EIP-712) through MetaMask EvmWalletExecutor
66
+ */
67
+ export declare function executeSignTypedData(ctx: PluginCommandContext, io: CommandIO, source: string, params: {
68
+ chainId: number;
69
+ typedData: {
70
+ domain: Record<string, unknown>;
71
+ types: Record<string, unknown>;
72
+ primaryType: string;
73
+ message: Record<string, unknown>;
74
+ };
75
+ }): Promise<`0x${string}`>;
package/dist/sdk.js CHANGED
@@ -1,12 +1,99 @@
1
- /**
2
- * Base PluginCommand class simulating the sealed host lifecycle of MetaMask Agent Wallet
3
- */
4
- export class PluginCommand {
5
- static description = "";
6
- static requiresAuth = true;
7
- static requiresInit = true;
8
- ctx;
1
+ import { PluginCommand, CommandError, InputFieldType, } from "@metamask/agent-wallet/plugin";
2
+ import { createPublicClient, http, HttpRequestError } from "viem";
3
+ import { resolveChain, MONAD_TESTNET_CHAIN_ID } from "./monad.js";
4
+ export class BaseMonadPluginCommand extends PluginCommand {
5
+ static description;
9
6
  setContext(ctx) {
10
7
  this.ctx = ctx;
11
8
  }
9
+ /**
10
+ * Get an EVM PublicClient for reads, preferring the host's publicClient if available,
11
+ * with fallback to canonical Monad RPC specifically on transport errors (e.g. host Infura
12
+ * proxy returning 400 "Invalid chainId" when querying testnet 10143).
13
+ */
14
+ getPublicClient(chainId = MONAD_TESTNET_CHAIN_ID) {
15
+ const chain = resolveChain(chainId);
16
+ const directClient = createPublicClient({
17
+ transport: http(chain.rpcUrl),
18
+ });
19
+ if (this.ctx && typeof this.ctx.publicClient === "function") {
20
+ try {
21
+ const hostClient = this.ctx.publicClient(chain.chainId);
22
+ return new Proxy(hostClient, {
23
+ get(target, prop, receiver) {
24
+ const orig = Reflect.get(target, prop, receiver);
25
+ if (typeof orig === "function") {
26
+ return (...args) => {
27
+ const res = orig.apply(target, args);
28
+ // Only wrap promises to preserve sync behavior of synchronous methods
29
+ if (res && typeof res.then === "function") {
30
+ return res.catch((err) => {
31
+ const errMsg = String(err?.message || err);
32
+ const isTransportError = err instanceof HttpRequestError ||
33
+ err?.cause instanceof HttpRequestError ||
34
+ err?.name === "HttpRequestError" ||
35
+ err?.cause?.name === "HttpRequestError" ||
36
+ (typeof err?.status === "number" && (err.status === 400 || err.status === 500)) ||
37
+ (typeof err?.cause?.status === "number" && (err.cause.status === 400 || err.cause.status === 500)) ||
38
+ errMsg.includes("HTTP request failed") ||
39
+ errMsg.includes("Invalid chainId") ||
40
+ errMsg.includes("MISSING_PROJECT_ID") ||
41
+ errMsg.includes("fetch failed");
42
+ if (isTransportError) {
43
+ const fallbackFn = Reflect.get(directClient, prop, directClient);
44
+ if (typeof fallbackFn === "function") {
45
+ return fallbackFn.apply(directClient, args);
46
+ }
47
+ }
48
+ throw err;
49
+ });
50
+ }
51
+ return res;
52
+ };
53
+ }
54
+ return orig;
55
+ },
56
+ });
57
+ }
58
+ catch {
59
+ // Host resolution threw synchronously (e.g. missing projectId)
60
+ }
61
+ }
62
+ return directClient;
63
+ }
64
+ }
65
+ export { CommandError, InputFieldType, };
66
+ /**
67
+ * Helper function to execute transactions through MetaMask EvmWalletExecutor
68
+ */
69
+ export async function executeTransaction(ctx, io, source, params) {
70
+ const executor = await ctx.walletExecutor(io, source);
71
+ const res = (await executor({
72
+ kind: "transaction",
73
+ chainId: params.chainId,
74
+ transaction: {
75
+ to: params.to,
76
+ value: params.value,
77
+ data: params.data,
78
+ },
79
+ }, { signal: io.signal }));
80
+ if ((res.status !== "CONFIRMED" && res.status !== "SUBMITTED") || !res.hash) {
81
+ throw new CommandError("TRANSACTION_FAILED", `Transaction failed on Monad: ${res.failureDescription || res.status}`, "Check wallet balance and RPC connectivity, then retry.");
82
+ }
83
+ return res.hash;
84
+ }
85
+ /**
86
+ * Helper function to sign typed data (EIP-712) through MetaMask EvmWalletExecutor
87
+ */
88
+ export async function executeSignTypedData(ctx, io, source, params) {
89
+ const executor = await ctx.walletExecutor(io, source);
90
+ const res = (await executor({
91
+ kind: "typed-data",
92
+ chainId: params.chainId,
93
+ typedData: params.typedData,
94
+ }, { signal: io.signal }));
95
+ if (res.status !== "CONFIRMED" || !res.signature) {
96
+ throw new CommandError("SIGNING_FAILED", `EIP-712 signing failed: ${res.failureDescription || res.status}`, "Ensure wallet is unlocked and approved.");
97
+ }
98
+ return res.signature;
12
99
  }