@johngalt5/bsv-overlay 0.2.6 → 0.2.7
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/index.ts +25 -14
- package/package.json +1 -1
package/index.ts
CHANGED
|
@@ -153,21 +153,32 @@ function startBackgroundService(env, cliPath, logger) {
|
|
|
153
153
|
const event = JSON.parse(line);
|
|
154
154
|
logger?.debug?.(`[bsv-overlay] ${event.event || event.type || 'message'}:`, JSON.stringify(event).slice(0, 200));
|
|
155
155
|
|
|
156
|
-
// Detect queued-for-agent events and
|
|
156
|
+
// Detect queued-for-agent events and wake the agent immediately
|
|
157
157
|
if (event.action === 'queued-for-agent' && event.serviceId) {
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
158
|
+
logger?.info?.(`[bsv-overlay] ⚡ Incoming ${event.serviceId} request from ${event.from?.slice(0, 12)}... — waking agent`);
|
|
159
|
+
|
|
160
|
+
// Wake the agent via gateway cron.wake RPC (fire-and-forget)
|
|
161
|
+
const wakeText = `⚡ Incoming overlay service request: ${event.serviceId} from ${event.from?.slice(0, 16)}... (${event.satoshisReceived || '?'} sats paid). Check overlay({ action: "pending-requests" }) for details, fulfill it using your capabilities, then call overlay({ action: "fulfill", requestId: "...", recipientKey: "...", serviceId: "...", result: {...} }).`;
|
|
162
|
+
(async () => {
|
|
163
|
+
try {
|
|
164
|
+
const gatewayUrl = 'http://127.0.0.1:18789';
|
|
165
|
+
const wakeResp = await fetch(gatewayUrl, {
|
|
166
|
+
method: 'POST',
|
|
167
|
+
headers: { 'Content-Type': 'application/json' },
|
|
168
|
+
body: JSON.stringify({
|
|
169
|
+
jsonrpc: '2.0',
|
|
170
|
+
id: `overlay-wake-${Date.now()}`,
|
|
171
|
+
method: 'cron.wake',
|
|
172
|
+
params: { mode: 'now', text: wakeText },
|
|
173
|
+
}),
|
|
174
|
+
});
|
|
175
|
+
if (wakeResp.ok) {
|
|
176
|
+
logger?.info?.('[bsv-overlay] Agent woken for service fulfillment');
|
|
177
|
+
}
|
|
178
|
+
} catch (wakeErr: any) {
|
|
179
|
+
logger?.warn?.('[bsv-overlay] Failed to wake agent:', wakeErr.message);
|
|
180
|
+
}
|
|
181
|
+
})();
|
|
171
182
|
}
|
|
172
183
|
} catch {}
|
|
173
184
|
}
|