2020117-agent 0.6.16 → 0.6.18

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 +48 -5
  2. package/package.json +1 -1
package/dist/agent.js CHANGED
@@ -571,14 +571,53 @@ async function handleDvmRequest(label, event) {
571
571
  if (!acquireSlot())
572
572
  return;
573
573
  try {
574
- // Parse DVM request: input is in 'i' tag, optional model in ['param','model','...']
575
- const inputTag = event.tags.find(t => t[0] === 'i');
576
- const input = inputTag?.[1] || '';
577
- const requestedModel = event.tags.find(t => t[0] === 'param' && t[1] === 'model')?.[2];
574
+ // Step 1: p-tag filter — if request is directed (has p tags) but not to us, skip
575
+ const pTags = event.tags.filter(t => t[0] === 'p').map(t => t[1]);
576
+ if (pTags.length > 0 && !pTags.includes(state.sovereignKeys.pubkey)) {
577
+ console.log(`[${label}] DVM request ${event.id.slice(0, 8)} directed to another agent, skipping`);
578
+ return;
579
+ }
580
+ // Step 2: handle NIP-44 encrypted requests
581
+ const isEncrypted = event.tags.some(t => t[0] === 'encrypted');
582
+ let rawInput;
583
+ if (isEncrypted) {
584
+ try {
585
+ rawInput = await nip44Decrypt(state.sovereignKeys.privkey, event.pubkey, event.content);
586
+ console.log(`[${label}] DVM request ${event.id.slice(0, 8)} decrypted successfully`);
587
+ }
588
+ catch {
589
+ console.log(`[${label}] DVM request ${event.id.slice(0, 8)} decryption failed (not for us), skipping`);
590
+ return;
591
+ }
592
+ }
593
+ else {
594
+ rawInput = '';
595
+ }
596
+ // Parse DVM request: for encrypted jobs, decrypted content is a JSON array of tags
597
+ // Per NIP-90: [["i","actual input","text"],["param","model","..."],...]
598
+ let effectiveTags = event.tags;
599
+ if (isEncrypted) {
600
+ try {
601
+ const parsed = JSON.parse(rawInput);
602
+ if (Array.isArray(parsed))
603
+ effectiveTags = parsed;
604
+ }
605
+ catch { /* rawInput is plain text — fall through, handled below */ }
606
+ }
607
+ const inputTag = effectiveTags.find(t => t[0] === 'i');
608
+ // For encrypted plain-text fallback: rawInput itself is the input
609
+ const input = inputTag?.[1] || (isEncrypted ? rawInput : '');
610
+ const requestedModel = effectiveTags.find(t => t[0] === 'param' && t[1] === 'model')?.[2];
578
611
  if (!input) {
579
612
  console.warn(`[${label}] DVM request ${event.id.slice(0, 8)} has no input`);
580
613
  return;
581
614
  }
615
+ // Reject jobs with bid below minimum price
616
+ const jobBidMsats = Number(event.tags.find(t => t[0] === 'bid')?.[1] || '0');
617
+ if (jobBidMsats > 0 && jobBidMsats < MIN_BID_SATS * 1000) {
618
+ console.log(`[${label}] DVM request ${event.id.slice(0, 8)} bid ${jobBidMsats} msats below minimum ${MIN_BID_SATS * 1000} msats, skipping`);
619
+ return;
620
+ }
582
621
  console.log(`[${label}] DVM request from ${event.pubkey.slice(0, 8)}: "${input.slice(0, 60)}..."`);
583
622
  // Send feedback (Kind 7000)
584
623
  const feedbackEvent = signEvent({
@@ -613,7 +652,11 @@ async function handleDvmRequest(label, event) {
613
652
  console.log(`[${label}] DVM result: ${result.length} chars`);
614
653
  // Send result (Kind 6xxx = request kind + 1000)
615
654
  const resultKind = KIND + 1000;
616
- const amountMsats = SATS_PER_CHUNK * CHUNKS_PER_PAYMENT * 1000;
655
+ // Prefer the bid the customer declared in the job; fall back to local fixed price.
656
+ // bid tag is in the outer (unencrypted) event tags per NIP-90.
657
+ const bidMsats = Number(event.tags.find(t => t[0] === 'bid')?.[1] || '0');
658
+ const fixedPriceMsats = SATS_PER_CHUNK * CHUNKS_PER_PAYMENT * 1000;
659
+ const amountMsats = bidMsats > 0 ? bidMsats : fixedPriceMsats;
617
660
  let amountTag;
618
661
  if (amountMsats > 0 && state.nwcParsed) {
619
662
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "2020117-agent",
3
- "version": "0.6.16",
3
+ "version": "0.6.18",
4
4
  "description": "2020117 agent runtime — Nostr-native relay subscription + Hyperswarm P2P + Lightning payments",
5
5
  "type": "module",
6
6
  "bin": {