@johngalt5/bsv-overlay 0.2.11 → 0.2.12

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/index.ts +17 -4
  2. package/package.json +1 -1
package/index.ts CHANGED
@@ -677,8 +677,11 @@ async function handleServiceRequest(params, env, cliPath, config, api) {
677
677
  throw new Error(`Service request failed: ${requestOutput.error}`);
678
678
  }
679
679
 
680
- // 7. Poll for response
681
- const maxPollAttempts = 12; // ~60 seconds with 5 second intervals
680
+ // 7. Poll for response (up to 120s, with early return)
681
+ // The WebSocket background service will also receive the response
682
+ // asynchronously, so we return a "pending" status if we time out
683
+ // rather than throwing an error.
684
+ const maxPollAttempts = 24; // ~120 seconds with 5 second intervals
682
685
  let attempts = 0;
683
686
 
684
687
  while (attempts < maxPollAttempts) {
@@ -690,7 +693,7 @@ async function handleServiceRequest(params, env, cliPath, config, api) {
690
693
  const pollOutput = parseCliOutput(pollResult.stdout);
691
694
 
692
695
  if (pollOutput.success && pollOutput.data) {
693
- // FIX: Check pollOutput.data.messages array for service-response
696
+ // Check pollOutput.data.messages array for service-response
694
697
  const messages = pollOutput.data.messages || [];
695
698
  for (const msg of messages) {
696
699
  if (msg.type === 'service-response' && msg.from === bestProvider.identityKey) {
@@ -711,7 +714,17 @@ async function handleServiceRequest(params, env, cliPath, config, api) {
711
714
  }
712
715
  }
713
716
 
714
- throw new Error(`Service request timed out after ${maxPollAttempts * 5} seconds`);
717
+ // Don't throw the response may still arrive via WebSocket
718
+ // Record the spend since payment was already sent
719
+ recordSpend(walletDir, price, service, bestProvider.agentName);
720
+ return {
721
+ provider: bestProvider.agentName,
722
+ cost: price,
723
+ status: "pending",
724
+ message: `Request sent and paid (${price} sats). The provider hasn't responded within 120s, but the response may still arrive via the background WebSocket service. Check notifications later.`,
725
+ requestId: requestOutput.data?.messageId,
726
+ providerKey: bestProvider.identityKey,
727
+ };
715
728
  }
716
729
 
717
730
  async function handleDiscover(params, env, cliPath) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@johngalt5/bsv-overlay",
3
- "version": "0.2.11",
3
+ "version": "0.2.12",
4
4
  "description": "Clawdbot BSV Overlay — agent discovery, service marketplace, and micropayments on the BSV blockchain",
5
5
  "type": "module",
6
6
  "files": [