agentic-x402 0.3.4 → 0.3.6

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/SKILL.md CHANGED
@@ -4,7 +4,7 @@ description: Make x402 payments to access gated APIs and content. Fetch paid res
4
4
  license: MIT
5
5
  compatibility: Requires Node.js 20+, network access to x402 facilitators and EVM chains
6
6
  homepage: https://www.npmjs.com/package/agentic-x402
7
- metadata: {"author": "monemetrics", "version": "0.3.4", "openclaw": {"requires": {"bins": ["x402"], "env": ["EVM_PRIVATE_KEY"]}, "primaryEnv": "EVM_PRIVATE_KEY", "install": [{"id": "node", "kind": "node", "package": "agentic-x402", "bins": ["x402"], "label": "Install agentic-x402 (npm)"}], "plugin": true}}
7
+ metadata: {"author": "monemetrics", "version": "0.3.6", "openclaw": {"requires": {"bins": ["x402"], "env": ["EVM_PRIVATE_KEY"]}, "primaryEnv": "EVM_PRIVATE_KEY", "install": [{"id": "node", "kind": "node", "package": "agentic-x402", "bins": ["x402"], "label": "Install agentic-x402 (npm)"}], "plugin": true}}
8
8
  allowed-tools: Bash(x402:*) Bash(npm:*) Read
9
9
  ---
10
10
 
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "id": "agentic-x402",
3
3
  "name": "x402 Payments",
4
- "version": "0.3.4",
4
+ "version": "0.3.6",
5
5
  "description": "Agent skill for x402 payments — pay for and sell gated content with background payment watching",
6
6
  "skills": ["./skills/x402"],
7
7
  "configSchema": {
@@ -27,6 +27,10 @@
27
27
  "default": "https://21.cash",
28
28
  "description": "Base URL of the x402 links API (21.cash)"
29
29
  },
30
+ "hooksToken": {
31
+ "type": "string",
32
+ "description": "Bearer token for gateway hooks endpoint (must match hooks.token in gateway config). Falls back to OPENCLAW_HOOKS_TOKEN env var."
33
+ },
30
34
  "watcher": {
31
35
  "type": "object",
32
36
  "properties": {
@@ -68,6 +72,11 @@
68
72
  "x402LinksApiUrl": {
69
73
  "label": "21.cash API URL",
70
74
  "placeholder": "https://21.cash"
75
+ },
76
+ "hooksToken": {
77
+ "label": "Hooks Token",
78
+ "sensitive": true,
79
+ "placeholder": "your-hooks-secret"
71
80
  }
72
81
  }
73
82
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agentic-x402",
3
- "version": "0.3.4",
3
+ "version": "0.3.6",
4
4
  "description": "Agent skill for x402 payments - pay for and sell gated content",
5
5
  "type": "module",
6
6
  "bin": {
@@ -3,7 +3,7 @@
3
3
 
4
4
  import type { X402PluginConfig } from './types.js';
5
5
 
6
- const CONFIG_MAP: Record<keyof Omit<X402PluginConfig, 'watcher'>, string> = {
6
+ const CONFIG_MAP: Record<keyof Omit<X402PluginConfig, 'watcher' | 'hooksToken'>, string> = {
7
7
  evmPrivateKey: 'EVM_PRIVATE_KEY',
8
8
  network: 'X402_NETWORK',
9
9
  maxPaymentUsd: 'X402_MAX_PAYMENT_USD',
@@ -23,7 +23,7 @@ export function applyConfigBridge(pluginConfig: Record<string, unknown>): void {
23
23
  const config = pluginConfig as X402PluginConfig;
24
24
 
25
25
  for (const [key, envVar] of Object.entries(CONFIG_MAP)) {
26
- const value = config[key as keyof Omit<X402PluginConfig, 'watcher'>];
26
+ const value = config[key as keyof Omit<X402PluginConfig, 'watcher' | 'hooksToken'>];
27
27
  if (value !== undefined && value !== null && !process.env[envVar]) {
28
28
  process.env[envVar] = String(value);
29
29
  }
@@ -11,11 +11,11 @@ export default {
11
11
  name: 'x402 Payments',
12
12
 
13
13
  register(api: OpenClawPluginApi): void {
14
- const { logger, config, gatewayPort } = api;
15
- const pluginConfig = config as X402PluginConfig;
14
+ const { logger, gatewayPort } = api;
15
+ const pluginConfig = (api.pluginConfig ?? {}) as X402PluginConfig;
16
16
 
17
17
  // 1. Apply config bridge: inject plugin config → process.env
18
- applyConfigBridge(config);
18
+ applyConfigBridge(pluginConfig);
19
19
  logger.debug('x402 config bridge applied');
20
20
 
21
21
  // 2. Register background watcher service (unless disabled)
@@ -26,6 +26,7 @@ export default {
26
26
  watcher = new PaymentWatcher({
27
27
  logger,
28
28
  gatewayPort,
29
+ hooksToken: pluginConfig.hooksToken,
29
30
  pollIntervalMs: pluginConfig.watcher?.pollIntervalMs,
30
31
  notifyOnPayment: pluginConfig.watcher?.notifyOnPayment,
31
32
  });
@@ -52,6 +52,7 @@ export interface CliCommand {
52
52
  export interface OpenClawPluginApi {
53
53
  logger: PluginLogger;
54
54
  config: Record<string, unknown>;
55
+ pluginConfig?: Record<string, unknown>;
55
56
  gatewayPort: number;
56
57
  registerService(service: PluginService): void;
57
58
  registerTool(tool: PluginTool): void;
@@ -67,6 +68,7 @@ export interface X402PluginConfig {
67
68
  network?: 'mainnet' | 'testnet';
68
69
  maxPaymentUsd?: number;
69
70
  x402LinksApiUrl?: string;
71
+ hooksToken?: string;
70
72
  watcher?: {
71
73
  enabled?: boolean;
72
74
  pollIntervalMs?: number;
@@ -20,6 +20,7 @@ const ERC20_BALANCE_ABI = [{
20
20
  interface WatcherOptions {
21
21
  logger: PluginLogger;
22
22
  gatewayPort: number;
23
+ hooksToken?: string;
23
24
  pollIntervalMs?: number;
24
25
  notifyOnPayment?: boolean;
25
26
  }
@@ -29,6 +30,7 @@ export class PaymentWatcher implements PluginService {
29
30
 
30
31
  private logger: PluginLogger;
31
32
  private gatewayPort: number;
33
+ private hooksToken: string | undefined;
32
34
  private pollIntervalMs: number;
33
35
  private notifyOnPayment: boolean;
34
36
 
@@ -42,6 +44,7 @@ export class PaymentWatcher implements PluginService {
42
44
  constructor(options: WatcherOptions) {
43
45
  this.logger = options.logger;
44
46
  this.gatewayPort = options.gatewayPort;
47
+ this.hooksToken = options.hooksToken || process.env.OPENCLAW_HOOKS_TOKEN;
45
48
  this.pollIntervalMs = options.pollIntervalMs ?? 30_000;
46
49
  this.notifyOnPayment = options.notifyOnPayment ?? true;
47
50
  }
@@ -208,23 +211,33 @@ export class PaymentWatcher implements PluginService {
208
211
 
209
212
  private async sendHook(event: PaymentEvent): Promise<void> {
210
213
  const port = this.gatewayPort || 18789;
214
+
215
+ if (!this.hooksToken) {
216
+ this.logger.warn('No hooks token configured — skipping hook delivery. Set hooksToken in plugin config or OPENCLAW_HOOKS_TOKEN env var.');
217
+ return;
218
+ }
219
+
211
220
  const hookUrl = `http://127.0.0.1:${port}/hooks/agent`;
212
221
 
213
222
  try {
214
223
  const response = await fetch(hookUrl, {
215
224
  method: 'POST',
216
- headers: { 'Content-Type': 'application/json' },
225
+ headers: {
226
+ 'Content-Type': 'application/json',
227
+ 'Authorization': `Bearer ${this.hooksToken}`,
228
+ },
217
229
  body: JSON.stringify({
230
+ message: `Payment detected on ${event.routerName}: +${event.increase} USDC (${event.previousBalance} → ${event.newBalance}). Router: ${event.routerAddress}`,
218
231
  name: 'x402-payment',
219
232
  wakeMode: 'now',
220
- data: event,
221
233
  }),
222
234
  });
223
235
 
224
- if (!response.ok) {
225
- this.logger.warn(`Hook POST failed: ${response.status} ${response.statusText}`);
226
- } else {
236
+ // /hooks/agent returns 202 on success (async run started)
237
+ if (response.status === 202 || response.ok) {
227
238
  this.logger.debug(`Hook delivered for payment on ${event.routerName}`);
239
+ } else {
240
+ this.logger.warn(`Hook POST failed: ${response.status} ${response.statusText}`);
228
241
  }
229
242
  } catch (err) {
230
243
  this.logger.warn(`Hook POST error: ${err instanceof Error ? err.message : String(err)}`);
@@ -4,7 +4,7 @@ description: Make x402 payments to access gated APIs and content. Fetch paid res
4
4
  license: MIT
5
5
  compatibility: Requires Node.js 20+, network access to x402 facilitators and EVM chains
6
6
  homepage: https://www.npmjs.com/package/agentic-x402
7
- metadata: {"author": "monemetrics", "version": "0.3.4", "openclaw": {"requires": {"bins": ["x402"], "env": ["EVM_PRIVATE_KEY"]}, "primaryEnv": "EVM_PRIVATE_KEY", "install": [{"id": "node", "kind": "node", "package": "agentic-x402", "bins": ["x402"], "label": "Install agentic-x402 (npm)"}], "plugin": true}}
7
+ metadata: {"author": "monemetrics", "version": "0.3.6", "openclaw": {"requires": {"bins": ["x402"], "env": ["EVM_PRIVATE_KEY"]}, "primaryEnv": "EVM_PRIVATE_KEY", "install": [{"id": "node", "kind": "node", "package": "agentic-x402", "bins": ["x402"], "label": "Install agentic-x402 (npm)"}], "plugin": true}}
8
8
  allowed-tools: Bash(x402:*) Bash(npm:*) Read
9
9
  ---
10
10