2020117-agent 0.3.2 → 0.3.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 (2) hide show
  1. package/dist/agent.js +27 -10
  2. package/package.json +1 -1
package/dist/agent.js CHANGED
@@ -367,11 +367,20 @@ async function startSwarmListener(label) {
367
367
  };
368
368
  activeSessions.set(sessionId, session);
369
369
  // Debit first 10 minutes immediately (prepaid model)
370
- const firstDebit = await collectPayment({
371
- ndebit: session.ndebit,
372
- lightningAddress: LIGHTNING_ADDRESS,
373
- amountSats: debitAmount,
374
- });
370
+ let firstDebit;
371
+ try {
372
+ firstDebit = await collectPayment({
373
+ ndebit: session.ndebit,
374
+ lightningAddress: LIGHTNING_ADDRESS,
375
+ amountSats: debitAmount,
376
+ });
377
+ }
378
+ catch (e) {
379
+ console.warn(`[${label}] Session ${sessionId}: first debit error: ${e.message}`);
380
+ node.send(socket, { type: 'error', id: msg.id, message: `Payment error: ${e.message}` });
381
+ activeSessions.delete(sessionId);
382
+ return;
383
+ }
375
384
  if (!firstDebit.ok) {
376
385
  console.warn(`[${label}] Session ${sessionId}: first debit failed: ${firstDebit.error}`);
377
386
  node.send(socket, { type: 'error', id: msg.id, message: `Payment failed: ${firstDebit.error}` });
@@ -397,11 +406,19 @@ async function startSwarmListener(label) {
397
406
  });
398
407
  // Debit every 10 minutes
399
408
  session.debitTimer = setInterval(async () => {
400
- const debit = await collectPayment({
401
- ndebit: session.ndebit,
402
- lightningAddress: LIGHTNING_ADDRESS,
403
- amountSats: debitAmount,
404
- });
409
+ let debit;
410
+ try {
411
+ debit = await collectPayment({
412
+ ndebit: session.ndebit,
413
+ lightningAddress: LIGHTNING_ADDRESS,
414
+ amountSats: debitAmount,
415
+ });
416
+ }
417
+ catch (e) {
418
+ console.log(`[${label}] Session ${sessionId}: debit error (${e.message}) — ending session`);
419
+ endSession(node, session, label);
420
+ return;
421
+ }
405
422
  if (!debit.ok) {
406
423
  console.log(`[${label}] Session ${sessionId}: debit failed (${debit.error}) — ending session`);
407
424
  endSession(node, session, label);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "2020117-agent",
3
- "version": "0.3.2",
3
+ "version": "0.3.3",
4
4
  "description": "2020117 agent runtime — API polling + Hyperswarm P2P + CLINK Lightning payments",
5
5
  "type": "module",
6
6
  "bin": {