apow-cli 0.11.0 → 0.11.1

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.
@@ -55,6 +55,23 @@ let _fetchWithPayment = null;
55
55
  function resetPaymentFetch() {
56
56
  _fetchWithPayment = null;
57
57
  }
58
+ function extractErrorDetail(body) {
59
+ if (!body)
60
+ return "";
61
+ try {
62
+ const parsed = JSON.parse(body);
63
+ if (typeof parsed.error === "string" && parsed.error.trim())
64
+ return parsed.error.trim();
65
+ if (typeof parsed.message === "string" && parsed.message.trim())
66
+ return parsed.message.trim();
67
+ if (body.trim() === "{}")
68
+ return "";
69
+ }
70
+ catch {
71
+ // plain text body
72
+ }
73
+ return body.trim();
74
+ }
58
75
  async function getPaymentFetch(privateKey) {
59
76
  if (_fetchWithPayment)
60
77
  return _fetchWithPayment;
@@ -93,6 +110,7 @@ async function grindNonceHttp(challengeNumber, target, minerAddress, grindUrl, p
93
110
  break;
94
111
  }
95
112
  const body = await response.text().catch(() => "");
113
+ const bodyDetail = extractErrorDetail(body);
96
114
  const paymentRequiredB64 = response.headers.get("payment-required");
97
115
  let reason = "";
98
116
  if (paymentRequiredB64) {
@@ -102,7 +120,7 @@ async function grindNonceHttp(challengeNumber, target, minerAddress, grindUrl, p
102
120
  }
103
121
  catch { /* ignore decode errors */ }
104
122
  }
105
- const combinedError = `${reason} ${body}`.trim();
123
+ const combinedError = `${reason} ${bodyDetail}`.trim();
106
124
  if (attempt === 1 && combinedError.includes("No matching payment requirements")) {
107
125
  resetPaymentFetch();
108
126
  continue;
@@ -115,13 +133,13 @@ async function grindNonceHttp(challengeNumber, target, minerAddress, grindUrl, p
115
133
  throw new Error(`x402 GPU payment failed: EVM simulation failed (USDC approval issue?) [${reason}]`);
116
134
  }
117
135
  else {
118
- throw new Error(`x402 GPU payment failed: ${reason || body.slice(0, 200) || "unknown"}`);
136
+ throw new Error(`x402 GPU payment failed: ${reason || bodyDetail.slice(0, 200) || "unknown"}`);
119
137
  }
120
138
  }
121
139
  if (response.status === 504) {
122
140
  throw new Error("Remote GPU grind timed out (120s)");
123
141
  }
124
- throw new Error(`GrindProxy HTTP ${response.status}: ${body.slice(0, 200)}`);
142
+ throw new Error(`GrindProxy HTTP ${response.status}: ${(bodyDetail || body).slice(0, 200)}`);
125
143
  }
126
144
  if (!response || !response.ok) {
127
145
  throw new Error("x402 GPU payment failed: no successful response");
package/dist/miner.js CHANGED
@@ -456,7 +456,7 @@ async function startMining(tokenId) {
456
456
  else {
457
457
  console.log(` ${ui.dim(`Native grinder error: ${msg}`)}`);
458
458
  }
459
- return new Promise(() => { }); // hang forever (race will resolve via another grinder)
459
+ throw err;
460
460
  }));
461
461
  }
462
462
  if (useHttpGrind) {
@@ -477,7 +477,7 @@ async function startMining(tokenId) {
477
477
  else {
478
478
  console.log(` ${ui.dim(`x402 GPU grinder error: ${msg}`)}`);
479
479
  }
480
- return new Promise(() => { });
480
+ throw err;
481
481
  }));
482
482
  }
483
483
  // JS fallback is disabled by default when x402 grinding is active.
@@ -494,7 +494,20 @@ async function startMining(tokenId) {
494
494
  } : undefined,
495
495
  }));
496
496
  }
497
- grind = await Promise.race(grinders);
497
+ try {
498
+ grind = await Promise.any(grinders);
499
+ }
500
+ catch (err) {
501
+ if (err instanceof AggregateError && err.errors.length > 0) {
502
+ const firstNonAbort = err.errors.find((inner) => {
503
+ if (!(inner instanceof Error))
504
+ return true;
505
+ return inner.name !== "AbortError";
506
+ });
507
+ throw firstNonAbort ?? err.errors[0];
508
+ }
509
+ throw err;
510
+ }
498
511
  const khs = grind.hashrate > 0 ? (grind.hashrate / 1000).toFixed(0) : "?";
499
512
  nonceSpinner.stop(`Nonce found (${grind.elapsed.toFixed(1)}s${grind.hashrate > 0 ? `, ${khs}k H/s` : ""})`);
500
513
  // Final stale check: a challenge can change between the periodic
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "apow-cli",
3
- "version": "0.11.0",
3
+ "version": "0.11.1",
4
4
  "description": "Mine AGENT tokens on Base L2 with Agentic Proof of Work",
5
5
  "keywords": [
6
6
  "apow",