2020117-agent 0.6.11 → 0.6.13

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 +42 -11
  2. package/package.json +1 -1
package/dist/agent.js CHANGED
@@ -413,17 +413,33 @@ async function handleDvmResult(label, event) {
413
413
  return;
414
414
  // Extract job reference, amount, and provider's Lightning Address
415
415
  const requestId = event.tags.find(t => t[0] === 'e')?.[1];
416
- const amountMsats = Number(event.tags.find(t => t[0] === 'amount')?.[1] || '0');
416
+ const amountTag = event.tags.find(t => t[0] === 'amount');
417
+ const amountMsats = Number(amountTag?.[1] || '0');
417
418
  const amountSats = Math.floor(amountMsats / 1000);
418
- const lightningAddress = event.tags.find(t => t[0] === 'lightning_address')?.[1];
419
+ const bolt11 = amountTag?.[2] || null; // NIP-90: ["amount", "<msats>", "<bolt11>"]
420
+ // Providers may use lud16, lightning_address, or lud06 to declare their payment address
421
+ const lightningAddress = event.tags.find(t => t[0] === 'lud16' || t[0] === 'lightning_address')?.[1];
419
422
  console.log(`[${label}] DVM result from ${event.pubkey.slice(0, 8)}: ${event.content.slice(0, 80)}...`);
420
- // Auto-pay if we have NWC and provider has Lightning Address
423
+ // Auto-pay if we have NWC
421
424
  let paid = false;
422
- if (amountSats > 0 && lightningAddress && state.nwcParsed) {
425
+ if (amountSats > 0 && state.nwcParsed) {
423
426
  try {
424
- const { preimage } = await nwcPayLightningAddress(state.nwcParsed, lightningAddress, amountSats);
425
- console.log(`[${label}] Paid ${amountSats} sats ${lightningAddress} (preimage: ${preimage.slice(0, 16)}...)`);
426
- paid = true;
427
+ if (bolt11) {
428
+ // Preferred: pay bolt11 invoice directly from amount tag
429
+ const { nwcPayInvoice } = await import('./nwc.js');
430
+ const { preimage } = await nwcPayInvoice(state.nwcParsed, bolt11);
431
+ console.log(`[${label}] Paid ${amountSats} sats via bolt11 (preimage: ${preimage.slice(0, 16)}...)`);
432
+ paid = true;
433
+ }
434
+ else if (lightningAddress) {
435
+ // Fallback: pay via Lightning Address (lud16 / lightning_address tag)
436
+ const { preimage } = await nwcPayLightningAddress(state.nwcParsed, lightningAddress, amountSats);
437
+ console.log(`[${label}] Paid ${amountSats} sats → ${lightningAddress} (preimage: ${preimage.slice(0, 16)}...)`);
438
+ paid = true;
439
+ }
440
+ else {
441
+ console.warn(`[${label}] Result requires ${amountSats} sats but provider has no bolt11 or Lightning Address`);
442
+ }
427
443
  }
428
444
  catch (e) {
429
445
  console.error(`[${label}] Payment failed: ${e instanceof Error ? e.message : 'Unknown error'}`);
@@ -432,9 +448,6 @@ async function handleDvmResult(label, event) {
432
448
  else if (amountSats === 0) {
433
449
  paid = true; // free job
434
450
  }
435
- else if (amountSats > 0 && !lightningAddress) {
436
- console.warn(`[${label}] Result requires ${amountSats} sats but provider has no Lightning Address`);
437
- }
438
451
  else if (amountSats > 0 && !state.nwcParsed) {
439
452
  console.warn(`[${label}] Result requires ${amountSats} sats but no NWC wallet configured`);
440
453
  }
@@ -597,15 +610,33 @@ async function handleDvmRequest(label, event) {
597
610
  console.log(`[${label}] DVM result: ${result.length} chars`);
598
611
  // Send result (Kind 6xxx = request kind + 1000)
599
612
  const resultKind = KIND + 1000;
613
+ const amountMsats = SATS_PER_CHUNK * CHUNKS_PER_PAYMENT * 1000;
614
+ let amountTag;
615
+ if (amountMsats > 0 && state.nwcParsed) {
616
+ try {
617
+ const { bolt11 } = await nwcMakeInvoice(state.nwcParsed, amountMsats, `DVM job ${event.id.slice(0, 8)}`);
618
+ amountTag = ['amount', String(amountMsats), bolt11];
619
+ }
620
+ catch (e) {
621
+ console.warn(`[${label}] Failed to generate invoice via NWC, falling back to amount-only:`, e);
622
+ amountTag = ['amount', String(amountMsats)];
623
+ }
624
+ }
625
+ else {
626
+ amountTag = ['amount', String(amountMsats)];
627
+ }
600
628
  const resultTags = [
601
629
  ['p', event.pubkey],
602
630
  ['e', event.id],
603
631
  ['request', JSON.stringify(event)],
604
- ['amount', String(SATS_PER_CHUNK * CHUNKS_PER_PAYMENT * 1000)], // msats
632
+ amountTag,
605
633
  ];
606
634
  if (LIGHTNING_ADDRESS) {
607
635
  resultTags.push(['lightning_address', LIGHTNING_ADDRESS]);
608
636
  }
637
+ if (state.processor?.name) {
638
+ resultTags.push(['model', state.processor.name]);
639
+ }
609
640
  const resultEvent = signEvent({
610
641
  kind: resultKind,
611
642
  tags: resultTags,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "2020117-agent",
3
- "version": "0.6.11",
3
+ "version": "0.6.13",
4
4
  "description": "2020117 agent runtime — Nostr-native relay subscription + Hyperswarm P2P + Lightning payments",
5
5
  "type": "module",
6
6
  "bin": {