2020117-agent 0.4.0 → 0.4.2

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/dist/agent.js CHANGED
@@ -357,7 +357,8 @@ function subscribeNipXX(label) {
357
357
  function subscribeDvmRequests(label) {
358
358
  if (!state.sovereignKeys || !state.relayPool)
359
359
  return;
360
- state.relayPool.subscribe({ kinds: [KIND], '#p': [state.sovereignKeys.pubkey] }, (event) => {
360
+ // Subscribe to all DVM requests of our kind (broadcast + directed)
361
+ state.relayPool.subscribe({ kinds: [KIND] }, (event) => {
361
362
  handleDvmRequest(label, event).catch(e => {
362
363
  console.error(`[${label}] DVM request error: ${e.message}`);
363
364
  });
package/dist/session.js CHANGED
@@ -72,6 +72,7 @@ const state = {
72
72
  skill: null,
73
73
  satsPerMinute: 0,
74
74
  totalSpent: 0,
75
+ pendingAmount: 0, // accumulates fractional sats until >= 1
75
76
  startedAt: 0,
76
77
  httpServer: null,
77
78
  shuttingDown: false,
@@ -194,19 +195,32 @@ function setupMessageHandler() {
194
195
  }
195
196
  }
196
197
  else if (cashuState) {
197
- // Cashu mode: split tokens and send
198
- log(`Paying with Cashu: ${amount} sats...`);
198
+ // Cashu mode: accumulate fractional amounts, pay in whole sats
199
+ state.pendingAmount += amount;
200
+ const payNow = Math.floor(state.pendingAmount);
201
+ if (payNow < 1) {
202
+ // Not enough to pay yet — ack without token
203
+ state.node.send(state.socket, {
204
+ type: 'session_tick_ack',
205
+ id: msg.id,
206
+ session_id: state.sessionId,
207
+ amount: 0,
208
+ });
209
+ break;
210
+ }
211
+ log(`Paying with Cashu: ${payNow} sats (accumulated from ${state.pendingAmount.toFixed(2)})...`);
199
212
  try {
200
- const { token, change } = await sendCashuToken(cashuState.mintUrl, cashuState.proofs, amount);
213
+ const { token, change } = await sendCashuToken(cashuState.mintUrl, cashuState.proofs, payNow);
201
214
  cashuState.proofs = change;
202
- state.totalSpent += amount;
203
- log(`Paid ${amount} sats (total: ${state.totalSpent}, ~${estimatedMinutesLeft()} min left)`);
215
+ state.totalSpent += payNow;
216
+ state.pendingAmount -= payNow;
217
+ log(`Paid ${payNow} sats (total: ${state.totalSpent}, ~${estimatedMinutesLeft()} min left)`);
204
218
  state.node.send(state.socket, {
205
219
  type: 'session_tick_ack',
206
220
  id: msg.id,
207
221
  session_id: state.sessionId,
208
222
  cashu_token: token,
209
- amount,
223
+ amount: payNow,
210
224
  });
211
225
  }
212
226
  catch (e) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "2020117-agent",
3
- "version": "0.4.0",
3
+ "version": "0.4.2",
4
4
  "description": "2020117 agent runtime — API polling + Hyperswarm P2P + Sovereign Nostr mode + Cashu/Lightning payments",
5
5
  "type": "module",
6
6
  "bin": {